LINUX下VNC服务的安装配置

1.首先检查VNC软件是否已经安装[root@ocm1 ~]# rpm -qa|grep vncvnc-server-4.1.2-14.el5_3.12.启动VNC服务使用vncserver命令启动,格式: server :1 ,这是城:1是桌面号,每个连接需要一个桌面号。[root@ocm1 ~]# vncserver :1You will require a password to access your desktops.Password: Password must be at least 6 characters – try againPassword: —需要输入密码Verify:xauth: creating new authority file /root/.XauthorityNew ‘ocm1.bys.com:1 (root)’ desktop is ocm1.bys.com:1Creating default startup script /root/.vnc/xstartupStarting applications specified in /root/.vnc/xstartupLog file is /root/.vnc/ocm1.bys.com:1.log以上命令执行的过程中,因为是第一次执行,需要输入密码,这个密码被加密保存在用户主目录下的.vnc子目录(/root/.vnc/passwd)中;同时在用户主目录下的.vnc子目录中为用户自动建立xstartup配置文件(/root/.vnc/xstartup),在每次启动VND服务时,都会读取该文件中的配置信息。/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 ACCEPT4.测试VNC服务是否正常第一种方法是使用VNC Viewer软件登陆测试,操作流程如下启动VNC Viewer软件 –> Server输入“192.168.57.215:1” –> 点击“OK” –> Password输入登陆密码 –> 点击“OK”登陆到X-Window图形桌面环境 –> 测试成功VNC服务默认使用的是twm图形桌面环境–和SHELL差不多,可以在打开的窗口输入oclock看能否出来时钟的图标。第二种方法是使用Web浏览器(如Firefox,IE,Safari)登陆测试,操作流程如下地址栏输入http://192.168.57.215: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进行安装)############此时使用VNC Viewer登陆后能看到SHELL界面,但是无法KDE或GNOME桌面环境5.配置VNC图形桌面环境为KDE或GNOME桌面环境–我这里是配置为GNOME如何判断LINUX上安装的是GNOME/KDE? –我这里是GNOME。[root@ocm1 ~]# ps -ef|grep gnome —或ps -ef|grep kde oracle 2541 2513 0 10:53 ? 00:00:00 /usr/bin/gnome-session因为VNC服务默认使用的是twm图形桌面环境的,可以在VNC的配置文件xstartup中对其进行修改。–即在/root/.vnc/xstartup最后一行的:twm & 替换为:startkde & 或者 gnome-session &我的文件修改如下:[root@ocm1 ~]# 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/.Xresourcesxsetroot -solid greyvncconfig -iconic &xterm -geometry 80×24+10+10 -ls -title "$VNCDESKTOP Desktop" &#twm &gnome-session &重启启动vncserver即可登陆到GNOME桌面环境:[root@ocm1 ~]# vncserver -kill :1Killing Xvnc process ID 2898[root@ocm1 ~]# vncserver :1New ‘ocm1.bys.com:1 (root)’ desktop is ocm1.bys.com:1Starting applications specified in /root/.vnc/xstartupLog file is /root/.vnc/ocm1.bys.com:1.log—-此时使用VNC Viewer登陆后能看到GNOME桌面环境了。比如在我的环境中,还配置了ORACLE用户的VNC,也要在ORACLE家目录下的/.vnc/xstartup文件进行本步的操作–完成同样要重启vncserver -kill :2。

[oracle@ocm1 ~]$ vncserver :2

You will require a password to access your desktops.Password:Verify:xauth: creating new authority file /home/oracle/.XauthorityNew ‘ocm1.bys.com:2 (oracle)’ desktop is ocm1.bys.com:2Creating default startup script /home/oracle/.vnc/xstartupStarting applications specified in /home/oracle/.vnc/xstartupLog file is /home/oracle/.vnc/ocm1.bys.com:2.log

[oracle@ocm1 ~]$ vi ./.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/.Xresourcesxsetroot -solid greyvncconfig -iconic &xterm -geometry 80×24+10+10 -ls -title "$VNCDESKTOP Desktop" &#twm &gnome-session & [oracle@ocm1 ~]$ vncserver -kill :2Killing Xvnc process ID 2680[oracle@ocm1 ~]$ vncserver :2New ‘ocm1.bys.com:2 (oracle)’ desktop is ocm1.bys.com:2Starting applications specified in /home/oracle/.vnc/xstartupLog file is /home/oracle/.vnc/ocm1.bys.com:2.log注意:VNC Viewer中服务器地址栏需要输入IP+桌面号:192.168.57.215:2 这个地址就决定了用哪个用户登陆,不用再输入用户名,只输入密码即可。6.配置多个桌面并设置VNC密码可以使用如下的方法启动多个桌面的VNCvncserver :1vncserver :2vncserver :3……但是这种手工启动的方法在服务器重新启动之后将失效,因此,下面介绍如何让系统自动管理多个桌面的VNC,方法是将需要自动管理的信息添加到/etc/sysconfig/vncservers配置文件中,先以桌面1为root用户桌面2为oracle用户为例进行配置如下:格式为:VNCSERVERS="桌面号:使用的用户名 桌面号:使用的用户名"[root@ocm1 ~]# vi /etc/sysconfig/vncservers –在文件末尾增加以下两项VNCSERVERS="1:root 2:oracle"VNCSERVERARGS[1]="-geometry 1024×768"VNCSERVERARGS[2]="-geometry 1024×768"设置和更改VNC客户端连接的密码[root@ocm1 ~]# vncpasswd Password:Verify:[root@ocm1 ~]# su – oracle[oracle@ocm1 ~]$ vncpasswdPassword:Verify:7.启动和停止VNC命令以及设置开机自启服务–要用root用户/etc/init.d/vncserver start|stop|restart为加绝对路径直接用也可以:service vncserver start|stop|restart命令示例:[root@ocm1 ~]# service vncserver statusXvnc is stopped[root@ocm1 ~]# service vncserver startStarting VNC server: 1:root New ‘ocm1.bys.com:1 (root)’ desktop is ocm1.bys.com:1Starting applications specified in /root/.vnc/xstartupLog file is /root/.vnc/ocm1.bys.com:1.log2:oracle New ‘ocm1.bys.com:2 (oracle)’ desktop is ocm1.bys.com:2Starting applications specified in /home/oracle/.vnc/xstartupLog file is /home/oracle/.vnc/ocm1.bys.com:2.log[ OK ][root@ocm1 ~]# service vncserver stopShutting down VNC server: 1:root 2:oracle [ OK ]配置VNC服务自启动:[root@ocm1 ~]# chkconfig –list vncservervncserver 0:off 1:off 2:off 3:off 4:off 5:off 6:off[root@ocm1 ~]# chkconfig vncserver on[root@ocm1 ~]# chkconfig –list vncservervncserver 0:off 1:off 2:on 3:on 4:on 5:on 6:off———-结束,参考了secooler文章,感谢 !原文 http://blog.itpub.net/519536/viewspace-607549人生就是一次充满未知的旅行,在乎的是沿途的风景,

LINUX下VNC服务的安装配置

相关文章:

你感兴趣的文章:

标签云: