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