秋栈博客

七月

CentOS 7 x86_64 搭建Zabbix-server端

4
2022-08-06

CentOS 7 x86_64 搭建Zabbix-server端

1、Server主机准备

1.1、关闭防火墙、

[root@VM-0-7-centos ~]# hostnamectl set-hostname zabbix-server
[root@VM-0-7-centos ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@VM-0-7-centos ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@VM-0-7-centos ~]# yum clean all && yum makecache
[root@VM-0-7-centos ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
[root@VM-0-7-centos ~]# getenforce
Disabled
[root@VM-0-7-centos ~]# systemctl stop firewalld && systemctl disable firewalld

1.2、安装依赖包

yum install vim iotop bc gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel zip unzip zlib-devel net-tools lrzsz tree ntpdate telnet lsof tcpdump wget libevent libevent-devel
 

2、安装MySQL-8.0

2.1、配置MySQL源

#下载MySQL源
wget https://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm
#配置MySQL源
yum -y install mysql80-community-release-el7-5.noarch.rpm

2.2、安装依赖

#安装MySQL相关依赖
yum -y install gcc-c++ mysql-devel net-snmp-devel libevent-devel

2.3、下载MySQL、zabbix

#下载zabbix
wget https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.1.tar.gz
#下载MySQL
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar

[root@zabbix-server ~]# ll
mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar
mysql80-community-release-el7-5.noarch.rpm
zabbix-6.0.1.tar.gz

2.4、解压安装MySQL

#创建MySQL目录
mkdir /usr/local/mysql
#解压MySQL安装包
tar xvf mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar -C /usr/local/mysql
#移动到mysql目录
cd /usr/local/mysql/
#RPM方式安装MySQL
rpm -ivh mysql-community-common-8.0.28-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-libs-8.0.28-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-libs-compat-8.0.28-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-client-8.0.28-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-server-8.0.28-1.el7.x86_64.rpm --force --nodeps
到mysql目录查看并安装
[root@zabbix-server ~]# cd /usr/local/mysql/
[root@zabbix-server mysql]# ls
mysql-community-client-8.0.28-1.el7.x86_64.rpm
mysql-community-client-plugins-8.0.28-1.el7.x86_64.rpm
mysql-community-common-8.0.28-1.el7.x86_64.rpm
mysql-community-devel-8.0.28-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.28-1.el7.x86_64.rpm
mysql-community-icu-data-files-8.0.28-1.el7.x86_64.rpm
mysql-community-libs-8.0.28-1.el7.x86_64.rpm
mysql-community-libs-compat-8.0.28-1.el7.x86_64.rpm
mysql-community-server-8.0.28-1.el7.x86_64.rpm
mysql-community-test-8.0.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-common-8.0.28-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-libs-8.0.28-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-libs-compat-8.0.28-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-client-8.0.28-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-server-8.0.28-1.el7.x86_64.rpm --force --nodeps

2.5、检查安装包

[root@zabbix-server ~]# rpm -qa |grep mysql
mysql-community-client-plugins-8.0.30-1.el7.x86_64
mysql-community-libs-compat-8.0.28-1.el7.x86_64
mysql-community-libs-compat-8.0.30-1.el7.x86_64
mysql-community-libs-8.0.28-1.el7.x86_64
mysql-community-libs-8.0.30-1.el7.x86_64
mysql-community-common-8.0.28-1.el7.x86_64
mysql-community-server-8.0.28-1.el7.x86_64
mysql80-community-release-el7-5.noarch
mysql-community-common-8.0.30-1.el7.x86_64
mysql-community-devel-8.0.30-1.el7.x86_64
mysql-community-client-8.0.28-1.el7.x86_64

2.6、启动MySQL并设置开机自启

[root@zabbix-server ~]# systemctl start mysqld
[root@zabbix-server ~]# systemctl enable mysqld
[root@zabbix-server ~]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 六 2022-08-06 15:38:26 CST; 13s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 4069 (mysqld)
   Status: "Server is operational"
   CGroup: /system.slice/mysqld.service
           └─4069 /usr/sbin/mysqld

2.7、查看MySQL端口

[root@zabbix-server ~]# netstat -anptu |grep mysql
tcp6       0      0 :::33060                :::*                    LISTEN      4069/mysqld
tcp6       0      0 :::3306                 :::*                    LISTEN      4069/mysqld
[root@zabbix-server ~]# ps -ef |grep mysql
mysql     4069     1  0 15:38 ?        00:00:00 /usr/sbin/mysqld
root      4259  1627  0 15:39 pts/0    00:00:00 grep --color=auto mysql

2.8、查看默认密码

[root@zabbix-server ~]# cat /var/log/mysqld.log | grep password
2022-08-06T07:38:21.672038Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: tatRxF=Tu8zn
密码:tatRxF=Tu8zn

2.9、修改MySQL密码

由于MySQL8.0 有密码验证组件,若希望设置简单的密码,需要修改服务验证条件 密码检查等级,0/LOW、1/MEDIUM、2/STRONG
set global validate_password.policy=0;
# 密码的最短长度
set global validate_password.length=6;
# 密码至少要包含的小写字母个数和大写字母个数
set global validate_password.mixed_case_count=0;
# 设置密码
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密码';
用默认密码登录上mysql
[root@zabbix-server ~]# mysql -uroot -p
Enter password: tatRxF=Tu8zn
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.28

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密码';

2.10、创建zabbix数据库

mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected, 2 warnings (0.01 sec)

mysql> create user zabbix@localhost identified by 'MySQL密码';
Query OK, 0 rows affected (0.01 sec)

mysql> grant all privileges on zabbix.* to zabbix@localhost;
Query OK, 0 rows affected (0.01 sec)

3、安装zabbix6.0

3.1、解压源码包

https://www.zabbix.com/cn/download_sources#60LTS
#创建zabbix目录
mkdir /usr/local/zabbix
#解压
tar -zxvf zabbix-6.0.1.tar.gz -C /usr/local/zabbix/

3.2、创建zabbix用户、组。

[root@zabbix-server ~]# groupadd zabbix
[root@zabbix-server ~]# useradd -g zabbix -M -s /sbin/nologin zabbix

3.3、编译安装zabbix

[root@zabbix-server zabbix-6.0.1]# ./configure --prefix=/usr/local/zabbix/ --enable-server --enable-agent --with-net-snmp --with-mysql
看到此页面后开始编译安装
[root@zabbix-server zabbix-6.0.1]# make install

4、安装PHP

4.1、下载

<
 yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm  
 yum -y install yum-utils
 yum-config-manager --disable 'remi-php*'
 yum-config-manager --enable   remi-php74 
 yum -y install php php-bcmath php-gd php-xml  php-mbstring php-mysqlnd php-ldap
 yum -y install curl-devl libxml2 libxml2-devel 

4.2、编辑配置文件

[root@zabbix-server ~]# vim /etc/php.ini

post_max_size = 8M
#修改为16M
post_max_size = 16M

max_execution_time = 30
#修改为300
max_execution_time = 300

max_input_time = 60
#修改为300
max_input_time = 300

5、配置阿帕奇

CentOS7自带Apache
[root@zabbix-server ~]# rpm -qa httpd
httpd-2.4.6-97.el7.centos.5.x86_64

5.1、移动zabbix前端文件至web服务的根目录并授权

[root@zabbix-server ~]# cp -r /usr/local/zabbix/zabbix-6.0.1/ui/* /var/www/html/
[root@zabbix-server ~]# chown apache:apache /var/www/html -R

5.2、导入zabbix数据库

mysql -uzabbix -p密码 zabbix < /usr/local/zabbix/zabbix-6.0.1/database/mysql/schema.sql 
mysql -uzabbix -p密码 zabbix < /usr/local/zabbix/zabbix-6.0.1/database/mysql/images.sql
mysql -uzabbix -p密码 zabbix < /usr/local/zabbix/zabbix-6.0.1/database/mysql/data.sql 
若出现该警告:mysql: [Warning] Using a password on the command line interface can be insecure. 提醒建议不要在命令行输入明文密码,此处忽略,等待导入完成即可。

5.3、修改zabbix-server文件数据库密码

 vim /usr/local/zabbix/etc/zabbix_server.conf
 
# DBPassword=    修改为MySQL的zabbix用户密码
DBPassword=密码

5.4、启动Apache、zabbix

[root@zabbix-server ~]# systemctl restart httpd
[root@zabbix-server ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

[root@zabbix-server ~]# cd /usr/local/zabbix/sbin/
[root@zabbix-server sbin]# ./zabbix_server

5、访问IP:80 进行初始化配置

6.0版本可以直接选择中文进入配置
选择时区
再次检查配置,点击下一步

恩!不错zabbix前端已经配置好了!千山万水第一步!加油,少年!

6、登录前端

默认账号:Admin 默认密码:zabbix

7、修改密码

 
  • 0