Debian

libjli.so 未找到。如何在沒有root訪問權限的情況下安裝java?

  • April 20, 2020

我想在一個簡單的 Web 託管伺服器上執行 java,我有 ssh 訪問權限但沒有 root 權限。我已經下載並解壓了 jdk linux/x64 tarball,但執行 java 二進製文件然後產生

jdk-14.0.1/bin/java: error while loading shared libraries: libjli.so:
cannot open shared object file: No such file or directory

該文件libjli.so位於jdk-14.0.1/lib子目錄中,但 java 二進製文件似乎無法找到它。

執行strace jdk-14.0.1/bin/java產量:

execve("jdk-14.0.1/bin/java", ["jdk-14.0.1/bin/java"], [/* 17 vars */]) = 0
brk(0)                                  = 0x7fa16e241000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa16d87c000
readlink("/proc/self/exe", 0x7fffb04bc970, 4096) = -1 ENOENT (No such file or directory)
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=24961, ...}) = 0
mmap(NULL, 24961, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fa16d875000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/tls/x86_64/libz.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/lib/x86_64-linux-gnu/tls/x86_64", 0x7fffb04bd280) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/tls/libz.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/lib/x86_64-linux-gnu/tls", 0x7fffb04bd280) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/x86_64/libz.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/lib/x86_64-linux-gnu/x86_64", 0x7fffb04bd280) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libz.so.1", O_RDONLY) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\340#\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=92752, ...}) = 0
mmap(NULL, 2187792, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fa16d448000
mprotect(0x7fa16d45e000, 2093056, PROT_NONE) = 0
mmap(0x7fa16d65d000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x15000) = 0x7fa16d65d000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libjli.so", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/tls/x86_64/libjli.so", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/usr/lib/x86_64-linux-gnu/tls/x86_64", 0x7fffb04bd250) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/tls/libjli.so", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/usr/lib/x86_64-linux-gnu/tls", 0x7fffb04bd250) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/x86_64/libjli.so", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/usr/lib/x86_64-linux-gnu/x86_64", 0x7fffb04bd250) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/libjli.so", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/usr/lib/x86_64-linux-gnu", {st_mode=S_IFDIR|0755, st_size=36864, ...}) = 0
open("/lib/tls/x86_64/libjli.so", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/lib/tls/x86_64", 0x7fffb04bd250) = -1 ENOENT (No such file or directory)
open("/lib/tls/libjli.so", O_RDONLY)    = -1 ENOENT (No such file or directory)
stat("/lib/tls", 0x7fffb04bd250)        = -1 ENOENT (No such file or directory)
open("/lib/x86_64/libjli.so", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/lib/x86_64", 0x7fffb04bd250)     = -1 ENOENT (No such file or directory)
open("/lib/libjli.so", O_RDONLY)        = -1 ENOENT (No such file or directory)
stat("/lib", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
open("/usr/lib/tls/x86_64/libjli.so", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/usr/lib/tls/x86_64", 0x7fffb04bd250) = -1 ENOENT (No such file or directory)
open("/usr/lib/tls/libjli.so", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/usr/lib/tls", 0x7fffb04bd250)    = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64/libjli.so", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/usr/lib/x86_64", 0x7fffb04bd250) = -1 ENOENT (No such file or directory)
open("/usr/lib/libjli.so", O_RDONLY)    = -1 ENOENT (No such file or directory)
stat("/usr/lib", {st_mode=S_IFDIR|0755, st_size=20480, ...}) = 0
writev(2, [{"jdk-14.0.1/bin/java", 19}, {": ", 2}, {"error while loading shared libra"..., 36},
{": ", 2}, {"libjli.so", 9}, {": ", 2}, {"cannot open shared object file", 30}, {": ", 2},
{"No such file or directory", 25}, {"\n", 1}], 10jdk-14.0.1/bin/java: error while loading shared
libraries: libjli.so: cannot open shared object file: No such file or directory
) = 128
exit_group(127)                         = ?

顯然,java 在我沒有寫入權限的地方搜尋 libjli.so 共享庫文件。

Google搜尋,我發現了許多類似的問題,但無法使用提供的任何提示,因為它們需要 root 訪問權限。但是,我不相信沒有 root 訪問權限是問題的核心,因為在我的家庭 linux 機器上解壓縮相同的 tarball 可以毫無問題地執行相同的 java 二進製文件,而不是使用 root 權限。因此,我假設伺服器失去還有其他一些先決條件。

在伺服器上,執行uname -ayield Linux [...] 3.2.0-6-amd64 #1 SMP Debian 3.2.102-1 x86_64 GNU/Linux,這對我來說似乎並不奇怪。

當然,我將非常感謝任何幫助,並很樂意提供更多資訊。提前致謝。

首先,libjli.so庫應該在lib目錄而不是bin目錄中。根據您擁有它的方式,它應該位於以下兩個位置之一

jdk-14.0.1/lib/
jdk-14.0.1/jli/

然後,您需要使用 PATH 和 JAVA_HOME 將它們的位置添加到您的環境中。將這些行添加到您的 .bashrc 並開始一個新的 shell 會話:

export PATH=/home/presencia/jdk-14.0.1/bin:$PATH

export LD_LIBRARY_PATH=/home/presencia/jdk-14.0.1/lib:$LD_LIBRARY_PATH

export JAVA_HOME=/home/presencia/jdk-14.0.1

引用自:https://unix.stackexchange.com/questions/581158