服务器名称
操作系统版本
内网IP
外网IP(模拟)
Hostname
部署模块
salt100
CentOS7.5
172.16.1.100
10.0.0.100
salt-master、salt-minion
salt01
172.16.1.11
10.0.0.11
salt-minion
salt02
172.16.1.12
10.0.0.12
salt03
172.16.1.13
10.0.0.13
Saltstack文档
1 https://docs.saltstack.com/en/latest/contents.html
salt100、salt01、salt02、salt03的hosts文件都追加如下信息。
这样主机名相互之间可以解析。
1 [root@salt100 ~]# cat /etc/hosts 2 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 3 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 4 5 172.16.1.11 salt01 6 172.16.1.12 salt02 7 172.16.1.13 salt03 8 172.16.1.14 salt04 9 172.16.1.15 salt0510 172.16.1.100 salt100
说明:
1、 运维人员使用的登录账号;
2、 所有的业务都放在 /app/ 下「yun用户的家目录」,避免业务数据乱放;
3、 该用户也可用于后期salt-ssh使用,因为几乎所有的生产环境都是禁止root远程登录的(因此进行了 sudo 提权)。
1 # 使用一个专门的用户,避免直接使用root用户2 # 添加用户、指定家目录并指定用户密码3 useradd -u 1050 -d /app yun && echo '123456' | /usr/bin/passwd --stdin yun4 # sudo提权5 echo "yun ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers6 # 让其它普通用户可以进入该目录查看信息7 chmod 755 /app/
运维三板斧
监控
执行
配置管理
Saltstack四种运行方式
Local
Minion/Master C/S
Syndic 代理方式
Salt SSH
官方镜像源查询
1 https://repo.saltstack.com/
安装镜像源
在salt100、salt01、salt02、salt03机器上执行
1 yum install -y https://repo.saltstack.com/yum/redhat/salt-repo-latest-2.el7.noarch.rpm
根据规划在salt100安装salt的master和minion,在其他机器安装salt的minion。
在salt100上操作
yum install -y salt-master salt-minion
在salt01、salt02、salt03上操作
yum install -y salt-minion
版本查看
1 [root@salt100 ~]# salt --version # master版本查看2 salt 2018.3.3 (Oxygen)3 [root@salt100 ~]# salt-minion --version # minion版本查看4 salt-minion 2018.3.3 (Oxygen)
在salt100上执行,无需任务配置修改
1 [root@salt100 ~]# systemctl start salt-master.service
在salt100、salt01、salt02、salt03上操作
配置修改原因:
1、 minion端指向的master是哪个
2、 minion端的ID是什么
1 [root@salt100 salt]# pwd 2 /etc/salt 3 [root@salt100 salt]# vim minion 4 ……………… 5 # 可以是IP或者hostname 6 # 如果是hostname那么必须能够解析【最佳实践配置为 主机名】 7 master: salt100 8 ……………… 9 # Explicitly declare the id for this minion to use, if left commented the id10 # will be the hostname as returned by the python call: socket.getfqdn()11 # Since salt uses detached ids it is possible to run multiple minions on the12 # same machine but with different ids, this can be useful for salt compute13 # clusters.14 # 如果id不配置,那么默认为hostname15 # 如果下次要更改该配置,那么要把 /etc/salt/minion_id 也给删除掉,并重启客户端【会生成一个新的minion_id】16 #id:17 ………………
1 [root@salt100 ~]# systemctl start salt-minion.service
master开机自启动
systemctl enable salt-master.service
minion开机自启动
1 systemctl enable salt-minion.service
salt100上的信息
1 [root@salt100 salt]# pwd 2 /etc/salt 3 [root@salt100 salt]# ll 4 total 128 5 -rw-r----- 1 root root 2926 Oct 8 23:56 cloud 6 drwxr-xr-x 2 root root 6 Oct 9 00:42 cloud.conf.d 7 drwxr-xr-x 2 root root 6 Oct 9 00:42 cloud.deploy.d 8 drwxr-xr-x 2 root root 6 Oct 9 00:42 cloud.maps.d 9 drwxr-xr-x 2 root root 6 Oct 9 00:42 cloud.profiles.d10 drwxr-xr-x 2 root root 6 Oct 9 00:42 cloud.providers.d11 -rw-r----- 1 root root 51532 Oct 8 23:56 master12 drwxr-xr-x 2 root root 6 Oct 9 00:42 master.d13 -rw-r----- 1 root root 36072 Nov 25 23:01 minion14 drwxr-xr-x 2 root root 6 Oct 9 00:42 minion.d15 -rw-r--r-- 1 root root 7 Nov 25 23:05 minion_id16 drwxr-xr-x 4 root root 34 Nov 25 22:41 pki17 -rw-r----- 1 root root 28162 Oct 8 23:56 proxy18 drwxr-xr-x 2 root root 6 Oct 9 00:42 proxy.d19 -rw-r----- 1 root root 344 Oct 8 23:56 roster20 [root@salt100 salt]# tree pki/21 pki/22 ├── master23 │ ├── master.pem24 │ ├── master.pub25 │ ├── minions26 │ ├── minions_autosign27 │ ├── minions_denied28 │ ├── minions_pre # master还未进一步认证【接受或拒绝】,minion的公钥都先放在这里29 │ │ ├── salt0130 │ │ ├── salt0231 │ │ ├── salt0332 │ │ └── salt10033 │ └── minions_rejected34 └── minion35 ├── minion.pem36 └── minion.pub37 38 7 directories, 8 files
salt03上的信息
1 [root@salt03 salt]# pwd 2 /etc/salt 3 [root@salt03 salt]# ll 4 total 128 5 -rw-r----- 1 root root 2926 Oct 8 23:56 cloud 6 drwxr-xr-x 2 root root 6 Oct 9 00:42 cloud.conf.d 7 drwxr-xr-x 2 root root 6 Oct 9 00:42 cloud.deploy.d 8 drwxr-xr-x 2 root root 6 Oct 9 00:42 cloud.maps.d 9 drwxr-xr-x 2 root root 6 Oct 9 00:42 cloud.profiles.d10 drwxr-xr-x 2 root root 6 Oct 9 00:42 cloud.providers.d11 -rw-r----- 1 root root 51532 Oct 8 23:56 master12 drwxr-xr-x 2 root root 6 Oct 9 00:42 master.d13 -rw-r----- 1 root root 36000 Nov 25 23:12 minion14 drwxr-xr-x 2 root root 6 Oct 9 00:42 minion.d15 -rw-r--r-- 1 root root 6 Nov 25 23:12 minion_id16 drwxr-xr-x 4 root root 34 Nov 25 22:41 pki17 -rw-r----- 1 root root 28162 Oct 8 23:56 proxy18 drwxr-xr-x 2 root root 6 Oct 9 00:42 proxy.d19 -rw-r----- 1 root root 344 Oct 8 23:56 roster20 [root@salt03 salt]# tree pki/21 pki/22 ├── master23 └── minion24 ├── minion.pem25 └── minion.pub26 27 2 directories, 2 files
salt100上的salt-key信息
1 [root@salt100 salt]# salt-key 2 Accepted Keys:3 Denied Keys:4 Unaccepted Keys:5 salt016 salt027 salt038 salt1009 Rejected Keys:
1 [root@salt100 salt]# salt-key -a salt01 # 单个接受 2 The following keys are going to be accepted: 3 Unaccepted Keys: 4 salt01 5 Proceed? [n/Y] y 6 Key for minion salt01 accepted. 7 [root@salt100 salt]# salt-key 8 Accepted Keys: 9 salt0110 Denied Keys:11 Unaccepted Keys:12 salt0213 salt0314 salt10015 Rejected Keys:
1 [root@salt100 salt]# salt-key -a salt0* 2 The following keys are going to be accepted: 3 Unaccepted Keys: 4 salt02 5 salt03 6 Proceed? [n/Y] y 7 Key for minion salt02 accepted. 8 Key for minion salt03 accepted. 9 [root@salt100 salt]# salt-key 10 Accepted Keys:11 salt0112 salt0213 salt0314 Denied Keys:15 Unaccepted Keys:16 salt10017 Rejected Keys:
1 [root@salt100 salt]# salt-key -A 2 The following keys are going to be accepted: 3 Unaccepted Keys: 4 salt100 5 Proceed? [n/Y] y 6 Key for minion salt100 accepted. 7 [root@salt100 salt]# salt-key 8 Accepted Keys: 9 salt0110 salt0211 salt0312 salt10013 Denied Keys:14 Unaccepted Keys:15 Rejected Keys:
1 [root@salt100 salt]# pwd 2 /etc/salt 3 [root@salt100 salt]# tree pki/ 4 pki/ 5 ├── master 6 │ ├── master.pem 7 │ ├── master.pub 8 │ ├── minions # minion的公钥从minions_pre 移到了此目录 9 │ │ ├── salt0110 │ │ ├── salt0211 │ │ ├── salt0312 │ │ └── salt10013 │ ├── minions_autosign14 │ ├── minions_denied15 │ ├── minions_pre16 │ └── minions_rejected17 └── minion18 ├── minion_master.pub # 接受了来自master的公钥19 ├── minion.pem20 └── minion.pub21 22 7 directories, 9 files
1 [root@salt03 salt]# tree pki/2 pki/3 ├── master4 └── minion5 ├── minion_master.pub # 接受了来自master的公钥6 ├── minion.pem7 └── minion.pub8 9 2 directories, 3 files
1 [root@salt100 salt]# salt '*' test.ping # 看master可以控制哪些minion 2 salt02:3 True4 salt03:5 True6 salt01:7 True8 salt100:9 True
完毕!
原文链接:http://www.cnblogs.com/zhanglianghhh/p/10597456.html
本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728