天天看点

linux的vnc远程桌面的安装

VNC最初由AT&T开发的,它的源代码是开源的。

1. 检查vnc客户端和服务器是否已经安装:

[root@localhost ~]# rpm -q vnc

package vnc is not installed

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

package vnc-server is not installed

没有安装的话。在光盘里找到rpm包安装

[root@localhost ~]# [root@localhost ~]# mount /dev/cdrom /media/

mount: block device /dev/cdrom is write-protected, mounting read-only

[root@localhost ~]# cd /media/CentOS/

[root@localhost CentOS]# rpm -ivh vnc-server-4.1.2-14.el5.i386.rpm

warning: vnc-server-4.1.2-14.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID e8562897

Preparing...                ########################################### [100%]

   1:vnc-server             ########################################### [100%]

[root@localhost ~]# rpm -ivh /mnt/cdrom/CentOS/vnc-4.1.2-9.el5.i386.rpm

  1:vnc                    ########################################### [100%]

这里已经安装成功。

2. 将用户名称加入到配置文件:(/etc/sysconfig/vncservers)

(注:这里的“用户名”是指linux系统用户的名称)

# 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 800x600 "

这里注意一下,默认系统配置里有 –nolisten tcp 和 –nohttpd ,这两个是阻止Xwindows登陆和HTTP方式VNC登陆的,如果需要图形界面,那就删除这部分。

3. 设置密码

 [root@localhost ~]# vncpasswd

Password:

Verify:

[root@localhost ~]#

注意这里设置的密码不是root用户的密码,而且我们用vncview客户端登录时的密码。也就是这个vnc软件的密码。

4. 启动VNC服务

[root@localhost ~]# /sbin/service vncserver start

Starting VNC server: 1:root xauth:  creating new authority file /root/.Xauthority

New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1

Creating default startup script /root/.vnc/xstartup

Starting applications specified in /root/.vnc/xstartup

Log file is /root/.vnc/localhost.localdomain:1.log

                                                           [  OK  ]

注意:此时在/root/.vnc已经有VNC登陆的启动文件xstartup,和日志文件localhost:1.log。这一步很重要,之后我们才可以修改xstartup这个文件。

5.修改xstartup

[root@localhost ~]# cd /root/.vnc/

[root@localhost .vnc]# vi 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" &

gnome-session

#startkde & #kde desktop

#twm &

注意: 这一步也很重要,如是不修改这个文件的话也连不到桌面,是一片空白,所以要加上相应的桌面的参数。

6. 最后,需要配置一下防火墙,允许VNC客户端连接VNC server。VNC server监听的端口从5900开始,display :1的监听5901,display :2监听5902,以此类推。CentOs的防火墙缺省是不允许连接这些端口的,所以需要使用下面的步骤打开防火墙(需要root权限):

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

# Firewall configuration written by system-config-securitylevel

# Manual customization of this file is not recommended.

*filter

:INPUT ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [0:0]

:RH-Firewall-1-INPUT - [0:0]

-A INPUT -j RH-Firewall-1-INPUT

-A FORWARD -j RH-Firewall-1-INPUT

-A RH-Firewall-1-INPUT -i lo -j ACCEPT

-A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT

-A RH-Firewall-1-INPUT -p 50 -j ACCEPT

-A RH-Firewall-1-INPUT -p 51 -j ACCEPT

-A RH-Firewall-1-INPUT -p udp --dport 5353 -d 224.0.0.251 -j ACCEPT

-A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT

-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 631 -j ACCEPT

-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5900:5903 -j ACCEPT

-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited

COMMIT

在此行之前,加上下面的内容:

这句话的含义是,允许其它机器访问本机的5900到5903端口,这样,display:1, display:2, display:3的用户就可以连接到本机。

然后使用root身份重新启动防火墙和VNC:

[root@localhost ~]# /sbin/service iptables restart

Flushing firewall rules:                                   [  OK  ]

Setting chains to policy ACCEPT: filter                    [  OK  ]

Unloading iptables modules:                                [  OK  ]

Applying iptables firewall rules:                          [  OK  ]

Loading additional iptables modules: ip_conntrack_netbios_n[  OK  ]

[root@localhost ~]# /sbin/service vncserver resatrt

Usage: /etc/init.d/vncserver {start|stop|restart|condrestart|status}

[root@localhost ~]# /sbin/service vncserver restart

Shutting down VNC server: 1:root                           [  OK  ]

Starting VNC server: 1:root

7. Windows登陆到VNC Server

Windows 客户端 VNC Viewer 的配置: 1. 从 http://www.realvnc.com/download.html 下载 VNC Free Edition for Windows Version 4.1.2 2. 打开 VNCViewer : 填入VNCServer 的IP:编号(1或2或...) 3. VNCViewer 切换全屏模式:F8

注意我的选项

这个密码就是vncpasswd的密码

哈哈。已经成功啦。

8. 允许VNC server在系统启动过程中被启动。这可以通过“系统设置–>服务器设置–>服务”菜单来配置,把vncserver一项选上就可以了。

如果使用命令行的话,以root身份运行以下两条命令:

cd /etc/rc5.d

mv K35vncserver S35vncserver

另外可以再终端里输入:ntsysv 找到vncserver这项勾上。

9.如果是在VMware上装的话,还需要这样设置一步

虚拟机——设置——选项——远程显示——启用

密码填不填都行。

继续阅读