CentOS7搭建Zabbix4.2系统

时间:2022-07-23
本文章向大家介绍CentOS7搭建Zabbix4.2系统,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

关闭防火墙


systemctl stop firewalld.service    # 关闭防火墙 
systemctl disable firewalld.service # 关闭开机自启

关闭 SeLinux


sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config && /usr/sbin/setenforce 0

开始安装

1、安装zabbix包
# rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/4.2/rhel/7/x86_64/zabbix-release-4.2-2.el7.noarch.rpm
# yum clean all
2、安装 Zabbix server、Web前端、agent
vim /etc/yum.repos.d/zabbix.repo

将所有的repo.zabbix.com 修改为mirrors.aliyun.com/zabbix/ 重新生成缓存

sed -i 's/repo.zabbix.com/mirrors.aliyun.com/zabbix/g' /etc/yum.repos.d/zabbix.repo

清除源建立缓存

yum clean all
yum makecache

开始安装

yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent
3、安装并初始化数据库

如果没安装我们先安装

yum install mariadb mariadb-server
# 安装完成执行 
systemctl enable mariadb --now # 设置为开机自启动服务并启动服务
# 初始化数据库
mysql_secure_installation 
# 按照下面顺序执行 回车 y 新密码 再次输入密码 y y y

登录数据库

[root@idc ~]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 11
Server version: 5.5.65-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)]> 

执行如下命令

MariaDB [(none)]> use mysql;
MariaDB [mysql]>  create database zabbix character set utf8 collate utf8_bin;
MariaDB [mysql]>  create user zabbix@localhost identified by 'password';
MariaDB [mysql]>  grant all privileges on zabbix.* to zabbix@localhost;
MariaDB [mysql]>  quit;
4、导入初始架构和数据,系统将提示您输入新创建的密码
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
5、为Zabbix server配置数据库

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

DBPassword=password # 你设置的数据库密码
6、为Zabbix前端配置PHP

编辑配置文件 /etc/httpd/conf.d/zabbix.conf, uncomment and set the right timezone for you.

配置中查找下面的位置 并在下方添加
# php_value date.timezone Europe/Riga #默认 是注释 直接搜索这句话就行
php_value date.timezone Asia/Shanghai
7、启动Zabbix server和agent进程
systemctl restart zabbix-server zabbix-agent httpd # 启动
systemctl enable zabbix-server zabbix-agent httpd # 开机自启
8、配置Zabbix前端

访问:http://server_ip_or_name/zabbix

详情信息访问:https://www.zabbix.com/documentation/4.0/zh/manual/installation/install