码迷,mamicode.com
首页 > 其他好文 > 详细

Saltstack_实战指南02_各主机Pillar信息指定

时间:2019-05-30 21:54:24      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:指南   http   backup   tps   code   serve   结构   keepalive   files   

 

1. 实战项目GitHub地址

该项目已经放在了GitHub上,地址如下:

https://github.com/zhanglianghhh/salt-example-lnmp

技术图片

 

2. 主机规划

技术图片

 

3. pillar的整体目录结构

 1 [root@salt150-master pillar]# pwd
 2 /srv/pillar
 3 [root@salt150-master pillar]# ll
 4 total 4
 5 drwxr-xr-x 2 root root  62 Mar 10 17:27 base
 6 drwxr-xr-x 2 root root  83 Mar 10 17:39 prod
 7 -rw-r--r-- 1 root root 183 Mar 10 17:42 top.sls
 8 [root@salt150-master pillar]# tree 
 9 .
10 ├── base
11 │   ├── database.sls
12 │   ├── monitor.sls
13 │   └── nosql.sls
14 ├── prod
15 │   ├── high_available.sls
16 │   ├── program.sls
17 │   ├── proxy.sls
18 │   └── web.sls
19 └── top.sls
20 
21 2 directories, 8 files

 

4. Pillar的top.sls 文件信息

 1 [root@salt150-master pillar]# cat top.sls 
 2 base:
 3   *:
 4     # base 目录
 5     - base.database
 6     - base.nosql
 7     - base.monitor
 8     # prod 目录
 9     - prod.web
10     - prod.program
11     - prod.proxy
12     - prod.high_available

 

5. base基础信息

 1 [root@salt150-master base]# pwd
 2 /srv/pillar/base
 3 [root@salt150-master base]# ll
 4 total 12
 5 -rw-r--r-- 1 root root 258 Mar 10 17:27 database.sls
 6 -rw-r--r-- 1 root root 272 Mar 10 17:20 monitor.sls
 7 -rw-r--r-- 1 root root  99 Mar 10 17:25 nosql.sls
 8 [root@salt150-master base]# cat database.sls 
 9 # 数据库信息
10 # 包含配置文件信息
11 # 注意和 zabbix pillar 不同 的写法
12 {% if grains[host] == salt03-web %}
13 database_info:
14   database: mysql
15   role: master
16   server-id: 1
17   read_only: "OFF"
18 {% elif grains[host] == salt04-web %}
19 database_info:
20   database: mysql
21   role: slave
22   server-id: 2
23   read_only: "ON"
24 {% elif grains[host] == salt05-web %}
25 database_info:
26   database: mysql
27   role: slave
28   server-id: 3
29   read_only: "ON"
30 {% elif grains[host] == salt150-master %}
31 database_info:
32   database: mariadb
33   read_only: "OFF"
34 {% endif %}
35 
36 [root@salt150-master base]# cat nosql.sls 
37 # nosql 信息
38 {% if grains[host] == salt05-web %}
39 nosql_info:
40   nosql: memcached
41 {% endif %}
42 
43 [root@salt150-master base]# cat monitor.sls 
44 # 其中 salt150-maste 172.16.1.150 机器,不仅是 zabbix 客户端,还是服务端
45 # 只包含 zabbix 的属性 【服务端 客户端】
46 monitor_info:
47   monitor:
48     {% if grains[host] == salt150-master %}
49     zabbix_server: True
50     {% endif %}
51     zabbix_agent: True
52     zabbix_server_hostname: salt150-master

 

6. prod业务组件信息

 1 [root@salt150-master prod]# pwd
 2 /srv/pillar/prod
 3 [root@salt150-master prod]# ll
 4 total 16
 5 -rw-r--r-- 1 root root 326 Mar 10 17:39 high_available.sls
 6 -rw-r--r-- 1 root root 174 Mar 10 17:34 program.sls
 7 -rw-r--r-- 1 root root 148 Mar 10 17:38 proxy.sls
 8 -rw-r--r-- 1 root root 160 Mar 10 17:33 web.sls
 9 [root@salt150-master prod]# cat web.sls 
10 # web 服务器
11 {% if grains[host] == salt03-web or grains[host] == salt04-web or grains[host] == salt05-web %}
12 web_info:
13   web: nginx
14 {% endif %}
15 
16 [root@salt150-master prod]# cat program.sls 
17 # 使用的编程语言
18 {% if grains[host] == salt03-web or grains[host] == salt04-web or grains[host] == salt05-web %}
19 program_info:
20   program: php
21 {% endif %}
22 
23 [root@salt150-master prod]# cat proxy.sls 
24 # 负载均衡服务器
25 {% if grains[host] == salt01-haproxy or grains[host] == salt02-haproxy %}
26 proxy_info:
27   proxy: haproxy
28 {% endif %}
29 
30 [root@salt150-master prod]# cat high_available.sls 
31 # 高可用keepalived 的 pillar 信息
32 {% if grains[host] == salt01-haproxy %}
33 high_available_info:
34   high_available: keepalived
35   high_state: MASTER
36   high_priority: 100
37 {% elif grains[host] == salt02-haproxy %}
38 high_available_info:
39   high_available: keepalived
40   high_state: BACKUP
41   high_priority: 50
42 {% endif %}

 

7. pillar信息生效

 1 [root@salt150-master pillar]# salt * saltutil.refresh_pillar
 2 salt02-haproxy:
 3     True
 4 salt01-haproxy:
 5     True
 6 salt05-web:
 7     True
 8 salt03-web:
 9     True
10 salt150-master:
11     True
12 salt04-web:
13     True

 

8. pillar信息查看

  1 [root@salt150-master pillar]# salt * pillar.items  
  2 salt05-web:
  3     ----------
  4     database_info:
  5         ----------
  6         database:
  7             mysql
  8         read_only:
  9             ON
 10         role:
 11             slave
 12         server-id:
 13             3
 14     monitor_info:
 15         ----------
 16         monitor:
 17             ----------
 18             zabbix_agent:
 19                 True
 20             zabbix_server_hostname:
 21                 salt150-master
 22     nosql_info:
 23         ----------
 24         nosql:
 25             memcached
 26     program_info:
 27         ----------
 28         program:
 29             php
 30     web_info:
 31         ----------
 32         web:
 33             nginx
 34 salt02-haproxy:
 35     ----------
 36     high_available_info:
 37         ----------
 38         high_available:
 39             keepalived
 40         high_priority:
 41             50
 42         high_state:
 43             BACKUP
 44     monitor_info:
 45         ----------
 46         monitor:
 47             ----------
 48             zabbix_agent:
 49                 True
 50             zabbix_server_hostname:
 51                 salt150-master
 52     proxy_info:
 53         ----------
 54         proxy:
 55             haproxy
 56 salt03-web:
 57     ----------
 58     database_info:
 59         ----------
 60         database:
 61             mysql
 62         read_only:
 63             OFF
 64         role:
 65             master
 66         server-id:
 67             1
 68     monitor_info:
 69         ----------
 70         monitor:
 71             ----------
 72             zabbix_agent:
 73                 True
 74             zabbix_server_hostname:
 75                 salt150-master
 76     program_info:
 77         ----------
 78         program:
 79             php
 80     web_info:
 81         ----------
 82         web:
 83             nginx
 84 salt04-web:
 85     ----------
 86     database_info:
 87         ----------
 88         database:
 89             mysql
 90         read_only:
 91             ON
 92         role:
 93             slave
 94         server-id:
 95             2
 96     monitor_info:
 97         ----------
 98         monitor:
 99             ----------
100             zabbix_agent:
101                 True
102             zabbix_server_hostname:
103                 salt150-master
104     program_info:
105         ----------
106         program:
107             php
108     web_info:
109         ----------
110         web:
111             nginx
112 salt01-haproxy:
113     ----------
114     high_available_info:
115         ----------
116         high_available:
117             keepalived
118         high_priority:
119             100
120         high_state:
121             MASTER
122     monitor_info:
123         ----------
124         monitor:
125             ----------
126             zabbix_agent:
127                 True
128             zabbix_server_hostname:
129                 salt150-master
130     proxy_info:
131         ----------
132         proxy:
133             haproxy
134 salt150-master:
135     ----------
136     database_info:
137         ----------
138         database:
139             mariadb
140         read_only:
141             OFF
142     monitor_info:
143         ----------
144         monitor:
145             ----------
146             zabbix_agent:
147                 True
148             zabbix_server:
149                 True
150             zabbix_server_hostname:
151                 salt150-master

 

9. 说明

1 其他的就不单独写文章了,都是之前讲解过的。
2 该实战项目中有些细节补充,结合之前所学,即可达到整体实战目的。项目实战代码请参见开头的GitHub地址。
3 如果阅读后有些地方不清楚,可以结合之前的《Saltstack_使用指南_系列》进行参考。

 

技术图片

 

Saltstack_实战指南02_各主机Pillar信息指定

标签:指南   http   backup   tps   code   serve   结构   keepalive   files   

原文地址:https://www.cnblogs.com/zhanglianghhh/p/10952198.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!