This commit is contained in:
ofreax 2015-06-15 21:33:06 +02:00
parent ac8b946967
commit 2df1fb5c42
5 changed files with 24 additions and 18 deletions

View File

@ -6,6 +6,8 @@ MAINTAINER Bertrand Gouny <bertrand.gouny@osixia.net>
# --net=host # --net=host
# -v /lib/modules:/lib/modules # -v /lib/modules:/lib/modules
# sudo docker run --privileged=true --net=host -v /lib/modules:/lib/modules -d osixia/keepalived:0.1.0
# Use baseimage-docker's init system. # Use baseimage-docker's init system.
CMD ["/sbin/my_init"] CMD ["/sbin/my_init"]

View File

@ -1,4 +1,4 @@
KEEPALIVED_INTERFACE: eno1 KEEPALIVED_INTERFACE: wlan0
KEEPALIVED_PASSWORD: d0cker KEEPALIVED_PASSWORD: d0cker
# for electing MASTER, highest priority wins. # for electing MASTER, highest priority wins.
@ -6,10 +6,7 @@ KEEPALIVED_PASSWORD: d0cker
KEEPALIVED_PRIORITY: 150 KEEPALIVED_PRIORITY: 150
KEEPALIVED_UNICAST_PEERS: KEEPALIVED_UNICAST_PEERS:
- 172.17.8.101 - 192.168.1.9
- 172.17.8.102
- 172.17.8.103
KEEPALIVED_VIRTUAL_IPS: KEEPALIVED_VIRTUAL_IPS:
- 192.168.200.17/24 dev eth1 - 192.168.1.230
- 192.168.200.18/24 dev eth2 label eth2:1

View File

@ -1,19 +1,26 @@
vrrp_instance VI_1 { vrrp_instance vip-1 {
interface {{ keepalived_interface }} interface {{ keepalived_interface }}
track_interface {
{{ keepalived_interface }}
}
state MASTER state MASTER
virtual_router_id 51 virtual_router_id 51
priority {{ keepalived_priority }} priority {{ keepalived_priority }}
nopreempt
unicast_peer { unicast_peer {{ keepalived_unicast_peers }}
{{ peer_ip }}
}
virtual_ipaddress { virtual_ipaddress {
{{ floating_ip }} {{ keepalived_virtual_ips }}
} }
authentication { authentication {
auth_type PASS auth_type PASS
auth_pass {{ keepalived_password }} auth_pass {{ keepalived_password }}
} }
debug
} }

View File

@ -28,13 +28,13 @@ if [ ! -e "$FIRST_START_DONE" ]; then
# it's just a peer # it's just a peer
# stored in a variable # stored in a variable
if [ -n "${!peer}" ]; then if [ -n "${!peer}" ]; then
sed -i "s|{{ peer_ip }}|${!peer}\n {{ peer_ip }}|g" /etc/keepalived/keepalived.conf sed -i "s|{{ keepalived_unicast_peers }}|${!peer}\n {{ keepalived_unicast_peers }}|g" /etc/keepalived/keepalived.conf
# directly # directly
else else
sed -i "s|{{ peer_ip }}|${peer}\n {{ peer_ip }}|g" /etc/keepalived/keepalived.conf sed -i "s|{{ keepalived_unicast_peers }}|${peer}\n {{ keepalived_unicast_peers }}|g" /etc/keepalived/keepalived.conf
fi fi
done done
sed -i "/{{ peer_ip }}/d" /etc/keepalived/keepalived.conf sed -i "/{{ keepalived_unicast_peers }}/d" /etc/keepalived/keepalived.conf
# virtual ips # virtual ips
KEEPALIVED_VIRTUAL_IPS=($KEEPALIVED_VIRTUAL_IPS) KEEPALIVED_VIRTUAL_IPS=($KEEPALIVED_VIRTUAL_IPS)
@ -43,13 +43,13 @@ if [ ! -e "$FIRST_START_DONE" ]; then
# it's just a peer # it's just a peer
# stored in a variable # stored in a variable
if [ -n "${!vip}" ]; then if [ -n "${!vip}" ]; then
sed -i "s|{{ floating_ip }}|${!vip}\n {{ floating_ip }}|g" /etc/keepalived/keepalived.conf sed -i "s|{{ keepalived_virtual_ips }}|${!vip}\n {{ keepalived_virtual_ips }}|g" /etc/keepalived/keepalived.conf
# directly # directly
else else
sed -i "s|{{ floating_ip }}|${vip}\n {{ floating_ip }}|g" /etc/keepalived/keepalived.conf sed -i "s|{{ keepalived_virtual_ips }}|${vip}\n {{ keepalived_virtual_ips }}|g" /etc/keepalived/keepalived.conf
fi fi
done done
sed -i "/{{ floating_ip }}/d" /etc/keepalived/keepalived.conf sed -i "/{{ keepalived_virtual_ips }}/d" /etc/keepalived/keepalived.conf
fi fi
fi fi

View File

@ -1,2 +1,2 @@
#!/bin/bash -e #!/bin/bash -e
exec /usr/sbin/keepalived -f /etc/keepalived/keepalived.conf --dont-fork --log-console exec /usr/sbin/keepalived -f /etc/keepalived/keepalived.conf --dont-fork --log-console -D -d