一、搭建环境

1、搭建java环境:可以参考:

https://blog.csdn.net/lxw983520/article/details/78998934

2、搭建jenkins环境:可以参考(使用rpm安装,也可以直接下载war包):

https://blog.csdn.net/lxw983520/article/details/78903419

二、下载tomcat

1、下载一个tomcat并进行解压在不同的位置,例如:第一个tomcat的位置:/usr/local/tomcat,第二个tomcat的位置:/opt/tomcat 
2、分别配置两个tomcat:配置环境变量的操作

vim /etc/profile

进入该文件后添加:

####第一个Tomcat####
export CATALINA_BASE=/opt/tomcat/
export CATALINA_HOME=/opt/tomcat
export TOMCAT_HOME=/opt/tomcat
###第二个Tomcat--jenkins####
export CATALINA_2_BASE=/usr/local/tomcat
export CATALINA_2_HOME=/usr/local/tomcat
export TOMCAT_2_HOME=/usr/local/tomcat

保存后进行生效

source /etc/profile

3、在第二个tomcat下的catalina.sh和server.xml进行配置

vim /usr/local/tomcat/bin/catalina.sh

1)进入编辑,找到#OS开头的段落,后面添加代码

# OS specific support.  $var _must_ be set to either true or false.
export CATALINA_BASE=$CATALINA_2_BASE
export CATALINA_HOME=$CATALINA_2_HOME
vim /usr/local/tomcat/conf/server.xml

2)进入编辑:更改端口号8089以及监听端口8009、9009(这个要和第一个不同,否则也不可以同时运行)

 <Connector port="8089" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
port="8089" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
-->
.....
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="9009" protocol="AJP/1.3" redirectPort="8443" />
.....
<!-- Use the LockOutRealm to prevent attempts to guess user passwords
v
<Realm className="org.apache.catalina.n AJP 1.3 Connector on port 8009 -->
<Connector port="9009" protocol="AJP/1.3" redirectPort="8443" />realm.LockOutRealm">

三、配置开机启动 
1)文件配置:一开始是没有tomcat.service这些文件的

####配置第一个######
cd /usr/lib/systemd/system/
vim tomcat.service
###第一个文件下的文本:
[Unit]
Description=Tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target [Service]
Type=forking
Environment='JAVA_HOME=/usr/local/jdk1.8'
Environment='CATALINA_PID=/usr/local/tomcat/bin/tomcat.pid'
Environment='CATALINA_HOME=/usr/local/tomcat/'
Environment='CATALINA_BASE=/usr/ local/tomcat/'
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC' WorkingDirectory=/usr/ local/tomcat/ ExecStart=/usr/local/tomcat/bin/startup.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true [Install]
WantedBy=multi-user.target ####配置第二个######
cd /usr/lib/systemd/system/
vim tomcat2.service
##第二个下的文本
[Unit]
Description=Tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target [Service]
Type=forking
Environment='JAVA_HOME=/usr/local/jdk1.8'
Environment='CATALINA_PID=/opt/tomcat/bin/tomcat.pid'
Environment='CATALINA_HOME=/opt/tomcat/'
Environment='CATALINA_BASE=/opt/tomcat/'
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC' WorkingDirectory=/opt/tomcat/ ExecStart=/usr/local/tomcat/bin/startup.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true [Install]
WantedBy=multi-user.target

2)设置为开启机启动:

systemctl  enable  tomcat.service
systemctl restart tomcat.service
systemctl enable tomcat2.service
systemctl restart tomca2t.service

3)添加启动:在rc.local文件中添加tomcat的startup.sh的路径

vim /etc/rc.d/rc.local

添加如下语句:主要是tomcat启动文件的路径

 /usr/local/tomcat/bin/startup.sh
/opt/tomcat/bin/startup.sh

使文件生效

source /etc/rc.d/rc.local

如果无法成功,将rc.local文件的权限改为755:

chmod 755 /etc/rc.d/rc.local
05-11 15:05