一、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数据库
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
4、安装后调整
(1)修改密码:
echo -n 123456|openssl md5
Use zabbix
update users set passwd="e10adc3949ba59abbe56e057f20f883e" where userid=1;
(2)中文界面
(3)调整字体
cd /usr/share/fonts/dejavu
mv DejaVuSans.ttf DejaVuSans.ttf.bak
cp /root/simhei.ttf /usr/share/fonts/dejavu/DejaVuSans.ttf
(4)修改默认监控主机zabbix-server IP地址
二、添加被监控主机
(1)添加主机群组
(4)查看最新数据与图形
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
三、自定义监控: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监控项
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 创建监控项
4、创建图形
yum install httpd-tools -y
ab -n 10000000 -c 10 http://192.168.100.10/index.html
5、创建触发器
常用触发器函数
(1)avg():avg(#5,10m):十分钟内取5次值的平均值
(2)count():count(10,2,gt):10秒内值大于2的个数,count(#10,2,gt):10次取值内值大于2的个数
(3)last():last(#5):最近的第5次取值
(4)max()&min():max(5):5秒内的最大值
(5)nodata():指定时间间隔未接收到值,{node1:nginx.active.nodata(30)}=1
(6)sum():指定时间间隔值的和,sum(5)
6、告警
(1)qq邮箱告警
A、生成授权码
B、启用动作、编辑操作
C、设置报警媒介类型、用户报警媒介
(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、配置微信告警
创建媒体类型
配置用户报警媒介
创建动作、编辑操作
验证结果
四、zabbix生产案例(持续更新)
1、web站点监控
(1)web页面监控:以百度为例
创建web场景
(2)PV&UV监控
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监控: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默认模板
(3)被监控主机重新链接模板
(4)查看数据
(5)监控MYSQL主从状态
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"
创建监控项
查看图形
(6)创建模板、复制监控项
(7)导入导出模板