本文链接
https://www.cnsre.cn/posts/210303161655/
Zabbix架构
在讲Zabbix优化之前,先来看看Zabbix Server 的逻辑架构图:
对于上图中,架构组件的描述:
Zabbix进程
- Self-Monitoring:用于收集Zabbix系统内部的监控信息;
- Configuration syncer:用于将配置文件中的配置信息同步到内存中缓存;
- Timer:用于处理触发器中与时间相关的函数和维护模式的进程;
- History syncer:用于写历史数据表的进程;
- Escalator:用于处理Action中的步骤的进程;
- Housekeeper:用于清理过期的历史数据的进程;
- Db watchdog:用于监视Zabbix系统的数据库状态,当数据库状态变为不可用时,发送警告信息(服务器代理端不支持这类型进程)。
Zabbix Poller
- Poller:用于普通的被动监控项目的轮询;
- ICMP pinger:用于定期的进行ICMP PING检查;
- IPMI poller:用于定期进行IPMI监控项目的检查;
- Unreachable poller:用于轮询不可达的设备;
- Proxy poller:用于服务器代理的被动轮询;
- Trapper:用于处理主动采集、陷入以及分布式节点间或服务器代理的通信;
- Java poller:用于轮询Java监控项目;
- Http poller:用于轮询Web类的监控项目;
- Snmp trapper:用于轮询Snmp/trap类的监控项目;
- Discovery:用于自动发现设备的进程;
- Vmware Collector:负责从VMware服务进程中收集数据(服务器代理端不支持这种类型的进程);
- Alerter:用于发送报警通知进程。
优化内容
优化Zabbix架构
常用的架构:
说明:Zabbix最简单的架构,常用于监控主机比较少的情况下。
分布式架构:
Server-Proxy-Agentd模式。
说明:Zabbix分布式架构,常用于监控主机比较多的情况下,使用Zabbix Proxy进行分布式监控,有效的减轻了Zabbix Server端的压力。
Zabbix Server/Zabbix Proxy配置优化
调整配置文件:Zabbix_Server.conf
Zabbix进程参数调整:
1
2
3
4
5
6
|
StartPollers=80
StartPingers=10
StartPollersUnreachable=80
StartIPMIPollers=10
StartTrappers=20
StartDBSyncers=8
|
值得注意的是,当Zabbix的Pollers数量过多时(超过limit默认值1024),需要对系统的limit的参数大小进行修改。
1
2
3
4
5
|
shell> vi /etc/security/limit.conf
* hard nofile 65536
* soft nofile 65536
* hard nproc 65536
* soft nproc 65536
|
Zabbix In-Memory Cache参数优化(以下值仅做参考):
ValueCacheSize=256M
HistoryIndexCacheSize = 64M
TrendCacheSize=64M
HistoryCacheSize=128M
CacheSize=128M
VMwareCacheSize=64M
优化Zabbix的数据库(MySQL)
调整MySQL配置文件:my.cnf或my.ini,在[mysqld]酌情修改参数:
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
|
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
[mysql]
prompt="\u@mysqldb \R:\m:\s [\d]> "
no-auto-rehash
[mysqld]
user= mysql
port = 3306
datadir = /data/mysql/
socket = /var/lib/mysql/mysql.sock
pid-file = mysqldb.pid
character-set-server = utf8mb4
skip_name_resolve = 1
# Timestamp
explicit_defaults_for_timestamp = 1
# Connections
back_log = 1024
max_connections = 512
max_connect_errors = 5120
innodb_thread_concurrency = 16
# Limit
open_files_limit = 65535
innodb_open_files = 65535
# Query Cache
query_cache_type = 0
query_cache_size = 0
# binary logs
server-id = 3306001
binlog_format = row
log-bin = /data/mysql/mysql-binlog
expire_logs_days = 7
sync_binlog = 1
max_binlog_size = 1G
binlog_cache_size = 4m
max_binlog_cache_size = 1G
# slow query
slow_query_log = 1
long_query_time = 2
slow_query_log_file = /data/mysql/slow.log
# Timeout
interactive_timeout = 600
wait_timeout = 600
# Engine
default-storage-engine = innodb
# Buffer
key_buffer_size = 32M
read_buffer_size = 1M
sort_buffer_size = 1M
read_rnd_buffer_size = 1M
tmp_table_size = 32M
join_buffer_size = 16M
max_heap_table_size = 32M
max_tmp_tables = 48
thread_cache_size = 32
# Time
log_timestamps = SYSTEM
# Tablespace & File I/O
innodb_data_file_path = ibdata1:1G:autoextend
innodb_file_per_table = 1
# Redo Log
innodb_flush_log_at_trx_commit = 1
innodb_log_file_size = 256M
innodb_log_files_in_group = 2
innodb_log_buffer_size = 16M
# Innodb
innodb_buffer_pool_size = 8G
innodb_buffer_pool_instances = 8
innodb_flush_method = O_DIRECT
innodb_change_buffer_max_size = 50
innodb_max_dirty_pages_pct = 30
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_io_capacity = 500
innodb_io_capacity_max= 1000
innodb_support_xa = 0
innodb_rollback_on_timeout = 1
|
优化Zabbix监控项
优化监控项的数据采集方式,由被动方式改为主动模式(Passive mode -> Active mode),主动模式的优势: