一般在windows上用vnc工具进行登入访问 1.确认VNC是否安装 检查VNC是否安装 rpm -qa | grep vnc 如果没有需要 VNC安装包(基本上可以如下) gtk-vnc-0.3.10-3.el6.x86_64.rpm libvncserver-0.9.7-4.el6.x86_64.rpm tigervnc-server-1.0.90-0.10.20100115svn3945.el6.x86_64.rpm 不同的linux Os下可能需要不同的依赖包 安装命令 rpm- ivh *.rpm 安装完毕后 2.启动VNC服务 使用vncserver命令启动VNC服务,命令格式为“vncserver :桌面号”,其中“桌面号”用“数字”的方式表示,每个用户连个需要占用1个桌面 启动编号为1的桌面示例如下 [root@testdb ~]# vncserver :1 You will require a password to access yourdesktops. Password: Verify: 第一次需要输入密码 3.VNC服务使用的端口号与桌面号的关系 VNC服务使用的端口号与桌面号相关,VNC使用TCP端口从5900开始,对应关系如下 桌面号为“1”  ---- 端口号为5901 桌面号为“2”  ---- 端口号为5902 桌面号为“3”  ---- 端口号为5903 基于上面的介绍,如果Linux开启了防火墙功能,就需要手工开启相应的端口,以开启桌面号为“1”相应的端口为例,命令如下 修改防火墙配置文件: vi /etc/sysconfig/iptables

-A RH-Firewall-1-INPUT -mstate –state NEW -m tcp -p tcp –dport 5901 -j ACCEPT

chmod 755 /root/.vnc/xstartup [root@testdb ~]# vi/root/.vnc/xstartup #!/bin/sh [ -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桌面环境 可以直接删掉全部覆盖 #!/bin/sh 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 "$VNCDESKTOPDesktop" & gnome-session & #set starting GNOME desktop #startkde & #kde desktop #twm & #Text interface #/usr/bin/startxfce4 #exec /usr/bin/fluxbox 重新启动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" VNCSERVERARGS[1]="-geometry 1024x768" 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:root2: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