zabbix安装手册
1 准备工作
1.1 关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
1.2 关闭selinux
[root@localhost ~]# vim /etc/selinux/config
SELINUX=disabled
2 解压各组件源代码
# zabbix组件
tar xzvf zabbix-7.2.7.tar.gz
# php组件
tar xzvf php-8.4.7.tar.gz
# nginx组件
tar xzvf nginx-1.28.0.tar.gz
# postgresql组件
tar jxvf postgresql-17.0.tar.bz2
各组件解压后生成目录
drwxr-xr-x 8 502 games 229 4月 23 19:55 nginx-1.28.0
drwxr-xr-x 17 root root 4096 5月 6 20:31 php-8.4.7
drwxrwxr-x 6 root root 4096 9月 24 2024 postgresql-17.0
drwxr-xr-x 13 1000 1000 4096 5月 20 17:08 zabbix-7.2.7
3 编译安装postgresql数据库
3.1 编译、安装postgresql
./configure --prefix=/opt/pgsql-17.0 --without-readline
make -j4 && sudo make install
3.2 创建用户及权限
groupadd postgres
useradd -g postgres postgres
chown -R postgres:postgres /opt/pgsql-17.0
3.3 数据库初始化
3.3.1 创建目录及授权
mkdir -p /data/postgresql/data
chown postgres:postgres /data/postgresql/data
3.3.2 初始化数据库
su - postgres
/opt/pgsql-17.0/bin/initdb -D /data/postgresql/data -E UTF8 --locale=en_US.UTF-8
3.3.3 环境变量配置
编辑/etc/profile添加:
export PGHOME=/opt/pgsql-17.0
export PATH=$PGHOME/bin:$PATH
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
3.4 生成postgresql.service
3.4.1 生成服务日志目录
su - postgres
mkdir -p /tmp/postgresql/logs
3.4.2 配置服务文件
vim /etc/systemd/system/postgresql.service
[Unit]
Description=PostgreSQL 17.0
After=network.target
[Service]
Type=forking
User=postgres
Group=postgres
ExecStart=/opt/pgsql-17.0/bin/pg_ctl -D /data/postgresql/data -l /tmp/postgresql/logs/postgresql.log start
ExecStop=/opt/pgsql-17.0/bin/pg_ctl -D /data/postgresql/data stop
[Install]
WantedBy=multi-user.target
3.4.3 服务启动postgresql
systemctl daemon-reload
systemctl start postgresql.service
systemctl enable postgresql.service
4 安装postgresql数据库环境
4.1 登录数据库
su - postgres
psql -U postgres -d postgres
4.2 创建数据库
postgres=# CREATE DATABASE zabbix WITH ENCODING 'UTF8';
CREATE DATABASE
4.3 创建数据库用户
postgres=# CREATE USER zabbix WITH PASSWORD 'zabbix';
CREATE ROLE
4.4 数据库授权
--授予数据库所有权
postgres=# ALTER DATABASE zabbix OWNER TO zabbix;
ALTER DATABASE
--授予完整操作权限
postgres=# GRANT ALL PRIVILEGES ON DATABASE zabbix TO zabbix;
GRANT
--模式级权限配置
postgres=# GRANT USAGE, CREATE ON SCHEMA public TO zabbix;
GRANT
4.5 验证登录
psql -U zabbix -d zabbix -W
Password:
5 编译安装ZabbixServer
5.1 准备工作
5.1.1 yum安装net-snmp-devel、ncurses-devel、libcurl-devel
yum install ncurses-devel.x86_64 net-snmp-devel.x86_64 libcurl-devel.x86_64
5.1.2 rpm安装
rpm -ivh OpenIPMI-devel-2.0.29-1.ky10.x86_64.rpm
rpm -ivh libevent-devel-2.1.12-3.ky10.x86_64.rpm
5.2 编译安装ZabbixServer
./configure --enable-server --with-postgresql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi
make install
# 验证ZabbixServer安装情况
/usr/local/sbin/zabbix_server -V
zabbix_server (Zabbix) 7.2.7
Revision 1274916a6bc 20 May 2025, compilation time: May 31 2025 09:23:31
Copyright (C) 2025 Zabbix SIA
License AGPLv3: GNU Affero General Public License version 3 <https://www.gnu.org/licenses/>.
This is free software: you are free to change and redistribute it according to
the license. There is NO WARRANTY, to the extent permitted by law.
5.3初始化ZabbixServer数据库环境
5.3.1 准备工作
# 根据不通的数据库环境进入相应脚本目录
cd /root/zabbix-software/zabbix-7.2.7/database/postgresql
# 使用zabbix用户和zabbix数据库执行相关脚本
cp *.sql /home/postgres/zabbix_db_sql/.
chown postgres.postgres /home/postgres/zabbix_db_sql/*.*
su - postgres
5.3.2 开始初始化
cd /home/postgres/zabbix_db_sql/
# 每条命令执行后输入用户zabbix密码zabbix
cat schema.sql |psql -U zabbix -d zabbix -W
cat images.sql |psql -U zabbix -d zabbix -W
cat data.sql |psql -U zabbix -d zabbix -W
5.3.3 验证数据库初始化情况
zabbix=> select count(*) from pg_tables where tableowner='zabbix';
count
-------
203
5.3.4 配置ZabbixServer的数据库连接
# grep DB /usr/local/etc/zabbix_server.conf |grep -v ^#
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
5.4 配置ZabbixServer的服务
5.4.1 创建服务文件
cat /etc/systemd/system/zabbix_server.service
[Unit]
Description=Zabbix Server
After=network.target syslog.target
Requires=postgresql.service
[Service]
Type=forking
User=zabbix
Group=zabbix
Environment="CONFFILE=/usr/local/etc/zabbix_server.conf"
ExecStart=/usr/local/sbin/zabbix_server -c $CONFFILE
ExecStop=/usr/bin/kill $MAINPID
Restart=on-failure
RestartSec=5
PIDFile=/tmp/zabbix_server.pid
[Install]
WantedBy=multi-user.target
5.4.2 操作系统创建zabbix用户
groupadd --system zabbix
useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
5.4.3 启动并配置开机启动服务
systemctl enable zabbix_server.service
systemctl start zabbix_server.service
systemctl status zabbix_server.service
6.编译安装nginx
6.1 编译安装nginx
./configure --prefix=/usr/local/nginx
make && make install
6.2 配置nginx
6.2.1 修改默认站点
先修改如下
cat /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name 192.168.100.162;
root /usr/local/nginx/html/zabbix;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/home/www/php-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
修改完后检查nginx.conf配置是否正确
/usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
6.2.2 部署Zabbix前端
mkdir /usr/local/nginx/html/zabbix
cp -r /root/zabbix-software/zabbix-7.2.7/ui/* /usr/local/nginx/html/zabbix
6.3 配置nginx的服务
6.3.1 创建服务文件
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
6.3.2 启动并配置开机启动服务
systemctl start nginx.service
systemctl status nginx.service
systemctl enable nginx.service
7 编译安装php
7.1 准备工作
7.1.1 安装oniguruma正则表达式库
rpm -ivh oniguruma-6.9.0-3.ky10.x86_64.rpm
rpm -ivh oniguruma-devel-6.9.0-3.ky10.x86_64.rpm
7.1.2 创建www用户和组
groupadd www
useradd -g www www
7.2 编译安装php
./configure --prefix=/usr/local/php \
--enable-fpm --with-fpm-user=www --with-fpm-group=www \
--with-openssl --with-zlib --enable-mbstring \
--with-pgsql=/opt/pgsql-17.0 --with-pdo-pgsql=/opt/pgsql-17.0
make -j$(nproc) && sudo make install
7.3 配置php相关配置文件
cp ~/zabbix-software/php-8.4.7/php.ini-production /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
7.3.1 根据Zabbix要求修改php.ini相关配置
vim /usr/local/php/lib/php.ini
max_execution_time = 300
post_max_size = 16M
max_input_time = 300
date.timezone = Asia/Shanghai
7.3.2 根据Zabbix要求修改www.conf
注意:listen的值必须和nginx.conf中fastcgi_pass unix值相同,且nginx启动的用户必须有权限访问listen指向的文件
user = www
group = www
listen = /home/www/php-fpm.sock
listen.owner = www
listen.group = www
listen.mode = 0660
7.3.3 修改nginx.conf文件
指定nginx启动的用户,确保有权限能访问php-fpm.sock文件
user www;
7.4 编译php其他ZabbixServer必须模块
进入源码的ext目录
7.4.1 编译安装bcmath
cd bcmath
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
7.4.2 编译安装gd
rpm -ivh libjpeg-turbo-devel-2.0.5-3.ky10.x86_64.rpm
cd gd
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-freetype --with-jpeg
7.4.3 编译安装sockets
cd sockets
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
7.4.4 编译安装gettext
cd gettext
./configure --with-php-config=/usr/local/php/bin/php-conf
make && make install
7.4.5 编译安装curl
cd curl
./configure --with-php-config=/usr/local/php/bin/php-conf
make && make install
7.5 php-fpm开启extension
vim /usr/local/php/lib/php.ini
extension=bcmath
extension=gd
extension=gettext
extension=sockets
extension=curl
7.6 重启php-fpm和nginx激活extension
systemctl restart nginx.service php-fpm.service
8 在web配置Zabbix
8.1 安装前的汇总信息,注意schema这里填写public
8.2 最后提示无法创建配置文件
按照要求下载配置文件,存放至相关目录
保存为 “/usr/local/nginx/html/zabbix/conf/zabbix.conf.php”
8.3 登录ZabbixServer
用户名:Admin(注意大小写)
密码:zabbix
版权声明:
本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自
数据生活,生活数据!
喜欢就支持一下吧