黑帽联盟

标题: saltstack自动化安装编译keepalived [打印本页]

作者: yun    时间: 2019-9-1 11:08
标题: saltstack自动化安装编译keepalived
环境:centos6.7
172.31.225.250 node1.example.com (salt-master运行的地方)
172.31.225.252 node3.example.com (salt-minion运行的地方,keepalived主)
172.31.225.254 node4.example.com (salt-minion运行的地方,keepalived备)

我们所需要用到的相关文件都在 /srv/salt/prod/files/ 这个目录下面,大家直接下载即可: files.zip (993.52 KB, 下载次数: 0)
5.png

master相关配置:(/etc/salt/master)

  1. file_roots:
  2.   base:
  3.     - /srv/salt/base
  4.   dev:
  5.     - /srv/salt/dev
  6.   prod:
  7.     - /srv/salt/prod

  8. pillar_roots:
  9.   base:
  10.     - /srv/salt/base/pillar
  11.   dev:
  12.     - /srv/salt/dev/pillar
  13.   prod:
  14.     - /srv/salt/prod/pillar
复制代码
1、部署keepalived(这里个人是编译安装)
首先下载源码包:
wget https://www.keepalived.org/software/keepalived-2.0.18.tar.gz


初始化安装:(/srv/salt/prod/init/keepalived-init.sls)
  1. pkg-init:
  2.   pkg.installed:
  3.     - names:
  4.       - gcc
  5.       - gcc-c++
  6.       - glibc
  7.       - make
  8.       - autoconf
  9.       - openssl
  10.       - openssl-devel
  11.       - libnl
  12.       - libnl-devel
复制代码

keepalived安装:(/srv/salt/prod/keepalived/keepalived.sls)
  1. include:
  2.   - init.keepalived-init

  3. keepalived-source:
  4.   file.managed:
  5.     - name: /usr/local/src/keepalived-2.0.18.tar.gz
  6.     - source: salt://keepalived/files/keepalived-2.0.18.tar.gz
  7.     - user: root
  8.     - group: root
  9.     - mode: 644
  10.     - unless: test -f /usr/local/src/keepalived-2.0.18.tar.gz

  11. keepalived-install:
  12.   cmd.run:
  13.     - name: cd /usr/local/src && tar xf keepalived-2.0.18.tar.gz && cd keepalived-2.0.18 && ./configure --prefix=/usr/local/keepalived --disable-fwmark && make && make install
  14.     - unless: test -d /usr/local/keepalived
  15.     - require:
  16.       - file: keepalived-source
  17.       - pkg: pkg-init

  18. /etc/sysconfig/keepalived:
  19.   file.managed:
  20.     - source: salt://keepalived/files/keepalived.sysconfig
  21.     - user: root
  22.     - group: root
  23.     - mode: 644

  24. /etc/init.d/keepalived:
  25.   file.managed:
  26.     - source: salt://keepalived/files/keepalived
  27.     - user: root
  28.     - group: root
  29.     - mode: 755

  30. keepalived-chkconfig:
  31.   cmd.run:
  32.     - name: chkconfig --add keepalived
  33.     - unless: chkconfig --list | grep keepalived
  34.     - require:
  35.       - file: /etc/init.d/keepalived

  36. /etc/keepalived:
  37.   file.directory:
  38.     - user: root
  39.     - group: root
  40.     - mode: 755

  41. /etc/keepalived/keepalived.conf:
  42.   file.managed:
  43.     - source: salt://keepalived/files/keepalived.conf
  44.     - user: root
  45.     - group: root
  46.     - mode: 644
  47.     - template: jinja
  48.     {% if grains['fqdn'] == 'node3.example.com' %}
  49.     - ROUTEID: node3
  50.     - STATE: MASTER
  51.     - NETWORK: eth0
  52.     - PRIORITY: 150
  53.     {% elif grains['fqdn'] == 'node4.example.com' %}
  54.     - ROUTEID: node4
  55.     - STATE: BACKUP
  56.     - NETWORK: eth0
  57.     - PRIORITY: 100
  58.     {% endif %}

  59. keepalived-service:
  60.   service.running:
  61.     - name: keepalived
  62.     - enable: True
  63.     - require:
  64.       - file: /etc/init.d/keepalived
  65.     - watch:
  66.       - file: /etc/keepalived/keepalived.conf
复制代码

下面正式安装:
安装之前最好先进行测试安装,检查有没有错误,因为在生产环境下直接执行安装错误,会导致对外服务的相关组件有可能出现问题,所以先进性测试安装
  1. salt '*' state.sls keepalived.keepalived env=prod test=True
复制代码
这里我测试没有问题,就直接安装了
  1. salt '*' state.sls keepalived.keepalived env=prod
复制代码
查看keepalived服务,或者查看vip有没有在机器上(这里自己是在172.31.225.252和172.31.225.254这两台机器上安装的,252为主,254为备)
7.png

8.png


至此就结束了。原创不易,转载请注明原创来处,谢谢!


相关文章:
lvs+nginx负载均衡 (实战)





欢迎光临 黑帽联盟 (https://bbs.cnblackhat.com/) Powered by Discuz! X2.5