1. 创建Oracle用户及权限配置
在Oracle数据库中运行以下SQL命令来创建用户并授予必要的权限:
CREATE USER ZABBIX IDENTIFIED BY xxxxxxx DEFAULT TABLESPACE SYSTEM TEMPORARY TABLESPACE TEMP PROFILE DEFAULT ACCOUNT UNLOCK;
GRANT CONNECT TO ZABBIX;
GRANT RESOURCE TO ZABBIX;
ALTER USER ZABBIX DEFAULT ROLE ALL;
GRANT SELECT ANY TABLE TO ZABBIX;
GRANT CREATE SESSION TO ZABBIX;
GRANT SELECT ANY DICTIONARY TO ZABBIX;
GRANT UNLIMITED TABLESPACE TO ZABBIX;
GRANT SELECT ANY DICTIONARY TO ZABBIX;
用户信息:
- 用户名:
ZABBIX
- 密码:
xxxxxxxx
数据库信息:
- 数据库IP:
192.168.104.215
- 实例名:
xxx
2. 安装必要的软件
下载Oracle Instant Client和unixODBC相关安装包
- 创建目录并进入目录:
mkdir -p /opt/oracle cd /opt/oracle
- 下载安装包:
wget https://download.oracle.com/otn_software/linux/instantclient/217000/oracle-instantclient-basic-21.7.0.0.0-1.x86_64.rpm wget https://download.oracle.com/otn_software/linux/instantclient/217000/oracle-instantclient-sqlplus-21.7.0.0.0-1.x86_64.rpm wget https://download.oracle.com/otn_software/linux/instantclient/217000/oracle-instantclient-devel-21.7.0.0.0-1.x86_64.rpm wget https://download.oracle.com/otn_software/linux/instantclient/217000/oracle-instantclient-odbc-21.7.0.0.0-1.x86_64.rpm
- 安装Oracle客户端和unixODBC:
yum -y localinstall oracle-instantclient-* yum -y install unixODBC unixODBC-devel
3. 配置环境变量
编辑系统环境变量配置文件:
vim /etc/profile
添加以下内容:
export LD_LIBRARY_PATH=/usr/lib/oracle/21/client64/lib:$LD_LIBRARY_PATH
export PATH=/usr/lib/oracle/21/client64/bin:$PATH
export TNS_ADMIN=/usr/lib/oracle/21/client64/network/admin
使配置生效:
source /etc/profile
4. 配置ODBC驱动
编辑ODBC驱动配置文件:
vim /etc/odbcinst.ini
添加以下内容:
[OracleODBC-21.7]
Description = Oracle ODBC driver for Instant Client 21.7
Driver = /usr/lib/oracle/21/client64/lib/libsqora.so.21.1
FileUsage = 1
5. 验证Oracle Instant Client运行环境
通过以下命令验证是否安装成功:
ldd /usr/lib/oracle/21/client64/lib/libsqora.so.21.1
确保输出中所有依赖库均已正确解析,如:
/lib64/libdl.so.2
/lib64/libodbcinst.so.2
6. 配置数据库连接
编辑ODBC配置文件:
vim /etc/odbc.ini
添加数据库连接配置:
[abcd]
Description = Oracle ODBC Connection
Driver = OracleODBC-21.7
ServerName = 192.168.104.215/xxx
UserID = ZABBIX
Password = xxxxxxxx
7. 测试连接
使用isql
命令测试数据库连接:
isql -v abcd
如果配置正确,应显示类似以下输出:
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
+---------------------------------------+
至此,ODBC连接Oracle配置完成。