DISPLAY變量和xhost(原創)


DISPLAY

在Linux/Unix類操作系統上, DISPLAY用來設置將圖形顯示到何處. 直接登陸圖形界面或者登陸命令行界面后使用startx啟動圖形, DISPLAY環境變量將自動設置為:0:0, 此時可以打開終端, 輸出圖形程序的名稱(比如xclock)來啟動程序, 圖形將顯示在本地窗口上, 在終端上輸入printenv查看當前環境變量, 輸出結果中有如下內容:
DISPLAY=:0.0
使用xdpyinfo可以查看到當前顯示的更詳細的信息.
DISPLAY 環境變量格式如下hostname: displaynumber.screennumber,我們需要知道,在某些機器上,可能有多個顯示設備共享使用同一套輸入設備,例如在一台PC上連接兩台CRT顯示器,但是它們只共享使用一個鍵盤和一個鼠標。這一組顯示設備就擁有一個共同的displaynumber,而這組顯示設備中的每個單獨的設備則擁有自己單獨的 screennumber。displaynumber和screennumber都是從零開始的數字。這樣,對於我們普通用戶來說, displaynumber、screennumber就都是0。 hostname指Xserver所在的主機主機名或者ip地址, 圖形將顯示在這一機器上, 可以是啟動了圖形界面的Linux/Unix機器, 也可以是安裝了Exceed, X-Deep/32等Windows平台運行的Xserver的Windows機器. 如果Host為空, 則表示Xserver運行於本機, 並且圖形程序(Xclient)使用unix socket方式連接到Xserver, 而不是TCP方式. 使用TCP方式連接時, displaynumber為連接的端口減去6000的值, 如果displaynumber為0, 則表示連接到6000端口; 使用unix socket方式連接時則表示連接的unix socket的路徑, 如果displaynumber為0, 則表示連接到/tmp/.X11-unix/X0 . screennumber則幾乎總是0.
如果使用su username或者su - username切換到別的用戶, 並且使用命令
export DISPLAY=:0.0
設置DISPLAY環境變量, 運行圖形程序(如xclock)時會收到如下錯誤:
Xlib: connection to ":0.0" refused by server
Xlib: No protocol specified
Error: Can't open display: :0.0
這是因為Xserver默認情況下不允許別的用戶的圖形程序的圖形顯示在當前屏幕上. 如果需要別的用戶的圖形顯示在當前屏幕上, 則應以當前登陸的用戶, 也就是切換身份前的用戶執行如下命令
xhost +

xhost 是用來控制X server訪問權限的,這個命令將允許別的用戶啟動的圖形程序將圖形顯示在當前屏幕上.。通常當你從hostA登陸到hostB上運行hostB上的應用程序時,做為應用程序來說,hostA是client,但是作為圖形來說,是在hostA上顯示的,需要使用hostA的Xserver,所以hostA是
server.因此在登陸到hostB前,需要在hostA上運行xhost +,來使其它用戶能夠訪問hostA的Xserver.
xhost + 是使所有用戶都能訪問Xserver.
xhost + ip使ip上的用戶能夠訪問Xserver.
xhost + nis:user@domain使domain上的nis用戶user能夠訪問
xhost + inet:user@domain使domain上的inet用戶能夠訪問。
在2台Linux機器之間, 如果設置服務器端配置文件/etc/ssh/sshd_config中包含
X11Forwarding no
客戶端配置文件/etc/ssh/ssh_config包含
ForwardX11 yes
則從客戶端ssh到服務器端后會自動設置DISPLAY環境變量, 允許在服務器端執行的圖形程序將圖形顯示在客戶端上. 在服務器上查看環境變量顯示如下(這個結果不同的時候並不相同)
DISPLAY=localhost:10.0
在客戶機上用netstat -lnp可以看到有程序監聽了6010端口
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 4827/1
如果希望允許遠程機器上的圖形程序將圖形顯示在本地機器的Xserver上, 除了要設置遠端機器的DISPLAY環境變量以外, 還需要設置本地機器的Xserver監聽相應的TCP端口. 而現在的Linux系統出於安全的考慮, 默認情況下不再監聽TCP端口. 可通過修改/etc/X11/xinit/xserverrc文件, 將
exec /usr/bin/X11/X -dpi 100 -nolisten tcp
修改為
exec /usr/bin/X11/X -dpi 100
允許在直接使用startx啟動圖形時啟動對TCP端口的監聽.
修改/etc/kde3/kdm/kdmrc, 將
ServerArgsLocal=-nolisten tcp
修改為
ServerArgsLocal=
允許kdm作為顯示管理器時, 啟動會話時監聽相應的TCP端口.
修改/etc/gdm/gdm.conf, 在[Security]一節增加
DisallowTCP=false
或者在登陸窗口選擇"Options" -> "Configure Login Manager..."的Security頁面, 取消"Deny TCP connections to Xserver", 允許gdm作為顯示管理器時, 啟動會話時監聽相應的TCP端口.

常見錯誤和解決方法

cause:
X-Windows emulation is not yet correctly configured or is being mis-used.
solution:
1.Make sure that "DISPLAY” is set properly as either:
     <ip address of the DBA desktop PC>:0.0
          or
     <hostname of the DBA desktop PC>:0.0
note:In this example, ip_address/hostnameis the host name or IP address of the system that you want to use to display Oracle Universal Installer (your workstation or PC).
eg.[root@rac1 ~]# xhost +
access control disabled, clients can connect from any host
[root@rac1 ~]# su - oracle
[oracle@rac1 ~]$ export DISPLAY=192.16.2.98:0.0
[oracle@rac1 ~]$ cd database/
[oracle@rac1 database]$ ./runInstaller
Starting Oracle Universal Installer... 
Checking installer requirements... 
Checking operating system version: must be redhat-3, SuSE-9, redhat-4, UnitedLinux-1.0, asianux-1 or asianux-2
                                      Passed 
All installer requirements met. 
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2009-03-05_03-36-28PM. Please wait ...[oracle@rac1 database]$ Oracle Universal Installer, Version 10.2.0.1.0 Production
Copyright (C) 1999, 2005, Oracle. All rights reserved.

2. Oracle Customer Support has seen instances where use of the UNIX/Linux “su” command, even “su - oracle” has caused this “Can't connect to X11 window server” error. Therefore, please be sure that you are LOGGED ON as the oracle account. Log directly into the install session. Do not use any variety of “su”.
     use oracle log on , not "su - oracle"
eg. [oracle@rac1 database]$ ./runInstaller

3.Oracle Customer Support has seen instances where the incorrect “ulimit” setting for number of files (aka “-n”, aka “nofiles”) has caused this “Can't connect to X11 window server” error. Therefore, please be sure that your values for “nofiles” in the output of “ulimit -a” is at least 65536.

備注:前2個辦法只需要滿足其中一個就可以避免這個錯誤了:直接用oracle登陸,不能su - oracle  or 設置display=ip_address_that you want to use to display Oracle Universal Installer:0.0

NO.35 xhost: unable to open display ""
以root用戶登錄
輸入命令xdpyinfo,記錄下里面的name of display:后的字符串,如 name of display:127.0.0.1:1.0
在執行xhost +命令(使得所有客戶都可以訪問)
返回信息為:
access control disabled,clients can connect from any host
如果xhost +不能執行,可以輸入命令export DISPLAY=:0執行一下
再執行xhost +
xhost + ip (name表示那個ip機器可以使用該服務)
2、以oracle用戶登錄
如果前面root登錄下執行xdpyinfo后的name of display:后的字符串是127.0.0.1:1.0
那么在該oracle用戶下執行一下export DISPLAY=:1.0
然后再執行xdpyinfo命令,如果能出現信息說明你已經成功了
這樣估計就可以解決linux下安裝oracle出現的xhost問題
如果還是不成功,請確認是否開啟了startx

XDMCP被禁用

啟用 XDMCP 紅帽 Linux 上

在 RHEL,默認情況下僅為本地主機啟用 X 11。你需要能夠連接從外部框中編輯文件/etc/gdm/custom.conf。RHEL 的默認設置是

DisallowTCP=yes
其中應改為"假"
要啟用 XDMCP 一些用戶需要你需要啟用它。
[xdmcp]
Enable=true
之后重新啟動 X 11 服務器使用命令
init 3 && init 5
如果另外您想要提供能力,以 root 用戶身份登錄,您需要安保科,如下所示
[security]
    DisallowTCP=false
    AllowRemoteRoot=true
如果啟用了防火牆,則您需要打開幾個端口
177 (UDP) 端口和端口 6000-6005 (TCP)
如果您正在使用 Gnome 打開 TCP 端口 16001 和 TCP 35091 在兩個方向。
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 16001 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 177 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 35091 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 6000:6005 -j ACCEPT


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM