salt-ssh部署salt-minion

本文介绍了如何利用salt-ssh在master上安装并配置,通过脚本批量添加客户端IP,设置SSH免密登录,并详细阐述了为客户端部署salt-minion的步骤,包括使用状态文件更新yum源和配置salt-minion。
摘要由CSDN通过智能技术生成

安装与配置

在 master 上安装 salt-ssh

[root@master ~]# yum -y install salt-ssh

修改配置文件

[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/bash
while 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.info
1 192.168.47.122
2 192.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

为客户端部署salt-minion

使用状态文件部署yum源

[root@master ~]# cd /srv/salt/base/init/yum/
[root@master yum]# pwd
/srv/salt/base/init/yum
[root@master yum]# tree
.
├── files
│   ├── centos-7.repo
│   ├── centos-8.repo
│   ├── epel-7.repo
│   ├── epel-8.repo
│   ├── salt-7.repo
│   └── salt-8.repo
└── main.sls

1 directory, 7 files
[root@master yum]# cat main.sls 
{
   % if grains['os'] == 'RedHat' %}
/etc/yum.repos.d/centos-{
   {
    grains['osmajorrelease'] }}.repo:
  file.managed:
    - source: salt://init/yum/files/centos-{
   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值