Zabbix 是一款开源的企业级监控解决方案,能够监控网络的多个参数以及服务器、虚拟机、应用程序、服务、数据库、网站和云的健康状况和完整性。它提供了灵活的通知机制,允许用户为几乎任何事件配置基于电子邮件的告警,从而能够快速响应服务器问题。Zabbix 基于存储的数据提供出色的报告和数据可视化功能,使其成为容量规划的理想选择。
Zabbix 的核心特性
-
数据收集:Zabbix 支持多种数据收集方式,包括 SNMP、IPMI、JMX、VMware 监控,以及自定义检查。它可以按照自定义的时间间隔收集所需数据,并通过 Server/Proxy 和 Agents 来执行数据采集。
-
灵活的阈值定义:用户可以定义非常灵活的告警阈值,称之为触发器,触发器从后端数据库获得参考值。
-
高度可配置化告警:告警通知可以根据递增计划、接收者、媒介类型自定义发送,使用宏变量可以使告警通知变得更加高效有益。
-
实时绘图:内置图形功能可实现将监控项绘制成图形。
-
WEB监控功能:Zabbix 可以追踪模拟鼠标在 Web 网站上的点击操作,检查 Web 网站的功能和响应时间。
-
丰富的可视化选项:包括自定义图形、网络拓扑图、仪表盘样式展示、报表以及监控资源的高层次(业务)视图。
目录
详细步骤
1、关闭SELinux和防火墙
2、Nginx安装
3、安装php
4、配置Nginx和php
5、测试php和nginx
6、安装数据库
7、安装zabbix server
8、zabbix前端页面准备
本次使用的虚拟机为CentOs7-2009版本
IP:192.168.157.177
详细步骤
1、关闭SELinux和防火墙
systemctl stop firewalld && systemctl disable firewalld
vim /etc/sysconfig/selinux #进入SElinux配置文件
永久禁用SELinux vim /etc/sysconfig/selinux修改如下图所示
将SELinux=enforcing改为SELinux=disabled
修改完之后reboot重启一下
2、Nginx安装
(1)配置yum源
vim /etc/yum.repo.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
(2)安装nginx
yum install -y nginx --enablerepo=nginx-stable
(3)测试
rpm -qa | grep nginx
3、安装php
(1)安装所需要的环境
curl-o/etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-7.repo
yum install epel-release.noarch -y #安装epel
curl-o/etc/yum.repos.d/epel.repohttp://mirrors.aliyun.com/repo/epel-7.repo
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml php72w-process
-
(2)检查环境(14个)
rpm -qa |egrep 'nginx|php72w'
4、配置Nginx和php
(1)启动服务
systemctl enable nginx php-fpm.service
systemctl start nginx php-fpm.service
(2)配置nginx
Server_name 后面跟自己的主机ip
vim /etc/nginx/conf.d/zbx.oldboylinux.cn.conf
server {
listen 80;
server_name 192.168.157.177;
root /app/code/zbx;
location / {
index index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /app/code/zbx$fastcgi_script_name;
include fastcgi_params;
}
}
先测试一下,然后重启
nginx -t #测试
systemctl reload nginx #重启
(3)配置php
sed -ri '/^(user|group)/s#apache#nginx#g' /etc/php-fpm.d/www.conf
egrep '^(user|group)' /etc/php-fpm.d/www.conf
-
(4)配置nginx session
grep 'var/lib/php/session' /etc/php-fpm.d/www.conf
php_value[session.save_path] = /var/lib/php/session
mkdir -p /var/lib/php/session
chown nginx:nginx /var/lib/php/session
php-fpm -t #测试
systemctl reload php-fpm.service #重启服务
测试一下php-fpm -t
重启一下服务systemctl reload php-fpm.service
5、测试php和nginx
(1)添加测试文件
mkdir -p /app/code/zbx #创建一个目录用于测试
chown nginx:nginx /app/code/zbx #添加权限
vim /app/code/zbx/info.php #进入文件里面添加测试代码
<?php
phpinfo();
?>
(2)查看修改一下文件目录权限
# 查看文件权限
ls -l /app/code/zbx/info.php
# 递归修改目录权限(示例以用户 www-data 为例)
chown -R nginx:nginx /app/code/zbx
find /app/code/zbx -type d -exec chmod 755 {} \; # 目录权限:755
find /app/code/zbx -type f -exec chmod 644 {} \; # 文件权限:644
cat /app/code/zbx/info.php
(3)打开浏览器测试
http://192.168.157.177/info.php(输入自己的IP地址)
查看一下日志(可忽略)
tail -f /var/log/nginx/error.log
6、安装数据库
(1)数据库安装
yum install -y mariadb-server
systemctl start mariadb #加入自启动
systemctl enable mariadb
(2)登录mysql
mysql -u root 因为我之前已经创建过了所以进来是图中所示
mysql mysql -u root
(3)删除多余root账户
delete from user where user='root' and host='127.0.0.1';
delete from user where user='root' and host='::1';
(4)给mysql root设置密码(密码设置成功后进入数据库用mysql -u root -p)
mysql_secure_installation
(5)配置数据库
create database zabbix charset utf8 collate utf8_bin;
grant all on zabbix.* to 'zabbix'@'localhost' identified by '123456' ;
#123456为zabbix用户密码,可以修改为自己想设置的密码
grant all on zabbix.* to 'zabbix'@'192.168.157.%' identified by '123456' ;
#授予用户对 zabbix 数据库中所有表的所有权限,并使用相同的密码 123456
select user,host from mysql.user ; #查看数据库
show databases; #显示数据库
(6)修改root远程连接
use mysql;
update user set host='%' where user='root';
FLUSH PRIVILEGES;
7、安装zabbix server
(1)安装zabbix yum源
rpm -Uvh https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
sed -i 's#http://repo.zabbix.com#https://mirrors.tuna.tsinghua.edu.cn/zabbix#g'
vim /etc/yum.repos.d/zabbix.repo #编辑文件如下所示
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/$basearch/
enabled=1
gpgcheck=0
[zabbix-frontend]
name=Zabbix Official Repository frontend - $basearch
baseurl=https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/$basearch/frontend
enabled=0
gpgcheck=0
[zabbix-debuginfo]
name=Zabbix Official Repository debuginfo - $basearch
baseurl=https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/$basearch/debuginfo/
enabled=0
gpgcheck=0
[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=http://repo.zabbix.com/non-supported/rhel/7/$basearch/
enabled=1
gpgcheck=0
(2)安装server
yum install -y zabbix-server-mysql zabbix-agent2 #安装
zcat /usr/share/doc/zabbix-server-mysql-5.0.46/create.sql.gz |mysql -uzabbix -p1 zabbix #zabbix数据库导入数据
vim /etc/zabbix/zabbix_server.conf #配置连接数据库
:set nu可以显示行数,找到第91、100、116、124行修改成如下所示(每一行前面都不要有空格)
systemctl enable zabbix-server.service #启动zabbix-server
systemctl start zabbix-server.service
ss -lntup|grep zabbix
8、zabbix前端页面准备
(1)源码包下载
https://cdn.zabbix.com/zabbix/sources/stable/5.0/下载5.0.18版本
tar xzvf zabbix-5.0.18.tar.gz
cd zabbix-5.0.18/
cp -a ui/* /app/code/zbx/
chown -R nginx.nginx /app/code/zbx/
(2)安装zabbix
浏览器搜索http://192.168.157.177/setup.php(替换成自己的IP地址)
点next step进入到该界面时出现报错
进入vim /etc/php.ini修改配置,找到第368,378,656,802,877行修改成如图所示
vim /etc/php.ini
重启一下服务systemctl reload php-fpm.service,刷新界面
systemctl reload php-fpm.service
如果出现:界面报错 PHP bcmath extension missing (PHP configuration…
yum install php72w-bcmath
systemctl reload php-fpm.service #重启
再次刷新界面(我已经调成中文版了)
这里的Username输入Admin,Password输入zabbix
最终如图所示
结束!!!!
如果您在博客中发现任何错误和不解的地方欢迎在评论区进行指正和询问,看见后一定会及时更正和解答的。愿我们能够共同成长、进步!!!