实战在centos8上面部署监控服务zabbix 6.4.6
第一步:部署lamp,可以看完我之前的博客
注意事项:
php版本必须在7.4.0 - 8.2.X
mariadb的版本必须在10.5.00-10.8.X
apache的版本必须在1.3.12 或更高版本
安装部署mariadb10.5的版本:
mariadb的官网:MariaDB Products & Tools Downloads | MariaDB
找到对应的版本下载下来,使用第三方软件上传到自己的主机上面去
[root@kh2 lamp]# systemctl stop firewalld.service
[root@kh2 lamp]# setenforce 0
[root@kh2 ~]# ls
anaconda-ks.cfg mariadb-10.5.22-rhel-8-x86_64-rpms.tar
[root@kh2 ~]# tar xf mariadb-10.5.22-rhel-8-x86_64-rpms.tar
[root@kh2 ~]# ls
anaconda-ks.cfg mariadb-10.5.22-rhel-8-x86_64-rpms mariadb-10.5.22-rhel-8-x86_64-rpms.tar
[root@kh2 ~]# cd mariadb-10.5.22-rhel-8-x86_64-rpms/
[root@kh2 mariadb-10.5.22-rhel-8-x86_64-rpms]# ./setup_repository
[root@kh2 mariadb-10.5.22-rhel-8-x86_64-rpms]# yum install MariaDB-server -y
[root@kh2 mariadb-10.5.22-rhel-8-x86_64-rpms]# rpm -qa | grep -i mariadb #查看是否下载
MariaDB-client-10.5.22-1.el8.x86_64
MariaDB-server-10.5.22-1.el8.x86_64
MariaDB-shared-10.5.22-1.el8.x86_64
MariaDB-common-10.5.22-1.el8.x86_64
[root@kh2 lamp]# systemctl start mariadb.service #开启服务
[root@kh2 lamp]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
#连接设置密码:
[root@kh2 lamp]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.5.22-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 password = password('123456');
Query OK, 0 rows affected (0.001 sec)
###能成功访问到php页面在开始部署zabbix
zabbix服务端安装
zabbix官方网站:Download Zabbix sources
//安装依赖包
[root@localhost ~]# yum -y install net-snmp-devel libevent-devel mysql-devel OpenIPMI-libs
[root@kh2 ~]# 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
安装过程略....
//创建zabbix用户和组
[root@kh2 lamp]# useradd -r -M -s /sbin/nologin zabbix
[root@kh2 lamp]# id zabbix
uid=991(zabbix) gid=988(zabbix) groups=988(zabbix)
[root@kh2 lamp]#
//下载zabbix
[root@localhost ~]# cd /usr/src/
[root@kh2 src]# wget https://cdn.zabbix.com/zabbix/sources/stable/6.4/zabbix-6.4.6.tar.gz
//解压
[root@kh2 src]# tar xf zabbix-6.4.6.tar.gz
//配置zabbix数据库
[root@kh2 ~]# mysql -uroot -p123456
MariaDB [(none)]> create database zabbix character set utf8mb4 collate utf8mb4_bin; #创建zabbix的数据库它的编码是utf8
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> create user 'zabbix'@'localhost' identified by '123456'; #创建一个zabbix用户只允许它在本地登录密码为123456
Query OK, 0 rows affected (0.044 sec)
MariaDB [(none)]> grant all privileges on zabbix.* to 'zabbix'@'localhost'; #对zabbix进行授权
Query OK, 0 rows affected (0.012 sec)
MariaDB [(none)]> SET GLOBAL log_bin_trust_function_creators = 1; #设置全局变量
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> flush privileges; #刷新权限
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> show databases; #zabbix数据库创建成功
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| zabbix |
+--------------------+
5 rows in set (0.044 sec)
#创建表
#查看我们的表在哪里
[root@kh2 database]# ls
elasticsearch Makefile.in oracle sqlite3
Makefile.am mysql postgresql
[root@kh2 database]# cd mysql/
[root@kh2 mysql]# ls
data.sql history_pk_prepare.sql Makefile.am schema.sql
double.sql images.sql Makefile.in
[root@kh2 mysql]#
#导入表到zxbbix到数据库中去
[root@kh2 mysql]# mysql -uzabbix -p123456 zabbix < schema.sql
[root@kh2 mysql]# mysql -uzabbix -p123456 zabbix < images.sql
[root@kh2 mysql]# mysql -uzabbix -p123456 --default-character-set=utf8mb4 zabbix < data.sql
#成功导入schema后,可以禁用 log_bin_trust_function_creators:
mysql> SET GLOBAL log_bin_trust_function_creators = 0;
#查看表创建成功没
MariaDB [(none)]> show tables from zabbix;
+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| acknowledges |
| actions |
| alerts |
........省略........
| valuemap_mapping |
| widget |
| widget_field |
+----------------------------+
186 rows in set (0.001 sec)
#创建了186张表
#配置源
构建Zabbix服务器、Zabbix代理 或Zabbix代理需要带有GNU扩展的C99。此版本可以通过设置CFLAGS="-std=gnu99"来显式指定:1
[root@kh2 mysql]# export CFLAGS="-std=gnu99"
[root@kh2 mysql]# echo $CFLAGS
-std=gnu99
#配置源代码
#当为Zabbix server或proxy配置源码时,必须指定要使用的数据库类型。同一时间,只用一种数据库类型可以与server或proxy编译。
#要查看所有支持的配置选项,在提取的Zabbix源代码目录运行:
./configure --help
#要为Zabbix server和agent配置源代码,你可以执行类似如下命令:
[root@kh3 zabbix-6.4.6]# cd /usr/src/zabbix-6.4.6
[root@kh2 zabbix-6.4.6]# ./configure --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi
[root@kh2 zabbix-6.4.6]# make install
zabbix服务端配置
[root@kh2 zabbix-6.4.6]# cd /usr/local/etc/
[root@kh2 etc]# ls
zabbix_agentd.conf zabbix_server.conf
zabbix_agentd.conf.d zabbix_server.conf.d
//修改服务端配置文件
//设置数据库信息
[root@localhost ~]# vim /usr/local/etc/zabbix_server.conf
....
DBPassword=123456 //设置123456数据库连接密码
//启动zabbix_server和zabbix_agentd
[root@localhost ~]# zabbix_server
[root@localhost ~]# zabbix_agentd
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 *:10051 *:*
LISTEN 0 128 127.0.0.1:9000 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*
zabbix服务端web界面安装与配置
zabbix web界面安装前配置
//修改/etc/php.ini的配置并重启php-fpm
[root@localhost ~]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@localhost ~]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[root@localhost ~]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[root@localhost ~]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[root@localhost ~]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
#把监控的网站复制到你虚拟主机指定的网站去
[root@kh2 dxw.com]# cd /usr/local/apache/htdocs/dxw.com
[root@kh2 dxw.com]# pwd
/usr/local/apache/htdocs/dxw.com
[root@kh2 dxw.com]#
[root@kh2 dxw.com]# \cp -a /usr/src/zabbix-6.4.6/ui/* . #吧网页复制过去
[root@kh2 dxw.com]# ls
api_jsonrpc.php imgstore.php
api_scim.php include
....省略...
httpdetails.php widgets
image.php zabbix.php
[root@kh2 dxw.com]# chown -R apache.apache /usr/local/apache/htdocs #修改权限
//配置apache虚拟主机
[root@localhost ~]# vim /etc/httpd24/httpd.conf
//在配置文件的末尾加如下内容
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/dxw.com"
ServerName www.wangqing.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/dxw.com/
<Directory "/usr/local/apache/htdocs/dxw.com">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
//设置zabbix/conf目录的权限,让zabbix有权限生成配置文件zabbix.conf.php
[root@kh3 dxw.com]# chmod 777 /usr/local/apache/htdocs/dxw.com/conf
[root@kh3 dxw.com]# ll -d /usr/local/apache/htdocs/dxw.com/conf
drwxrwxrwx. 3 apache apache 94 Aug 22 16:10 /usr/local/apache/htdocs/dxw.com/conf
[root@kh3 dxw.com]#
//重启apache
[root@localhost ~]# apachectl -t
Syntax OK
[root@localhost ~]# apachectl stop
[root@localhost ~]# apachectl start
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 *:10051 *:*
LISTEN 0 128 127.0.0.1:9000 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*
4.3.2 安装zabbix web界面
- 修改/etc/hosts文件,添加域名与IP的映射
- 在浏览器上访问域名,本文设置的域名为www.dxw.com,你需要修改成你自己的域名
- 恢复zabbix/conf目录的权限为755
[root@kh2 dxw.com]# cat /etc/host
cat: /etc/host: No such file or directory
[root@kh2 dxw.com]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.227.130 fw fw
192.168.227.131 kh1 kh1
192.168.227.133 kh2 kh2
192.168.227.134 kh3 kh3
在浏览器上访问域名进行安装:
恢复zabbix/conf目录的权限为755:
[root@localhost ~]# chmod 755 /usr/local/apache/htdocs/dxw.com/conf
[root@localhost ~]# ll -d /usr/local/apache/htdocs/dxw.com/conf
drwxr-xr-x 2 apache apache 104 Aug 17 13:05 /usr/local/apache/htdocs/zabbix/conf
4.4 登录zabbix
zabbix默认登录用户名和密码:
用户名 | 密码 |
---|---|
Admin | zabbix |
完成!!!
设置zabbix开机自启
[root@kh2 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
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 128 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
#配置zabbix_server
[root@kh2 ~]# cp /usr/lib/systemd/system/sshd.service /usr/lib/systemd/system/zabbix_server.service
[root@kh2 ~]# vim /usr/lib/systemd/system/zabbix_server.service
[root@kh2 ~]# cat /usr/lib/systemd/system/zabbix_server.service
[Unit]
Description=zabbix server daemon
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/sbin/zabbix_server
ExecStop=pkill zabbix_server
ExecReload=/bin/kill -HUP $MAINPID
[Install]
#配置zabbix_agentd
[root@kh2 ~]# cp /usr/lib/systemd/system/zabbix_server.service /usr/lib/systemd/system/zabbix_agentd.service
[root@kh2 ~]# vim /usr/lib/systemd/system/zabbix_agentd.service
[root@kh2 ~]# cat /usr/lib/systemd/system/zabbix_agentd.service
[Unit]
Description=zabbix agentd daemon
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/sbin/zabbix_agentd
ExecStop=pkill zabbix_agentd
ExecReload=/bin/kill -HUP $MAINPID
[Install]
[root@kh2 ~]# systemctl daemon-reload #重新加载
#测试:
[root@kh2 ~]# pkill zabbix* #关闭zabbix服务
[root@kh2 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@kh2 ~]# systemctl enable --now zabbix_server.service 开启服务并设置开机自启
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix_server.service → /usr/lib/systemd/system/zabbix_server.service.
[root@kh2 ~]# systemctl enable --now zabbix_agentd.service
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix_agentd.service → /usr/lib/systemd/system/zabbix_agentd.service.
[root@kh2 ~]# ss -antl #成功开启服务
State Recv-Q Send-Q Local Address:Port Peer Address:Port
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 128 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@kh2 ~]#