Zabbix-监控教程
1:什么是监控,为什么需要监控
监控:监视,控制
2:常见的linux监控命令
free
df
top
htop(epel)
uptime
iftop
iostat
iotop
vmstat
netstat
nethogs
总结:cpu,内存,硬盘,网络
3:使用shell脚本来监控服务器
内存:每隔1分钟监控一次内存,当你的可用内存低于100m,发邮件报警,要求显示剩余内存值
#!/bin/bash while true do Free=`free -m | awk 'NR==2{print $NF}'` if [ $Free -lt 100 ] then echo $Free | mail -s "当前内存" y3967z@163.com fi sleep 60 done
压力测试
ab -n 10000 -c 3 http://10.0.0.100/zabbix/index.php
4:zabbix的基础服务架构
zabbix-agent c语言 ----> zabbix-server c语言 ----> 数据库 mysql <--- zabbix web lamp
5:zabbix生产环境安装
5.1:配置zabbix yum仓库并安装
wget http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm rpm -ivh zabbix-release-4.0-1.el7.noarch.rpm
5.2:地址更改为清华源
[root@zabbix-server ~]# cat /etc/yum.repos.d/zabbix.repo [zabbix] name=Zabbix Official Repository - $basearch baseurl=https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX [zabbix-non-supported] name=Zabbix Official Repository non-supported - $basearch baseurl=https://mirror.tuna.tsinghua.edu.cn/zabbix/non-supported/rhel/7/$basearch/ enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX gpgcheck=1
5.3:安装zabbix服务端和zabbix-web前端
yum install zabbix-server-mysql zabbix-web-mysql -y
5.4:安装mariadb,创建zabbix库,授权zabbix用户
yum install mariadb-server -y systemctl start mariadb systemctl enable mariadb mysql_secure_installation
回车 输入 “n”
继续 “Y”
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin; MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by '123456';
5.5:导入zabbix表结构和初始数据
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p123456 zabbix
5.6:检查zabbix库是否导入成功
mysql -uroot zabbix -e 'show tables'
5.7:配置启动zabbix-server
vim /etc/zabbix/zabbix_server.conf DBHost=localhost DBName=zabbix DBUser=zabbix DBPassword=123456
systemctl start zabbix-server systemctl enable zabbix-server
5.8:修改Zabbix前端的PHP配置,并启动httpd
vim /etc/httpd/conf.d/zabbix.conf php_value date.timezone Asia/Shanghai
systemctl start httpd systemctl enable httpd
5.9:前端zabbix-web的安装
浏览器:http://10.0.0.61/zabbix
后期修改zabbix数据库密码的时候,需要修改的配置文件:
/etc/zabbix/web/zabbix.conf.php
http://10.0.0.61/zabbix/zabbix.php
登录的账号密码;
Admin
zabbix
6:监控一台服务器主机
6.1:安装zabbix-agent
rpm -ivh https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.11-1.el7.x86_64.rpm
6.2:配置启动zabbix-agent
vim /etc/zabbix/zabbix_agentd.conf Server=10.0.0.61 systemctl start zabbix-agent systemctl enable zabbix-agent
6.3:zabbix-web界面,添加主机
7:自定义监控项
7.1:命令行,手动取值
[root@zabbix-server ~]# iostat|awk '$1 ~/sda/' sda 4.07 41.98 68.30 255455 415578 [root@zabbix-server ~]# iostat|awk '$1 ~/sda/{print $2}' 4.07
7.2:修改zabbix-agent配置文件
vim /etc/zabbix/zabbix_agentd.conf UserParameter=sda_tps,iostat|awk '$1 ~/sda/{print $2}' systemctl restart zabbix-agent.service
7.3:zabbix-server测试监控项取值
zabbix_get -s 127.0.0.1 -k sda_tps
7.4:在web界面添加自定义监控项
8:自定义触发器
9:邮件报警和微信报警
邮件报警
9.1.1: 定义发件人
9.1.2:收件人
定制报警的内容
https://www.zabbix.com/documentation/4.0/zh/manual/appendix/macros/supported_by_location
9.2.1微信报警
9.2.2:将weixin.py放在zabbix特定目录/usr/lib/zabbix/alertscripts
9.2.3:配置发件人
9.2.4:收件人
9.2.5:测试
10:自定义图像,grafana
10.1 zabbix自定义图形
预览效果