Zabbix安装odbc创建oracle连接

文章目录

  • 前言
  • 一、下载软件包
  • 二、安装
    • 1.安装odbc
    • 2.安装Oracle客户端
  • 三、配置
  • 四、创建odbc连接
    • 1.添加数据源
    • 2.ISQL测试


前言

zabbix监控oracle数据库需要安装odbc和oracle客户端


一、下载软件包

odbc可以直接挂载系统镜像源进行安装,无需下载。
oracle客户端下载地址:官网链接

在这里插入图片描述

二、安装

1.安装odbc

yum install -y unixODBC*

2.安装Oracle客户端

yum -y install oracle-instantclient19.9-*

安装完成后的客户端目录

[root@zabbix-server soft]# cd /usr/lib/oracle/19.9/client64/
[root@zabbix-server client64]# ls
bin  lib
[root@zabbix-server client64]# cd /usr/share/oracle/19.9/client64/
[root@zabbix-server client64]# ls
admin  demo  doc
[root@zabbix-server client64]# cd /usr/include/oracle/19.9/client64/
[root@zabbix-server client64]# ls
ldap.h     occiAQ.h       occiData.h     oci1.h    ociapr.h  ocidfn.h   ocikpr.h    ocixstream.h  orid.h  oro.h
nzerror.h  occiCommon.h   occi.h         oci8dp.h  ocidef.h  ociextp.h  ociver.h    odci.h        ori.h   ort.h
nzt.h      occiControl.h  occiObjects.h  ociap.h   ocidem.h  oci.h      ocixmldb.h  oratypes.h    orl.h   xa.h
[root@zabbix-server client64]#

测试客户端是否可用
配置tns


[root@zabbix-server client64]# mkdir -p  /usr/lib/oracle/19.9/client64/network/admin/
[root@zabbix-server client64]# cd /usr/lib/oracle/19.9/client64/network/admin/
[root@zabbix-server admin]# ls
[root@zabbix-server admin]# vi tnsnames.ora
[root@zabbix-server admin]# cat tnsnames.ora 
EMRDB =
   (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.130 )(PORT = 1521 ))
    (CONNECT_DATA =
     (SERVER = DEDICATED)
     (SERVICE = DEDICATED)
     (SERVICE_NAME = zlemr)
 )
)

测试连接

[root@zabbix-server admin]# sqlplus zabbix/Zabbix_123@192.168.100.130/zlemr

SQL*Plus: Release 19.0.0.0.0 - Production on Thu Dec 21 10:12:07 2023
Version 19.9.0.0.0

Copyright (c) 1982, 2020, Oracle.  All rights reserved.


???: 
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> show parameter name

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
cell_offloadgroup_name		     string
db_file_name_convert		     string	 Z:\ORADATA\ZLEMR, Z:\ORADATA\Z
						 LEMR
db_name 			     string	 zlemr
db_unique_name			     string	 NZLEMR
global_names			     boolean	 FALSE
instance_name			     string	 zlemr
lock_name_space 		     string
log_file_name_convert		     string	 Z:\ORADATA\ZLEMR, Z:\ORADATA\Z
						 LEMR
processor_group_name		     string

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
service_names			     string	 ZLEMR
SQL>

三、配置

配置环境变量

[root@zabbix-server ~]#cat /etc/profile
export ORACLE_HOME=/usr/lib/oracle/19.9/client64
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib64:$LD_LIBRARY_PATH
export TNS_ADMIN=$ORACLE_HOME/network/admin
export PATH=$PATH:$ORACLE_HOME/bin:$HOME/bin
生效环境变量
[root@zabbix-server ~]# source /etc/profile

配置类库

[root@zabbix-server ~]# chmod +x /usr/lib/oracle/19.9/client64/lib/libsqora.so.19.1 
[root@zabbix-server ~]# cd /usr/lib64/
[root@zabbix-server lib64]# ln -s libodbcinst.so.2.0.0 libodbcinst.so.1

odbc添加oracle驱动

[root@zabbix-server lib64]# vi /etc/odbcinst.ini
添加如下行
######oracle#######
[Oracle]
Description     = ODBC for Oracle
Driver          = /usr/lib/oracle/19.9/client64/lib/libsqora.so.19.1

查看odbc版本信息

[root@zabbix-server lib64]# odbcinst -j
unixODBC 2.3.1
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8

四、创建odbc连接

1.添加数据源


[root@zabbix-server lib64]# cat /etc/odbc.ini 
[ZLEMR]
Driver = Oracle
DSN = ZLEMR
ServerName = 192.168.100.130:1521/zlemr
UserID = zabbix
Password = Zabbix_123

2.ISQL测试


[root@zabbix-server lib64]# isql -v zlemr
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+

连接成功。

你可能感兴趣的:(Zabbix,zabbix,oracle,数据库)