CentOS7搭建ZABBIX6.0安装及自定义监控使用-1

一.简介

1.部署zabbix的原因

(1)作为一个运维,管理多系统时需要使用监控系统查看服务器系统性能,应用服务状态等从而了解网站健康状态

(2)回溯事故发生时系统的问题和报警情况,利用历史数据为后期计算资源扩容做数据支撑

(3)界面友好,方便给领导展示和数据分析

2.zabbix是什么

(1)zabbix是一个基于web界面的提供的分布式系统监视以及网络监视功能的企业级的开源解决方案

(2)zabbix能监视各种网络参数,常见于:Agent:通用;Snmp:网络设备 带宽 流量;Jmx(java gateway tomcat);Ipmi等;并提供多种方式告知管理员:邮件,微信,短信,电话,钉钉,调用api接口

(3)zabbix由两个部分构成,zabbix server与可选组件zabbix agent(安装在被监控的目标服务器上),通过C/S模式采集数据,通过B/S模式在Web端展示和配置

(4)Zabbix-agent获取数据—发送给—zabbix-server服务端-数据会被存放——>数据库ßweb页面展示数据

3.zabbix 6.0新特性

(1)zabbix server高可用

      原生选择加入HA群集配置
      定义一个或多个备用节点
      实时监控Zabbix server群集节点的状态
      不需要外部工具即可将Zabbix server配置为HA群集模式

(2)新增kubernets监控功能,一定程度上可取代prometheus

      Kubernetes节点和pods的自动发现和监控
      无代理方式采集Kubernetes pods和节点的信息
       获取Kubernetes节点主机高水平信息

二.环境搭建

  • 系统:centos 7不支持yum方式安装zabbix 6.0服务端
  • 安装方式:zabbix服务端采用编译安装的方式,zabbix客户端采用yum安装的方式
  • 搭建zabbix6.0之前首先需要搭建LNMP或LAMP,并且最低需要MySQL8.0版本,PHP最低需要7.0版本暂不支持8.0版本的PHP

1.部署服务端

系统版本:Centos7(选择合适的版本下载对应的iso)

下载地址:Index of /

安装结束之后,手动修改ip地址,确认可正常访问

第一步,查看网卡信息

命令

ifconfig

执行结果

第二步,配置网络 切换到网卡存放路径

/etc/sysconfig/network-scripts #网卡存放路径

第三步:

修改网卡对应配置文件

使用 vi/vim 打开文件 vi ifcfg-ens192 查看以下内容

第四步:修改配置文件内容(静态or动态 IP地址)

静态:

1、将 BOOTPROTO=dhcp 改成 BOOTPROTO=static                                

2、将 ONBOOT=no 改成 ONBOOT=yes

3、在配置文件末行中添加如下 3 项:(根据自己所在网段配置设置固定IP地址)

IPADDR=10.59.46.50

NETMASK=255.255.252.0

GATEWAY=10.59.44.1

DNS1=10.59.30.10

动态:

1、将 ONBOOT=no 改成 ONBOOT=yes

第五步:修改后重启网络服务

systemctl restart network

第六步:再次查看IP地址

ip add

2.部署Nginx+php环境

第一步:关闭防火墙

# 关闭selinux与防火墙
systemctl stop firewalld
systemctl disable firewalld

第二步:下载阿里云网络yum源和epe扩展源

[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

[root@localhost ~]# wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo

[root@localhost ~]# yum makecache

第三步:安装Nginx(可以yum也可以编译,yum简单)

[root@localhost ~]# vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[root@localhost ~]# yum makecache
[root@localhost ~]# yum -y install nginx
[root@localhost ~]# systemctl enable nginx --now

第四步,配置php

配置php-fpm源
[root@localhost ~]#  yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
[root@localhost ~]#  yum install yum-utils           
 ##    安装 yum-utils 软件包的命令(用于 yum-config-manager 命令)
启用存储库的命令:  
 [root@localhost ~]# yum-config-manager --disable 'remi-php*'
 [root@localhost ~]# yum-config-manager --enable   remi-php82
 [root@localhost ~]# yum-config-manager --enable remi-php82
 [root@localhost ~]# yum -y install php-fpm php-mysql php-gd

#php-fpm: php接受动态请求程序  连接nginx
#php-mysql:php连接mysql的程序 
#php-gd:图形库程序(GD库可以处理图片,或者生成图片)

[root@localhost ~]# systemctl enable php-fpm --now
[root@localhost ~]# netstat -anptu | grep 9000
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      1163/php-fpm: maste 

#测试php是否可以正常使用
[root@localhost ~]# vim /usr/share/nginx/html/index.php
<?php
phpinfo( );
?>
[root@localhost ~]# vim /etc/nginx/conf.d/default.conf

#启动nginx_fastcgi功能 把原本注释的部分取消即可 修改这里$document_root$fastcgi_script_name;

location ~ \.php$ {
    root /usr/share/nginx/html;
    fastcgi_pass 127.0.0.1:9000;#Nginx通过本机的9000端口将PHP请求转发给PHP-FPM进行处理
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;#Nginx调用fastcgi接口处理PHP请求
    }
  [root@localhost ~]# systemctl restart nginx

第五步,访问验证

3.部署SQL

第一步,官网下载yum仓库的包

[root@localhost ~]# wget https://repo.mysql.com//mysql80-community-release-el7-7.noarch.rpm
[root@localhost ~]# yum -y install mysql80-community-release-el7-7.noarch.rpm
#仓库查看mysqlyum源
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls

找到含有sql的三个即为官方mysql yum源

##这三个就是官方mysql yum源,进入mysql-community.repo查看版本再此也可以选择版本默认是mysql8.0版本,如果要选择mysql5.7版本就把mysql8.0的enabled=1改成0,mysql5.7的enabled=0改成1然后yum makecache,本次安装8.0版本即使用默认的配置文件即可

[root@localhost yum.repos.d]# vim mysql-community.repo 

第二步 安装MySQL

[root@localhost ~]# yum -y install mysql-community-server.x86_64
[root@localhost ~]# systemctl enable mysqld --now 
[root@localhost ~]# netstat -anptu | grep mysql
tcp6       0      0 :::33060                :::*                    LISTEN      2866/mysqld         
tcp6       0      0 :::3306                 :::*                    LISTEN      2866/mysqld     
 
#查看mysql默认密码
[root@localhost ~]# grep password /var/log/mysqld.log

第三步,链接SQL,修改SQL默认密码

[root@localhost ~]# mysql -uroot -p'umo<+#udI0t='
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.32 MySQL Community Server - GPL
 
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
 
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql> 
 
##登录成功
[root@localhost ~]# vim /etc/my.cnf
skip-grant-tables   ##加入这行意思是跳过权限验证的问题
[root@localhost ~]# systemctl restart mysqld
 
现在可以不要密码登录mysql
 
[root@localhost ~]# msyql -uroot
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)
mysql> use mysql;
mysql> update user set authentication_string='' where  user = 'root'; ##把root密码设置为空
mysql> flush privileges;  ##刷新权限
 
登出mysql进入mysql配置文件把skip-grant-tables加注释
 
[root@localhost ~]# vim /etc/my.cnf
#skip-grant-tables
[root@localhost ~]# systemctl restart mysqld
[root@localhost ~]# mysql -uroot
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'ABc123...';
##注意mysql密码必须含有大小写字母,数字,特殊符号
 
尝试登录mysql
 
[root@localhost ~]# mysql -uroot -p'ABc123...'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 8.0.32 MySQL Community Server - GPL
 
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
 
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql> 

第四步,测试PHP是否可以连接mysql

准备数据库存放apps
mysql> create database apps;
mysql> grant all on apps.* to phptest@'192.168.1.1'identified by '123123';
#####报错信息如下:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
解决:
mysql> set global validate_password_policy=0; 
mysql> set global validate_password_length=1;
重新授权
mysql> flush privileges;

 测试php是否可以连接mysql
 [root@localhost ~]# vim /usr/share/nginx/html/index.php
 <?php
$link=mysqli_connect('localhost','root','*******');  ##mysql密码
if($link) echo "<h1>mysql connected success ! its ok !!</h1>";
mysqli_close($link);
?>

4.部署PHP

注意下 zabbix6.0 不支持php 8.0及以上版本,可以通过php-v 确认安装版本是否合适

第一步,确认php的是否安装

[root@zabbix ~]# rpm -qa | grep php
oniguruma5php-6.9.9-1.el7.remi.x86_64
php-sodium-8.2.20-1.el7.remi.x86_64
gd3php-2.3.3-7.el7.remi.x86_64
php-common-8.2.20-1.el7.remi.x86_64
php-cli-8.2.20-1.el7.remi.x86_64
php-fpm-8.2.20-1.el7.remi.x86_64
php-8.2.20-1.el7.remi.x86_64
#查看php的版本 不合适的版本先卸载#
[root@zabbix ~]# rpm -e php-8.2.20-1.el7.remi.x86_64
[root@zabbix ~]# rpm -e php-common-8.2.20-1.el7.remi.x86_64
[root@zabbix ~]# rpm -e php-sodium-8.2.20-1.el7.remi.x86_64
[root@zabbix ~]# rpm -e php-sodium-8.2.20-1.el7.remi.x86_64^C
[root@zabbix ~]# rpm -e php-cli-8.2.20-1.el7.remi.x86_64
[root@zabbix ~]# rpm -e php-fpm-8.2.20-1.el7.remi.x86_64
[root@zabbix ~]# rpm -e php-common-8.2.20-1.el7.remi.x86_64
[root@zabbix ~]# rpm -qa | grep php
oniguruma5php-6.9.9-1.el7.remi.x86_64
gd3php-2.3.3-7.el7.remi.x86_64
#注意卸载有依赖包的顺序问题,顺序不对卸载会报错,可以按报错提示按顺序卸载#

第二步,安装php 7.4

[root@zabbix ~]# yum install -y epel-release
[root@zabbix ~]# yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
[root@zabbix ~]# yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
[root@zabbix ~]# sudo yum install -y yum-utils
[root@zabbix ~]# sudo yum-config-manager --enable remi-php74
[root@zabbix ~]# sudo yum install -y php-opcache php-devel php-mbstring php-gd php-curl php-mysqlnd
[root@zabbix ~]# sudo yum install -y php-xmlwriter
[root@zabbix ~]# sudo yum install -y php-bcmath
[root@zabbix ~]# sudo systemctl start php-fpm
[root@zabbix ~]# sudo systemctl enable php-fpm
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
[root@zabbix ~]# php -v
PHP 7.4.33 (cli) (built: Jun  5 2024 05:05:14) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies

第三步,配置php配置文件

[root@zabbix ~]# vim /etc/php.ini
  • 修改date.timezone = Asia/Shanghai

  • 修改post_max_size为16M

  • 修改max_execution_time为300

  • 修改max_input_time为300

5.部署zabbix

注意 zabbix sever在centos 7.x的版本不支持yum安装需要编译安装

第一步,安装zabbix

[root@localhost ~]# groupadd zabbix
[root@localhost ~]# useradd -r -g zabbix zabbix
[root@localhost ~]# yum -y install mysql-devel net-snmp-devel libevent-devel curl-devel libxml2 libxml2-devel
 
#升级gcc为8.0版本以上不然make isntall 会报错
[root@localhost ~]# yum -y install centos-release-scl 
[root@localhost ~]# yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils 
[root@localhost ~]# scl enable devtoolset-9 bash
#永久设置
[root@localhost ~]# echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
下载并上传zabbix包
[root@localhost ~]# wget https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.13.tar.gz
 
#解压配置zabbix包
[root@localhost ~]# tar zxvf zabbix-6.0.13.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/zabbix-6.0.13/
[root@localhost zabbix-6.0.13]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
[root@localhost zabbix-6.0.13]# make install

第二步,创建mysql数据库并授权

[root@localhost ~]# mysql -uroot -pABc123...
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> create user zabbix@'%' identified by 'Abc123...';
mysql> grant all on zabbix.* to zabbix@'%' with grant option;
mysql> flush privileges;

第三步,导入数据库架构及数据

[root@localhost ~]# mysql -uroot -pABc123... zabbix < /usr/src/zabbix-6.0.13/database/mysql/schema.sql
[root@localhost ~]# mysql -uroot -pABc123... zabbix < /usr/src/zabbix-6.0.13/database/mysql/images.sql
[root@localhost ~]# mysql -uroot -pABc123... zabbix < /usr/src/zabbix-6.0.13/database/mysql/data.sql

第四步,创建zabbix日志存储位置和pid存储位置并设置属主属组

[root@localhost ~]# mkdir /usr/local/zabbix/{logs,pid}
[root@localhost ~]# chown zabbix:zabbix /usr/local/zabbix/ -R 

第五步,修改配置zabbix server&agent配置文件

[root@localhost ~]# vim /usr/local/zabbix/etc/zabbix_server.conf
 
LogFile=/usr/local/zabbix/logs/zabbix_server.log               ##日志存放路径
PidFile=/usr/local/zabbix/pid/zabbix_server.pid                ##运行的PID文件
DBHost=10.59.46.50                                             ##数据库主机ip
DBSocket=/var/lib/mysql/mysql.sock                             ##mysql.sock
DBName=zabbix                                                  ##数据库名字
DBUser=zabbix                                                  ##mysql授权的用户
DBPassword=Abc123...                                           ##mysql授权的密码
Include=/usr/local/zabbix/etc/zabbix_server.conf.d/*.conf      ##开启附加配置文件目录
[root@localhost ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf

 
LogFile=/usr/local/zabbix/logs/zabbix_agentd.log
PidFile=/usr/local/zabbix/pid/zabbix_agent.pid
Server=10.59.46.50
ServerActive=10.59.46.50                        ####输入agent主机采集到数据发送到的server端
Hostname=zabbix
Include=/usr/local/zabbix/etc/zabbix_server.conf.d/*.conf

第六步,配置zabbix_server启动脚本

[root@localhost ~]# vim /usr/lib/systemd/system/zabbix.service
[Unit]
Description=Zabbix Server with MySQL DB
After=syslog.target network.target mysqld.service
[Service]
Type=simple
ExecStart=/usr/local/zabbix/sbin/zabbix_server -f   ##zabbix安装目录
User=zabbix
[Install]
WantedBy=multi-user.target   
 
[root@localhost ~]# systemctl daemon-reload  
 
启动监控端 
[root@localhost ~]# systemctl enable zabbix --now       
启动agent端
[root@localhost ~]# /usr/local/zabbix/sbin/zabbix_agentd 
[root@localhost ~]# ss -tln | grep 1005
LISTEN     0      128          *:10050                    *:*                  
LISTEN     0      128          *:10051                    *:*                  
LISTEN     0      128       [::]:10050                 [::]:*                  
LISTEN     0      128       [::]:10051                 [::]:*   

第七步,移动前端文件至web服务的根目录并授权

[root@localhost ~]# cp -r /usr/src/zabbix-6.0.13/ui/* /usr/share/nginx/html/zabbix
[root@localhost ~]# chown -R nginx:nginx /usr/share/nginx/html/zabbix/
[root@localhost ~]# chown -R nginx:nginx /etc/opt/remi/php74/php.ini 

浏览器输入主机ip并加入zabbix前端文件路径

10.59.46.50/zabbix

修改zabbix.conf.php完成配置&网页修改完成配置,可以正式进入页面啦

默认账号 Admin 账号zabbix

后续调整可参考

搭建Zabbix6.0版本-CSDN博客

  • 22
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是在 CentOS 7 上安装和配置 Zabbix 6.0 的详细步骤: 1. 添加 Zabbix 官方仓库 首先需要添加 Zabbix 官方仓库到 CentOS 7 中,以便安装最新版本的 Zabbix。可以通过以下命令添加: ``` rpm -ivh https://repo.zabbix.com/zabbix/6.0/rhel/7/x86_64/zabbix-release-6.0-1.el7.noarch.rpm ``` 2. 安装 Zabbix Server、Agent 和 Web 安装 Zabbix Server、Agent 和 Web 可以使用以下命令: ``` yum install -y zabbix-server-mysql zabbix-web-mysql zabbix-agent ``` 3. 创建 Zabbix 数据库和用户 在安装 Zabbix 之前,需要先创建一个数据库和用户。可以使用以下步骤创建: - 安装 MySQL:`yum install -y mariadb-server mariadb` - 启动 MySQL 服务:`systemctl start mariadb` - 运行 MySQL 安全脚本以提高安全性:`mysql_secure_installation` - 登录 MySQL:`mysql -u root -p` - 创建数据库和用户: ``` CREATE DATABASE zabbix character set utf8 collate utf8_bin; CREATE USER 'zabbix'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'localhost'; FLUSH PRIVILEGES; ``` 注意将 `password` 替换为您想要设置的密码。 4. 导入 Zabbix 数据库模式和数据 使用以下命令导入 Zabbix 数据库模式和数据: ``` zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -u zabbix -p zabbix ``` 输入上一步中创建的 `zabbix` 用户的密码。 5. 配置 Zabbix Server 编辑 Zabbix Server 配置文件 `/etc/zabbix/zabbix_server.conf`,设置以下参数: ``` DBPassword=password ``` 将 `password` 替换为上一步中创建的 `zabbix` 用户的密码。 6. 配置 PHP 编辑 PHP 配置文件 `/etc/php.ini`,设置以下参数: ``` max_execution_time = 300 memory_limit = 256M post_max_size = 32M upload_max_filesize = 16M max_input_time = 300 date.timezone = Asia/Shanghai ``` 7. 启动 Zabbix Server 和 Agent 启动 Zabbix Server 和 Agent 服务: ``` systemctl start zabbix-server systemctl enable zabbix-server systemctl start zabbix-agent systemctl enable zabbix-agent ``` 8. 配置防火墙 如果您的服务器上启用了防火墙,需要打开以下端口: ``` firewall-cmd --add-service={http,https} --permanent firewall-cmd --add-port={10050/tcp,10051/tcp} --permanent firewall-cmd --reload ``` 9. 访问 Zabbix Web 界面 现在,您可以通过在 Web 浏览器中输入服务器 IP 地址或域名来访问 Zabbix Web 界面。在第一次访问时,将会出现 Zabbix安装向导,您需要按照向导进行配置。 完成以上步骤后,您应该成功地在 CentOS 7 上安装和配置了 Zabbix 6.0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值