[root@master ~]# vim /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# passwd: foobarbaz # The password to use for login, if omitted, keys are used# sudo: True # Whether to sudo to root, not enabled by default#web2:# host: 192.168.42.2
node1:
host:192.168.47.120#只需要将客户端的ip写进来就可以了
node2:
host:192.168.47.121
如果客户端数量多,可以通过脚本来添加ip地址
[root@master ~]# vim circulation_ip.sh[root@master ~]# cat circulation_ip.sh#!/bin/bashwhile read line;do
cat >>/etc/salt/roster << EOF
p$(echo $line | awk '{print $1}'):
host: $(echo $line | awk '{print $2}')
EOF
done < host.info
//定义的ip
[root@master ~]# vim host.info[root@master ~]# cat host.info1192.168.47.1222192.168.47.123//执行脚本之后生成的文件
[root@master ~]# chmod +x circulation_ip.sh [root@master ~]# ./circulation_ip.sh[root@master ~]# 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# passwd: foobarbaz # The password to use for login, if omitted, keys are used# sudo: True # Whether to sudo to root, not enabled by default#web2:# host: 192.168.42.2
node1:
host:192.168.47.120
node2:
host:192.168.47.121
p1:
host:192.168.47.122
p2:
host:192.168.47.123
配置ssh
[root@master ~]# cd .ssh/[root@master .ssh]# vim config
StrictHostKeyChecking=no
第一次连接需要输入root用户密码,后面就不用了
[root@master .ssh]# salt-ssh '*' test.ping
Permission denied for host node1, do you want to deploy the salt-ssh key? (password required):[Y/n] y
Password for root@node1:
node1:True
Permission denied for host node2, do you want to deploy the salt-ssh key? (password required):[Y/n] y
Password for root@node2:
node2:True[root@master .ssh]# salt-ssh '*' test.ping
node1:True
node2:True
你可以在配置文件中指定用户和密码,这样就不用输入密码了
# host: 192.168.42.1 # The IP addr or DNS hostname# user: fred # Remote executions will be executed as user fred# passwd: foobarbaz # The password to use for login, if omitted, keys are used# sudo: True # Whether to sudo to root, not enabled by default#web2:# host: 192.168.42.2
node1:
host:192.168.47.120
user: root
passwd:1
port:22
node2:
host:192.168.47.121
user: root
passwd:1
port:22[root@master ~]# salt-ssh '*' test.ping
node1:True
node2:True