tomcat部署应用Jenkins
原创
©著作权归作者所有:来自51CTO博客作者959_1x的原创作品,请联系作者获取转载授权,否则将追究法律责任
jenkins
文章目录
1. Jenkins简介
Jenkins是一个独立的开源软件项目,是基于Java开发的一种持续集成工具,用于监控持续重复的工作,旨在提供一个开放易用的软件平台,使软件的持续集成变成可能。前身是Hudson是一个可扩展的持续集成引擎。可用于自动化各种任务,如构建,测试和部署软件。Jenkins可以通过本机系统包Docker安装,甚至可以通过安装Java Runtime Environment的任何机器独立运行。
2. Jenkins功能
Jenkins功能包括:
- 持续的软件版本发布/测试项目。
- 监控外部调用执行的工作。
3. 启动
- 首先保证系统中已经安装了jdk,最好是jdk1.5以上。
- 第一种启动方法,切换到jenkins.war存放的目录,输入如下命令:$ java -jar jenkins.war
- 如果需要修改端口可以使用如下命令:
- $ java -jar jenkins.war–httpPort=8081
- 然后在浏览器中(推荐用火狐)输入localhost:8081,localhost可以是本机的ip,也可以是计算机名。就可以打开jenkins。
- 第二种方法是用tomcat打开
- 解压tomcat到某个目录,如/usr/local,进入tomcat下的/bin目录,启动tomcat将jenkins.war文件放入tomcat下的webapps目录下,启动tomcat时,会自动在webapps目录下建立jenkins目录,在地址栏上需要输入localhost:8080/jenkins。
4. tomcat部署
# 下载tomcat
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.24/bin/apache-tomcat-9.0.24.tar.gz
--2018-09-04 19:43:28-- https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.24/bin/apache-tomcat-9.0.24.tar.gz
Resolving archive.apache.org (archive.apache.org)... 163.172.17.199
Connecting to archive.apache.org (archive.apache.org)|163.172.17.199|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9818695 (9.4M) [application/x-gzip]
Saving to: ‘apache-tomcat-9.0.24.tar.gz’
100%[=============================================================================================>] 9,818,695 416KB/s in 22s
2018-09-04 19:43:52 (434 KB/s) - ‘apache-tomcat-9.0.24.tar.gz’ saved [9818695/9818695]
# 解压部署
[root@localhost src]# ls
apache-tomcat-9.0.24.tar.gz debug kernels
[root@localhost src]# tar xf apache-tomcat-9.0.24.tar.gz -C /usr/local/
[root@localhost src]# cd /usr/local/
[root@localhost local]# ln -s apache-tomcat-9.0.24/ tomcat
[root@localhost local]# ll
total 0
drwxr-xr-x. 9 root root 160 Sep 4 19:45 apache-tomcat-9.0.24
drwxr-xr-x. 2 root root 6 Mar 10 2016 bin
drwxr-xr-x. 2 root root 6 Mar 10 2016 etc
drwxr-xr-x. 2 root root 6 Mar 10 2016 games
drwxr-xr-x. 2 root root 6 Mar 10 2016 include
drwxr-xr-x. 2 root root 6 Mar 10 2016 lib
drwxr-xr-x. 2 root root 6 Mar 10 2016 lib64
drwxr-xr-x. 2 root root 6 Mar 10 2016 libexec
drwxr-xr-x. 2 root root 6 Mar 10 2016 sbin
drwxr-xr-x. 5 root root 49 Jun 13 19:03 share
drwxr-xr-x. 2 root root 6 Mar 10 2016 src
lrwxrwxrwx. 1 root root 20 Sep 4 19:45 tomcat -> apache-tomcat-9.0.24/
# 写一个hello world的java页面
[root@localhost ~]# vim index.jsp
[root@localhost ~]# cat index.jsp
test page
<%
out.println("Hello World");
%>
[root@localhost ~]# mkdir /usr/local/tomcat/webapps/test
[root@localhost ~]# cp index.jsp /usr/local/tomcat/webapps/test/
[root@localhost ~]# ll /usr/local/tomcat/webapps/test/
total 4
-rw-r--r--. 1 root root 113 Sep 4 20:32 index.jsp
# 启动tomcat
[root@localhost ~]# /usr/local/tomcat/bin/catalina.sh start
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@localhost ~]# ps -ef|grep tomcat
root 21582 1 24 20:33 pts/0 00:00:05 /usr/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
root 21632 10293 0 20:34 pts/0 00:00:00 grep --color=auto tomcat
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 100 :::8080 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 1 ::ffff:127.0.0.1:8005 :::*
LISTEN 0 100 :::8009
5. Jenkins部署
Jenkins官网:https://jenkins.io/zh/
# 下载Jenkins的war包
[root@localhost ~]# wget -O /usr/local/tomcat/webapps/ http://mirrors.jenkins.io/war-stable/latest/jenkins.war
[root@localhost webapps]# ls
docs examples host-manager jenkins jenkins.war manager ROOT
# 重启服务
[root@localhost webapps]# /usr/local/tomcat/bin/catalina.sh stop
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
[root@localhost webapps]# /usr/local/tomcat/bin/catalina.sh start
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@localhost webapps]# ls
docs examples host-manager jenkins jenkins.war manager ROOT #已经自动解压好了
在浏览器访问
[root@localhost webapps]# cat /root/.jenkins/secrets/initialAdminPassword
5101f6b8be304344b6b69cc50c83bbdb ##使用这个文件里的密码登录
- 根据提示安装插件
- 创建一个管理员用户