Linux安装Jenkins、部署并运行springboot项目

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 IntegrationDeploy to container。Maven Integration这个插件用来构建maven项目,Deploy to container用来发布war包到远程机器上
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

7.项目部署

在这里插入图片描述
在这里插入图片描述

![在这里插入图片描述](https://img-blog.csdnimg.cn/2020081720160882.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTI4MTgxODM=,size_16,color_FFFFFF,t_70#pic_center
在这里插入图片描述
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拉去代码打包编译的文件路径

![在这里插入图片描述](https://img-blog.csdnimg.cn/20200818102351305.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTI4MTgxODM=,size_16,color_FFFFFF,t_70#pic_center
到此项目已经运行发布成功!!!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值