在CentOS系统安装的时候,我们应该对VNC做好配置,所以,在这里,我们来简单的学习一下如何在CentOS系统中进行VNC配置。

1.检查VNC客户端和服务器端是否已经安装

执行如下命令:

rpm-qvncvnc-server

假如返回类似如下信息,

packagevncisnotinstalled

vnc-server-4.0-8.1

则说明系统已经默认安装了vnc服务器端(一般来说,CentOS系统都默认安装了vncserver)。

2.在CentOS系统中将用户名加入到配置文件中

使用如下命令编辑配置文件,添加帐户信息:

vi/etc/sysconfig/vncservers

做如下修改

##UncommentthelinebelowtostartaVNCserverondisplay:1#asmy'myusername'(adjustthistoyourown).Youwillalso#needtosetaVNCpassword;run'manvncpasswd'toseehow#todothat.##DONOTRUNTHISSERVICEifyourlocalareanetworkis#untrusted!ForasecurewayofusingVNC,see#lt;URL:http://www.uk.research.att.com/vnc/sshvnc.htmlamp;gt;.#VNCSERVERS="1:myusername"#VNCSERVERS="1:gavin2:john"#usethemethodformoreuserVNCSERVERS="2:root"#VNCSERVERARGS[1]="-geometry800x600"VNCSERVERARGS[2]="-geometry1024x768"3.设置root用户的密码

使用如下命令设置密码:vncpasswd

当提示Verify时,再次输入密码确认。

4.启动VNC服务

使用如下命令启动VNCSERVER

sbin/servicevncserverstart

当显示如下信息时,表示启动成功:

StartingVNCserver:2:root [OK]

5.修改VNCSERVER的窗口治理器

vncserver默认使用的窗口治理器是twn,这是一个非常简单的窗口治理器,我们可以改成常用的GNOME或者KDE。

先使用如下命令进入用户的home目录:cd"/.vnc

编辑启动项:vixstartup

按照如下方式修改启动项:#!/bin/sh

#Uncommentthefollowingtwolinesfornormaldesktop:unsetSESSION_MANAGERexec/etc/X11/xinit/xinitrc[-x/etc/vnc/xstartup]&exec/etc/vnc/xstartup[-r$HOME/.Xresources]&xrdb$HOME/.Xresourcesxsetroot-solidgreyvncconfig-iconicxterm-geometry80x241010-ls-title"$VNCDESKTOPDesktop"gnome-session#以GNOME作为VNC的窗口治理器#startkde#kdedesktop#twm#注掉CentOS系统默认的窗口治理器

6.重启VNCSERVER

/sbin/servicevncserverrestart

当CentOS系统提示如下信息时,表示重启成功:

ShuttingdownVNCserver:2:root[OK]

StartingVNCserver:2:root[OK] 

7、从VNCview登录

在windows上安装vncview,然后输入xxx.xxx.xxx.xxx:2,连接登录,输入密码即可。备注:假如从vncview登录时,提示connectionrefused(10061),则是因为linux防火墙的问题,登录centos系统,选择SystemPreferencesRemoteDesktop,勾选sharing中的两项,Security两项不勾,点击关闭,然后再重新用vncview登录即可。