💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
1)把在这个目录,编写配置文件 [admin@master files]$ pwd /srv/salt/prod/cluster/files ~~~ [admin@master files]$ sudo vim haproxy_outside_keepalived.conf global_defs { notification_email { test@163.com } notification_email_from keepalived@example.com smtp_server 127.0.0.1 smtp_connect_timeout 30 route_id {{ROUTERID}} } 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.2.11.170 } } ~ ~~~ 2)编写sls ~~~ [admin@master cluster]$ cat 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'] == 'proxy01.test.com' %} - ROUTERID: haproxy_ha - STATEID: MASTER - PRIORITYID: 120 {% elif grains['fqdn'] == 'proxy02.test.com' %} - ROUTERID: haproxy_ha - STATEID: BACKUP - PRIORITYID: 100 {% endif %} service.running: - name: keepalived - enable: True - watch: - file: keepalived-service ~~~ 3)编写top.sls文件 ~~~ [admin@master base]$ sudo vim top.sls base: "*": - init.env_init prod: "proxy01.test.com": - cluster.haproxy-outside - cluster.haproxy-outside-keepalived "proxy02.test.com": - cluster.haproxy-outside - cluster.haproxy-outside-keepalived ~~~ 4)执行状态 [admin@master base]$ sudo salt 'proxy*' state.highstate Summary ------------- Succeeded: 48 (changed=7) Failed: 0 ------------- Total states run: 48 5)查看 [admin@proxy01 ~]$ ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 52:54:00:e7:11:63 brd ff:ff:ff:ff:ff:ff inet 10.2.11.207/24 brd 10.2.11.255 scope global eth0 inet 10.2.11.170/32 scope global eth0 inet6 fe80::5054:ff:fee7:1163/64 scope link valid_lft forever preferred_lft forever 然后我们测试把proxy01的keepalived停掉 [admin@proxy01 ~]$ sudo service keepalived stop Stopping keepalived: [ OK ] 在查看 [admin@proxy02 ~]$ ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 52:54:00:4f:3a:45 brd ff:ff:ff:ff:ff:ff inet 10.2.11.206/24 brd 10.2.11.255 scope global eth0 inet 10.2.11.170/32 scope global eth0 inet6 fe80::5054:ff:fe4f:3a45/64 scope link valid_lft forever preferred_lft forever