標籤:業務引用 keepalived saltstack
================>keepalived的設定檔
[[email protected] cluster]# cat /srv/salt/prod/cluster/files/haproxy-outside-keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
}
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
}
}
=========>服務管理模組
[[email protected] 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‘ %}
- ROUTEID: haproxy_ha
- STATEID: BACKUP
- PRIORITYID: 100
{% endif %}
service.running:
- name: keepalived
- enable: True
- watch:
- file: keepalived-service
執行一般狀態:
[[email protected] 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:
............
Summary
-------------
Succeeded: 15 (changed=2)
Failed: 0
-------------
Total states run: 15
===============top file檔案,供執行進階狀態用
[[email protected] 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‘:
- cluster.haproxy-outside
- cluster.haproxy-outside-keepalived
執行進階狀態:
[[email protected] cluster]# salt ‘*‘ state.highstate
linux-node2.example.com:
................
Summary
-------------
Succeeded: 29
Failed: 0
-------------
Total states run: 29
linux-node1.example.com:
................
Summary
-------------
Succeeded: 29
Failed: 0
-------------
Total states run: 29
然後通過命令查看虛擬IP狀態:
[[email protected] 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
[[email protected] ~]# ip ad li
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
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
valid_lft forever preferred_lft forever
停掉linux-node1上面的keepalived服務然後再查看狀態:
[[email protected] cluster]# /etc/init.d/keepalived stop
停止 keepalived: [確定]
然後再次通過命令查看虛擬IP狀態:
[[email protected] 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
inet6 fe80::20c:29ff:fe5c:e013/64 scope link
valid_lft forever preferred_lft forever
[[email protected] ~]# ip ad li
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
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
inet 10.0.0.11/32 scope global eth0 ==================>虛擬IP已漂移到linux-node2上面
inet6 fe80::20c:29ff:fe38:4be3/64 scope link
valid_lft forever preferred_lft forever
老男孩網址:http://www.etiantian.org
qq:406564728
歡迎交流
本文出自 “linux” 部落格,請務必保留此出處http://chenjisong.blog.51cto.com/7858025/1714335
SaltStack組態管理-業務引用keepalived