标签:指南 http backup tps code serve 结构 keepalive files
该项目已经放在了GitHub上,地址如下:
https://github.com/zhanglianghhh/salt-example-lnmp
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
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
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‘
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 %}
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
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
1 其他的就不单独写文章了,都是之前讲解过的。 2 该实战项目中有些细节补充,结合之前所学,即可达到整体实战目的。项目实战代码请参见开头的GitHub地址。 3 如果阅读后有些地方不清楚,可以结合之前的《Saltstack_使用指南_系列》进行参考。
Saltstack_实战指南02_各主机Pillar信息指定
标签:指南 http backup tps code serve 结构 keepalive files
原文地址:https://www.cnblogs.com/zhanglianghhh/p/10952198.html