linux上如何安装配置VNC

/ 0评 / 0

Centos5.6 VNC安装配置

这几天在公司需要在linux上面安装oracle,于是找了一台PC机装上centos5.6准备练习一下,由于安装时要在网上查找很多资料,办公电脑和测试机也隔得比较远,为了方便就决定先安装VNC服务然后进行远程安装,下面就是安装过程,虽然是在Centos5.6下安装成功,但些过程适用于大部分的linux的系统。

一、检查是否安装了VNC的服务端和客户端
[root@localhost ~]# rpm –q vnc vnc-server
使用如上命令查看是否安装VNC的服务端和客户端。如果显示如下,说明已经安装
[root@tenjak-250 ~]# rpm -q vnc vnc-server
vnc-4.1.2-14.el5_5.4
vnc-server-4.1.2-14.el5_5.4
如果什么都没显示说明没有安装,则需要安装
[root@localhost ~]# yum install vnc vnc-server

二、配置VNC

1、  切换到想启动VNC服务的用户下执行vncserver,启动VNC并在该用户家目      录里面生成远程桌面配置文件,这里就以root用户为例

需要在每个用户下启动vncserver,生成该用户远程桌面连接时的配置文件以及访问密码,方法就是切换到每个用户,执行 vncserver。
(注释:在启动VNCserver时,你也可以为server指定一个display参数。你可以把display理解为一个桌面,每个用户都可以有自己的桌面。VNC客户端在连接时,可以指定连接到哪个桌面上。在系统中,display号不能重复,也就是说,如果有用户已经建立了名为“:1”的display,另外一个用户就不能再使用“:1”了,他可以使用“:2”。指定display号码的启动VNC server的命令是:   vncserver : 1)

[root@localhost ~]# vncserver         #运行vncserver。

You will require a password to access your desktops.

enter password:    #首次运行会让你设置密码,密码要求6位以上

verify password:    #确认密码

xauth: creating new authority file /root/.Xauthority        #首次运行会生成本用户的相关配置文件,以及日志文件,生成位置在~.vnc/目录下

New 'CPAYNET005:1 (root)' desktop is CPAYNET005:1 注意这个数字1

Creating default startup script /root/.vnc/xstartup

Starting applications specified in /root/.vnc/xstartup

Log file is /root/.vnc/CPAYNET005:1.log     #注意这个数字

[root@localhost ~]# vncserver   -kill   :1    #杀死刚才运行的vncserver,数字1正是上面1.log那个1。注意上面红色字体。

[root@localhost ~]# vi ~/.vnc/xstartup       #编辑这个配置脚本文件,配置使远程登录为gnome或者kde桌面。

#!/bin/sh
 # Uncomment the following two lines for normal desktop:
 # unset SESSION_MANAGER
 [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
 [ -r HOME/.Xresources ] && xrdbHOME/.Xresources
 xsetroot -solid grey
 vncconfig -iconic &
 #xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
 #twm &
 gnome-session &
 #startkde &#kde

若是用kde桌面,则将上一行开始#号去掉,注释上面的gnome

如果还要为其它的用户名配置vnc,方法同上,只需要改一下端口号就行

2.接下来编辑vnc的配置文件

[root@localhost~]#vi /etc/sysconfig/vncservers

以下是文件内容:

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

# The VNCSERVERS variable is a list of display:user pairs.
 # Uncomment the line below to start a VNC server on display : 1
 # 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/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= “ 1:root “
 VNCSERVERARGS [ 1 ] = “ -geometry 1024×768 “

解释一下这个文件:
VNCSERVERS这一行是配置在系统启动时启动几个VNC server,上面的例子里运行了一个VNC server,root在display:1 VNCSERVERARGS这行,为VNC server 1配置启动参数,上面的例子里对root使用屏幕分辨率1024×768。

设置完成后就可以启动vncserver服务了。

[root@localhost~]#/sbin/service vncserver restart  防止VNC已经启动,我们用重新启动的命令以防万一

启动失败的原因有:

1./etc/sysconfig/vncservers文件参数不对

2.没有为vncservers提到的用户生成各自的配置文件

3.在生成配置文件后,没有使用命令vncserver -kill :1 将那个进程杀死

Leave a Reply

Your email address will not be published. Required fields are marked *