linux12Devops -->06Jenkins部署tomcat
Posted FikL-09-19
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux12Devops -->06Jenkins部署tomcat相关的知识,希望对你有一定的参考价值。
文章目录
Jenkins部署tomcat
编译环境(Jenkins服务器)
运行环境(web服务器)
1.部署maven编译环境(在Jenkins服务器上部署)
#1.下载maven
[root@jenkins opt]# wget https://mirrors.aliyun.com/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
#2.解压
[root@jenkins opt]# tar -xf apache-maven-3.6.3-bin.tar.gz -C /usr/local/
#3.查看java版本
[root@jenkins opt]# java -version
openjdk version "1.8.0_282"
OpenJDK Runtime Environment (build 1.8.0_282-b08)
OpenJDK 64-Bit Server VM (build 25.282-b08, mixed mode)
#4.添加环境变量
[root@jenkins opt]# vim /etc/profile.d/java.sh
export MAVEN_HOME=/usr/local/apache-maven-3.6.3
export PATH=$MAVEN_HOME/bin:$PATH
#5.重载环境变量,测试mvn
[root@jenkins opt]# source /etc/profile
#6.测试mvn
[root@jenkins opt]# mvn --version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
2.配置Jenkins+maven
- 配置JDK
- 配置maven环境变量
- 安装maven插件
- 创建新项目
- 将源代码上传到仓库(master服务器)
#1.下载远程仓库
[root@k8s-m-01 ~]# mkdir java-tomcat
[root@k8s-m-01 java-tomcat]# git clone git@192.168.15.101:root/java-tomcat.git
#2.将源代码压缩包传到下载的仓库内并解压
[root@k8s-m-01 java-tomcat]# rz -E
rz waiting to receive.
[root@k8s-m-01 java-tomcat]# unzip chenyang0910-springboot-master.zip
[root@k8s-m-01 java-tomcat]# mv springboot/* java-tomcat/
[root@k8s-m-01 ~]# cd jenkins-tomcat/
[root@k8s-m-01 java-tomcat]# ll
total 28
-rwxr-xr-x 1 root root 10070 Apr 15 20:24 mvnw
-rw-r--r-- 1 root root 6608 Apr 15 20:24 mvnw.cmd
-rw-r--r-- 1 root root 1664 Apr 15 20:24 pom.xml
-rw-r--r-- 1 root root 34 Aug 15 23:22 README.md
drwxr-xr-x 4 root root 30 Apr 15 20:24 src
#3.将源代码上传到远程仓库
[root@k8s-m-01 java-tomcat]# git add .
[root@k8s-m-01 java-tomcat]# git commit -m 'init' .
[root@k8s-m-01 java-tomcat]# git push -u origin master
- 创建maven仓库(Jenkins服务器)
#1.创建maven仓库
[root@jenkins ~]# mkdir -pv /data/software/repository
mkdir: 已创建目录 "/data"
mkdir: 已创建目录 "/data/software"
mkdir: 已创建目录 "/data/software/repository"
[root@jenkins ~]# chown jenkins.jenkins /data/software/repository/
#2.修改配置文件
[root@jenkins ~]# vim /usr/local/apache-maven-3.6.3/conf/settings.xml
<settings
<!--本地仓库-->
<localRepository>/data/software/repository</localRepository>
<mirrors>
<!--阿里云镜像-->
<mirror>
<id>aliyun-maven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven mirror</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
</mirrors>
# 下面那个mirrors不写,切记,切记,否则就冲突了
- 测试maven仓库
选择标签开始构建(第一次编译时间稍长)
[root@jenkins ~]# ll /var/lib/jenkins/workspace/jenkins部署tomcat项目/springboot/
总用量 24
-rwxr-xr-x 1 jenkins jenkins 10070 4月 16 13:52 mvnw
-rw-r--r-- 1 jenkins jenkins 6608 4月 16 13:52 mvnw.cmd
-rw-r--r-- 1 jenkins jenkins 1664 4月 16 13:52 pom.xml
drwxr-xr-x 4 jenkins jenkins 30 4月 16 13:52 src
drwxr-xr-x 10 jenkins jenkins 266 4月 16 14:12 target #编译成功后生成的
运行环境
1.安装tomcat
#1.下载
[root@k8s-m-01 ~]# yum install java-1.8.0-openjdk* -y
#2.创建下载tomcat目录
[root@k8s-m-01 ~]# mkdir tomcat
[root@k8s-m-01 tomcat]# wget https://ftp.wayne.edu/apache/tomcat/tomcat-9/v9.0.52/bin/apache-tomcat-9.0.52.tar.gz
#3.解压
[root@k8s-m-01 ~]# tar -xf apache-tomcat-9.0.52.tar.gz -C /usr/local/
#4.软连接
[root@k8s-m-01 ~]# ln -s /usr/local/apache-tomcat-9.0.52/ /usr/local/tomcat
#5.添加环境变量
[root@k8s-m-01 bin]# vim /etc/profile.d/tomcat.sh
export PATH=$PATH:/usr/local/tomcat/bin
[root@k8s-m-01 bin]# source /etc/profile
#6.启动
方式一:
[root@k8s-m-01 ~]# /usr/local/apache-tomcat-9.0.52/bin/startup.sh #启动tomcat
方式二:
[root@k8s-m-01 bin]# pwd #启动tomcat
/usr/local/tomcat/bin
[root@k8s-m-01 bin]# ./startup.sh
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
Using CATALINA_OPTS:
Tomcat started.
#8.验证启动端口
[root@k8s-m-01 ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp6 0 0 :::8080 :::* LISTEN 116492/java
2.配置tomcat权限
[root@k8s-m-01 ~]# vim /usr/local/apache-tomcat-9.0.52/conf/tomcat-users.xml
#插入到倒数第二行
<role rolename="tomcat"/>
<role rolename="role1"/>
<role rolename="manager-script"/>
<role rolename="manager-gui"/>
<role rolename="manager-status"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<user username="tomcat" password="tomcat" roles="manager-gui,manager-script,tomcat,admin-gui,admin-script"/>
[root@k8s-m-01 ~]# vim /usr/local/apache-tomcat-9.0.52/webapps/manager/META-INF/context.xml
#注释掉这段内容
<!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\\.\\d+\\.\\d+\\.\\d+|::1|0:0:0:0:0:0:0:1" /> -->
#重启
[root@k8s-m-01 ~]# /usr/local/apache-tomcat-9.0.52/bin/shutdown.sh
Using CATALINA_BASE: /usr/local/apache-tomcat-9.0.52
Using CATALINA_HOME: /usr/local/apache-tomcat-9.0.52
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-9.0.52/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/apache-tomcat-9.0.52/bin/bootstrap.jar:/usr/local/apache-tomcat-9.0.52/bin/tomcat-juli.jar
Using CATALINA_OPTS:
[root@k8s-m-01 ~]# /usr/local/apache-tomcat-9.0.52/bin/startup.sh
Using CATALINA_BASE: /usr/local/apache-tomcat-9.0.52
Using CATALINA_HOME: /usr/local/apache-tomcat-9.0.52
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-9.0.52/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/apache-tomcat-9.0.52/bin/bootstrap.jar:/usr/local/apache-tomcat-9.0.52/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
[root@k8s-m-01 ~]# cd /usr/local/apache-tomcat-9.0.52/
[root@k8s-m-01 apache-tomcat-9.0.52]# ll
drwxr-x--- 2 root root 4096 Aug 16 00:34 bin
-rw-r----- 1 root root 18949 Jul 31 12:12 BUILDING.txt
drwx------ 3 root root 254 Aug 16 00:42 conf
-rw-r----- 1 root root 6210 Jul 31 12:12 CONTRIBUTING.md
drwxr-x--- 2 root root 4096 Aug 16 00:34 lib
-rw-r----- 1 root root 57092 Jul 31 12:12 LICENSE
drwxr-x--- 2 root root 197 Aug 16 00:36 logs
-rw-r----- 1 root root 2333 Jul 31 12:12 NOTICE
-rw-r----- 1 root root 3372 Jul 31 12:12 README.md
-rw-r----- 1 root root 6898 Jul 31 12:12 RELEASE-NOTES
-rw-r----- 1 root root 16507 Jul 31 12:12 RUNNING.txt
drwxr-x--- 2 root root 30 Aug 16 00:34 temp
drwxr-x--- 7 root root 81 Jul 31 12:12 webapps
drwxr-x--- 3 root root 22 Aug 16 00:36 work
[root@k8s-m-01 apache-tomcat-9.0.52]# cd webapps/
[root@k8s-m-01 webapps]# ll
total 4
drwxr-x--- 15 root root 4096 Aug 16 00:34 docs
drwxr-x--- 7 root root 99 Aug 16 00:34 examples
drwxr-x--- 6 root root 79 Aug 16 00:34 host-manager
drwxr-x--- 6 root root 114 Aug 16 00:34 manager
drwxr-x--- 3 root root 223 Aug 16 00:34 ROOT
3.配置Jenkins操作tomcat
安装插件
配置构建过程===》添加构建后操作
以上是关于linux12Devops -->06Jenkins部署tomcat的主要内容,如果未能解决你的问题,请参考以下文章
linux12Devops -->04Jenkins参数化构建
linux12Devops -->06Jenkins部署tomcat
linux12Devops -->07jenkins部署python