Saltstack_使用指南01_部署

 

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 https://docs.saltstack.com/en/latest/contents.html    

 

1.1. 机器hosts文件修改

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    salt05
10 172.16.1.100   salt100

 

 

2. 添加用户账号

说明:

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 yun
4 # sudo提权
5 echo "yun  ALL=(ALL)       NOPASSWD: ALL" >>  /etc/sudoers
6 # 让其它普通用户可以进入该目录查看信息
7 chmod 755 /app/

 

运维三板斧

监控

执行

配置管理

 

Saltstack四种运行方式

Local

Minion/Master    C/S

Syndic  代理方式

Salt SSH

 

 

3. SaltStack部署

3.1. 镜像源安装

官方镜像源查询

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

 

3.2. saltstack安装

根据规划在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)

 

 

4. 服务端启动

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

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

 

 

5. 客户端启动

在salt100、salt01、salt02、salt03上操作

 

5.1. 修改minion配置文件

配置修改原因:

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 id
10 # 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 the
12 # same machine but with different ids, this can be useful for salt compute
13 # clusters.
14 # 如果id不配置,那么默认为hostname
15 # 如果下次要更改该配置,那么要把 /etc/salt/minion_id 也给删除掉,并重启客户端【会生成一个新的minion_id】
16 #id:
17 ………………

 

5.2. 启动minion服务

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

 

 

6. 加入开机自启动

master开机自启动

systemctl enable salt-master.service

 

minion开机自启动

1 systemctl enable salt-minion.service

 

 

7. master接受minion

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

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

 

salt100上的salt-key信息

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

 

7.2. master接受minion

7.2.1. 单个接受

 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 salt01
10 Denied Keys:
11 Unaccepted Keys:
12 salt02
13 salt03
14 salt100
15 Rejected Keys:

 

7.2.2. 通配符接受

 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 salt01
12 salt02
13 salt03
14 Denied Keys:
15 Unaccepted Keys:
16 salt100
17 Rejected Keys:

 

7.2.3. 接受所有minion

 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 salt01
10 salt02
11 salt03
12 salt100
13 Denied Keys:
14 Unaccepted Keys:
15 Rejected Keys:

 

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

salt100上的信息

 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 │   │   ├── salt01
10 │   │   ├── salt02
11 │   │   ├── salt03
12 │   │   └── salt100
13 │   ├── minions_autosign
14 │   ├── minions_denied
15 │   ├── minions_pre
16 │   └── minions_rejected
17 └── minion
18     ├── minion_master.pub  # 接受了来自master的公钥
19     ├── minion.pem
20     └── minion.pub
21 
22 7 directories, 9 files

 

salt03上的信息

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

 

 

8. 测试结果

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

 

完毕!

 

posted on 2019-03-25 23:02  踏歌行666  阅读(446)  评论(0编辑  收藏  举报

导航