salt-ssh-install-salt-minion
阿新 • • 發佈:2018-05-09
ble imp ont 很多 for 文件 dir stat 拷貝
Saltstack?
Salt 一種全新的基礎設施管理方式,部署輕松,在幾分鐘內可運行起來,擴展性好,很容易管理上萬臺服務器,速度夠快,服務器之間秒級通訊。
salt底層采用動態的連接總線, 使其可以用於編配, 遠程執行, 配置管理等等.
批量部署salt-minion客戶端
大規模部署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
一、salt-ssh安裝(master端)
1、克隆代碼:
$ git clone https://github.com/BigbigY/salt-ssh-install-salt-minion.git
2、導入SaltStack存儲密鑰:
$ rpm --import SALTSTACK-GPG-KEY.pub
3、將saltstack.repo拷貝到/etc/yum.repos.d/
4、Run sudo yum clean expire-cache.
5、Run sudo yum update.
6、安裝salt-ssh
提示:salt-ssh不需要啟動服務,只需要啟動下salt-master服務
$ yum -y install salt-ssh salt-master
$ systemctl start salt-master
二、配置salt-ssh客戶端信息,通信
1、ip文件:
把所有minion_ip放到文件中,格式如下:
$ cat host_ip.txt
192.168.1.14
192.168.1.15
192.168.1.16
192.168.1.17
2、批量添加腳本:
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
3、執行,查看
$ 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
4、測試
$ 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
三、批量安裝salt-minion
1、目錄結構:
$ 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
2、需要在控制端/etc/hosts文件增加Host解析(master)
$ 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
3、執行:
minion配置文件根據自己master_ip修改,id根據自身情況獲取
$ pwd
/srv/salt
salt-ssh -i ‘*‘ state.sls minions.7.install
4、查看需要授權的主機:
$ 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:
5、授權要管理的主機:
$ 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:
6、salt測試
$ salt ‘*‘ test.ping
192.168.1.14:
True
192.168.1.15:
True
192.168.1.16:
True
192.168.1.17:
True
7、取消salt-ssh:
在/etc/salt/roster清除添加的認證主機
8、測試
$ 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模塊來獲取。
salt-ssh-install-salt-minion