本文用于搭建一个基于haproxy和keepalived的高可用的私有docker registry
部署结构
- haproxy keepalived 主:221.228.86.4
- haproxy keepalived 备:221.228.86.5
- docker registry 1: 221.228.86.6
- docker registry 2: 221.228.86.67
- VIP : 221.228.86.70
1 | 221.228.86.100 |
修改docker daemon 启动参数
1 | 修改/etc/default/docker文件,在DOCKER_OPTS="--insecure-registry vip:5000" |
Docker Registry 配置
- 参考 https://github.com/docker/distribution/blob/master/docs/configuration.md
- 221.228.86.5 221.228.86.67
- 在/var/lib/pri_docker_registry/目录下建立config.yml配置文件,内容如下:
1 | version: 0.1 |
- 在docker registry 1 、2、3上分别执行如下命令
1 | $ mkdir -p /var/lib/registry |
一定要将ceph的配置文件挂载进入容器,rados访问ceph需要
- 配置iptables规则,只允许proxy机器访问
1 | $ iptables -A INPUT -d 221.228.86.67/32 -m comment --comment "not allow to be connected except proxy" -j DROP |
Haproxy 配置
- 参考 https://hub.docker.com/_/haproxy/
- 在haproxy 主备上分别执行下面命令,在/var/lib/hadporxy/目录下建立haproxy.cfg配置文件,内容如下:
1 | global |
创建haproxy-registry容器
1 | $ mkdir -p /var/lib/haproxy |
清除Iptables 规则,目前让所有机器都能访问该proxy
1 | $ iptables -D INPUT -d 221.228.86.5/32 -m comment --comment sigma -j DROP |
Keepalived主备配置
使用Keeplalived管理浮动IP
1 | $ apt-get install keepalived |
Master(221.228.86.4)服务器配置 /etc/keepalived/keepalived.conf
1 | global_defs { |
Backup(221.228.86.6)服务器上的配置 /etc/keepalived/keepalived.conf
1 | global_defs { |
chk_haproxy.sh内容 /usr/local/keepalived/chk_haproxy.sh
1 |
|
启动keepalived服务
1 | $ service keepalived start |