在Linux上安装Oracle Instantclient而不设置环境变量?

时间:2022-05-27 11:42:15

Oracle's instructions specify setting LD_LIBRARY_PATH. This makes my application dependent on random users' configuration and is very troublesome to set up.

Oracle的指令指定设置LD_LIBRARY_PATH。这使我的应用程序依赖于随机用户的配置,并且设置起来非常麻烦。

How can I avoid having to set any environment variables?

如何避免设置任何环境变量?

related note for OS/X: installing Oracle Instantclient on Mac OS/X without setting environment variables?

OS / X的相关说明:在Mac OS / X上安装Oracle Instantclient而不设置环境变量?

6 个解决方案

#1


Oracle's instantclient installation instructions specify that the user set LD_LIBRARY_PATH. This is very troublesome to manage for multiple users.

Oracle的instantclient安装说明指定用户设置LD_LIBRARY_PATH。管理多个用户非常麻烦。

To use the instantclient without setting any environment variables:

要在不设置任何环境变量的情况下使用instantclient:

Download the instantclient distribution from oracle.com. For doing non-java software development, you will need (assuming Oracle 10.2):

从oracle.com下载instantclient发行版。对于非Java软件开发,您将需要(假设Oracle 10.2):

instantclient-basic-linux-x86_64-10.2.0.4.0.zip
instantclient-sdk-linux-x86_64-10.2.0.4.0.zip
instantclient-sqlplus-linux-x86_64-10.2.0.4.0.zip

Unzip the three files. This will give you a directory

解压缩这三个文件。这将为您提供一个目录

instantclient_10_2/

Copy the files to /usr, which is one of the default places the dynamic loader searches.

将文件复制到/ usr,这是动态加载程序搜索的默认位置之一。

sudo cp instantclient_10_2/sdk/include/*.h /usr/include
sudo cp instantclient_10_2/sqlplus         /usr/bin
sudo cp instantclient_10_2/*.so*           /usr/lib

If you use tnsnames.ora, copy it to /etc, which is the default global place the oracle runtime searches.

如果使用tnsnames.ora,请将其复制到/ etc,这是oracle运行时搜索的默认全局位置。

sudo cp tnsnames.ora /etc

Test with

/usr/bin/sqlplus scott/tiger@myoracle

#2


Add the library path to /etc/ld.so.conf, then run /sbin/ldconfig. You don't need to set LD_LIBRARY_PATH for libraries installed in standard locations like /usr/lib because these locations are already configured in /etc/ld.so.conf.

将库路径添加到/etc/ld.so.conf,然后运行/ sbin / ldconfig。您不需要为安装在/ usr / lib等标准位置的库设置LD_LIBRARY_PATH,因为这些位置已在/etc/ld.so.conf中配置。

#3


You could of course rename sqlplus to sqlplus.real and make a wrapper script:

你当然可以将sqlplus重命名为sqlplus.real并制作一个包装脚本:

#!/bin/sh

if [ "$LD_LIBRARY_PATH" = "" ]
then
        LD_LIBRARY_PATH=/what/ever
else
        LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/what/ever
fi

export LD_LIBRARY_PATH

exec sqlplus.real ${1+"$@"}

#4


or you can try using this command

或者您可以尝试使用此命令

Linux

sqlplus user/pass@'(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname)(PORT=port_number)))(CONNECT_DATA=(SID=sid)))'

Windows

sqlplus user/pass@"(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname)(PORT=port_number)))(CONNECT_DATA=(SID=sid)))"

so you don't need the tnsnames.ora

所以你不需要tnsnames.ora

#5


Oracle's instructions regarding setting the LD_LIBRARY_PATH are suboptimal.

Oracle关于设置LD_LIBRARY_PATH的指令不是最理想的。

On ELF platforms like Linux or Solaris there is really no need to require setting the LD_LIBRARY_PATH because the correct library search path (a.k.a. runpath) can be written into the binary, at build-time, relative to the location of the binary. Thus, with such binaries, the runtime linker is always able to find the packaged libraries, even if the installed subtree is copied around.

在Linux或Solaris等ELF平台上,实际上不需要设置LD_LIBRARY_PATH,因为正确的库搜索路径(a.k.a.runpath)可以在构建时相对于二进制文件的位置写入二进制文件。因此,使用此类二进制文件,运行时链接程序始终能够找到打包的库,即使已复制已安装的子树也是如此。

Unfortunately, Oracle doesn't create the Linux 'Instant Client' binaries like that. But, it is possible to fix them with patchelf.

不幸的是,Oracle没有像这样创建Linux“Instant Client”二进制文件。但是,可以用patchelf修复它们。

For example:

patchelf --set-rpath '$ORIGIN/..' /path/to/instantclient_11_2/sdk/proc
patchelf --set-rpath '$ORIGIN'    /path/to/instantclient_11_2/sqlplus
patchelf --set-rpath '$ORIGIN'    /path/to/instantclient_11_2/libclntsh.so.11.1

After those changes the runtime linker is able to find all needed libraries without any LD_LIBRARY_PATH environment variable.

在这些更改之后,运行时链接程序能够找到所有需要的库,而不需要任何LD_LIBRARY_PATH环境变量。

On Solaris there is elfedit - but IIRC at least some Oracle DB packages for Solaris already come with a sufficient runpath. One can verify that via e.g. elfdump /path/to/sqlplus | grep PATH.

在Solaris上有elfedit - 但是IIRC至少有一些用于Solaris的Oracle数据库软件包已经有足够的运行路径。可以通过例如验证elfdump / path / to / sqlplus | grep PATH。

For more details on elfedit and other good alternatives to LD_LIBRARY_PATH (that don't involve changing the binary itself) see also my article LD_LIBRARY_PATH considered harmful.

有关elfedit和LD_LIBRARY_PATH的其他良好替代方案的更多详细信息(不涉及更改二进制文件本身),另请参阅我的文章LD_LIBRARY_PATH被认为有害。

#6


For anyone playing with Solaris (like me!) coming from a Linux background, I found that @David Phillips solution worked well using the Solaris command crle -u -l /opt/instantclient

对于那些使用Solaris(像我一样)来自Linux背景的人来说,我发现@David Phillips解决方案使用Solaris命令运行良好crle -u -l / opt / instantclient

Thanks to post http://chrismiles.info/systemsadmin/solaris/articles/ld-path-customisation-on-solaris/

感谢帖子http://chrismiles.info/systemsadmin/solaris/articles/ld-path-customisation-on-solaris/

#1


Oracle's instantclient installation instructions specify that the user set LD_LIBRARY_PATH. This is very troublesome to manage for multiple users.

Oracle的instantclient安装说明指定用户设置LD_LIBRARY_PATH。管理多个用户非常麻烦。

To use the instantclient without setting any environment variables:

要在不设置任何环境变量的情况下使用instantclient:

Download the instantclient distribution from oracle.com. For doing non-java software development, you will need (assuming Oracle 10.2):

从oracle.com下载instantclient发行版。对于非Java软件开发,您将需要(假设Oracle 10.2):

instantclient-basic-linux-x86_64-10.2.0.4.0.zip
instantclient-sdk-linux-x86_64-10.2.0.4.0.zip
instantclient-sqlplus-linux-x86_64-10.2.0.4.0.zip

Unzip the three files. This will give you a directory

解压缩这三个文件。这将为您提供一个目录

instantclient_10_2/

Copy the files to /usr, which is one of the default places the dynamic loader searches.

将文件复制到/ usr,这是动态加载程序搜索的默认位置之一。

sudo cp instantclient_10_2/sdk/include/*.h /usr/include
sudo cp instantclient_10_2/sqlplus         /usr/bin
sudo cp instantclient_10_2/*.so*           /usr/lib

If you use tnsnames.ora, copy it to /etc, which is the default global place the oracle runtime searches.

如果使用tnsnames.ora,请将其复制到/ etc,这是oracle运行时搜索的默认全局位置。

sudo cp tnsnames.ora /etc

Test with

/usr/bin/sqlplus scott/tiger@myoracle

#2


Add the library path to /etc/ld.so.conf, then run /sbin/ldconfig. You don't need to set LD_LIBRARY_PATH for libraries installed in standard locations like /usr/lib because these locations are already configured in /etc/ld.so.conf.

将库路径添加到/etc/ld.so.conf,然后运行/ sbin / ldconfig。您不需要为安装在/ usr / lib等标准位置的库设置LD_LIBRARY_PATH,因为这些位置已在/etc/ld.so.conf中配置。

#3


You could of course rename sqlplus to sqlplus.real and make a wrapper script:

你当然可以将sqlplus重命名为sqlplus.real并制作一个包装脚本:

#!/bin/sh

if [ "$LD_LIBRARY_PATH" = "" ]
then
        LD_LIBRARY_PATH=/what/ever
else
        LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/what/ever
fi

export LD_LIBRARY_PATH

exec sqlplus.real ${1+"$@"}

#4


or you can try using this command

或者您可以尝试使用此命令

Linux

sqlplus user/pass@'(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname)(PORT=port_number)))(CONNECT_DATA=(SID=sid)))'

Windows

sqlplus user/pass@"(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname)(PORT=port_number)))(CONNECT_DATA=(SID=sid)))"

so you don't need the tnsnames.ora

所以你不需要tnsnames.ora

#5


Oracle's instructions regarding setting the LD_LIBRARY_PATH are suboptimal.

Oracle关于设置LD_LIBRARY_PATH的指令不是最理想的。

On ELF platforms like Linux or Solaris there is really no need to require setting the LD_LIBRARY_PATH because the correct library search path (a.k.a. runpath) can be written into the binary, at build-time, relative to the location of the binary. Thus, with such binaries, the runtime linker is always able to find the packaged libraries, even if the installed subtree is copied around.

在Linux或Solaris等ELF平台上,实际上不需要设置LD_LIBRARY_PATH,因为正确的库搜索路径(a.k.a.runpath)可以在构建时相对于二进制文件的位置写入二进制文件。因此,使用此类二进制文件,运行时链接程序始终能够找到打包的库,即使已复制已安装的子树也是如此。

Unfortunately, Oracle doesn't create the Linux 'Instant Client' binaries like that. But, it is possible to fix them with patchelf.

不幸的是,Oracle没有像这样创建Linux“Instant Client”二进制文件。但是,可以用patchelf修复它们。

For example:

patchelf --set-rpath '$ORIGIN/..' /path/to/instantclient_11_2/sdk/proc
patchelf --set-rpath '$ORIGIN'    /path/to/instantclient_11_2/sqlplus
patchelf --set-rpath '$ORIGIN'    /path/to/instantclient_11_2/libclntsh.so.11.1

After those changes the runtime linker is able to find all needed libraries without any LD_LIBRARY_PATH environment variable.

在这些更改之后,运行时链接程序能够找到所有需要的库,而不需要任何LD_LIBRARY_PATH环境变量。

On Solaris there is elfedit - but IIRC at least some Oracle DB packages for Solaris already come with a sufficient runpath. One can verify that via e.g. elfdump /path/to/sqlplus | grep PATH.

在Solaris上有elfedit - 但是IIRC至少有一些用于Solaris的Oracle数据库软件包已经有足够的运行路径。可以通过例如验证elfdump / path / to / sqlplus | grep PATH。

For more details on elfedit and other good alternatives to LD_LIBRARY_PATH (that don't involve changing the binary itself) see also my article LD_LIBRARY_PATH considered harmful.

有关elfedit和LD_LIBRARY_PATH的其他良好替代方案的更多详细信息(不涉及更改二进制文件本身),另请参阅我的文章LD_LIBRARY_PATH被认为有害。

#6


For anyone playing with Solaris (like me!) coming from a Linux background, I found that @David Phillips solution worked well using the Solaris command crle -u -l /opt/instantclient

对于那些使用Solaris(像我一样)来自Linux背景的人来说,我发现@David Phillips解决方案使用Solaris命令运行良好crle -u -l / opt / instantclient

Thanks to post http://chrismiles.info/systemsadmin/solaris/articles/ld-path-customisation-on-solaris/

感谢帖子http://chrismiles.info/systemsadmin/solaris/articles/ld-path-customisation-on-solaris/