zabbix的使用,监控一台主机
一,添加主机
[root@\ db02~]# rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
[root@\ db02~]# yum install zabbix-agent -y
[root@\ db02~]# vim /etc/zabbix/zabbix_agentd.conf
...
# 修改server的ip地址,即server端的IP
Server=192.168.15.199
...
# 启动
[root@\ db02~]# systemctl start zabbix-agent
[root@\ db02~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 535/rpcbind
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 839/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1271/master
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 1490/zabbix_agentd
tcp6 0 0 :::3306 :::* LISTEN 1255/mysqld
tcp6 0 0 :::111 :::* LISTEN 535/rpcbind
tcp6 0 0 :::22 :::* LISTEN 839/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1271/master
tcp6 0 0 :::10050 :::* LISTEN 1490/zabbix_agentd
二,添加键值
在zabbix-server 端获取agent端数据,使用zabbix_get命令
1,安装zabbix_get命令
[root@zabbix ~]# yum install -y zabbix-get
2, zabbix_get命令测试
# 自带查看数据库信息的键值
root@\ db02/etc/zabbix/zabbix_agentd.d]# cd
[root@\ db02~]# cd /etc/zabbix/zabbix_agentd.d/
[root@\ db02/etc/zabbix/zabbix_agentd.d]# ll
-rw-r--r-- 1 root root 1531 Nov 12 2018 userparameter_mysql.conf
[root@\ db02/etc/zabbix/zabbix_agentd.d]# vim userparameter_mysql.conf
...
UserParameter=mysql.ping,HOME=/var/lib/zabbix mysqladmin ping | grep -c alive
...
# zabbix_server端查看
[root@\ zabbix~]# zabbix_get -s 192.168.15.152 -p 10050 -k 'mysql.ping'
1
# 在zabbix_agent服务器添加键值
[root@\ db02/etc/zabbix/zabbix_agentd.d]# cat userparameter_memory.conf
UserParameter=memory,free -m | awk -F ' ' 'NR==2 {print $4}'
##格式:
UserParameter=命名,命令
# 重启服务
[root@\ db02/etc/zabbix/zabbix_agentd.d]# systemctl restart zabbix-agent.service
# zabbix_server端查看
[root@\ zabbix~]# zabbix_get -s 192.168.15.152 -p 10050 -k 'memory'
123
# 验证
[root@\ db02/etc/zabbix/zabbix_agentd.d]# free -m
total used free shared buff/cache available
Mem: 972 580 123 13 267 241
Swap: 2047 0 2047
三,创建用户, 添加主机/模板,创建监控项
1,添加用户



2,添加主机





3,创建监控项
需要定义在zabbix_agent机器的文件中



[root@\ db02/etc/zabbix/zabbix_agentd.d]# free -m
total used free shared buff/cache available
Mem: 972 580 116 13 274 241
Swap: 2047 0 2047
4,自定义模板



agent服务器添加键值文件
[root@\ db02/etc/zabbix/zabbix_agentd.d]# cat userparameter_user.conf
UserParameter=memory,uptime | awk -F ' ' '{print $4}'




四,添加报警





五,第三方报警平台
1,安装 Agent

# 切换到zabbix脚本目录
[root@\ zabbix~]# cd /usr/lib/zabbix/externalscripts/
[root@\ zabbix/usr/lib/zabbix/alertscripts]# wget https://download.aiops.com/ca_agent/zabbix/ca_zabbix_release-3.0.1.tar.gz
--2021-04-29 18:01:01-- https://download.aiops.com/ca_agent/zabbix/ca_zabbix_release-3.0.1.tar.gz
Resolving download.aiops.com (download.aiops.com)... 39.96.131.192
Connecting to download.aiops.com (download.aiops.com)|39.96.131.192|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3930 (3.8K) [text/plain]
Saving to: ‘ca_zabbix_release-3.0.1.tar.gz’
100%[===================================================================================================================================================>] 3,930 --.-K/s in 0s
2021-04-29 18:01:02 (428 MB/s) - ‘ca_zabbix_release-3.0.1.tar.gz’ saved [3930/3930]
[root@\ zabbix/usr/lib/zabbix/alertscripts]# tar -xzf ca_zabbix_release-3.0.1.tar.gz
[root@\ zabbix/usr/lib/zabbix/alertscripts]# ll
total 4
-rw-r--r-- 1 root root 3930 Jan 12 20:14 ca_zabbix_release-3.0.1.tar.gz
drwxr-xr-x 3 root root 17 Nov 17 18:05 cloudalert
[root@\ zabbix/usr/lib/zabbix/alertscripts]# cd cloudalert/
[root@\ zabbix/usr/lib/zabbix/alertscripts/cloudalert]# ll
drwxr-xr-x 2 root root 73 Nov 17 18:05 bin
[root@\ zabbix/usr/lib/zabbix/alertscripts/cloudalert]# cd bin/
[root@\ zabbix/usr/lib/zabbix/alertscripts/cloudalert/bin]# ll
-rwxr-xr-x 1 root root 581 Oct 21 2020 alert.sh
-rw-r--r-- 1 root root 642 Oct 21 2020 funcs
-rwxr-xr-x 1 root root 10115 Nov 17 18:03 install.sh
-rwxr-xr-x 1 root root 2591 Nov 17 18:04 uninstall.sh
# 默认账户名Admin,密码zabbix
[root@\ zabbix/usr/lib/zabbix/alertscripts/cloudalert/bin]# bash install.sh cb6d0322-5375-4b3b-baa4-3581ba43945a
请输入Zabbix管理地址:http://192.168.15.199/zabbix
Check connection success!
请输入Zabbix管理员账号:Admin
请输入Zabbix管理员密码: % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 170 100 70 100 100 1853 2647 --:--:-- --:--:-- --:--:-- 2702
Authentication success!
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 109 100 42 100 67 1291 2060 --:--:-- --:--:-- --:--:-- 2093
Check api version success!
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 313 100 56 100 257 1450 6656 --:--:-- --:--:-- --:--:-- 6763
Create new media type success!
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 192 100 54 100 138 1390 3553 --:--:-- --:--:-- --:--:-- 3631
Create new group success!
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 397 100 51 100 346 1145 7770 --:--:-- --:--:-- --:--:-- 7863
Create new user success!
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1580 100 51 100 1529 1095 32835 --:--:-- --:--:-- --:--:-- 33239
Create new action success!
Install zabbix agent success!
# 重启zabbix_server
[root@\ zabbix~]# systemctl restart zabbix-server.service
2, 查看zabbix页面

3,配置

4,配置时间及通知

5,zabbix更改动作-> 操作

6,收到报警邮箱


网友评论