iis服务器助手广告广告
返回顶部
首页 > 资讯 > 服务器 >0404---通过SSH连接远程服务器运行图形界面程序问题
  • 255
分享到

0404---通过SSH连接远程服务器运行图形界面程序问题

服务器sshlinuxwindows 2023-08-30 11:08:55 255人浏览 八月长安
摘要

远程运行 linux 服务器图形界面程序问题 ​ 通常部署在数据中心机房中的服务器是没有图形桌面的,对服务器的日常运维也往往通过远程客户端命令窗口来进行,但有时候往往需要在服务器上远程安装或运行图形窗口类软件,图形窗口的本地显示往往困扰很多

远程运行 linux 服务器图形界面程序问题

​ 通常部署在数据中心机房中的服务器是没有图形桌面的,对服务器的日常运维也往往通过远程客户端命令窗口来进行,但有时候往往需要在服务器上远程安装或运行图形窗口类软件,图形窗口的本地显示往往困扰很多人,譬如在远程安装 oracle数据库系统的时候,因安装系统需要图形窗口支持,就必须实现图形窗口在用户工作计算机上显示。本文详细讨论几种常用的方法,并给出最佳实践。

​ 如果服务端安装了图形桌面,还可通过在服务端安装 tigervnc-server,在客户端安装 tightvnc viewer 来实现远程操作服务器,本文对此不做详细讨论。

一 服务器端环境准备

1 安装必要的组件

服务器的操作系统Centos7

# 安装 X 系统组件yum install xorg-x11-xauth xorg-x11-apps# 如果显示乱码。可以在用户家目录下的环境配置文件中加入如下内容vim .bash_profile#文件最后加入export LANG=C

2 设置 sshd_config

vim  /etc/ssh/sshd_config# 设置X11Forwarding yes#将X11UseLocalhost去掉注释改为noX11UseLocalhost no

二 客户端工具准备

1 Xshell

打开连接的属性,设置X11 转移
在这里插入图片描述

2 Mobaxterm

MobaXterm ssh 客户端软件,自带 X server 服务器,可直接使用。有关设置,参见下图。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

三 实现方法

下面以 mobaXterm 为例进行说明

1 在公司局域网络环境下,工作电脑和服务器之间通过IP地址可以相互访问

  1. ip 地址
# server IP 10.31.100.107#个人工作电脑10.31.122.199
  1. 操作和测试过程
[root@orc19c ~]# xclock#时钟显示正常[root@orc19c ~]# echo $DISPLAY#输出结果localhost:10.0切换到其它用户su - oracle[oracle@orc19c ~]$ echo $DISPLAY# 输出为空#把DISPLAY环境变量设置为 root下的值[oracle@orc19c ~]$ export DISPLAY=localhost:10.0[oracle@orc19c ~]$ xclock#显示结果MoTTY X11 proxy: Authorisation not recognised# MoTTY X11 代理:不认识的授权# 因有独立的IP,把DISPLAY设置为工作电脑的IP,一切OK[oracle@orc19c ~]$ export DISPLAY=10.31.122.199:0.0[oracle@orc19c ~]$ xclock#时钟显示正常
  1. 鼠标点击 MobaXterm 的 Xserver 图标,可以观察 处于侦听状态的 DISPLAY列表。
    在这里插入图片描述

2 针对家庭网络连接公司的server,因没有直通的IP地址,设置与操作步骤如下

[root@orc19c ~]# xclock# X 图形窗口显示正常#直接切换用户[root@orc19c ~]# su - oracle[oracle@orc19c ~]$ xclockError: Can't open display:[oracle@orc19c ~]$ echo $DISPLAY# DISPLAY环境变量为空# 切回root[oracle@orc19c ~]$ exit#查看 root环境下的DISPLAY环境变量[root@orc19c ~]# echo $DISPLAY10.31.100.107:10.0# 载切回 oracle用户,并设置和root环境相同的 DISPLAY[root@orc19c ~]# su - oracle[oracle@orc19c ~]$ export DISPLAY=10.31.100.107:10.0# 运行 xclock[oracle@orc19c ~]$ xclock#显示信息# MoTTY X11 proxy: Authorisation not recognised# MoTTY X11 代理:不认识的授权# 切回root,查找 xauth授权信息root@orc19c ~]# xauth list $DISPLAYorc19c:10  MIT-MAGIC-COOKIE-1  9f793a8b51f502a3a3c3359055d13556#切回 oracle,增加xauth授权[root@orc19c ~]# su - oracleLast login: Tue Apr  4 10:44:58 CST 2023 on pts/0[oracle@orc19c ~]$ xauth add orc19c:10  MIT-MAGIC-COOKIE-1  9f793a8b51f502a3a3c3359055d13556#设置 DISPLAY环境变量[oracle@orc19c ~]$ export DISPLAY=10.31.100.107:10.0[oracle@orc19c ~]$ xclock#xclock运行正常

四 最佳实践

1 显示器的编号从10开始,这是由 sshd_config 配置文件确定的

[root@orc19c ~]# vim /etc/ssh/sshd_config....#GatewayPorts noX11Forwarding yes#X11DisplayOffset 10#X11UseLocalhost yesX11UseLocalhost no.....

2 如果同时打开多个ssh客户端窗口, 每打开一个连接终端 Display号 增加1

#terminal 1DISPLAY=10.31.100.107:10.0#terminal 2DISPLAY=10.31.100.107:11.0#terminal 3DISPLAY=10.31.100.107:12.0....

3 打开新的连接终端,xclock都能运行正常

无论是在 公司环境或是在家工作环境,如果条件允许(有充分的权限),利用SSH工具可以同时打开两个客户端窗口,一个以 root登录,可以随时进行系统的设定,另一个以其它用户进行登录进行软件操作,避免了来回切换带来的图形窗口显示的麻烦。

五 补充资料

The display part is also used on X over SSH. Every new SSH connection with X forwarding enabled is assigned a different display, because these screens correspond internally to a tcp port number offset, e.g. DISPLAY=localhost:10.0 will cause the client to direct graphical output to host localhost port 6010. This is required for SSH X forwarding, because if you have multiple connections to the same computer, your program must send different outputs to different ports so that the SSH server can forward the X output to the proper destination.

DISPLAY=:0 will use a unix domain Socket, DISPLAY=localhost:0 will use a internet domain socket (IP).

When you connect to a remote by ssh -X this automatically sets up a reverse channel, over the same connection, to your originating display. It uses the first free port starting from 6010 and initialises DISPLAY to this minus 6000. If you are getting localhost:11.0 then probably someone else has already connected and taken that port, so you get the next one. You would have to kill them and reconnect to get 10.

2023-04-04
tting localhost:11.0 then probably someone else has already connected and taken that port, so you get the next one. You would have to kill them and reconnect to get 10.

2023-04-04

来源地址:https://blog.csdn.net/gmriwyf/article/details/129958946

--结束END--

本文标题: 0404---通过SSH连接远程服务器运行图形界面程序问题

本文链接: https://www.lsjlt.com/news/382816.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作