1.salt-ssh管理
1.1 在master上安装salt-ssh
[root@node01 yum.repos.d]# yum -y install salt-ssh
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 salt-ssh.noarch.0.3000-1.el7 将被 安装
--> 正在处理依赖关系 salt = 3000-1.el7,它被软件包 salt-ssh-3000-1.el7.noarch 需要
--> 正在检查事务
---> 软件包 salt.noarch.0.2019.2.3-1.el7 将被 升级
--> 正在处理依赖关系 salt = 2019.2.3-1.el7,它被软件包 salt-master-2019.2.3-1.el7.noarch 需要
--> 正在处理依赖关系 salt = 2019.2.3-1.el7,它被软件包 salt-minion-2019.2.3-1.el7.noarch 需要
---> 软件包 salt.noarch.0.3000-1.el7 将被 更新
--> 正在处理依赖关系 python-setuptools >= 9.1,它被软件包 salt-3000-1.el7.noarch 需要
--> 正在处理依赖关系 python-msgpack >= 0.6,它被软件包 salt-3000-1.el7.noarch 需要
--> 正在处理依赖关系 python-singledispatch,它被软件包 salt-3000-1.el7.noarch 需要
--> 正在处理依赖关系 python-backports_abc,它被软件包 salt-3000-1.el7.noarch 需要
--> 正在检查事务
---> 软件包 python-backports_abc.noarch.0.0.5-11.el7 将被 安装
---> 软件包 python-setuptools.noarch.0.36.6.0-2.ius.el7 将被 安装
---> 软件包 python-singledispatch.noarch.0.3.4.0.3-16.el7 将被 安装
---> 软件包 python2-msgpack.x86_64.0.0.5.6-7.el7 将被 升级
1.2通过使用用户密码的ssh实现远程管理
修改配置文件,添加受控机信息
[root@node01 salt]# vi roster
[root@node01 salt]# tail roster
# 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
node02:
host: 192.169.100.132
user: root
passwd: zrl98726
[root@node01 salt]# tail -4 roster
node02:
host: 192.169.100.132
user: root
passwd: zrl98726
测试连通性
[root@node01 salt]# salt-ssh '*' test.ping
node02:
----------
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.100.132 (192.168.100.132)' can't be established.
ECDSA key fingerprint is SHA256:yFHQkd6jOgbdek2OtzkVftgApvG1bFp6Ki44/uH+te0.
ECDSA key fingerprint is MD5:8b:b7:00:45:f3:fb:55:df:10:9a:b2:12:10:28:c7:c7.
Are you sure you want to continue connecting (yes/no)?
发现需要进行主机验证,于是我们需要对其进行设置,让系统不去进行主机验证
[root@node01 ~]# vi .ssh/config
[root@node01 ~]# cat .ssh/config
StrictHostKeyChecking no
然后在ping一下测试连通性
[root@node01 ~]# salt-ssh '*' test.ping
node02:
True
然后就可以使用命令进行远程执行了,这里的*代表的是配置文件里写的受控机
[root@node01 ~]# salt-ssh '*' cmd.run 'ls /root'
node02:
a
anaconda-ks.cfg
haha