第八话 SaltStack 架构扩展

目录

一、Salt 的多 master 高可用架构

环境准备:

1、Salt 多 master 的原理

2、具体搭建过程

2.1 首先根据第一话的 master 安装过程安装 Salt-master

2.2 然后同步之前的 master 的配置文件、状态文件和秘钥文件到新的 master

2.3 修改 minion 的配置文件的 master 配置项,并重启 minion

2.4 重启新的 master 服务

2.5 在新的 master 服务器上查看 minion 并运行命令

二、syndic 方式扩展 Salt 的管理架构

环境准备:

1、syndic 概念

2、配置 syndic 服务器

2.1 安装配置 syndic 服务器

2.2 修改 syndic 服务器的 master 配置文件指向上级 master 的地址

2.3 配置上级 master 服务

2.4 配置下级 minion 服务器

2.5 在 syndic 服务器上接受所有连接的 minion 的key

2.6 在 master 端接受所有的 syndic

3、测试 master 服务器通过 syndic 管理 minion

三、Salt 的无 master 模式

四、Salt-ssh 实现无 master 管理 minion


一、Salt 的多 master 高可用架构

环境准备:

  master 服务端01 master 服务端02 minion 客户端01 minion 客户端02 minion 客户端03 minion 客户端04
IP 10.20.2.94 10.20.5.74 10.20.3.30 10.20.5.71 10.20.2.94 10.20.5.74

查看系统版本

# cat /etc/redhat-release

CentOS release 6.5 (Final)

CentOS Linux release 7.0.1406 (Core) CentOS release 6.5 (Final) CentOS release 6.5 (Final) CentOS release 6.5 (Final) CentOS Linux release 7.0.1406 (Core)

查看系统内核版本

# uname -r

2.6.32-431.el6.x86_64 3.10.0-123.el7.x86_64 2.6.32-888.el6.x86_64 2.6.32-431.el6.x86_64 2.6.32-431.el6.x86_64 3.10.0-123.el7.x86_64

查看selinux的状态(未关闭则先关闭)

# getenforce

Disabled Disabled Disabled Disabled Disabled Disabled

1、Salt 多 master 的原理

Salt 多 master 只需要在 minion 端配置多个 master 地址即可实现。通过扩展多 master 的方式来避免了 salt-master 的单点问题。

Salt 支持多 master 的配置,Salt 多 master方式只是让一台 minion 可以同时接受两台或多台 master 的管理而已,没有其它更多的配置。因此,多个 master 之间不会有任何感知,也没有状态同步。

如果想做高可用的多 master 架构,就需要来维护多个 master,并且让它们的配置文件、状态文件和秘钥文件完全相同,否则主从 minion 端配置多个 master 是无法实现高可用架构的。

2、具体搭建过程

2.1 首先根据第一话的 master 安装过程安装 Salt-master

## 注意如果系统版本不同,启动方式也不同

# /etc/init.d/salt-master restart          # Version6 重启
或
# service salt-master restart              # Version6 重启
 
# systemctl restart salt-master.service    # Version7 重启

2.2 然后同步之前的 master 的配置文件、状态文件和秘钥文件到新的 master

同步配置文件:

# rsync -avprP -e ssh 10.20.2.94:/etc/salt/master /etc/salt/
receiving incremental file list
master
         51,068 100%   48.70MB/s    0:00:00 (xfr#1, to-chk=0/1)
 
sent 30 bytes  received 51,151 bytes  102,362.00 bytes/sec
total size is 51,068  speedup is 1.00

同步状态文件:

# rsync -avprP -e ssh 10.20.2.94:/etc/salt/states /etc/salt/
receiving incremental file list
states/
states/dev/
states/init/
states/prod/
 
sent 27 bytes  received 110 bytes  274.00 bytes/sec
total size is 0  speedup is 0.00

同步密钥文件:

# rsync -avprP -e ssh 10.20.2.94:/etc/salt/pki/master /etc/salt/pki/
receiving incremental file list
master/
master/master.pem
          1,674 100%    1.60MB/s    0:00:00 (xfr#1, to-chk=10/12)
master/master.pub
            450 100%  439.45kB/s    0:00:00 (xfr#2, to-chk=9/12)
master/minions/
master/minions/10.20.2.94
            450 100%  439.45kB/s    0:00:00 (xfr#3, to-chk=3/12)
master/minions/10.20.3.30
            450 100%  439.45kB/s    0:00:00 (xfr#4, to-chk=2/12)
master/minions/10.20.5.71
            450 100%  439.45kB/s    0:00:00 (xfr#5, to-chk=1/12)
master/minions/10.20.5.74
            450 100%  439.45kB/s    0:00:00 (xfr#6, to-chk=0/12)
master/minions_autosign/
master/minions_denied/
master/minions_pre/
master/minions_rejected/
 
sent 149 bytes  received 4,464 bytes  9,226.00 bytes/sec
total size is 3,924  speedup is 0.85

2.3 修改 minion 的配置文件的 master 配置项,并重启 minion

## vim /etc/salt/minion(minion 端)

 master:
  - 10.20.2.94
  - 10.20.5.74

重启 minion:

# /etc/init.d/salt-minion restart          # Version6 重启
或
# service salt-minion restart              # Version6 重启
 
# systemctl restart salt-minion.service    # Version7 重启

2.4 重启新的 master 服务

## 新 master 端:

# /etc/init.d/salt-master restart          # Version6 重启
或
# service salt-master restart              # Version6 重启
 
# systemctl restart salt-master.service    # Version7 重启

2.5 在新的 master 服务器上查看 minion 并运行命令

## 新 master 端:

# salt '*' test.ping
10.20.2.94:
    True
10.20.5.74:
    True
10.20.5.71:
    True
10.20.3.30:
    True

对比:

## 原 master 端:

# salt '*' test.ping
10.20.2.94:
    True
10.20.5.74:
    True
10.20.5.71:
    True
10.20.3.30:
    True

二、syndic 方式扩展 Salt 的管理架构

环境准备:

  master 服务端01 syndic 服务端01 minion 客户端01 minion 客户端02 minion 客户端03 minion 客户端04
IP 10.20.2.94 10.20.5.74 10.20.3.30 10.20.5.71 10.20.2.94 10.20.5.74

查看系统版本

# cat /etc/redhat-release

CentOS release 6.5 (Final)

CentOS Linux release 7.0.1406 (Core) CentOS release 6.5 (Final) CentOS release 6.5 (Final) CentOS release 6.5 (Final) CentOS Linux release 7.0.1406 (Core)

查看系统内核版本

# uname -r

2.6.32-431.el6.x86_64 3.10.0-123.el7.x86_64 2.6.32-888.el6.x86_64 2.6.32-431.el6.x86_64 2.6.32-431.el6.x86_64 3.10.0-123.el7.x86_64

查看selinux的状态(未关闭则先关闭)

# getenforce

Disabled Disabled Disabled Disabled Disabled Disabled

        如果管理主机的数量非常巨大,那一台 master 性能就会出现问题,即便是多 master(Salt 下多 master 只是解决了 salt-master 单点问题,其原理是让一台 minion 可以同时接受多台 master 的管理而已),并不能缓解数量巨大的 minion 带来的性能问题。这时候就需要对 Salt 进行多级扩展,用 syndic 的方式可以完成多级扩展,syndic 的扩展架构如下图说是:

1、syndic 概念

syndic 是一种中间层,它接受来自 master 的任务,然后将任务下发给所有由 syndic 管理的机器,最后将所有 minion 执行的结果返回给 syndic,syndic 再将结果发回给 master。syndic 可以减轻 master 的压力,不需要 master 和每一台被管理的 minion 直接进行通信。

2、配置 syndic 服务器

2.1 安装配置 syndic 服务器

## syndic 端:

# 具体搭建参考第一话,以下是重要执行命令:
# yum install salt-master
# yum install salt-syndic

2.2 修改 syndic 服务器的 master 配置文件指向上级 master 的地址

## syndic 端:

syndic_master: 10.20.2.94    # 指向上级 master 服务器

重启 syndic 服务器上的 salt-master 服务:

## syndic 端:

# /etc/init.d/salt-master restart          # Version6 重启
或
# service salt-master restart              # Version6 重启
 
# systemctl restart salt-master.service    # Version7 重启

启动 syndic 服务:

## syndic 端:

# /etc/init.d/salt-syndic restart          # Version6 重启
或
# service salt-syndic restart              # Version6 重启
 
# systemctl restart salt-syndic.service    # Version7 重启

2.3 配置上级 master 服务

开启上级 master 的 order-master 设置:

## 上级 master 端:

# order_masters: False
order_masters: True

重启上级 master 服务:

## 上级 master 端:

# /etc/init.d/salt-master restart          # Version6 重启
或
# service salt-master restart              # Version6 重启
 
# systemctl restart salt-master.service    # Version7 重启

2.4 配置下级 minion 服务器

## vim /etc/salt/minion(下级 minion 端):

master: 10.20.5.74    # 指向上级 syndic 服务器

重启下级 minion 服务:

## 下级 minion 端:

# /etc/init.d/salt-minion restart          # Version6 重启
或
# service salt-minion restart              # Version6 重启
 
# systemctl restart salt-minion.service    # Version7 重启

2.5 在 syndic 服务器上接受所有连接的 minion 的key

## syndic 端:

# salt-key
Accepted Keys:
Denied Keys:
Unaccepted Keys:
10.20.5.71
10.20.5.74
Rejected Keys:
 
# salt-key -A
The following keys are going to be accepted:
Unaccepted Keys:
10.20.5.71
10.20.5.74
Proceed? [n/Y] y
Key for minion 10.20.5.71 accepted.
Key for minion 10.20.5.74 accepted.
 
# salt-key
Accepted Keys:
10.20.5.71
10.20.5.74
Denied Keys:
Unaccepted Keys:
Rejected Keys:

2.6 在 master 端接受所有的 syndic

## 上级 master 端:

# salt-key
Accepted Keys:
10.20.2.94
10.20.3.30
Denied Keys:
Unaccepted Keys:
10.20.5.74
Rejected Keys:
  
# salt-key -a 10.20.5.74
The following keys are going to be accepted:
Unaccepted Keys:
10.20.5.74
Proceed? [n/Y] y
Key for minion 10.20.5.74 accepted.
  
# salt-key
Accepted Keys:
10.20.2.94
10.20.3.30
10.20.5.74
Denied Keys:
Unaccepted Keys:
Rejected Keys:

3、测试 master 服务器通过 syndic 管理 minion

## 上级 master 端:

# salt '*' test.ping
10.20.2.94:
    True
10.20.3.30:
    True
10.20.5.71:
    True
10.20.5.74:
    True
  
# salt '10.20.5.71' test.ping
10.20.5.71:
    True

三、Salt 的无 master 模式

四、Salt-ssh 实现无 master 管理 minion

猜你喜欢

转载自blog.csdn.net/weixin_42018518/article/details/106057013
今日推荐