经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 数据库/运维 » Linux/Shell » 查看文章
Saltstack_使用指南01_部署
来源:cnblogs  作者:踏歌行666  时间:2019/3/26 8:36:35  对本文有异议

 

1. 主机规划

服务器名称

操作系统版本

内网IP

外网IP(模拟)

Hostname

部署模块

salt100

CentOS7.5

172.16.1.100

10.0.0.100

salt100

salt-master、salt-minion

salt01

CentOS7.5

172.16.1.11

10.0.0.11

salt01

salt-minion

salt02

CentOS7.5

172.16.1.12

10.0.0.12

salt02

salt-minion

salt03

CentOS7.5

172.16.1.13

10.0.0.13

salt03

salt-minion

 

Saltstack文档

  1. 1 https://docs.saltstack.com/en/latest/contents.html

 

1.1. 机器hosts文件修改

salt100、salt01、salt02、salt03的hosts文件都追加如下信息。

这样主机名相互之间可以解析。

  1. 1 [root@salt100 ~]# cat /etc/hosts
  2. 2 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
  3. 3 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  4. 4
  5. 5 172.16.1.11 salt01
  6. 6 172.16.1.12 salt02
  7. 7 172.16.1.13 salt03
  8. 8 172.16.1.14 salt04
  9. 9 172.16.1.15 salt05
  10. 10 172.16.1.100 salt100

 

 

2. 添加用户账号

说明:

1、  运维人员使用的登录账号;

2、  所有的业务都放在 /app/ 下「yun用户的家目录」,避免业务数据乱放;

3、  该用户也可用于后期salt-ssh使用,因为几乎所有的生产环境都是禁止root远程登录的(因此进行了 sudo 提权)。

  1. 1 # 使用一个专门的用户,避免直接使用root用户
  2. 2 # 添加用户、指定家目录并指定用户密码
  3. 3 useradd -u 1050 -d /app yun && echo '123456' | /usr/bin/passwd --stdin yun
  4. 4 # sudo提权
  5. 5 echo "yun ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
  6. 6 # 让其它普通用户可以进入该目录查看信息
  7. 7 chmod 755 /app/

 

运维三板斧

监控

执行

配置管理

 

Saltstack四种运行方式

Local

Minion/Master    C/S

Syndic  代理方式

Salt SSH

 

 

3. SaltStack部署

3.1. 镜像源安装

官方镜像源查询

  1. 1 https://repo.saltstack.com/

 

安装镜像源

在salt100、salt01、salt02、salt03机器上执行

  1. 1 yum install -y https://repo.saltstack.com/yum/redhat/salt-repo-latest-2.el7.noarch.rpm

 

3.2. saltstack安装

根据规划在salt100安装salt的master和minion,在其他机器安装salt的minion。

在salt100上操作

  1. yum install -y salt-master salt-minion

 

在salt01、salt02、salt03上操作

  1. yum install -y salt-minion

 

版本查看

  1. 1 [root@salt100 ~]# salt --version # master版本查看
  2. 2 salt 2018.3.3 (Oxygen)
  3. 3 [root@salt100 ~]# salt-minion --version # minion版本查看
  4. 4 salt-minion 2018.3.3 (Oxygen)

 

 

4. 服务端启动

在salt100上执行,无需任务配置修改

  1. 1 [root@salt100 ~]# systemctl start salt-master.service

 

 

5. 客户端启动

在salt100、salt01、salt02、salt03上操作

 

5.1. 修改minion配置文件

配置修改原因:

1、  minion端指向的master是哪个

2、  minion端的ID是什么

  1. 1 [root@salt100 salt]# pwd
  2. 2 /etc/salt
  3. 3 [root@salt100 salt]# vim minion
  4. 4 ………………
  5. 5 # 可以是IP或者hostname
  6. 6 # 如果是hostname那么必须能够解析【最佳实践配置为 主机名】
  7. 7 master: salt100
  8. 8 ………………
  9. 9 # Explicitly declare the id for this minion to use, if left commented the id
  10. 10 # will be the hostname as returned by the python call: socket.getfqdn()
  11. 11 # Since salt uses detached ids it is possible to run multiple minions on the
  12. 12 # same machine but with different ids, this can be useful for salt compute
  13. 13 # clusters.
  14. 14 # 如果id不配置,那么默认为hostname
  15. 15 # 如果下次要更改该配置,那么要把 /etc/salt/minion_id 也给删除掉,并重启客户端【会生成一个新的minion_id】
  16. 16 #id:
  17. 17 ………………

 

5.2. 启动minion服务

  1. 1 [root@salt100 ~]# systemctl start salt-minion.service

 

 

6. 加入开机自启动

master开机自启动

  1. systemctl enable salt-master.service

 

minion开机自启动

  1. 1 systemctl enable salt-minion.service

 

 

7. master接受minion

7.1. master和minion启动后生成的pki信息

salt100上的信息

  1. 1 [root@salt100 salt]# pwd
  2. 2 /etc/salt
  3. 3 [root@salt100 salt]# ll
  4. 4 total 128
  5. 5 -rw-r----- 1 root root 2926 Oct 8 23:56 cloud
  6. 6 drwxr-xr-x 2 root root 6 Oct 9 00:42 cloud.conf.d
  7. 7 drwxr-xr-x 2 root root 6 Oct 9 00:42 cloud.deploy.d
  8. 8 drwxr-xr-x 2 root root 6 Oct 9 00:42 cloud.maps.d
  9. 9 drwxr-xr-x 2 root root 6 Oct 9 00:42 cloud.profiles.d
  10. 10 drwxr-xr-x 2 root root 6 Oct 9 00:42 cloud.providers.d
  11. 11 -rw-r----- 1 root root 51532 Oct 8 23:56 master
  12. 12 drwxr-xr-x 2 root root 6 Oct 9 00:42 master.d
  13. 13 -rw-r----- 1 root root 36072 Nov 25 23:01 minion
  14. 14 drwxr-xr-x 2 root root 6 Oct 9 00:42 minion.d
  15. 15 -rw-r--r-- 1 root root 7 Nov 25 23:05 minion_id
  16. 16 drwxr-xr-x 4 root root 34 Nov 25 22:41 pki
  17. 17 -rw-r----- 1 root root 28162 Oct 8 23:56 proxy
  18. 18 drwxr-xr-x 2 root root 6 Oct 9 00:42 proxy.d
  19. 19 -rw-r----- 1 root root 344 Oct 8 23:56 roster
  20. 20 [root@salt100 salt]# tree pki/
  21. 21 pki/
  22. 22 ├── master
  23. 23 ├── master.pem
  24. 24 ├── master.pub
  25. 25 ├── minions
  26. 26 ├── minions_autosign
  27. 27 ├── minions_denied
  28. 28 ├── minions_pre # master还未进一步认证【接受或拒绝】,minion的公钥都先放在这里
  29. 29 ├── salt01
  30. 30 ├── salt02
  31. 31 ├── salt03
  32. 32 └── salt100
  33. 33 └── minions_rejected
  34. 34 └── minion
  35. 35 ├── minion.pem
  36. 36 └── minion.pub
  37. 37
  38. 38 7 directories, 8 files

 

salt03上的信息

  1. 1 [root@salt03 salt]# pwd
  2. 2 /etc/salt
  3. 3 [root@salt03 salt]# ll
  4. 4 total 128
  5. 5 -rw-r----- 1 root root 2926 Oct 8 23:56 cloud
  6. 6 drwxr-xr-x 2 root root 6 Oct 9 00:42 cloud.conf.d
  7. 7 drwxr-xr-x 2 root root 6 Oct 9 00:42 cloud.deploy.d
  8. 8 drwxr-xr-x 2 root root 6 Oct 9 00:42 cloud.maps.d
  9. 9 drwxr-xr-x 2 root root 6 Oct 9 00:42 cloud.profiles.d
  10. 10 drwxr-xr-x 2 root root 6 Oct 9 00:42 cloud.providers.d
  11. 11 -rw-r----- 1 root root 51532 Oct 8 23:56 master
  12. 12 drwxr-xr-x 2 root root 6 Oct 9 00:42 master.d
  13. 13 -rw-r----- 1 root root 36000 Nov 25 23:12 minion
  14. 14 drwxr-xr-x 2 root root 6 Oct 9 00:42 minion.d
  15. 15 -rw-r--r-- 1 root root 6 Nov 25 23:12 minion_id
  16. 16 drwxr-xr-x 4 root root 34 Nov 25 22:41 pki
  17. 17 -rw-r----- 1 root root 28162 Oct 8 23:56 proxy
  18. 18 drwxr-xr-x 2 root root 6 Oct 9 00:42 proxy.d
  19. 19 -rw-r----- 1 root root 344 Oct 8 23:56 roster
  20. 20 [root@salt03 salt]# tree pki/
  21. 21 pki/
  22. 22 ├── master
  23. 23 └── minion
  24. 24 ├── minion.pem
  25. 25 └── minion.pub
  26. 26
  27. 27 2 directories, 2 files

 

salt100上的salt-key信息

  1. 1 [root@salt100 salt]# salt-key
  2. 2 Accepted Keys:
  3. 3 Denied Keys:
  4. 4 Unaccepted Keys:
  5. 5 salt01
  6. 6 salt02
  7. 7 salt03
  8. 8 salt100
  9. 9 Rejected Keys:

 

7.2. master接受minion

7.2.1. 单个接受

  1. 1 [root@salt100 salt]# salt-key -a salt01 # 单个接受
  2. 2 The following keys are going to be accepted:
  3. 3 Unaccepted Keys:
  4. 4 salt01
  5. 5 Proceed? [n/Y] y
  6. 6 Key for minion salt01 accepted.
  7. 7 [root@salt100 salt]# salt-key
  8. 8 Accepted Keys:
  9. 9 salt01
  10. 10 Denied Keys:
  11. 11 Unaccepted Keys:
  12. 12 salt02
  13. 13 salt03
  14. 14 salt100
  15. 15 Rejected Keys:

 

7.2.2. 通配符接受

  1. 1 [root@salt100 salt]# salt-key -a salt0*
  2. 2 The following keys are going to be accepted:
  3. 3 Unaccepted Keys:
  4. 4 salt02
  5. 5 salt03
  6. 6 Proceed? [n/Y] y
  7. 7 Key for minion salt02 accepted.
  8. 8 Key for minion salt03 accepted.
  9. 9 [root@salt100 salt]# salt-key
  10. 10 Accepted Keys:
  11. 11 salt01
  12. 12 salt02
  13. 13 salt03
  14. 14 Denied Keys:
  15. 15 Unaccepted Keys:
  16. 16 salt100
  17. 17 Rejected Keys:

 

7.2.3. 接受所有minion

  1. 1 [root@salt100 salt]# salt-key -A
  2. 2 The following keys are going to be accepted:
  3. 3 Unaccepted Keys:
  4. 4 salt100
  5. 5 Proceed? [n/Y] y
  6. 6 Key for minion salt100 accepted.
  7. 7 [root@salt100 salt]# salt-key
  8. 8 Accepted Keys:
  9. 9 salt01
  10. 10 salt02
  11. 11 salt03
  12. 12 salt100
  13. 13 Denied Keys:
  14. 14 Unaccepted Keys:
  15. 15 Rejected Keys:

 

7.3. master接受minion之后的pki信息

salt100上的信息

  1. 1 [root@salt100 salt]# pwd
  2. 2 /etc/salt
  3. 3 [root@salt100 salt]# tree pki/
  4. 4 pki/
  5. 5 ├── master
  6. 6 ├── master.pem
  7. 7 ├── master.pub
  8. 8 ├── minions # minion的公钥从minions_pre 移到了此目录
  9. 9 ├── salt01
  10. 10 ├── salt02
  11. 11 ├── salt03
  12. 12 └── salt100
  13. 13 ├── minions_autosign
  14. 14 ├── minions_denied
  15. 15 ├── minions_pre
  16. 16 └── minions_rejected
  17. 17 └── minion
  18. 18 ├── minion_master.pub # 接受了来自master的公钥
  19. 19 ├── minion.pem
  20. 20 └── minion.pub
  21. 21
  22. 22 7 directories, 9 files

 

salt03上的信息

  1. 1 [root@salt03 salt]# tree pki/
  2. 2 pki/
  3. 3 ├── master
  4. 4 └── minion
  5. 5 ├── minion_master.pub # 接受了来自master的公钥
  6. 6 ├── minion.pem
  7. 7 └── minion.pub
  8. 8
  9. 9 2 directories, 3 files

 

 

8. 测试结果

  1. 1 [root@salt100 salt]# salt '*' test.ping # 看master可以控制哪些minion
  2. 2 salt02:
  3. 3 True
  4. 4 salt03:
  5. 5 True
  6. 6 salt01:
  7. 7 True
  8. 8 salt100:
  9. 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

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号