Salt 一种全新的基础设施管理方式,部署轻松,在几分钟内可运行起来,扩展性好,很容易管理上万台服务器,速度够快,服务器之间秒级通信。node
salt底层采用动态的链接总线, 使其能够用于编配, 远程执行, 配置管理等等.git
大规模部署salt的时候,为了减轻运维工做,须要批量来安装salt-minion客户端。github
salt-ssh是Saltstack的另外一种管理方式,无需安装minion端,能够运用Salt的一切功能,管理和使用方式和基本和Salt同样。可是执行效率会比有minion端慢不少,不适合大规模批量操做web
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服务bash
$ 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根据自身状况获取ssh
$ 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模块来获取。code