centos7 安装 jenkins

服务器上要安装: gitjdkmaven

方法一

  1. 获取jenkins源文件
wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
  1. 导入jenkins公钥
rpm --import http://pkg.jenkins.io/redhat-stable/jenkins.io.key
  1. yum安装jenkins
yum install -y jenkins
  1. 文件目录说明:
/usr/lib/jenkins/ #jenkins安装目录,WAR包会放在这里。
/etc/sysconfig/jenkins #jenkins配置文件
/var/lib/jenkins/ #默认的JENKINS_HOME。 
/var/log/jenkins/jenkins.log #日志文件

方法二

  1. 安装jdk
    https://blog.csdn.net/qq_36493822/article/details/105731717

  2. 下载 jenkins(选择自己要的版本,赋值链接) wget
    https://pkg.jenkins.io/redhat-stable/

wget https://pkg.jenkins.io/redhat-stable/jenkins-2.204.1-1.1.noarch.rpm

  1. 安装(2选1) sudo rpm -ih
sudo rpm -ih https://pkg.jenkins.io/redhat-stable/jenkins-2.204.1-1.1.noarch.rpm
sudo rpm -ih jenkins-2.204.1-1.1.noarch.rpm

在这里插入图片描述

配置属性

  1. 配置 jdk路径
vim /etc/init.d/jenkins 

  1. 启动 、重启、停止
systemctl start jenkins
service jenkins start
service jenkins restart
service jenkins stop
  1. 出现警告运行:
systemctl daemon-reload
  1. 默认8080端口,修改端口/角色 JENKINS_PORT / JENKINS_USER
vim /etc/sysconfig/jenkins
JENKINS_USER  必须是root
  1. 启动不了
    a、端口被占用,修改端口
    b、第六点
    c、linux 防火墙
    d、服务器安全规则(阿里云不去配置会访问不到_自行百度)
  2. 访问 ip+端口

在这里插入图片描述

  1. 安装插件
    在这里插入图片描述
  2. 等待安装完成,创建用户

在这里插入图片描述

  1. 登陆后配置:系统管理、全局工具配置
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

  2. 新增项目
    在这里插入图片描述

  3. 项目配置
    在这里插入图片描述

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

  1. 脚本
#!/bin/bash

//传入的war包名称
name=$1 	
//war包所在目录							
path=$2
//上传的war包位置				
path_w=$3		
//如果项目正在运行就杀死进程
if [ -f "$path/$name" ];then
	echo "delete the file $name"
	rm -f  $path/$name
else
	echo "the file $name is not exist"
fi
//把jenkins上传的war包拷贝到我们所在目录 
cp $path_w/$name $path/
echo "copy the file $name from $path_w to $path"

//获取该项目正在运行的pid			
pid=$(ps -ef | grep java | grep $name | awk '{print $2}')
echo "pid = $pid"
//如果项目正在运行就杀死进程
if [ $pid ];then
	kill -9 $pid
	echo "kill the process $name pid = $pid"
else
	echo "process is not exist"
fi
//要切换到项目目录下才能在项目目录下生成日志
cd $path
//防止被jenkins杀掉进程 BUILD_ID=dontKillMe
BUILD_ID=dontKillMe
//启动项目
nohup java -server -Xms256m -Xmx512m -jar -Dserver.port=20000 $name >> nohup.out 2>&1 &
//判断项目是否启动成功
pid_new=$(ps -ef | grep java | grep $name | awk '{print $2}')
if [ $? -eq 0 ];then
echo "this application  $name is starting  pid_new = $pid_new"
else 
echo "this application  $name  startup failure"
fi
echo $! > /var/run/myClass.pid
echo "over"

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

//端口号
port=30000
//war包名称
name=$1
//本项目所在的路径
path=$2
//jenkins打包所在的路径
path_w=$3
//线程pid名称
pid_name="${4}.pid"
//该项目运行的pid(用于杀死线程)
pid="$(cat /var/run/"${pid_name}")"

#$(ps -ef | grep java | grep $name | awk '{print $2}')

echo "s1 = $name"
echo "s2 = $path"
echo "s3 = $path_w"
echo "pid = $pid"
//删除项目文件下面已有的war
#rm the war if exist
echo "$path/$name"
if [ -f "$path/$name" ];then
echo "delete the file $name"
rm -f  $path/$name
else
echo "the file $name is not exist"
fi

sleep 1s
//把刚编译的war包复制到项目所在文件夹下
#copy the war 
cp $path_w/$name $path/
echo "copy the file $name from $path_w to $path"
//杀死已有的线程
#shundow the process if exist
if [ $pid ];then
kill -9 $pid
echo "kill the process $name pid = $pid"
else
echo "process is not exist"
fi

sleep 1s
#start the application

#要切换到项目目录下才能在这里生成日志
cd $path
#防止被jenkins杀掉进程
BUILD_ID=dontKillMe
nohup java -server -Xms256m -Xmx512m -jar -Dserver.port=$port $name >> nohup.out 2>&1 &
sleep 1s
//查找新的线程pid
pid_new=$(ps -ef | grep java | grep $name | awk '{print $2}')
//
if [ $? -eq 0 ];then
echo "this application  $name is starting  pid_new = $pid_new and port = $port"
else 
echo "this application  $name  startup failure"
fi

echo $! > /var/run/$pid_name


echo "over"

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值