【VNC】Linux环境VNC服务安装、配置与使用

1.确认VNC是否安装
默认状况下,Red Hat Enterprise Linux安装程序会将VNC服务安装在系统上。
确认是否已经安装VNC服务及查看安装的VNC版本
[root@testdb ~]# rpm -q vnc-server
vnc-server-4.1.2-9.el5
[root@testdb ~]#

若系统没有安装,能够到操做系统安装盘的Server目录下找到VNC服务的RPM安装包vnc-server-4.1.2-9.el5.x86_64.rpm,安装命令以下
rpm -ivh /mnt/Server/vnc-server-4.1.2-9.el5.x86_64.rpm

2.启动VNC服务
使用vncserver命令启动VNC服务,命令格式为“vncserver :桌面号”,其中“桌面号”用“数字”的方式表示,每一个用户连个须要占用1个桌面
启动编号为1的桌面示例以下
[root@testdb ~]# vncserver :1

You will require a password to access your desktops.

Password:
Verify:
xauth:  creating new authority file /root/.Xauthority

New 'testdb:1 (root)' desktop is testdb:1

Creating default startup script. /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/testdb:1.log

以上命令执行的过程当中,由于是第一次执行,须要输入密码,这个密码被加密保存在用户主目录下的.vnc子目录(/root/.vnc/passwd)中;同时在用户主目录下的.vnc子目录中为用户自动创建xstartup配置文件(/root/.vnc/xstartup),在每次启动VND服务时,都会读取该文件中的配置信息。
BTW:/root/.vnc/目录下还有一个“testdb:1.pid”文件,这个文件记录着启动VNC后对应后天操做系统的进程号,用于中止VNC服务时准肯定位进程号。

3.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@testdb ~]# iptables -I INPUT -p tcp --dport 5901 -j ACCEPT
[root@testdb ~]# iptables -I INPUT -p tcp --dport 5801 -j ACCEPT

4.测试VNC服务
第一种方法是使用VNC Viewer软件登录测试,操做流程以下
启动VNC Viewer软件 --> Server输入“144.194.192.183:1” --> 点击“OK” --> Password输入登录密码 --> 点击“OK”登录到X-Window图形桌面环境 --> 测试成功
第二种方法是使用Web浏览器(如Firefox,IE,Safari)登录测试,操做流程以下
地址栏输入http://144.194.192.183:5801/ --> 出现VNC viewer for Java(此工具是使用Java编写的VNC客户端程序)界面,同时跳出VNC viewer对话框,在Server处输入“144.194.192.183:1”点击“OK” --> Password输入登录密码 --> 点击“OK”登录到X-Window图形桌面环境 --> 测试成功
(注:VNC viewer for Java须要JRE支持,若是页面没法显示,表示没有安装JRE,能够到http://java.sun.com/javase/downloads/index_jdk5.jsp这里下载最新的JRE进行安装)

5.配置VNC图形桌面环境为KDE或GNOME桌面环境
若是您是按照个人上面方法进行的配置的,登录到桌面后效果是很是简单的,只有一个Shell可供使用,这是为何呢?怎么才能看到可爱而且美丽的KDE或GNOME桌面环境呢?回答以下
之因此那么的难看,是由于VNC服务默认使用的是twm图形桌面环境的,能够在VNC的配置文件xstartup中对其进行修改,先看一下这个配置文件
[root@testdb ~]# 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" &
twm &

将这个xstartup文件的最后一行修改成“startkde &”,再从新启动vncserver服务后就能够登录到KDE桌面环境
将这个xstartup文件的最后一行修改成“gnome-session &”,再从新启动vncserver服务后就能够登录到GNOME桌面环境

从新启动vncserver服务的方法:
[root@testdb ~]# vncserver -kill :1
[root@testdb ~]# vncserver :1

6.配置多个桌面
可使用以下的方法启动多个桌面的VNC
vncserver :1
vncserver :2
vncserver :3
……
可是这种手工启动的方法在服务器从新启动以后将失效,所以,下面介绍如何让系统自动管理多个桌面的VNC,方法是将须要自动管理的信息添加到/etc/sysconfig/vncservers配置文件中,先以桌面1为root用户桌面2为oracle用户为例进行配置以下:
格式为:VNCSERVERS="桌面号:使用的用户名 桌面号:使用的用户名"
[root@testdb ~]# vi /etc/sysconfig/vncservers
VNCSERVERS="1:root 2:oracle"
VNCSERVERARGS[1]="-geometry 1024x768 –alwaysshared -depth 16"

7.修改VNC访问的密码
使用命令vncpasswd对不一样用户的VNC的密码进行修改,必定要注意,若是配置了不一样用户的VNC须要分别到各自用户中进行修改,例如在个人这个实验中,root用户和oracle用户须要分别修改,修改过程以下:
[root@testdb ~]# vncpasswd
Password:
Verify:
[root@testdb ~]#

8.启动和中止VNC服务
1)启动VNC服务命令
[root@testdb ~]# /etc/init.d/vncserver start
Starting VNC server: 1:root
New 'testdb:1 (root)' desktop is testdb:1

Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/testdb:1.log

2:oracle
New 'testdb:2 (oracle)' desktop is testdb:2

Starting applications specified in /home/oracle/.vnc/xstartup
Log file is /home/oracle/.vnc/testdb:2.log

                                                           [  OK  ]
2)中止VNC服务命令
[root@testdb ~]# /etc/init.d/vncserver stop
Shutting down VNC server: 1:root 2:oracle                  [  OK  ]

3)从新启动VNC服务命令
[root@testdb ~]# /etc/init.d/vncserver restart
Shutting down VNC server: 1:root 2:oracle                  [  OK  ]
Starting VNC server: 1:root
New 'testdb:1 (root)' desktop is testdb:1

Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/testdb:1.log

2:oracle
New 'testdb:2 (oracle)' desktop is testdb:2

Starting applications specified in /home/oracle/.vnc/xstartup
Log file is /home/oracle/.vnc/testdb:2.log

                                                           [  OK  ]

4)设置VNC服务随系统启动自动加载
第一种方法:使用“ntsysv”命令启动图形化服务配置程序,在vncserver服务前加上星号,点击肯定,配置完成。
第二种方法:使用“chkconfig”在命令行模式下进行操做,命令使用以下(预知chkconfig详细使用方法请自助式man一下)
[root@testdb ~]# chkconfig vncserver on
[root@testdb ~]# chkconfig --list vncserver
vncserver       0:off   1:off   2:on    3:on    4:on    5:on    6:off

9.小结
  VNC的详细配置方法到此已经写完,但愿能对你们有帮助。
VNC对于远程调用图形化界面来讲很是的轻巧和便捷,善用之!java

相关文章
相关标签/搜索