• CentOS 7操作系统使用LAMP架构安装Zabbix 5.0监控系统的详细指南


    前言

    在这里插入图片描述

    🏠个人主页:我是沐风晓月
    🧑个人简介:大家好,我是沐风晓月,阿里云社区博客专家
    😉😉 💕 座右铭: 先努力成长自己,再帮助更多的人,一起加油进步
    🍺🍺🍺 💕欢迎大家:这里是CSDN,我总结知识的地方,喜欢的话请三连,有问题请私信😘

    可以关注我的云原生社区:云原生社区
    也可以关注我的英语社区:从零开始学英语

    一. 实验环境

    操作系统:

    [root@mufeng163 ~]# cat /etc/redhat-release 
    CentOS Linux release 7.5.1804 (Core)
    
    • 1
    • 2

    关闭防火墙和selinux

    [root@mufeng163 ~]# setenforce 0
    [root@mufeng163 ~]# iptables -F
    
    
    • 1
    • 2
    • 3

    二. 安装zabbix的步骤

    2.1 安装zabbix 5.0的repo

    [root@mufeng163 ~]# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
    获取https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
    警告:/var/tmp/rpm-tmp.3sloXz: 头V4 RSA/SHA512 Signature, 密钥 ID a14fe591: NOKEY
    准备中...                          ################################# [100%]
    正在升级/安装...
       1:zabbix-release-5.0-1.el7         ################################# [100%]
    [root@mufeng163 ~]# ls
    anaconda-ks.cfg  initial-setup-ks.cfg  公共  模板  视频  图片  文档  下载  音乐  桌面
    [root@mufeng163 ~]# cd /etc/yum.repos.d/
    [root@mufeng163 yum.repos.d]# ls
    CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo  zabbix.repo
    CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo  redhat.repo
    [root@mufeng163 yum.repos.d]# 
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    在这里插入图片描述

    2.2 安装zabbix server ,agent , web前端

    [root@mufeng163 yum.repos.d]# yum install zabbix-server-mysql zabbix-agent -y
    root@mufeng163 yum.repos.d]# yum install centos-release-scl -y
    
    
    • 1
    • 2
    • 3

    centos-release-scl: CentOS Software Collections(简称SCL)软件仓库的。SCL是一个为CentOS提供额外软件包的软件仓库,它包含的软件包版本比默认的CentOS基础软件库要新一些,并且可以在CentOS 7及以上版本中使用。通过安装centos-release-scl软件包,可以方便地从SCL软件源中安装软件包,并保持更新。

    SCL提供了很多常用的软件包,如PHP版本的扩展模块、Python版本的扩展模块、各种版本的Web服务器、MySQL版本的扩展组件、Ruby版本等,使得使用CentOS的用户可以很容易地升级或切换软件的不同版本

    2.3 修改 zabbix.repo

    [root@mufeng163 yum.repos.d]# sed -i '11s/0/1/' /etc/yum.repos.d/zabbix.repo
    
    • 1

    sed -i '11s/0/1/' /etc/yum.repos.d/zabbix.repo 这句命令是在修改Zabbix官方yum源的配置文件/etc/yum.repos.d/zabbix.repo中第11行的内容。具体来说,它使用sed命令(一种文本处理工具)在该文件中寻找第11行(通常是“enabled=0”),并将“enabled=0”替换为“enabled=1”。

    这样做的目的是启用Zabbix官方yum源,让系统可以从Zabbix官方仓库中更新和安装Zabbix软件包。修改完成后,可以使用yum命令一键安装最新版本的Zabbix软件。

    2.4 安装frontend包

    yum install zabbix-web-mysql-scl zabbix-apache-conf-scl -y
    
    • 1

    2.5 安装数据库并设置

    安装并启动

    [root@mufeng163 yum.repos.d]# yum -y install mariadb mariadb-server &&  systemctl  restart mariadb  
    
    • 1

    设置开机自启

    [root@mufeng163 ~]# systemctl  enable mariadb
    
    
    • 1
    • 2

    查看端口和进程

    root@mufeng163 ~]# netstat -antup |grep mysql
    tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      18126/mysqld
    
    • 1
    • 2

    创建数据库并授权

    root@mufeng163 ~]# mysql 
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 2
    Server version: 5.5.68-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 utf8 collate utf8_bin;
    Query OK, 1 row affected (0.00 sec)
    
    MariaDB [(none)]> create user zabbix@localhost identified by '123456';
    Query OK, 0 rows affected (0.00 sec)
    
    MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost;
    Query OK, 0 rows affected (0.01 sec)
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    若想让代码更健壮,可以使用下面的方法:
    (注意:如果你执行 了上面的操作,下面的这个健壮的代码就不要执行了)

    MySQL
    CREATE DATABASE IF NOT EXISTS zabbix CHARACTER SET utf8 COLLATE utf8_bin;
    CREATE USER 'zabbix'@'localhost' IDENTIFIED BY 'your_password_here';
    GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'localhost';
    FLUSH PRIVILEGES;
    
    • 1
    • 2
    • 3
    • 4
    • 5

    这样做的优势在于,首先在创建数据库时加入“IF NOT EXISTS”选项可以避免多次运行时出现错误提示;此外,选择一个更加复杂和安全的密码可以提高用户密码的安全性,确保仅授予用户必要的权限,最后通过FLUSH PRIVILEGES来刷新权限,使其立即生效。

    2.6 导入数据

    [root@mufeng163 ~]# cd /usr/share/doc/zabbix-server-mysql-5.0.35/
    [root@mufeng163 zabbix-server-mysql-5.0.35]# ls
    AUTHORS  ChangeLog  COPYING  create.sql.gz  double.sql  NEWS  README
    
    [root@mufeng163 zabbix-server-mysql-5.0.35]# zcat create.sql.gz | mysql -uzabbix -p zabbix
    Enter password: 
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    2.7 更改zabbix配置文件

    更改zabbix配置文件的目的在于,让zabbix服务可以访问数据库

    在这里插入图片描述
    修改以下几个参数:
    DBUser=zabbix
    DBPassword=123456

    2.8 更改PHP配置文件,设置时区

    虽然现在系统重没有安装PHP及其扩展包,但之前安装过Software Collections(SCL)软件仓库。在一些使用SCL软件的情况下,可以运行成为程序的Apache和PHP之外的另一个应用服务器:PHP-FPM(PHP FastCGI进程管理器),以加速Web应用程序的响应速度。

    root@mufeng163 ~]# vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf 
    
    [root@mufeng163 ~]# tail -n 2 /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
    php_value[date.timezone] = Asia/Shanghai
    
    • 1
    • 2
    • 3
    • 4

    在这里插入图片描述

    2.9 启动zabbix server 和agent进程,并查看服务状态

    [root@mufeng163 ~]# systemctl  restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
    [root@mufeng163 ~]# systemctl  enable zabbix-server zabbix-agent httpd rh-php72-php-fpm
    
    
    • 1
    • 2
    • 3

    三. 网页端配置

    3.1 查看IP

    [root@mufeng163 ~]# ifconfig |grep inet |cut -d " " -f 10|head -1
    192.168.1.163
    
    
    • 1
    • 2
    • 3

    3.2 访问 192.168.1.163/zabbix

    在这里插入图片描述
    在这里插入图片描述
    端口号:3306

    数据库名称、用户名、密码:均为命令行创建的

    单击Nest step
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

    用户名为:Admin

    密码为:zabbix

    在这里插入图片描述

    点击登录后:

    在这里插入图片描述

    总结

    zabbix 5.0 安装比较简单,相较于prometheus来说可能稍微复杂一点,但只要细心点,还是很容易部署成功的。

    💕 好啦,这就是今天要分享给大家的全部内容了,我们下期再见!
    💕 本文由沐风晓月原创,首发于CSDN博客, 博客主页:mufeng.blog.csdn.net
    💕 日拱一卒无尽有,功不唐捐终入海
    💕 喜欢的话记得点赞收藏哦

  • 相关阅读:
    oracle 里常用的一些 create insert update table
    $nextTick 的原理源码解读
    .NET 8发布首个RC,比.NET 7的超级快更快
    YOLOv5改进之二:添加CBAM注意力机制
    Dijkstra算法略解
    PointSIFT: A SIFT-like Network Module for 3D Point Cloud Semantic Segmentation
    【Paraview教程】第一章安装与基础介绍
    Redis_24_Redission的使用
    【JAVA问题解决方案】02.Freemarker导出Excel超出上限分表解决方案
    毕业设计之基于springboot+uniapp的租房小程序
  • 原文地址:https://blog.csdn.net/wisdom_futrue/article/details/131147490