在Zabbix Server伺服器上安裝oracle-instantclient11.2後,結果使用sqlplus命令時遇到“sqlplus: error while loading shared libraries: libnsl.so.1: cannot open shared object f... ...
在Zabbix Server伺服器上安裝oracle-instantclient11.2後,結果使用sqlplus命令時遇到“sqlplus: error while loading shared libraries: libnsl.so.1: cannot open shared object file: No such file or directory“錯誤,下麵總結一下解決過程。希望對以後遇到的人有所幫助.
操作系統版本 :CentOS Linux release 8.2.2004 (Core)
Oracle Client:oracle-instantclient11.2
從官方網址下載這些安裝包:
https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html
安裝過程非常簡單,如下所示:
# rpm -ivh oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
# rpm -ivh oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm
# rpm -ivh oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm
定位這些包的安裝路徑:
# rpm -ql oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
/usr/lib/oracle/11.2/client64/bin/adrci
/usr/lib/oracle/11.2/client64/bin/genezi
/usr/lib/oracle/11.2/client64/lib/libclntsh.so.11.1
/usr/lib/oracle/11.2/client64/lib/libnnz11.so
/usr/lib/oracle/11.2/client64/lib/libocci.so.11.1
/usr/lib/oracle/11.2/client64/lib/libociei.so
/usr/lib/oracle/11.2/client64/lib/libocijdbc11.so
/usr/lib/oracle/11.2/client64/lib/ojdbc5.jar
/usr/lib/oracle/11.2/client64/lib/ojdbc6.jar
/usr/lib/oracle/11.2/client64/lib/xstreams.jar
# rpm -ql oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm
/usr/bin/sqlplus64
/usr/lib/oracle/11.2/client64/bin/sqlplus
/usr/lib/oracle/11.2/client64/lib/glogin.sql
/usr/lib/oracle/11.2/client64/lib/libsqlplus.so
/usr/lib/oracle/11.2/client64/lib/libsqlplusic.so
配置環境變數
# vi /etc/profile 增加下麵配置
#Add by kerry
export ORACLE_HOME=/usr/lib/oracle/11.2/client64
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export PATH=$PATH:$ORACLE_HOME/bin
執行下麵的命令使配置生效
#source /etc/profile
添加動態庫配置文件
# vi /etc/ld.so.conf.d/oracle.conf
/usr/lib/oracle/11.2/client64/lib
~
執行命令
# ldconfig
關於ldconfig命令的用途介紹如下:
ldconfig是一個動態鏈接庫管理命令。
為了讓動態鏈接庫為系統所共用,需運行動態鏈接庫的管理命令
主要是在搜尋預設目錄/lib和/usr/lib以及動態庫配置文件/etc/ld.so.conf內所列的目錄,搜索出可共用的動態鏈接庫(格式如lib*.so*),進而創建出動態裝入程式(ld.so)所需的連接和緩存文件,緩存文件預設為/etc/ld.so.cache,此文件保存已排好序的動態鏈接庫名字列表。linux下的共用庫機制採用了類似高速緩存機制,將庫信息保存在/etc/ld.so.cache,程式連接的時候首先從這個文件里查找,然後再到ld.so.conf的路徑中查找。為了讓動態鏈接庫為系統所共用,需運行動態鏈接庫的管理命令ldconfig,此執行程式存放在/sbin目錄下。
也可以使用下麵shell腳本進行配置
sh -c "echo /usr/lib/oracle/11.2/client64/lib > /etc/ld.so.conf.d/oracle.conf";sudo ldconfig
驗證測試時,sqlplus出現下麵問題:
# sqlplus /nolog
sqlplus: error while loading shared libraries: libnsl.so.1: cannot open shared object file: No such file or directory
出現這個錯誤的可能情況非常多,例如,環境變數配置有問題,缺少依賴包等等。這裡前面的環境變數配置正常,排查依賴的庫是否有問題,發現libnsl.so.1找不到。
# ldd /usr/lib/oracle/11.2/client64/bin/sqlplus
linux-vdso.so.1 (0x00007ffd0b7a5000)
libsqlplus.so => /usr/lib/oracle/11.2/client64/lib/libsqlplus.so (0x00007f927b563000)
libclntsh.so.11.1 => /usr/lib/oracle/11.2/client64/lib/libclntsh.so.11.1 (0x00007f9278bb3000)
libnnz11.so => /usr/lib/oracle/11.2/client64/lib/libnnz11.so (0x00007f92787e6000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f92785e2000)
libm.so.6 => /lib64/libm.so.6 (0x00007f9278260000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f9278040000)
libnsl.so.1 => not found
libc.so.6 => /lib64/libc.so.6 (0x00007f9277c7e000)
libnsl.so.1 => not found
libnsl.so.1 => not found
libaio.so.1 => /lib64/libaio.so.1 (0x00007f9277a7b000)
/lib64/ld-linux-x86-64.so.2 (0x00007f927b522000)
根據下麵命令判斷依賴的libnsl包沒有安裝。
# yum list installed | grep libnsl
# yum list | grep libnsl
libnsl2.x86_64 1.2.0-2.20180605git4a062cf.el8 @anaconda
libnsl.i686 2.28-101.el8 BaseOS
libnsl.x86_64 2.28-101.el8 BaseOS
libnsl2.i686 1.2.0-2.20180605git4a062cf.el8 BaseOS
# yum install libnsl.x86_64
安裝缺失的依賴包後,測試驗證問題解決。
# sqlplus /nolog
SQL*Plus: Release 11.2.0.4.0 Production on Thu Jul 23 20:29:49 2020
Copyright (c) 1982, 2013, Oracle. All rights reserved.
SQL>