Two series:
To deploy the keepalived total directory structure
[[email protected] salt]# tree /srv/salt//srv/salt/├── base│ ├── init│ │ ├── audit.sls│ │ ├── dns.sls│ │ ├── env_init.sls│ │ ├── epel.sls│ │ ├── files│ │ │ └── resolv.conf│ │ ├── history.sls│ │ └── sysctl.sls│ └── top.sls└── prod ├── cluster │ ├── files │ │ ├── haproxy-outside.cfg │ │ ├── haproxy-outside.cfg.bak │ │ └── haproxy-outside-keepalived.conf │ ├── haproxy-outside-keepalived.sls │ └── haproxy-outside.sls ├── haproxy │ ├── files │ │ ├── haproxy-1.4.24.tar.gz │ │ └── haproxy.init │ └── install.sls ├── keepalived │ ├── files │ │ ├── keepalived-1.1.19.tar.gz │ │ ├── keepalived.init │ │ └── keepalived.sysconfig │ └── install.sls └── pkg ├── create-haproxy.sls ├── Keepalived-init.sls └── pkg-init.sls
1. Package Management
CD/USR/LOCAL/SRCCP Keepalived-1.1.19.tar.gz/srv/salt/prod/keepalived/filestar XF KEEPALIVED-1.1.19.TAR.GZCD Keepalived-1.1.19/keepalived/etc/init.d/keepalived.init/srv/salt/prod/keepalived/files CP keepalived-1.1.19/ Keepalived/etc/init.d/keepalived.sysconfig/srv/salt/prod/keepalived/files
Because the default installation of Keepalived is under the/usr/local/keepalived directory, manually modify the init script in the source package:
Daemon keepalived ${keepalived_options}
Modified to:
Daemon/usr/local/keepalived/sbin/keepalived ${keepalived_options}
2. Write keepalived Install SLS
2.1. Installing dependent Packages
[Email protected] pkg]# Cat/srv/salt/prod/pkg/keepalived-init.sls keepalived-init:pkg.installed:-Names:-Ke Rnel-devel-popt-devel
The installation of 2.2.Keepalived is as follows:
[[Email protected] keepalived]# cat /srv/salt/prod/keepalived/install.sls include: - pkg.keepalived-initkeepalived_install: file.managed: - name: /usr/local/src/keepalived-1.1.19.tar.gz - source: salt:// keepalived/files/keepalived-1.1.19.tar.gz - user: root - group: root - mode: 755 cmd.run: - name: mkdir -p /var/log/keepalived && cd /usr/local/ src && tar xf keepalived-1.1.19.tar.gz && cd Keepalived-1.1.19 && ./configure --prefix=/usr/local/keepalived --disable-fwmark && make && make install - unless: test -d /usr/local/keepalived &Nbsp; - require: - file: keepalived_ installkeepalived_sysconfig: file.managed: - name: /etc/sysconfig/ keepalived - source: salt://keepalived/files/keepalived.sysconfig - mode: 644 - user: root - Group: root
keepalived-rsyslogs: file.append: - name: /etc/rsyslog.conf - text: - local0.* /var/log/ keepalived/keepalived.log cmd.run: - name: /etc/init.d/ rsyslog restartkeepalived_init.d: file.managed: - name: /etc/ init.d/keepalived - source: salt://keepalived/files/keepalived.init - mode: 744 - user: root - group: rootkeepalived_init: cmd.run: - name: chkconfig --add keepalived - unless: chkconfig --list|grep keepalived - require: - file: /etc/ init.d/keepalived# another way of writing/etc/keepalived: file.directory: - user: root - group: root
2.3.Keepalived Business Reference: [keepalived Profile and service management]
Note: keepalived is the main backup node, some configurations are different, so you need to use the Jinja template to complete the configuration file management, here I used the Jinja judgment function, through grains to get the Minion side ID name to set the different ID name of the unused variable.
[[Email protected] cluster]# cat /srv/salt/prod/cluster/haproxy-outside-keepalived.sls include: - keepalived.installkeepalived-server: 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[' id '] == ' Jenkins.saltstack.me ' %} ROUTEID: haproxy_ha STATEID: MASTER PRIORITYID: 150 {% elif grains[' id '] == ' gitlab.saltstack.me ' %} routeid: hapRoxy_ha stateid: backup priorityid: 100 {% endif %} service.running: - name: keepalived - enable: True - watch: - file: keepalived-server
2.4. Perform keepalived status
[[email protected] base]# cat /srv/salt/base/top.sls base: ' * ': - init.env_initprod: ' * ': - cluster.haproxy-outside - cluster.haproxy-outside-keepalived2.5. Last Note: [Email protected] files]# cat keepalived.sysconfig# Options for keepalived. see ' Keepalived --help ' output and keepalived (8) and# keepalived.conf (5) man pages for a list of all options. here are the most# common ones :## --vrrp -p only run with vrrp subsystem .# --check -c only run with health-checker subsystem.# --dont-release-vrrp -v dont remove vrrp vips & vroutes on daemon stop.# -- dont-release-ipvs -i dont remove ipvs topology on daemon stop.# --dump-conf -d Dump the configuration data.# --log-detail -D Detailed log messages.# --log-facility -s 0-7 set local syslog facility (default=log_daemon) # #KEEPALIVED_OPTIONS = "-D" keepalived_options= "-d -d -s 0" #keepalived日志的配置.
Keepalived-rsyslogs:file.append:-Name:/etc/rsyslog.conf-text:-local0.*/var/log/keepalived/keepalive D.log # #keepalived日志配置
This article is from the "Randolph" blog, make sure to keep this source http://randolph.blog.51cto.com/10900500/1912120
Saltstack Automatic Deployment haproxy+keepalived+nginx+memcache+php (fastcgi)