本文目标:配置gitlab一主二从(master 192.168.117.129,slave 192.168.117.130,192.168.117.131),其中gitlab-master外挂一主两从的数据库postgresql,gitlab-slave130挂载postgresql-130,gitlab-slave131挂载postgresql-131。
在三台机器上部署gitlab
下载安装包链接: https://pan.baidu.com/s/1geCvvWl54kp_5AJ6O8bJ3w 提取码: tser
其中gitlab-ce-zh110104.tar为gitlab-11.1.4,gitlab-ce-zh100604.tar为gitlab-10.6.4
(1)将安装包上传到/home目录,并加载镜像
1 2
| docker load -i gitlab-ce-zh110104.tar vim /home/gitlab/docker-compose.yml
|
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
| version: '2' services: gitlab: image: 'twang2218/gitlab-ce-zh:11.1.4' restart: unless-stopped hostname: '192.168.117.129' environment: TZ: 'Asia/Shanghai' GITLAB_OMNIBUS_CONFIG: | external_url 'http://192.168.117.129' gitlab_rails['time_zone'] = 'Asia/Shanghai' gitlab_rails['gitlab_shell_ssh_port'] = 54322 postgresql['enable'] = false gitlab_rails['db_adapter'] = "postgresql" gitlab_rails['db_encoding'] = "utf8" gitlab_rails['db_database'] = "gitlabtest" gitlab_rails['db_username'] = "postgres" gitlab_rails['db_password'] = "postgres" gitlab_rails['db_host'] = "192.168.117.129" gitlab_rails['db_port'] = 5432 ports: - '8080:80' - '843:443' - '54322:22' volumes: - '/data/gitlab/config:/etc/gitlab' - '/data/gitlab/logs:/var/log/gitlab' - '/data/gitlab/config/gitlab/data:/var/opt/gitlab'
|
注意:上述postgresql挂载分别为三台机器上各自的postgresql
安装keepalived服务
Gitlab-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
| vim /etc/keepalived/keepalived.conf
vrrp_script chk_gitlab{ script "/etc/keepalived/check-gitlab.sh" interval 2 } vrrp_instance VI_1 { state MASTER interface ens33 virtual_router_id 51 priority 101 authentication { auth_type PASS auth_pass gitlab } track_script { chk_gitlab } virtual_ipaddress { 192.168.117.208 } }
|
(3)创建检测脚本
1 2 3 4 5 6 7
| #!/bin/bash
return_code=`curl -s -w "%{http_code}" -o /dev/null http://192.168.117.129`
if [[ $return_code -ne 200 ]]; then systemctl stop keepalived fi
|
(4)重启keepalived
1
| systemctl restart keepalived
|
Gitlab-slave按照上述步骤配置keepalived,只需要把其中的ip换成slave机器的ip,priority值要比master小。
安装Rsyncd服务
安装包下载链接: https://pan.baidu.com/s/1s1nPjzM9w9M8e0V4EqcZog 提取码: gv5w
master-129
(1)安装
(2))创建用户名和密码
1 2
| useradd forgitlab 创建用户forgitlab passwd forgitlab 给已创建的用户forgitlab设置密码为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
[forgitlab]
path = /data/gitlab/data/git-data
auth users = forgitlab
|
(4)创建认证文件
如果在rsyncd服务中定义了可选配置,则需创建认证文件。
1 2 3
| [root@localhost ~] forgitlab: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 ~]
|
slave-130 master备节点
(1)安装
(2)创建认证文件
1 2 3 4 5 6
| [root@localhost ~] pass123 chmod 600 /etc/rsync.pass (3)手动测试 ``` bash [root@localhost ~]
|
(4)自动执行
1 2
| [root@localhost ~] */5 * * * * rsync -avzrtlp --progress --delete --password-file=/etc/rsync.pass forgitlab@192.168.117.129::forgitlab /data/gitlab/data/git-data
|
【说明1】每5分钟同步一次。
【说明2】如果出现目录可以同步,文本文件类型的文件不能同步,请检查SELinux是否关闭
1、临时关闭:输入命令setenforce 0,重启系统后还会开启。
2、永久关闭:输入命令vi /etc/selinux/config,将SELINUX=enforcing改为SELINUX=disabled,然后保存退出。