zabbix7.0实操指南:基于麒麟V10操作系统部署zabbix7.0
在当今信息技术飞速发展的时代,企业对于IT基础设施的监控管理需求日益增长。为了确保系统的稳定性和高效性,我们需要一个强大的监控工具来实时监控各种硬件和软件资源的状态。Zabbix作为一个开源的企业级监控解决方案,因其强大的功能和灵活的配置而广受欢迎。
麒麟操作系统作为中国自主研发的一款安全、稳定、可靠的操作系统,已经广泛应用于政府、金融、教育等多个领域。本文将介绍如何在麒麟V10操作系统上搭建Zabbix7.0环境,以实现对IT基础设施的全面监控。通过本文的学习,您将掌握Zabbix的安装、配置以及基本使用方法,为您的企业提供一个高效、稳定的监控系统。
1. lnpp安装
linux+nginx+postgresql+php
Linux为麒麟V10
Nginx的版本为1.24.0
数据库postgresql版本为16.2
Php版本为8.3.3
以上源码包可以到对应官网进行下载
1.1. linux环境
(1) 本操作示例中linux环境使用kylinV10 SP2
(2) 环境已配置公网yum源
1.2. nginx安装
(1) yum 安装工具及环境依赖
yum -y install gcc-c++ # 编译工具安装 yum -y install pcre-devel openssl-devel # nginx 依赖安装
(2) itops用户创建
groupadd itops # 创建itops用户组 useradd -g itops itops # 程序用户itops创建 echo Kylin_p@ssw0rd | passwd --stdin itops # 修改itops用户密码
(3) nginx编译操作
tar xf nginx-1.24.0.tar.gz #解压源码包 cd nginx-1.24.0/ #进入源码包目录 ./configure --user=itops --group=itops --prefix=/opt/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre #配置和准备软件包以进行编译和安装的操作 make -j8 && make install #将编译好的程序安装到系统中
(4) nginx配置文件编写
mv /opt/nginx/conf/nginx.conf /opt/nginx/conf/nginx.bak #备份默认文件 vi /opt/nginx/conf/nginx.conf #创建并编辑Nginx配置文件 #i#输入 user itops itops; worker_processes 1; error_log logs/error.log crit; error_log logs/error.log notice; error_log logs/error.log info; pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm index.php; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } } 保存退出 # 测试nginx配置格式 chown itops: -R /opt/zabbix /opt/nginx/sbin/nginx -t
(5) nginx服务文件编写
vi /usr/lib/systemd/system/nginx.service #i# 输入 [Unit] Description=nginx After=network.target [Service] Type=forking ExecStart=/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf ExecReload=/opt/nginx/sbin/nginx -s reload ExecStop=/opt/nginx/sbin/nginx -s quit PrivateTmp=true [Install] WantedBy=multi-user.target
(6) nginx服务启动及自启
systemctl enable nginx --now
页面访问测试
1.3. 数据库postgresql安装
(1) yum安装postgresql工具及环境依赖
yum install -y unzip gcc gcc-c++ perl readline readline-devel openssl openssl-devel zlib zlib-devel ncurses-devel perl-ExtUtils-Embed python python-devel libxslt* python3-devel
(2) cmake 工具安装
yum install cmake -y # cmake版本需大于3.4版本,如yum方式安装cmake版本低,则需要用手动编译方式进行替换 cmake --version
(3) PG编译安装
# 编译PG tar xf postgresql-16.2.tar.gz cd postgresql-16.2/ ./configure --prefix=/opt/postgresql --with-pgport=5432 --with-segsize=16 --with-blocksize=32 --with-wal-blocksize=64 --with-libedit-preferred --with-perl --with-openssl --with-libxml --with-python --with-libxslt --enable-thread-safety --enable-nls=en_US.UTF-8 --without-icu make -j8 && make install # 初始化 mkdir /data chown itops: /data su - itops /opt/postgresql/bin/initdb -D /data/postgresql -E utf8 /opt/postgresql/bin/pg_ctl -D /data/postgresql/ start # 启动 vim /etc/profile # 设定全局变量 #i # 尾行追加如下部分 PATH=/opt/postgresql/bin:/usr/bin:/usr/sbin:/bin:/sbin/bin export PATH PG_CONFIG=/opt/postgresql/bin/pg_config export PG_CONFIG PGDATA=/data/postgresql export PGDATA LD_LIBRARY_PATH=/opt/postgresql/lib:$LD_LIBRARY_PATH export LD_LIBRARY_PATH source /etc/profile # 执行如下命令使变量生效
(4) postgresql服务文件编写
vi /usr/lib/systemd/system/postgresql.service #i# 输入 [Unit] Description=PostgreSQL database server After=network.target [Service] Type=forking User=itops Group=itops Environment=PGPORT=5432 Environment=PGDATA=/data/postgresql OOMScoreAdjust=-1000 ExecStart=/opt/postgresql/bin/pg_ctl start -D ${PGDATA} -s -o "-p ${PGPORT}" -w -t 300 ExecStop=/opt/postgresql/bin/pg_ctl stop -D ${PGDATA} -s -m fast ExecReload=/opt/postgresql/bin/pg_ctl reload -D ${PGDATA} -s TimeoutSec=300 [Install] WantedBy=multi-user.target
(5) pg服务启动及自启
su - itops -c 'pg_ctl stop' systemctl enable postgresql --now
1.4. php安装
(1) yum 安装工具及环境依赖
oniguruma、oniguruma-devel包(kylinV10) yum -y install libxml2-devel bzip2-devel libcurl-devel libpng-devel libjpeg-devel freetype-devel gmp-devel openldap-devel readline-devel libxslt-devel net-snmp-devel yum install oniguruma-* # 编译安装php tar xf php-8.3.3.tar.gz cd php-8.3.3/ cp -frp /usr/lib64/libldap* /usr/lib/ ./configure --prefix=/opt/php --with-config-file-path=/opt/php/etc --with-pgsql=/opt/postgresql --with-pdo-pgsql=/opt/postgresql --enable-gd --enable-bcmath --with-jpeg --with-freetype --enable-ctype --enable-xml --enable-session --enable-sockets --enable-mbstring --with-gettext --with-ldap --with-openssl --without-pdo-sqlite --without-sqlite3 --enable-fpm sed -i "s@-lcrypto@-lcrypto -llber@g" Makefile make -j8 && make install # 配置php相关参数 cp php.ini-production /opt/php/etc/php.ini ln -s /opt/php/etc/php.ini /etc/php.ini cp /opt/php/etc/php-fpm.conf.default /opt/php/etc/php-fpm.conf cp /opt/php/etc/php-fpm.d/www.conf.default /opt/php/etc/php-fpm.d/www.conf sed -i "s@user = nobody@user = itops@g" /opt/php/etc/php-fpm.d/www.conf sed -i "s@group = nobody@group = itops@g" /opt/php/etc/php-fpm.d/www.conf sed -i "s@pm.max_children = 5@pm.max_children = 30@g" /opt/php/etc/php-fpm.d/www.conf sed -i "s@;pid = run/php-fpm.pid@pid = run/php-fpm.pid@g" /opt/php/etc/php-fpm.d/www.conf sed -i "s@post_max_size = 8M@post_max_size = 16M@g" /opt/php/etc/php.ini sed -i "s@max_execution_time = 30@max_execution_time = 300@g" /opt/php/etc/php.ini sed -i "s@max_input_time = 60@max_input_time = 300@g" /opt/php/etc/php.ini # 生成php-fpm启动文件 cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm chmod +x /etc/init.d/php-fpm chown -R itops: /opt/php systemctl enable php-fpm --now
2. zabbix安装及启动
2.1. zabbix 编译安装
(1) yum 安装编译工具及依赖
yum -y install libssh2 libssh2-devel OpenIPMI-devel libevent-devel unixODBC unixODBC-devel java-1.8.0-openjdk-devel openssl-devel
(2) zabbix编译及配置参数定义
tar xf zabbix-7.0.0.tar.gz cd zabbix-7.0.0 ./configure --prefix=/opt/zabbix --enable-server --enable-agent --with-postgresql=/opt/postgresql/bin/pg_config --with-net-snmp --with-libcurl --with-libxml2 --with-unixodbc --with-openipmi --enable-ipv6 --enable-java --with-openssl --with-ssh2 --with-iconv --with-iconv-include --with-iconv-lib --with-libpcre --with-libevent --with-zlib --with-zlib-include --with-zlib-lib --with-libpthread --with-ldap make -j8 && make install 等待编译完成后 chown itops: -R /opt/zabbix vi /opt/zabbix/etc/zabbix_server.conf # 文件最后追加如下行 LogFile=/tmp/zabbix_server.log DBHost=localhost DBName=zabbix DBUser=zabbix DBPassword=ZABBIX DBPort=5432 Timeout=4 LogSlowQueries=3000 User=itops StatsAllowedIP=127.0.0.1
(3) zabbix库创建
# 创建zabbix用户 su - itops -c 'createuser --pwprompt zabbix' # 输入用户密码 # 创建zabbix库 su - itops -c 'createdb -O zabbix -E Unicode -T template0 zabbix'
(4) 数据库表结构导入
# 进入编译包数据库路径下 cd zabbix-7.0.0/database/postgresql/ # 导入表结构 cat schema.sql | /opt/postgresql/bin/psql -Uzabbix zabbix cat images.sql | /opt/postgresql/bin/psql -Uzabbix zabbix cat data.sql | /opt/postgresql/bin/psql -Uzabbix zabbix /opt/postgresql/bin/psql -Uzabbix zabbix -c 'CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE' # 关闭压缩,如果需要正常压缩,则跳过下方sed命令 sed -i 's#compression_status=1#compression_status=0#g' timescaledb/schema.sql cat timescaledb/schema.sql | /opt/postgresql/bin/psql -Uzabbix zabbix # 抛出 TimescaleDB is configured successfully 即视为超表创建成功,其余提示信息可忽略
2.2. zabbix 服务及agent程序启动
(1) 启动zabbix_server
/opt/zabbix/sbin/zabbix_server ss -lnt
(2) zabbix agent启动
echo 'User=itops' >> /opt/zabbix/etc/zabbix_agentd.conf /opt/zabbix/sbin/zabbix_agentd
2.3. zabbix_web 配置及初始化
(1) web部署
# 进入编译包路径下 cd zabbix-7.0.0/ # 拷贝ui代码至nginx cp -r ui/ /opt/nginx/html/zabbix chown itops: -R /opt/nginx/html/zabbix
(2) web页面初始化配置
访问页面初始化配置
完成后跳转至登录页,部署完默认账号密码为Admin/zabbix