介绍:

salt-ssh 是 0.17.0 新出现的一个功能,一听这名字就知道它是依赖 ssh 来进行远程命令执行的工具,好处就是你不需要在客户端安装 minion,也不需要安装 master(直接安装 salt-ssh 这个包即可),有点类似 paramiko、pssh、ansible 这类的工具,有些时候你还真的需要 salt-ssh(例如:条件不允许安装 minion、不用长期管理某台 minion) 最最重要的是 salt-ssh 并不只是单纯的 ssh 工具,它支持 salt 大部分的功能,如 grains、modules、state 等

备注 需要注意的是,salt-ssh 并没有继承原来的通讯架构 (ZeroMQ),也就是说它的执行速度啥的都会比较慢

安装salt-ssh

root@iZ23f6c5z8tZ:~# apt-get install salt-ssh -y

salt-ssh 是通过调用 roster 配置文件来实现的,语法很简答,定义 ID、host、user、password 即可

root@iZ23f6c5z8tZ:/etc/salt# pwd/etc/saltroot@iZ23f6c5z8tZ:/etc/salt# lsmaster  master.bak  master.d  pki  rosterroot@iZ23f6c5z8tZ:/etc/salt# cat 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.2node1:   host: 192.168.1.10   user: root   passwd: xxxooo

   

格式:

:    # ID,用于salt-ssh引用host:     # IP或域名user:     # 登录用户名passwd:   # 登录密码    # 可选参数port:     # 自定义的端口sudo:     # 是否允许sudo到root,默认不允许priv:     # ssh登录key路径,默认为salt-ssh.rsatimeout:  # 等待超时

执行salt-ssh提示需要输入y,那么多要输入y,总不能手动输入吧。

root@iZ23f6c5z8tZ:~# salt-ssh 'node1' -r 'pwd'

解决办法: 

root@iZ23f6c5z8tZ:~# touch /root/.ssh/config  root@iZ23f6c5z8tZ:~# cat /root/.ssh/config host 121.42.137.107 StrictHostKeyChecking no

再次使用salt-ssh

root@iZ23f6c5z8tZ:~# salt-ssh 'node1' -r 'free -m'node1:                 total       used       free     shared    buffers     cached    Mem:          7983        767       7215          0         23        575    -/+ buffers/cache:        168       7815    Swap:            0          0          0

使用salt-ssh安装salt-minion

root@iZ23f6c5z8tZ:~# salt-ssh 'node1' -r 'apt-get install salt-minion -y'node1:    Reading package lists...    Building dependency tree...    Reading state information...    salt-minion is already the newest version.    0 upgraded, 0 newly installed, 0 to remove and 158 not upgraded