SaltStack入门篇(一)之SaltStack部署

一、SaltStack概述

Salt,,一种全新的基础设施管理方式,部署轻松,在几分钟内可运行起来,扩展性好,很容易管理上万台服务器,速度够快,服务器之间秒级通讯。

salt底层采用动态的连接总线, 使其可以用于编配, 远程执行, 配置管理等等.

多种配置管理工具对比: 
Puppet(rubby开发,现在很少使用) 
ansible(python开发,轻量级,没有agent,大规模环境下使用ssh会很慢,串行传输) 
Saltstack(python开发,远程执行、配置管理、事件驱动基础设施、使用saltcloud可以管理私有云和公有云)

官方文档:https://docs.saltstack.com/en/getstarted/; 
官方提供官方yum源:repo.slatstack.com–>可以使用cobbler自定义yum仓库进行同步 
官方安装源:http://repo.saltstack.com/2016.11.html#rhel; 
Saltstack组件: 
SaltMaster 
SaltMinion 
Execution Modules

环境说明:

主机名                  IP地址        说明          系统
linux-node1.example.com    192.168.56.11    模式:master    Centos 7.4 x86_64
linux-node2.example.com    192.168.56.12    模式:minion    Centos 7.4 x86_64

二、SaltStack安装

1.安装指定的yum源

[root@linux-node1 ~]# yum install https://repo.saltstack.com/yum/redhat/salt-repo-2016.11-2.el7.noarch.rpm
[root@linux-node2 ~]# yum install https://repo.saltstack.com/yum/redhat/salt-repo-2016.11-2.el7.noarch.rpm 

2.安装salt-master和salt-minion

[root@linux-node1 ~]# yum install -y salt-master
[root@linux-node1 ~]# yum install -y salt-minion
[root@linux-node2 ~]# yum install -y salt-minion

3.修改minion配置并启动

[root@linux-node1 ~]# systemctl start salt-master    #启动salt-master
[root@linux-node1 ~]# vim /etc/salt/minion           #配置salt-minion
master: 192.168.56.11      #可以是主机名需要解析(指定服务端的IP地址),冒号有空格
id:   唯一标识符,可以不配,不配默认就是主机名
[root@linux-node1 ~]# systemctl start salt-minion    #启动salt-minion
[root@linux-node2 salt]# vim minion
master: 192.168.56.11      #可以是主机名需要解析(指定服务端的IP地址),冒号有空格
id:   唯一标识符,可以不配,不配默认就是主机名
[root@linux-node2 salt]# systemctl start salt-minion

minion配置中有一个id配置,默认是hostname,如果id配置和hostname不一致会导致无法进行通信,那么当hostname做了修改,或者错误的时候该怎么配置呢?
①关闭salt-minion  
②salt-key -d id  在master上删除minion的id  
③minion上删除pki目录 
④minion上删除minion_id文件
⑤修改完成,启动minion
#此处必须先停掉minion修改,并删除相应的文件,否则会默认地去查找原先的配置,已踩坑

#以下是刚装完查看minion_id变成了www.test123.com。进行修改成linux-node2.example.com
[root@linux-node2 salt]# cat minion_id 
www.test123.com
[root@linux-node2 salt]# systemctl stop salt-minion
[root@linux-node2 salt]# rm -rf pki
[root@linux-node2 salt]# rm -rf minion_id 
[root@linux-node2 salt]# systemctl start salt-minion
[root@linux-node2 salt]# cat minion_id 
linux-node2.example.com

4.配置说明

[root@linux-node2 salt]# ll
总用量 124
-rw-r----- 1 root root  2624 9月  15 23:19 cloud
drwxr-xr-x 2 root root     6 9月  16 00:41 cloud.conf.d
drwxr-xr-x 2 root root     6 9月  16 00:41 cloud.deploy.d
drwxr-xr-x 2 root root     6 9月  16 00:41 cloud.maps.d
drwxr-xr-x 2 root root     6 9月  16 00:41 cloud.profiles.d
drwxr-xr-x 2 root root     6 9月  16 00:41 cloud.providers.d
-rw-r----- 1 root root 46034 9月  15 23:19 master
drwxr-xr-x 2 root root     6 9月  16 00:41 master.d
-rw-r----- 1 root root 35101 1月  16 10:29 minion
drwxr-xr-x 2 root root    27 1月  16 11:47 minion.d
-rw-r--r-- 1 root root    23 1月  16 11:45 minion_id
drwxr-xr-x 3 root root    19 1月  16 11:45 pki
-rw-r----- 1 root root 26984 9月  15 23:19 proxy
drwxr-xr-x 2 root root     6 9月  16 00:41 proxy.d
-rw-r----- 1 root root   344 9月  15 23:19 roster

说明:
(1)salt-minion首次启动会在/etc/salt/pki/minion目录下生成公钥和秘钥
[root@linux-node2 salt]# ll /etc/salt/pki/minion/
总用量 12
-rw-r--r-- 1 root root  450 1月  16 11:47 minion_master.pub
-r-------- 1 root root 1674 1月  16 11:45 minion.pem
-rw-r--r-- 1 root root  450 1月  16 11:45 minion.pub

(2)并且在salt-master的/etc/salt/pki/master/minion_pre中存放了salt-minion的公钥。
[root@linux-node1 ~]# ll /etc/salt/pki/master/minions_pre/
linux-node1.example.com
linux-node2.example.com

5.配置salt-master和slat-minion通信

[root@linux-node1 salt]# salt-key
Accepted Keys:       同意的
Denied Keys:                拒绝的
Unaccepted Keys:            等待同意的
linux-node1.example.com
linux-node2.example.com
Rejected Keys:

同意认证的方法:
分为三种:

[root@linux-node1 salt]# salt-key -A
[root@linux-node1 salt]# salt-key -a 指定id
[root@linux-node1 salt]# salt-key -a 支持通配符
[root@linux-node1 master]# salt-key -a linux*
The following keys are going to be accepted:
Unaccepted Keys:
linux-node1.example.com
linux-node2.example.com
Proceed? [n/Y] Y
Key for minion linux-node1.example.com accepted.
Key for minion linux-node2.example.com accepted.

salt-key 命令参数介绍
-L  列出所有
-d 删除指定的支持通配符
-D 删除所有
-A 添加所有
-a 指定添加

同意之后生成的文件
pki/
├── master
│   ├── master.pem
│   ├── master.pub
│   ├── minions
│   │   ├── linux-node1.example.com
│   │   └── linux-node2.example.com
│   ├── minions_autosign
│   ├── minions_denied
│   ├── minions_pre
│   └── minions_rejected
└── minion
    ├── minion_master.pub  同意之后master发送公钥
    ├── minion.pem
    └── minion.pub

猜你喜欢

转载自www.cnblogs.com/linuxk/p/9273290.html