1、创建目录:
[root@master_server modules]# mkdir -p keepalived//files && cd keepalived/
2、编辑文件:
[root@master_server keepalived]# cd /srv/salt/prod/modules/
[root@master_server modules]# cd keepalived/
[root@master_server keepalived]# ls
files install.sls
[root@master_server keepalived]# vim install.sls
keepalived-install:
file.managed:
– name: /usr/local/src/keepalived-1.2.17.tar.gz
– source: salt://modules/keepalived/files/keepalived-1.2.17.tar.gz
– mode: 755
– user: root
– group: root
cmd.run:
– name: cd /usr/local/src && tar zxf keepalived-1.2.17.tar.gz && cd keepalived-1.2.17 && ./configure –prefix=/usr/local/keepalived –disable-fwmark && make && make install
– unless: test -d /usr/local/keepalived
– require:
– file: keepalived-install
/etc/sysconfig/keepalived:
file.managed:
– source: salt://modules/keepalived/files/keepalived.sysconfig
– mode: 644
– user: root
– group: root
/etc/init.d/keepalived:
file.managed:
– source: salt://modules/keepalived/files/keepalived.init
– mode: 755
– user: root
– group: root
keepalived-init:
cmd.run:
– name: chkconfig –add keepalived
– unless: chkconfig –list | grep keepalived
– require:
– file: /etc/init.d/keepalived
/etc/keepalived:
file.directory:
– user: root
– group: root
3、修改 完毕后:执行安装
[root@master_server keepalived]# salt ‘*’ state.sls modules.keepalived.install saltenv=prod
查看结果:
4、可以将源码包做成一个名称做成一个变量,这样就可以通用
[root@master_server keepalived]# vim install.sls
做成变量:
{% set keepalived_tar = ‘keepalived-1.2.17.tar.gz’ %}
{% set keepalived_source = ‘salt://modules/keepalived/files/keepalived-1.2.17.tar.gz’ %}
keepalived-install:
file.managed:
– name: /usr/local/src/{{ keepalived_tar }}
– source: {{ keepalived_source }}
– mode: 755
– user: root
– group: root
cmd.run:
– name: cd /usr/local/src && tar zxf {{ keepalived_source }} && cd keepalived-1.2.17 && ./configure –prefix=/usr/local/keepalived –disable-fwmark && make && make install
– unless: test -d /usr/local/keepalived
– require:
– file: keepalived-install
/etc/sysconfig/keepalived:
file.managed:
– source: salt://modules/keepalived/files/keepalived.sysconfig
– mode: 644
– user: root
– group: root
/etc/init.d/keepalived:
file.managed:
– source: salt://modules/keepalived/files/keepalived.init
– mode: 755
– user: root
– group: root
keepalived-init:
cmd.run:
– name: chkconfig –add keepalived
– unless: chkconfig –list | grep keepalived
– require:
– file: /etc/init.d/keepalived
/etc/keepalived:
file.directory:
– user: root
– group: root
执行下,确保无误:
[root@master_server keepalived]# salt ‘*’ state.sls modules.keepalived.install saltenv=prod
5、进入目录,新建文件及上传安装包
/srv/salt/prod/modules/keepalived/
编辑两个配置文件,上传keepalived安装包
[root@master_server files]# ls
keepalived-1.2.17.tar.gz keepalived.init keepalived.sysconfig
6、编辑配置文件,配置haproxy+keepalived.sls,文件内容所在目录
[root@master_server cluster]# vim haproxy-outside-keepalived.sls
[root@master_server cluster]# pwd
/srv/salt/prod/cluster
[root@master_server cluster]#
7、编辑文件内容
[root@master_server cluster]# vim haproxy-outside-keepalived.sls
黄色部分需要改动地方
include:
– modules.keepalived.install
keepalived-server:
file.managed:
– name: /etc/keepalived/keepalived.conf
– source: salt://cluster/files/haproxy-outside-keepalived.conf
– mode: 644
– user: root
– group: root
– template: jinja
{% if grains[‘fqdn’] == ‘master_server’ %}
– ROUTEID: haproxy_ha
– STATEID: MASTER
– PRIORITYID: 150
{% elif grains[‘fqdn’] == ‘master_agent’ %}
– ROUTEID: haproxy_ha
– STATEID: BACKUP
– PRIORITYID: 100
{% endif %}
service.running:
– name: keepalived
– enable: True
– watch:
– file: keepalived-server
8、编辑配置文件内容
[root@master_server files]# pwd
/srv/salt/prod/cluster/files
[root@master_server files]# vim haproxy-outside-keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
saltstack@example.com
}
notification_email_from keepalived@example.com
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 {
192.168.56.20
}
}
9、修改top.sls文件
[root@master_server files]# cd /srv/salt/base/
[root@master_server base]# vim top.sls
10、执行下高级状态:
[root@master_server base]# salt ‘*’ state.highstate
11、查看VIP是否会产生飘移
打赏作者

Leave a Reply

Your email address will not be published.