曲宝全 2010/01/14
1 / 4
试验环境:CentOS 5.2
服务器IP:192.168.10.196
1. 检查vnc 客户端和服务器是否已经安装:
[root@localhost ~]#rpm -q vnc vnc-server
vnc-4.1.2-9.el5
vnc-server-4.1.2-9.el5
[root@localhost ~]#
CentOS 已包含vnc 的安装包
如没有安装,则:
[root@localhost ~]#yum -y install vnc vnc-server
2.将用户名添加到配置文件:
(注:这里的“用户名”是指linux 系统用户的名称)
[root@localhost ~]#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
曲宝全 2010/01/14
2 / 4
# <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"
VNCSERVERS="2:root"
# VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -nohttpd
-localhost"
VNCSERVERARGS[2]="-geometry 1024x768 -nolisten tcp -nohttpd"
3. 设置用户root 的vnc 密码:
[root@localhost ~]#vncpasswd
Password:
Verify:
4. 启动VNC 服务
[root@localhost ~]#/sbin/service vncserver start
Starting VNC server: 2:root [ OK ]
5. 更改脚本使其允许通过图形界面访问
[root@localhost ~]$cd ~/.vnc/
[root@localhost .vnc]$vi xstartup
#!/bin/sh
曲宝全 2010/01/14
3 / 4
# Uncomment the following two lines for normal desktop:
#unset SESSION_MANAGER
#e xec /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 & #Text interface
gnome-session & #set starting GNOME desktop
#startkde & #kde desktop
6. 重启vncserver
[root@localhost ~]#/sbin/service vncserver restart
Shutting down VNC server: 2:root [ OK ]
Starting VNC server: 2:root [ OK ]
7. 注册为系统服务:
[root@slave .vnc]# chkconfig --add vncserver
[root@slave .vnc]# chkconfig --levels 2345 vncserver on
8. 开启防火墙访问
[root@slave .vnc]# iptables -I INPUT -p tcp --dport 5902 -j ACCEPT
[root@slave .vnc]# service iptables save
9. 在windows 客户机上安装vncviewer(用法见下图)
曲宝全 2010/01/14
4 / 4