1、安装

yum install vnc*
2、启动
/etc/init.d/vncserver start
Starting VNC server: no displays configured                [  OK  ]
3、配置用户名
CODE:[root@localhost ~]#  vi /etc/sysconfig/vncservers
# The VNCSERVERS variable is a list of display:user pairs.
#
# Uncomment the line below to start a VNC server on display :1
# 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/vnc/sshvnc.html
                                                                                             
# VNCSERVERS="1:myusername"
VNCSERVERS="1:root" (注意:root是CentOS用户名)
如果建2个,可以用VNCSERVERS="1:root 2:linglong"来配置
3.用vncpasswd创建一个vnc的口令

注意这将同时在你的home目录下,创建一个隐藏的目录.vnc,其中有一个文件passwd保存着你的vnc口令.
CODE:
[root@localhost ~]# vncpasswd
Password:
Verify:
[root@localhost ~]# ls -d .vnc
.vnc
[root@localhost ~]# ls .vnc
passwd
4.启动vnc服务.
CODE:[root@localhost ~]#  /sbin/service vncserver restart
Shutting down VNC server: 1:root                          [ OK ]
Starting VNC server: 1:root perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
       LANGUAGE = (unset),
       LC_ALL = (unset),
       LANG = "zh_EN.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:1.log
                                                      [ OK ]
察看一下.vnc这个目录的内容,应该类似于下面的东西.
注:在这里我刚开始出现“Warning: *****   is taken because of /tmp/.X1-lock”
在网上找了好多方法,终于找到解决办法了!
   我直接将: /tmp/.X1-lock 删除就可以 了 ,命令式: rm /tmp/.X1-lock
如果还出现其他的文件错误 也可照样操作!
CODE:[root@localhost ~]# cd .vnc
[root@localhost .vnc]# ls
localhost.localdomain:1.log localhost.localdomain:2.log passwd
localhost.localdomain:1.pid localhost.localdomain:2.pid xstartup
[root@localhost .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

因为我们已经修改了启动脚本,现在来重新启动vncserver.
CODE:[root@localhost .vnc]#   /sbin/service vncserver restart
Shutting down VNC server: 1:root                          [ OK ]
Starting VNC server: 1:root perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
       LANGUAGE = (unset),
       LC_ALL = (unset),
       LANG = "zh_EN.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:1.log
                                                      [ OK ]
[root@localhost .vnc]# 
5.防火墙端口设置
在使用防火墙的情况下来连接到一个远程系统,需要打开端口5901.
加入以下红色的部分,然后重启iptables服务。
[root@localhost ~]#   /sbin/service iptables restart
Flushing firewall rules:                               [   OK   ]
Setting chains to policy ACCEPT: filter                    [   OK   ]
Unloading iptables modules:                                [   OK   ]
Applying iptables firewall rules:                          [   OK   ]
[root@localhost ~]#
http://blog.163.com/yumen_guohou/blog/static/1683042812010628354781/