zabbix基础搭建

zabbix简介

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

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

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

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

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

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监控代理部署在监控目标上,主动监控本地资源和应用(硬件驱动,内存等)

搭建Zabbix

1、设置时钟同步(关闭防火墙和selinux)

[root@zabbix-server ~]#  yum -y install chrony
[root@zabbix-server ~]#  systemctl restart chronyd
[root@zabbix-server ~]#  systemctl enable chronyd
[root@zabbix-server ~]#  timedatectl 
               Local time: Thu 2024-08-08 18:26:21 CST
           Universal time: Thu 2024-08-08 10:26:21 UTC
                 RTC time: Thu 2024-08-08 10:26:21
                Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

2、安装zabbix源

[root@zabbix-server ~]# ls
anaconda-ks.cfg  -e  -i.bak  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                    epel-testing.repo      rocky-devel.repo      rocky-extras.repo.bak  zabbix.repo
epel-cisco-openh264.repo  rocky-addons.repo      rocky-devel.repo.bak  rocky.repo
epel.repo                 rocky-addons.repo.bak  rocky-extras.repo     rocky.repo.bak

3、将zabbix的源换成阿里源

[root@zabbix-server ~]# vim /etc/yum.repos.d/zabbix.repo 
[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
[root@zabbix-server ~]# 

4、在epel源后面添加一行

[root@zabbix-server ~]# vim /etc/yum.repos.d/epel.repo
excludepkgs=zabbix*

5、安装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 

6、启动数据库服务,并初始化数据库

[root@zabbix-server ~]# systemctl  restart  mariadb
[root@zabbix-server ~]# systemctl  enable  mariadb
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
[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!

7、创建数据库

[root@zabbix-server ~]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
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.001 sec)

MariaDB [(none)]> 

8、导入数据库

[root@zabbix-server ~]# zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p zabbix

9、查看是否导入成功

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| zabbix             |
+--------------------+
4 rows in set (0.001 sec)

MariaDB [(none)]> use zabbix;
MariaDB [(none)]> use zabbix;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [zabbix]> show tables;
+----------------------------+
| Tables_in_zabbix           |
+----------------------------+
| acknowledges               |
| actions                    |
| alerts                     |
| auditlog                   |
| autoreg_host               |
| changelog                  |
| conditions                 |
| config                     |
| config_autoreg_tls         |
| connector                  |
| connector_tag              |
| corr_condition             |
| corr_condition_group       |
| corr_condition_tag         |
| corr_condition_tagpair     |
| corr_condition_tagvalue    |
| corr_operation             |
| correlation                |
| dashboard                  |
| dashboard_page             |
| dashboard_user             |
| dashboard_usrgrp           |
| dbversion                  |
| dchecks                    |
| dhosts                     |
| drules                     |
| dservices                  |
| escalations                |
| event_recovery             |
| event_suppress             |
| event_symptom              |
| event_tag                  |
| events                     |
| expressions                |
| functions                  |
| globalmacro                |
| globalvars                 |
| graph_discovery            |
| graph_theme                |
| graphs                     |
| graphs_items               |
| group_discovery            |
| group_prototype            |
| ha_node                    |
| hgset                      |
| hgset_group                |
| history                    |
| history_bin                |
| history_log                |
| history_str                |
| history_text               |
| history_uint               |
| host_discovery             |
| host_hgset                 |
| host_inventory             |
| host_proxy                 |
| host_rtdata                |
| host_tag                   |
| hostmacro                  |
| hosts                      |
| hosts_groups               |
| hosts_templates            |
| housekeeper                |
| hstgrp                     |
| httpstep                   |
| httpstep_field             |
| httpstepitem               |
| httptest                   |
| httptest_field             |
| httptest_tag               |
| httptestitem               |
| icon_map                   |
| icon_mapping               |
| ids                        |
| images                     |
| interface                  |
| interface_discovery        |
| interface_snmp             |
| item_condition             |
| item_discovery             |
| item_parameter             |
| item_preproc               |
| item_rtdata                |
| item_rtname                |
| item_tag                   |
| items                      |
| lld_macro_path             |
| lld_override               |
| lld_override_condition     |
| lld_override_opdiscover    |
| lld_override_operation     |
| lld_override_ophistory     |
| lld_override_opinventory   |
| lld_override_opperiod      |
| lld_override_opseverity    |
| lld_override_opstatus      |
| lld_override_optag         |
| lld_override_optemplate    |
| lld_override_optrends      |
| maintenance_tag            |
| maintenances               |
| maintenances_groups        |
| maintenances_hosts         |
| maintenances_windows       |
| media                      |
| media_type                 |
| media_type_message         |
| media_type_param           |
| mfa                        |
| mfa_totp_secret            |
| module                     |
| opcommand                  |
| opcommand_grp              |
| opcommand_hst              |
| opconditions               |
| operations                 |
| opgroup                    |
| opinventory                |
| opmessage                  |
| opmessage_grp              |
| opmessage_usr              |
| optag                      |
| optemplate                 |
| permission                 |
| problem                    |
| problem_tag                |
| profiles                   |
| proxy                      |
| proxy_autoreg_host         |
| proxy_dhistory             |
| proxy_group                |
| proxy_group_rtdata         |
| proxy_history              |
| proxy_rtdata               |
| regexps                    |
| report                     |
| report_param               |
| report_user                |
| report_usrgrp              |
| rights                     |
| role                       |
| role_rule                  |
| scim_group                 |
| script_param               |
| scripts                    |
| service_alarms             |
| service_problem            |
| service_problem_tag        |
| service_status_rule        |
| service_tag                |
| services                   |
| services_links             |
| sessions                   |
| sla                        |
| sla_excluded_downtime      |
| sla_schedule               |
| sla_service_tag            |
| sysmap_element_trigger     |
| sysmap_element_url         |
| sysmap_shape               |
| sysmap_url                 |
| sysmap_user                |
| sysmap_usrgrp              |
| sysmaps                    |
| sysmaps_element_tag        |
| sysmaps_elements           |
| sysmaps_link_triggers      |
| sysmaps_links              |
| tag_filter                 |
| task                       |
| task_acknowledge           |
| task_check_now             |
| task_close_problem         |
| task_data                  |
| task_remote_command        |
| task_remote_command_result |
| task_result                |
| timeperiods                |
| token                      |
| trends                     |
| trends_uint                |
| trigger_depends            |
| trigger_discovery          |
| trigger_queue              |
| trigger_tag                |
| triggers                   |
| ugset                      |
| ugset_group                |
| user_scim_group            |
| user_ugset                 |
| userdirectory              |
| userdirectory_idpgroup     |
| userdirectory_ldap         |
| userdirectory_media        |
| userdirectory_saml         |
| userdirectory_usrgrp       |
| users                      |
| users_groups               |
| usrgrp                     |
| valuemap                   |
| valuemap_mapping           |
| widget                     |
| widget_field               |
+----------------------------+
203 rows in set (0.001 sec)

10、禁用log_bin_trust_function_creators选项

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

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

11、配置zabbix并启动服务

[root@zabbix-server ~]# vim /etc/zabbix/zabbix_server.conf
ListenPort=10051     //服务端口
DBHost=localhost 	//数据库主机
DBName=zabbix 		//数据库名称
DBUser=zabbix 		//数据库用户
DBPassword=123456   // 数据库密码
DBSocket=/var/lib/mysql/mysql.sock  //数据库sock文件
ListenIP=0.0.0.0    //监听的IP

12、为zabbix前端配置PHP,并启动服务

//去除以下两行的注释
[root@zabbix-server ~]#  vim /etc/nginx/conf.d/zabbix.conf
        listen          8080;
        server_name     example.com;

[root@zabbix-server ~]# systemctl restart zabbix-server zabbix-agent nginx php-fpm
[root@zabbix-server ~]# systemctl enable zabbix-server zabbix-agent nginx php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-server.service → /usr/lib/systemd/system/zabbix-server.service.
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-agent.service → /usr/lib/systemd/system/zabbix-agent.service.
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.

13、登录配置Zabbix,设置支持中文解决乱码

在这里插入图片描述

[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

在这里插入图片描述

全部ok下一步
在这里插入图片描述
修改端口为3306和密码
在这里插入图片描述
设置主机名称和默认时区
在这里插入图片描述

选择下一步
在这里插入图片描述
初始用户 Admin 密码 zabbix
在这里插入图片描述
监控 -----> 主机 -------> 图形化
在这里插入图片描述
在这里插入图片描述
可以看到上图出现乱码
1、找到windows下的简体 楷体 常规字体
C:\Windows\Fonts
2、将简体 楷体 常规字体文件复制出来
3、上传到Linux系统中的/usr/share/zabbix/assets/fonts
4、替换原先的字体文件即可
mv simkai.ttf graphfont.ttf

[root@zabbix-server fonts]# ls
graphfont.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]# 

下图为解决乱码
在这里插入图片描述

13、监控客服端

修改源
[root@node1 ~]# vim /etc/yum.repos.d/zabbix.repo 
[root@node1 ~]# vim /etc/yum.repos.d/epel.repo

安装zabbix
[root@node1 ~]# yum -y install zabbix-agent
 [root@zabbix-agent ~]# vim /etc/zabbix/zabbix_agentd.conf 
[root@zabbix-agent ~]# systemctl restart zabbix-agent
[root@zabbix-agent ~]# systemctl enable zabbix-agent
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-agent.service → /usr/lib/systemd/system/zabbix-agent.service.

数据采集 -----> 主机 -----> 添加主机 -----> 修改主机名、模板(Templates/Operating systems —> Linux by Zabbix agent)、主机群组(Linux server)
在这里插入图片描述

监控----->主机------>看可用的ZBX是否变为绿色

在这里插入图片描述

04-26
<think>好的,用户想了解Zabbix监控系统的使用指南,包括安装、配置、使用或监控解决方案。首先,我需要整理Zabbix的基本信息,确保覆盖用户可能关心的主要方面。根据引用内容,用户提供的参考资料提到了安装、配置监控项、主动监控设置、模板应用等。 首先,我应该分步骤来回答,结构要清晰。可能分为安装部署、基础配置、监控项管理、告警设置、模板应用几个部分。每个部分需要简明扼要,给出关键步骤,同时结合引用中的具体操作,比如引用3提到的主动监控配置,引用4提到的模板下载,这些都需要包含进去。 要注意用户可能需要具体的命令行操作,比如修改配置文件的位置和参数,例如引用3中的zabbix_agentd.conf的修改,以及重启服务等步骤。这些细节对用户配置Zabbix代理很重要,必须准确无误。 另外,用户可能对监控模板的使用感兴趣,引用4提到了社区模板库,需要说明如何下载和应用这些模板,步骤要具体,比如下载后如何导入Zabbix界面。 告警配置部分,引用3提到了主动监控的主机创建,可能需要说明如何在Zabbix前端添加主机并关联模板,同时设置触发器动作。需要确保用户了解如何测试告警是否生效。 可能还需要提到性能优化,比如主动监控的优势,减少服务端压力,如引用3中设置StartAgents=0和ServerActive参数,这样用户知道如何优化代理配置。 最后,相关问题部分需要生成与Zabbix相关的进一步问题,可能涉及高级配置、分布式监控、集成其他工具等,参考用户之前的示例,问题要具体且有引导性。 需要检查所有技术细节是否正确,比如配置文件路径、参数名称,确保和引用中的信息一致,避免错误。同时,保持回答的中文自然流畅,符合用户要求的分段和格式,使用列表和代码块来展示命令和配置示例,增强可读性。</think>以下是Zabbix监控系统的使用指南,涵盖核心功能与操作流程: ### 一、安装部署(以CentOS为例) 1. 环境准备 ```bash # 安装Zabbix仓库 yum install https://repo.zabbix.com/zabbix/6.0/rhel/7/x86_64/zabbix-release-6.0-4.el7.noarch.rpm # 安装服务端组件 yum install zabbix-server-mysql zabbix-web-mysql zabbix-nginx-conf zabbix-sql-scripts zabbix-agent ``` 2. 数据库初始化 ```bash mysql> CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin; mysql> GRANT ALL ON zabbix.* TO 'zabbix'@'localhost' IDENTIFIED BY 'YourPassword'; # 导入初始数据 zcat /usr/share/doc/zabbix-sql-scripts/mysql/server.sql.gz | mysql -uzabbix -p zabbix ``` ### 二、基础配置 1. 服务端配置 ```bash vim /etc/zabbix/zabbix_server.conf DBPassword=YourPassword # 配置数据库连接 ``` 2. 客户端配置(被监控节点) ```bash vim /etc/zabbix/zabbix_agentd.conf Server=192.168.88.5 # Zabbix服务端IP ServerActive=192.168.88.5 Hostname=web1 # 需与服务端注册名称一致 ``` ### 三、监控项管理 1. **主动监控配置**(降低服务端负载) ```bash StartAgents=0 # 关闭被动监控 ServerActive=192.168.88.5 RefreshActiveChecks=120 # 主动检查间隔[^3] ``` 2. 自定义监控项开发 ```bash # 创建自定义监控脚本 vim /etc/zabbix/zabbix_agentd.d/custom_script.conf UserParameter=app.status,/opt/scripts/check_app.sh ``` ### 四、告警配置 1. 触发器设置 ```text {web1:net.tcp.service[http,,80].last()}=0 # 当HTTP服务不可用时触发 ``` 2. 通知渠道配置 - 支持邮件/Slack/Webhook等多种方式 - 配置路径:管理 → 报警媒介类型 ### 五、模板应用 1. 使用社区模板[^4] ```bash # 下载模板文件 wget https://github.com/endersonmaia/zabbix-templates/raw/master/template_nginx.xml # 通过Web界面导入:配置 → 模板 → 导入 ``` 2. 模板关联主机 - 通过"自动注册"功能实现新主机自动关联模板 - 手动关联路径:主机配置 → 模板标签页
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值