一、SaltStack概述
Salt,,一种全新的基础设施管理方式,部署轻松,在几分钟内可运行起来,扩展性好,很容易管理上万台服务器,速度够快,服务器之间秒级通讯。
salt底层采用动态的连接总线, 使其可以用于编配, 远程执行, 配置管理等等.
多种配置管理工具对比: Puppet(rubby开发,现在很少使用) ansible(python开发,轻量级,没有agent,大规模环境下使用ssh会很慢,串行传输) Saltstack(python开发,远程执行、配置管理、事件驱动基础设施、使用saltcloud可以管理私有云和公有云)
官方文档:https://docs.saltstack.com/en/getstarted/; 官方提供官方yum源:repo.slatstack.com–>可以使用cobbler自定义yum仓库进行同步 官方安装源:http://repo.saltstack.com/2016.11.html#rhel; Saltstack组件: SaltMaster SaltMinion Execution Modules
环境说明:
1主机名 IP地址 说明 系统 2linux-node1.example.com 192.168.56.11 模式:master Centos 7.4 x86_64 3linux-node2.example.com 192.168.56.12 模式:minion Centos 7.4 x86_64
二、SaltStack安装
1.安装指定的yum源
1[root@linux-node1 ~]# yum install https://repo.saltstack.com/yum/redhat/salt-repo-2016.11-2.el7.noarch.rpm 2[root@linux-node2 ~]# yum install https://repo.saltstack.com/yum/redhat/salt-repo-2016.11-2.el7.noarch.rpm
2.安装salt-master和salt-minion
1[root@linux-node1 ~]# yum install -y salt-master 2[root@linux-node1 ~]# yum install -y salt-minion 3[root@linux-node2 ~]# yum install -y salt-minion
3.修改minion配置并启动
1[root@linux-node1 ~]# systemctl start salt-master #启动salt-master 2[root@linux-node1 ~]# vim /etc/salt/minion #配置salt-minion 3master: 192.168.56.11 #可以是主机名需要解析(指定服务端的IP地址),冒号有空格 4id: 唯一标识符,可以不配,不配默认就是主机名 5[root@linux-node1 ~]# systemctl start salt-minion #启动salt-minion 6[root@linux-node2 salt]# vim minion 7master: 192.168.56.11 #可以是主机名需要解析(指定服务端的IP地址),冒号有空格 8id: 唯一标识符,可以不配,不配默认就是主机名 9[root@linux-node2 salt]# systemctl start salt-minion 10 11minion配置中有一个id配置,默认是hostname,如果id配置和hostname不一致会导致无法进行通信,那么当hostname做了修改,或者错误的时候该怎么配置呢? 12①关闭salt-minion 13②salt-key -d id 在master上删除minion的id 14③minion上删除pki目录 15④minion上删除minion_id文件 16⑤修改完成,启动minion 17#此处必须先停掉minion修改,并删除相应的文件,否则会默认地去查找原先的配置,已踩坑 18 19#以下是刚装完查看minion_id变成了www.test123.com。进行修改成linux-node2.example.com 20[root@linux-node2 salt]# cat minion_id 21www.test123.com 22[root@linux-node2 salt]# systemctl stop salt-minion 23[root@linux-node2 salt]# rm -rf pki 24[root@linux-node2 salt]# rm -rf minion_id 25[root@linux-node2 salt]# systemctl start salt-minion 26[root@linux-node2 salt]# cat minion_id 27linux-node2.example.com
4.配置说明
1[root@linux-node2 salt]# ll 2总用量 124 3-rw-r----- 1 root root 2624 9月 15 23:19 cloud 4drwxr-xr-x 2 root root 6 9月 16 00:41 cloud.conf.d 5drwxr-xr-x 2 root root 6 9月 16 00:41 cloud.deploy.d 6drwxr-xr-x 2 root root 6 9月 16 00:41 cloud.maps.d 7drwxr-xr-x 2 root root 6 9月 16 00:41 cloud.profiles.d 8drwxr-xr-x 2 root root 6 9月 16 00:41 cloud.providers.d 9-rw-r----- 1 root root 46034 9月 15 23:19 master 10drwxr-xr-x 2 root root 6 9月 16 00:41 master.d 11-rw-r----- 1 root root 35101 1月 16 10:29 minion 12drwxr-xr-x 2 root root 27 1月 16 11:47 minion.d 13-rw-r--r-- 1 root root 23 1月 16 11:45 minion_id 14drwxr-xr-x 3 root root 19 1月 16 11:45 pki 15-rw-r----- 1 root root 26984 9月 15 23:19 proxy 16drwxr-xr-x 2 root root 6 9月 16 00:41 proxy.d 17-rw-r----- 1 root root 344 9月 15 23:19 roster 18 19说明: 20(1)salt-minion首次启动会在/etc/salt/pki/minion目录下生成公钥和秘钥 21[root@linux-node2 salt]# ll /etc/salt/pki/minion/ 22总用量 12 23-rw-r--r-- 1 root root 450 1月 16 11:47 minion_master.pub 24-r-------- 1 root root 1674 1月 16 11:45 minion.pem 25-rw-r--r-- 1 root root 450 1月 16 11:45 minion.pub 26 27(2)并且在salt-master的/etc/salt/pki/master/minion_pre中存放了salt-minion的公钥。 28[root@linux-node1 ~]# ll /etc/salt/pki/master/minions_pre/ 29linux-node1.example.com 30linux-node2.example.com
5.配置salt-master和slat-minion通信
1[root@linux-node1 salt]# salt-key 2Accepted Keys: 同意的 3Denied Keys: 拒绝的 4Unaccepted Keys: 等待同意的 5linux-node1.example.com 6linux-node2.example.com 7Rejected Keys: 8 9同意认证的方法: 10分为三种: 11 12[root@linux-node1 salt]# salt-key -A 13[root@linux-node1 salt]# salt-key -a 指定id 14[root@linux-node1 salt]# salt-key -a 支持通配符 15[root@linux-node1 master]# salt-key -a linux* 16The following keys are going to be accepted: 17Unaccepted Keys: 18linux-node1.example.com 19linux-node2.example.com 20Proceed? [n/Y] Y 21Key for minion linux-node1.example.com accepted. 22Key for minion linux-node2.example.com accepted. 23 24salt-key 命令参数介绍 25-L 列出所有 26-d 删除指定的支持通配符 27-D 删除所有 28-A 添加所有 29-a 指定添加 30 31同意之后生成的文件 32pki/ 33├── master 34│ ├── master.pem 35│ ├── master.pub 36│ ├── minions 37│ │ ├── linux-node1.example.com 38│ │ └── linux-node2.example.com 39│ ├── minions_autosign 40│ ├── minions_denied 41│ ├── minions_pre 42│ └── minions_rejected 43└── minion 44 ├── minion_master.pub 同意之后master发送公钥 45 ├── minion.pem 46 └── minion.pub