目录
1.前提准备工作
# 前提准备工作:
做完我的博客中脚本一键部署部署lamp后做此操作,记得去掉其中的安装数据库步骤
或者
自己已经部署好apache 和 php7.4版本以上,并且实现网页效果
2.为mariadb10+版本的部署安装依赖
1.安装依赖
[root@c83 ~]# yum -y install http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/mariadb-common-10.5.9-1.module_el8.5.0+732+7afc82e7.x86_64.rpm
[root@c83 ~]# yum -y install http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/mariadb-connector-c-3.1.11-2.el8_3.x86_64.rpm
[root@c83 ~]# yum -y install http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/mariadb-errmsg-10.5.9-1.module_el8.5.0+732+7afc82e7.x86_64.rpm
[root@c83 ~]# yum -y install http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/mariadb-10.5.9-1.module_el8.5.0+732+7afc82e7.x86_64.rpm
[root@c83 ~]# yum -y install http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/mariadb-server-10.5.9-1.module_el8.5.0+732+7afc82e7.x86_64.rpm
3.启动服务,并查看服务状态已启动
systemctl enable --now mariadb
systemctl status mariadb
2.部署zabbix
1.安装zabbix依赖
[root@c83 ~]# yum -y install net-snmp-devel mysql-devel libevent-devel
[root@c83 zabbix-6.4.6]# yum -y install http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/OpenIPMI-devel-2.0.31-3.el8.x86_64.rpm
2.创建zabbix用户和组
[root@c83 ~]# groupadd --system zabbix
[root@c83 ~]# useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
3.下载zabbix至/usr/src目录并解压
[root@c83 src]# wget https://cdn.zabbix.com/zabbix/sources/stable/6.4/zabbix-6.4.6.tar.gz
[root@c83 src]# tar -zxvf zabbix-6.4.6.tar.gz
[root@c83 src]# ls
annobin apr-util-1.6.3.tar.gz kernels zabbix-6.4.6.tar.gz
apr-1.6.5 debug php-8.2.9
apr-1.6.5.tar.gz httpd-2.4.57 php-8.2.9.tar.xz
apr-util-1.6.3 httpd-2.4.57.tar.gz zabbix-6.4.6
4.配置mysql,创建zabbix库,创建zabbix用户并自定义密码
mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin;
mysql> create user 'zabbix'@'localhost' identified by '2664218545Z';
mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost';
mysql> SET GLOBAL log_bin_trust_function_creators = 1;
mysql> quit;
5.进入/usr/src/zabbix
[root@c83 src]# cd zabbix-6.4.6
[root@c83 zabbix-6.4.6]# ls
aclocal.m4 ChangeLog config.sub database install-sh man README
AUTHORS compile configure depcomp m4 misc sass
bin conf configure.ac include Makefile.am missing src
build config.guess COPYING INSTALL Makefile.in NEWS ui
[root@c83 zabbix-6.4.6]# cd database/
[root@c83 database]# ls
elasticsearch Makefile.am Makefile.in mysql oracle postgresql sqlite3
# 这里可以看到库创建后出现的一些文件
6.配置zabbix用户的库文件
[root@c83 database]# cd mysql/
[root@c83 mysql]# ls
data.sql history_pk_prepare.sql Makefile.am schema.sql
double.sql images.sql Makefile.in
[root@c83 mysql]# mysql -uzabbix -p2664218545Z zabbix < schema.sql
[root@c83 mysql]# mysql -uzabbix -p2664218545Z zabbix < images.sql
[root@c83 mysql]# mysql -uzabbix -p2664218545Z --default-character-set=utf8mb4 zabbix < data.sql
7.再登录mariadb
[root@c83 mysql]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 10.5.9-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)]> SET GLOBAL log_bin_trust_function_creators = 0;
Query OK, 0 rows affected (0.000 sec)
# 再将1改回0
8.设置环境变量
[root@c83 mysql]# export CFLAGS="-std=gnu99"
9.开始编译安装zabbix
[root@c83 zabbix-6.4.6]# ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi
***********************************************************
* Now run 'make install' *
* *
* Thank you for using Zabbix! *
* <http://www.zabbix.com> *
***********************************************************
# 叫我们立即make install
10.安装完成后看到一些新的目录和文件
[root@c83 ~]# cd /usr/local/etc/
[root@c83 etc]# ls
zabbix_agentd.conf zabbix_agentd.conf.d zabbix_server.conf zabbix_server.conf.d
10.在zabbix服务的主配置文件中添加zabbix数据库中zabbix用户的密码
[root@c83 etc]# vim zabbix_server.conf
# 找到这里
DBUser=zabbix
### Option: DBPassword
# Database password.
# Comment this line if no password is used.
#
# Mandatory: no
# Default:
# DBPassword=
DBPassword=2664218545Z # 这行是添加上去的密码,其它不变
11.启动服务
[root@c83 ~]# zabbix_server
[root@c83 ~]# zabbix_agentd
[root@c83 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10051 0.0.0.0:*
LISTEN 0 2048 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 128 [::]:10050 [::]:*
LISTEN 0 128 [::]:10051 [::]:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
# 10050和10051端口都出来了
12.将zabbix的网页文件复制到虚拟主机下
[root@c83 src]# cd zabbix-6.4.6
[root@c83 zabbix-6.4.6]# ls
aclocal.m4 compile config.sub depcomp Makefile missing ui
AUTHORS conf configure include Makefile.am NEWS
bin config.guess configure.ac INSTALL Makefile.in README
build config.log COPYING install-sh man sass
ChangeLog config.status database m4 misc src
# 将原有的php网页文件覆盖
[root@c83 zabbix-6.4.6]# cp -a ui/* /usr/local/httpd/htdocs/www.pupu.com/
cp: overwrite '/usr/local/httpd/htdocs/www.pupu.com/index.php'? y
# 13.将htdocs目录的属主和属组设为apache用户
[root@c83 httpd]# chown -R apache.apache htdocs/
[root@c83 httpd]# ll
total 40
drwxr-xr-x. 2 root root 4096 Sep 21 23:34 bin
drwxr-xr-x. 2 root root 167 Sep 21 23:34 build
drwxr-xr-x. 2 root root 78 Sep 21 23:34 cgi-bin
drwxr-xr-x. 4 root root 101 Sep 22 04:06 conf
drwxr-xr-x. 3 root root 4096 Sep 21 23:34 error
drwxr-xr-x. 3 apache apache 44 Sep 21 23:42 htdocs
drwxr-xr-x. 3 root root 8192 Sep 21 23:34 icons
drwxr-xr-x. 2 root root 4096 Sep 21 23:34 include
drwxr-xr-x. 2 root root 58 Sep 22 04:01 logs
drwxr-xr-x. 4 root root 30 Sep 21 23:34 man
drwxr-xr-x. 14 root root 8192 Sep 21 23:34 manual
drwxr-xr-x. 2 root root 4096 Sep 21 23:34 modules
[root@c83 httpd]# cd htdocs/
[root@c83 htdocs]# ll
total 8
-rw-r--r--. 1 apache apache 45 Jun 11 2007 index.html
drwxr-xr-x. 14 apache apache 4096 Sep 22 04:10 www.pupu.com
# 14.赋予conf文件777权限
[root@c83 htdocs]# chmod 777 /usr/local/httpd/htdocs/www.pupu.com/conf
# 15.用域名访问,可以看到zabbix网页
通过网页可以看到有些参数不满足要求
# 这里可以看到有些配置不满足需求
需要做以下操作
[root@c83 ~]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@c83 ~]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[root@c83 ~]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[root@c83 ~]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
# 然后重启php服务
[root@c83 ~]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
# 刷新网页
# 已经满足全部要求,进行下一步
# 账号密码是zabbix数据库zabbix用户的账号和密码 ,然后一直回车
# 用户名: : admin
# 密码: zabbix
登录
# 最终效果如下