zabbix部署及监控测试

环境准备

准备虚拟机
192.168.90.30 zabbixserver zbxserver.com centos7 3G 50G zabbix server 即webUI所在的服务器
192.168.90.20 zabbixagent mysql.com centos7 3G 50G mysql服务器即 zabbixagent 所在的服务器

配置域名:
两台服务器分别配置host

[root@localhost conf.d]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.90.20 mysql.com
192.168.90.30 zbxserver.com

安装MySQL
自行安装

部署配置server

192.168.90.30 服务器部署zabbix server
关闭防火墙和selinux

[root@localhost ~]# setenforce 0
[root@localhost ~]# sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/’ /etc/selinux/config
[root@localhost ~]# systemctl stop firewalld.service

安装并更新zabbix仓库

[root@localhost ~]# wget https://repo.zabbix.com/zabbix/4.2/rhel/7/x86_64/zabbix-release-4.2-1.el7.noarch.rpm
[root@localhost ~]# rpm -ivh zabbix-release-4.2-1.el7.noarch.rpm
警告:zabbix-release-4.2-1.el7.noarch.rpm: 头V4 RSA/SHA512 Signature, 密钥 ID a14fe591: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:zabbix-release-4.2-1.el7         ################################# [100%]
[root@localhost ~]# yum repolist
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
 * base: mirrors.bfsu.edu.cn
 * extras: mirrors.bupt.edu.cn
 * updates: mirrors.bupt.edu.cn
base                                                                                                            | 3.6 kB  00:00:00     
extras                                                                                                          | 2.9 kB  00:00:00     
updates                                                                                                         | 2.9 kB  00:00:00     
zabbix                                                                                                          | 2.9 kB  00:00:00     
zabbix-non-supported                                                                                            | 2.9 kB  00:00:00     
(1/4): extras/7/x86_64/primary_db                                                                               | 243 kB  00:00:00     
(2/4): zabbix-non-supported/x86_64/primary_db                                                                   | 3.7 kB  00:00:00     
(3/4): zabbix/x86_64/primary_db                                                                                 |  71 kB  00:00:01     
(4/4): updates/7/x86_64/primary_db                                                                              |  11 MB  00:00:01     
源标识                                               源名称                                                                      状态
base/7/x86_64                                        CentOS-7 - Base                                                             10,072
extras/7/x86_64                                      CentOS-7 - Extras                                                              500
updates/7/x86_64                                     CentOS-7 - Updates                                                           2,747
zabbix/x86_64                                        Zabbix Official Repository - x86_64                                            132
zabbix-non-supported/x86_64                          Zabbix Official Repository non-supported - x86_64                                5
repolist: 13,456

安装zabbix

[root@localhost ~]# yum -y install epel-release.noarch
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
.....


[root@localhost ~]# yum -y install zabbix-agent zabbix-get zabbix-sender zabbix-server-mysql zabbix-web zabbix-web-mysql
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                                                                            | 7.5 kB  00:00:00     
  base: mirrors.bfsu.edu.cn
 ......
作为依赖被安装:
  OpenIPMI.x86_64 0:2.0.27-1.el7           OpenIPMI-libs.x86_64 0:2.0.27-1.el7            OpenIPMI-modalias.x86_64 0:2.0.27-1.el7      
  apr.x86_64 0:1.4.8-7.el7                 apr-util.x86_64 0:1.5.2-6.el7                  fping.x86_64 0:3.16-1.el7                    
  httpd.x86_64 0:2.4.6-97.el7.centos       httpd-tools.x86_64 0:2.4.6-97.el7.centos       libzip.x86_64 0:0.10.1-8.el7                 
  mailcap.noarch 0:2.1.41-2.el7            php.x86_64 0:5.4.16-48.el7                     php-bcmath.x86_64 0:5.4.16-48.el7            
  php-cli.x86_64 0:5.4.16-48.el7           php-common.x86_64 0:5.4.16-48.el7              php-gd.x86_64 0:5.4.16-48.el7                
  php-ldap.x86_64 0:5.4.16-48.el7          php-mbstring.x86_64 0:5.4.16-48.el7            php-mysql.x86_64 0:5.4.16-48.el7             
  php-pdo.x86_64 0:5.4.16-48.el7           php-xml.x86_64 0:5.4.16-48.el7                 t1lib.x86_64 0:5.1.2-14.el7                  
  unixODBC.x86_64 0:2.3.1-14.el7      

配置zabbixserver

找到zabbix数据初始化sql,并复制到 mysql服务器

[root@localhost ~]# rpm -ql zabbix-server-mysql
/etc/logrotate.d/zabbix-server
/etc/zabbix/zabbix_server.conf
/usr/lib/systemd/system/zabbix-server.service
/usr/lib/tmpfiles.d/zabbix-server.conf
/usr/lib/zabbix/alertscripts
/usr/lib/zabbix/externalscripts
/usr/sbin/zabbix_server_mysql
/usr/share/doc/zabbix-server-mysql-4.2.8
/usr/share/doc/zabbix-server-mysql-4.2.8/AUTHORS
/usr/share/doc/zabbix-server-mysql-4.2.8/COPYING
/usr/share/doc/zabbix-server-mysql-4.2.8/ChangeLog
/usr/share/doc/zabbix-server-mysql-4.2.8/NEWS
/usr/share/doc/zabbix-server-mysql-4.2.8/README
/usr/share/doc/zabbix-server-mysql-4.2.8/create.sql.gz
/usr/share/man/man8/zabbix_server.8.gz
/var/log/zabbix
/var/run/zabbix
[root@localhost ~]# scp /usr/share/doc/zabbix-server-mysql-4.2.8/create.sql.gz root@192.168.90.20:/root/

mysql服务器创建数据库,并执行初始化sql

[root@localhost ~]# zcat create.sql.gz > create.sql
[root@localhost mysql]# bin/mysql -uroot -p**
mysql>create database zabbix;
mysql>GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY 'zabbix';
mysql> flush privileges;
mysql> use zabbix
Database changed
mysql> source /root/create.sql

修改server端配置文件

[root@localhost ~]# cp /etc/zabbix/zabbix_server.conf{,_bak}   --备份文件
[root@localhost ~]# cd /etc/zabbix/
[root@localhost zabbix]# ls
web  zabbix_agentd.conf  zabbix_agentd.d  zabbix_server.conf  zabbix_server.conf_bak
[root@localhost zabbix]# vi zabbix_server.conf  

修改如下内容,并保存

ListenPort=10051            # 默认监听端口
SourceIP=192.168.37.111     # 发采样数据请求的 IP
DBHost=192.168.90.20     #数据库对外的主机
DBName=zabbix               #数据库名称
DBUser=zabbix              #数据库用户
DBPassword=zabbix             #数据库密码
DBPort=3306                 #数据库启动端口

启动zabbixServer服务

[root@localhost zabbix]# systemctl start zabbix-server.service
[root@localhost zabbix]# ss -nutl |grep 10051
tcp    LISTEN     0      128       *:10051                 *:*                  
tcp    LISTEN     0      128      :::10051                :::*  

部署配置webUI

找到配置文件并备份

[root@localhost zabbix]#  rpm -ql zabbix-web | less
/etc/httpd/conf.d/zabbix.conf
/etc/zabbix/web
/etc/zabbix/web/maintenance.inc.php
/etc/zabbix/web/zabbix.conf.php
/usr/share/doc/zabbix-web-3.2.6
......
[root@localhost zabbix]# cp /etc/httpd/conf.d/zabbix.conf{,_bak}
[root@localhost zabbix]# cd /etc/httpd/conf.d/
[root@localhost conf.d]# ll
总用量 28
-rw-r--r--. 1 root root 2926 1117 2020 autoindex.conf
-rw-r--r--. 1 root root  691 41 2020 php.conf
-rw-r--r--. 1 root root  366 1117 2020 README
-rw-r--r--. 1 root root 1252 1116 2020 userdir.conf
-rw-r--r--. 1 root root  824 1116 2020 welcome.conf
-rw-r--r--. 1 root root  870 826 2019 zabbix.conf
-rw-r--r--. 1 root root  870 911 17:50 zabbix.conf_bak
[root@localhost conf.d]# vi zabbix.conf

修改配置文件

Alias /zabbix /usr/share/zabbix #访问的时候要在主机后加上/zabbix来访问服务

php_value date.timezone Asia/Shanghai

启动httpd服务

[root@localhost conf.d]# systemctl enable httpd
[root@localhost conf.d]# systemctl start httpd
[root@localhost conf.d]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since 六 2021-09-11 18:03:34 CST; 12s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 13796 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
    Tasks: 6
   CGroup: /system.slice/httpd.service
           ├─13796 /usr/sbin/httpd -DFOREGROUND
           ├─13798 /usr/sbin/httpd -DFOREGROUND
           ├─13799 /usr/sbin/httpd -DFOREGROUND
           ├─13800 /usr/sbin/httpd -DFOREGROUND
           ├─13801 /usr/sbin/httpd -DFOREGROUND
           └─13802 /usr/sbin/httpd -DFOREGROUND

911 18:03:34 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
911 18:03:34 localhost.localdomain httpd[13796]: AH00558: httpd: Could not reliably determine the server's fully qualified...essage
911 18:03:34 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.

浏览器访问并配置
浏览器访问如下地址:http://192.168.90.30/zabbix/
点击下一步
在这里插入图片描述

确认配置项,点击下一步:
在这里插入图片描述

配置数据库信息,下一步
在这里插入图片描述
输入zabbix服务器的地址和端口,下一步
在这里插入图片描述
确认配置信息,下一步
在这里插入图片描述
安装成功
在这里插入图片描述

输入 admin zabbix 登录
在这里插入图片描述

登录成功进入系统
在这里插入图片描述

部署配置agent

192.168.90.20服务器部署agent
部署agent

[root@localhost ~]# wget https://repo.zabbix.com/zabbix/4.2/rhel/7/x86_64/zabbix-release-4.2-1.el7.noarch.rpm
[root@localhost ~]# rpm -ivh zabbix-release-4.2-1.el7.noarch.rpm 
[root@localhost ~]# yum -y install epel-release.noarch
[root@localhost ~]# yum install zabbix-agent zabbix-sender -y

备份并修改配置文件

[root@localhost ~]# rpm -ql zabbix-agent 
/etc/logrotate.d/zabbix-agent
/etc/zabbix/zabbix_agentd.conf
/etc/zabbix/zabbix_agentd.d
/etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
/usr/lib/systemd/system/zabbix-agent.service
/usr/lib/tmpfiles.d/zabbix-agent.conf
/usr/sbin/zabbix_agentd
/usr/share/doc/zabbix-agent-4.2.8
/usr/share/doc/zabbix-agent-4.2.8/AUTHORS
/usr/share/doc/zabbix-agent-4.2.8/COPYING
/usr/share/doc/zabbix-agent-4.2.8/ChangeLog
/usr/share/doc/zabbix-agent-4.2.8/NEWS
/usr/share/doc/zabbix-agent-4.2.8/README
/usr/share/man/man8/zabbix_agentd.8.gz
/var/log/zabbix
/var/run/zabbix
[root@localhost ~]# cp /etc/zabbix/zabbix_agentd.conf{,_bak}
[root@localhost ~]# cd /etc/zabbix/
[root@localhost zabbix]# ls
web  zabbix_agentd.conf  zabbix_agentd.conf_bak  zabbix_agentd.d  zabbix_server.conf
[root@localhost zabbix]# vi zabbix_agentd.conf

配置文件结构说明
在这里插入图片描述
修改内容如下:

Server=192.168.90.30      # 指明服务器是谁的
ListenPort=10050            # 自己监听的端口
ListenIP=0.0.0.0            # 自己监听的地址,0.0.0.0表示本机所有地址
StartAgents=3               # 优化时使用的

ServerActive=192.168.90.30   # 主动监控时的服务器
Hostname=mysql.com    # 自己能被server端识别的名称

启动服务

[root@localhost zabbix]# systemctl start zabbix-agent.service
[root@localhost zabbix]#  ss -ntul |grep 10050
tcp    LISTEN     0      128       *:10050                 *:*  

监控测试

修改为中文界面
在这里插入图片描述

创建主机群组
zabbix中主机就是被监控的对象,而且每个主机要归属到一个主机群组中

通过如下菜单创建名未mysql20的主机群组
在这里插入图片描述

创建主机
通过如下菜单创建主机
在这里插入图片描述
主机明细如下,这里我们根据mysql所在服务器的信息填写
可见的名称就是主机简称
在这里插入图片描述
创建完成后主机列表中可以看到我i们创建的主机。

为主机创建应用集

主机列表中点击mysql主机,进入如下界面。通过如下菜单创建应用集,应用集可以理解为监控指标的集合
在这里插入图片描述
这里我们对cpu监控,填写CPU
在这里插入图片描述
为主机创建监控项
监控项就是具体的监控指标,点击主机名称,进入如下界面,点击创建监控项创建
在这里插入图片描述

监控项明细如下,这里我们选择最简单的 cpu中断数。

在这里插入图片描述

在这里插入图片描述
创建完成后,在主机列表界面我们看到mysql主机 可用性列zbx显示绿色,同时可以看到应用集和监控项的数量等
在这里插入图片描述

点击如下菜单可以我们创建的监控项列表

在这里插入图片描述
点击图形 选择合适的时间区间,可以看到指标数据图如下
在这里插入图片描述

点击仪表板的编辑仪表盘
在这里插入图片描述

空白处点击可以追加构件
在这里插入图片描述
选择图形 ,数据设置选择 mysql mysql20CPU 监控项,选择合适的时间区间
在这里插入图片描述
显示选项选择自动
在这里插入图片描述
时间区间选择10分钟
在这里插入图片描述
选择应用,效果如下

在这里插入图片描述

乱码问题解决

图形图例的中文显示为乱码
在这里插入图片描述

默认使用的是DejaVuSans字体,是一款英文字体

[root@zbxserver ~]# ll /etc/alternatives/ |grep zabbix-web-font
lrwxrwxrwx. 1 root root 38 912 10:04 zabbix-web-font -> /usr/share/fonts/dejavu/DejaVuSans.ttf

删除原来的文件链接,并将新的字体文件 链接到中文字体/usr/share/fonts/vlgothic/VL-Gothic-Regular.ttf

[root@zbxserver ~]# rm /etc/alternatives/zabbix-web-font
[root@zbxserver ~]# ln -s /usr/share/fonts/vlgothic/VL-Gothic-Regular.ttf  /etc/alternatives/zabbix-web-font

刷新页面后中文显示正常
在这里插入图片描述

有的服务器上没有安装其他字体,我这里将windows系统的字体上传使用后,无法正常使用,可以先用以下命令安装字体,然后选择中文字体

sudo yum groupinstall Fonts
  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

catch that elf

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值