1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
| 操作内容:
一、基础环境
1、使用tvm-cobbler安装一个tvm-zabbix虚拟机来做实验。
2、网络:
eth0:host-only(用于虚拟内网,手动固定IP,这样从宿主机可以直接连接到这个vm)
eth1:NAT(用于上外网,动态IP)
[iyunv@tvm-zabbix ~]# cd /etc/sysconfig/network-scripts/
[iyunv@tvm-zabbix network-scripts]# cat ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=192.168.56.200
PREFIX=24
GATEWAY=192.168.56.1
DNS1=192.168.56.254
[iyunv@tvm-zabbix network-scripts]# cat ifcfg-eth1
DEVICE=eth1
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp
DNS1=192.168.56.254
[iyunv@tvm-zabbix ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 36G 1.8G 32G 6% /
tmpfs 499M 12K 499M 1% /dev/shm
/dev/sda1 194M 29M 155M 16% /boot
/dev/sdb1 99G 188M 94G 1% /data
使用域名:
[iyunv@tvm-yum ~]# cat /etc/dnsmasq.d/office.conf |grep zbx-m
address=/zbx-m.office.test/192.168.56.200
3、repo
我们在自己的office这个repo中已经增加了几个rpm包:
[iyunv@tvm-zabbix data]# yum search --disablerepo=\* --enablerepo=office percona
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
======================================================================================= N/S Matched: percona =======================================================================================
Percona-Server-55-debuginfo.x86_64 : Debug information for package Percona-Server-55
Percona-Server-client-55.x86_64 : Percona Server - Client
Percona-Server-devel-55.x86_64 : Percona Server - Development header files and libraries
Percona-Server-server-55.x86_64 : Percona Server: a very fast and reliable SQL database server
Percona-Server-shared-55.x86_64 : Percona Server - Shared libraries
Percona-Server-test-55.x86_64 : Percona Server - Test suite
percona-zabbix-templates.noarch : Percona Monitoring Plugins for Zabbix
Name and summary matches only, use "search all" for everything.
二、配置
1、sls文件
[iyunv@tvm-saltmaster base]# cat mysql/server.sls
## 安装mysql-server,以及对应的zabbix监控相关文件。
#
# via pc @ 2015/8/12
Percona-Server:
pkg.installed:
## for local-office.repo
#
- fromrepo: office,base,repo
- name: zabbix-agent
- skip_verify: True
- refresh: True
- pkgs:
## for percona-server
#
- Percona-Server-55-debuginfo
- Percona-Server-client-55
- Percona-Server-devel-55
- Percona-Server-server-55
- Percona-Server-shared-55
- Percona-Server-test-55
- percona-zabbix-templates
## for zabbix
# Scripts are installed to /var/lib/zabbix/percona/scripts
# Templates are installed to /var/lib/zabbix/percona/templates
#
# /var/lib/zabbix/percona/scripts:
# total 64
# -rwxr-xr-x 1 root root 1251 Jul 21 2014 get_mysql_stats_wrapper.sh
# -rwxr-xr-x 1 root root 58226 Jul 21 2014 ss_get_mysql_stats.php
#
# /var/lib/zabbix/percona/templates:
# total 284
# -rw-r--r-- 1 root root 18866 Jul 21 2014 userparameter_percona_mysql.conf
# -rw-r--r-- 1 root root 269258 Jul 21 2014 zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.4.xml
#
- php
- php-mysql
/etc/my.cnf:
file.managed:
- source: salt://conf.d/mysql/my.cnf
- mode: 644
- require:
- pkg: Percona-Server
/data/mysql:
file.directory:
- user: mysql
- group: mysql
- mode: 755
- makedirs: True
- require:
- pkg: Percona-Server
run-mysql:
## Installing MySQL system tables
# PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
# /usr/bin/mysqladmin -u root password 'new-password'
cmd.run:
- name: /usr/bin/mysql_install_db
- onlyif:
- d_mysql=$(grep 'datadir' /etc/my.cnf |cut -d'=' -f2);
d_mysql_install="${d_mysql}/mysql";
test ! -d ${d_mysql_install}
service.running:
- name: mysql
- enable: True
- require:
- pkg: Percona-Server
## for zabbix
percona_zabbix_php:
file.managed:
- name: /etc/php.ini
- source: salt://conf.d/mysql/percona_zabbix_php.ini
- mode: 755
- require:
- pkg: Percona-Server
## for zabbix
# notice! password need to be protected in file: ss_get_mysql_stats.php
ss_get_mysql_stats:
file.managed:
- name: /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
- source: salt://conf.d/mysql/ss_get_mysql_stats.php
- mode: 770
- require:
- pkg: Percona-Server
2、conf文件
[iyunv@tvm-saltmaster base]# tree conf.d/mysql/
conf.d/mysql/
├── my.cnf
├── percona_zabbix_php.ini
└── ss_get_mysql_stats.php
0 directories, 3 files
[iyunv@tvm-saltmaster base]# cat conf.d/mysql/my.cnf
[mysqld]
# GENERAL
datadir=/data/mysql
socket=/data/mysql/mysql.sock
pid_file=/data/mysql/mysqld.pid
user=mysql
port=3306
#enforce_storage_engine=InnoDB
default-storage-engine=InnoDB
character_set_server=utf8
# InnoDB
innodb_buffer_pool_size=2G
innodb_flush_method=O_DIRECT
innodb_file_per_table=1
innodb_open_files=500
innodb_log_buffer_size=128M
innodb_log_file_size=256M
innodb_stats_on_metadata=OFF
innodb_support_xa=OFF
innodb_thread_concurrency=0
innodb_io_capacity=200
# MyISAM
key_buffer_size=128M
#BINLOG
server_id=10
log_bin=/data/mysql/mysql-bin
binlog_format=mixed
#replicate-do-db=cdn
#replicate-ignore-db=mysql
#replicate-ignore-db=test
#relay_log=/data/mysql/relay-log
# LOGGING
log_error=/data/mysql/mysql-error.log
slow_query_log=ON
long_query_time=2
slow_query_log_file=/data/mysql/mysql-slow
##These two variables are only for Percona
max_slowlog_files=5
max_slowlog_size=100M
expire_logs_days=14
# OTHER
tmp_table_size=32M
max_heap_table_size=32M
open_files_limit=600000
query_cache_type=0
query_cache_size=0
thread_cache_size=64
table_definition_cache=500
table_open_cache=1000
max_allowed_packet=16M
max_connections=800
max_user_connections=400
max_connect_errors=99999999
skip_name_resolve
[client]
default_character_set=utf8
socket=/data/mysql/mysql.sock
其他2个文件,主要是mysql相关的配置要调整:
[iyunv@tvm-saltmaster base]# grep 'mysql.sock' conf.d/mysql/percona_zabbix_php.ini
mysql.default_socket = /data/mysql/mysql.sock
mysqli.default_socket = /data/mysql/mysql.sock
[iyunv@tvm-saltmaster base]# grep -E '^\$mysql_(u|p)' conf.d/mysql/ss_get_mysql_stats.php
$mysql_user = 'zabbix_ro';
$mysql_pass = 'xxx';
$mysql_port = 3306;
三、执行
[iyunv@tvm-saltmaster base]# salt 'tvm-zabbix' state.sls mysql.server --output-file='/tmp/salt.log'
四、注意事项
如果我们在另一个shell中,开启了salt-minion的debug日志,而同时,我们的salt-minion服务并未结束,此时有多个salt-minion:
[iyunv@tvm-zabbix data]# salt-minion -l debug
[iyunv@tvm-zabbix ~]# ps -ef |grep salt
root 31623 1 0 16:45 ? 00:00:01 /usr/bin/python2.6 /usr/bin/salt-minion -d
root 31882 1205 0 17:04 pts/0 00:00:00 /usr/bin/python2.6 /usr/bin/salt-minion -l debug
root 31885 31882 1 17:04 pts/0 00:00:00 /usr/bin/python2.6 /usr/bin/salt-minion -l debug
root 32083 29908 0 17:05 pts/1 00:00:00 grep salt
则,在salt-master上执行salt命令可能会出现如下的异常:
[iyunv@tvm-saltmaster base]# salt 'tvm-zabbix' state.sls mysql.server --output-file='/tmp/salt.log'
[iyunv@tvm-saltmaster base]# cat /tmp/salt.log
tvm-zabbix:
Data failed to compile:
----------
The function "state.sls" is running as PID 32031 and was started at 2015, Aug 12 17:04:42.900197 with jid 20150812170442900197
因此,建议的做法是,先关闭monit和salt-minion服务,然后再手动启动debug模式的salt-minion服务:
service monit stop
service salt-minion stop
salt-minion -l debug
ZYXW、参考
1、老大提供的资料。
|