SaltStack服务器配置

############################################################
*
* SaltStack服务器配置

############################################################
1.系统初始化 (如:把应该改的全部改了,一些常的服务都装上并配置好)
2.功能模块(如:nginx php nginx+php mysql主 mysql从 memcached )
3.业务模块(所有状态以业务为单位)
4.配置管理注意事项:
一、缩进,不要使用tab键(TAML固定的缩进风格,数据层结构关系,每个缩进级别为两个空格组成)
二、冒号,冒号后面跟空格,顶级的可以以冒号结束
三、短横线、短横线后面跟空格,短横线上层跟两个空格

yum install -y salt-master salt-minion

#服务器端配置
[root@M01 salt]# grep -Ev '^$|^#' /etc/salt/master
file_roots:
base:

  • /srv/salt/
    pillar_roots:
    base:
  • /srv/pillar

[root@M01 ~]# mkdir -p /srv/salt
[root@M01 ~]# mkdir -p /srv/pillar

#客户端配置
[root@M01 salt]# grep -Ev '^$|^#' /etc/salt/minion
master: 192.168.44.61
id: M01

#重新启动
[root@M01 ~]# /etc/init.d/salt-master restart
[root@M01 ~]# /etc/init.d/salt-minion restart

#加入开机自启动
[root@M01 ~]# chkconfig salt-master on
[root@M01 ~]# chkconfig salt-minion on

#查看客户端公钥和私钥
[root@M01 ]# ls /etc/salt/pki/minion/
minion.pem minion.pub

#查看服务端公钥和私钥
[root@M01 minion]# ls /etc/salt/pki/master/
master.pem master.pub

#如果报错 Minion did not return. [Not connected]
#如果客户存在公钥和私钥就先删除
\rm -fr /etc/salt/pki/minion/minion_master.pub
/etc/init.d/salt-minion restart

#查看没有同意的主机
root@M01 master]# salt-key
Accepted Keys:
YUM01
Denied Keys:
Unaccepted Keys:
M01

#按Y同意M01加入,-d删除 -a hostname 只加入这一台 -A全部加入
[root@M01 master]# salt-key -a M01
The following keys are going to be accepted:
Unaccepted Keys:
M01
Proceed? [n/Y] Y

#服务器端远程执行命令
[root@M01 master]# salt '*' test.ping
LB01:
True
.....

#服务器端远程执行查看硬盘空间命令,使用cmd模块和run方法
[root@M01 ~]# salt '*' cmd.run 'df -h'

猜你喜欢

转载自blog.51cto.com/yehaixiao/2125087