1
2
3
4
5
|
salt install haproxy
http:
/
/
www.cnblogs.com
/
reblue520
/
p
/
6732913.html
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
https:
/
/
chegva.com
/
794.html
haproxy.install.sls
include pkg.pkg
-
init 依赖
haproxy
-
install
-
file
.managed cmd.run 编译haproxy
haproxy
-
init
-
file
.managed cmd.run 启动脚本并chkconfig
haproxy
-
config
-
dir
file
.directory 目录权限
cluster.haproxy
-
outside.sls
include haproxy.install
haproxy
-
service
-
file
.managed service.running haproxy配置文件,服务自启动
# cd /srv/salt/base/
# vim top.sls
base:
'*'
:
-
init.env_init
prod:
'*'
:
-
cluster.haproxy
-
outside
语法
-
require:
-
cmd: haproxy
-
init
-
watch:
-
file
: haproxy
-
service
-
unless: test
-
d
/
usr
/
local
/
haproxy
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
salt install keepalived
/
etc
/
keepalived
/
keepalived.conf
# cp keepalived/etc/init.d/keepalived.init /srv/salt/prod/keepalived/files/
# cp keepalived/etc/init.d/keepalived.sysconfig /srv/salt/prod/keepalived/files/
# cp keepalived/etc/keepalived/keepalived.conf /srv/salt/prod/keepalived/files/
keepalived.install.sls
include pkg.pkg
-
init 依赖
keepalived
-
install
-
file
.managed cmd.run 编译keepalived
keepalived
-
init
-
file
.managed cmd.run
file
.managed
file
.directory 启动脚本并chkconfig
cluster.keepalived
-
outside.sls
include keepalived.install
keepalived
-
service
-
file
.managed service.running keepalived配置文件,服务自启动
语法
-
template: jinja
{
%
if
grains[
'fqdn'
]
=
=
'mini1'
%
}
-
ROUTEID: haproxy_ha
-
STATEID: MASTER
-
PRIORITYID:
150
{
%
elif
grains[
'fqdn'
]
=
=
'node2.chinasoft.com'
%
}
-
ROUTEID: haproxy_ha
-
STATEID: BACKUP
-
PRIORITYID:
100
{
%
endif
%
}
|
1
2
3
4
5
6
7
8
9
10
11
|
salt install memcached
user.www
libevent.install
-
file
.managed cmd.run require
-
file
: libevent
-
source
-
install
memcached.install
include:
-
libevent.install
-
user.www
-
file
.managed cmd.run
require
-
cmd: libevent
-
source
-
install
-
file
: memcached
-
source
-
install
memcached.service
include:
-
memcached.install
-
cmd.run
require
-
cmd: memcached
-
source
-
install
-
user: www
-
user
-
group
|
与安装haproxy区别的是,memcached引用了libevent,本来是3步,最后变为4步
1
2
3
4
5
6
7
8
9
10
|
salt install nginx (三步)
pcre
-
source
-
install
-
file
.managed
-
cmd.run
nginx.install
-
include
-
pcre.install
-
user.www
nginx
-
source
-
install
-
file
.managed
-
cmd.run
nginx.service
-
include nginx.install
nginx
-
init
-
file
.managed
-
cmd.run
/
usr
/
local
/
nginx
/
conf
/
nginx.conf
nginx
-
service
file
.directory
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
salt php
+
nginx虚拟主机
1.php
配置
2.php
redis 模块
3.php
memcached模块
4.bbs
论坛
1.php
配置
php
-
init
php
-
install
-
include
-
file
.manage
-
cmd.run
2.php
redis模块
php
-
redis
-
install
-
file
.manage
-
cmd.run
-
file
.append
总结
1.php
配置
pkg
-
php
-
pkg.installed
php
-
source
-
install
-
file
.manage
-
cmd.run
php
-
ini
php
-
fpm
php
-
fastcgi
-
service
2.php
redis 模块
redis
-
plugin
/
usr
/
local
/
php
-
fastcgi
/
etc
/
php.ini
3.php
memcached模块
memcache
-
plugin
/
usr
/
local
/
php
-
fastcgi
/
etc
/
php.ini
4.bbs
论坛
-
require:
-
service: php
-
fastcgi
-
service
-
watch_in:
-
service: nginx
-
service
|
所有的目录结构
[root@saltstack-node1 ~]# tree /srv/salt/
/srv/salt/├── base│ ├── init│ │ ├── audit.sls
├── cluster
│ ├── files
│ │ ├── haproxy-outside.cfg
│ │ └── haproxy-outside-keepalived.conf
│ ├── haproxy-outside-keepalived.sls
│ └── haproxy-outside.sls
├── haproxy
│ ├── files
│ │ ├── haproxy-1.5.3.tar.gz
│ │ └── haproxy.init
│ └── install.sls
├── keepalived
│ ├── files
│ │ ├── keepalived-1.2.17.tar.gz
│ │ ├── keepalived.init
│ │ └── keepalived.sysconfig
│ └── install.sls
├── libevent
│ ├── files
│ │ └── libevent-2.0.22-stable.tar.gz
│ └── install.sls
├── memcached
│ ├── files
│ │ └── memcached-1.4.24.tar.gz
│ ├── install.sls
│ └── service.sls
├── nginx
│ ├── files
│ │ ├── nginx-1.9.1.tar.gz
│ │ ├── nginx.conf
│ │ └── nginx-init
│ ├── install.sls
│ └── service.sls
├── pcre
│ ├── files
│ │ └── pcre-8.37.tar.gz
│ └── install.sls
├── php
│ ├── files
│ │ ├── init.d.php-fpm
│ │ ├── memcache-2.2.7.tgz
│ │ ├── php-5.6.9.tar.gz
│ │ ├── php-fpm.conf.default
│ │ ├── php.ini-production
│ │ └── redis-2.2.7.tgz
│ └── install.sls
├── user
│ └── www.sls
└── web
├── bbs.sls
└── files
└── bbs.conf
salt安装nginx服务
vim /srv/salt/top.sls
dev:
'minion.hello.com':
- nginx
cd /srv/salt
mkdir dev
cd dev
mkdir nginx
/srv/salt/dev/nginx nginx.sls
nginx:
pkg:
- installed
service:
- running
- enable: Ture
- watch:
- file: /etc/nginx/nginx.conf
- file: /etc/nginx/conf.d/default.conf
- require:
- pkg: nginx
/etc/nginx/nginx.conf:
file.managed:
- source: salt://nginx/nginx.conf
- mode: 664
- user: root
- group: root
/etc/nginx/conf.d/default.conf:
file.managed:
- source: salt://nginx/default.conf
- mode: 664
- user: root
- group: root
salt 'minion.hello.com' state.highstate
salt haproxy
http://www.cnblogs.com/caoxiaojian/p/5095653.html
这篇博文写的非常详细,极力推荐,但是要自己操作。因为目录结构复杂点。
mkdir /srv/salt/prod/pkg/
mkdir /srv/salt/prod/haproxy/
mkdir /srv/salt/prod/haproxy/files
cd /srv/salt/prod/pkg/
vim pkg-init.sls
pkg-init: # ID describe
pkg.installed: # pkg模块 installed方法
- names:
- gcc
- gcc-c++
- glibc
- make
- autoconf
- openssl
- openssl-devel
cd /srv/salt/prod/haproxy/files/
ll
-rw-r--r-- 1 root root 1538976 11月 7 09:04 haproxy-1.6.2.tar.gz
cp haproxy-1.6.2.tar.gz /usr/local/src/
cd /usr/local/src/
make TARGET=linux26 PREFIX=/usr/local/haproxy && make install PREFIX=/usr/local/haproxy
vim haproxy.init
BIN=/usr/local/haproxy/sbin/$BASENAME
cp haproxy.init /srv/salt/prod/haproxy/files/
cd /srv/salt/prod/haproxy/
vim install.sls
include: # 导入pkg目录下的pkg-init.sls文件
- pkg.pkg-init
haproxy-install: # 定义声明一个ID
file.managed: # file模块下的managed方法
- name: /usr/local/src/haproxy-1.6.2.tar.gz # 文件名:拷贝minion端这里,文件名是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 zxf 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 # 判断是否存在,unless返回值是false时,才执行命令
- require: # 依赖下面的内容
- pkg: pkg-init # pkg是模块
- file: haproxy-install # file也是模块
haproxy-init: # 定义声明一个ID
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: # 定义声明一个ID
sysctl.present: # 修改系统的kernel值
- value: 1 # 改值为1
haproxy-config-dir:
file.directory:
- name: /etc/haproxy
- user: root
- group: root
- mode: 755
salt 'linux-node1.*' state.sls haproxy.install env=prod
注意
cat /etc/salt/master
file_roots:
base:
- /srv/salt/base
prod:
- /srv/salt/prod
interface: ip
nodegroups:
mysql: 'cm1'
目录结构
[root@nginx salt]# tree
.
├── base
│ └── _modules
│ └── my_disk.py
└── prod
├── haproxy
│ ├── files
│ │ ├── haproxy-1.5.4.tar.gz
│ │ └── haproxy.init
│ └── install.sls
└── pkg
└── pkg-init.sls
本文转自 liqius 51CTO博客,原文链接:http://blog.51cto.com/szgb17/1915156,如需转载请自行联系原作者