Saltstack 介绍、安装、配置(一)
Slatstack 介紹
官網:https://saltstack.com/
官方源:http://repo.saltstack.com/? (介紹各操作系統安裝方法)
centos 6源
yum install https://repo.saltstack.com/yum/redhat/salt-repo-latest-1.el6.noarch.rpmcentos 7 源
yum install https://repo.saltstack.com/yum/redhat/salt-repo-latest-1.el7.noarch.rpmhttp://repo.saltstack.com/yum/redhat/7/x86_64
基于python開發,提供REST API接口
三大功能: 遠程執行、配置管理(狀態)、云管理
其它:Puppet(ruby)、ansible(python)
四種運行方式:Local、Minion/Master(C/S)、Syndic(代理,類似zabbix proxy)、Salt SSH
?
快速安裝
?- 安裝
服務端
yum install salt-master salt-minion -y客戶端
yum install salt-minion -y啟動服務端
systemctl start salt-master配置客戶端
vim /etc/salt/minion master: 192.168.137.11 # 配置master地址 id: # 每臺主機的唯一標識,不配置默認為主機名啟動客戶端
systemctl start salt-minion啟動后/etc/salt下生成minion_id文件,默認為主機名
如果修改id,需要刪除minion_id
?
?- master和minion啟動后pki介紹
第一次啟動minion在/etc/salt下生成pki文件目錄
包含minion的公鑰minion.pub和私鑰minion.pem
第一次啟動master在/etc/salt下生成pki文件目錄
包含master的公鑰master.pub和私鑰master.pem
linux-node1.example.com和linux-node2.example.com為minion的公鑰,名稱為id名
minions_pre為預認證目錄
?
?- 認證
salt-keyAccepted Keys 已同意的key
Denied Keys 拒絕的key
Unaccepted Keys 未認證的key
salt-key -a linux-node1.example.com指定linux-node1.example.com這臺minion被信任
salt-key -a linux* # 通配符說明:-a :accept ,-A:accept-all,-d:delete,-D:delete-all
兩臺minion已認證成功,此時再次查看master pki文件目錄,minion的公鑰文件放入了minions目錄下
再次查看minion?pki文件目錄,存在minion_master.pub公鑰文件
?
?- 遠程執行
語法: 命令 目標 模塊.方法 方法參數
檢查所有主機狀態
salt '*' test.ping檢查指定主機狀態
salt "linux-node2.example.com" test.ping指定主機,遠程執行shell命令
salt "linux-node2.example.com" cmd.run "ls -lrt /root"重啟所有主機的zabbix agent
salt "*" cmd.run "systemctl restart zabbix-agent"?
- 狀態模塊
state 寫一個描述文件。格式:YAML ,后綴:.sls
YAML介紹(重要)
YAML是"YAML Ain't a Markup Language"(YAML不是一種置標語言)的遞歸縮寫。(可以查看百度百科介紹)
格式:數據結構可以用類似大綱的縮排方式呈現,結構通過縮進來表示,連續的項目通過減號“-”來表示,map結構里面的key/value對用冒號“:”來分隔。
樣例如下:
salt管理理解YAML介紹?https://docs.saltstack.com/en/latest/topics/yaml/index.html
salt YAML三個規則:
1)縮進,需要用2個空格,不能使用Tab鍵;
2)冒號,冒號和縮進共用、鍵值對(中間有空格)
3)短橫線, 于后面的值有空格
?
- master配置
vim /etc/salt/master file_roots # 定義base、測試、灰度、生產環境配置文件路徑,base名稱不能改重啟master
systemctl restart salt-master
創建配置文件目錄
cd /srv mkdir salt?
?- sls文件創建
apache.sls,放入到/srv/salt/web目錄下
apache-install: # 自定義的id,名稱pkg.installed: # 狀態模塊,salt自帶的, 模塊.方法- names: # 參數- httpd- httpd-develapache-service: # 自定義的id,名稱service.running: # 狀態模塊,salt自帶的, 模塊.方法- name: httpd # 參數- enable: True
執行這個文件
salt "*" state.sls web.apache執行流程:
1)master將這個文件發送至minion
2)minion放在/var/cache/salt/minion目錄下
3)minion根據這個文件從上往下執行
執行結果
1 linux-node2.example.com: 2 ---------- 3 ID: apache-install 4 Function: pkg.installed 5 Name: httpd 6 Result: True 7 Comment: The following packages were installed/updated: httpd 8 Started: 13:12:23.142622 9 Duration: 103093.75 ms 10 Changes: 11 ---------- 12 apr: 13 ---------- 14 new: 15 1.4.8-3.el7 16 old: 17 apr-util: 18 ---------- 19 new: 20 1.5.2-6.el7 21 old: 22 httpd: 23 ---------- 24 new: 25 2.4.6-40.el7.centos.4 26 old: 27 httpd-tools: 28 ---------- 29 new: 30 2.4.6-40.el7.centos.4 31 old: 32 mailcap: 33 ---------- 34 new: 35 2.1.41-2.el7 36 old: 37 ---------- 38 ID: apache-install 39 Function: pkg.installed 40 Name: httpd-devel 41 Result: True 42 Comment: The following packages were installed/updated: httpd-devel 43 Started: 13:14:06.266419 44 Duration: 75699.845 ms 45 Changes: 46 ---------- 47 apr-devel: 48 ---------- 49 new: 50 1.4.8-3.el7 51 old: 52 apr-util-devel: 53 ---------- 54 new: 55 1.5.2-6.el7 56 old: 57 cyrus-sasl-devel: 58 ---------- 59 new: 60 2.1.26-20.el7_2 61 old: 62 expat-devel: 63 ---------- 64 new: 65 2.1.0-8.el7 66 old: 67 httpd-devel: 68 ---------- 69 new: 70 2.4.6-40.el7.centos.4 71 old: 72 libdb-devel: 73 ---------- 74 new: 75 5.3.21-19.el7 76 old: 77 openldap-devel: 78 ---------- 79 new: 80 2.4.40-9.el7_2 81 old: 82 ---------- 83 ID: apache-service 84 Function: service.running 85 Name: httpd 86 Result: True 87 Comment: Service httpd has been enabled, and is running 88 Started: 13:15:22.549732 89 Duration: 509.773 ms 90 Changes: 91 ---------- 92 httpd: 93 True 94 95 Summary for linux-node2.example.com 96 ------------ 97 Succeeded: 3 (changed=3) 98 Failed: 0 99 ------------ 100 Total states run: 3 101 Total run time: 179.303 s 102 linux-node1.example.com: 103 ---------- 104 ID: apache-install 105 Function: pkg.installed 106 Name: httpd 107 Result: True 108 Comment: Package httpd is already installed 109 Started: 21:12:17.773014 110 Duration: 1030.017 ms 111 Changes: 112 ---------- 113 ID: apache-install 114 Function: pkg.installed 115 Name: httpd-devel 116 Result: True 117 Comment: The following packages were installed/updated: httpd-devel 118 Started: 21:12:18.803216 119 Duration: 179505.346 ms 120 Changes: 121 ---------- 122 apr-devel: 123 ---------- 124 new: 125 1.4.8-3.el7 126 old: 127 apr-util-devel: 128 ---------- 129 new: 130 1.5.2-6.el7 131 old: 132 cyrus-sasl-devel: 133 ---------- 134 new: 135 2.1.26-20.el7_2 136 old: 137 expat-devel: 138 ---------- 139 new: 140 2.1.0-8.el7 141 old: 142 httpd-devel: 143 ---------- 144 new: 145 2.4.6-40.el7.centos.4 146 old: 147 libdb-devel: 148 ---------- 149 new: 150 5.3.21-19.el7 151 old: 152 openldap-devel: 153 ---------- 154 new: 155 2.4.40-9.el7_2 156 old: 157 ---------- 158 ID: apache-service 159 Function: service.running 160 Name: httpd 161 Result: True 162 Comment: The service httpd is already running 163 Started: 21:15:18.523234 164 Duration: 62.391 ms 165 Changes: 166 167 Summary for linux-node1.example.com 168 ------------ 169 Succeeded: 3 (changed=1) 170 Failed: 0 171 ------------ 172 Total states run: 3 173 Total run time: 180.598 s View Code?
- top file
默認文件名top.sls,放在base目錄下,base目錄在file_roots配置項配置
通過top.sls文件可以實現根據不同的minion執行不同的sls文件
base: # 固定名稱,必填'linux-node1.example.com': # minion id- web.apache # apache.sls'linux-node2.example.com':- web.apache salt "*" state.highstate上面命令執行state高級狀態,它只會執行入口文件top.sls, 根據top文件中內容執行
生產環境中不建議使用*,需要指定具體主機,先用test測試
salt "linux-node1.example.com" state.highstate test=True測試正常后執行
salt "linux-node1.example.com" state.highstate?
總結
以上是生活随笔為你收集整理的Saltstack 介绍、安装、配置(一)的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: mybatis.xml中sql编写规范
- 下一篇: mysqlworkdbench 查看执行
