且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

salt-ssh的使用(不需要安装客户端)

更新时间:2022-09-16 13:58:39

什么情况下才使用salt-ssh,有一些比较老的红帽服务器,也有一些不方便安装salt-minion客户端。总会有一些服务器比较难安装上salt-minion的。

好了,下面来说说简单配置


默认使用roster配置文件

vim /etc/salt/roster 

1
2
3
4
5
6
7
8
9
10
11
12
13
# 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
hdd:                              //ID名字可以随便定义
  host: 10.0.0.221
  user: hdd
  passwd: 66666
  sudo: Ture

已经完成配置!下面直接使用salt-ssh

第一次运行没有添加-i,未能如期运行。

1
2
3
4
5
6
7
8
9
10
11
12
root@salt-master ~]# salt-ssh "*" -r 'free -m'
hdd:
    ----------
    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 '10.0.0.221 (10.0.0.221)' can't be established.
        ECDSA key fingerprint is b9:36:f5:d8:3a:88:94:93:43:78:8e:cb:43:78:8e:cb.
        Are you sure you want to continue connecting (yes/no)? 
[root@salt-master ~]#

添加-i参数继续执行命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
[root@salt-master ~]# salt-ssh "*" -r 'free -m' -i
hdd:
    ----------
    retcode:
        0
    stderr:
        Warning: Permanently added '10.0.0.221' (ECDSA) to the list of known hosts.
    stdout:
        hdd@10.0.0.221's password: 
                     total       used       free     shared    buffers     cached
        Mem:          7856       6698       1157         18        317       4298
        -/+ buffers/cache:       2082       5773
        Swap:         8061          0       8061
[root@salt-master ~]
[root@salt-master ~]# salt-ssh "hdd" -r 'df -h'             
hdd:
    ----------
    retcode:
        0
    stderr:
    stdout:
        Filesystem      Size  Used Avail Use% Mounted on
        udev            3.9G  4.0K  3.9G   1% /dev
        tmpfs           786M  1.5M  785M   1% /run
        /dev/sda1       910G  454G  410G  53% /
        none            4.0K     0  4.0K   0% /sys/fs/cgroup
        none            5.0M     0  5.0M   0% /run/lock
        none            3.9G   84K  3.9G   1% /run/shm
        none            100M   12K  100M   1% /run/user

但是我有一个问题,保存的密钥放在哪里呢?暂时我未有发现。


本文转自 yanconggod 51CTO博客,原文链接:http://blog.51cto.com/yanconggod/1876147