saltstack 的web平台集群部署(3)---haproxy+keepalive+httpd 的部署

上一篇文章咱们讲到了haproxy的部署与配置

咱们这里说说如何使用keepalive和httpd来实现haproxy+keepalive+httpd  这套web架构的saltstack集群部署

首先咱们 http的部署,很简答哦,直接yum安装就完成了,但是在咱们saltstack就是用installed定义就行了。

ok,让咱们搞起。

[root@test1 http]# pwd
/srv/salt/prod/http
[root@test1 http]# cat install.sls 
include:
  - pkg.pkg-init

httpd-install:
  pkg.installed:
    - names:
      - httpd
      - httpd-devel

是不是很简单,那咱们下边弄它的启动。

[root@test1 cluster]# pwd
/srv/salt/prod/cluster
[root@test1 cluster]# cat http.sls 
include:
  - http.install

http-service:
  file.managed:
    - name: /etc/httpd/conf/httpd.conf
    - source: salt://cluster/files/httpd.conf
    - user: root
    - group: root
    - mode: 644
  service.running:
    - name: httpd
    - enable: True
    - reload: True
    - unless: netstat -lntp |awk -F ':' '{print $4}' | grep 8080

下边咱们弄keepalived的安装文件。

[root@test1 keepalived]# pwd
/srv/salt/prod/keepalived
[root@test1 keepalived]# cat install.sls 
keepalived-install:
  file.managed:
    - name: /usr/local/src/keepalived-1.2.17.tar.gz
    - source: salt://keepalived/files/keepalived-1.2.17.tar.gz
    - mode: 755
    - user: root
    - group: root
  cmd.run:
    - name: cd /usr/local/src && tar zxf keepalived-1.2.17.tar.gz && cd keepalived-1.2.17 && ./configure --prefix=/usr/local/keepalived --disable-fwmark && make && make install
    - unless: test -d /usr/local/keepalived
    - require:
      - file: keepalived-install

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

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

keepalived-init:
  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

不同的人,定义的方式不同,但是实现的效果是一样的。这个配置很简答,就不在这里具体描述了。附件里有安装包。

安装部分完成了,咱们下边就弄启动部分。咱们还是放到cluster目录下边

[root@test1 cluster]# pwd
/srv/salt/prod/cluster
[root@test1 cluster]# cat haproxy-outside-keepalived.sls ##为了区分是haproxy外网的配置
include:
  - keepalived.install
keepalived-server:
  file.managed:
    - name: /etc/keepalived/keepalived.conf
    - source: salt://cluster/files/haproxy-outside-keepalived.conf
    - mode: 644
    - user: root
    - group: root
    - template: jinja
    {% if grains['fqdn'] == 'test1' %}
    - ROUTEID: haproxy_ha
    - STATEID: MASTER
    - PRIORITYID: 150
    {% elif grains['fqdn'] == 'test2' %}
    - ROUTEID: haproxy_ha
    - STATEID: BACKUP
    - PRIORITYID: 100
    {% endif %}
  service.running:
    - name: keepalived
    - enable: True
    - watch:
      - file: keepalived-server

这里咱们简单的说明一下,首先这里使用了jinja模板的方式,用pillar来定义了

下边是keepalived的配置文件

[root@test1 files]# pwd
/srv/salt/prod/cluster/files
[root@test1 files]# cat haproxy-outside-keepalived.conf 
! Configuration File for keepalived
global_defs {
   notification_email {
     [email protected]
   }
   notification_email_from [email protected]
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id {{ROUTEID}}
}

vrrp_instance haproxy_ha {
state {{STATEID}}
interface eth0
    virtual_router_id 36
priority {{PRIORITYID}}
    advert_int 1
authentication {
auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
       10.0.0.11
    }
}

执行salt '*' state.sls cluster.haproxy-outside-keepalived env=prod test=true

spacer.gif

当然最后咱们加到top里边进行定义。那就完成了。对web平台集群的部署。

[root@test1 base]# pwd
/srv/salt/base
[root@test1 base]# cat top.sls 
base:
  '*':
    - init.env_init

prod:
  'test[1,2]':
    - cluster.haproxy-outside-keepalived
    - cluster.haproxy-outside
    - cluster.http
[root@test1 base]# salt '*' state.highstate test=true

spacer.gif


你可能感兴趣的:(keepalived,haproxy,saltstack, ,web平台集群)