Xlib: connection to ":0.0" refused by server
Xlib: No protocol specified
java.lang.NoClassDefFoundError
環境:Linux AS 4 (RHEL 4 系列)、Oracle 10g/11g、DBCA 圖形化創建數據庫。
DISPLAY 環境變量未正確設置**,或 **X Server 拒絕該用戶連接** (默認 xhost 僅允許本地登入用戶)。NoClassDefFoundError 多為 X 連接失敗導致 GUI 類無法加載的連帶錯誤。# 1. root 用戶執行
xhost +local: # 允許本地所有用戶連接 X Server (比 xhost + 更安全)
# 2. 切換到 oracle 用戶
su - oracle
export DISPLAY=:0.0
# 或 export DISPLAY=localhost:0.0
dbca
# 作為 oracle 用戶執行
xhost +local: # 若報錯 "unable to open display" 則需先 export DISPLAY
export DISPLAY=127.0.0.1:0.0
dbca
# 客戶端 (本地有 X Server, 如 Windows + VcXsrv / Xming, Linux/macOS 原生)
ssh -X oracle@server_ip # -X 啟用 X11 Forwarding
# 或 -Y (Trusted Forwarding, 繞過 SECURITY extension, 兼容性更好)
ssh -Y oracle@server_ip
# 服務端 /etc/ssh/sshd_config 需確保:
X11Forwarding yes
X11UseLocalhost no # 允許綁定非回環地址 (某些版本需要)
# 重啟 sshd
systemctl restart sshd
# 登入後自動設置 DISPLAY=localhost:10.0 (或 :10.0)
dbca # 圖形界面將透過 SSH 隧道顯示在本地
# 安裝 TigerVNC Server
dnf install tigervnc-server
# 配置 vncserver@:1.service, 啟動
systemctl enable --now vncserver@:1
# 連接 VNC Viewer 到 server_ip:5901
# VNC 會話中:
export DISPLAY=:1
dbca
xclock & # 能彈出時鐘窗口即 X 通暢
xeyes & # 眼睛跟隨鼠標移動
glxinfo | grep "OpenGL renderer" # 驗證 3D 加速 (可選)
# /home/oracle/.bash_profile
export DISPLAY=:0.0
# 或針對 SSH Forwarding 自動適配
if [ -z "$DISPLAY" ] && [ -n "$SSH_CONNECTION" ]; then
export DISPLAY=localhost:10.0
fi
Xlib connection refused = X Server 拒絕連接。核心解法:**授權 (xhost +local:) + 正確 DISPLAY 變量**。遠程管理首選 **SSH -X/-Y Forwarding**;無顯示器服務器用 **VNC/Xvfb**。配置永久寫入 .bash_profile,一次設置永久生效。