黑帽联盟

 找回密码
 会员注册
查看: 1269|回复: 0
打印 上一主题 下一主题

[集群服务] saltstack自动化安装编译keepalived

[复制链接]
yun 黑帽联盟官方人员 

920

主题

37

听众

1364

积分

超级版主

Rank: 8Rank: 8

  • TA的每日心情
    奋斗
    2019-10-18 11:20
  • 签到天数: 678 天

    [LV.9]以坛为家II

    环境: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负载均衡 (实战)
    帖子永久地址: 

    黑帽联盟 - 论坛版权1、本主题所有言论和图片纯属会员个人意见,与本论坛立场无关
    2、本站所有主题由该帖子作者发表,该帖子作者与黑帽联盟享有帖子相关版权
    3、其他单位或个人使用、转载或引用本文时必须同时征得该帖子作者和黑帽联盟的同意
    4、帖子作者须承担一切因本文发表而直接或间接导致的民事或刑事法律责任
    5、本帖部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责
    6、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
    7、黑帽联盟管理员和版主有权不事先通知发贴者而删除本文

    您需要登录后才可以回帖 登录 | 会员注册

    发布主题 !fastreply! 收藏帖子 返回列表 搜索
    回顶部