SaltStack組態管理-業務引用keepalived

來源:互聯網
上載者:User

標籤:業務引用   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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.