sqlplus: error while loading shared libraries: libnsl.so.1: cannot open shared object file: No such

 

在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)

 

sqlplus: error while loading shared libraries: libnsl.so.1: cannot open shared object file: No such_第1张图片

 

根据下面命令判断依赖的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> 

你可能感兴趣的:(sqlplus: error while loading shared libraries: libnsl.so.1: cannot open shared object file: No such)