1:检查系统

检查是否已安装vncserver

[root@localhost oradisk]# rpm -qa|grep  vnc

上句检查已经安装过的rpm包,下面这句检查rpm包中的信息,都可以证明一个程序已经安装成功。

yum info tigervnc-server

发现光盘里已经安装了:

gtk-vnc-python-0.3.10-3.el6.x86_64
tigervnc-1.0.90-0.17.20110314svn4359.el6.x86_64
gtk-vnc-0.3.10-3.el6.x86_64
tigervnc-server-1.0.90-0.17.20110314svn4359.el6.x86_64

一开始程序安装的不好使,我又重新安装了一遍,卸载的方法如下:

yum -y remove realvnc-vnc-server-5.0.3.37046-1.x86_64

检测是否已经安装vnc
[root@localhost oradisk]# rpm -q vnc vnc-server

这步我检查时是(可是就算是我都已经可以远程访问了,这个命令的结果还是没有安装,很奇怪)

package vnc is not installed

package vnc-server is not installed

2:安装

我试过用直接用rpm -ivh VNC-Server-5.0.3-Linux-x64.rpm,但是出现了以下错误(外加缺少xterm 依赖):

error: Failed dependencies:
        tightvnc conflicts with realvnc-vnc-server-5.0.3.37046-1.x86_64
        tigervnc conflicts with realvnc-vnc-server-5.0.3.37046-1.x86_64
        tigervnc-server conflicts with realvnc-vnc-server-5.0.3.37046-1.x86_64

这个可以通过在rpm命令中添加 --nodeps --force 参数解决,安装后并没有直接影响到程序的使用。

[root@localhost oradisk]# tar -zxvf VNC-5.0.3-Linux-x64-RPM.tar.gz
[root@localhost oradisk]# rpm -ivh VNC-Server-5.0.3-Linux-x64.rpm

这里有依赖包,需要安装xterm,如下
[root@localhost oradisk]# yum install xterm
[root@localhost oradisk]# rpm -ivh VNC-Server-5.0.3-Linux-x64.rpm
[root@localhost oradisk]# vncserver :1(中间有空格)


无法启动,会要求输入license
[root@localhost oradisk]# vnclicense -add VKUPN-MTHHC-UDHGS-UWD76-6N36A

相关license如下:
VKUPN-MTHHC-UDHGS-UWD76-6N36A
69NCN-JRLBC-QD28Y-5KLY2-UEE6A
6GQQQ-HXLBS-U2H8Q-B6UB7-R7R6A
8XWCU-ZRJBF-U7BXZ-G5EAE-ZPQ2A
6XQQQ-WXL4Q-NN4KX-NUTC6-8ZK6A
PGUFQ-HTZBB-WNHU7-YHDQC-A7R6A

3:配置VNC

全都安装完毕之后

[root@localhost oradisk]#vncserver

发现错误提示:

xauth: (argv):1:  bad display name "KVM-A-05:1" in "add" command
Error: could not run xauth

在网上查资料发现这个错误是由于/etc/hosts文件中缺少配置造成的

[root@localhost oradisk]#vi  /etc/hosts

添加一句127.0.0.1 localhost的语句在最后。

配置显示分辨率、商品和用户,编辑 /etc/sysconfig/vncservers,参考注释掉的最后两行,添加 2 行(添加-alwaysshared可以允许多个终端同时登录服务器,-depth指颜色分辨率,可以是8,16,24,32)
VNCSERVERS="1:root 2:myname"

VNCSERVERARGS[1]="-geometry 1024x768 -nolisten tcp"
VNCSERVERARGS[2]="-geometry 1024x768 -nolisten tcp"

开启防火墙端口5900到5910
[root@localhost ~]# vim /etc/sysconfig/iptables
    加入如下内容,开启vnc的5900到5910连接端口,然后保存
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 5900:5910 -j ACCEPT
    :wq  保存退出

关于添加这句的位置,网上有说应该加在第四行,
查看防火墙
先查看端口 服务端口   netstat -ntlp
把防火墙端口打开      vi /etc/sysconfig/iptables   

重启防火墙
[root@localhost ~]# service iptables restart

修改登录画面可选KDE 和GNOME,注意:每个用户都需要改否则出现画面是VNC自带的界面

[root@centos .vnc]$ vi /root/.vnc/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 &   #set starting GNOME desktop
startkde &         #kde desktop
#twm &      #Text interface
注:将所有都注释掉,然后再最后添加gnome-session&或startkde &
c.
重启VNC即可。

 

启动vnc服务:
    1、/etc/init.d/vncserver start (stop reload restart等)
    2、service vncserver start (stop restart等)
    3、设置开机自动启动:chkconfig  vncserver on
          (检查开机自动启动设置:chkconfig --list vncserver)

附录:

 

1、VNC的启动/停止/重启
#service vncserver start/stop/restart
关闭具体的vncserver命令:vncserver -kill :1       vncserver -kill :2
 
2、设置密码
#vncpasswd
 
3、客户端登陆
在vnc客户端中输入:服务器端IP:1或服务器端IP:2
 
4、设置登陆到KDE桌面
a.
[root@centos ~]# vi /etc/sysconfig/vncservers
#
# 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:[url]http://www.uk.research.att.com/vnc/sshvnc.html[/url]>.
# VNCSERVERS="1:myusername"
VNCSERVERS="1:root"
# VNCSERVERARGS[1]="-geometry 800x600"
 VNCSERVERARGS[1]=”-geometry 800×600 -alwaysshared -depth 24″
-alwaysshared代表允许多用户同时登录 -depth代为色深,参数有8,16,24,32。
注:红色部分就是被修改或增加的部分
b.
[root@centos .vnc]$ vi /root/.vnc/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 &   #set starting GNOME desktop
startkde &         #kde desktop
#twm &      #Text interface
注:红色部分就是被修改或增加的部分
c.
重启VNC即可。
 

附一些常见的问题:(转)

VNC Viewer下载地址:http://download.csdn.net/source/1080853

以后如果服务器重新启动过,就要重新输入 vncserver 后才能登录。如果服务器一直没有重启过,就不用了。如果要杀掉 vncserver 进程,可执行 vncserver :1 kill ,1表示 display 的 ID 号。

(1) 重设VNC密码
[root@localhost ~]# vncpasswd
Password:
Verify:
(2) 启动和kill vncserver
[root@localhost ~]# vncserver :23
 
New ‘localhost.localdomain:23 (root)’ desktop is localhost.localdomain:23

Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:23.log

如下:kill  display 的 ID 1,1的pid是:6653
[root@localhost ~]# ps -auxwf|grep vnc|grep -v grep
Warning: bad syntax, perhaps a bogus ‘-’? See /usr/share/doc/procps-3.2.7/FAQ
root      6653  0.0  1.3  13660  6836 pts/0    S    04:44   0:00 Xvnc :1 -desktop localhost.localdomain:1 (root) -httpd /usr/share/vnc/classes -auth /root/.Xauthority -geometry 1024×768 -depth 16 -rfbwait 30000 -rfbauth /root/.vnc/passwd -rfbport 5901 -pn
root      6661  0.0  0.2   4276  1304 pts/0    S    04:44   0:00 vncconfig -iconic
root      6716  0.1  2.1  20972 11276 pts/0    S    04:51   0:01 Xvnc :2 -desktop localhost.localdomain:2 (root) -httpd /usr/share/vnc/classes -auth /root/.Xauthority -geometry 1024×768 -depth 16 -rfbwait 30000 -rfbauth /root/.vnc/passwd -rfbport 5902 -pn
root      6936  0.4  2.1  20856 11116 pts/0    S    05:06   0:00 Xvnc :23 -desktop localhost.localdomain:23 (root) -httpd /usr/share/vnc/classes -auth /root/.Xauthority -geometry 1024×768 -depth 16 -rfbwait 30000 -rfbauth /root/.vnc/passwd -rfbport 5923 -pn
[root@localhost ~]# kill -9 6653
[root@localhost ~]# ps -auxwf|grep vnc|grep -v grep
Warning: bad syntax, perhaps a bogus ‘-’? See /usr/share/doc/procps-3.2.7/FAQ
root      6716  0.1  2.1  20972 11276 pts/0    S    04:51   0:01 Xvnc :2 -desktop localhost.localdomain:2 (root) -httpd /usr/share/vnc/classes -auth /root/.Xauthority -geometry 1024×768 -depth 16 -rfbwait 30000 -rfbauth /root/.vnc/passwd -rfbport 5902 -pn
root      6936  0.3  2.1  20856 11116 pts/0    S    05:06   0:00 Xvnc :23 -desktop localhost.localdomain:23 (root) -httpd /usr/share/vnc/classes -auth /root/.Xauthority -geometry 1024×768 -depth 16 -rfbwait 30000 -rfbauth /root/.vnc/passwd -rfbport 5923 -pn

当然,vncserver -kill :2也可以了,
[root@localhost ~]# vncserver -kill :2
Killing Xvnc process ID 6716
[root@localhost ~]# ps -auxwf|grep vnc|grep -v grep
Warning: bad syntax, perhaps a bogus ‘-’? See /usr/share/doc/procps-3.2.7/FAQ
root      6936  0.2  2.1  20856 11116 pts/0    S    05:06   0:00 Xvnc :23 -desktop localhost.localdomain:23 (root) -httpd /usr/share/vnc/classes -auth /root/.Xauthority -geometry 1024×768 -depth 16 -rfbwait 30000 -rfbauth /root/.vnc/passwd -rfbport 5923 -pn

(3)重新启动一个手动kill的vncserver

[root@localhost ~]# vncserver :1

Warning: localhost.localdomain:1 is taken because of /tmp/.X1-lock
Remove this file if there is no X server localhost.localdomain:1
A VNC server is already running as :1
[root@localhost ~]# rm -rf /tmp/.X1-lock
[root@localhost ~]# vncserver :1       

Warning: localhost.localdomain:1 is taken because of /tmp/.X11-unix/X1
Remove this file if there is no X server localhost.localdomain:1
A VNC server is already running as :1
[root@localhost ~]# rm -rf /tmp/.X11-unix/X1
[root@localhost ~]# vncserver :1          

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

[root@localhost ~]#
[root@localhost ~]# ps -auxwf|grep vnc|grep -v grep
Warning: bad syntax, perhaps a bogus ‘-’? See /usr/share/doc/procps-3.2.7/FAQ
root      6936  0.0  2.4  22296 12680 pts/0    S    05:06   0:00 Xvnc :23 -desktop localhost.localdomain:23 (root) -httpd /usr/share/vnc/classes -auth /root/.Xauthority -geometry 1024×768 -depth 16 -rfbwait 30000 -rfbauth /root/.vnc/passwd -rfbport 5923 -pn
root      7337  1.0  2.1  20252 10856 pts/0    S    05:19   0:00 Xvnc :1 -desktop localhost.localdomain:1 (root) -httpd /usr/share/vnc/classes -auth /root/.Xauthority -geometry 1024×768 -depth 16 -rfbwait 30000 -rfbauth /root/.vnc/passwd -rfbport 5901 -pn

说明:因是手动删除的,所以也要把.lock删除掉,才能重新启动了.

(4).VNC服务使用的端口号与桌面号的关系

    VNC服务使用的端口号与桌面号相关,VNC使用TCP端口从5900开始,对应关系如下

    桌面号为“1”  —- 端口号为5901

    桌面号为“2”  —- 端口号为5902

    桌面号为“3”  —- 端口号为5903

    ……

    基于Java的VNC客户程序Web服务TCP端口从5800开始,也是与桌面号相关,对应关系如下

    桌面号为“1”  —- 端口号为5801

    桌面号为“2”  —- 端口号为5802

    桌面号为“3”  —- 端口号为5803

    ……

    基于上面的介绍,如果Linux开启了防火墙功能,就需要手工开启相应的端口,以开启桌面号为“1”相应的端口为例,命令如下

    [root@localhost~]# iptables -I INPUT -p tcp –dport 5901 -j ACCEPT

    [root@localhost ~]# iptables -I INPUT -p tcp –dport 5801 -j ACCEPT

(5)配置VNC图形桌面环境为KDE或GNOME桌面环境

[root@localhost ~]# cat /root/.vnc/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 80×24+10+10 -ls -title “$VNCDESKTOP Desktop” &
twm &

将这个xstartup文件的最后一行修改为“startkde &”,再重新启动vncserver服务后就可以登陆到KDE桌面环境

将这个xstartup文件的最后一行修改为“gnome-session &”,再重新启动vncserver服务后就可以登陆到GNOME桌面环境

重新启动vncserver服务的方法:

[root@localhost ~]# vncserver -kill :1

[root@localhost ~]# vncserver :1

(6) 配置多个桌面

    可以使用如下的方法启动多个桌面的VNC

    vncserver :1

    vncserver :2

    ……

    但是这种手工启动的方法在服务器重新启动之后将失效,因此,下面介绍如何让系统自动管理多个桌面的VNC,方法是将需要自动管理的信息添加到/etc/sysconfig/vncservers配置文件中,
    先以桌面1为test用户桌面2为test1用户为例进行配置如下:

    格式为:VNCSERVERS=”桌面号:使用的用户名 桌面号:使用的用户名”

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

    VNCSERVERS=”1:test 2:test1″

    VNCSERVERARGS[1]=”-geometry 1024×768″

    VNCSERVERARGS[2]=”-geometry 1024×768″

(7) 设置VNC服务随系统启动自动加载

 第一种方法:使用“ntsysv”命令启动图形化服务配置程序,在vncserver服务前加上星号,点击确定,配置完成。

 第二种方法:使用“chkconfig”在命令行模式下进行操作,命令使用如下:

    [root@localhost ~]# chkconfig vncserver on

    [root@testdb ~]# chkconfig –list vncserver

    vncserver       0:off   1:off   2:on    3:on    4:on    5:on    6:off

 第三种方法:把这行命令/etc/init.d/vncserver start加到/etc/rc.local启动项里。

 

posted on 2013-01-14 10:52  征征的美丽心情  阅读(6635)  评论(0编辑  收藏  举报