Jenkins环境安装与下载
1.下载
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
If you’ve previously imported the key from Jenkins, the rpm --import will fail because you already have a key. Please ignore that and move on.
[download]# yum install -y jenkins
Repository epel is listed more than once in the configuration
Jenkins-stable 424 B/s | 2.9 kB 00:07
Dependencies resolved.
=================================================================================================================================================================================================================================================
Package Architecture Version Repository Size
=================================================================================================================================================================================================================================================
Installing:
jenkins noarch 2.235.4-1.1 jenkins 63 M
Transaction Summary
=================================================================================================================================================================================================================================================
Install 1 Package
Total download size: 63 M
Installed size: 63 M
Downloading Packages:
[MIRROR] jenkins-2.235.4-1.1.noarch.rpm: Curl error (60): Peer certificate cannot be authenticated with given CA certificates for https://ftp.yz.yamagata-u.ac.jp/pub/misc/jenkins/redhat-stable/jenkins-2.235.4-1.1.noarch.rpm [SSL certificate problem: unable to get local issuer certificate]
[FAILED] jenkins-2.235.4-1.1.noarch.rpm: No more mirrors to try - All mirrors were already tried without success
The downloaded packages were saved in cache until the next successful transaction.
You can remove cached packages by executing 'dnf clean packages'.
Error: Error downloading packages:
Cannot download jenkins-2.235.4-1.1.noarch.rpm: All mirrors were tried
如:下载失败需要使用安装包下载
下载地址:Jenkins下载
rpm -ih jenkins-****.noarch.rpm
下载安装后相对于目录
/usr/lib/jenkins/jenkins.war WAR包
/etc/sysconfig/jenkins 配置文件
/var/lib/jenkins/ 默认的JENKINS_HOME目录
/var/log/jenkins/jenkins.log Jenkins日志文件
2.运行
service jenkins start
Starting jenkins (via systemctl): [ OK ]
3.配置修改:端口
vi /etc/sysconfig/jenkins
JENKINS_PORT="8091"
JENKINS_ARGS="--prefix=/jenkins"
Nginx反向代理配置
location /jenkins
{
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_pass http://localhost:8091;
}
4.安装完成
剩下的按照提示推荐,密码点击安装即可
5.配置Jenkins
6.插件安装
Maven Integration和Deploy to container。Maven Integration这个插件用来构建maven项目,Deploy to container用来发布war包到远程机器上
7.项目部署
Build中输入打包前的mvn命令
clean install -Dmaven.test.skip=true -Ptest
cp /var/lib/jenkins/workspace/**/target/***.jar /home/java/webapps
PID=$(ps -ef | grep zh-web-managment.jar | grep -v grep | awk '{ print $2 }')
if [ -z "$PID" ]
then
echo Application is already stopped
else
echo kill $PID
kill $PID
fi
BUILD_ID=DONTKILLME
cd /home/java/webapps
nohup java -jar -Xmx2048m -Xms2048m -Xmn1024m -Xss512k **.jar --spring.profiles.active=prod >/dev/null 2>&1 &
sleep 20
8.配置完成项目立即构建
这里看到Jenkins拉去代码打包编译的文件路径
到此项目已经运行发布成功!!!