[root@master zabbix]# grep -v ‘^#’ zabbix_server.conf | grep -v “^$”

LogFile=/tmp/zabbix_server.log

DBName=zabbix

DBUser=root

DBHost=192.168.33.220

DBName=zabbix

DBUser=zabbixuser

DBPassword=zabbixpass

StartPollers=30

StartTrappers=20

StartPingers=10

StartDiscoverers=120

MaxHousekeeperDelete=5000

CacheSize=1024M

StartDBSyncers=8

HistoryCacheSize=1024M

TrendCacheSize=128M

HistoryTextCacheSize=512M

AlertScriptsPath=/etc/zabbix/alertscripts

LogSlowQueries=1000

DBSocket=/tmp/mysql.sock

对Zabbix-Server进行监控,在server 端也需要安装Zabbix-Agent

客户端配置:

[root@master zabbix_agentd.conf.d]# grep -v “^#” /etc/zabbix/zabbix_agentd.conf | grep -v “^$”

LogFile=/tmp/zabbix_agentd.log

Server=192.168.33.220 ##被动模式,Zabbix-Server 的IP地址

ServerActive=192.168.33.220 ##主动模式

Hostname=master

UnsafeUserParameters=1

Include= /etc/zabbix/zabbix_agentd.conf.d/

Server: 被动模式,允许哪台服务器连接到Agent.

ServerActive: 主动模式,向哪台服务器传送数据。

一个Agent 是可以同时向多个服务端发送数据的,多个IP用逗号分隔。

Server=127.0.0.1,192.168.33.220,表示Server 的IP 为127.0.0.1和192.168.33.220这两台 Zabbix-Server

服务端可获取此Agent端的监控数据。

3.7 Zabbix-Get 的使用:

Zabbix-Get 是Zabbix 中的一个程序,用于Zabbix-Server 到Zabbix-Agent 的数据获取,通常可以用来验证Agent 的配置是否正确。

[root@master tmp]# zabbix_get -s 192.168.32.174 -p 10050

usage: zabbix_get [-hV] -s [-p ] [-I ] -k

[root@master tmp]# zabbix_get -s 192.168.32.174 -p 10050 -k system.uanme

-s Zabbix-Agent 的地址

-p Zabbix-Agent 使用的端口

-k 获取远程Zabbix-Agent 数据所使用的Key

[root@master tmp]# zabbix_get -s 192.168.32.174 -p 10050 -k systen.uname

ZBX_NOTSUPPORTED

刚接触zabbix新手少部分会出现如下错误:

Received empty response from Zabbix Agent at [192.168.1.2]. Assuming that agent dropped connection because of access permission

大概意思是说没有权限访问agent端口10050,解决方法如下:

1

2

cat zabbix_agentd.conf| grep Server=

Server=192.168.1.2 # zabbix server ip地址

如果你的server有多个IP地址,使用逗号分隔多个IP地址。

3.8 Zabbix 相关术语(命令)

1.zabbix_server

zabbix_server 是Zabbix 服务端的核心程序。

2.zabbix_proxy

zabbix_proxy 是Zabbix 代理服务的程序,用于分布式监控proxy 模式中。

3.zabbix_agent

zabbix_agent 是用超级服务(xinetd)的方式来启动的,对应的配置文件为zabbix_aegnt.conf

zabbix_agentd 是以独立进程的方式来启动的,对应的配置文件为zabbix_agentd.conf

zabbix_agent是Zabbix 专用客户端的程序

4.zabbix_java_gateway

Zabbix 的java采集服务端,用于JMX的监控方式。

5.zabbix_sender

Zabbix 的Trapping 模式,将采集到的数据通过定时任务等主动发送给zabbix_server,对于这种方式的使用

6.zabbix_get 是一个数据获取测试命令,相当于snmp中的snmpwalk

3.9 Zabbix-Server 对数据的存储

Zabbix-Server 将采集到的数据主要存储在History 和Trends 表中,其表结构为:

在History表中,主要存储收集到的历史数据,而Trends 主要存储经过计算的历史数据,如每小时数据的最小值,最大值和平均值。

下面看下Trends表,其创建表的语句如下:

mysql> show create table trends\G;

***************** 1. row *****************

Table: trends

Create Table: CREATE TABLE ​​trends​​ (

​itemid​​ bigint(20) unsigned NOT NULL,

​clock​​ int(11) NOT NULL DEFAULT ‘0’,

​num​​ int(11) NOT NULL DEFAULT ‘0’,

​value_min​​ double(16,4) NOT NULL DEFAULT ‘0.0000’,

​value_avg​​ double(16,4) NOT NULL DEFAULT ‘0.0000’,

​value_max​​ double(16,4) NOT NULL DEFAULT ‘0.0000’,

PRIMARY KEY (​​itemid​​,​​clock​​)

) ENGINE=InnoDB DEFAULT CHARSET=utf8

1 row in set (0.09 sec)

mysql> show create table trends_uint\G;

***************** 1. row *****************

Table: trends_uint

Create Table: CREATE TABLE ​​trends_uint​​ (

​itemid​​ bigint(20) unsigned NOT NULL,

​clock​​ int(11) NOT NULL DEFAULT ‘0’,

​num​​ int(11) NOT NULL DEFAULT ‘0’,

​value_min​​ bigint(20) unsigned NOT NULL DEFAULT ‘0’,

​value_avg​​ bigint(20) unsigned NOT NULL DEFAULT ‘0’,

​value_max​​ bigint(20) unsigned NOT NULL DEFAULT ‘0’,

PRIMARY KEY (​​itemid​​,​​clock​​)

) ENGINE=InnoDB DEFAULT CHARSET=utf8

1 row in set (0.00 sec)

ERROR:

No query specified

mysql> select table_name,(data_length+index_length)/1024/1024 as total_mb ,table_rows from information_schema.tables where table_schema=’zabbix’ order by 3 desc;

+———————–+————+————+

| table_name | total_mb | table_rows |

+———————–+————+————+

| history | 0.20312500 | 2157 |

| history_uint | 0.20312500 | 1935 |

| items_applications | 0.21875000 | 914 |

| items | 0.46875000 | 748 |

| functions | 0.07812500 | 336 |

| graphs_items | 0.09375000 | 334 |

| triggers | 0.12500000 | 308 |

| applications | 0.03125000 | 177 |

| events | 0.04687500 | 175 |

| item_discovery | 0.04687500 | 166 |

My understanding of calculating database size is to add the size of the tables to the size of the indexes; database = table(s) + index(es).

计算数据库的大小是计算表的大小加上索引的大小

SELECT concat( table_schema, ‘.’, table_name ) table_name,

concat( round( data_length / ( 1024 *1024 ) , 2 ) , ‘M’ ) data_length,

concat( round( index_length / ( 1024 *1024 ) , 2 ) , ‘M’ ) index_length,

concat( round( round( data_length + index_length ) / ( 1024 *1024 ) , 2 ) , ‘M’ ) total_size

FROM information_schema.TABLES

ORDER BY data_length DESC;

在了解对Zabbix 的数据库进行分表的必要性后,下面介绍如何划分表的区间。首先,对Trends 表进行区间划分,这里的分区的标准是按天进行划分的。

采用表分区后,需要关闭Housekeeper 的功能,此时如果需要清理历史数据,只需要对表区间对应的历史期限的数据进行删除即可。

注意,对于Housekeeper 进程的关闭,可以在Zabbix2.0的zabbix_server.conf 中设置,设置完成后,重启zabbix_server服务,即可使修改后的配置生效。

DisableHousekeeping=1 设置为1表示关闭

在Zabbix2.2中,zabbix_server.conf 没有这个可配置的参数, Zabbix 2.2 的housekeeper 是在Web界面中进行的配置

在Web页面中,依次找到Administration->General->Housekeeper,去掉勾选状态,即可关闭History和Trends的housekeeper功能。

History 表主要存储收集到的历史数据,而Trends 主要存储经过计算的历史数据,如每小时数据的最小值