type
status
date
slug
summary
tags
category
icon
password
1、基础信息1.1 环境介绍1.2 软件版本1.3 服务器配置2、编译安装2.1 Nginx2.2 PHP2.3 MySQL2.4 Zabbix 6.0LTS3、被监控客户端安装3.1 Windows3.2 Linux4、Zabbix中添加客户端4.1 登录zabbix4.2 创建主机(被动模式)4.3 添加完成4.4 查看数据5、拓扑图显示流量6、配置钉钉机器人告警6.1 编写脚本6.2 web端配置
1、基础信息
1.1 环境介绍
本案例全部软件都采用官网安装包或安装流程进行安装,由于7不支持yum安装zabbix,因此采用了编译安装的方式
软件也可以按需选择版本、YUM安装,请自行选择。
1.2 软件版本
名称 | 软件版本 | 链接 |
操作系统 | CentOS 7.9 | 自行安装(安装时选择中文) |
中间件 | Nginx 1.20.2 | http://nginx.org/download/nginx-1.20.2.tar.gz |
PHP | PHP 7.3.12 | https://www.php.net/distributions/php-7.3.12.tar.gz |
数据库 | Mysql 8.0.12 | https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.12.tar.gz |
Zabbix | LTS 6.0.28 | https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.28.tar.gz |
1.3 服务器配置
目前由于负载不大,暂时全在一台机器上,后期按使用率分配
关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
iptables -F

关闭SELinux

2、编译安装
搭建LNMP环境
2.1 Nginx
安装依赖
yum -y install gcc gcc-c++ make libtool zlib zlib-devel pcre pcre-devel openssl openssl-devel autoconf automake cmake GeoIP-devel.x86_64


创建用户和解压安装包
useradd -s /sbin/nologin -M www

下载安装包
wget http://nginx.org/download/nginx-1.20.2.tar.gz

解压到指定目录
tar -zxvf nginx-1.20.2.tar.gz -C /usr/local/src

进入解压后的目录
cd /usr/local/src/nginx-1.20.2

设置预编译环境


编译安装
make && make install


为Nginx添加PHP环境


配置启动脚本

2.2 PHP
安装libzip环境依赖
下载安装包
wget https://nih.at/libzip/libzip-1.2.0.tar.gz --no-check-certificate

解压安装包
tar -zxvf libzip-1.2.0.tar.gz

编译安装



配置环境变量

刷新环境变量
ldconfig -v

配置zip扩展环境
cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h

安装PHP
安装依赖
yum -y install libxml2 libxml2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype-devel openssl openssl-devel

下载安装包

解压安装包到指定位置
tar -zxvf php-7.3.12.tar.gz -C /usr/local/src/

进入解压的目录
cd /usr/local/src/php-7.3.12/

编译安装


安装
make && make install


配置php和php-fpm
生成php自身配置文件
cp /usr/local/src/php-7.3.12/php.ini-production /usr/local/php73/etc/php.ini
生成php-fpm配置文件
cp /usr/local/php73/etc/php-fpm.d/www.conf.default /usr/local/php73/etc/php-fpm.d/www.conf
cp /usr/local/php73/etc/php-fpm.conf.default /usr/local/php73/etc/php-fpm.conf

添加环境变量
echo 'PATH=/usr/local/php/bin:$PATH' >> /etc/profile
刷新环境变量
source /etc/profile

生成php-fpm启动脚本
cp /usr/local/src/php-7.3.12/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm




2.3 MySQL
添加环境依赖并生效

安装依赖包
yum -y install wget cmake gcc gcc-c++ ncurses ncurses-devel libaio-devel openssl openssl-devel

下载MySQL8的源码包
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.12.tar.gz

添加用户组
groupadd mysql
useradd -M -s /sbin/nologin -r -g mysql mysql

解压到指定位置
tar -zxvf mysql-boost-8.0.12.tar.gz -C /usr/local/src

设置预编译环境


安装
make -j4 && make install -j4


编辑配置文件

添加path路径
echo "export PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile
source /etc/profile

生成启动脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
添加执行权限
chmod +x /etc/init.d/mysqld
修改权限
chown -R mysql:mysql /usr/local/mysql

初始化数据库
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
启动服务
/etc/init.d/mysqld start

刚安装完成无需密码登录,直接输入mysql

复制服务脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# 添加此服务到系统服务
chkconfig --add mysqld
# 添加服务后,就可以使用systemctl命令进行管理了
# 启动服务
systemctl start mysqld
# 设置服务为开机自启动
systemctl enable mysqld
# 查看服务运行状态
systemctl status mysqld

2.4 Zabbix 6.0LTS
使用mysql创建数据库、用户、授权

下载压缩包,解压
wget https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.28.tar.gz

解压到指定目录
tar -zvxf zabbix-6.0.28.tar.gz -C /usr/local/src

创建用户组、授权等
groupadd --system zabbix
useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
mkdir -m u=rwx,g=rwx,o= -p /usr/lib/zabbix
chown zabbix:zabbix /usr/lib/zabbix

安装软件,设置系统时间与网络时间同步
yum -y install ntpdate
ntpdate ntp1.aliyun.com

安装依赖
yum install -y mariadb-devel net-snmp-devel libevent-devel unixODBC-devel libssh2-devel openldap openldap-devel

安装go环境
下载安装包
wget https://dl.google.com/go/go1.18.linux-amd64.tar.gz

解压到指定目录
tar zxvf go1.18.linux-amd64.tar.gz -C /usr/local/

添加环境变量并刷新
echo "export PATH=$PATH:/usr/local/go/bin" >>/etc/profile
source /etc/profile

验证环境
cd /usr/local/go
go env

配置 go mod 代理
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct

安装JDK环境
下载安装包(需要拥有Oracle账号)
‣

解压文件到/usr/local
tar -zxvf jdk-8u391-linux-x64.tar.gz -C /usr/local

配置环境变量

验证环境
java -version

设置预编译环境


安装
make && make install



修改zabbix server配置文件



修改PHP配置文件参数

进入编译好的/usr/local/zabbix/sbin/下启动server与agentd服务
cd /usr/local/zabbix/sbin/
./zabbix_server
./zabbix_agentd

Zabbix 前端是 PHP 编写的,所以必须运行在支持 PHP 的 Web 服务器上。需要从ui路径下复制 PHP 文件到 Web 服务器的 HTML 文档目录,完成安装,把整个ui目录都拷贝过去并命名为zabbix
cd /usr/local/src/zabbix-6.0.28/
cp -r ui /usr/local/nginx/html/zabbix/

重启php
/etc/init.d/php-fpm restart

配置开机自启
复制源码启动文文件——从解压的源码包zabbix-6.0.28里取
cp -r /usr/local/src/zabbix-6.0.28/misc/init.d/fedora/core/* /etc/init.d/
修改zabbix_server脚本
vim /etc/init.d/zabbix_server
BASEDIR=/usr/local/zabbix

修改zabbix_agentd脚本
vim /etc/init.d/zabbix_agentd
BASEDIR=/usr/local/zabbix

给脚本执行权限
chmod 775 /etc/init.d/zabbix_*
配置开机自启
chkconfig zabbix_server on
chkconfig zabbix_agentd on

页面有乱码——替换字体文件(改为DejaVuSans.ttf) windows系统C:\Windows\Fonts
cd /usr/local/nginx/html/zabbix/assets/fonts
mv xxxxx.ttf DejaVuSans.ttf
重启服务
service zabbix_server restart

报错

安装完成,访问
http://IP/zabbix/setup.php

初始化界面配置





# 根据需求下载zabbix.conf.php并移动到指定位置



3、被监控客户端安装
被监控客户端安装相对简单,Windows直接下载MSI安装包,CentOS 按照官网的流程yum或者编译安装即可,还有客户端需要在防火墙开放10050端口。
在官网下载对应安装包:
https://www.zabbix.com/cn/download_agents
本文的环境是6.0 LTS 6.0.28,你可以根据实际情况选择,版本建议选择agent2,功能、性能都好一些。
3.1 Windows






3.2 Linux
1、yum安装

2、编译安装
安装go环境
下载安装包
wget https://dl.google.com/go/go1.18.linux-amd64.tar.gz

解压到指定目录
tar zxvf go1.18.linux-amd64.tar.gz -C /usr/local/

添加环境变量并刷新
echo "export PATH=$PATH:/usr/local/go/bin" >>/etc/profile
source /etc/profile

验证环境
cd /usr/local/go
go env

配置 go mod 代理
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct

下载zabbix源码包
wget https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.28.tar.gz

解压到指定目录
tar zxvf zabbix-6.0.28.tar.gz -C /usr/local/src

安装依赖
yum -y install cmake make gcc-c++ cmake bison-devel ncurses-devel bison perl perl-devel perl perl-devel mariadb-devel net-snmp-devel libevent-devel -y

进入解压目录
cd /usr/local/src/zabbix-6.0.28/
设置预编译环境
./configure --prefix=/usr/local/zabbix -enable-agent2


编译安装
make && make install


默认文件位置
修改zabbix_agent2.conf 配置文件

配置启动脚本

4、Zabbix中添加客户端
4.1 登录zabbix
找到监测-主机

4.2 创建主机(被动模式)
主动模式和被动模式区别
被动模式:被动模式就是由zabbix server向zabbix agent发出指令获取数据, 即zabbixagent被动的去获取数据并返回给zabbix server, zabbix server周期性的向agent 索取数据, 这总模式的最大问题就是会加大zabbix server的工作量, 在数百台服务器的环境下zabbix server不能及时获取到最新数据, 但这也是默认的工作方式。
主动模式:是由zabbix agent主动采集数据并返回给zabbix server, 不再需要zabbix serve进行干预, 因此主动模式在一定程度上可减轻zabbix server的压力
- 主机名:填写IP地址或主机名
- 模板根据系统类型选择:
- Windows选择:Windows by Zabbix agent
- Liunx选择:Linux by Zabbix agent
- 群组:自行选择,可以用自带的,也可以新建
- Interfaces:点击“添加”,选择“客户端”,填写客户端IP地址


4.3 添加完成
ZBX图标变为绿色,表示添加成功

4.4 查看数据
点击最新数据,能看到数据表示监控成功


5、拓扑图显示流量
选择监测-拓扑图
点进Local network

选择编辑拓扑图

点中Zabbix Server主机编辑,其他部分不需要调整,编辑链接即可。


添加标签

键值可以在配置-主机-监控项里查找



保存

6、配置钉钉机器人告警
6.1 编写脚本




6.2 web端配置
创建报警媒介--->创建用户群组--->创建用户--->创建触发器动作
配置报警媒介

只有钉钉机器人配置
脚本参数:
{ALERT.SENDTO}
#对应脚本中的,user=sys.argv[1](发送给钉钉群中的哪个用户)
{ALERT.SUBJECT}
#代表发送的信息的标题,在"报表"的"动作日志"中可以看到。
{ALERT.MESSAGE}
#对应脚本中的,text=sys.argv[3](发送的报警内容)

报警动作设置
创建动作

添加触发器

添加告警操作和恢复操作

添加警告操作

添加恢复操作

恢复操作配置

给用户添加报警媒介
点击用户-------报警媒介-------添加
"收件人"对应"钉钉告警"中的:{ALERT.SENDTO}
特别注意:这里只需要添加钉钉群里的任何一个成员的钉钉账号即可,即添加一个收件人,这样在机器人群里
成员都能看到告警信息.
如果添加多个收件人,则机器人群里就会发送多个告警信息,一个收件人发一条信息.
# 填写钉钉号是普通发送 填写手机号是@用户发送

- 作者:Sangyxv
- 链接:https://sangyxv.top/article/1
- 声明:本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。