51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

Centos7通过war包部署jenkins(2022版)

在吴昊博客以前也发过多种Jenkins部署方法,由于随着Jenkins官方的不断更新,有些安装步骤已不能适用,以前默认安装插件是慢,现在是极其的慢,所以吴昊决定再写一篇文章,本文使用Centos7系统基于Jenkins2.332.1版本通过war包部署Jenkins

关闭防火墙,关闭selinux,或自行配置防火墙放行!

1、安装jdk11

这里提供两种方法,任选其一

方法一

使用openjdk
yum install java-11-openjdk

|---|-----------------------------| | 1 | yum install java-11-openjdk |

方法二

使用OracleJDK(我这里使用wlnmp源提供的OracleJDK或自行Oracle官方下载)
rpm -ivh https://mirrors.wlnmp.com/centos/wlnmp-release-centos.noarch.rpm yum install jdk-11

|-----|----------------------------------------------------------------------------------------------| | 1 2 | rpm -ivh https://mirrors.wlnmp.com/centos/wlnmp-release-centos.noarch.rpm yum install jdk-11 |

2、下载tomcat
mkdir /data cd /data wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.60/bin/apache-tomcat-9.0.60.tar.gz tar xf apache-tomcat-9.0.60.tar.gz cd apache-tomcat-9.0.60/webapps/ rm -rf ROOT/

|-------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 | mkdir /data cd /data wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.60/bin/apache-tomcat-9.0.60.tar.gz tar xf apache-tomcat-9.0.60.tar.gz cd apache-tomcat-9.0.60/webapps/ rm -rf ROOT/ |

3、下载Jenkins war包
cd /data/apache-tomcat-9.0.60/webapps/ wget https://mirrors.tuna.tsinghua.edu.cn/jenkins/war-stable/2.332.1/jenkins.war mv jenkins.war ROOT.war

|-------|-------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 | cd /data/apache-tomcat-9.0.60/webapps/ wget https://mirrors.tuna.tsinghua.edu.cn/jenkins/war-stable/2.332.1/jenkins.war mv jenkins.war ROOT.war |

4、修改Jenkins默认目录

修改默认的jenkins目录避免后续存储增大,导致撑满根磁盘空间
mkdir /data/jenkins_home echo "export JENKINS_HOME=/data/jenkins_home" >> /etc/profile source /etc/profile

|-------|--------------------------------------------------------------------------------------------------------------| | 1 2 3 | mkdir /data/jenkins_home echo "export JENKINS_HOME=/data/jenkins_home" >> /etc/profile source /etc/profile |

5、安装字体库
yum install fontconfig

|---|------------------------| | 1 | yum install fontconfig |

**注:**如果不安装字体库,启动tomcat后,访问Jenkins会看到以下报错

AWT is not properly configured on this server. Perhaps you need to run your container with "-Djava.awt.headless=true"? See also: https://www.jenkins.io/redirect/troubleshooting/java.awt.headless


6、启动tomcat
/data/apache-tomcat-9.0.60/bin/startup.sh

|---|-------------------------------------------| | 1 | /data/apache-tomcat-9.0.60/bin/startup.sh |

7、访问Jenkins

http://IP:8080

首次访问可能会加载很长时间,这是由于Jenkins访问不通,处于离线状态,等待一段时间后会看到Jenkins引导页面

8、安装Jenkins

不要选择推荐插件安装,由于网络问题会导致安装失败的可能性较大,建议不装任何插件,安装Jenkins完成后,修改镜像源后再进行插件安装。


选择"无"不安装任何插件,点击安装


这里可以直接使用admin用户,默认admin密码在/data/jenkins_home/secrets/initialAdminPassword


保存并完成即可




9、修改镜像源

登录仪表盘后访问:Manage Jenkins→Manage Plugins→Advanced→Update Site

或直接访问:http://jenkins:8080/pluginManager/advanced

将原有地址https://updates.jenkins.io/update-center.json替换为清华源https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json

10、安装Jenkins中文插件

访问:Manage Jenkins→Manage Plugins→Available搜索Chinese


11、修改admin默认密码(可选)

为了方便使用,可以手动更改admin密码,否则每次登录都需要通过/data/jenkins_home/secrets/initialAdminPassword来查看密码

12、反向代理tomcat(可选)
rpm -ivh https://mirrors.wlnmp.com/centos/wlnmp-release-centos.noarch.rpm yum install wnginx

|-----|----------------------------------------------------------------------------------------------| | 1 2 | rpm -ivh https://mirrors.wlnmp.com/centos/wlnmp-release-centos.noarch.rpm yum install wnginx |


vi /usr/local/nginx/conf/vhost/demo.conf server { listen 80; server_name 192.168.0.33; location / { proxy_pass http://127.0.0.1:8080; } }

|-----------------|-------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 8 | vi /usr/local/nginx/conf/vhost/demo.conf server { listen 80; server_name 192.168.0.33; location / { proxy_pass http://127.0.0.1:8080; } } |

重启nginx即可
/etc/init.d/nginx restart

|---|---------------------------| | 1 | /etc/init.d/nginx restart |

赞(0)
未经允许不得转载:工具盒子 » Centos7通过war包部署jenkins(2022版)