Hi 你好,欢迎访问!登录
当前位置:首页 - 自动化运维 - 正文 忍人所不忍,能人所不能。

Linux自动化工具之SaltStack 实战项目5(功能引用_keepalived)

2020-03-05自动化运维90root176°c
A+ A-

1.编写keepalived业务配置文件

[[email protected] ~]# cd /etc/salt/states/cluster/files/
[[email protected] files]# vim 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 
    route_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 { 
       192.168.15.100       #VIP.注意和haproxy-outside.cfg里vip相同 
    } 
}

2.编写keepalived sls文件

[[email protected] ~]# cd /etc/salt/states/cluster/ 
[[email protected] cluster]# vim haproxy-outside-keepalived.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'] == 'node2.90root.com' %} 
    - ROUTEID: haproxy_ha 
    - STATEID: MASTER 
    - PRIORITYID: 150 
    {% elif grains['fqdn'] == 'node3.90root.com' %} 
    - ROUTEID: haproxy_ha 
    - STATEID: BACKUP 
    - PRIORITYID: 100 
    {% endif %} 
  service.running: 
    - name: keepalived 
    - enable: True 
    - watch: 
      - file: keepalived-service

3.top.sls引入cluster/haproxy-outside-keepalived.sls文件

[[email protected] ~]# cd /etc/salt/states/ 
[[email protected] states]# vim top.sls  
base: 
  '*': 
    - init.env_init 
    - haproxy.install 
    - cluster.haproxy-outside 
    - keepalived.install                    #删除 
    - cluster.haproxy-outside-keepalived    #新增 
(PS:为何删除keepalived.install, 因为在haproxy-outside-keepalived已引入该keepalived.install)

4. 执行salt命令

[[email protected] cluster]# salt '*' state.highstate 
(ps: Failed为0即可,表示无报错)

Linux自动化工具之SaltStack 实战项目5(功能引用 keepalived) SaltStack Linux 自动化运维 第1张

5.keepalived vip验证

[[email protected] ~]# ip a

Linux自动化工具之SaltStack 实战项目5(功能引用 keepalived) SaltStack Linux 自动化运维 第2张

[[email protected] ~]# ip a

Linux自动化工具之SaltStack 实战项目5(功能引用 keepalived) SaltStack Linux 自动化运维 第3张

6.下图为浏览器访问VIP图片 

Linux自动化工具之SaltStack 实战项目5(功能引用 keepalived) SaltStack Linux 自动化运维 第4张

7.下图为haproxy监控信息

Linux自动化工具之SaltStack 实战项目5(功能引用 keepalived) SaltStack Linux 自动化运维 第5张

关于VIP切换, 笔者已测试通过. 详细图片不截图了.

  移步手机端
Linux自动化工具之SaltStack 实战项目5(功能引用_keepalived)

1、打开你手机的二维码扫描APP
2、扫描左则的二维码
3、点击扫描获得的网址
4、可以在手机端阅读此文章
标签:

发表评论

选填

必填

必填

选填

请拖动滑块解锁
>>


  用户登录