================>keepalived的配置檔案
[root@linux-node1 cluster]# cat /srv/salt/prod/cluster/files/haproxy-outside-keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id ` ROUTEID `
}
vrrp_instance haproxy_ha {
state ` STATEID `
interface eth0
virtual_router_id 36
priority ` PRIORITYID `
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.0.11
=========>服務管理子產品
[root@linux-node1 cluster]# cat /srv/salt/prod/cluster/haproxy-outside-keepalives.sls
include:
- keepalived.install
keepalived-service:
file.managed:
- name: /etc/keepalived/keepalived.conf
- source: salt://cluster/files/haproxy-outside-keepalived.conf
- user: root
- group: root
- mode: 644
- template: jinja
{% if grains['fqdn'] == 'linux-node1.example.com' %}
- ROUTEID: haproxy_ha
- STATEID: MASTER
- PRIORITYID: 150
{% elif grains['fqdn'] == 'linux-node2.example.com' %}
- STATEID: BACKUP
- PRIORITYID: 100
{% endif %}
service.running:
- name: keepalived
- enable: True
- watch:
- file: keepalived-service
執行一般狀态:
[root@linux-node1 cluster]# salt '*' state.sls cluster.haproxy-outside-keepalived env=prod
linux-node2.example.com:
.............
Summary
-------------
Succeeded: 15 (changed=2)
Failed: 0
Total states run: 15
linux-node1.example.com:
............
===============top file檔案,供執行進階狀态用
[root@linux-node1 cluster]# cat /srv/salt/base/top.sls
base:
'*':
- init.env_init
prod:
'linux-node1.example.com':
- cluster.haproxy-outside
- cluster.haproxy-outside-keepalived
'linux-node2.example.com':
執行進階狀态:
[root@linux-node1 cluster]# salt '*' state.highstate
................
Succeeded: 29
Total states run: 29
然後通過指令檢視虛拟IP狀态:
[root@linux-node1 cluster]# ip ad li
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:5c:e0:13 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.7/24 brd 10.0.0.255 scope global eth0
inet 10.0.0.11/32 scope global eth0 ===============>此處為虛拟IP
inet6 fe80::20c:29ff:fe5c:e013/64 scope link
valid_lft forever preferred_lft forever
[root@linux-node2 ~]# ip ad li
link/ether 00:0c:29:38:4b:e3 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.8/24 brd 10.0.0.255 scope global eth0
inet6 fe80::20c:29ff:fe38:4be3/64 scope link
停掉linux-node1上面的keepalived服務然後再檢視狀态:
[root@linux-node1 cluster]# /etc/init.d/keepalived stop
停止 keepalived: [确定]
然後再次通過指令檢視虛拟IP狀态:
inet 10.0.0.11/32 scope global eth0 ==================>虛拟IP已漂移到linux-node2上面
valid_lft forever preferred_lft forever
qq:406564728
歡迎交流
本文轉自陳繼松 51CTO部落格,原文連結:http://blog.51cto.com/chenjisong/1714335,如需轉載請自行聯系原作者