优秀的编程知识分享平台

网站首页 > 技术文章 正文

3分钟完成在Linux 8上从零到一的监控部署Zabbix 6.4

nanyue 2025-01-24 13:17:32 技术文章 8 ℃

#每日生活的感悟# #IT运维##监控告警##Linux##Linux一日一技##安丫智数据坊#

Zabbix 是一个功能强大的开源监控解决方案,广泛用于企业级环境中的系统、网络和应用程序监控。本文将详细介绍如何在 Linux 8 上安装和配置 Zabbix 6.4,帮助你快速搭建一个高效的监控系统。无论你是初学者还是有经验的系统管理员,本文都将为你提供详细的步骤和最佳实践,确保你能顺利地完成安装和配置。


一、选择您Zabbix服务器的平台


配置环境如下

ZABBIX版本:6.4

OS版本:RHEL 8

DB版本:postgresql 16

WEB服务器版本: Apache/2.4.37

php版本:7.4


二、安装和配置 Zabbix

2.1 配置安装 Zabbix 存储库

1) 禁用 EPEL 提供的 Zabbix 软件包(如果已安装)。

编辑配置文件/etc/yum.repos.d/epel.repo并添加以下语句。

[epel]
...
excludepkgs=zabbix*

2)继续安装 zabbix 存储库。
 rpm -Uvh https://repo.zabbix.com/zabbix/6.4/rhel/8/x86_64/zabbix-release-6.4-1.el8.noarch.rpm
 dnf clean all

2.2 安装Zabbix server,Web前端,agent

dnf install zabbix-server-pgsql zabbix-web-pgsql zabbix-apache-conf zabbix-sql-scripts zabbix-selinux-policy zabbix-agent zabbix-get net-snmp nginx

2.3. 配置监控数据库

1)初始化pg数据库

  • 配置环境变量
$ cat .bash_profile
export PGHOME=/usr/local/postgres
export PGDATA=/data/pgdata/data
export PGLIB=/usr/local/postgresql/lib
export LC_ALL=en_US.UTF8
export LANG=en_US.UTF8
PATH=/usr/local/postgres/bin:$PATH
export PATH
  • 初始化数据库
$ initdb
 pg_ctl -D /data/pgdata/data -l logfile start
  • 调整参数
listen_addresses = '*'
log_min_duration_statement=0
logging_collector = on
log_filename = 'postgresql-%Y-%m-%d.log'
log_rotation_age = '1d'
log_directory = 'pg_log'
log_checkpoints = on
log_connections = on
log_disconnections = on
log_lock_waits = on
log_temp_files = 0
log_autovacuum_min_duration = 0
  • 调整hba
host all all 0.0.0.0/0 trust


  • 重启数据库
 pg_ctl restart -D /data/pgdata/data


2)创建监控数据库和监控用户

[postgres用户]
createuser --pwprompt zabbix
createdb -O zabbix zabbix

--授权
psql
postgres=# alter user zabbix SUPERUSER;
ALTER ROLE


3)导入初始架构和数据

# zcat /usr/share/zabbix-sql-scripts/postgresql/server.sql.gz | psql zabbix

2.4. 配置Zabbix server和agent

1)配置Zabbix server参数

编辑配置文件 /etc/zabbix/zabbix_server.conf
# egrep -v '^\#|^#39; /etc/zabbix/zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/run/zabbix/zabbix_server.pid
SocketDir=/run/zabbix
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1

2)配置Zabbix agent参数

编辑配置文件 /etc/zabbix/zabbix_agent.conf
[root@db1 zabbix]# egrep -v '^\#|^#39; /etc/zabbix/zabbix_agentd.conf
PidFile=/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=192.168.2.115
ServerActive=192.168.2.115
Hostname=192.168.2.115
Include=/etc/zabbix/zabbix_agentd.d/*.conf

#Server=192.168.2.115 agent向server上报的服务器,也就是server服务器
#Hostname=192.168.2.115 agent地址

3) 验证zabbix server和agent连接

# zabbix_get -s 192.168.2.115 -p 10050 -k "system.cpu.load[all,avg1]"
0.570000


4) 启动Zabbix server和agent进程

启动Zabbix server和agent进程,并为它们设置开机自启:

# systemctl restart zabbix-server zabbix-agent httpd php-fpm
# systemctl enable zabbix-server zabbix-agent httpd php-fpm

2.5. 升级php版本

zabbix 6.4对php最低版本要求为7.4,当前配置版本为7.2,不符合要求。

1)查看当前使用的php版本

[root@ora19c zabbix]# dnf module list php
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 1:09:35 ago on Mon 10 Jun 2024 11:04:18 PM CST.
CentOS-8 - AppStream - mirrors.aliyun.com
Name Stream Profiles Summary
php 7.2 [d][e] common [d], devel, minimal PHP scripting language
php 7.3 common [d], devel, minimal PHP scripting language
php 7.4 common [d], devel, minimal PHP scripting language

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

2)卸载重新安装

dnf module reset php:7.2
dnf module install php:7.4

3)查看生效的版本

# dnf module list php
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:41:15 ago on Mon 10 Jun 2024 10:44:15 PM PDT.
CentOS-8 - AppStream - mirrors.aliyun.com
Name Stream Profiles Summary
php 7.2 [d] common [d], devel, minimal PHP scripting language
php 7.3 common [d], devel, minimal PHP scripting language
php 7.4 [e] common [d] [i], devel, minimal PHP scripting language

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled


三、安装Zabbix UI

3.1 选择安装语言


3.2 安装前检查


3.2 配置pg数据库


3.3 配置zabbix属性


3.4 安装信息预览

3.5 完成安装

用户名默认Admin,密码zabbix


写在最后

数据库在当今信息社会中扮演着重要角色,为各行各业提供数据支持。如果你想深入了解数据库的使用与管理,欢迎关注我们的微信公众号“安呀智数据坊”,我们将定期分享更多相关知识和行业动态。

如果你觉得这篇文章对你有帮助,记得点赞支持一下哦!你的每一个点赞都是我继续创作的动力!

Tags:

最近发表
标签列表