Docker-Zabbix使用ODBC监控数据库

Docker-Zabbix使用ODBC监控数据库

前言

因最近容器化改造,zabbix-server也在k8s集群部署了,但官网容器未部署部分unixODBC驱动程序,需要自行重新构建新容器。

因此本次对PostgreSQLMySQLOracle三个数据库进行unixODBC驱动部署。

过程

因基础镜像使用的是底层系统为Centos8版本,因此需要提前准备好对应RPM包

其他系统可参考官方文档:https://www.zabbix.com/documentation/6.0/zh/manual/config/items/itemtypes/odbc_checks

提前下载一下rpm包:

mysql-connector-odbc-8.3.0-1.el8.x86_64.rpm
oracle-instantclient-basic-21.3.0.0.0-1.x86_64.rpm
oracle-instantclient-devel-21.3.0.0.0-1.x86_64.rpm
oracle-instantclient-odbc-21.3.0.0.0-1.x86_64.rpm
oracle-instantclient-sqlplus-21.3.0.0.0-1.x86_64.rpm
postgresql-odbc-10.03.0000-2.el8.src.rpm

Dockerfile重新构建内容如下:

FROM zabbix/zabbix-server-pgsql:6.0.25-centos
MAINTAINER GLJ

USER root

# 安装 ODBC驱动
copy mysql-connector-odbc-8.3.0-1.el8.x86_64.rpm /tmp/mysql-connector-odbc-8.3.0-1.el8.x86_64.rpm
#copy postgresql-odbc-10.03.0000-2.el8.src.rpm /tmp/postgresql-odbc-10.03.0000-2.el8.src.rpm
copy oracle-instantclient-basic-21.3.0.0.0-1.x86_64.rpm /tmp/oracle-instantclient-basic-21.3.0.0.0-1.x86_64.rpm
copy oracle-instantclient-devel-21.3.0.0.0-1.x86_64.rpm /tmp/oracle-instantclient-devel-21.3.0.0.0-1.x86_64.rpm
copy oracle-instantclient-odbc-21.3.0.0.0-1.x86_64.rpm /tmp/oracle-instantclient-odbc-21.3.0.0.0-1.x86_64.rpm
copy oracle-instantclient-sqlplus-21.3.0.0.0-1.x86_64.rpm /tmp/oracle-instantclient-sqlplus-21.3.0.0.0-1.x86_64.rpm

RUN sed -i.bak \
        -e 's|^mirrorlist=|#mirrorlist=|' \
        -e 's|^#baseurl=|baseurl=|' \
        -e 's|http://mirror.centos.org|https://mirrors.aliyun.com|' \
        /etc/yum.repos.d/CentOS-*.repo \
    && yum install -y unixODBC* postgresql-odbc  \
    && yum install -y /tmp/mysql-connector-odbc-8.3.0-1.el8.x86_64.rpm \
    && yum install -y /tmp/oracle-instantclient-basic-21.3.0.0.0-1.x86_64.rpm \
    && yum install -y /tmp/oracle-instantclient-devel-21.3.0.0.0-1.x86_64.rpm \
    && yum install -y /tmp/oracle-instantclient-odbc-21.3.0.0.0-1.x86_64.rpm \
    && yum install -y /tmp/oracle-instantclient-sqlplus-21.3.0.0.0-1.x86_64.rpm \
    && rm -f /tmp/mysql-connector-odbc-8.3.0-1.el8.x86_64.rpm \
    && rm -f /tmp/oracle-instantclient-*.rpm

USER 1997

构建新镜像

上次所有文件到一文件夹执行

docker build -t reg-hub.glj.com/zabbix/zabbix-server-pgsql:6.0.25-centos-db .

k8s引入odbcinst.iniodbc.ini文件内容

apiVersion: v1
kind: ConfigMap
metadata:
  namespace: zabbix
  name: zabbix-server-config
  labels:
    app: zabbix-server
    name: zabbix-server
data:
  odbc.ini: |-

    [postgres28]
    Driver = PostgreSQL
    Description = Test on PostgreSQL
    Database = zabbix
    Servername = 10.10.10.10
    UserName = zabbix
    Port = 5432
    ReadOnly = No
    Password = zabbix123


  odbcinst.ini: |-
    [PostgreSQL]
    Description=ODBC for PostgreSQL
    Driver=/usr/lib/psqlodbcw.so
    Setup=/usr/lib/libodbcpsqlS.so
    Driver64=/usr/lib64/psqlodbcw.so
    Setup64=/usr/lib64/libodbcpsqlS.so
    FileUsage=1

    [MySQL]
    Description=ODBC for MySQL
    Driver=/usr/lib/libmyodbc5.so
    Setup=/usr/lib/libodbcmyS.so
    Driver64=/usr/lib64/libmyodbc5.so
    Setup64=/usr/lib64/libodbcmyS.so
    FileUsage=1

    [FreeTDS]
    Description=Free Sybase & MS SQL Driver
    Driver=/usr/lib/libtdsodbc.so
    Setup=/usr/lib/libtdsS.so
    Driver64=/usr/lib64/libtdsodbc.so
    Setup64=/usr/lib64/libtdsS.so
    Port=1433

    [MariaDB]
    Description=ODBC for MariaDB
    Driver=/usr/lib/libmaodbc.so
    Driver64=/usr/lib64/libmaodbc.so
    FileUsage=1

    [MySQL ODBC 8.3 Unicode Driver]
    DRIVER=/usr/lib64/libmyodbc8w.so
    UsageCount=1

    [MySQL ODBC 8.3 ANSI Driver]
    DRIVER=/usr/lib64/libmyodbc8a.so
    UsageCount=1

    [Oracle]
    Description=ODBC for Oracle
    Driver=/usr/lib/oracle/21/client64/lib/libsqora.so.21.1

分别绑定到容器/etc/odbc.ini/etc/odbcinst.ini路径

image-20240131151137275

大致过程已完成,剩下即可进行zabbix页面配置监控,配置参考:Zabbix 中使用 PostgreSQL by ODBC

参考

1.https://www.zabbix.com/documentation/6.0/zh/manual/config/items/itemtypes/odbc_checks

2.https://github.com/zabbix/zabbix-docker/issues/80

3.https://blog.csdn.net/ethnicitybeta/article/details/126729825

评论

  1. Macintosh Chrome 121.0.0.0
    12 月前
    2024-2-01 9:26:08

    水两句别的吧,太专业了看不懂啊

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇