CentOS 下 VNC Server 的配置与使用

VNC 是一款优秀的远程控制工具软件。由著名的 AT&T 的欧洲研究实验室开发的。VNC 是在基于 UNIX 和 Linux 操作系统的免费的开源软件,远程控制能力强大,高效有用,其性能能够和 Windows 和 MAC 中的不论什么远程控制软件媲美。 在 Linux 中。VNC 包含下面四个命令:vncserver。vncviewer,vncpasswd,和 vncconnect。

大多数情况下用户仅仅须要当中的两个命令:vncserver 和 vncviewer。

1.命令描写叙述

vncserver:此服务程序必须在在主(或遥控)计算机上执行。你仅仅能作为使用者(不须要根用户身份)使用此项服务。


vncviewer:本地应用程序。用于远程接入执行vncserver的计算机并显示其环境。你须要知道远程计算机的IP地址和vncserver设定的password。
vncpasswd:vncserver的password设置工具。vncserver服务程序没有设置password将不能执行。假设你没有设置,执行vncserver时它会提示你输入一个password。
vncconnect:告诉vncserver连接到远程一个执行vncviewer的计算机的IP和port号。这样我就能够避免给其它人一个接入的password。
Xvnc:一个vnc“主控”程序。一般来说不须要直接执行。(vncserver和vncviewer实际上是Xvnc的脚本)
查找全部可用的选项。执行:
Xvnc --help
出于安全的考虑,一般不建议直接以超级用户帐号执行vncserver程序。

假设你须要超级用户的环境,请以一般用户登录后再使用su命令登录到超级用户帐号。
VNC执行的工作流程例如以下:
(1) VNCclient通过浏览器或VNC Viewer连接至VNC Server。
(2) VNC Server传送一对话窗体至client,要求输入连接password。以及存取的VNC Server显示装置。


(3) 在client输入联机password后。VNC Server验证client是否具有存取权限。
(4) 若是client通过VNC Server的验证,client即要求VNC Server显示桌面环境。
(5) VNC Server通过X Protocol 要求X Server将画面显示控制权交由VNC Server负责。
(6) VNC Server将来由 X Server的桌面环境利用VNC通信协议送至client,而且同意client控制VNC Server的桌面环境及输入装置。

下面安装环境一CentOS6.5为例。


2.安装 VNC

首先检查一下本机是否安装了 VNC。默认情况下,CentOS 6.0 是没有安装的。


检查是否安装,输入:

[root@localhost ~]# rpm -q vnc vnc-server
得到:

package vnc is not installed
package vnc-server is not installed

提示没有安装,那么就開始安装。输入:

[root@localhost ~]# yum install vnc vnc-server
注:假设是 Ubuntu 则输入:
[root@localhost ~]# apt-get install vnc vnc-server
系统会提示你确认一些选项,输入 "Y" 确认。

首次设置VNCpassword

[root@localhost ~]# vncserver

反复输入两次就可以。


错误解决1

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

[dix] Could not init font path element /usr/share/X11/fonts/misc, removing from list!
[dix] Could not init font path element /usr/share/X11/fonts/Type1, removing from list!
[dix] Could not init font path element /usr/share/fonts/default/Type1, removing from list!
[dix] Could not init font path element built-ins, removing from list! Fatal server error:
could not open default font 'fixed'

解决方法:

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


错误解决2

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

-bash vncserver: command not found

解决方法:

yum install tightvnc-server

3.配置桌面

[root@localhost ~]# vi ~/.vnc/xstartup

主要改动最后两行。

改为:

# xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
# twm &
gnome-session &
通常是将原来配置文件的最后两行凝视掉。而且增加了一行代码。表明使用的是 "Gnome" 桌面。


保存该文件就可以。


4.配置登录帐号

[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 this URL:
# http://kbase.redhat.com/faq/docs/DOC-7028
# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
# 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 -localhost"

编辑最后两行。将这两行凝视去掉,得到:

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

假设你有多个帐号,则依照以下格式配置。

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

假设使用user2,须要对user2用户运行例如以下操作

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


5.配置防火墙。系统服务

VNC server 监听的port从 5900 開始,display:1 的监听 5901,display:2 监听 5902,以此类推。CentOS 的防火墙缺省是不同意连接这些port的,所以须要使用以下的步骤打开防火墙:

[root@localhost ~]# vi /etc/sysconfig/iptables
上面我们仅仅加入了一个 root 帐号和桌面 1。所以这里依照上面的规则。加入一个 "5901" port号就可以。


-A INPUT -m state --state NEW -m tcp -p tcp --dport 5901 -j ACCEPT
重新启动防火墙服务。
设置 VNC 自己主动启动
[root@localhost ~]# chkconfig -level 345 vncserver on

  

6.測试VNC连接

以windows的vncviewer连接为例:

输入password


得到效果




7.參考及拓展链接


posted @ 2017-06-23 19:52  jzdwajue  阅读(486)  评论(0编辑  收藏  举报