Linux之zabbix监控介绍与搭建(附思维导图)

zabbix介绍:

1、zabbix简介

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

2、zabbix特性

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

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

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

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

3、zabbix结构图

1、Zabbix Server
        这是Zabbix的核心组件,负责接收Agent发送的数据,处理数据,触发告警等。Server也可以主动向Agent请求获取需要的监控数据。一个Zabbix安装实例可以包含一个或多个Zabbix Server,以提供高可用性和可扩展性。
2.、Zabbix Agent
        部署在被监控目标上,它负责定期收集本地的监控数据(如CPU、内存、磁盘使用情况等)并发送给Zabbix Server。Agent也可以执行Server发送的命令(例如重启服务或执行脚本)。
3.、Zabbix Proxy
        是一个可选组件,常用于分布式监控环境中。Proxy可以代替Server收集Agent发送的数据,然后再将数据转发给Server,这样可以减轻Server的负担并提高数据收集的效率。
4、Zabbix Web
        这是Zabbix的用户界面,用户可以通过Web界面配置监控项、查看监控数据和接收告警等。Web界面非常灵活,支持自定义仪表板、报表和告警设置。
5、Zabbix Database
        用于存储所有的配置信息、监控数据和历史数据。Zabbix支持多种数据库,如MySQL、PostgreSQL、Oracle等。

主流的开源监控平台介绍:

  • 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.com/
  • ganglia 设计用于测量数以千计的节点,资源消耗非常小。官网地址:http://ganglia.info/
  • open-falcon 小米公司开源,高效率,高可用。用户基数相对小。官网地址: http://open-falcon.org/
  • zabbix 跨平台,画图,多条件告警,多种API接口。用户基数大。官网地址: https://www.zabbix.com/
  • prometheus 基于时间序列的数值数据的容器监控解决方案。官网地址: https://prometheus.io/

思维导图:

 

开始部署zabbix监控:

关闭防火墙,selinux,设置时钟同步;安装zabbix源

[root@zabbix-server ~]# ls
anaconda-ks.cfg  zabbix-release-7.0-2.el9.noarch.rpm
[root@zabbix-server ~]# 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@zabbix-server ~]#  ls /etc/yum.repos.d/
backup                    rocky-addons.repo      rocky-extras.repo      zabbix.repo
epel-cisco-openh264.repo  rocky-addons.repo.bak  rocky-extras.repo.bak   // zabbix源
epel.repo                 rocky-devel.repo       rocky.repo
epel-testing.repo         rocky-devel.repo.bak   rocky.repo.bak
 
///将zabbix的源换成阿里源/
[root@zabbix-server ~]# cat /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

修改/etc/yum.repos.d/epel.repo

[root@zabbix-server ~]# vim /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux $releasever - $basearch
# It is much more secure to use the metalink, but if you wish to use a local mirror
# place its address here.
#baseurl=https://download.example/pub/epel/$releasever/Everything/$basearch/
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=1
gpgcheck=1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-$releasever
excludepkgs=zabbix*            # 在后面加上这一行

安装 zabbix server、web前端、agent、mariadb数据库;启动数据库服务,并初始化数据库

[root@zabbix-server ~]# yum install zabbix-server-mysql zabbix-web-mysql zabbix-nginx-conf zabbix-sql-scripts zabbix-selinux-policy zabbix-agent mariadb-server mariadb -y
[root@zabbix-server ~]#
[root@zabbix-server ~]# systemctl  restart  mariadb
[root@zabbix-server ~]# systemctl  enable  mariadb
[root@zabbix-server ~]# 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!

配置数据库并导入,zabbix表数据


[root@zabbix-server ~]# mysql -uroot -p
Enter password: 
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 '123456';
Query OK, 0 rows affected (0.001 sec)
 
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost;
Query OK, 0 rows affected (0.001 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

导入数据库;导入后禁用log_bin_trust_function_creators选项,设置为0

[root@zabbix-server ~]# zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p zabbix
[root@zabbix-server ~]#
[root@zabbix-server ~]# mysql -uroot -p
Enter password: 
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;        //设置为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

配置zabbix服务并启动服务;为zabbix前端配置php

[root@zabbix-server ~]# 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
# 用 / 找到每一行并修改

# 取消注释/etc/nginx/conf.d/zabbix.conf文件中两行内容
[root@zabbix-server ~]# cat /etc/nginx/conf.d/zabbix.conf
server {
        listen          8080;
        server_name     example.com;

启动 zabbix-server zabbix-agent nginx php-fpm服务

[root@zabbix-server ~]# systemctl restart zabbix-server zabbix-agent nginx php-fpm
[root@zabbix-server ~]# systemctl enable zabbix-server zabbix-agent nginx php-fpm

使用浏览器访问自己的IP地址:http://192.168.200.30:8080/setup.php

 会发现不支持中文,此时需安装支持中文的依赖包

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

再次刷新浏览器,此时就支持中文了

 点击下一步,检查其中的值是否都是OK

下一步,输入端口号和密码

自己设置主机名称,设置地区为亚洲上海

检查有无问题,没问题下一步

配置好了,点击完成

注意,此时登录用户名为默认的Admin,密码为zabbix

 登录成功

 解决乱码问题:

1、找到windows下的简体 楷体 常规字体  C:\Windows\Fonts

2、将简体 楷体 常规字体文件复制出来

3、上传到Linux系统中的/usr/share/zabbix/assets/fonts

4、替换原先的字体文件即可

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

监控远程Linux服务器:

另开一台虚拟机当作客户端使用

[root@zabbix-agent ~]# yum -y install zabbix-agent

[root@zabbix-agent ~]# vim /etc/zabbix/zabbix_agentd.conf

Server=192.168.200.20                 # zabbix服务器的IP,agent被动监控(默认模式)

ServerActive=192.168.200.20           # zabbix服务器的IP,agent主动监控

Hostname=zabbix-agent                 # zabbix服务器的主机名


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

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

 添加主机

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值