saltstack自动化运维一键部署haproxy负载均衡

配置环境:
hostname | ip | 节点| 部署服务|os

  • | :-: | -:
    server1|172.25.12.1|salt-manster salt-minion|haproxy| rhel6.5
    server2|172.25.12.2|salt-minion|httpd |rhel6.5
    server3|172.25.12.3|salt-minion | nginx|rhel6.5

一、编写haproxy的安装服务模块

[root@server1 salt]# mkdir haproxy
[root@server1 salt]# cd haproxy/
[root@server1 haproxy]# vim install.sls
[root@server1 haproxy]# cat install.sls 
haproxy-install:
  pkg.installed:
    - pkgs:
      - haproxy
  file.managed:
    - name: /etc/haproxy/haproxy.cfg
    - source: salt://haproxy/files/haproxy.cfg

  service.running:
    - name: haproxy
    - reload: ture
    - watch:
      - file: haproxy-install
[root@server1 haproxy]# mkdir files
[root@server1 haproxy]# cd files.
[root@server1 files]# ls
haproxy.cfg
[root@server1 files]# cat haproxy.cfg 
#---------------------------------------------------------------------
# Example configuration for a possible web application.  See the
# full configuration options online.
#
#   http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------

#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
    # to have these messages end up in /var/log/haproxy.log you will
    # need to:
    #
    # 1) configure syslog to accept network log events.  This is done
    #    by adding the '-r' option to the SYSLOGD_OPTIONS in
    #    /etc/sysconfig/syslog
    #
    # 2) configure local2 events to go to the /var/log/haproxy.log
    #   file. A line like the following can be added to
    #   /etc/sysconfig/syslog
    #
    #    local2.*                       /var/log/haproxy.log
    #
    log         127.0.0.1 local2

    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon

    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000

#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend  main *:80
    #acl url_static       path_beg       -i /static /images /javascript /stylesheets
    #acl url_static       path_end       -i .jpg .gif .png .css .js

    #use_backend static          if url_static
    default_backend             app

backend app
    balance     roundrobin
    server  app1 172.25.12.2:80 check
    server  app2 172.25.12.3:80 check

2、编写全局推送文件,一键推送所有节点

[root@server1 salt]# pwd
/srv/salt
[root@server1 salt]# ls
haproxy  httpd  nginx  pkgs  top.sls  users
[root@server1 salt]# cat top.sls 
base:
  'server1':
    - haproxy.install
  'server2':
    - httpd.service
  'server3':
    - nginx.service

httpd和nginx的自动化部署可查看上一篇https://blog.csdn.net/weixin_41789003/article/details/81107111

3、一键高级推送所有节点

[root@server1 salt]# salt '*' state.highstate
server3:
----------
          ID: nginx-make
    Function: pkg.installed
      Result: True
     Comment: All specified packages are already installed
     Started: 15:06:20.461271
    Duration: 431.393 ms
     Changes:   
----------
          ID: nginx-install
    Function: file.managed
        Name: /mnt/nginx-1.12.0.tar.gz
      Result: True
     Comment: File /mnt/nginx-1.12.0.tar.gz is in the correct state
     Started: 15:06:20.894364
    Duration: 97.767 ms
     Changes:   
----------
          ID: nginx-install
    Function: cmd.run
        Name: cd /mnt && tar zxf nginx-1.12.0.tar.gz && cd nginx-1.12.0 && sed -i.bak 's/CFLAGS="$CFLAGS -g"/#CFLAGS="$CFLAGS -g"/g' auto/cc/gcc && sed -i.bak 's/#define NGINX_VER          "nginx\/" NGINX_VERSION/#define NGINX_VER          "nginx"/g' src/core/nginx.h && ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-threads --with-file-aio &> /dev/null && make > /dev/null && make install > /dev/null
      Result: True
     Comment: /usr/local/nginx exists
     Started: 15:06:20.992845
    Duration: 0.395 ms
     Changes:   
----------
          ID: nginx-group
    Function: group.present
        Name: nginx
      Result: True
     Comment: Group nginx is present and up to date
     Started: 15:06:20.993548
    Duration: 0.337 ms
     Changes:   
----------
          ID: nginx-user
    Function: user.present
        Name: nginx
      Result: True
     Comment: User nginx is present and up to date
     Started: 15:06:20.994394
    Duration: 1.203 ms
     Changes:   
----------
          ID: /usr/local/nginx/conf/nginx.conf
    Function: file.managed
      Result: True
     Comment: File /usr/local/nginx/conf/nginx.conf is in the correct state
     Started: 15:06:20.995740
    Duration: 54.552 ms
     Changes:   
----------
          ID: nginx-service
    Function: file.managed
        Name: /etc/init.d/nginx
      Result: True
     Comment: File /etc/init.d/nginx is in the correct state
     Started: 15:06:21.050428
    Duration: 33.289 ms
     Changes:   
----------
          ID: nginx-service
    Function: service.running
        Name: nginx
      Result: True
     Comment: The service nginx is already running
     Started: 15:06:21.085242
    Duration: 42.04 ms
     Changes:   

Summary for server3
------------
Succeeded: 8
Failed:    0
------------
Total states run:     8
Total run time: 660.976 ms
server2:
----------
          ID: apache-install
    Function: pkg.installed
      Result: True
     Comment: All specified packages are already installed
     Started: 15:06:19.797543
    Duration: 1357.509 ms
     Changes:   
----------
          ID: apache-config
    Function: file.managed
        Name: /etc/httpd/conf/httpd.conf
      Result: True
     Comment: File /etc/httpd/conf/httpd.conf is in the correct state
     Started: 15:06:21.178843
    Duration: 116.952 ms
     Changes:   
----------
          ID: apache-service
    Function: service.running
        Name: httpd
      Result: True
     Comment: The service httpd is already running
     Started: 15:06:21.296877
    Duration: 81.54 ms
     Changes:   

Summary for server2
------------
Succeeded: 3
Failed:    0
------------
Total states run:     3
Total run time:   1.556 s
server1:
----------
          ID: haproxy-install
    Function: pkg.installed
      Result: True
     Comment: All specified packages are already installed
     Started: 15:06:20.129688
    Duration: 1576.999 ms
     Changes:   
----------
          ID: haproxy-install
    Function: file.managed
        Name: /etc/haproxy/haproxy.cfg
      Result: True
     Comment: File /etc/haproxy/haproxy.cfg is in the correct state
     Started: 15:06:21.753298
    Duration: 79.789 ms
     Changes:   
----------
          ID: haproxy-install
    Function: service.running
        Name: haproxy
      Result: True
     Comment: Started Service haproxy
     Started: 15:06:21.834092
    Duration: 179.49 ms
     Changes:   
              ----------
              haproxy:
                  True

Summary for server1
------------
Succeeded: 3 (changed=1)
Failed:    0
------------
Total states run:     3
Total run time:   1.836 s
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
openstack一键安装(含安装包、自制工具)支持centos6.5最小化安装 本资源分为3部分下载: 【1】openstack一键安装(1) 【2】openstack一键安装(2) 【3】openstack一键安装(3) 注意:下载完整后,请放在同一目录下解压 ==================================================== | 安装说明 | ==================================================== 注意:以下路径不能随意更改,一定要按照以下顺序进行安装 1.把openstack-cloud文件夹用SSHSecureShellClient工具上传到服务器的/usr目录下并且设置权限: chmod 777 -R /usr/openstack-cloud/ 基本配置: (1)配好主机ip重启网络 (2)更改/usr/openstack-cloud/目录下的五个的文件参数,文件分别有: =============================================================== | glance.sh httpd.conf keystone.sh nova.conf nova-user.sh | =============================================================== 将所有有关IP:192.168.1.2全部替换成服务器的IP 2.一键yum(会把原来自带yum备份到/etc/yum.repos.d/bak下): ./usr/openstack-cloud/yum.sh 3.一键安装openstack: ./usr/openstack-cloud/install-openstack.sh _________________________________________________ |可选工具 | |===============================================| |一键卸载openstack | | ./usr/openstack-cloud/install-openstack.sh | |_______________________________________________| 4.一键配置: ./usr/openstack-cloud/config.sh 5.一键创建和连接数据库 ./usr/openstack-cloud/db-connection.sh 注意:在创建数据库的过程中需要输入数据库的密码,如果没有设置数据库密码则为空,直接回车即可继续! _________________________________________________ |可选工具 | |===============================================| |一键重启服务 | | ./usr/openstack-cloud/service-restart.sh | |_______________________________________________| |一键停止服务 | |./usr/openstack-cloud/service-stop.sh | |_______________________________________________| 6.http://服务器ip/dashboard 7.最后上传镜像,运行实例——(管理节点)完毕 *如果需要手动配置和安装请参考(CentOS6.5+OpenStack+kvm云平台部署)文献。 ========服务先到这里,感谢您的使用,技术问题请联系!============ | 联系方式:QQ:1098978739 邮箱1098978739@qq.com | | QQ认证请输入:openstack+姓名 | ================开发者:小马 版权所有2014年5月21日 =============

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值