您的位置:首页 > 运维架构 > Linux

REALVNC在linux下的安装与使用

2015-08-24 17:59 549 查看
VNC的安装与使用』

本人的操作环境:被控端 RHEL AS 3 U4,主控端Windows 2003。

1.下载RealVNC Server与RealVNC viewer.

VNC Server下载地址:http://www.realvnc.comvnc-4_1_1-1.i386.rpm

2.安装。

rpm –Uvh vnc-4_1_1-1.i386.rpm(如果是源代码请看包里的说明)

安装winvnc.exe

3.在Linux上启动VNC Server

执行vncserver命令:

[root@linux root]# vncserver

You will require a password to access your desktops.

Password: ----为了不想任何人都可以任意遥控此计算机。因此当第

Verify: ---1次启动VNC server时,会要求设置网络遥控的密码。

New ‘X’ desktop is linux:1 ----一定要记住这一行稍后会用到。

Creating default startup script /root/.vnc/xstartup

Starting applications specified in /root/.vnc/xstartup

Log file is /root/.vnc/linux:1.log

(经上述步骤后,便已启动了VNC Server。如果你想要更改VNC Server的密码,只要执行vncpasswd命令即可。)

4.在Microsoft Windows上运行VNC Viewer

直接运行“vncviewer.exe”,系统会出现”Connection details”对话框。

在“Connection details”对话框中的“VNC server”文本框中输入VNC Server的IP地址(或主机名及显示装置编号,(请看3。在Linux上启动VNC server的这一行,New
‘X’ desktop is linux:1 得到此信息),例如:192.168.0.1:1(冒号后面的1是执行VNC Server生成的显示装置编号),单击“OK”按钮后,VNC Server即会开始检查所输入的信息,若是信息错误,系统会出现“Failed
to connect to server”的错误信息:若是信息正确,则会接着出现“VNC Authentication”对话框。

若是在“VNC Authentication”对话框中输入的密码正确,就可以成功地打开Linux的桌面窗口。

5. 从浏览器远程遥控。

启动VNC Server
后直接打开浏览器,在地址栏中输入被控端的网址或IP地址,并在网址后加上“:5800+显示编号”的端口号即可操控该计算机。

例如:http://192.168.01.:5801 (如果显示编号为1,一般第一次设置的显示编号都是1,就用5800+1=5801。)

6.FAQ

A.为什么连接后,不能显示桌面,而只有一个Terminal窗口?

试着修改/root/.vnc/xstartup,把最后一行 twm& 改成 gnome-session& or kde&(据说KDE在目前的VNC Viewer上的表现不太稳定)

B.为什么重新启动VNC Server后,连接不上了?

因为重新启动VNC Server时,系统会指定一个新的显示编号,需使用此新的编号,否则就无法连接。

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

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

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@localhost ~]#
注意:此时在/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

-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
在此行之前,加上下面的内容:

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

这句话的含义是,允许其它机器访问本机的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

New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1
Starting applications specified in /root/.vnc/xstartup

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

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上装的话,还需要这样设置一步
虚拟机——设置——选项——远程显示——启用
密码填不填都行。

vnc
源码安装

anyway, download source code from
http://www.realvnc.com/products/free/4.1/download.html
[root@localhost Code]# tar zxvf vnc-4_1_3-x86_linux.tar.gz

[root@localhost vnc-4_1_3-x86_linux]# cd vnc-4_1_3-x86_linux

root@vinco:/home/vinco/Downloads/vnc-4_1_3-x86_linux# ls

java vncconfig vncpasswd vncserver.man vncviewer.man Xvnc

LICENCE.txt vncconfig.man vncpasswd.man vnc.so x0vncserver Xvnc.man

README vncinstall vncserver vncviewer x0vncserver.man

this action is important, believe it or not:

[root@localhost vnc-4_1_3-x86_linux]# vim README

vncviewer 4.1.2 is install by default:

[root@localhost vnc-4_1_3-x86_linux]# which vncviewer

/usr/bin/vncviewer

[root@localhost vnc-4_1_3-x86_linux]#

[root@localhost vnc-4_1_3-x86_linux]# ./vncinstall /usr/local/bin /usr/local/man

Can't install manual pages to /usr/local/man/man1

Copying Xvnc to /usr/local/bin

Copying vncviewer to /usr/local/bin

Copying vncpasswd to /usr/local/bin

Copying vncconfig to /usr/local/bin

Copying vncserver to /usr/local/bin

Copying x0vncserver to /usr/local/bin

[root@localhost vnc-4_1_3-x86_linux]#

[root@localhost vnc-4_1_3-x86_linux]# vncviewer

VNC Viewer Free Edition 4.1.2 for X - built Oct 6 2008 07:20:19

Copyright (C) 2002-2005 RealVNC Ltd.

See http://www.realvnc.com for information on VNC.

[root@localhost vnc-4_1_3-x86_linux]#

[root@localhost vnc-4_1_3-x86_linux]# which vncviewer

/usr/local/bin/vncviewer

[root@localhost vnc-4_1_3-x86_linux]#

remove the old one:

[root@localhost vnc-4_1_3-x86_linux]# rm /usr/bin/vncviewer

Things are not always the way its going :

[root@localhost vnc-4_1_3-x86_linux]# vncserver

You will require a password to access your desktops.

vncpasswd: error while loading shared libraries: libstdc++-libc6.2-2.so.3: cannot open shared object file: No such file or directory

[root@localhost vnc-4_1_3-x86_linux]#

somebody advised to create a soft link like this:

[root@localhost lib]# pwd

/usr/lib

[root@localhost lib]# ln -s libstdc++.so.6.0.10 libstdc++-libc6.2-2.so.3

[root@localhost lib]# ls -l libstdc*

lrwxrwxrwx 1 root root 19 2012-05-31 20:40 libstdc++-libc6.2-2.so.3 -> libstdc++.so.6.0.10

lrwxrwxrwx 1 root root 19 2011-06-17 08:35 libstdc++.so.6 -> libstdc++.so.6.0.10

-rwxr-xr-x 1 root root 966072 2008-11-05 20:14 libstdc++.so.6.0.10

[root@localhost lib]#

the guy cheat me, it doesn't work at all:

[root@localhost vnc-4_1_3-x86_linux]# vncserver

You will require a password to access your desktops.

vncpasswd: symbol lookup error: vncpasswd: undefined symbol: __builtin_vec_new

[root@localhost vnc-4_1_3-x86_linux]#
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: