标签:saltstack
系统环境:CentOS release 6.7 (Final)
内核版本:2.6.32-573.el6.x86_64
硬件环境:20G硬盘 2G内存 双核CPU
IP地址部署:
master: 10.0.0.7 hostname:linux-node1.example.com
minion: 10.0.0.8 hostname:linux-node2.example.com
[root@linux-node1 ~]# yum install salt-master salt-minion -y
[root@linux-node1 ~]# cat /etc/salt/master | grep -v "^#"
client_acl:
oldboy:
- test.ping
- network.*
user01:
- linux-node1.example.com:
- test.ping
file_roots:
base:
- /srv/salt/base
prod:
- /srv/salt/prod
test:
- /srv/salt/test
pillar_roots:
base:
- /srv/pillar/base
master_job_cache: mysql
mysql.host: ‘10.0.0.7‘
mysql.user: ‘salt‘
mysql.pass: ‘salt‘
mysql.db: ‘salt‘
mysql.port: 3306
etcd_pillar_config:
etcd.host: 10.0.0.7
etcd.port: 4001
ext_pillar:
- etcd: etcd_pillar_config root=/salt/haproxy/
[root@linux-node1 ~]# cat /etc/salt/minion | grep -v "^#"
master: 10.0.0.7
id: linux-node1.example.com
grains:
roles:
- webserver
- memcache
mysql.host: ‘10.0.0.7‘
mysql.user: ‘salt‘
mysql.pass: ‘salt‘
mysql.db: ‘salt‘
mysql.port: 3306
[root@linux-node1 ~]# /etc/init.d/salt-master restart
Stopping salt-master daemon: [确定]
Starting salt-master daemon: [确定]
[root@linux-node1 ~]# /etc/init.d/salt-minion restart
Stopping salt-minion daemon: [确定]
Starting salt-minion daemon: [确定]
[root@linux-node1 ~]# salt-key -L -L 显示所有的机器列表
Accepted Keys:
Denied Keys:
Unaccepted Keys:
linux-node1.example.com
linux-node2.example.com
Rejected Keys:
[root@linux-node1 ~]# salt-key -a linux-node1.example.com -a 指定接受某台机器
The following keys are going to be accepted:
Unaccepted Keys:
linux-node1.example.com
Proceed? [n/Y] y
Key for minion linux-node1.example.com accepted.
[root@linux-node1 ~]# salt-key
Accepted Keys:
linux-node1.example.com
Denied Keys:
Unaccepted Keys:
linux-node2.example.com
Rejected Keys:
[root@linux-node1 ~]# salt-key -A -A 接受所有的机器
The following keys are going to be accepted:
Unaccepted Keys:
linux-node2.example.com
Proceed? [n/Y] Y
Key for minion linux-node2.example.com accepted.
[root@linux-node1 ~]# salt-key 不带参数默认为-L
Accepted Keys:
linux-node1.example.com
linux-node2.example.com
Denied Keys:
Unaccepted Keys:
Rejected Keys:
[root@linux-node1 ~]# salt ‘*‘ test.ping ======salt-master是否与salt-minion建立联系,如果建立则返回True
linux-node2.example.com:
True
linux-node1.example.com:
True
top file文件的作用:
告诉minion端在哪台机器上执行什么操作:
例子:
[root@linux-node1 ~]# cat /srv/salt/top.sls
base: =============>指明什么环境
‘*.example.com‘: =============>指明哪台机器
- apache =============>指明需要执行什么状态
apache.sls文件:
apache-install: ==============>id,可随意取
pkg.installed: ==============>模块和方法
- names: ==============>指定下面需要安装什么模块
- httpd ==============>需要哪个软件包
- httpd-devel ==============>需要哪个软件包
apache-service: ==============>id,可随意取
service.running: ==============>模块和方法
- name: httpd ==============>程序名
- enable: True ==============>是否开机自启动
- reload: True ==============>是否允许重载
[root@linux-node1 salt]# salt ‘*‘ state.sls apache
salt 命令
* 指明哪一台机器
state 模块
sls 方法
apache 指明是哪个状态文件需要执行
###########################################################################################################################################################################
###########################################################################################################################################################################
###########################################################################################################################################################################
[root@linux-node2 ~]# yum install salt-minion -y
[root@linux-node2 ~]# cat /etc/salt/minion | grep -v "^#"
master: 10.0.0.7
id: linux-node2.example.com
mysql.host: ‘10.0.0.7‘
mysql.user: ‘salt‘
mysql.pass: ‘salt‘
mysql.db: ‘salt‘
mysql.port: 3306
[root@linux-node1 ~]# /etc/init.d/salt-minion restart
Stopping salt-minion daemon: [确定]
Starting salt-minion daemon: [确定]
老男孩网址:http://www.etiantian.org/
联系qq:406564728
欢迎提出宝贵建议
本文出自 “linux” 博客,请务必保留此出处http://chenjisong.blog.51cto.com/7858025/1714016
标签:saltstack
原文地址:http://chenjisong.blog.51cto.com/7858025/1714016