Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2765746
  • 博文数量: 154
  • 博客积分: 7136
  • 博客等级: 准将
  • 技术积分: 1428
  • 用 户 组: 管理员
  • 注册时间: 2010-02-21 11:26
文章分类

全部博文(154)

文章存档

2016年(2)

2014年(2)

2013年(4)

2012年(16)

2011年(51)

2010年(68)

2009年(3)

2006年(3)

2005年(5)

分类: 系统运维

2016-06-27 10:07:11

原文地址:Centos7.2部署saltstack 作者:hugh_liu

参考文档:

1.    Saltstack安装文档:

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

一.环境

ServerCentOS Linux release 7.2.1511 (Core)

Salt-master172.18.12.201

Salt-minion172.18.12.204

二.Saltstack安装与配置

1.  yum安装

Salt-master安装:

点击(此处)折叠或打开

  1. [root@localhost ~]# yum install https://repo.saltstack.com/yum/redhat/salt-repo-latest-1.el7.noarch.rpm
  2. [root@localhost ~]# yum clean expire-cache
  3. [root@localhost ~]# yum install salt-master

Salt-minion安装,最后一步安装组件有区别:

点击(此处)折叠或打开

  1. [root@localhost ~]# yum install salt-minion

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

CentOS7.2默认自带firewall,无iptable

点击(此处)折叠或打开

  1. [root@localhost ~]# systemctl stop firewalld.service
  2. [root@localhost ~]# systemctl disable firewalld.service
  3. [root@localhost ~]# yum install iptables-services –y
  4. [root@localhost ~]# systemctl enable iptables.service
  5. [root@localhost ~]# systemctl restart iptables.service
  6. [root@localhost ~]# vim /etc/sysconfig/iptables
  7. -A INPUT -p tcp -m state --state NEW -m tcp --dport 4505 -j ACCEPT
  8. -A INPUT -p tcp -m state --state NEW -m tcp --dport 4506 -j ACCEPT

#移除系统自带firewall的开机启动,安装iptable,设置iptable开机启动;

#tcp4506salt-master发送命令信息的端口,tcp4506salt-minion返回信息的端口;

# Salt-minion可不做防火墙处理,默认iptable规则即可。

3.  salt-master配置

点击(此处)折叠或打开

  1. [root@localhost ~]# sed -i 's/#interface: 0.0.0.0/interface: 172.18.12.201/g' /etc/salt/master
  2. [root@localhost ~]# sed -i 's/#hash_type: md5/hash_type: sha256/g' /etc/salt/master
  3. [root@localhost ~]# sed -i 's/#auto_accept: False/auto_accept: True/g' /etc/salt/master

#interface参数绑定master的通信ip,默认可不变更,表示所有主机ip

#hash_type参数默认可不变更,salt-master也可启动,但启动后有告警如下:

点击(此处)折叠或打开

  1. [WARNING ] IMPORTANT: Do not use md5 hashing Please set "hash_type" to sha256 in Salt Master

#auto_accept参数是自动认证开关,默认关闭,使用salt-key确认证书信任。

4.  salt-minion配置

点击(此处)折叠或打开

  1. [root@localhost ~]# sed -i 's/#master: salt/master: 172.18.12.201/g' /etc/salt/minion
  2. [root@localhost ~]# sed -i 's/#hash_type: sha256/hash_type: sha256/g' /etc/salt/master
  3. [root@localhost ~]# sed -i 's/#id:/id: 172.18.12.204/g' /etc/salt/minion

#master参数指定master ip (或者主机名)必配参数,如果minion启动时不能解析到master 主机,启动会失败;

#hash_type参数同master

#id参数设置salt-minion名,默认设置,minion名取主机hostname中设定的主机名

5.  启动服务

启动salt-master

点击(此处)折叠或打开

  1. [root@localhost ~]# systemctl enable salt-master.service
  2. [root@localhost ~]# systemctl start salt-master.service
  3. [root@localhost ~]# systemctl status salt-master.service

#设置开机启动,启动后查看状态,如下:

#启动中有问题可通过”systemctl status salt-master.service””salt-mater -l debug”等命令定位故障,下面salt-minion相同。

启动salt-minion

点击(此处)折叠或打开

  1. [root@localhost ~]# systemctl enable salt-minion.service
  2. [root@localhost ~]# systemctl start salt-minion.service
  3. [root@localhost ~]# systemctl status salt-mionion.service

#设置开机启动,启动后查看状态,如下:

6.  验证(salt-master)

查看minion

点击(此处)折叠或打开

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

Salt-master已经设置”auto_accept”参数为”True”minion主机”172.18.12.204”已在”Acceptd Keys”(主机名为salt-minion设置的idhostname)

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

点击(此处)折叠或打开

  1. [root@localhost ~]# salt-key -A
  2. [root@localhost ~]# salt-key -a 172.18.12.204

#-A指确认”Unacceptd Keys”中的全部minion(unacceptd中的minion列表为红色,确认到accepted列表中后变为绿色)-a”Unacceptd Keys”中特定的minion

简单的命令测试

点击(此处)折叠或打开

  1. [root@localhost ~]# salt "*" test.ping

#”*”表示所有”Acceptd Keys”中的minion,也可以对特定的minion执行命令;

#返回值为”True”表示masterminion连接成功。

点击(此处)折叠或打开

  1. [root@localhost ~]# salt "*" cmd.run "iptables -nL"

#使用”cmd.run”可以执行具体的命令。

阅读(4748) | 评论(0) | 转发(0) |
0

上一篇:Centos7.2部署saltstack

下一篇:没有了

给主人留下些什么吧!~~