salt 介紹:python
Salt,,一種全新的基礎設施管理方式,部署輕鬆,在幾分鐘內可運行起來,擴展性好,很容易管理上萬臺服務器,速度夠快,服務器之間秒級通信。bash
salt底層採用動態的鏈接總線, 使其能夠用於編配, 遠程執行, 配置管理等等.服務器
salt安裝:測試
master:192.168.31.231 mongo1.example.comspa
minion:192.168.31.232 mongo2.example.com code
minion:192.168.31.233 mongo3.example.comblog
修改/etc/hostsip
192.168.31.231 mongo1.example.com 192.168.31.232 mongo2.example.com 192.168.31.233 mongo3.example.com
系統版本:部署
[root@mongo1 salt]# uname -r 2.6.32-431.el6.x86_64 [root@mongo1 salt]# uname -n mongo1.example.com [root@mongo1 salt]# cat /etc/redhat-release CentOS release 6.5 (Final)
安裝master:cmd
[root@mongo1 ~]# rpm -ivh http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm Retrieving http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm warning: /var/tmp/rpm-tmp.MJ9wJa: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY Preparing... ########################################### [100%] 1:epel-release ########################################### [100%]
[root@mongo1 ~]# yum install -y salt-master
修改/etc/salt/master文件:
添加:
publish_port: 4505 #監聽salt的消息發佈系統端口 ret_port: 4506 #salt客戶端與服務端通訊的端口
啓動master服務:service salt-master start
安裝minion:
[root@mongo2 ~]# rpm -ivh http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm Retrieving http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm warning: /var/tmp/rpm-tmp.QcKooE: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY Preparing... ########################################### [100%] 1:epel-release ########################################### [100%] [root@mongo2 ~]# yum install -y salt-minion
修改/etc/salt/minion文件:
添加:
master: mongo1.example.com id: mongo2
啓動minion服務:service salt-minion start
查看認證:
[root@mongo1 pki]# salt-key -L Accepted Keys: Denied Keys: Unaccepted Keys: mongo2 mongo3 Rejected Keys:
添加認證:
[root@mongo1 pki]# salt-key -a mongo2
The following keys are going to be accepted:
Unaccepted Keys:
mongo2
Proceed? [n/Y] y Key for minion mongo2 accepted. [root@mongo1 pki]# salt-key -L Accepted Keys: mongo2 Denied Keys: Unaccepted Keys: mongo3 Rejected Keys: [root@mongo1 pki]# salt-key -a mongo3 The following keys are going to be accepted: Unaccepted Keys: mongo3.example.com Proceed? [n/Y] y Key for minion mongo3 accepted. [root@mongo1 pki]# salt-key -L Accepted Keys: mongo2 mongo3 Denied Keys: Unaccepted Keys: Rejected Keys:
或者能夠配置自動認證,在/etc/salt/master中添加auto_accept: True,重啓master服務。
測試驗證:
[root@mongo1 minions]# salt '*' test.ping
mongo3:
True
mongo2:
True
[root@mongo1 salt]# salt '*' cmd.run 'date'
mongo3:
Mon Sep 7 21:42:13 CST 2015 mongo2: Mon Sep 7 21:42:14 CST 2015 [root@mongo1 salt]# salt '*' cmd.run 'uptime' mongo3: 21:42:18 up 1:44, 1 user, load average: 0.00, 0.00, 0.00 mongo2: 21:42:20 up 1:44, 1 user, load average: 0.00, 0.00, 0.00
刪除不須要的認證:
[root@mongo1 minions]# pwd
/etc/salt/pki/master/minions
[root@mongo1 minions]# ls mongo2 mongo2.example.com mongo3 mongo3.example.com [root@mongo1 minions]# rm -rf mongo2.example.com mongo3.example.com
簡單測試腳本:
/srv/salt目錄須要手動建立
[root@mongo1 minions]# cd /srv/salt/
[root@mongo1 salt]# ls test.sh [root@mongo1 salt]# cat test.sh #!/bin/bash echo "ni hao" [root@mongo1 salt]# salt '*' cmd.script salt://test.sh mongo3: ---------- pid: 2617 retcode: 0 stderr: stdout: ni hao mongo2: ---------- pid: 1733 retcode: 0 stderr: stdout: ni hao [root@mongo1 salt]#