CentOS 下 VNC Server 的配置与使用

来源:互联网 发布:集贤第一中学网络空间 编辑:程序博客网 时间:2024/06/16 10:44

1.安装 VNC


yum install vnc vnc-server 

系统会提示你确认一些选项,输入 "Y" 确认。

首次设置VNC密码 XXXXX  重复输入两次即可。


错误解决1

安装过程中课程出现错误:

  1. [dix] Could not init font path element /usr/share/X11/fonts/misc, removing from list!  
  2. [dix] Could not init font path element /usr/share/X11/fonts/Type1, removing from list!  
  3. [dix] Could not init font path element /usr/share/fonts/default/Type1, removing from list!  
  4. [dix] Could not init font path element built-ins, removing from list! Fatal server error:  
  5. could not open default font 'fixed' 
解决方法:

  1. yum install libXfont xorg-x11-xinit xorg-x11-fonts-Type1  

错误解决2

安装过程中课程出现错误:

  1. -bash vncserver: command not found 

解决方法:

  1. yum install tightvnc-server  

2.配置桌面

vi ~/.vnc/xstartup 

主要修改最后两行。改为:

  1. # xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &  
  2. # twm &  
  3. gnome-session & 
一般是将原来配置文件的最后两行注释掉,并且加入了一行代码,表明使用的是 "Gnome" 桌面。

保存该文件即可。

3.配置登录帐号

 vi /etc/sysconfig/vncservers

出现如下提示:

# The VNCSERVERS variable is a list of display:user pairs.


  1. #  
  2. # Uncomment the lines below to start a VNC server on display :2  
  3. # as my 'myusername' (adjust this to your own).  You will also  
  4. # need to set a VNC password; run 'man vncpasswd' to see how  
  5. # to do that.  
  6. #  
  7. # DO NOT RUN THIS SERVICE if your local area network is  
  8. # untrusted!  For a secure way of using VNC, see this URL:  
  9. # http://kbase.redhat.com/faq/docs/DOC-7028  
  10. # Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.  
  11. # Use "-localhost" to prevent remote VNC clients connecting except when  
  12. # doing so through a secure tunnel.  See the "-via" option in the  
  13. # `man vncviewer' manual page.  
  14.   
  15.   
  16. # VNCSERVERS="2:myusername"  
  17. # VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -localhost"  

编辑最后两行,将这两行注释去掉,得到:

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

如果你有多个帐号,则按照下面格式配置。

  1. VNCSERVERS="1:user1 2:user2 3:user3"  
  2. VNCSERVERARGS[1]="-geometry 1024×768"  
  3. VNCSERVERARGS[2]="-geometry 1024×768"  
  4. VNCSERVERARGS[3]="-geometry 800×600 -depth 24 -nolisten tcp -nohttpd -localhost"  #不支持 tcp,不支持 http 连接,只能在本地测试访问。  

如果使用user2,需要对user2用户执行如下操作


  1. [root@<span style="background-color: rgb(240, 240, 240);">localhost </span>~]#su user2  
  2. [test@<span style="background-color: rgb(240, 240, 240);">localhost </span>~]$mkdir .vnc   //*创建.vnc目录,用于保存此用户的vnc配置文件*//  
  3. [test@<span style="background-color: rgb(240, 240, 240);">localhost </span>~]$vncpasswd    //*设置user2用户的vnc远程连接密码*//  
  4. [test@<span style="background-color: rgb(240, 240, 240);">localhost </span>~]$su root  
  5. [root@<span style="background-color: rgb(240, 240, 240);">localhost </span>~]#service vncserver restart  

4.配置防火墙,系统服务

VNC server 监听的端口从 5900 开始,display:1 的监听 5901,display:2 监听 5902,以此类推。CentOS 的防火墙缺省是不允许连接这些端口的,所以需要使用下面的步骤打开防火墙:

vi /etc/sysconfig/iptables 

上面我们只添加了一个 root 帐号和桌面 1,所以这里按照上面的规则,添加一个 "5901" 端口号即可。

  1. -A INPUT -m state --state NEW -m tcp -p tcp --dport 5901 -j ACCEPT  
重启防火墙服务。
设置 VNC 自动启动

chkconfig -level 345 vncserver on 










0 0
原创粉丝点击