1:在歷史記錄和事件表上創(chuàng)建MySQL分區(qū)(可選)
Zabbix使用housekeeping
進(jìn)程刪除舊的趨勢(shì)和歷史數(shù)據(jù)。使用 SQL?DELETE
語(yǔ)句從數(shù)據(jù)庫(kù)中刪除舊數(shù)據(jù)可能會(huì)對(duì)數(shù)據(jù)庫(kù)性能產(chǎn)生負(fù)面影響。因此,有時(shí)候我們看到這個(gè)告警:Zabbix housekeeper processes more than 75% busy
這個(gè)問題可以通過數(shù)據(jù)庫(kù)分區(qū)輕松解決。分區(qū)為每個(gè)小時(shí)或每天創(chuàng)建表,并在不再需要時(shí)刪除它們。SQL?DROP
比?DELETE
語(yǔ)句更有效。
您可以參照這個(gè)教程對(duì)MySQL表進(jìn)行分區(qū)。
2:優(yōu)化Zabbix服務(wù)器(可選)
如果您計(jì)劃監(jiān)視大量設(shè)備,請(qǐng)繼續(xù)執(zhí)行此步驟。
使用vi
或nano
命令打開zabbix_server.conf
文件:
nano etc/zabbix/zabbix_server.conf
然后將下列配置添加到文件中的任意位置:
StartPollers=100
StartPollersUnreachable=50
StartPingers=50
StartTrappers=10
StartDiscoverers=15
StartPreprocessors=15
StartHTTPPollers=5
StartAlerters=5
StartTimers=2
StartEscalators=2
CacheSize=128M
HistoryCacheSize=64M
HistoryIndexCacheSize=32M
TrendCacheSize=32M
ValueCacheSize=256M
保存并退出文件(ctrl+x,后跟 y 并回車)。請(qǐng)根據(jù)實(shí)際情況修改這些配置,比如你不使用ping監(jiān)控,可以設(shè)定StartPingers=1
。
3:優(yōu)化 MySQL/MariaDB 數(shù)據(jù)庫(kù)(可選)
有時(shí)您會(huì)碰到下面這個(gè)告警:
[Z3001] connection to database 'Zabbix' failed: [1040] Too many connections/var/log/zabbix/zabbix_server.log
那么您可以添加如下配置:
a. 創(chuàng)建自定義 MySQL 配置文件
通過vi
或nano
命令創(chuàng)建mysql.cnf
配置文件:
nano etc/my.cnf.d/mysql.cnf
粘貼如下配置:
[mysqld]
max_connections = 404
innodb_buffer_pool_size = 800M
innodb-log-file-size = 128M
innodb-log-buffer-size = 128M
innodb-file-per-table = 1
innodb_buffer_pool_instances = 8
innodb_old_blocks_time = 1000
innodb_stats_on_metadata = off
innodb-flush-method = O_DIRECT
innodb-log-files-in-group = 2
innodb-flush-log-at-trx-commit = 2
tmp-table-size = 96M
max-heap-table-size = 96M
open_files_limit = 65535
max_connect_errors = 1000000
connect_timeout = 60
wait_timeout = 28800
保存并退出文件(ctrl+x,后跟 y 并回車)。給該文件添加權(quán)限:
chown mysql:mysql etc/my.cnf.d/mysql.cnf
chmod 644 etc/my.cnf.d/mysql.cnf
要注意的2個(gè)參數(shù):
- 參數(shù)
max_connections
必須大于所有 Zabbix 進(jìn)程的總數(shù)加上 150。您可以使用以下命令自動(dòng)檢查Zabbix進(jìn)程的數(shù)量(該命令的結(jié)果是加上了150后的值):
egrep "^Start.+=[0-9]" etc/zabbix/zabbix_server.conf | awk -F "=" '{s+=$2} END {print s+150}'
404
- 第二個(gè)重要的參數(shù)是
innodb_buffer_pool_size
。它決定了MySQL可以獲得多少內(nèi)存來(lái)緩存InnoDB表和索引數(shù)據(jù)。如果服務(wù)器上僅安裝了數(shù)據(jù)庫(kù),則應(yīng)將該參數(shù)設(shè)置為系統(tǒng)內(nèi)存的 70%。
但是通常情況下,我們將Zabbix數(shù)據(jù)庫(kù)和Apache安裝在同一臺(tái)服務(wù)器,因此建議將innodb_buffer_pool_size
設(shè)置為總系統(tǒng)內(nèi)存的40%。如果服務(wù)器是2G RAM,那么這個(gè)值將設(shè)定為是800MB。
b. 重新啟動(dòng) Zabbix Server 和 MySQL 服務(wù)
systemctl stop zabbix-server
systemctl stop mysql
systemctl start mysql
systemctl start zabbix-server
4:如何管理Zabbix MySQL Apache服務(wù)
有時(shí)您需要檢查或重新啟動(dòng)Zabbix,MySQL或Apache服務(wù), 使用下面的命令來(lái)執(zhí)行此操作。
Zabbix Server
systemctl <status/restart/start/stop> zabbix-server
MySQL/MariaDB Server
systemctl <status/restart/start/stop> mysql
Apache Server
systemctl <status/restart/start/stop> httpd
PHP FastCGI Process Manager
systemctl <status/restart/start/stop> php-fpm
Zabbix Agent
systemctl <status/restart/start/stop> zabbix-agent
upgrade
dnf upgrade 'zabbix-*'