一、安装vncserver
yum -y install vnc*
二、配置vncserver ,参考如下配置文件
[root@localhost ~]# cat /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"
三、设置vnc 密码
[root@localhost ~]# vncpasswd
Password:
Verify:
[root@localhost ~]#
四 、启动vncserver
[root@localhost ~]# service vncserver stop
关闭 VNC 服务器:1:root [确定]
[root@localhost ~]# service vncserver start
启动 VNC 服务器:1:root
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
[确定]
[root@localhost ~]#
五、关于桌面的配置文件
[root@localhost ~]# cat /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 &
gnome-session &
[root@localhost ~]#
六、访问方式
1、网页连接 用IE打开 http://192.168.xxx.xxx:5801/ 特别注意:用IE
2、使用 VNC Viewer 4 ,本文后有附件,可以下载。连接时填写参数如:
192.168.xx.xxx:1
七、关于多用户
其实个人并不建议VNC保持长期开启,只作为临时需要使用的时候开启服务,但是我仍然给出相关方法。
编辑 /etc/sysconfig/vncserver
VNCSERVERS="1:root 2:user01"
VNCSERVERARGS[1]="-geometry 1024x768"
VNCSERVERARGS[2]="-geometry 1024x768"
八、一些命令
1、kill当前某个vnc帐户
vncserver -kill :1
2、启动某个vnc帐户
vncserver :1
3、关闭、启动、重启 vnc服务
service vncserver stop
service vncserver start
service vncserver restart
九、一些错误
1、你可能同时开启了ssh和vnc等终端服务,vnc连接后服务器可能会提示
“我检测到已有一个面板在运行,现在将退出”的对话框,另外你可能还发现系统桌面上的菜单栏点不了或跟本看不见。
解决方法:
[root@localhost ~]# cat /etc/inittab
#
# inittab This file describes how the INIT process should set up
# the system in a certain run-level.
#
# Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
# Modified for RHS Linux by Marc Ewing and Donnie Barnes
#
# Default runlevel. The runlevels used by RHS are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#
#id:5:initdefault:
id:3:initdefault:
更改系统的运行模式为多用户,将 id:5:initdefault: 改成 id:3:initdefault: