在不设置环境变量的情况下在 Linux 上安装 Oracle Instantclient?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/764871/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 01:49:04  来源:igfitidea点击:

installing Oracle Instantclient on Linux without setting environment variables?

linuxoracleunixinstantclient

提问by Mark Harrison

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 而不设置环境变量?

回答by Mark Harrison

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:

要在不设置任何环境变量的情况下使用即时客户端:

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

回答by David Phillips

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

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

回答by hlovdal

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+"$@"}

回答by maxschlepzig

Oracle's instructions regarding setting the LD_LIBRARY_PATHare suboptimal.

Oracle 关于设置 的说明LD_LIBRARY_PATH并不理想。

On ELF platforms like Linux or Solaris there is really no need to require setting the LD_LIBRARY_PATHbecause 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因为可以在构建时将正确的库搜索路径(又名运行路径)写入二进制文件中,相对于二进制文件的位置。因此,使用此类二进制文件,运行时链接程序始终能够找到打包的库,即使已安装的子树被复制。

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

不幸的是,Oracle 不会像这样创建 Linux 的“即时客户端”二进制文件。但是,可以使用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_PATHenvironment 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 DB 包已经带有足够的运行路径。可以通过例如elfdump /path/to/sqlplus | grep PATH.

For more details on elfeditand 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 被认为是有害的

回答by user727445

or you can try using this command

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

Linux

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

回答by Aaron X

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/