本文目标:配置jenkins的一主一从( 192.168.117.129 MASTER (jenkins master),192.168.117.130 BACKUP (jenkins master),192.168.117.131 (jenkins slave) )。
部署jenkin
在三台机器上按照jenkins部署文档,部署jenkins。
安装keepalived服务
Jenkins-master
(1)为keepalived开启转发
1 2 3 4
| [root@localhost ~] net.ipv4.ip_forward = 1 net.ipv4.ip_nonlocal_bind = 1 [root@localhost ~]
|
(2)修改keepalived的配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| vim /etc/keepalived/keepalived.conf
vrrp_script chk_apiserver { script "/usr/bin/curl -k http://192.168.117.129:8088 --connect-timeout 3" interval 10 weight -10 fall 3 rise 2 }
vrrp_instance VI_1 { state MASTER interface ens33 virtual_router_id 51 mcast_src_ip 192.168.117.129 priority 101 authentication { auth_type PASS auth_pass gitlab } track_script { chk_apiserver } virtual_ipaddress { 192.168.117.208 } notify_master "/home/jenkins/start.sh" notify_backup "/home/jenkins/stop.sh"
}
|
(3)重启keepalived
1
| systemctl restart keepalived
|
Jenkins-slave按照上述步骤配置keepalived,只需要把其中的ip换成slave机器的ip,priority值要比master小。
安装rsync
安装包下载链接: https://pan.baidu.com/s/1s1nPjzM9w9M8e0V4EqcZog 提取码: gv5w
master-129
(1)安装
(2))创建用户名和密码
1 2
| useradd forjenkins passwd forjenkins 给已创建的用户forjenkins设置密码为pass123
|
(3)修改配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| vim /etc/rsyncd.conf
uid=root
gid=root
max connections=3
use chroot=no
log file=/var/log/rsyncd.log
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock
secrets file=/etc/rsync.pass
hosts allow= *
read only = no
list = no
[forjenkins]
path = /home/jenkins/work
auth users = forjenkins
|
(4)创建认证文件
如果在rsyncd服务中定义了可选配置,则需创建认证文件。
1 2 3
| [root@localhost ~] forjenkins:pass123 chmod 600 /etc/rsync.pass
|
(5)启动Rsyncd服务
1 2
| [root@localhost ~] [root@localhost ~]
|
(6)开启rsyncd服务端口
1 2 3
| [root@localhost ~] [root@localhost ~] [root@localhost ~]
|
master-130 master备节点
(1)安装
(2)创建认证文件
1 2 3
| [root@localhost ~] pass123 chmod 600 /etc/rsync.pass
|
(3)手动测试
(4)自动执行
1 2
| [root@localhost ~] */5 * * * * rsync -avzrtlp --progress --delete --password-file=/etc/rsync.pass forjenkins@192.168.117.129::forjenkins /home/jenkins/work
|
【说明1】每5分钟同步一次。
【说明2】如果出现目录可以同步,文本文件类型的文件不能同步,请检查SELinux是否关闭
1、临时关闭:输入命令setenforce 0,重启系统后还会开启。
2、永久关闭:输入命令vi /etc/selinux/config,将SELINUX=enforcing改为SELINUX=disabled,然后保存退出。