CentOS7源码编译安装Zabbix6.2并进行调优、与grafana集成

Zabbix6.2在CentOS7上不支持使用yum方式安装,如果是CentOS8/9、Rocky等可以直接使用dnf(yum)包安装,虽然不如源码编译灵活,但是简单快捷,能够满足大多数使用场景需求。同时由于Zabbix6.2要求采用MySQL8数据库,而计划用于部署的服务器上还同时部署了其它不兼容MySQL8的系统,这里采用PostgreSQL作为Zabbix server数据库

  • Zabbix的架构信息:

1. zabbix-server

zabbix 的server 端,负责接收agent发送过来的监控数据,并且提供zabbix的所有核心功能。

2. database

用于存储监控数据和配置信息的数据库,目前常用的有mysql和postgresql两种数据库。

3. zabbix-web

zabbix的UI端,提供操作控制台和监控展示等功能。

4. zabbix-java-gateway

用于监控Java程序的JVM状态,zabbix本身无法直接从jvm获取监控指标,需使用该网关来实现。

5. zabbix-agent

zabbix的代理端,部署在目标主机上,用于收集主机的监控数据,并提供给到zabbix server。

  • 安装环境

  • 1.安装php74

    #查看系统自带php包
    rpm -qa | grep php
    
    #卸载php,注意先卸载依赖包
    rpm -e <包名>
    
    #安装PHP74
    wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
    rpm -Uvh epel-release-latest-7.noarch.rpm
    rpm -Uvh remi-release-7.rpm
    yum install yum-utils
    yum-config-manager --enable remi-php74
    yum install php74-php-gd php74-php-pdo php74-php-mbstring php74-php-cli php74-php-fpm php74-php-mysqlnd php-pgsql
    yum -y install curl-devl libxml2 libxml2-devel
    systemctl enable  php74-php-fpm.service
    systemctl start php74-php-fpm.service
    
    #如果php命令找不到,创建软连接
    ln -s /opt/remi/php74/root/usr/bin/php /usr/bin/php
    
    #修改php参数
    vim /etc/php.ini
    #修改post_max_size为16M
    #修改max_execution_time为300
    #修改max_input_time为300
    systemctl restart httpd php74-php-fpm.service

    2.安装postgresql 15

    wget https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/l/libzstd-1.5.2-1.el7.x86_64.rpm
    wget https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/l/llvm5.0-devel-5.0.1-7.el7.x86_64.rpm
    wget https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/l/llvm5.0-5.0.1-7.el7.x86_64.rpm
    wget https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/l/llvm5.0-libs-5.0.1-7.el7.x86_64.rpm
    yum install -y ./libzstd-1.5.2-1.el7.x86_64.rpm
    yum install -y centos-release-scl-rh llvm5*
    yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
    yum install postgresql15-server postgresql15-devel
    postgresql-15-setup  initdb
    systemctl enable postgresql-15
    systemctl start postgresql-15
    
    #修改postgres用户密码
    passwd postgres
    systemctl restart postgresql-15
    
    #修改数据库密码
    sudo -u postgres psql
    \password
    #退出psql命令行
    \q

  • 源码编译部署Zabbix6.2:

1.官网下载ZABBIX源码安装包(tar.gz)

扫描二维码关注公众号,回复: 16987747 查看本文章

2.解压

cd /home/cgyxt/workspace/zabbix
tar -zxvf zabbix-6.2.6.tar.gz

3.创建用户

groupadd --system zabbix
useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix

3.导入数据库

chmod -R 777 /home/cgyxt/workspace/zabbix/

#创建数据库用户zabbix

sudo -u postgres createuser --pwprompt zabbix

#创建数据库

sudo -u postgres createdb -O zabbix -E Unicode -T template0 zabbix

#导入数据库

cd /home/cgyxt/workspace/zabbix/zabbix-6.2.6/database/postgresql
cat schema.sql | sudo -u zabbix psql zabbix
cat images.sql | sudo -u zabbix psql zabbix
cat data.sql | sudo -u zabbix psql zabbix

4.按照需要安装安装依赖

yum install -y net-snmp-devel OpenIPMI-devel libevent-devel curl-devel java-1.6.0-openjdk-devel libssh2-devel go fping openldap openldap-devel unixODBC unixODBC-devel freetds mysql-connector-odbc

如需使用modbus协议传输数据:源码安装依赖libmodbus

tar -zxvf libmodbus-3.1.6.tar.gz
cd libmodbus-3.1.6/
./configure
make install

5.编译安装

cd /home/cgyxt/workspace/zabbix/zabbix-6.2.6/

./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-postgresql=/usr/pgsql-15/bin/pg_config --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-zlib --with-libpthread --with-libevent --with-libpcre --with-libmodbus=/usr/local --with-openipmi --with-ssh2 --with-unixodbc --with-ldap --with-openssl --with-iconv --enable-java --enable-webservice

注:也可以使用gnutls替代openssl加密:

yum install gnutls.x86_64 gnutls-c++.x86_64 gnutls-dane.x86_64  gnutls-devel.x86_64 gnutls-utils.x86_64 -y

./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-postgresql=/usr/pgsql-15/bin/pg_config --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-zlib --with-libpthread --with-libevent --with-libpcre --with-libmodbus=/usr/local --with-openipmi --with-ssh2 --with-unixodbc --with-ldap --with-gnutls --with-iconv --enable-java --enable-webservice

make install

6.修改配置文件

vim /usr/local/zabbix/etc/zabbix_server.conf
DBPassword=<password>
CacheSize=1024M   #增大zabbix_server缓存空间,避免主机较多时缓存用尽导致服务停止

7.创建启动脚本

#创建环境变量,用于直接用zabbix_server命令启动服务
echo "export PATH=$PATH:/usr/local/zabbix/sbin" >> ~/.bashrc


#创建zabbix_server守护文件
vim /lib/systemd/system/zabbix-server.service


[Unit]
Description=Zabbix Server
After=syslog.target
After=network.target

[Service]
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_server.conf"
#EnvironmentFile=-/etc/sysconfig/zabbix-server
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_server.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_server -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
TimeoutStopSec=10s

[Install]
WantedBy=multi-user.target


chmod 754 /lib/systemd/system/zabbix-server.service



#创建zabbix_agentd守护文件
vim /usr/lib/systemd/system/zabbix-agent.service

[Unit]
Description=Zabbix Agent
After=syslog.target
After=network.target

[Service]
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_agentd.conf"
#EnvironmentFile=-/etc/sysconfig/zabbix-agent
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_agentd.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_agentd -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s

[Install]
WantedBy=multi-user.target

chmod 754 /lib/systemd/system/zabbix-agent.service

8.移动前端文件至Apache服务目录

mkdir /var/www/html/zabbix/
cp -r /home/cgyxt/workspace/zabbix/zabbix-6.2.6/ui/* /var/www/html/zabbix/
chmod -R 777 /var/www/html/zabbix/

9.启动服务

systemctl daemon-reload
systemctl enable zabbix-server.service
systemctl start zabbix-server.service
systemctl enable zabbix-agent.service
systemctl start zabbix-agent.service
#查看进程检查结果
ps -ef | grep zabbix

#检查服务运行情况
systemctl -a | grep zabbix

10.Web界面中依据向导安装

11.修复中文乱码

#从电脑fonts文件夹中拷贝出微软雅黑字体,放入zabbix字体文件夹中
cp /home/cgyxt/workspace/zabbix/msyh.ttc /var/www/html/zabbix/assets/fonts/

#备份原有字体
mv /var/www/html/zabbix/assets/fonts/DejaVuSans.ttf /var/www/html/zabbix/assets/fonts/DejaVuSans.ttf.bak

#建立软连接
ln -s /var/www/html/zabbix/assets/fonts/msyh.ttc /var/www/html/zabbix/assets/fonts/DejaVuSans.ttf
#或直接覆盖:mv /var/www/html/zabbix/assets/fonts/msyh.ttc /var/www/html/zabbix/assets/fonts/DejaVuSans.ttf

11.设置zabbix用户无密码sudo权限,方便后续脚本编写

vim /etc/sudoers
#添加:zabbix  ALL=(ALL)       NOPASSWD:ALL


## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
zabbix  ALL=(ALL)       NOPASSWD:ALL
  • yum安装zabbix agent2

rpm -Uvh https://repo.zabbix.com/zabbix/6.2/rhel/7/x86_64/zabbix-release-6.2-3.el7.noarch.rpm
yum clean all
yum install zabbix-agent2 zabbix-agent2-plugin-* -y
systemctl restart zabbix-agent2
systemctl enable zabbix-agent2
  • 安装grafana并与Zabbix集成

1.下载rpm包并安装

wget https://dl.grafana.com/enterprise/release/grafana-enterprise-9.3.2-1.x86_64.rpm
yum -y install grafana-enterprise-9.3.2-1.x86_64.rpm
systemctl start grafana-server && systemctl enable grafana-server

浏览器访问IP:3000,用户名/密码:admin

2.下载安装Zabbix插件

(1)方法一

浏览器打开:

 ​https://grafana.com/api/plugins/alexanderzobnin-zabbix-app

搜索"downloadurl",在结果中“/api….”前加上“​​​ ​Grafana: The open observability platform | Grafana Labs“ 访问下载页面,重定向至下载地址:

https://storage.googleapis.com/plugins-community/alexanderzobnin-zabbix-app/release/4.2.10/alexanderzobnin-zabbix-app-4.2.10.zip

#下载完成后,上传到服务器,复制到/var/lib/grafana/plugins文件夹下并解压

cp alexanderzobnin-zabbix-app-4.2.10.zip /var/lib/grafana/plugins/
cd /var/lib/grafana/plugins/
unzip alexanderzobnin-zabbix-app-4.2.10.zip

(2)方法二

grafana-cli plugins install alexanderzobnin-zabbix-app

3.重启grafana-server,进入Web界面启用安装Zabbix插件

systemctl restart grafana-server

Web界面Configuration>Plugins>Zabbix,点enable

4.配置zabbix数据源

#Configuration>Datasources,添加,选择zabbix

填写zabbix服务器地址和用户名密码,进行测试。

猜你喜欢

转载自blog.csdn.net/N71FS1/article/details/130026855
今日推荐