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
完畢!
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章