为了节省系统资源,VNC这个服务一般是不开启的,但是偶尔还是用得着。

一、安装vncserver 

 
  
  1. yum -y install vnc* 

 

二、配置vncserver ,参考如下配置文件 

 
  
  1. [root@localhost ~]# cat /etc/sysconfig/vncservers 
  2. # The VNCSERVERS variable is a list of display:user pairs. 
  3. # Uncomment the lines below to start a VNC server on display :2 
  4. as my 'myusername' (adjust this to your own).  You will also 
  5. # need to set a VNC password; run 'man vncpasswd' to see how 
  6. # to do that.   
  7. # DO NOT RUN THIS SERVICE if your local area network is 
  8. # untrusted!  For a secure way of using VNC, see 
  9. # <URL:http://www.uk.research.att.com/archive/vnc/sshvnc.html>. 
  10.  
  11. # Use "-nolisten tcp" to prevent X connections to your VNC server via TCP. 
  12.  
  13. # Use "-nohttpd" to prevent web-based VNC clients connecting. 
  14.  
  15. # Use "-localhost" to prevent remote VNC clients connecting except when 
  16. # doing so through a secure tunnel.  See the "-via" option in the 
  17. # `man vncviewer' manual page. 
  18.  
  19. # VNCSERVERS="2:myusername" 
  20. # VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -nohttpd -localhost" 
  21.  
  22. VNCSERVERS="1:root" 
  23. VNCSERVERARGS[1]="-geometry 1024x768" 

 

三、设置vnc 密码 

 
  
  1. [root@localhost ~]# vncpasswd 
  2. Password: 
  3. Verify: 
  4. [root@localhost ~]#  

 

四 、启动vncserver 

 
  
  1. [root@localhost ~]# service vncserver stop 
  2. 关闭 VNC 服务器:1:root [确定] 
  3. [root@localhost ~]# service vncserver start 
  4. 启动 VNC 服务器:1:root  
  5. New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1 
  6.  
  7. Starting applications specified in /root/.vnc/xstartup 
  8. Log file is /root/.vnc/localhost.localdomain:1.log 
  9.  
  10. [确定] 
  11. [root@localhost ~]#  

 

五、关于桌面的配置文件

 
  
  1. [root@localhost ~]# cat /root/.vnc/xstartup 
  2. #!/bin/sh 
  3.  
  4. # Uncomment the following two lines for normal desktop: 
  5. # unset SESSION_MANAGER 
  6. exec /etc/X11/xinit/xinitrc 
  7.  
  8. [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup 
  9. [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources 
  10. xsetroot -solid grey 
  11. vncconfig -iconic & 
  12. #xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & 
  13. #twm & 
  14. gnome-session & 
  15. [root@localhost ~]#  

 

六、访问方式

1、网页连接 用IE打开 http://192.168.xxx.xxx:5801/  特别注意:用IE

2、使用 VNC Viewer 4 ,本文后有附件,可以下载。连接时填写参数如:

    192.168.xx.xxx:1

七、关于多用户

   其实个人并不建议VNC保持长期开启,只作为临时需要使用的时候开启服务,但是我仍然给出相关方法。

编辑 /etc/sysconfig/vncserver

 
  
  1. VNCSERVERS="1:root 2:user01" 
  2. VNCSERVERARGS[1]="-geometry 1024x768" 
  3. VNCSERVERARGS[2]="-geometry 1024x768"  

八、一些命令

1、kill当前某个vnc帐户

 
  
  1. vncserver -kill :1 

2、启动某个vnc帐户

 
  
  1. vncserver :1 

3、关闭、启动、重启 vnc服务

 
  
  1. service vncserver stop 
  2. service vncserver start 
  3. service vncserver restart 

九、一些错误

1、你可能同时开启了ssh和vnc等终端服务,vnc连接后服务器可能会提示

“我检测到已有一个面板在运行,现在将退出”的对话框,另外你可能还发现系统桌面上的菜单栏点不了或跟本看不见。

解决方法:

 

 
  
  1. [root@localhost ~]# cat /etc/inittab  
  2. # inittab       This file describes how the INIT process should set up 
  3. #               the system in a certain run-level. 
  4. # Author:       Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org> 
  5. #               Modified for RHS Linux by Marc Ewing and Donnie Barnes 
  6.  
  7. # Default runlevel. The runlevels used by RHS are: 
  8. #   0 - halt (Do NOT set initdefault to this) 
  9. #   1 - Single user mode 
  10. #   2 - Multiuser, without NFS (The same as 3, if you do not have networking) 
  11. #   3 - Full multiuser mode 
  12. #   4 - unused 
  13. #   5 - X11 
  14. #   6 - reboot (Do NOT set initdefault to this) 
  15. #  
  16. #id:5:initdefault: 
  17. id:3:initdefault: 

更改系统的运行模式为多用户,将 id:5:initdefault:  改成 id:3:initdefault: