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

Saltstack配置管理功能模块-haproxy

时间:2015-11-18 18:11:01      阅读:296      评论:0      收藏:0      [点我收藏+]

标签:haproxy   saltstack

[root@linux-node1 base]# mkdir /srv/salt/prod/pkg

[root@linux-node1 base]# mkdir /srv/salt/prod/haproxy

[root@linux-node1 base]# mkdir /srv/salt/prod/haproxy/files

[root@linux-node1 base]# cd /srv/salt/prod/haproxy/files

[root@linux-node1 files]# rz -y

rz waiting to receive.

Starting zmodem transfer.  Press Ctrl+C to cancel.

Transferring haproxy-1.6.2.tar.gz...

  100%    1502 KB    1502 KB/sec    00:00:01       0 Errors  


[root@linux-node1 files]# ls

haproxy-1.6.2.tar.gz

[root@linux-node1 files]# cp haproxy-1.6.2.tar.gz /usr/local/src/             =========================>将文件拷贝到/usr/local/src下面


[root@linux-node1 base]# cd /srv/salt/prod/pkg/

[root@linux-node1 base]# vim pkg-init.sls

[root@linux-node1 pkg]# cat /srv/salt/prod/pkg/pkg-init.sls                    ================================>首先需要安装如下依赖包

pkg-init:

  pkg.installed:

    - names:

      - gcc

      - gcc-c++

      - glibc

      - make

      - autoconf

      - openssl

      - openssl-devel


[root@linux-node1 files]# salt ‘*‘ state.sls pkg.pkg-init env=prod               ============================>执行状态,安装依赖包


安装步骤记录:

cd /usr/local/src/

tar xf haproxy-1.6.2.tar.gz

cd haproxy-1.6.2

make TARGET=linux26 PREFIX=/usr/local/haproxy && make install PREFIX=/usr/local/haproxy


[root@linux-node1 haproxy]# pwd

/srv/salt/prod/haproxy


[root@linux-node1 haproxy]# ls

files  install.sls


[root@linux-node1 haproxy]# cat install.sls 

include:

  - pkg.pkg-init        #################先包含之前安装的依赖包####################


haproxy-install:        ###########安装haproxy程序############

  file.managed:

    - name: /usr/local/src/haproxy-1.6.2.tar.gz

    - source: salt://haproxy/files/haproxy-1.6.2.tar.gz

    - user: root

    - group: root

    - mode: 755

  cmd.run:

    - name: cd /usr/local/src/ && tar xf haproxy-1.6.2.tar.gz && cd haproxy-1.6.2 && make TARGET=linux26 PREFIX=/usr/local/haproxy && make install PREFIX=/usr/local/haproxy

    - unless: test -d /usr/local/haproxy        ######判断一个目录是否存在#########

    - require:                                  ###########检查依赖###########

      - pkg: pkg-init                           ##########此处指明依赖哪个模块########

      - file: haproxy-install                   #######一个id下一个模块只能用一次#########



haproxy-init:

  file.managed:                                #########文件管理模块与方法###########

    - name: /etc/init.d/haproxy

    - source: salt://haproxy/files/haproxy.init   ##########启动脚本的位置###########

    - user: root

    - group: root

    - mode: 755

    - require:                              ##############检测依赖###############

      - cmd: haproxy-install                ############检测是否装上###############

  cmd.run:

    - name: chkconfig --add haproxy

    - unless: chkconfig --list | grep haproxy

    - require:

      - file: haproxy-init


net.ipv4.ip_nonlocal_bind:

  sysctl.present:

    - value: 1


haproxy-config-dir:                       #########创建一个配置文件目录###########

  file.directory:                         

    - name: /etc/haproxy

    - user: root

    - group: root

    - mode: 755


[root@linux-node1 haproxy]# salt ‘*‘ state.sls haproxy.install env=prod

返回结果:

linux-node1.example.com:

..........................

Summary

-------------

Succeeded: 13

Failed:     0

-------------

Total states run:     13

linux-node2.example.com:

..........................

Summary

-------------

Succeeded: 13

Failed:     0

-------------

Total states run:     13 


老男孩网址:http://www.etiantian.org

qq:406564728

欢迎交流

本文出自 “linux” 博客,请务必保留此出处http://chenjisong.blog.51cto.com/7858025/1714331

Saltstack配置管理功能模块-haproxy

标签:haproxy   saltstack

原文地址:http://chenjisong.blog.51cto.com/7858025/1714331

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