阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS 7.2安装部署SaltStack

133次阅读
没有评论

共计 2966 个字符,预计需要花费 8 分钟才能阅读完成。

参考文档:

  1. Saltstack 安装文档:https://repo.saltstack.com/#rhel

SaltStack 的安装与简单配置,应用。

一.环境

Server:CentOS Linux release 7.2.1511 (Core)

Salt-master:172.18.12.201

Salt-minion:172.18.12.204

二.Saltstack 安装与配置

1. yum 安装

# Salt-master 安装:
[root@localhost ~]# yum install https://repo.saltstack.com/yum/RedHat/salt-repo-latest-1.el7.noarch.rpm
[root@localhost ~]# yum clean expire-cache
[root@localhost ~]# yum install salt-master

# Salt-minion 安装,最后一步安装组件有区别:
[root@localhost ~]# yum install salt-minion

2. 防火墙配置 (salt-master)

# CentOS7.2 默认自带 firewall,无 iptable;
# 移除系统自带 firewall 的开机启动,安装 iptable,设置 iptable 开机启动 
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# systemctl disable firewalld.service
[root@localhost ~]# yum install iptables-services –y
[root@localhost ~]# systemctl enable iptables.service
[root@localhost ~]# systemctl restart iptables.service

# tcp4506 是 salt-master 发送命令信息的端口,tcp4506 是 salt-minion 返回信息的端口;
# Salt-minion 可不做防火墙处理,默认 iptable 规则即可 
[root@localhost ~]# vim /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 4505 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 4506 -j ACCEPT

3. salt-master 配置

#interface 参数绑定 master 的通信 ip,默认可不变更,表示所有主机 ip;
[root@localhost ~]# sed -i 's/#interface: 0.0.0.0/interface: 172.18.12.201/g' /etc/salt/master

# hash_type 参数默认可不变更,salt-master 也可启动,但启动后有告警如下:
# [WARNING] IMPORTANT: Do not use md5 hashing algorithm! Please set "hash_type" to sha256 in Salt Master config!
[root@localhost ~]# sed -i 's/#hash_type: md5/hash_type: sha256/g' /etc/salt/master

# auto_accept 参数是自动认证开关,默认关闭,使用 salt-key 确认证书信任 
[root@localhost ~]# sed -i 's/#auto_accept: False/auto_accept: True/g' /etc/salt/master

4. salt-minion 配置

# master 参数指定 master 的 ip (或者主机名), 必配参数 ,如果 minion 启动时不能解析到 master 主机,启动会失败;
[root@localhost ~]# sed -i 's/#master: salt/master: 172.18.12.201/g' /etc/salt/minion

# hash_type 参数同 master;
[root@localhost ~]# sed -i 's/#hash_type: sha256/hash_type: sha256/g' /etc/salt/master

# id 参数设置 salt-minion 名,默认未设置,minio 名取主机 hostname 中设定的主机名 
[root@localhost ~]# sed -i 's/#id:/id: 172.18.12.204/g' /etc/salt/minion

5.  启动服务

启动 salt-master

# 设置开机启动,启动后查看状态;
# 启动中有问题可通过 "systemctl status salt-master.service" 与 "salt-mater -l debug" 等命令定位故障,下面 salt-minion 相同 
[root@localhost ~]# systemctl enable salt-master.service 
[root@localhost ~]# systemctl start salt-master.service
[root@localhost ~]# systemctl status salt-master.service

CentOS 7.2 安装部署 SaltStack

启动 salt-minion

# 设置开机启动,启动后查看状态 
[root@localhost ~]# systemctl enable salt-minion.service
[root@localhost ~]# systemctl start salt-minion.service
[root@localhost ~]# systemctl status salt-mionion.service

CentOS 7.2 安装部署 SaltStack 

6.  验证 (salt-master)

查看 minion 表

[root@localhost ~]# salt-key -L

CentOS 7.2 安装部署 SaltStack

Salt-master 已经设置 ”auto_accept” 参数为 ”True”,minion 主机 ”172.18.12.204″ 已在 ”Acceptd Keys” 中 (主机名为 salt-minion 设置的 id 或 hostname)。

手动认证 key(“auto_accept” 参数为 ”False” 时)

# - A 指确认 "Unacceptd Keys" 中的全部 minion(unacceptd 中的 minion 列表为红色,确认到 accepted 列表中后变为绿色)
[root@localhost ~]# salt-key -A

# - a 指 "Unacceptd Keys" 中特定的 minion
# 或 [root@localhost ~]# salt-key -a 172.18.12.204

简单的命令测试

# "*" 表示所有 "Acceptd Keys" 中的 minion,也可以对特定的 minion 执行命令;
# 返回值为 "True" 表示 master 与 minion 连接成功 
[root@localhost ~]# salt "*" test.ping

CentOS 7.2 安装部署 SaltStack

# 使用 "cmd.run" 可以执行具体的命令 
[root@localhost ~]# salt "*" cmd.run "iptables -nL"

CentOS 7.2 安装部署 SaltStack

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2017-10/147565.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-21发表,共计2966字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中