CentOS7.6安装zabbix6
一、环境介绍
OS版本:CentOS7.6
zabbix版本:zabbix6.0.6
数据库版本:MySQL8.0.19
php版本:php7.2.34
http:Apache2.4.6
libevent-devel:2.0.21
二、安装过程
1、配置yum源、安装依赖
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
rpm -ivh libevent-devel-2.0.21-4.el7.x86_64.rpm
yum install -y httpd php72w-cli php72w-common php72w-gd php72w-ldap php72w-mbstring php72w-mysqlnd php72w-xml php72w-bcmath mod_php72w
yum -y install gcc-c++ net-snmp-devel libevent curl curl-devel libxml2-devel libaio perl
2、关闭selinux,调整firewalld、创建用户
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config && setenforce 0
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
groupadd zabbix
useradd -g zabbix -M -s /sbin/nologin zabbix
3、配置php
vi /etc/php.ini,修改下列值:
max_execution_time = 300
max_input_time = 300
post_max_size = 16M
date.timezone = Asia/Shanghai
4、安装MySQL
tar -xf mysql-8.0.19-1.el7.x86_64.rpm-bundle.tar
libs=`rpm -qa | grep mariadb*`
rpm -e --nodeps $libs
rpm -ivh mysql-community-common-8.0.19-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.19-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-8.0.19-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-8.0.19-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.19-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.19-1.el7.x86_64.rpm
systemctl start mysqld
systemctl enable mysqld
查看初始密码,进入数据库:
cat /var/log/mysqld.log | grep password
mysql -uroot -p
对数据库进行如下设置:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'yourpassword';
UPDATE mysql.user SET `Host`='%' WHERE User='root';
flush privileges;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'yourpassword';
grant system_user on *.* to 'root';
create database zabbix character set utf8 collate utf8_bin;
CREATE USER 'zabbix'@'%' IDENTIFIED BY 'Zabbix@123';
flush privileges;
grant all privileges on *.* to zabbix@'%' with grant option;
ALTER USER 'zabbix'@'%' IDENTIFIED WITH mysql_native_password BY 'Zabbix@123';
flush privileges;
exit
更改MySQL默认数据存放位置
systemctl stop mysqld
mv /var/lib/mysql /data
vi /etc/my.cnf
[client]
port=3306
socket=/data/mysql/mysql.sock
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
5、导入zabbix数据库
systemctl start mysqld
tar -zxf zabbix-6.0.6.tar.gz
cd zabbix-6.0.6/database/mysql
mysql -uzabbix -pZabbix@123 -hlocalhost zabbix < schema.sql
mysql -uzabbix -pZabbix@123 -hlocalhost zabbix < images.sql
mysql -uzabbix -pZabbix@123 -hlocalhost zabbix < data.sql
6、编译安装zabbix
cp -a zabbix/ui /var/www/html/zabbix/
chown -R apache:apache /var/www/html
./configure --prefix=/usr/local/zabbix/ --enable-server --enable-agent --with-net-snmp --with-mysql --with-libcurl --with-libevent --with-libxml2 --with-openipmi
make && make install
vi /usr/local/zabbix/etc/zabbix_server.conf,修改下列值:
LogFile=/var/log/zabbix_server.log
DBName=zabbix
DBUser=zabbix
DBPassword=Zabbix@123
DBSocket=/data/mysql/mysql.sock
cd /var/www/html/zabbix/conf/
cp -a zabbix.conf.php.example zabbix.conf.php
vi zabbix.conf.php,修改下列值:
$DB['TYPE'] = 'MYSQL';
$DB['SERVER'] = '127.0.0.1';
$DB['PORT'] = '3306';
$DB['DATABASE'] = 'zabbix';
$DB['USER'] = 'zabbix';
$DB['PASSWORD'] = 'Zabbix@123';
启动httpd、启动zabbix_server
systemctl start httpd
cd /usr/local/zabbix/sbin
./zabbix_server
7、安装结果
进入网页,查看安装结果,默认账户密码:Admin/zabbix
三、安装排错
1、zabbix service is not running:the information displayed may not be current
查看zabbix_server.log
错误原因:connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
解决:vi /usr/local/zabbix/etc/zabbix_server.conf
更改:DBSocket=/data/mysql/mysql.sock
2、configure报错 error: MySQL library not found
错误原因:没有安装mysql-devel
解决:rpm -ivh mysql-community-devel-8.0.19-1.el7.x86_64.rpm
无需yum或rpm安装其他mysql-devel
3、进入网页报错:Zabbix Cannot connect to the database
cd /var/www/html/zabbix/conf
cp zabbix.conf.php.example zabbix.conf.php
vi zabbix.conf.php
$DB['TYPE'] = 'MYSQL';
$DB['SERVER'] = '127.0.0.1';
$DB['PORT'] = '3306';
$DB['DATABASE'] = 'zabbix';
$DB['USER'] = 'zabbix';
$DB['PASSWORD'] = 'Zabbix@123';
4、进入网页报错:atabase error: no such file or directory
cd /var/www/html/zabbix/conf
cp zabbix.conf.php.example zabbix.conf.php
$DB['SERVER'] = '127.0.0.1';