1.SaltStack安装部署及主从认证

SaltStack四种运行方式

  1. Local
  2. Minion/Master C/S架构
  3. Syndic
  4. Salt SSH 无需在客户端安装agent,只需要ssh

windows服务器只能部署Minion 不能部署Master

一、安装部署

minion被控端192.168.202.25 hostname:test2
master节点192.168.202.24 hostname:test1

https://repo.saltproject.io/#rhel #可根据salt文档进行安装

192.168.202.24上操作:
[root@test1 ~]# sudo rpm --import https://repo.saltproject.io/py3/redhat/7/x86_64/3004/SALTSTACK-GPG-KEY.pub

[root@test1 ~]# curl -fsSL https://repo.saltproject.io/py3/redhat/7/x86_64/3004.repo | sudo tee /etc/yum.repos.d/salt.repo

[root@test1 ~]# cat /etc/yum.repos.d/salt.repo 
[salt-3004-repo]
name=Salt repo for RHEL/CentOS 7 PY3
baseurl=https://repo.saltproject.io/py3/redhat/7/x86_64/3004
skip_if_unavailable=True
failovermethod=priority
enabled=1
enabled_metadata=1
gpgcheck=1
gpgkey=https://repo.saltproject.io/py3/redhat/7/x86_64/3004/SALTSTACK-GPG-KEY.pub, https://repo.saltproject.io/py3/redhat/7/x86_64/3004/base/RPM-GPG-KEY-CentOS-7

[root@test1 ~]# sudo yum clean expire-cache

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

[root@test1 ~]# vim /etc/salt/minion
 master: 192.168.202.24

配置开机自启动

[root@test1 ~]# sudo systemctl enable salt-master && sudo systemctl start salt-master
Created symlink from /etc/systemd/system/multi-user.target.wants/salt-master.service to /usr/lib/systemd/system/salt-master.service.
[root@test1 ~]# sudo systemctl enable salt-minion && sudo systemctl start salt-minion
Created symlink from /etc/systemd/system/multi-user.target.wants/salt-minion.service to /usr/lib/systemd/system/salt-minion.service.
192.168.202.25上操作:
[root@test2 ~]# sudo rpm --import https://repo.saltproject.io/py3/redhat/7/x86_64/3004/SALTSTACK-GPG-KEY.pub

[root@test2 ~]# curl -fsSL https://repo.saltproject.io/py3/redhat/7/x86_64/3004.repo | sudo tee /etc/yum.repos.d/salt.repo

[root@test2 ~]# sudo yum clean expire-cache

[root@test2 ~]# yum -y install salt-minion

[root@test1 ~]# vim /etc/salt/minion
 master: 192.168.202.24
 
配置开机自启动
[root@test2 ~]# sudo systemctl enable salt-minion && sudo systemctl start salt-minion
Created symlink from /etc/systemd/system/multi-user.target.wants/salt-minion.service to /usr/lib/systemd/system/salt-minion.service.

二、Master/Minion认证过程

首先我们在192.168.202.25查看

[root@test2 ~]# cd /etc/salt/
[root@test2 salt]# tree pki/
pki/
├── master
└── minion
    ├── minion.pem                ##发现pki/minion目录下有两个文件  pem私钥 pub公钥 要想实现和master通信就要将minion.pub发送给master
    └── minion.pub

然后我们在192.168.202.24查看

[root@test1 ~]# cd /etc/salt/
[root@test1 salt]# tree pki/
pki/
├── master
│   ├── master.pem         ##因为192.168.202.24上同时安装了master和minion 所以master也会生成两个秘钥文件
│   ├── master.pub
│   ├── minions
│   ├── minions_autosign
│   ├── minions_denied
│   ├── minions_pre        ##master/minion_pre目录下有两个minion的公钥文件  
│   │   ├── test1
│   │   └── test2
│   └── minions_rejected
└── minion                 ##192.168.202.24上也安装了minion 所以生成了minion的两个秘钥文件
    ├── minion.pem
    └── minion.pub

7 directories, 6 files

通过查看以上文件内容我们大概知道master和minion之间是如何认证的。

那么,我们在minion配置文件里配置了master的ip地址,同样master节点也要认证要管理哪些节点。并不是你minion单方同意我就管理你,而我master也要同意。

[root@test1 salt]# salt-key            ##master上执行salt-key可以查看
Accepted Keys:    已允许的key
Denied Keys:      已拒绝的key
Unaccepted Keys:   未允许的key:有test1和test2
test1
test2
Rejected Keys:
    
[root@test1 salt]# salt-key -a test1        ##允许单个节点 salt-key -a "节点名称"
The following keys are going to be accepted:
Unaccepted Keys:
test1
Proceed? [n/Y] y
Key for minion test1 accepted.

 
[root@test1 salt]# salt-key -a test*        ##允许多个节点 可以使用通配符
The following keys are going to be accepted:
Unaccepted Keys:
test2
Proceed? [n/Y] y
Key for minion test2 accepted.

 
[root@test1 salt]# salt-key                #再次查看 发现test1和test2都已经被允许了
Accepted Keys:
test1
test2
Denied Keys:
Unaccepted Keys:
Rejected Keys:

关于salt-key命令的更多语法可以使用 salt-key --help查看帮助

常用参数:
salt-key -a:允许单个
salt-key -A:允许所有
salt-key -d:删除单个
salt-key -D:删除所有

经过刚才master上使用salt-key认证后,文件也发生了变化 我们再看下:

[root@test1 salt]# tree pki/        #再次查看pki目录
pki/
├── master
│   ├── master.pem
│   ├── master.pub
│   ├── minions                    ##master/minions目录下有了test1和test2 表示认可这两个节点是自己的minion
│   │   ├── test1
│   │   └── test2
│   ├── minions_autosign
│   ├── minions_denied
│   ├── minions_pre
│   └── minions_rejected
└── minion                        ##minion目录下多了一个minion_master.pub 这个文件时master的公钥  表示双方已经互相信任。
    ├── minion_master.pub
    ├── minion.pem
    └── minion.pub

7 directories, 7 files
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

二郎5

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值