目录
1. salt-ssh介绍
salt-ssh可以让我们不需要在受控机上安装salt-minion客户端也能够实现管理操作。
1.1 salt-ssh的特点
远程系统需要Python支持,除非使用-r选项发送原始ssh命令
salt-ssh是一个软件包,需安装之后才能使用,命令本身也是salt-ssh
salt-ssh不会取代标准的Salt通信系统,它只是提供了一个基于SSH的替代方案,不需要ZeroMQ和agent
请注意,由于所有与Salt SSH的通信都是通过SSH执行的,因此它比使用ZeroMQ的标准Salt慢得多
1.2 salt-ssh远程管理的方式
salt-ssh有两种方式实现远程管理,一种是在配置文件中记录所有客户端的信息,诸如 IP 地址、端口号、用户名、密码以及是否支持sudo等;另一种是使用密钥实现远程管理,不需要输入密码。
2. salt-ssh管理
在 master 上安装 salt-ssh
[root@node1 ~]# yum -y install salt-ssh
2.1 通过使用用户名密码的SSH实现远程管理
修改配置文件,添加受控机信息
[root@node1 ~]# 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.136.164
user: root
passwd: 123456
node2:
host: 192.168.136.165
user: root
passwd: 123456
测试连通性
[root@node1 ~]# salt-ssh '*' test.ping
node2:
----------
retcode:
254
stderr:
stdout:
The host key needs to be accepted, to auto accept run salt-ssh with the -i flag:
The authenticity of host '192.168.136.165 (192.168.136.165)' can't be established.
ECDSA key fingerprint is SHA256:xb2UGeSbbMPWguFesJfqUhvaplJ9KuOCUifgRniaDSU.
ECDSA key fingerprint is MD5:ad:94:a5:3d:68:1d:a6:b4:0a:f9:94:80:c8:ba:66:12.
Are you sure you want to continue connecting (yes/no)?
node1:
----------
retcode:
254
stderr:
stdout:
The host key needs to be accepted, to auto accept run salt-ssh with the -i flag:
The authenticity of host '192.168.136.164 (192.168.136.164)' can't be established.
ECDSA key fingerprint is SHA256:uN0Vd9u/GGh1TgTNrXBRphj1OpHmNrDfRpU0H0l14tQ.
ECDSA key fingerprint is MD5:07:4c:6d:0a:1b:ac:d0:c0:d1:b2:95:e3:a8:a3:65:e6.
Are you sure you want to continue connecting (yes/no)?
从上面的信息可以看出,第一次访问时需要输入 yes/no ,但是 saltstack 是不支持交互式操作的,所以为了解决这个问题,我们需要对其进行设置,让系统不进行主机验证。
[root@node1 ~]# vim ~/.ssh/config
StrictHostKeyChecking no
[root@node1 ~]# salt-ssh '*' test.ping
node1:
True
node2:
True