1、获取安装文件:
从百度网盘下载:1、jenkins-2.99-1.1.noarch.rpm,2、jdk-8u121-linux-x64.rpm两个文件
2、安装jdk
[root@node1 ~]# rpm -ivh jdk-8u121-linux-x64.rpm
3、安装jenkins
[root@node1 ~]# yrpm -ivh jenkins-2.99-1.1.noarch.rpm
[root@node1 ~]# systemctl start jenkins
[root@node1 ~]# systemctl restart jenkins
[root@node1 ~]# systemctl status jenkins
#service jenkins start
重启
#service jenkins restart
停止
#service jenkins stop
4、Jenkins WEB配置
浏览器中访问:http://你服务器的ip:8080,出现如下图所示界面,根据提示在命令行上复制密码,然后下一步
192.168.19.132:8080
获取密码:
cat /var/lib/jenkins/secrets/initialAdminPassword
先别装插件 直接进入
改密码:
alxk1357924680
列出Jenkins主目录
rpm -ql jenkins
进入主要配置文件
vim /etc/sysconfig/jenkins
JENKINS_USER="root"
查看插件安装
cd /var/lib/jenkins/plugins/
将插件文件复制到该目录下
/usr/local/src/
进行解压
tar xf plugins.tar.gz
进入目录
cd plugins
剪切到插件安装目录
mv * /var/lib/jenkins/plugins/
程序文件所在路径,想升级Jenkins时,直接替换jenkins.war即可
/usr/lib/jenkins/jenkins.war
安装git
yum install -y git
生成key
ssh-keygen -t rsa
取出公钥
cat /root/.ssh/id_rsa.pub
进入项目目录
cd /var/lib/jenkins/workspace/My-freestyle-job # My-freestyle-job:Jenkins创建的项目
# 执行到这里了
mkdir /server/scripts -p
cd /server/scripts
新建.sh脚本文件
vim /server/scripts/deploy.sh
执行脚本文件
sh /server/scripts/deploy.sh
脚本示例
#!/bin/bash
name=web-$(date +%F)-$(($RANDOM+10000))
host=$1
project_name=$2
job_name=$3
service_path=/usr/local/nginx/html
cd /var/lib/jenkins/workspace/${job_name} && tar czf /opt/${name}.tar.gz ./*
ssh ${host} "cd ${service_path} && mkdir ${name}"
scp /opt/${name}.tar.gz ${host}:${service_path}/${name}
ssh ${host} "cd ${service_path}/${name} && tar xf ${name}.tar.gz && rm -f ${name}.tar.gz"
ssh ${host} "cd ${service_path} && rm -rf ${project_name}"
ssh ${host} "cd ${service_path} && mv ${name} ${project_name}"
ssh ${host} "/etc/init.d/uwsgi stop"
ssh ${host} "killall -9 nginx"
ssh ${host} "source ~/${project_name}/bin/activate && cd ${service_path}/${project_name} && python3 man
age.py makemigrations && python3 manage.py migrate"
ssh ${host} "/etc/init.d/uwsgi start"
ssh ${host} "/usr/local/nginx/sbin/nginx"