zabbix监控服务器部署
- 一、监控的作用
- 1、监控的方式
- 2、zabbix监控获取数据的方式
- 二、zabbix server部署
- 1、确保时间同步
- 2、添加epel源
- 3、添加zabbix仓库
- 4、安装zabbix服务端软件
- 5、在数据库创建zabbix需要的表、授权用户
- 6、编辑zabbix server配置文件,指定数据库连接
- 7、启动zabbix server
- 8、初始化zabbix webUI
- 9、访问zabbix webUI
- 三、本机监控配置
- 1、安装配置zabbix-agent
- 2、在web界面修改agent监听地址
- 3、查看监控图形
- 4、解决图形乱码问题
一、监控的作用
发现问题、解决问题、预防问题
1、监控的方式
- 人工巡检,巡检脚本
- 监控软件
zabbix
promethues
2、zabbix监控获取数据的方式
- zabbix-agent, 适用于服务器、主机监控
- SNMP协议,适用于网络设备(交换机、路由器、防火墙、IDS/IPS)
udp/161, v2版本稳定版 - IPMI协议,适用于监控硬件设备信息(温度、序列号)
- JMX协议,适用于java应用的监控
二、zabbix server部署
1、确保时间同步
[root@zabbix_server ~]# crontab -l
*/30 * * * * /usr/sbin/ntpdate 120.25.115.20 &> /dev/null[root@zabbix_server ~]# ntpdate 120.25.115.20
20 Jun 10:33:44 ntpdate[1553]: step time server 120.25.115.20 offset -86399.438588 sec
2、添加epel源
[root@zabbix_server ~]# wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
--2024-06-20 10:38:23-- https://mirrors.aliyun.com/repo/epel-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 182.201.241.69, 182.201.241.67, 42.202.209.193, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|182.201.241.69|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 664 [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/epel.repo’100%[============================================================================================>] 664 --.-K/s in 0.005s 2024-06-20 10:38:24 (124 KB/s) - ‘/etc/yum.repos.d/epel.repo’ saved [664/664]
3、添加zabbix仓库
[root@zabbix_server ~]# cat /etc/yum.repos.d/zabbix.repo
[zabbix]
name=zabbix
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/4.4/rhel/7/x86_64/
enabled=1
gpgcheck=0
4、安装zabbix服务端软件
[root@zabbix_server ~]# yum install -y mariadb-server zabbix-server-mysql zabbix-web-mysql
5、在数据库创建zabbix需要的表、授权用户
[root@zabbix_server ~]# mysql -uroot
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.68-MariaDB MariaDB ServerCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]>
MariaDB [(none)]> create database zabbix charset utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)MariaDB [(none)]> create user 'zbuser'@'localhost' identified by 'redhat';
Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> grant all on zabbix.* to 'zbuser'@'localhost';
Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]>
[root@zabbix_server ~]# cd /usr/share/doc/zabbix-server-mysql-4.4.10/
[root@zabbix_server zabbix-server-mysql-4.4.10]# ls
AUTHORS ChangeLog COPYING create.sql.gz NEWS README
[root@zabbix_server zabbix-server-mysql-4.4.10]#
[root@zabbix_server zabbix-server-mysql-4.4.10]# zcat create.sql.gz | mysql -uroot zabbix
6、编辑zabbix server配置文件,指定数据库连接
[root@zabbix_server ~]# vim /etc/zabbix/zabbix_server.conf DBHost=localhost
DBName=zabbix
DBUser=zbuser
DBPassword=redhat
DBSocket=/var/lib/mysql/mysql.sock
7、启动zabbix server
[root@zabbix_server ~]# systemctl enable --now zabbix-server[root@zabbix_server ~]# netstat -tunlp | grep zabbix
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 2155/zabbix_server
tcp6 0 0 :::10051 :::* LISTEN 2155/zabbix_server
8、初始化zabbix webUI
[root@zabbix_server ~]# vim /etc/httpd/conf.d/zabbix.conf
php_value date.timezone Asia/Shanghai[root@zabbix_server ~]# systemctl enable --now httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@zabbix_server ~]#
9、访问zabbix webUI
http://192.168.140.10/zabbix/
默认用户名:Admin, 密码: zabbix
三、本机监控配置
1、安装配置zabbix-agent
[root@zabbix_server ~]# yum install -y zabbix-agent
[root@zabbix_server ~]# vim /etc/zabbix/zabbix_agentd.conf
Server=监控服务器地址
ServerActive=监控服务器地址
Hostname=Zabbix server // 被监控机名称,惟一zabbix-agent两种工作模式:主动、被动; 默认为被动
[root@zabbix_server ~]# systemctl enable --now zabbix-agent[root@zabbix_server ~]# netstat -tunlp | grep zabbix
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 4775/zabbix_agentd
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 2155/zabbix_server
tcp6 0 0 :::10050 :::* LISTEN 4775/zabbix_agentd
tcp6 0 0 :::10051 :::* LISTEN 2155/zabbix_server
2、在web界面修改agent监听地址
3、查看监控图形
4、解决图形乱码问题
[root@zabbix_server ~]# mv simkai.ttf /usr/share/zabbix/assets/fonts/
[root@zabbix_server ~]# ls /usr/share/zabbix/assets/fonts/
graphfont.ttf simkai.ttf
[root@zabbix_server ~]# [root@zabbix_server ~]# vim /usr/share/zabbix/include/defines.inc.php
define('ZBX_GRAPH_FONT_NAME', 'simkai'); // font file name
define('ZBX_FONT_NAME', 'simkai');