linux上zabbix-server優化(配置檔案和資料庫)
linux上zabbix-server優化(配置檔案和資料庫)
一、:修改配置檔案
vim /usr/local/zabbix/etc/zabbix_server.conf
Timeout=20 (大概426行)
二、:直接使用優化指令碼
#!/bin/bash
A=`cat -n /usr/local/zabbix/etc/zabbix_server.conf | grep StartPollers= | awk '{print $1}'`
B=`cat -n /usr/local/zabbix/etc/zabbix_server.conf | grep StartTrappers= | awk '{print $1}'`
C=`cat -n /usr/local/zabbix/etc/zabbix_server.conf | grep StartDBSyncers= | awk '{print $1}'`
D=`cat -n /usr/local/zabbix/etc/zabbix_server.conf | grep StartPingers= | awk '{print $1}'`
E=`cat -n /usr/local/zabbix/etc/zabbix_server.conf | grep StartPollersUnreachable= | awk '{print $1}'`
F=`cat -n /usr/local/zabbix/etc/zabbix_server.conf | grep StartDiscoverers= | awk '{print $1}'`
G=`cat -n /usr/local/zabbix/etc/zabbix_server.conf | grep CacheUpdateFrequency=`
H=`cat -n /usr/local/zabbix/etc/zabbix_server.conf | grep HistoryCacheSize= | awk '{print $1}'`
I=`cat -n /usr/local/zabbix/etc/zabbix_server.conf | grep TrendCacheSize= | awk '{print $1}'`
J=`cat -n /usr/local/zabbix/etc/zabbix_server.conf | grep ValueCacheSize= | awk '{print $1}'`
sed -i ''"$A"'c StartPollers=500' /usr/local/zabbix/etc/zabbix_server.conf
sed -i ''"$B"'c StartTrappers=200' /usr/local/zabbix/etc/zabbix_server.conf
sed -i ''"$C"'c StartDBSyncers=50 ' /usr/local/zabbix/etc/zabbix_server.conf
sed -i ''"$D"'c StartPingers=500' /usr/local/zabbix/etc/zabbix_server.conf
sed -i ''"$E"'c StartPollersUnreachable=500' /usr/local/zabbix/etc/zabbix_server.conf
sed -i ''"$F"'c StartDiscoverers=120' /usr/local/zabbix/etc/zabbix_server.conf
sed -i ''"$G"'c CacheUpdateFrequency=300' /usr/local/zabbix/etc/zabbix_server.conf
sed -i ''"$H"'c HistoryCacheSize=512M' /usr/local/zabbix/etc/zabbix_server.conf
sed -i ''"$I"'c TrendCacheSize=512M' /usr/local/zabbix/etc/zabbix_server.conf
sed -i ''"$J"'c ValueCacheSize=1G' /usr/local/zabbix/etc/zabbix_server.conf
/etc/init.d/zabbix_server restart
三、:優化資料庫
使用tmpfs檔案系統
mkdir /zabbixtmp
chown mysql:mysql /zabbixtmp
echo "tmpfs /zabbixtmp tmpfs rw,size=400m,nr_inodes=10k,mod=0700,uid=mysql,gid=mysql 0 0 " >> /etc/fstab
注意檔案的大小設定,一般情況下設成實體記憶體的8%-10%
我的資料庫配置如下:
[mysqld]
# Disabling symbolic-links is recommended to prevent assorted security risks
tmpdir=/zabbixtmp ---檔案系統
#network
connect_timeout =60
wait_timeout =5000
max_connections =400
max_allowed_packet =16M
max_connect_errors =400
#limits
tmp_table_size =256M
max_heap_table_size =64M
table_cache =256
#innodb_data_file_path =ibdata1:128M;ibdata2:128M:autoextend:max:4096M
innodb_file_per_table =1 #每個table一個檔案
innodb_status_file =1
innodb_additional_mem_pool_size =128M
innodb_buffer_pool_size =5G #一般設為伺服器實體記憶體的70%-80%
innodb_flush_method =O_DIRECT
innodb_support_xa =0
query_cache_size=128M
join_buffer_size=128M
read_buffer_size=128M
read_rnd_buffer_size=128M
key_buffer=128M
systemctl restart mariadb
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
四、:zabbix頁面:
1:管理----一般----右上角---其他---600s
2:模板中的自動發現---資源週期不足,時間改短(列如 7d)
3:也可以 zabbix模板中批量修改成為zabbix agent(active)模式(模板中監控項中,修改為主動模式)
再做個任務計劃,每天重啟一次,清理殭屍程序
0 4 * * * /etc/init.d/zabbix_server restart > /dev/null 2>&1
0 4 * * * /etc/init.d/grafana-server restart > /dev/null 2>&1
0 4 * * * /mnt/cache.sh
vim cache.sh
#! /bin/bash
# cache釋放:
sync
sync
echo 3 > /proc/sys/vm/drop_caches