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 salt01 salt-minion
salt03 CentOS7.5 172.16.1.13 10.0.0.13 salt01 salt-minion
Saltstack文档

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

1.1. 机器hosts文件修改

salt100、salt01、salt02、salt03的hosts文件都追加如下信息。
这样主机名相互之间可以解析。

[root@salt100 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

172.16.1.11    salt01
172.16.1.12    salt02
172.16.1.13    salt03
172.16.1.14    salt04
172.16.1.15    salt05
172.16.1.100   salt100

2. 添加用户账号

说明:

1、 运维人员使用的登录账号;
2、 所有的业务都放在 /app/ 下「yun用户的家目录」,避免业务数据乱放;
3、 该用户也可用于后期salt-ssh使用,因为几乎所有的生产环境都是禁止root远程登录的(因此进行了 sudo 提权)。

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

监控
执行
配置管理

Saltstack四种运行方式

Local
Minion/Master C/S
Syndic 代理方式
Salt SSH

3. SaltStack部署

3.1. 镜像源安装

官方镜像源查询

https://repo.saltstack.com/

Saltstack_使用指南01_部署

安装镜像源

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

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 
版本查看
[root@salt100 ~]# salt --version   # master版本查看
salt 2018.3.3 (Oxygen)
[root@salt100 ~]# salt-minion --version   # minion版本查看
salt-minion 2018.3.3 (Oxygen)

4. 服务端启动

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

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

5. 客户端启动

在salt100、salt01、salt02、salt03上操作

5.1. 修改minion配置文件

配置修改原因:

1、 minion端指向的master是哪个
2、 minion端的ID是什么

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

5.2. 启动minion服务

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

6. 加入开机自启动

master开机自启动
systemctl enable salt-master.service
minion开机自启动
systemctl enable salt-minion.service

7. master接受minion

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

salt100上的信息
[root@salt100 salt]# pwd
/etc/salt
[root@salt100 salt]# ll
total 128
-rw-r----- 1 root root  2926 Oct  8 23:56 cloud
drwxr-xr-x 2 root root     6 Oct  9 00:42 cloud.conf.d
drwxr-xr-x 2 root root     6 Oct  9 00:42 cloud.deploy.d
drwxr-xr-x 2 root root     6 Oct  9 00:42 cloud.maps.d
drwxr-xr-x 2 root root     6 Oct  9 00:42 cloud.profiles.d
drwxr-xr-x 2 root root     6 Oct  9 00:42 cloud.providers.d
-rw-r----- 1 root root 51532 Oct  8 23:56 master
drwxr-xr-x 2 root root     6 Oct  9 00:42 master.d
-rw-r----- 1 root root 36072 Nov 25 23:01 minion
drwxr-xr-x 2 root root     6 Oct  9 00:42 minion.d
-rw-r--r-- 1 root root     7 Nov 25 23:05 minion_id
drwxr-xr-x 4 root root    34 Nov 25 22:41 pki
-rw-r----- 1 root root 28162 Oct  8 23:56 proxy
drwxr-xr-x 2 root root     6 Oct  9 00:42 proxy.d
-rw-r----- 1 root root   344 Oct  8 23:56 roster
[root@salt100 salt]# tree pki/
pki/
├── master
│   ├── master.pem
│   ├── master.pub
│   ├── minions
│   ├── minions_autosign
│   ├── minions_denied
│   ├── minions_pre   # master还未进一步认证【接受或拒绝】,minion的公钥都先放在这里
│   │   ├── salt01
│   │   ├── salt02
│   │   ├── salt03
│   │   └── salt100
│   └── minions_rejected
└── minion
    ├── minion.pem
    └── minion.pub

7 directories, 8 files
salt03上的信息
[root@salt03 salt]# pwd
/etc/salt
[root@salt03 salt]# ll
total 128
-rw-r----- 1 root root  2926 Oct  8 23:56 cloud
drwxr-xr-x 2 root root     6 Oct  9 00:42 cloud.conf.d
drwxr-xr-x 2 root root     6 Oct  9 00:42 cloud.deploy.d
drwxr-xr-x 2 root root     6 Oct  9 00:42 cloud.maps.d
drwxr-xr-x 2 root root     6 Oct  9 00:42 cloud.profiles.d
drwxr-xr-x 2 root root     6 Oct  9 00:42 cloud.providers.d
-rw-r----- 1 root root 51532 Oct  8 23:56 master
drwxr-xr-x 2 root root     6 Oct  9 00:42 master.d
-rw-r----- 1 root root 36000 Nov 25 23:12 minion
drwxr-xr-x 2 root root     6 Oct  9 00:42 minion.d
-rw-r--r-- 1 root root     6 Nov 25 23:12 minion_id
drwxr-xr-x 4 root root    34 Nov 25 22:41 pki
-rw-r----- 1 root root 28162 Oct  8 23:56 proxy
drwxr-xr-x 2 root root     6 Oct  9 00:42 proxy.d
-rw-r----- 1 root root   344 Oct  8 23:56 roster
[root@salt03 salt]# tree pki/
pki/
├── master
└── minion
    ├── minion.pem
    └── minion.pub

2 directories, 2 files
salt100上的salt-key信息
[root@salt100 salt]# salt-key 
Accepted Keys:
Denied Keys:
Unaccepted Keys:
salt01
salt02
salt03
salt100
Rejected Keys:

Saltstack_使用指南01_部署

7.2. master接受minion

7.2.1. 单个接受

[root@salt100 salt]# salt-key -a salt01  # 单个接受
The following keys are going to be accepted:
Unaccepted Keys:
salt01
Proceed? [n/Y] y
Key for minion salt01 accepted.
[root@salt100 salt]# salt-key 
Accepted Keys:
salt01
Denied Keys:
Unaccepted Keys:
salt02
salt03
salt100
Rejected Keys:

Saltstack_使用指南01_部署

7.2.2. 通配符接受

[root@salt100 salt]# salt-key -a salt0*
The following keys are going to be accepted:
Unaccepted Keys:
salt02
salt03
Proceed? [n/Y] y
Key for minion salt02 accepted.
Key for minion salt03 accepted.
[root@salt100 salt]# salt-key 
Accepted Keys:
salt01
salt02
salt03
Denied Keys:
Unaccepted Keys:
salt100
Rejected Keys:

Saltstack_使用指南01_部署

7.2.3. 接受所有minion

[root@salt100 salt]# salt-key -A
The following keys are going to be accepted:
Unaccepted Keys:
salt100
Proceed? [n/Y] y
Key for minion salt100 accepted.
[root@salt100 salt]# salt-key 
Accepted Keys:
salt01
salt02
salt03
salt100
Denied Keys:
Unaccepted Keys:
Rejected Keys:

Saltstack_使用指南01_部署

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

salt100上的信息
[root@salt100 salt]# pwd
/etc/salt
[root@salt100 salt]# tree pki/
pki/
├── master
│   ├── master.pem
│   ├── master.pub
│   ├── minions   # minion的公钥从minions_pre 移到了此目录
│   │   ├── salt01
│   │   ├── salt02
│   │   ├── salt03
│   │   └── salt100
│   ├── minions_autosign
│   ├── minions_denied
│   ├── minions_pre
│   └── minions_rejected
└── minion
    ├── minion_master.pub  # 接受了来自master的公钥
    ├── minion.pem
    └── minion.pub

7 directories, 9 files
salt03上的信息
[root@salt03 salt]# tree pki/
pki/
├── master
└── minion
    ├── minion_master.pub  # 接受了来自master的公钥
    ├── minion.pem
    └── minion.pub

2 directories, 3 files

8. 测试结果

[root@salt100 salt]# salt '*' test.ping  # 看master可以控制哪些minion 
salt02:
    True
salt03:
    True
salt01:
    True
salt100:
    True
完毕!
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章