码迷,mamicode.com
首页 > 其他好文 > 详细

saltstack搭建集群2

时间:2017-08-22 00:27:16      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:saltstack

功能模块-----keepalived模块


写之前先找一台主机源码安装测试

http://www.keepalived.org/software/keepalived-1.2.19.tar.gz

[root@node1 tools]# tar xf keepalived-1.2.19.tar.gz

[root@node1 tools]# cd keepalived-1.2.19

[root@node1 keepalived-1.2.19]# ./configure --prefix=/usr/local/keepalived --disable-fwmark

[root@node1 keepalived-1.2.19]# make && make install

keepalived-1.2.19/keepalived/etc/init.d/keepalived.init       #启动脚本

keepalived-1.2.19/keepalived/etc/keepalived/keepalived.conf    #配置文件

 

配置keepalived模块路径及相关文件

[root@node1 ~]# mkdir /srv/salt/prod/keepalived

[root@node1 ~]# mkdir /srv/salt/prod/keepalived/files

[root@node1 keepalived]# cp ~/tools/keepalived-1.2.19.tar.gz /srv/salt/prod/keepalived/

files/

[root@node1 tools]#cp keepalived-1.2.19/keepalived/etc/init.d/keepalived.init /srv/salt/prod/keepalived/files/        #复制启动脚本

[root@node1 tools]#cp keepalived-1.2.19/keepalived/etc/keepalived/keepalived.conf /srv/salt/prod/keepalived/files/           #复制配置文件

[root@node1 tools]# cp keepalived-1.2.19/keepalived/etc/init.d/keepalived.sysconfig /srv/salt/prod/keepalived/files/

[root@node1 tools]# cd /srv/salt/prod/keepalived/files/

[root@node1 files]# vim keepalived.init     #修改启动脚本路径

daemon /usr/local/keepalived/sbin/keepalived ${KEEPALIVED_OPTIONS}


1.keepalived功能模块

[root@node1 keepalived]# cd /srv/salt/prod/keepalived/

[root@node1 keepalived]# cat install.sls

include:

  - pkg.pkg-init

keepalived-install:

  file.managed:

    - name: /usr/local/src/keepalived-1.2.19.tar.gz

    - source: salt://keepalived/files/keepalived-1.2.19.tar.gz

    - user: root

    - group: root

    - mode: 755

  cmd.run:

    - name: cd /usr/local/src/ && tar xf keepalived-1.2.19.tar.gz && cd keepalived-1.2.19 && ./configure --prefix=/usr/local/keepalived --disable-fwmark && make &&make install

    - unless: test -d /usr/local/keepalived

    - require:

      - pkg: pkg-init

      - file: keepalived-install

keepalived-init:

  file.managed:

    - name: /etc/init.d/keepalived

    - source: salt://keepalived/files/keepalived.init

    - user: root

    - group: root

    - mode: 755

  cmd.run:

    - name: chkconfig --add keepalived

    - unless: chkconfig --list |grep keepalived

    - require:

      - file: keepalived-init

/etc/sysconfig/keepalived:

  file.managed:

    - source: salt://keepalived/files/keepalived.sysconfig

    - user: root

    - group: root

    - mode: 644

/etc/keepalived:

  file.directory:

    - user: root

    - group: root

    - mode: 755

 

[root@node1 files]# salt ‘*‘ state.sls keepalived.install env=prod     #手动测试一下


2.keepalived业务模块

[root@node1 ~]# cd /srv/salt/prod/cluster/files/

[root@node1 files]# cat haproxy-outside-keepalived.cfg #keepalived配置文件,里面用到了jinja变量

#configutation file for keepalive

globlal_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 eth2

    virtual_router_id 36

priority {{PRIORITYID}}

    advert_int 1

authentication {

auth_type PASS

    auth_pass 1111

  }

  virtual_ipaddress {

    192.168.10.130

  }

}

 

[root@node1 ~]# cd /srv/salt/prod/cluster/

[root@node1 cluster]# cat haproxy-outside-keepalived.sls

include:

 - keepalived.install

 

keepalived-service:

  file.managed:

    - name: /etc/keepalived/keepalived.conf

    - source: salt://cluster/files/haproxy-outside-keepalived.cfg

    - user: root

    - group: root

    - mode: 644

    - template: jinja

    {% if grains[‘fqdn‘] == ‘node1‘ %}

    - ROUTEID: haproxy_ha

    - STATEID: MASTER

    - PRIORITYID: 150

    {% elif grains[‘fqdn‘] == ‘node2‘ %}

    - ROUTEID: haproxy_ha

    - STATEID: BACKUP

    - PRIORITYID: 100

    {% endif %}

  service.running:

    - name: keepalived

    - enable: True

    - watch:

      - file: keepalived-service

 

 

[root@node1 cluster]# salt ‘*‘ state.sls cluster.haproxy-outside-keepalived env=prod  #测试一下


指定服务器执行keepalived模块

[root@node1 salt]# cat /srv/salt/base/top.sls

base:

  ‘*‘:

    - init.env_init

prod:

  ‘node1‘:

    - cluster.haproxy-outside

    - cluster.haproxy-outside-keepalived

  ‘node2‘:

    - cluster.haproxy-outside

    - cluster.haproxy-outside-keepalived

 

 

[root@node1 salt]# salt ‘*‘ state.highstate    #到这步执行成功的话就实现了keepalived+haproxy

 

遇到问题:发现keepalived 虚拟vip写不上去

查看日志 cat /var/log/messages,发现下面一句

Aug 11 15:10:12 node1 Keepalived_vrrp[29442]: VRRP_Instance(haproxy_ha{) sending 0 priority

haproxy_ha后面打了个空格解决

vrrp_instance haproxy_ha {


本文出自 “feng” 博客,请务必保留此出处http://fengxiaoli.blog.51cto.com/12104465/1958138

saltstack搭建集群2

标签:saltstack

原文地址:http://fengxiaoli.blog.51cto.com/12104465/1958138

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!