首页 星云 工具 资源 星选 资讯 热门工具
:

PDF转图片 完全免费 小红书视频下载 无水印 抖音视频下载 无水印 数字星空

彻底理解Linux的DISPLAY变量的作用

编程知识
2024年07月19日 14:48

背景

最近遇到个两年前遇到的问题,使用virt-manager提示(virt-manager:873): Gtk-WARNING **: 14:53:28.147: cannot open display: :1,当时专门运维的同事帮忙临时调了下DISPLAY变量,好像是将:1改成了SSH用户本地IP:10.0,当时的确好了,用完就关了再没用到,也没深究原因,那个运维同事也不大理解(网上查到的解决办法)。然而最近在做资产盘点,领导让我把我挂名管理的服务器作置换申请,需要知道虚拟机的信息,赶上盘到两年前有问题的机器上,又出现同样的问题,经过查找了资料找到了个几乎万无一失的理解,记一记。

DISPLAY变量是啥

首先,它是Linux X11 server(显示服务)用到的一个环境变量,用来指示你的显示(也可以包含键盘和鼠标)指向的显示服务地址,通常桌面PC该值会被设为:0.0

其次,它的格式有三部分: [主机名]:显示服务端口号-6000.显示器编号

  • [主机名] :一般是可以省略的,可以不写,也可以写成$HOSTNAME变量表示的主机名 或 localhost
  • 显示服务端口号-6000:意思是sshd服务的X11Forwarding占用端口减去6000的值
  • 显示器编号:一般都是0,表示第一个显示器

如何正确设置DISPLAY变量

分两种情况:

  • Linux桌面系统:直接设置:0.0
  • SSH连接的Linux服务器:需要按照格式进行检查。

检查步骤如下:

[root@hz ~]# netstat -anpt |grep sshd |grep LISTEN |grep 60
tcp   0  0 127.0.0.1:6010  0.0.0.0:*  LISTEN   30346/sshd: root@pt
tcp6  0  0 ::1:6010        :::*       LISTEN   30346/sshd: root@pt

找到60开头的sshd端口,这时是6010,减去6000是10,SSH只写第一显示器编号

则我的DISPLAY变量可设为 :10.0 或者 hz:10.0

附:参考

The magic word in the X window system is DISPLAY. A display consists (simplified) of:

  • a keyboard,
  • a mouse
  • and a screen.

A display is managed by a server program, known as an X server. The server serves displaying capabilities to other programs that connect to it.

The remote server knows where it has to redirect the X network traffic via the definition of the DISPLAY environment variable which generally points to an X Display server located on your local computer.

The value of the display environment variable is:

hostname:D.S

where:

hostname is the name of the computer where the X server runs. An omitted hostname means the localhost.

D is a sequence number (usually 0). It can be varied if there are multiple displays connected to one computer.

S is the screen number. A display can actually have multiple screens. Usually, there's only one screen though where 0 is the default.

Example of values

localhost:4
google.com:0
:0.0

hostname:D.S means screen S on display D of host hostname; the X server for this display is listening at TCP port 6000+D.

host/unix:D.S means screen S on display D of host host; the X server for this display is listening at UNIX domain socket /tmp/.X11-unix/XD (so it's only reachable from host).

:D.S is equivalent to host/unix:D.S, where host is the local hostname.

:0.0 means that we are talking about the first screen attached to your first display in your local host

Read more here: support.objectplanet.com and here: superuser.com and here: docstore.mik.ua.

From a X(7) man page:

From the user's perspective, every X server has a display name of the form:

hostname:displaynumber.screennumber

This information is used by the application to determine how it should connect to the server and which screen it should use by default (on displays with multiple monitors):

hostname The hostname specifies the name of the machine to which the display is physically connected. If the hostname is not given, the most efficient way of communicating to a server on the same machine will be used. displaynumber The phrase "display" is usually used to refer to a collection of monitors that share a common keyboard and pointer (mouse, tablet, etc.). Most workstations tend to only have one keyboard, and therefore, only one display. Larger, multi-user systems, however, frequently have several displays so that more than one person can be doing graphics work at once. To avoid confusion, each display on a machine is assigned a display number (beginning at 0) when the X server for that display is started. The display number must always be given in a display name. screennumber Some displays share a single keyboard and pointer among two or more monitors. Since each monitor has its own set of windows, each screen is assigned a screen number (beginning at 0) when the X server for that display is started. If the screen number is not given, screen 0 will be used.

From:https://www.cnblogs.com/hellxz/p/18311622
本文地址: http://www.shuzixingkong.net/article/194
0评论
提交 加载更多评论
其他文章 JuiceFS 直连 NFS 新功能介绍,赋能 NAS 进行 AI 训练
NAS 通过提供多用户网络数据存取服务,极大地简化了数据共享和管理。而 NFS 作为实现这种共享的一种主流协议,尽管广泛应用,但在处理复杂的 AI 训练场景时常常受限于其性能和一致性问题。 JuiceFS 在最新的1.2版本中增加了直连 NFS 功能,这一创新允许 JuiceFS 直接利用 NAS
论如何直接用EF Core实现创建更新时间、用户审计,自动化乐观并发、软删除和树形查询(下)
前言 数据库并发,数据审计和软删除一直是数据持久化方面的经典问题。早些时候,这些工作需要手写复杂的SQL或者通过存储过程和触发器实现。手写复杂SQL对软件可维护性构成了相当大的挑战,随着SQL字数的变多,用到的嵌套和复杂语法增加,可读性和可维护性的难度是几何级暴涨。因此如何在实现功能的同时控制这些S
论如何直接用EF Core实现创建更新时间、用户审计,自动化乐观并发、软删除和树形查询(下) 论如何直接用EF Core实现创建更新时间、用户审计,自动化乐观并发、软删除和树形查询(下)
云仿真技术与云仿真平台特点分析
云计算和仿真技术的不断发展,使云仿真平台成为处理大规模仿真任务的重要工具.通过结合云计算和仿真技术,云仿真平台能够提供可扩展性、虚拟化、网络协作、弹性计算和数据管理等特征,为用户带来更高效、灵活和精确的虚拟仿真体验,本文,将介绍云仿真的基本概念和云仿真平台的特征.
云仿真技术与云仿真平台特点分析 云仿真技术与云仿真平台特点分析 云仿真技术与云仿真平台特点分析
.NET单元测试使用AutoFixture按需填充属性的几种方式,以及最佳实践
AutoFixture是一个.NET库,旨在简化单元测试中的数据设置过程。通过自动生成测试数据,它帮助开发者减少测试代码的编写量,使得单元测试更加简洁、易读和易维护。AutoFixture可以用于任何.NET测试框架,如xUnit、NUnit或MSTest。 默认情况下AutoFixture生成的字
【VMware VCF】VMware Cloud Foundation Part 02:部署 Cloud Builder。
VMware Cloud Builder 是用于构建 VMware Cloud Foundation 第一个管理域的自动化部署工具,通过将一个预定义信息的 Excel 参数表导入到 Cloud Builder 以启动 VCF 的初始构建过程(Bring-up)。VMware Cloud Builde
【VMware VCF】VMware Cloud Foundation Part 02:部署 Cloud Builder。 【VMware VCF】VMware Cloud Foundation Part 02:部署 Cloud Builder。 【VMware VCF】VMware Cloud Foundation Part 02:部署 Cloud Builder。
诞生记(一)——上线一个小程序最低要花多少钱?
我是一个很懒的人,很少写博客。为什么?因为技术发展太快了,刚学习记录下来过段时间来看看,发现全都过时了。太浪费感情了。 曾经我也是一个软粉,一个.Net开发者,同学都入坑Android、Java踩着时代的红利拿高薪的时候。我却始终爱着微软。一直到微软彻底抛弃Windows Phone10的时候我才死
诞生记(一)——上线一个小程序最低要花多少钱? 诞生记(一)——上线一个小程序最低要花多少钱?
开源!开源一个flutter实现的古诗拼图游戏
去年(2023年)年底我初学flutter,看了一些文档和教程,想找个东西来练练手。 小时候看过一个关于历史名人儿时事迹的短片,有一集是讲周总理的,有一个细节我记得很清楚:幼年周恩来经常要做一个游戏--有一堆纸片,每片纸上一个字,他要一个一个字拼起来拼成一首诗。 很多年前我就想,或许可以把这个游戏做
开源!开源一个flutter实现的古诗拼图游戏 开源!开源一个flutter实现的古诗拼图游戏 开源!开源一个flutter实现的古诗拼图游戏
bitwarden本地搭建(无需购买SSL证书)
bitwarden本地搭建(无需购买SSL证书) 在安装之前,笔者在这里先声明一下,我安装bitwarden使用的操作环境为ArchLinux,我的想法是,因为这只是一个“密码本”,并且最好能保证其能够在开机后占用尽量少的内存让密码本保持稳定运行。在此前提下,我选择了干净整洁的ArchLinux,关
bitwarden本地搭建(无需购买SSL证书) bitwarden本地搭建(无需购买SSL证书) bitwarden本地搭建(无需购买SSL证书)