SaltStack配置管理-业务引用keepalived

================>keepalived的配置文件

[root@linux-node1 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

    }

}


=========>服务管理模块

[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' %}

    - ROUTEID: haproxy_ha

    - 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:

............

Summary

-------------

Succeeded: 15 (changed=2)

Failed:     0

-------------

Total states run:     15




===============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':

    - cluster.haproxy-outside

    - cluster.haproxy-outside-keepalived


执行高级状态:

[root@linux-node1 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状态:

[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

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服务然后再查看状态:

[root@linux-node1 cluster]# /etc/init.d/keepalived stop

停止 keepalived:                                          [确定]

然后再次通过命令查看虚拟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

    inet6 fe80::20c:29ff:fe5c:e013/64 scope link 

       valid_lft forever preferred_lft forever


[root@linux-node2 ~]# 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

欢迎交流

你可能感兴趣的:(keepalived,saltstack, , ,业务引用)