VNC的安装和常用命令

主要参考文章:http://www.cnblogs.com/coderzh/archive/2008/07/16/1243990.html 

                        http://os.51cto.com/art/201005/201136_all.htm 

                        http://blog.itpub.net/519536/viewspace-607549/

安装:

1. 下载VNC文件,我使用的是:VNC-5.2.2-Linux-x64-RPM.tar.gz。去官网下载即可。

2. 解压:tar -xzvf VNC-5.2.2-Linux-x64-RPM.tar.gz

3. 安装:yum install VNC-Server-5.2.2-Linux-x64.rpm

    // 如果需要依赖某些程序,可以通过挂载印象,安装常用开发软件包解决

 添加license:vnclicense -add DNHA4-2H25M-Q5CSB-3J395-TTB8A       // 注意:必须是对应版本的license

4. 安装完毕执行,vncserver 或 vncpasswd 命令设置用户名和密码 ;后续只能通过 vncpasswd 设置修改密码

5. 某些 vnc 的图形界面可能还需要配置文件才能显示出来。如下:修改/root/.vnc/xstartup,

    把最后一行 twm& 改成 gnome-session& 或者 kde& (据说KDE在目前的VNC Viewer上的表现不太稳定)

6. 客户端登陆 : 在vnc客户端中输入:服务器端IP:1 或 服务器端IP:5901 (后面的端口是根据server端的端口而定的)

7. 配置多个桌面,可以使用如下的方法启动多个桌面的VNC

    vncserver :1

    vncserver :2

    vncserver :3

 

常用命令:

1. 启动:vncserver(第一次推荐,可通过该命令设置密码) 或 vncserver :1 (设置完密码后推荐这种启动,指定启动端口)

2. 关闭命令 : vncserver -kill :1 ; vncserver -kill :2

3. 设置自启动 : 配置VNC自动启动。在/etc/sysconfig 下有一个 vncservers 的配置文件。修改成如下: VNCSERVERS="1:root" 意思就是使用ip:1即可使用root的

    用户桌面。而在屏幕上不显示。 使用chkconfig --level 3 vncserver 即可在启动时加载vncserver

4. 设置完自启动后,VNC的启动/停止/重启 : service vncserver start/stop/restart

    注意:3 和 4 未验证,仅供参考

 

说明:

1. 设置的密码会被加密保存在用户主目录下的.vnc子目录(/root/.vnc/passwd)目录中;同时在用户主目录下的.vnc子目录中为用户自动建立xstartup配置文件

  (/root/.vnc/xstartup),在每次启动VND服务时,都会读取该文件中的配置信息。

    /root/.vnc/目录下还有一个“testdb:1.pid”文件,这个文件记录着启动VNC后对应后天操作系统的进程号,用于停止VNC服务时准确定位进程号。

    以上是常规的配置,我有次装完后在上面目录找不到,实际上xstartup在/etc/vnc目录。可以通过locate搜索命名查找指定文件。

2. 若VNC非正常关闭,会导致当前非正常关闭的端口一直被占用(上面提到的.pid文件)。必须手动清楚相关文件,文件一般在/tmp 和 /tmp/.X11-unix/ 目录中。

    例如:/tmp/.X1-lock 和 /tmp/.X11-unix/X1

    如果记不住,我们可以通过启动命令:vncserver :1 ,指定启动端口。报错信息中会指明加锁文件所在位置。

3. 运行vncserver可能会出现如下错误:

vncext: VNC extension running!
vncext: Listening for VNC connections on port 5901
vncext: Listening for HTTP connections on port 5801
vncext: created VNC server for screen 0
error opening security policy file /usr/X11R6/lib/X11/xserver/SecurityPolicy
Could not init font path element /usr/X11R6/lib/X11/fonts/misc/, removing from list!
Could not init font path element /usr/X11R6/lib/X11/fonts/Speedo/, removing from list!
Could not init font path element /usr/X11R6/lib/X11/fonts/Type1/, removing from list!
Could not init font path element /usr/X11R6/lib/X11/fonts/CID/, removing from list!
Could not init font path element /usr/X11R6/lib/X11/fonts/75dpi/, removing from list!
Could not init font path element /usr/X11R6/lib/X11/fonts/100dpi/, removing from list!
Fatal server error:
could not open default font 'fixed'
xsetroot: unable to open display 'localhost.localdomain:1'
vncconfig: unable to open display "localhost.localdomain:1"
Warning: This program is an suid-root program or is being run by the root user.
The full text of the error or warning message cannot be safely formatted
in this environment. You may get a more descriptive message by running the
program as a non-root user or by removing the suid bit on the executable.
xterm Xt error: Can't open display: %s

      原因:vncserver默认寻找的X系统的字体路径在/usr/X11R6/lib/X11/fonts/下,但RHEL5却在/usr /share/X11/fonts/下

      解决:

             mkdir /usr/X11R6/lib    

             cd /usr/X11R6/lib

             ln -s /usr/share/X11 X11

 

推荐参考文章:http://blog.itpub.net/519536/viewspace-607549/

posted @ 2015-01-17 15:47  Jtianlin  阅读(11680)  评论(0编辑  收藏  举报