linux VNCserver配置方法 下载本文

内容发布更新时间 : 2024/6/16 7:17:21星期一 下面是文章的全部内容请认真阅读。

linux VNCserver配置 (linux 远程桌面)

目前linux系统都自带VNC

在Linux操作系统最流行的图形化操作软件是VNC,正如windows下的mstsc远程桌面,在大多数 Linux 发行版都带了 VNC Server 的发行包,通过rpm -qa|grep vnc检查,若没有,下载rpm包进行安装即可.

1.[root@localhost ~]# rpm -qa|grep vnc vnc-4.1.2-14.el5_3.1

vnc-server-4.1.2-14.el5_3.1 2.启动服务器端的VNC 服务

[root@localhost ~]# /etc/init.d/vncserver start

Starting VNC server: [ OK ] 目前linux系统都自带VNC,不用安装 启动VNC

[root@localhost ~]# service vncservice restart

3.运行 vncserver 命令,如果第一次配置 VNC Server,会要求提供登录 VNC 使用的密码。以后也可以使用 vncpasswd 来修改密码。 [root@localhost ~]# vncserver

You will require a password to access your desktops. Password: Verify:

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 4.修改配置文件 /root/.vnc/xstartup

[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 &

5.在 Windows 使用 VNC Viewer 登录了 输入服务器地址:ip:1

然后提示输入密码,输入你刚才设定的密码就好了.

注意:IP 地址后面的 :1 的意思是 Linux 上面 VNC 设定的 Display No. 每运行一个 vncserver 就会多创建一个 Display,Display No 也就会加1。

6.在 SSH终端中输入 vncserver,让 VNC 打开一个新的 Display

[root@localhost ~]# vncserver

New ‘localhost.localdomain:2 (root)’ desktop is localhost.localdomain:2 Starting applications specified in /root/.vnc/xstartup Log file is /root/.vnc/localhost.localdomain:2.log 附一些常见的问题:

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启动项里。个人工作业务总结 本人于2009年7月进入新疆中正鑫磊地矿技术服务有限公司(前身为“西安中正矿业信息咨询有限公司”),主要从事测量技术工作,至今已有三年。 在这宝贵的三年时间里,我边工作、边学习测绘相专业书籍,遇到不懂得问题积极的请教工程师们,在他们耐心的教授和指导下,我的专业知识水平得到了很到的提高,并在实地测量工作中加以运用、总结,不断的提高自己的专业技术水平。同时积极的参与技术培训学习,加速自身知识的不断更新和自身素质的提高。努力使自己成为一名合格的测绘技术人员。 在这三年中,在公司各领导及同事的帮助带领下,按照岗位职责要求和行为规范,努力做好本职工作,认真完成了领导所交给的各项工作,在思想觉悟及工作能力方面有了很大的提高。 在思想上积极向上,能够认真贯彻党的基本方针政策,积极学习政治理论,坚持四项基本原则,遵纪守法,爱岗敬业,具有强烈的责任感和事业心。积极主动学习专业知识,工作态度端正,认真负责,具有良好的思想政治素质、思想品质和职业道德。 在工作态度方面,勤奋敬业,热爱本职工作,能够正确认真的对待每一项工作,能够主动寻找自己的不足并及时学习补充,始终保持严谨认真的工作态度和一丝不苟的工作作风。 在公司领导的关怀以及同事们的支持和帮助下,我迅速的完成了职业角色的转变。 一、回顾这四年来的职业生涯,我主要做了以下工作: 1、参与了新疆库车县新疆库车县胡同布拉克石灰岩矿的野外测绘和放线工作、点之记的编写工作、1:2000地形地质图修测、1:1000勘探剖面测量、测绘内业资料的编写工作,提交成果《新疆库车县胡同布拉克石灰岩矿普查报告》已通过评审。 2、参与了库车县城北水厂建设项目用地压覆矿产资源评估项目的室内地质资料编写工作,提交成果为《库车县城北水厂建设项目用地压覆矿产资源评估报告》,现已通过评审。 3、参与了《新疆库车县巴西克其克盐矿普查》项目的野外地质勘查工作,参与项目包括:1:2000地质测图、1:1000勘查线剖面测量、测绘内业资料的编写工作;最终提交的《新疆库车县康村盐矿普查报告》已通过评审。 4、参与了新疆哈密市南坡子泉金矿2009年度矿山储量监测工作,项目包括:野外地质测量与室内地质资料的编写,提交成果为《新疆哈密市南坡子泉金矿2009年度矿山储量年报》,现已通过评审。 6、参与了《新疆博乐市五台石灰岩矿9号矿区勘探》项目的野外地质勘查工作,项目包括:1:2000地质测图、1:1000勘探剖面测量、测绘内业资料的编写工作,并绘制相应图件。 7、参与了《新疆博乐市托特克斜花岗岩矿详查报告》项目的野外地质勘查工作,项目包括:1:2000地质测图、1:1000勘探剖面测量、测绘内业资料的编写工作,并绘制相应图件。 通过以上的这些工作,我学习并具备了以下工作能力: 1、通过实习,对测绘这门学科的研究内容及实际意义有了系统的认识。加深对测量学基本理论的理解,能够用有关理论指导作业实践,做到理论与实践相统一,提高分析问题、解决问题的能力,从而对测量学的基本内容得到一次实际应用,使所学知识进一步巩固、深化。 2、熟悉了三、四等控制测量的作业程序及施测方法,并掌握了全站仪、静态GPS、RTK等测量仪器的工作原理和操作方法。 3、掌握了GPS控制测量内业解算软件(南方测绘 Gps数据处理)以及内业成图软件(南方cass)的操作应用。能够将外业测量的数据导入软件进行地形图成图和处理。 4、在项目技术负责的指导下熟悉了测量技术总结的编写要求和方法,并参与了部分项目测量技术总结章节的编写工作。 5、在项目负责的领导下参与整个测量项目的组织运作,对项目的实施过程有了深刻理解。通过在项目组的实习锻炼了自己的组织协调能力,为以后的工作打下了坚实基础。 二、工作中尚存在的问题 从事测绘工作以来,深深感受到工作的繁忙、责任的重大,也因此没能全方位地进行系统地学习实践,主要表现为没有足够的经验,对于地形复杂的地段理解不够深刻;理论知识掌握不够系统,实践能力尚为有限。以上问题,在今后工作中自己将努力做到更好。 三、今后的工作打算 通过总结四年来的工作,我无论从工作技术上,还是从世界观、人生观、价值观等各个方面,都有了很大的提高。今后,我会在此基础上,刻苦钻研,再接再厉,使自己在业务知识水平更上一层楼,为测绘事业的发展,贡献自己的力量。