天天看點

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, <code>ip_address/hostname</code>is 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

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 &amp;&amp; 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

參考至:http://blog.csdn.net/jlds123/article/details/6834287

http://blog.csdn.net/dysh61301601/article/details/3208326

http://blog.sina.com.cn/s/blog_73582d750100ppto.html

本文原創,轉載請注明出處、作者

如有錯誤,歡迎指正

郵箱:[email protected]

作者:czmmiao  文章出處:http://czmmiao.iteye.com/blog/2141131

繼續閱讀