使用VNC Server连接Linux图形界面

 

说明:本文资料部分来自网络同仁文章,特此感谢。

 

对于目前的企业应用操作系统而言,Unix和Linux应该是占到主流地位。无论是管理员还是开发人员,都已能操作一手流利的字符命令行“为荣”。虽然经过若干年的改进优化,Linux GUI图形界面无论是操作性上还是运行效率上,都有了很大进步,但是字符命令行界面操作方式,依然是服务器的主流。

 

但是,很多时候,我们又不能避免使用GUI界面。比如在安装Oracle的时候,如果不使用图形界面,就只能使用slient模式配合response file,配置复杂而且很不方便。这个时候,有一个图形界面还是很方便的。

 

和桌面PC不同,我们访问服务器一般都是通过命令行远程登录连接,如ssh协议等,直接图形桌面只能到“高辐射”的机房去使用。怎么样能够在远程使用到Linux的GUI界面?

 

比较常见的是两个方案,XWindows软件和VNC Server远程联入。XWindows产品的典型代表是XManager,这个软件套件中包括了很多系统运维人员常用的远程登录和FTP工具。最重要的软件是其中的Passive模式,启动该模式之后,配合DISPLAY环境变量,就可以接受远程Unix/Linux传入的图形信息。VNC Server是另一种轻量级的解决方案,相对于XManager收费软件,VNC Server是一种不错的选择。

 

本文主要介绍一下在Oracle安装过程中VNC Server的配置过程。

 

1、VNC Server基本配置

 

VNC Server是Linux一个后台服务项目,当前的Linux版本很多时候都是默认安装这个服务的。我们可以通过rpm –qa进行检查。

 

 

[root@bspdev ~]# rpm -qa vnc

vnc-4.1.2-14.el5_6.6

 

 

如果没有查到这个结果,说明vnc没有安装上。可以从Linux安装盘上找到对应的rpm包,使用rpm –ivh命令安装。

 

在确定安装之后,可以针对一个特定的用户(当前用户)远程联入时候的桌面,我们称为“桌面”。

 

 

[root@bspdev ~]# vncserver :1

 

You will require a password to access your desktops.

 

Password:

Verify:

 

New 'bspdev.localdomain:1 (root)' desktop is bspdev.localdomain:1

 

Creating default startup script. /root/.vnc/xstartup

Starting applications specified in /root/.vnc/xstartup

Log file is /root/.vnc/bspdev.localdomain:1.log

 

 

密码部分,要对这个用户(root)使用vncserver联入的时候设置一个密码。联入过程中的一些参数,都在/root/.vnc/xstartup文件中进行配置。

 

启动之后,我们可以在后台看到vncserver启动的进程信息。

 

 

[root@bspdev ~]# ps -ef | grep vnc

root      3282     1  0 05:46 pts/0    00:00:00 Xvnc :1 -desktop bspdev.localdomain:1 (root) -httpd /usr/share/vnc/classes -auth /root/.Xauthority -geometry 1024x768 -depth 16 -rfbwait 30000 -rfbauth /root/.vnc/passwd -rfbport 5901 -pn

root      3291     1  0 05:46 pts/0    00:00:00 vncconfig -iconic

root      3318  3244  0 05:47 pts/0    00:00:00 grep vnc

 

 

vncserver也是在主机host的特定端口进行等待联入。一个VNC Server能够开启多个桌面,分别使用:1,:2来表示。每个桌面对应不同的端口。

 

客户端连接的时候,VNC Server可以支持两种类型的客户端。一种是Windows的客户端,通常是绿色软件。另一种是基于Web浏览器的Java客户端。

 

在联入的时候,要注意端口的使用。VNC使用TCP端口从5900开始,桌面1对应5901端口,桌面2对应5902端口,依次排序。

 

如果使用Java Web浏览器的方式,端口则是从5800开始。

 

如果我们使用Windows客户端连接,使用地址:进行访问。例如:192.168.0.88:1。

 

2、防火墙配置

 

如果我们的Linux是开启了网络防火墙,则需要将指定端口打开。

 

 

[root@testdb ~]# iptables -I INPUT -p tcp --dport 5901 -j ACCEPT

[root@testdb ~]# iptables -I INPUT -p tcp --dport 5801 -j ACCEPT

 

 

3、桌面客户端配置

 

默认我们使用vnc server客户端开启的时候,会发现提供的桌面很简单,基本和白黑桌面没有很大区别。这是因为VNC Server默认开启的是TWM简单界面。如果我们希望看到色彩丰富的KDE和GNOME,则需要修改配置脚本。

 

 

[root@bspdev ~]# vi /root/.vnc/xstartup

 

#!/bin/sh

 

# Uncomment the following two lines for normal desktop:

# unset SESSION_MANAGER

# exec /etc/X11/xinit/xinitrc

 

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup

[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources

xsetroot -solid grey

vncconfig -iconic &

xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &

twm &

 

 

我们需要修改的是最后一行TWM &,如果需要使用KDE,就替换为startkde &。如果需要使用GNOME环境,就替换为gnome-session &。

 

修改结果如下:

 

 

vncconfig -iconic &

xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &

gnome-session &

 

 

此时配置内容不会立即生效,需要重新启动vncserver服务项。

 

--中断桌面:1的连接

[root@bspdev ~]# vncserver -kill :1

Killing Xvnc process ID 3282

--重新启动

[root@bspdev ~]# vncserver :1

 

New 'bspdev.localdomain:1 (root)' desktop is bspdev.localdomain:1

 

Starting applications specified in /root/.vnc/xstartup

Log file is /root/.vnc/bspdev.localdomain:1.log

 

 

4、桌面分辨率设置

 

很多软件在安装的时候,要求达到一定程度的桌面分辨率。在配置vncserver的时候,我们也需要进行配置。

 

修改vncservers参数配置信息。

 

 

[root@bspdev ~]# vi /etc/sysconfig/vncservers

 

# The VNCSERVERS variable is a list of display:user pairs.

#

# Uncomment the lines below to start a VNC server on display :2

# as my 'myusername' (adjust this to your own).  You will also

# need to set a VNC password; run 'man vncpasswd' to see how

# to do that.

#

# DO NOT RUN THIS SERVICE if your local area network is

# untrusted!  For a secure way of using VNC, see

# .

 

# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.

 

# Use "-nohttpd" to prevent web-based VNC clients connecting.

 

# Use "-localhost" to prevent remote VNC clients connecting except when

# doing so through a secure tunnel.  See the "-via" option in the

# `man vncviewer' manual page.

 

# VNCSERVERS="2:myusername"

# VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -nohttpd -localhost"

VNCSERVERS="1:root"

VNCSERVERARGS[1]="-geometry 1024x768"

 

 

配置vncservers和vncserverargs两个参数,可以给桌面:1配置分辨率。

 

再重新启动服务。

 

 

[root@bspdev ~]# /etc/init.d/vncserver restart

Shutting down VNC server: 1:root [  OK  ]

Starting VNC server: 1:root

New 'bspdev.localdomain:1 (root)' desktop is bspdev.localdomain:1

 

Starting applications specified in /root/.vnc/xstartup

Log file is /root/.vnc/bspdev.localdomain:1.log

 

[  OK  ]

 

 

5、xhost设置

 

经过上面的配置,一般情况下我们是可以在vncserver客户端上面开启各种界面。很多时候,还需要进行一些xhost配置。如下图所示:

 

17203031_201309092340511.jpg

 

6、结论

 

相对于Xmanager,VNCServer配置相对简单,而且客户端使用限制比较少。更重要的是,使用VNCServer对网络的要求比较低。当我们在安装软件的时候,难免出现网络中断的情况。如果使用Xmanager,则必然会使连接报错中断。但是如果使用VNCServer,只是客户端关闭,再次连接的时候,桌面状态是保存的,可以继续进行操作。

fj.png无标题.jpg

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/17203031/viewspace-772442/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/17203031/viewspace-772442/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值