|NO.Z.00044|——————————|^^ 構建 ^^|——|Zabbix3.2構建.V5|--------------------------------------|2臺server|
阿新 • • 發佈:2022-03-22
[Applications:Zabbix3.2構建.V5] [Applications.LBC&HAC$HPC] [|監控叢集|監控zabbix3.2版本|web初始化設定|中文亂碼|監控本機|zabbix-agent|] [自動發現|nginx併發監控|釘釘告警|2臺server|]
附錄一:構建zabbix監控伺服器
一、初始化系統設定
二、安裝LAMP環境### --- 初始化系統設定 systemctl stop firewalld systemctl disable firewalld setenforce 0 sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
### --- 安裝LAMP環境
wget http://mirros.163.com/./help/CentOS7-Base-163.repo
yum clean all
yum makecache
yum install -y mariadb mariadb-server httpd php php-mysql
systemctl enable httpd
systemctl restart httpd
systemctl enable mariadb
systemctl restart mariadb
mysql_secure_installation
三、安裝zabbix程式### --- 安裝zabbix程式 rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.3l7.noarch.rpm rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX yum install -y zabbix-server-mysql zabbix-web-mysql zabbix-agent ### --- 初始化資料庫: mysql -u root -p CREATE DATABASE zabbix DEFAULT CHARACTET SET utf8 COLLATE utf8_bin; grant all privileges on zabbix.* to zabbix@localhost identified by'zabbix';
### --- 讀入資料庫
cd /usr/share/doc/zabbix-server-mysql-3.2.1
zcat creat.sql.gz |mysql -uroot -p zabbix
### --- 啟動zabbix服務
vim /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
systemctl start zabbix-server
systemctl enable zabbix-server
### --- 編輯zabbix前端PHP配置
vim /etc/httpd/conf.d/zabbix.conf
php_value max_execution_time 300
php_value memory_limit 128M
php_value upload_max_filesize 2M
php_value max_input_time 300
php_value always_populate_raw_post_data -l
php_value date.timezone Asia/Shanghai
### --- 調整時間同步
yum install -y ntpdate
ntpdate cn.pool.ntp.org
### --- 重啟Apache服務生效
systemctl restart httpd
四、修改中文亂碼問題
### --- wind+R > fonts > 拷貝微軟雅黑字型改名為msyh.ttf > /usr/share/zabbix/fonts
vim /usr/share/zabbix/include/defines.inc.php
### --- 修改zabbix php 頁面配置,將'graohfont'修改為msyh
dnfine('ZBX_GRAPH_FONT_NAME','msyh');
五、新增客戶端
### --- 新增客戶端
vim /usr/local/zabbix/etc/zabbix_agentd.configure
LogFile=/tmp/zabbix_agentd.log
Server= 192.168.1.195
ServerActive = 192.168.1.195
Hostname = 192.168.1.195
rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/6/x86_64/zabbix-release-3.2-1.el6.noarch.rpm
六、新增監控主機/自動發現,nginx併發監控
### --- 新增監控主機
### --- 原始碼編譯安裝Nginx伺服器並開啟狀態統計模組
### --- zabbix客戶端配置
### --- 編寫nginx監控指令碼,在被監控端
#!/bin/bash
HOST="127.0.0.1"
PORT="80"
#檢測nginx程序是否存在
function ping {
/sbin/pidof nginx | wc -l
}
#檢測nginx效能
function active {
/usr/bin/curl "http://$HOST:$PORT/nginx-status/" 2>/dev/null| grep 'Active' | awk '{print $NF}'
}
function reading {
/usr/bin/curl "http://$HOST:$PORT/nginx-status/" 2>/dev/null| grep 'Reading' | awk '{print $2}'
}
function writing {
/usr/bin/curl "http://$HOST:$PORT/nginx-status/" 2>/dev/null| grep 'Writing' | awk '{print $4}'
}
function waiting {
/usr/bin/curl "http://$HOST:#PORT/nginx-status/" 2>/dev/null| grep 'Waiting' | awk' {print $6}'
}
function accepts {
/usr/bin/curl "http://$HOST:$PORT/nginx-status/" 2>/dev/null| awk NR==3 | awk '{print$1}'
}
function handled {
/usr/bin/curl "http://$HOST:$PORT/nginx-status/" 2>/dev/null| awk NR==3 | awk '{print $2}'
}
function requests {
/usr/bin/curl "http://$HOST:$PORT/nginx-status/" 2>/dev/null| awk NR==3 | awk '{print $3}'
}
#執行function
$1
### --- 將自定義的UserParameter加入配置檔案,然後重啟agentd
cat /usr/local/zabbi-3.0.0/etc/zabbix_agentd.conf|grep nginx
UserParameter=naginx.status[*],/usr/local/zabbix-3.0.0/scropts/ngx-status.sh $1
~~~ killall zabbix_agentd
~~~ usr/local/zabbix-3.0.0/sbin/zabbix_agentd
### --- zabbix_get獲取資料
/usr/local/zabbix-3.0.0/bin/zabbix_get -s 10.10.1.121 -k 'nginx.status[accepts]'
9570756
/usr/local/zabbix-3.0.0/bin/zabbix_get -s 10.10.1.121 -k 'nginx.status[ping]'
七、報警設定:zabbix 聯合釘釘實現終端報警
1、監控方式新增引數
{ALERT.SENDTO}
{ALERT.SUBJECT}
{ALERT.MESSAGE}
2、錯誤報警資訊引數
### --- 標題改為
故障{ERIGGER.STATUS},伺服器:{HOSTNAME1}發生:
{TRIGGER.NAME}故障
### --- 資訊改為
告警主機:{HOSTNAME1}
告警時間:{EVENT.DATE}{EVENT.TIME}
告警等級:{TRIGGER.SEVERITY}
告警資訊:{TRIGGER.NAME}
告警專案:{TRIGGER.KEY1}
問題詳情:{ITEM.NAME}:{ITEM.VALUE}
當前狀態:{TRIGGER.STATUS}:{ITEM.VALUE1}
事件ID:{EVENT.ID}
3、錯誤恢復報警資訊設定
### --- 標題改為
恢復{TRIGGER.STATUS},伺服器:{HOSTNAME1}:
{TRIGGER.NAME}故障
### --- 資訊改為
告警主機:{HOSTNAME1}
告警時間:{EVENT.DATE}{EVENT.TIME}
告警等級:{TRIGGER.SEVERITY}
告警資訊:{TRIGGER.NAME}
告警專案:{TRIGGER.KEY1}
問題詳情:{ITEM.NAME}:{ITEM.VALUE}
當前狀態:{TRIGGER.STATUS}:{ITEM.VALUE1}
事件ID:{EVENT.ID}
===============================END===============================
Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart ——W.S.Landor
來自為知筆記(Wiz)