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
# <URL:http://www.uk.research.att.com/archive/vnc/sshvnc.html>.
# 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配置。如下图所示:

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