Salt 一种全新的基础设施管理方式,部署轻松,在几分钟内可运行起来,扩展性好,很容易管理上万台服务器,速度够快,服务器之间秒级通讯。
salt底层采用动态的连接总线, 使其可以用于编配, 远程执行, 配置管理等等.
大规模部署salt的时候,为了减轻运维工作,需要批量来安装salt-minion客户端。
salt-ssh是Saltstack的另一种管理方式,无需安装minion端,可以运用Salt的一切功能,管理和使用方式和基本和Salt一样。但是执行效率会比有minion端慢很多,不适合大规模批量操作
192.168.1.14 服务端:salt-ssh salt-master salt-minion
192.168.1.15 客户端:salt-minion
192.168.1.16 客户端:salt-minion
192.168.1.17 客户端:salt-minion
$ git clone https://github.com/BigbigY/salt-ssh-install-salt-minion.git
$ rpm --import SALTSTACK-GPG-KEY.pub
提示:salt-ssh不需要启动服务,只需要启动下salt-master服务
$ yum -y install salt-ssh salt-master
$ systemctl start salt-master
把所有minion_ip放到文件中,格式如下:
$ cat host_ip.txt
192.168.1.14
192.168.1.15
192.168.1.16
192.168.1.17
USERNAME是客户端用户名,PASSWORD是客户端密码,这里的话客户端账号密码都相同,所有我写了个批量添加的脚本
$ cat ip.sh
#!/bin/bash
USERNAME="root"
PASSWORD="123"
for i in `cat /root/host_ip.txt`
do
echo "$i:" >> /etc/salt/roster ##$i表示取文件的每行内容
echo " host: $i" >> /etc/salt/roster
echo " user: $USERNAME" >>/etc/salt/roster
echo " passwd: $PASSWORD" >>/etc/salt/roster
# echo " sudo: True" >>/etc/salt/roster
echo " timeout: 10" >>/etc/salt/roster
done
$ cat /etc/salt/roster
# Sample salt-ssh config file
#web1:
# host: 192.168.42.1 # The IP addr or DNS hostname
# user: fred # Remote executions will be executed as user fred
# sudo: True # Whether to sudo to root, not enabled by default
#web2:
# host: 192.168.42.2
192.168.1.14:
host: 192.168.1.14
user: root
passwd: 123
timeout: 10
192.168.1.15:
host: 192.168.1.15
user: root
passwd: 123
timeout: 10
192.168.1.16:
host: 192.168.1.16
user: root
passwd: 123
timeout: 10
192.168.1.17:
host: 192.168.1.17
user: root
passwd: 123
timeout: 10
$ salt-ssh -i '*' test.ping
192.168.1.17:
True
192.168.1.14:
True
192.168.1.16:
True
192.168.1.15:
True
$ pwd
/srv/salt
$ tree minions/
minions/
├── 5
│ └── README.md
├── 6
│ └── README.md
└── 7
├── conf
│ ├── minion
│ ├── SALTSTACK-GPG-KEY.pub
│ └── saltstack.repo
└── install.sls
4 directories, 6 files
$ cat /etc/hosts
192.168.1.14 salt.node1.com
192.168.1.15 salt.node2.com
192.168.1.16 salt.node3.com
192.168.1.17 salt.node4.com
minion配置文件根据自己master_ip修改,id根据自身情况获取
$ pwd
/srv/salt
salt-ssh -i '*' state.sls minions.7.install
$ salt-key
Accepted Keys:
Denied Keys:
Unaccepted Keys:
192.168.1.14
192.168.1.15
192.168.1.16
192.168.1.17
Rejected Keys:
$ salt-key -A
The following keys are going to be accepted:
Unaccepted Keys:
192.168.1.14
192.168.1.15
192.168.1.16
192.168.1.17
Proceed? [n/Y] y
Key for minion 192.168.1.14 accepted.
Key for minion 192.168.1.15 accepted.
Key for minion 192.168.1.16 accepted.
Key for minion 192.168.1.17 accepted.
$ salt-key
Accepted Keys:
192.168.1.14
192.168.1.15
192.168.1.16
192.168.1.17
Denied Keys:
Unaccepted Keys:
Rejected Keys:
$ salt '*' test.ping
192.168.1.14:
True
192.168.1.15:
True
192.168.1.16:
True
192.168.1.17:
True
在/etc/salt/roster清除添加的认证主机
$ salt '*' test.ping
192.168.1.14:
True
192.168.1.15:
True
192.168.1.16:
True
192.168.1.17:
True
温馨提示: 此篇以ip为minion_id,如果需要根据主机名,可以先把主机名写命名好,然后改写install.sls grains获取改成host主机名就可以了。 或者可以自己编写个grains模块来获取。