[root@server3 ~]# yum repolist
repo id repo name status
rhel-source Red Hat Enterprise Linux 6Server - x86_64 - Source 3,690
slat slatstack 29repolist:3,719
[root@server3 ~]# yum list salt-*
Loaded plugins: product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Available Packages
salt.noarch2016.11.3-1.el6 slat
salt-api.noarch2016.11.3-1.el6 slat
salt-cloud.noarch2016.11.3-1.el6 slat
salt-master.noarch2016.11.3-1.el6 slat
salt-minion.noarch2016.11.3-1.el6 slat
salt-ssh.noarch2016.11.3-1.el6 slat
salt-syndic.noarch
3、安装 salt-master(minion端安装salt-minion)
[root@server3 ~]# yum install -y salt-master
二、配置 salt
1、master 端
[root@server3 ~]# cd /etc/salt/
[root@server3 salt]# vim master14# The address of the interface to bind to:15interface:172.25.120.3
[root@server3 salt]# /etc/init.d/salt-master startStarting salt-master daemon: [ OK ]
[root@server3 salt]# netstat -antple
tcp 00172.25.120.3:45060.0.0.0:*LISTEN0141211427/python2.6BLISHED0171071421/python2.6
tcp 00172.25.120.3:4505
4505端口:链接用的,发布订阅
4506端口:请求响应,模式为:zmq(消息队列)
2、minion端(两台主机操作一致)
[root@server4 ~]# cd /etc/salt/
[root@server4 salt]# vim minion15# resolved, then the minion will fail to start.16master:172.25.120.3
[root@server4 salt]# /etc/init.d/salt-minion startStarting salt-minion:root:server4 daemon:OK
[root@server3 master]# salt '*' test.pingserver5:
True
server4:
True
[root@server3 master]# salt '*' cmd.run hostnameserver5:
server5
server4:
server4
四、配置自动化部署
master端:
1、修改配置文件
[root@server3 ~]# cd /etc/salt/
[root@server3 salt]# vim master534file_roots:535base:536 - /srv/salt
[root@server3 salt]# mkdir /srv/salt
[root@server3 salt]# /etc/init.d/salt-master restartStopping salt-master daemon: [ OK ]
Starting salt-master daemon: [ OK ]
2、配置部署脚本
同样的id,同样的模块只能掉用1次!!
yum源必须ok!
[root@server3 salt]# cd /srv/salt
[root@server3 salt]# mkdir httpd
[root@server3 salt]# cd httpd/
[root@server3 httpd]# vim apache.sls
apache-install:##格式1
pkg.installed:
- pkgs:
- httpd
- php
3、测试、执行脚本
测试
[root@server3 httpd]# salt server4 state.sls httpd.apache test=true
server4:
---------- ID: apache-install Function: pkg.installed Result: None Comment: The following packages would be installed/updated: httpd, php Started: 10:53:39.185588 Duration: 327.12 ms Changes: Summary for server4
------------
Succeeded: 1 (unchanged=1)
Failed: 0
------------
执行,回传结果
[root@server3 httpd]# salt server4 state.sls httpd.apache
Summary for server4
------------
Succeeded: 1 (changed=1)
Failed: 0
------------
Total states run: 1
Total run time: 18.215 s
[root@server3 salt]# vim /etc/yum.repos.d/rhel-source.repo
[root@server3 salt]# yum list haproxy
Loaded plugins: product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Available Packages
haproxy.x86_64 1.4.24-2.el6 LoadBalancer
3、配置salt
[root@server3 salt]# salt-key -A
The following keys are going to be accepted:
Unaccepted Keys:
server3
Proceed? [n/Y] Y
Key for minion server3 accepted.
[root@server3 salt]# salt-key -L
Accepted Keys:
server3
server4
server5
Denied Keys:
Unaccepted Keys:
Rejected Keys:
4、配置haproxy
[root@server3 salt]# cd /srv/salt/
[root@server3 salt]# mkdir haproxy ##haproxy配置
[root@server3 salt]# vim haproxy/install.sls
haproxy-install:
pkg.installed:
- pkgs:
- haproxy
[root@server3 haproxy]# salt server3 state.sls haproxy.install ##安装haproxyserver3:
----------
ID: haproxy-install
Function: pkg.installed
Result: True
Summary for server3
------------
Succeeded: 1Failed: 0
------------
[root@server3 salt]# cd haproxy/
[root@server3 haproxy]# cp /etc/haproxy/haproxy.cfg .
[root@server3 haproxy]# mkdir files ##haproxy源码
[root@server3 haproxy]# mv haproxy.cfg files/
[root@server3 haproxy]# vim 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: True
- watch:
- file: haproxy-install
[root@server3 haproxy]# vim files/haproxy.cfg ##haproxy配置文件#---------------------------------------------------------------------# 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.120.4:80 check
server app2 172.25.120.5:80 check
[root@server3 salt]# vim top.sls ##注意:httpd端口和默认发布文件base:
'server3':
- haproxy.install
'server4':
- httpd.service
'server5':
- nginx.server
##高级推送
[root@server3 salt]# salt '*' state.highstate