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

发布于 2024-07-18 09:01:51 字数 220 浏览 11 评论 0原文

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

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

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

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

茶底世界 2024-07-25 09:01:51

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

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

从 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

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

instantclient_10_2/

将文件复制到 /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

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

sudo cp tnsnames.ora /etc

测试用

/usr/bin/sqlplus scott/tiger@myoracle

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

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

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.

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.

sudo cp tnsnames.ora /etc

Test with

/usr/bin/sqlplus scott/tiger@myoracle
智商已欠费 2024-07-25 09:01:51

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

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.

挖个坑埋了你 2024-07-25 09:01:51

您当然可以将 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+"$@"}

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

#!/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+"$@"}
请止步禁区 2024-07-25 09:01:51

Oracle 关于设置 LD_LIBRARY_PATH 的说明不是最佳的。

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

不幸的是,Oracle 不会创建这样的 Linux“即时客户端”二进制文件。 但是,可以使用 patchelf 修复它们。

例如:

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

进行这些更改后,运行时链接器无需任何 LD_LIBRARY_PATH 环境变量即可找到所有需要的库。

在 Solaris 上,有 elfedit - 但 IIRC 至少有一些适用于 Solaris 的 Oracle DB 软件包已经附带了足够的运行路径。 人们可以通过例如 elfdump /path/to/sqlplus | 来验证这一点。 grep 路径。

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

Oracle's instructions regarding setting the LD_LIBRARY_PATH are suboptimal.

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.

Unfortunately, Oracle doesn't create the Linux 'Instant Client' binaries like that. But, it is possible to fix them with 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.

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.

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.

百合的盛世恋 2024-07-25 09:01:51

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

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

这样您就不需要 tnsnames.ora

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

风蛊 2024-07-25 09:01:51

对于来自 Linux 背景的任何使用 Solaris 的人(比如我!),我发现 @David Phillips 解决方案使用 Solaris 命令 crle -u -l /opt/instantclient 效果很好,

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

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文