yun 发表于 2019-9-1 11:08:03

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/ 这个目录下面,大家直接下载即可:


master相关配置:(/etc/salt/master)
file_roots:
  base:
    - /srv/salt/base
  dev:
    - /srv/salt/dev
  prod:
    - /srv/salt/prod

pillar_roots:
  base:
    - /srv/salt/base/pillar
  dev:
    - /srv/salt/dev/pillar
  prod:
    - /srv/salt/prod/pillar1、部署keepalived(这里个人是编译安装)
首先下载源码包:
wget https://www.keepalived.org/software/keepalived-2.0.18.tar.gz


初始化安装:(/srv/salt/prod/init/keepalived-init.sls)pkg-init:
  pkg.installed:
    - names:
      - gcc
      - gcc-c++
      - glibc
      - make
      - autoconf
      - openssl
      - openssl-devel
      - libnl
      - libnl-devel

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

keepalived-source:
  file.managed:
    - name: /usr/local/src/keepalived-2.0.18.tar.gz
    - source: salt://keepalived/files/keepalived-2.0.18.tar.gz
    - user: root
    - group: root
    - mode: 644
    - unless: test -f /usr/local/src/keepalived-2.0.18.tar.gz

keepalived-install:
  cmd.run:
    - 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
    - unless: test -d /usr/local/keepalived
    - require:
      - file: keepalived-source
      - pkg: pkg-init

/etc/sysconfig/keepalived:
  file.managed:
    - source: salt://keepalived/files/keepalived.sysconfig
    - user: root
    - group: root
    - mode: 644

/etc/init.d/keepalived:
  file.managed:
    - source: salt://keepalived/files/keepalived
    - user: root
    - group: root
    - mode: 755

keepalived-chkconfig:
  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
    - mode: 755

/etc/keepalived/keepalived.conf:
  file.managed:
    - source: salt://keepalived/files/keepalived.conf
    - user: root
    - group: root
    - mode: 644
    - template: jinja
    {% if grains['fqdn'] == 'node3.example.com' %}
    - ROUTEID: node3
    - STATE: MASTER
    - NETWORK: eth0
    - PRIORITY: 150
    {% elif grains['fqdn'] == 'node4.example.com' %}
    - ROUTEID: node4
    - STATE: BACKUP
    - NETWORK: eth0
    - PRIORITY: 100
    {% endif %}

keepalived-service:
  service.running:
    - name: keepalived
    - enable: True
    - require:
      - file: /etc/init.d/keepalived
    - watch:
      - file: /etc/keepalived/keepalived.conf

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





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


相关文章:
lvs+nginx负载均衡 (实战)
页: [1]
查看完整版本: saltstack自动化安装编译keepalived