PHP笔记网

革命尚未成功,同志仍须努力下载JDK17

作者:Albert.Wen  添加时间:2022-05-28 20:40:11  修改时间:2024-11-25 20:32:37  分类:IT运维/网络管理  编辑

官方的安装教程:

https://www.zabbix.com/cn/download?zabbix=5.0&os_distribution=centos&os_version=7&db=mysql&ws=nginx

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

Zabbix 5.0 LTS + CentOS 7 + MySQL 5.7 + Nginx

2、Install and configure Zabbix server for your platform

2.1 Install Zabbix repository

rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
yum clean all

2.2 Install Zabbix server and agent

yum install zabbix-server-mysql zabbix-agent

2.3 Install Zabbix frontend

安装依赖库:(参考:Linux中 安装centos-release-scl 报错No package centos-release-scl available

rpm -ivh https://cbs.centos.org/kojifiles/packages/centos-release-scl-rh/2/3.el7.centos/noarch/centos-release-scl-rh-2-3.el7.centos.noarch.rpm
rpm -ivh https://cbs.centos.org/kojifiles/packages/centos-release-scl/2/3.el7.centos/noarch/centos-release-scl-2-3.el7.centos.noarch.rpm

Enable Red Hat Software Collections(参考:CentOS 安装PHP7的正确姿势

yum install centos-release-scl

编辑配置文件 /etc/yum.repos.d/zabbix.repo and enable zabbix-frontend repository.

[zabbix-frontend]
...
enabled=1
...

Install Zabbix frontend packages.

yum -y install zabbix-web-mysql-scl zabbix-nginx-conf-scl

2.4 创建初始数据库

Make sure you have database server up and running.

在数据库主机上运行以下代码:

# mysql -uroot -p
password
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> create user zabbix@localhost identified by 'password';
mysql> grant all privileges on zabbix.* to zabbix@localhost;
mysql> quit;

导入初始架构和数据,系统将提示您输入新创建的密码:

zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix

注意:我是通过phpMyAdmin新建数据库和还原数据库文件的,新建数据库时,“排序规则”字符集一定要选择 utf8_bin

2.5 为Zabbix server配置数据库

编辑配置文件 /etc/zabbix/zabbix_server.conf

DBHost=localhost  #默认
DBPort=53306
DBName=zabbix     #默认
DBUser=zabbix     #默认
DBPassword=密码

注意:可以在上述配置文件中,修改 数据库名、用户名、访问密码、端口号

2.6 为Zabbix前端配置PHP

编辑配置文件 /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf ,  uncomment and set 'listen' and 'server_name' directives.

# listen 80;
# server_name example.com;

编辑配置文件 /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf , add nginx to listen.acl_users directive.

listen.acl_users = apache,nginx

Then uncomment and set the right timezone for you.

; php_value[date.timezone] = Europe/Riga

改为 中国的时区:

php_value[date.timezone] = Asia/Shanghai

2.7 启动Zabbix server和agent进程

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

# systemctl restart zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm
systemctl restart zabbix-server
systemctl restart zabbix-agent
systemctl restart rh-nginx116-nginx
systemctl restart rh-php72-php-fpm

systemctl enable zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm

注意:如果启动失败,可查看日志文件:

(1) zabbix-server的日志文件:vim /var/log/zabbix/zabbix_server.log

(2) zabbix-agent的日志文件:vim /var/log/zabbix/zabbix_agentd.log

(3) nginx的日志文件:vim  /var/opt/rh/rh-nginx116/log/nginx/error.log

(4) php-fpm日志文件:vim /var/opt/rh/rh-php72/log/php-fpm/error.log

注意:如果服务器先前已安装并运行了php-fpm、nginx套件,对刚新安装的php-fpm、nginx还需特殊处理一下,解决端口冲突的问题

(1) 修改 php-fpm 端口:

vim /etc/opt/rh/rh-php72/php-fpm.d/www.conf

把 listen = 127.0.0.1:9000 改为 listen = 127.0.0.1:9001

(2) 修改 nginx 端口:

vim /etc/opt/rh/rh-nginx116/nginx/nginx.conf

把里面默认的监控80端口的 server 节点 注释掉

(3) 修改zabbix-servermysql通信的sock文件路径(报错日志:connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'

参考链接:https://blog.csdn.net/weixin_42110159/article/details/118945136

mkdir -pv /var/lib/mysql
ln -s /alidata/server/mysql/mysql-5.7/log/mysql.sock /var/lib/mysql/mysql.sock

(4) 防火墙开放端口:zabbix-server的10051,nginx的81(参考:CentOS 7.x 防火墙设置

firewall-cmd --permanent --add-port=10051/tcp
firewall-cmd --permanent --add-port=81/tcp
firewall-cmd --reload

2.8 配置Zabbix前端

连接到新安装的Zabbix前端: http://server_ip_or_name,

账号:Admin 密码:zabbix   (注意:A大写)

根据Zabbix文件里步骤操作: Installing frontend

3、开始使用Zabbix

Read in documentation: 快速开始指南