Zabbix(4.0\5.0)部署
2022-05-30 本文已影响0人
A二十一画
Zabbix4.0
1、部署环境
系统:CentOS7.8(内核3.10)
Zabbix版本:4.0
MySQL版本:8.0
Apache(httpd)版本:2.4.6
2、部署前准备
2.1、升级系统组件到最新版本
yum -y update
2.2、关闭selinux
# 临时关闭
setenforce 0
# 永久关闭
vim /etc/selinux/config
......
SELINUX=disabled
......
2.3、关闭防火墙
# 若是可以开启相关的端口,可以选择不关闭防火墙
systemctl stop firewalld
2.4、添加Zabbix、MySQL源
# 添加MySQL Yum源
wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
rpm -ivh mysql80-community-release-el7-1.noarch.rpm
yum clean all
yum makecache
# yum repolist all | grep mysql
# yum-config-manager --disable mysql57-community(关闭5.7版本)
# yum-config-manager --enable mysql80-community(开启8.0版本)
--------------------------------
# 添加Zabbix Yum源
cd /etc/yum.repos.d/
vim zabbix.repo
[zabbix]
name=Zabbix Official Repository - $basearch
#baseurl=http://repo.zabbix.com/zabbix/3.4/rhel/7/$basearch/
baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
3、构建LAMP环境
3.1、部署MySQL环境
# 安装MySQL
yum install mysql-community-server
systemctl start mysqld
# 修改密码
cat /var/log/mysqld.log | grep password # 获取初始root密码
mysql -uroot -p
> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!'
--------------------------------
# Mysql8.0设置密码过于简单解决方法:
> show variables like 'validate_password%';
> set global validate_password.policy=0;
> set global validate_password.length=1;
# 创建Zabbix数据库,以及zabbix用户
> create database zabbix character set utf8 collate utf8_bin;
> grant all on zabbix.* to 'zabbix'@'%' identified by 'ykadmin123';
> flush privileges;
# 删除MySQL空用户
> drop user ''@localhost;
> drop user ''@localhost.localdomain;
3.2、部署Apache环境
yum -y install httpd
systemct start httpd
# 配置httpd
vim /etc/httpd/conf/httpd.conf
......
ServerName www.xxxx.com # 可修改域名,此处使用ip访问,所以没有动
DirectoryIndex index.html index.php # 添加支持php格式
......
systemctl restart httpd
3.3、部署PHP环境
yum install -y php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mhash
# 配置PHP环境
vim /etc/php.ini
......
date.timezone = PRC # 设置时区
......
4、安装Zabbix
4.1、安装依赖包、组件
yum -y install net-snmp net-snmp-devel curl curl-devel libxml2 libxml2-devel libevent-devel.x86_64 javacc.noarch javacc-javadoc.noarch javacc-maven-plugin.noarch javacc*
4.2、安装Zabbbix
# 安装php支持zabbix的组件
yum -y install php-bcmath php-mbstring
# 安装Zabbix
yum -y install zabbix-server-mysql zabbix-web-mysql
# 导入Zabbix初始数据
zcat /usr/share/doc/zabbix-server-mysql-4.0.0/create.sql.gz | mysql -uzabbix -p zabbix
4.3、修改Zabbix配置
# Zabbix连接数据库设置
vim /etc/zabbix/zabbix_server.conf
......
DBName=zabbix
DBUser=zabbix
DBPassword=ykadmin123
......
# Zabbix时区设置
vim /etc/httpd/conf.d/zabbix.conf
......
将# php_value date.timezone Europe/Riga 变更成php_value date.timezone Asia/Shanghai
......
systemctl restart zabbix-server
5、Web安装Zabbix
浏览器访问地址:http://xxx.xxx.xxx.xxx/zabbix
6、安装时的坑
6.1、缺少libiksemel.so.3依赖
# 安装Zabbix时缺少libiksemel.so.3依赖
wget http://springdale.math.ias.edu/data/puias/unsupported/7/x86_64//iksemel-1.4-6.sdl7.x86_64.rpm
yum install iksemel-1.4-6.sdl7.x86_64.rpm
6.2、无法连接数据库
# Zabbix安装成功后遇到加密问题,无法登录数据库caching_sha2_password
tail -f /var/log/zabbix/zabbix_server.log
......
Details Cannot connect to the database.
Error connecting to database: Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/lib64/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory
......
# 修改加密规则
> ALTER USER 'zabbix'@'%' IDENTIFIED BY 'ykadmin123' PASSWORD EXPIRE NEVER;
# 更新密码(mysql_native_password模式)
> ALTER USER 'zabbix'@'%' IDENTIFIED WITH mysql_native_password BY 'ykadmin123';
6.3、中文字体乱码
windows字体位置:控制面板 -> 外观和个性化 -> 字体
将字体上传至/usr/share/zabbix/assets/fonts下
修改Zabbix配置文件
# 修改以下内容
vim /usr/share/zabbix/include/defines.inc.php
.....
define('ZBX_GRAPH_FONT_NAME', 'graphfont');
.....
define('ZBX_FONT_NAME', 'graphfont');
.....
# 将以上两行内的graphfont修改为上传字体名称(不需要加后缀)
Zabbix5.0
1、部署环境
系统:CentOS7.5(内核3.10)
Zabbix版本:5.0
MySQL版本:5.0
2、部署前准备
2.1、安装Zabbix源
# 下载Zabbix源
rpm -ivh https://mirrors.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.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo
# 更新
yum clean all && yum makecache
2.2、安装Zabbix
yum -y install zabbix-server-mysql zabbix-agent
yum install -y centos-release-scl
# 安装Zabbix前端包
yum -y install zabbix-web-mysql-scl zabbix-nginx-conf-scl
2.3、安装MySQL
# MySQL已经安装好
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to zabbix@'%' identified by 'rootroot';
mysql> flush privileges;
2.4、导入Zabbix的表
zcat /usr/share/doc/zabbix-server-mysql-5.0.22/create.sql.gz | mysql -uzabbix -p zabbix
2.5、修改Zabbix配置(与4.0配置一致)
2.6、修改前段配置PHP
# 编辑文件 /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf,取消注释并设置 'listen'指令
# listen 80;
listen 10088;
# 编辑文件 /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf,将 nginx 添加到 listen.acl_users 指令中
listen.acl_users = apache,nginx
# 修改时区
vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
php_value[date.timezone] = Asia/Shanghai
2.7、启动
systemctl restart zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm
systemctl enable zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm