centos7上安装Jenkins(war的方式)

1、JAVA环境准备

a、执行yum install -y java-11-openjdk 安装最新版本的JDK

b、执行java -version 验证

2、下载jenkins.war(Jenkins download and deployment)

centos7上安装Jenkins(war的方式)_第1张图片

b、文件上传到centos7的/data/jenkins/目录下

c、编写.sh脚本

#!/bin/bash

 # 导入环境变量
 export JENKINS_HOME=/home/jenkins
 #export JAVA_HOME=/data/soft/jdk1.8.0_181

 cd /data/jenkins/

 pid=`ps -ef | grep jenkins.war | grep -v 'grep'| awk '{print $2}'`
   if [ "$1" = "start" ];then
   if [ -n "$pid" ];then
   echo 'jenkins is running...'
 else
   ### java启动服务 配置java安装根路径,和启动war包存的根路径
   nohup java  -Xms128m -Xmx256m -jar /data/jenkins/jenkins.war --ajp13Port=-1 --httpPort=80 --webroot=/home/jenkins >/dev/null 2>&1 &
   fi
   elif [ "$1" = "stop" ];then
   exec ps -ef | grep jenkins | grep -v grep | awk '{print $2}'| xargs kill -9
   echo 'jenkins is stop...'
 else
   echo "Please input like this:"./jenkins.sh start" or "./jenkins stop""
   fi

d、设置环境变量(vi /etc/profile)

 

使用 source /etc/profile 进行刷新环境变量

e、验证

采用 cd /data/jenkins/目录下

启动:./jenkins.sh start

访问:http:127.0.0.1:80 即可访问

停止:./jenkins.sh stop

即可完成服务停止

3、SystemCtl 托管

a、执行 vi /lib/systemd/system/jenkins.service

[Unit]
Description=Jenkins
After=network.target

[Service]
Type=forking
### jenkins.sh的路径
ExecStart=/data/jenkins/jenkins.sh start
ExecReload=
ExecStop=/data/jenkins/jenkins.sh stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target

b、执行systemctl daemon-reload 刷新配置

c、执行systemctl start jenkins.service 启动

d、执行 systemctl enable jenkins.service 开机启动

e、执行  systemctl restart jenkins.service 进行重启

预览:

centos7上安装Jenkins(war的方式)_第2张图片

 

你可能感兴趣的:(DevOps,jenkins,运维,java)