centos7.5+zabbix4實戰(zhàn)圖文攻略--2019持續(xù)更新
一轧简、zabbix安裝與基本配置
1姨伟、配置YUM源
wget -O /etc/yum.repos.d/CentOS-Base.repo?http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo?http://mirrors.aliyun.com/repo/epel-7.repo
rpm -ivh?https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
Yum clean all
Yum makecache
2谊迄、安裝zabbix闷供、初始化mysql、zabbix數(shù)據(jù)庫
yum install zabbix-server-mysql zabbix-web-mysql mariadb-server zabbix-agent -y
systemctl start mariadb
systemctl enable mariadb
mysql_secure_installation
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on zabbix.* to zabbix@localhost identified by '123456';
zcat /usr/share/doc/zabbix-server-mysql-4.0.4/create.sql.gz|mysql -uzabbix -p123456 zabbix
3统诺、配置zabbix
vim /etc/httpd/conf.d/zabbix.conf
php_value date.timezone Asia/Shanghai
systemctl start httpd
systemctl enable httpd
vim /etc/zabbix/zabbix_server.conf
DBPassword=123456
systemctl start zabbix-server
systemctl enable zabbix-server
vim /etc/zabbix/zabbix_agentd.conf
Server=192.168.100.110
ServerActive=192.168.100.110 #主動模式的server IP地址
systemctl start zabbix-agent
systemctl enable zabbix-agent
http://192.168.100.100/zabbix/setup.php
默認(rèn)賬號:Admin歪脏,默認(rèn)密碼:zabbix
4、安裝后調(diào)整
(1)修改密碼:
echo -n 123456|openssl md5
Use zabbix
update users set passwd="e10adc3949ba59abbe56e057f20f883e" where userid=1;
(2)中文界面
(3)調(diào)整字體
cd /usr/share/fonts/dejavu
mv DejaVuSans.ttf DejaVuSans.ttf.bak
cp /root/simhei.ttf /usr/share/fonts/dejavu/DejaVuSans.ttf
(4)修改默認(rèn)監(jiān)控主機zabbix-server IP地址
二粮呢、添加被監(jiān)控主機
(1)添加主機群組
(2)創(chuàng)建主機
(3)關(guān)聯(lián)模板
(4)查看最新數(shù)據(jù)與圖形
yum install zabbix-agent -y
vim /etc/zabbix/zabbix_agentd.conf
Server=192.168.100.110
#ServerActive=192.168.100.110 #主動模式的server IP地址
systemctl start zabbix-agent
systemctl enable zabbix-agent
三婿失、自定義監(jiān)控:nginx活動連接
1、配置nginx:
yum install nginx -y
vim /etc/nginx/nginx.conf
location /nginx-status
{
stub_status on;
access_log off;
}
systemctl start nginx
systemctl enable nginx
2啄寡、自定義nginx監(jiān)控項
vim /etc/zabbix/zabbix_agentd.d/userparameter_nginx.conf
UserParameter=nginx.active,curl -s?http://192.168.100.10/nginx-status|grep?Active|awk '{print $3}'
systemctl restart zabbix-agent
3豪硅、zabbix 創(chuàng)建監(jiān)控項
4、創(chuàng)建圖形
yum install httpd-tools -y
ab -n 10000000 -c 10?http://192.168.100.10/index.html
5挺物、創(chuàng)建觸發(fā)器
常用觸發(fā)器函數(shù)
(1)avg():avg(#5,10m):十分鐘內(nèi)取5次值的平均值
(2)count():count(10,2,gt):10秒內(nèi)值大于2的個數(shù)懒浮,count(#10,2,gt):10次取值內(nèi)值大于2的個數(shù)
(3)last():last(#5):最近的第5次取值
(4)max()&min():max(5):5秒內(nèi)的最大值
(5)nodata():指定時間間隔未接收到值,{node1:nginx.active.nodata(30)}=1
(6)sum():指定時間間隔值的和识藤,sum(5)
6砚著、告警
(1)qq郵箱告警
A、生成授權(quán)碼
B蹋岩、啟用動作赖草、編輯操作
C、設(shè)置報警媒介類型剪个、用戶報警媒介
(2)微信告警
A扣囊、下載微信報警腳本wechat.py
https://github.com/X-Mars/Zabbix-Alert-WeChat
B、配置修改腳本
Chmod _x wechat.py
cp wechat.py /usr/lib/zabbix/alertscripts/
yum install python-requests.noarch -y
./wechat.py 1 2 3
C骂澄、配置微信告警
創(chuàng)建媒體類型
配置用戶報警媒介
創(chuàng)建動作、編輯操作
驗證結(jié)果
四私痹、zabbix生產(chǎn)案例(持續(xù)更新)
1桦山、web站點監(jiān)控
(1)web頁面監(jiān)控:以百度為例
創(chuàng)建web場景
(2)PV&UV監(jiān)控
vim userparameter_pvuv.conf
UserParameter=nginx.uv,awk '{print $1}' /var/log/nginx/access.log|sort|uniq -c|wc -l
UserParameter=nginx.pv,awk '{print $7}' /var/log/nginx/access.log|wc -l
systemctl restart zabbix-agent
2、mysql監(jiān)控:mysql登錄有密碼
(1)修改userparameter_mysql.conf
vim userparameter_mysql.conf
UserParameter=mysql.status[],echo "show global status where Variable_name='$3';" | HOME=/var/lib/zabbix mysql -u$1 -p$2 -N | awk '{print $$2}'
UserParameter=mysql.ping[
],HOME=/var/lib/zabbix mysqladmin -u$1 -p$2 ping | grep -c alive
UserParameter=mysql.version,mysql -V
(2)修改mysql默認(rèn)模板
(3)被監(jiān)控主機重新鏈接模板
(4)查看數(shù)據(jù)
(5)監(jiān)控MYSQL主從狀態(tài)
vim userparameter_mysql.conf
UserParameter=mysql.rep[*],mysql -u$1 -p$2 -e "show slave status \G;"|grep -E "Slave_IO_Running|Slave_SQL_Running"|grep -c "Yes"
創(chuàng)建監(jiān)控項
查看圖形
(6)創(chuàng)建模板御雕、復(fù)制監(jiān)控項
(7)導(dǎo)入導(dǎo)出模板