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

 

参考至: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

本文原创,转载请注明出处、作者

如有错误,欢迎指正

邮箱:czmcj@163.com

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

时间: 2024-08-01 11:17:44

DISPLAY变量和xhost(原创)的相关文章

smarty简单模板变量输出方法[原创]_php实例

本文简单讲述了Smarty的模板变量输出方法.分享给大家供大家参考,具体如下: config.inc.php配置文件如下: include_once('smarty/Smarty.class.php'); $smarty=new Smarty(); $smarty->config_dir="smarty/Config_File.class.php"; $smarty->caching=false; //是否开启缓存 $smarty->template_dir=&quo

smarty简单模板变量输出方法 原创

本文简单讲述了Smarty的模板变量输出方法.分享给大家供大家参考,具体如下: config.inc.php配置文件如下: include_once('smarty/Smarty.class.php'); $smarty=new Smarty(); $smarty->config_dir="smarty/Config_File.class.php"; $smarty->caching=false; //是否开启缓存 $smarty->template_dir=&quo

xhost和XServer相关概念汇总

1.xhost 控制什么人可以访问当前主机上的增强 X-Windows.语法:xhost [ + | - ] [ Name ] 2.xhost 是用来控制X server访问权限的.通常当你从hostA登陆到hostB上运行hostB上的应用程序时,做为应用程序来说,hostA是client,但是对图形来说,是在hostA上显示的,需要使用hostA的Xserver,所以hostA是server.因此在登陆到hostB前,需要在hostA上运行xhost +来使其它用户能够访问hostA的Xse

xhost命令介绍+0.1/1.0(引)

在ixpub上看到很多朋友遇到关于xhost命令的问题,例如报错:xhostunabletoopendisplay 很多没有得到很好哦解决,其实这个命令的使用很简单,只要熟悉了命令的使用,就不会有这么多问题了,下面先说说这个命令的使用,然后结合问题,说说遇到这类问题的解决办法. xhost命令 用途 控制什么人可以访问当前主机上的增强 X-Windows. 语法xhost[  + |  - ] [Name ] 描述xhost命令添加或删除 X 服务器接受连接的机器列表上的主机名. 该命令必须从有

xhost命令

xhost 命令 用途  控制什么人可以访问当前主机上的增强 X-Windows.语法  xhost [ + | - ] [ Name ] "+"表示增加,"-"表示去除描述  xhost 是用来控制X server访问权限的. 通常当你从hostA登陆到hostB上运行hostB上的应用程序时,做为应用程序来说,hostA是client,但是对图形来说,是在hostA上显示的,需要使用hostA的Xserver,所以hostA是server.因此在登陆到hostB

Linux下Oracle安装配置宝典

    Oracle的安装包括企业版服务器端和客户端两部分,用户可以根据实际情况选择不同的部分安装.    这里以企业版服务器端为主要介绍对象,客户端的安装方法相对要简单一些.    服务器端安装分为:典型安装.最小安装和定制安装三种.    客户端安装分为:管理员客户端.程序员客户端.应用用户客户端.定制安装客户端.    ■系统需求    1.硬件需求    ● 内存最低配置为128MB,建议使用256MB;    ● 硬盘交换分区至少是400MB或者是内存的二倍以上也可以:  

xdpyinfo-linux6.5上安装oracleq11gDISPLAY要怎么设置

问题描述 linux6.5上安装oracleq11gDISPLAY要怎么设置 linux6.5上安装oracle11g,DISPLAY要怎么设置.我设置了export DISPLAY=:0.0,为什么xhot,xclock,xdpyinfo命令都报错说,不能打开display.我觉得所有问题都是这个DISPLAY出了问题.有关DISPLAY的都报错.有谁知道怎么设置,求告知. 解决方案 如何设置DISPLAY变量,正确运行Oracle程序的问题http://zhidao.baidu.com/li

CentOS 6.5下安装Oracle 10g

一.硬件要求 1.内存 & swa Minimum: 1 GB of RAM  Recommended: 2 GB of RAM or more 检查内存情况 # grep MemTotal /proc/meminfo 注意大小写 # grep SwapTotal /proc/meminfo 注意大小写 2.硬盘 由于CentOS安装后差不多有4~5G,再加上Oracle等等的安装,所以请准备至少10G的硬盘空间. 检查磁盘情况 # df -h 二.软件 系统平台:CentOS 6.3(x32)

Linux下安装Oracle(CentOS-Oracle 12c)的方法_Linux

第一步:网络连接,在我的上一篇博客中有介绍,不再多说. 网络连接的目的:为了能使用yum命令,在网上直接下载文件. 第二步:前往oracle官网下载12c database服务器端的两个文件:(安装在Linux) linuxamd64_12102_database_1of2.zip linuxamd64_12102_database_2of2.zip 将这两个文件放在Linux的tmp目录下,使用 unzip 命令来解压. database的client的一个文件:(安装在Windows) 32