1.环境搭建
jdk环境必须大于1.8,jdk下载地址,如果机器存在jdk环境,不需要额外安装
2.tomcat环境安装
tomcat下载地址
2.1 tomcat解压
代码语言:java复制tar -zxvf apache-tomcat-8.5.73.tar.gz
2.2 tomcat修改默认访问路径
代码语言:java复制/home/apache-tomcat-8.5.73/conf/server.xml
# 在host标签中添加一下内容
<Context path="" docBase="/home/apache-tomcat-8.5.73/webapps/jenkins-new" debug="0" reloadable="true"/>
2.3 tomcat的启动和关闭
代码语言:java复制# 启动
sh /home/apache-tomcat-8.5.73/bin/startup.sh
# 关闭
ExecStop=/home/apache-tomcat-8.5.73/bin/shutdown.sh
3. jenkins war下载
jenkins war下载地址
4. 修改jenkins主工作目录
代码语言:java复制echo "JENKINS_HOME=/home/apache-tomcat-8.5.73/work" >> /etc/profile
source /etc/profile
5. 设置jenkins启动的环境
代码语言:shell复制cat > /home/apache-tomcat-8.5.73/bin/setenv.sh <<EOF
#add tomcat pid
CATALINA_PID="/home/apache-tomcat-8.5.73/jenkins.pid"
export JAVA_HOME=/usr/local/jdk1.8.0_65
export JENKINS_HOME=/home/apache-tomcat-8.5.73/work
EOF
6. 托管jenkins给systemctl
代码语言:shell复制cat > /usr/lib/systemd/system/jenkins.service << EOF
[Unit]
Description=tomcat of jenkins
After=syslog.target network.target remote-fs.target nss-lookup.target
# conf service pid, start,stop and restart
[Service]
Type=forking
PIDFile=/home/apache-tomcat-8.5.73/jenkins.pid
ExecStart=/home/apache-tomcat-8.5.73/bin/startup.sh
ExecStop=/home/apache-tomcat-8.5.73/bin/shutdown.sh
ExecReload=/bin/kill -s HUP
PrivateTmp=true
# conf use
[Install]
WantedBy=multi-user.target
EOF
7.systemctl一些使用命令
代码语言:shell复制# 重新加载systemctl
systemctl daemon-reload
# 设置下次开机自动启动
systemctl enable jenkins
# 启动jenkins
systemctl start jenkins
# 停止jenkins
systemctl stop jenkins
# 重启jenkins
systemctl restart jenkins