[[email protected] base]# mkdir /srv/salt/prod/pkg
[[email protected] base]# mkdir /srv/salt/prod/haproxy
[[email protected] base]# mkdir /srv/salt/prod/haproxy/files
[[email protected] base]# cd /srv/salt/prod/haproxy/files
[[email protected] 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
[[email protected] files]# ls
haproxy-1.6.2.tar.gz
[[email protected] files]# cp haproxy-1.6.2.tar.gz /usr/local/src/ =========================>将文件拷贝到/usr/local/src下面
[[email protected] base]# cd /srv/salt/prod/pkg/
[[email protected] base]# vim pkg-init.sls
[[email protected] pkg]# cat /srv/salt/prod/pkg/pkg-init.sls ================================>首先需要安装如下依赖包
pkg-init:
pkg.installed:
- names:
- gcc
- gcc-c++
- glibc
- make
- autoconf
- openssl
- openssl-devel
[[email protected] 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
[[email protected] haproxy]# pwd
/srv/salt/prod/haproxy
[[email protected] haproxy]# ls
files install.sls
[[email protected] 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
[[email protected] 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
欢迎交流