環境說明
saltStack01 |
10.123.209.34 |
master |
Centos 7 |
centos6 |
10.123.209.41 |
minion |
Centos 6 |
1.安裝salt-master和salt-minion
[root@saltStack01 ~]# yum install -y salt-master salt-minion
[root@centos6 ~]# yum install -y salt-minion
2.啓動salt-master
[root@saltStack01 ~]# systemctl start salt-master
三、配置salt-minion
# 能夠是主機名須要解析(指定服務端的IP地址),冒號有空格
[root@centos6 salt]# sed '16a master: 10.123.209.34' /etc/salt/minion -i
[root@centos6 salt]# cat /etc/salt/minion |grep -v '^#' |grep master:
master: 10.123.209.34
# id:惟一標識符,能夠不配,不配默認就是主機名
[root@centos6 salt]# sed -i "79a id: centos6 /etc/salt/minion
四、啓動salt-minion
[root@saltStack01 ~]# systemctl start salt-minion
[root@centos6 salt]# service salt-minion start
五、配置salt-master和slat-minion通訊
[root@linux-node1 salt]# salt-key
Accepted Keys: # 贊成的
Denied Keys: # 拒絕的
Unaccepted Keys: # 等待贊成的
saltStack01
centos6
Rejected Keys:
贊成認證的方法分爲三種
salt-key -A
salt-key -a 指定id
salt-key -a 支持通配符
salt-key 命令參數簡單介紹
- -L --列出全部
- -d --刪除指定的支持通配符
- -D --刪除全部
- -A --添加全部
- -a --指定添加
salt-key 贊成以後生成的文件
pki/
├── master
│ ├── master.pem
│ ├── master.pub
│ ├── minions
│ │ ├── saltStack01
│ │ └── centos6
│ ├── minions_autosign
│ ├── minions_denied
│ ├── minions_pre
│ └── minions_rejected
└── minion
├── minion_master.pub # 贊成以後master發送公鑰
├── minion.pem
└── minion.pub
六、修改id配置
- minion配置中有一個id配置,默認是hostname
- 若是id配置和hostname不一致會致使沒法進行通訊
關閉salt-minion
- 此處必須先停掉minion修改,並刪除相應的文件,不然會默認地去查找原先的配置
CentOS7:systemctl stop salt-minion
CentOS6:service salt-minion stop
在master上刪除minion的id
salt-key -d id
minion上刪除pki目錄
rm -rf /etc/salt/pki
minion上刪除minion_id文件
rm -rf /etc/salt/minion_id
修改完成,啓動minion
CentOS7:systemctl start salt-minion
CentOS6:service salt-minion start
salt-minion修改id腳本
#!/bin/bash
# liangjingfu
# 判斷是否傳參
if [[ $# == 0 ]]; then
echo "please input id content!"
exit 1
else
id=$1
fi
# 判斷系統版本,目前只是判斷系統是否爲centos六、centos7
issix=`cat /etc/redhat-release | grep 6.`
isseven=`cat /etc/redhat-release | grep 7.`
if [[ -n ${issix} ]]; then
sysType=6
elif [[ -n ${isseven} ]]; then
sysType=7
fi
# 根據系統版本關閉salt-minion
stop_salt_minion(){
if [[ ${sysType} == 6 ]]; then
service salt-minion stop
elif [[ ${sysType} == 7 ]]; then
systemctl stop salt-minion
fi
}
# 刪除相應文件
rm_file(){
if [[ -d "/etc/salt/pki" ]]; then
rm -rf /etc/salt/pki
fi
if [[ -f "/etc/salt/minion_id" ]]; then
rm -rf /etc/salt/minion_id
fi
}
# 修改salt-minion配置文件id
mv_id(){
isid=`cat /etc/salt/minion |grep -v '^#' |grep 'id:'`
if [[ -z $isid ]]; then
sed -i "79a id: ${id}" /etc/salt/minion
elif [[ -n $isid ]]; then
sed -i "s#${isid}#id: ${id}#g" /etc/salt/minion
fi
}
# 根據系統版本開啓salt-minion
start_salt_minion(){
if [[ ${sysType} == 6 ]]; then
service salt-minion start
elif [[ ${sysType} == 7 ]]; then
systemctl start salt-minion
fi
}
# 運行方法
stop_salt_minion
rm_file
mv_id
start_salt_minion
運行方式:
sh saltminionid.sh 10.123.209.41-centos6.liang.com