zabbix监控搭建(基础)

一、Zabbix介绍

Zabbix是一个监控系统,它可以帮助我们实时检查设备的状态,比如服务器、网络设备等。当设备出现问题时,它会及时通知我们,让我们可以采取措施来解决。同时,它还可以把收集到的数据转化成图表和报告,让我们更直观地了解设备的运行情况

1、监控的作用

任何你所想要监控的数据, 如cpu负载,cpu的idle时间,内存使用量,内存利用率,io,network等等。
现在很多开源监控方案已经把常见的监控做成了模板,我们可以直接套用
大型公司会有更多的监控需求, 那么就需要专业的开发人员来做监控开发(运维人员也可以开发)

2、zabbix特性

数据采集

Zabbix Agent方式会定期收集设备的各种指标数据,比如CPU使用率、内存占用、网络流量等。这些数据会被Zabbix Server主动获取。

触发检测告警

Zabbix会根据我们事先设定的阈值和触发条件,对采集到的数据进行检测。如果某个指标超过了阈值或满足了触发条件,Zabbix会触发一个告警。Zabbix会根据事先设置的通知方式,比如邮件、短信等,通知相关的人员或团队。这样我们可以及时知道设备出现了问题。

数据存储

Zabbix将采集到的数据存储在数据库中

数据展示

Zabbix提供了丰富的可视化功能,可以将采集到的数据转化成各种图表和报表。这样我们可以直观地了解设备的运行状态和趋势。

3、zabbix结构

在这里插入图片描述
Zabbix-server:收集监控数据,计算是否满足触发条件,向用户发送通知

Zabbix-database:所有配置信息和Zabbix收集到的数据都被存储在数据库中

Zabbix-Web:为了在任何地方和任何平台都能轻松地访问Zabbix,Zabbix提供了基于Web的界面。该界面是Zabbix Server的一部分,通常跟Zabbix Server运行在同一台物理机器上。

Zabbix-proxy:Zabbix Proxy可以替Zabbix Server收集性能和可用性数据。Proxy代理服务器是Zabbix 软件可选择部署的一部分。当然,Proxy代理服务器可以帮助单台Zabbix Server分担负载压力。

Zabbix-agent:Zabbix Agents监控代理部署在监控目标上,主动监控本地资源和应用(硬件驱动,内存等)

4、主流的开源监控平台介绍

mrtg (Multi Router Traffic Grapher)

通过snmp协议得到设备的流量信息,并以包含PNG格式的图形的HTML文档方式显示给用户。

cacti (仙人掌)

用php语言实现的一个软件,它的主要功能是用snmp服务获取数据,然后用rrdtool储存和更新数据。官网地址:https://www.cacti.net/

ntop

官网地址: https://www.ntop.org/

nagios

能够跨平台,插件多,报警功能强大。官网地址:https://www.nagios.org/

centreon

底层使用的就是nagios。是一个nagios整合版软件。官网地址:https://www.centreon.

ganglia

设计用于测量数以千计的节点,资源消耗非常小。官网地址:http://ganglia.info/

open-falcon

小米公司开源,高效率,高可用。用户基数相对小。官网地址:http://open-falcon.org/

zabbix

跨平台,画图,多条件告警,多种API接口。用户基数大。官网地址:https://www.zabbix.com/

prometheus

基于时间序列的数值数据的容器监控解决方案。官网地址:https://prometheus.io

二、安装zabbix

环境:rocky Linux 9虚拟机一台,selinux与firewalld均已关闭,使用Xshell连接

1、安装工具包

[root@zabbix ~]# yum -y install lrzsz tar net-tools chrony 
//时钟同步
[root@zabbix ~]# systemctl restart chronyd
[root@zabbix ~]# systemctl enable chronyd
[root@zabbix ~]# hwclock -w

2、配置zabbix源

//将包文件直接拖进来
[root@zabbix ~]# rz -E
rz waiting to receive.
[root@zabbix ~]# ls
anaconda-ks.cfg  zabbix-release-7.0-2.el9.noarch.rpm
[root@zabbix ~]# rpm -Uvh zabbix-release-7.0-2.el9.noarch.rpm 
warning: zabbix-release-7.0-2.el9.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID b5333005: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:zabbix-release-7.0-2.el9         ################################# [100%]

将zabbix的源换成阿里源
[root@zabbix ~]# vim /etc/yum.repos.d/zabbix.repo
//将该文件内容替换为以下内容
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/7.0/rocky/9/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-B5333005

[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/9/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-08EFA7DD
gpgcheck=1

[zabbix-sources]
name=Zabbix Official Repository source code - $basearch
baseurl=https://repo.zabbix.com/zabbix/7.0/rocky/9/SRPMS
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-B5333005
gpgcheck=1

在epel源后面添加一行
[root@zabbix ~]# vim /etc/yum.repos.d/epel.repo 
//[epel]这个标签的末尾加上一行信息,否则安装会报错
[epel]
......
excludepkgs=zabbix*

3、安装zabbix、web前端、agent、数据库包文件

[root@zabbix ~]# yum install zabbix-server-mysql zabbix-web-mysql zabbix-nginx-conf zabbix-sql-scripts zabbix-selinux-policy zabbix-agent mariadb-server mariadb -y

4、启动并初始化数据库

//启动数据库
[root@zabbix ~]# systemctl restart mariadb
[root@zabbix ~]# systemctl enable mariadb
//初始化数据库
[root@zabbix ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] y
Enabled successfully!
Reloading privilege tables..
 ... Success!


You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] y
New password: 输入密码
Re-enter new password: 再次输入密码
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n
 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

5、配置数据库并导入zabbix表数据

[root@zabbix ~]# mysql -uroot -predhat
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 10.5.22-MariaDB MariaDB Server

Copyright (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)]> create database zabbix character set utf8mb4 collate utf8mb4_bin;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> create user zabbix@localhost identified by 'redhat';
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost;
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> set global log_bin_trust_function_creators = 1;
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> exit
Bye

[root@zabbix ~]# zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p zabbix
Enter password: //这里输入数据库密码

6、导入数据库架构后禁用log_bin_trust_function_creators选项

[root@zabbix ~]# myaql -uroot -predhat
bash: myaql: command not found
[root@zabbix ~]# mysql -uroot -predhat
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 10.5.22-MariaDB MariaDB Server

Copyright (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)]> set global log_bin_trust_function_creators = 0;
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]>  flush privileges;
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> exit
Bye

7、配置zabbix并启动服务

[root@zabbix ~]# vim /etc/zabbix/zabbix_server.conf
//找到并修改以下内容,内容一样的去掉#
//内容不一样就修改并去掉#
ListenPort=10051        
DBHost=localhost 
DBName=zabbix 
DBUser=zabbix 
DBPassword=redhat              
DBSocket=/var/lib/mysql/mysql.sock 
ListenIP=0.0.0.0 

8、zabbix配置启动服务—浏览器访问

//编辑配置文件 /etc/nginx/conf.d/zabbix.conf 取消注释并设置“listen”和“server_name”指令
[root@zabbix ~]# vim /etc/nginx/conf.d/zabbix.conf 
        listen          8080;
        server_name     example.com;


//启动以下服务并enable
[root@zabbix ~]# systemctl restart zabbix-server zabbix-agent nginx php-fpm
[root@zabbix ~]# systemctl enable zabbix-server zabbix-agent nginx php-fpm

//浏览器访问http://192.168.100.115:8080/setup.php
注:ip换成自己的
在这里插入图片描述

9、解决支持中文

[root@zabbix ~]# yum -y install langpacks-zh_CN.noarch glibc-common
[root@zabbix ~]#  locale -a | grep zh_CN
zh_CN
zh_CN.gb18030
zh_CN.gbk
zh_CN.utf8

然后刷新浏览器

10、设置浏览器界面

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

下一步再接完成就配置好了,就可以进入登陆界面了

默认账号为Admin,密码为zabbix
在这里插入图片描述

11、解决中午乱码问题

找到windows下的简体 楷体 常规字体
C:\Windows\Fonts
将简体 楷体 常规字体文件复制出来上传到Linux系统中的/usr/share/zabbix/assets/fonts
替换原先的字体文件即可

[root@zabbix ~]# cd /usr/share/zabbix/assets/fonts/
[root@zabbix fonts]# rz -E
rz waiting to receive.
[root@zabbix fonts]# ls
graphfont.ttf  SIMKAI.TTF  zabbix-icons.svg  zabbix-icons.ttf  zabbix-icons.woff  zabbix-icons.woff2
[root@zabbix fonts]# mv SIMKAI.TTF graphfont.ttf
mv: overwrite 'graphfont.ttf'? y

12、监控远程主机

//新开一台虚拟机

[root@node6 ~]# rz -E
rz waiting to receive.  //将包文件拖进来
[root@node6 ~]#  rpm -Uvh zabbix-release-7.0-2.el9.noarch.rpm
warning: zabbix-release-7.0-2.el9.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID b5333005: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:zabbix-release-7.0-2.el9         ################################# [100%]
[root@node6 ~]# vim /etc/yum.repos.d/zabbix.repo 

[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/7.0/rocky/9/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-B5333005

[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/9/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-08EFA7DD
gpgcheck=1

[zabbix-sources]
name=Zabbix Official Repository source code - $basearch
baseurl=https://repo.zabbix.com/zabbix/7.0/rocky/9/SRPMS
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-B5333005
gpgcheck=1

[root@node6 ~]# vim /etc/yum.repos.d/epel.repo 
[epel]
......//在epel源后面添加一行
excludepkgs=zabbix*

[root@node6 ~]# yum -y install zabbix-agent chrony lazsz net-tools
[root@node6 ~]# systemctl restart chronyd
[root@node6 ~]# systemctl enable chronyd
[root@node6 ~]# hwclock -w

[root@node6 ~]# vim /etc/zabbix/zabbix_agentd.conf 
Server=192.168.100.40 				zabbix服务器的IP,agent被动监控(默认模式) 
ServerActive=192.168.100.40 			zabbix服务器的IP,agent主动监控 
Hostname=zabbix-agent 				zabbix服务器的主机名

[root@node6 ~]# systemctl restart zabbix-agent
[root@node6 ~]# systemctl enable zabbix-agent

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
完成

  • 25
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值