暂无图片
暂无图片
2
暂无图片
暂无图片
暂无图片

技术干货 | YashanDB+Zabbix搭建监控可视化平台,手把手实操!

YashanDB 2024-09-09
481
Zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案,能监视各种网络参数,保证服务器系统的安全运营,并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。接下来,这篇文章将详细展开如何基于YashanDB进行Zabbix的部署~





Zabbix简介



Zabbix由几部分构成,Zabbix server、Zabbix proxy、Zabbix agent、Zabbix UI和DB。



Zabbix与YashanDB

Zabbix通过oci接口连接YashanDB,简单架构如下图。

Web:监控管理页面,新增主机、监控项、触发器等(web直接写入db,从db直接获取数据)。

Server:负责数据的主动轮询和被动获取,计算触发器条件,向用户发送通知。从db读取监控有效项,存储在缓存中。接收监控项数据,并写入db。

DB:存储Zabbix表数据

Proxy:proxy连接到server,并请求配置数据。从agent收集数据,所有数据均在本地缓存,然后发送给server。需要独立的数据库。

Agent:根据监控项,监控数据。

主动:agent从server/porxy请求监控项,定期采集数据发送到server/proxy。

被动:server/proxy询求数据,agent返回结果。




Zabbix安装部署

Zabbix



1.安装YashanDB

    1、生成配置文件
    ./bin/yasboot package config gen --cluster yashandb -u yashan -p 123456 --ip 192.168.24.49 --port 22 --install-path home/yashan/yasdb_home --data-path home/yashan/yasdb_data --begin-port 1688 --db 1 --yas-type SE


    2、安装yashandb
    ./bin/yasboot package install -t hosts.toml -i yashandb-23.2.3.100-linux-x86_64.tar.gz


    3、部署启动数据库
    ./bin/yasboot cluster deploy -t yashandb.toml


    4、修改sys用户密码
    ./bin/yasboot cluster password set -n yasdb_123 -c yashandb


    5、设置环境变量
    source home/yashan/yasdb_home/yashandb/23.2.3.100/conf/yashandb.bash

    安装yashandb-oci

      cd data
      tar -xzvf yashandb-oci-23.2.1.100-4-gecc0e02-linux-x86_64.tar.gz
      mv yashandb-oci-23.2.1.100-4-gecc0e02-linux-x86_64 yashandb-oci

      安装yashandb-client:

        cd data
        mkdir yashandb-client
        tar -xzvf yashandb-client-23.2.3.100-linux-x86_64.tar.gz

        设置环境变量:

          export YASOCI_PATH=/data/yashandb-oci
          export YASCLI_PATH=/data/yashandb-client/lib
          export LD_LIBRARY_PATH=$YASOCI_PATH:$YASCLI_PATH:$LD_LIBRARY_PATH


          2.编译安装zabbix server

          zabbix版本:zabbix-6.4.17

          zabbix下载:https://www.zabbix.com/download_sources

          1)oci依赖安装

            下载路径:
            https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html


            oci lib库:
            rpm -ivh oracle-instantclient-basic-21.11.0.0.0-1.el8.x86_64.rpm
            /usr/lib/oracle/21/client64/lib/


            oci头文件:
            rpm -ivh oracle-instantclient-devel-21.11.0.0.0-1.el8.x86_64.rpm
            /usr/include/oracle/21/client64/

            2)编译安装zabbix server

              tar -xzvf zabbix-6.4.17.tar.gz
              cd zabbix-6.4.17/
              ./configure --prefix=/data/zabbix/ --enable-server --enable-agent --enable-proxy --enable-java --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi --with-unixodbc=yes --with-oracle=yes
              make
              make install
              3 )创建用户及导入数据
              a. 创建zabbix用户和表空间
                create tablespace ZABBIX datafile '?/dbfiles/ZABBIX_DATA' size 2G autoextend on next 128M maxsize unlimited databucket '?/local_fs/ZABBIX_DATA';
                create user ZABBIX IDENTIFIED BY 123456 default TABLESPACE ZABBIX;
                grant dba to ZABBIX;

                -- drop user ZABBIX cascade;
                -- drop tablespace ZABBIX including contents and datafiles CASCADE CONSTRAINTS;

                -- 如果需要用zabbix proxy,则创建zabbix_proxy用户和表空间
                create tablespace ZABBIX_PROXY datafile '?/dbfiles/ZABBIX_PROXY_DATA' size 2G autoextend on next 128M maxsize unlimited databucket '?/local_fs/ZABBIX_PROXY_DATA';
                create user ZABBIX_PROXY IDENTIFIED BY 123456 default TABLESPACE ZABBIX_PROXY;
                grant dba to ZABBIX_PROXY;

                b.导入数据到yashandb

                数据文件修改:

                yasql默认autocommit=false,所以data.sql与images.sql文件末尾后面添加 "commit;"

                schema.sql:
                hosts表,字段description类型长度改为nvarchar2(4000)

                data.sql插入数据时,数据长度超过了2048个字符,适当改大。
                images.sql:
                yashandb SQL语句中常量字符串输入长度规格暂时是16000,而images.sql中的数据大部分超过了16000。  用 "||" 连接符连接lob数据。参考:
                images.sql
                末尾添加"commit;"
                data.sql:
                yashandb暂时不支持TO_NCLOB函数,去掉TO_NCLOB,不影响数据准确性。

                末尾添加"commit;"

                  -- zabbix用户数据迁移
                  cd home/yashan/zabbix/zabbix-6.4.17/database/oracle
                  yasql zabbix/123456 -f -e schema.sql
                  yasql zabbix/123456 -f -e images.sql
                  yasql zabbix/123456 -f -e data.sql


                  -- 如有proxy代理用户,建表即可
                  yasql zabbix_proxy/123456 -f -e schema.sql

                  3.php安装

                  本次zabbix版本是zabbix-6.4.17,需要php 7.4以上。

                  下载地址:https://rpmfind.net/linux/remi/enterprise/7/modular/x86_64/

                  1)安装包

                    php-json-7.4.33-15.el7.remi.x86_64
                    php-fpm-7.4.33-15.el7.remi.x86_64
                    php-ldap-7.4.33-15.el7.remi.x86_64
                    php-cli-7.4.33-15.el7.remi.x86_64
                    php-bcmath-7.4.33-15.el7.remi.x86_64
                    php-mbstring-7.4.33-15.el7.remi.x86_64
                    php-common-7.4.33-15.el7.remi.x86_64
                    php-odbc-7.4.33-15.el7.remi.x86_64
                    php-embedded-7.4.33-15.el7.remi.x86_64
                    php-sodium-7.4.33-15.el7.remi.x86_64
                    php-mysqlnd-7.4.33-15.el7.remi.x86_64
                    php-devel-7.4.33-15.el7.remi.x86_64
                    php-gd-7.4.33-15.el7.remi.x86_64
                    php-pdo-7.4.33-15.el7.remi.x86_64
                    php-opcache-7.4.33-15.el7.remi.x86_64
                    gd3php-2.3.3-7.el7.remi.x86_64
                    php-imap-7.4.33-15.el7.remi.x86_64
                    oniguruma5php-6.9.9-1.el7.remi.x86_64
                    php-7.4.33-15.el7.remi.x86_64
                    php-xml-7.4.33-15.el7.remi.x86_64

                    2)php配置

                      #参数配置:
                      vim etc/php.ini
                      post_max_size = 64M
                      max_execution_time = 300
                      max_input_time = 600
                      date.timezone = Asia/Shanghai




                      #php,web中环境变量无法识别
                      vim etc/php-fpm.d/www.conf
                      clear_env=no




                      #环境变量配置:
                      vim etc/sysconfig/php-fpm
                      YASOCI_PATH=/data/yashandb-oci
                      YASCLI_PATH=/data/yashandb-client/lib
                      LD_LIBRARY_PATH=$YASOCI_PATH:$YASCLI_PATH:$LD_LIBRARY_PATH


                      export YASOCI_PATH
                      export YASOCI_PATH
                      export LD_LIBRARY_PATH




                      #重启php
                      sudo systemctl restart php-fpm
                      3) php oci8.so安装

                      下载地址:https://pecl.php.net/package/oci8

                      wget http://pecl.php.net/get/oci8-2.2.0.tgz

                      下载oci8-2.2.0,3.0之后版本需要php更高版本才能支持。PHP 7.4.33,oci8-2.2.0够了。

                      安装配置步骤:https://www.php.net/manual/zh/oci8.installation.php

                      编译环境修改:

                      a. 用php自带的php-oci8-7.4.33-15.el7.remi.x86_64.rpm

                      yashandb有一些oci接口暂时未曾实现,暂时用不了。后续版本会逐步完善oci接口。

                      b. 用oracle的库编译的oci8.so,php -v会报错:
                        undefined symbol: _object_init_ex

                        基于以上两个原因,oci8.so决定基于libyas_oci.so编译安装。编译前做如下框中修改:

                          cd /usr/lib/oracle/21/client64/
                          mv lib lib-org
                          mkdir lib
                          cd lib
                          ln -s /data/yashandb-oci/libyas_oci.so libclntsh.so
                          ln -s /data/yashandb-oci/libyas_oci.so libclntsh.so.21.1
                          ln -s /data/yashandb-oci/libyas_oci.so libnnz21.so

                          编译安装:

                            phpize
                            ./configure -with-oci8=shared,instantclient,/usr/lib/oracle/21/client64/lib/
                            make
                            make install

                            php添加oci8扩展库配置:

                              vim /etc/php.d/oci8.ini
                              ; Enable pdo extension module
                              extension=oci8.so
                              4. zabbix web、zabbix server、zabbix agent配置

                              1)zabbix web配置

                              nginx配置:

                                vi /etc/nginx/conf.d/zbx.conf
                                server {
                                listen 80;
                                server_name 192.168.24.49;
                                root /var/www/zbx;


                                location / {
                                index index.php;
                                }


                                location ~ \.php$ {
                                fastcgi_pass 127.0.0.1:9000;
                                fastcgi_index index.php;
                                fastcgi_param SCRIPT_FILENAME /var/www/zbx$fastcgi_script_name;
                                include fastcgi_params;
                                }
                                }
                                web配置:
                                  cp  /home/yashan/zabbix/zabbix-6.4.17/ui/*  /var/www/zbx -rf


                                  cp /var/www/zbx/conf/zabbix.conf.php.example /var/www/zbx/conf/zabbix.conf.php
                                  vim /var/www/zbx/conf/zabbix.conf.php
                                  $DB['TYPE'] = 'ORACLE';
                                  $DB['SERVER'] = '';
                                  $DB['PORT'] = '1688';
                                  $DB['DATABASE'] = '192.168.24.49:1688';
                                  $DB['USER'] = 'zabbix';
                                  $DB['PASSWORD'] = '123456';

                                  2)zabbix server配置

                                    vi  /data/zabbix/etc/zabbix_server.conf
                                    LogFile=/data/zabbix/zabbix_server.log
                                    DBHost=
                                    #DBName=192.xx.xx.xx:6688,192.xx.xx.xx:6688 主备多个yashandb情况
                                    DBName=192.168.24.49:1688
                                    DBUser=zabbix
                                    DBPort=1688

                                    3)zabbix agent配置

                                      vi  /data/zabbix/etc/zabbix_agentd.conf
                                      Server=192.168.24.49
                                      ListenPort=10080 //agent port
                                      ServerActive=192.168.24.49 //Zabbix server/proxy address
                                      5. 启动zabbix服务

                                      1)启动zabbix和agent

                                        systemctl restart php-fpm nginx
                                        /data/zabbix/sbin/zabbix_server [-f]
                                        /data/zabbix/sbin/zabbix_agentd -c /data/zabbix/etc/zabbix_agentd.conf

                                        2)如需要,可以把zabbix server的启停功能放入到systemctl

                                          --如下,添加zabbix server启动到systemctl中,agentd也可用同样的方法添加上去
                                          vi /usr/lib/systemd/system/zabbix-server.service
                                          [Unit]
                                          Description=Zabbix Server with YaShanDB
                                          After=


                                          [Service]
                                          Type=simple
                                          ExecStart=/data/zabbix/zabbix/sbin/zabbix_server -f
                                          ExecStop=/bin/killall -9 zabbix_server
                                          User=zabbix


                                          [Install]
                                          WantedBy=multi-user.target
                                          6. 效果展示

                                          路由:192.168.24.49/index.php

                                          1)初始用户和密码

                                          2)配置主机agent IP和端口

                                          3)查看主机监控项图形





                                          最后修改时间:2024-09-11 09:50:38
                                          文章转载自YashanDB,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

                                          评论