且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Linux/AIX上部署VNC Server

更新时间:2022-09-13 12:24:45

  •  安装VNC服务端

  1. [root@rhel6 ~]# rpm -q tigervnc-server 
  2. tigervnc-server-1.0.90-0.17.20110314svn4359.el6.x86_64 
  • 启动VNC服务

  1. [root@rhel6 ~]# vncserver                               #第一次启动display :1(第一张虚拟纸,依次类推),可通过vncserver :2 启动display:2 
  2.  
  3. New 'rhel6.xfcy.org:1 (root)' desktop is rhel6.xfcy.org:1 
  4.  
  5. Starting applications specified in /root/.vnc/xstartup 
  6. Log file is /root/.vnc/rhel6.xfcy.org:1.log 
  7.  
  8. [root@rhel6 ~]# /etc/init.d/vncserver status 
  9. Xvnc (pid 2182) is running... 
  • 修改VNC Server配置文件

  1. [root@rhel6 ~]# cat /etc/sysconfig/vncservers                   #启动vncserver后才生成 
  2. # The VNCSERVERS variable is a list of display:user pairs. 
  3. # 
  4. # Uncomment the lines below to start a VNC server on display :2 
  5. # as my 'myusername' (adjust this to your own).  You will also 
  6. # need to set a VNC password; run 'man vncpasswd' to see how 
  7. # to do that.   
  8. # 
  9. # DO NOT RUN THIS SERVICE if your local area network is 
  10. # untrusted!  For a secure way of using VNC, see this URL: 
  11. # http://kbase.redhat.com/faq/docs/DOC-7028 
  12.  
  13. # Use "-nolisten tcp" to prevent X connections to your VNC server via TCP. 
  14.  
  15. # Use "-localhost" to prevent remote VNC clients connecting except when 
  16. # doing so through a secure tunnel.  See the "-via" option in the 
  17. # `man vncviewer' manual page. 
  18.  
  19. # VNCSERVERS="2:myusername" 
  20. # VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -nohttpd -localhost" 
  21. VNCSERVERS="2:xfcy 3:root"                           #设置在vncserver启动2个display,且display:2,:3的用户权限分别为xfcy,root 
  22. VNCSERVERARGS[2]="-geometry 800x600"                     
  23. VNCSERVERARGS[3]="-geometry 800x600 -localhost"             #设置display:2的分辨率为800×600且只监听本地 
  • 设置VNC密码(保存在~/.vnc/passwd中),同时自动生成~/.vnc/xstartup(在每次启动VNC服务时候,都会读取该文件中的配置信息)

  1. [root@rhel6 ~]# vncpasswd                            
  2. Password: 
  3. Verify: 
  • 修改xstartup配置文件

  1. [root@rhel6 ~]# cat ~/.vnc/xstartup  
  2. #!/bin/sh 
  3.  
  4. [ -r /etc/sysconfig/i18n ] && . /etc/sysconfig/i18n 
  5. export LANG 
  6. export SYSFONT 
  7. vncconfig -iconic & 
  8. unset SESSION_MANAGER 
  9. unset DBUS_SESSION_BUS_ADDRESS 
  10. OS=`uname -s` 
  11. if [ $OS = 'Linux' ]; then 
  12.   case "$WINDOWMANAGER" in 
  13.     *gnome*) 
  14.       if [ -e /etc/SuSE-release ]; then 
  15.         PATH=$PATH:/opt/gnome/bin 
  16.         export PATH 
  17.       fi 
  18.       ;; 
  19.   esac 
  20. fi 
  21. if [ -x /etc/X11/xinit/xinitrc ]; then 
  22.   exec /etc/X11/xinit/xinitrc 
  23. fi 
  24. if [ -f /etc/X11/xinit/xinitrc ]; then 
  25.   exec sh /etc/X11/xinit/xinitrc 
  26. fi 
  27. [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources 
  28. xsetroot -solid grey 
  29. #xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & #注释掉这两行避免出现黑屏 
  30. #twm & 
  31.  
  32. gnome-session &                                 #登录到GNOME桌面环境 
  33. #startkde &                                     #登录到KDE桌面环境 
  • 配置Display:2(即用户权限为xfcy的共享桌面,配置方法同上)

  1. [root@rhel6 .vnc]# su - xfcy                                #必须在对应的用户下设置密码 
  2. [xfcy@rhel6 ~]$ vncserver :2 
  3.  
  4. You will require a password to access your desktops. 
  5.  
  6. Password: 
  7. Verify: 
  8.  
  9. New 'rhel6.xfcy.org:2 (xfcy)' desktop is rhel6.xfcy.org:2 
  10.  
  11. Creating default startup script /home/xfcy/.vnc/xstartup 
  12. Starting applications specified in /home/xfcy/.vnc/xstartup 
  13. Log file is /home/xfcy/.vnc/rhel6.xfcy.org:2.log 
  14.  
  15. [xfcy@rhel6 ~]$ vi .vnc/xstartup  
  16. #!/bin/sh 
  17.  
  18. [ -r /etc/sysconfig/i18n ] && . /etc/sysconfig/i18n 
  19. export LANG 
  20. export SYSFONT 
  21. vncconfig -iconic & 
  22. unset SESSION_MANAGER 
  23. unset DBUS_SESSION_BUS_ADDRESS 
  24. OS=`uname -s` 
  25. if [ $OS = 'Linux' ]; then 
  26.   case "$WINDOWMANAGER" in 
  27.     *gnome*) 
  28.       if [ -e /etc/SuSE-release ]; then 
  29.         PATH=$PATH:/opt/gnome/bin 
  30.         export PATH 
  31.       fi 
  32.       ;; 
  33.   esac 
  34. fi 
  35. if [ -x /etc/X11/xinit/xinitrc ]; then 
  36.   exec /etc/X11/xinit/xinitrc 
  37. fi 
  38. if [ -f /etc/X11/xinit/xinitrc ]; then 
  39.   exec sh /etc/X11/xinit/xinitrc 
  40. fi 
  41. [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources 
  42. xsetroot -solid grey 
  43. #xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & 
  44. #twm & 
  45.  
  46. gnome-session & 
  • 重启VNC Server服务

  1. [root@rhel6 ~]# /etc/init.d/vncserver restart 
  2. Shutting down VNC server: 2:xfcy 3:root                    [  OK  ] 
  3. Starting VNC server: 2:xfcy  
  4. New 'rhel6.xfcy.org:2 (xfcy)' desktop is rhel6.xfcy.org:2 
  5.  
  6. Starting applications specified in /home/xfcy/.vnc/xstartup 
  7. Log file is /home/xfcy/.vnc/rhel6.xfcy.org:2.log 
  8.  
  9. 3:root  
  10. New 'rhel6.xfcy.org:3 (root)' desktop is rhel6.xfcy.org:3 
  11.  
  12. Starting applications specified in /root/.vnc/xstartup 
  13. Log file is /root/.vnc/rhel6.xfcy.org:3.log 
  14.  
  15.                                                            [  OK  ] 
  16.  
  17. [root@rhel6 .vnc]# netstat -lntp | grep 590       #VNC server监听的端口从5900开始,display :1的监听5901,display :2监听5902,以此类推
  18.  
  19. tcp        0      0 0.0.0.0:5902                0.0.0.0:*                   LISTEN      3567/Xvnc            
  20. tcp        0      0 127.0.0.1:5903              0.0.0.0:*                   LISTEN      3649/Xvnc  
  • 客户端访问

  1. [root@rhel5 ~]# vncviewer 192.168.1.119:3 
  2.  
  3. VNC Viewer Free Edition 4.1.2 for X - built Jan 26 2009 11:52:08 
  4. Copyright (C) 2002-2005 RealVNC Ltd. 
  5. See http://www.realvnc.com for information on VNC. 
  6.  
  7. Sun Nov 18 23:17:16 2012 
  8.  CConn:       connected to host 192.168.1.119 port 5903 
  9.  CConnection: Server supports RFB protocol version 3.8 
  10.  CConnection: Using RFB protocol version 3.8 
  11.  
  12. Sun Nov 18 23:17:18 2012 
  13.  TXImage:     Using default colormap and visual, TrueColor, depth 16. 
  14.  CConn:       Using pixel format depth 6 (8bpp) rgb222 
  15.  CConn:       Using ZRLE encoding 
  16.  
  17. Sun Nov 18 23:17:21 2012 
  18.  CConn:       Throughput 20476 kbit/s - changing to hextile encoding 
  19.  CConn:       Throughput 20476 kbit/s - changing to full colour 
  20.  CConn:       Using pixel format depth 16 (16bpp) little-endian rgb565 
  21.  CConn:       Using hextile encoding 
  • 通过SSH加密VNC的远程连接

  1. [root@rhel5 ~]# vncviewer -via 192.168.1.119 :2 
  2.  
  3. VNC Viewer Free Edition 4.1.2 for X - built Jan 26 2009 11:52:08 
  4. Copyright (C) 2002-2005 RealVNC Ltd. 
  5. See http://www.realvnc.com for information on VNC. 
  6. The authenticity of host 'rhel6 (192.168.1.119)' can't be established. 
  7. RSA key fingerprint is 1a:cf:92:de:28:7d:f2:e0:e8:e6:ad:f1:7c:40:6a:67. 
  8. Are you sure you want to continue connecting (yes/no)? yes 
  9. Warning: Permanently added 'rhel6' (RSA) to the list of known hosts. 
  10. root@rhel6's password:   
  11.  
  12. Tue Nov 20 01:12:37 2012 
  13.  CConn:       connected to host localhost port 5599 
  14.  CConnection: Server supports RFB protocol version 3.8 
  15.  CConnection: Using RFB protocol version 3.8 
  16.  
  17. Tue Nov 20 01:12:39 2012 
  18.  TXImage:     Using default colormap and visual, TrueColor, depth 16. 
  19.  CConn:       Using pixel format depth 6 (8bpp) rgb222 
  20.  CConn:       Using ZRLE encoding 
  21.  
  22. Tue Nov 20 01:12:41 2012 
  23.  CConn:       Throughput 20588 kbit/s - changing to hextile encoding 
  24.  CConn:       Throughput 20588 kbit/s - changing to full colour 
  25.  CConn:       Using pixel format depth 16 (16bpp) little-endian rgb565 
  26.  CConn:       Using hextile encoding 
Linux/AIX上部署VNC Server
 
  • 关闭已启用的display:2

  1. [xfcy@rhel6 ~]$ vncserver -kill :2                          #必须以相应的用户进行操作 
  2. Killing Xvnc process ID 3567 
  3. Xvnc seems to be deadlocked.  Kill the process manually and then re-run 
  4.     /usr/bin/vncserver -kill :2 
  5. to clean up the socket files. 
  6.  
  7. [root@rhel6 ~]# netstat -lntp | grep 590 
  8. tcp        0      0 127.0.0.1:5903              0.0.0.0:*                   LISTEN      6585/Xvnc           
  • 附:AIX上部署VNC Server

  1. 一.安装VNC 
  2. # rpm -ivh vnc-3.3.3r2-6.aix5.1.ppc.rpm 
  3. vnc                         ################################################## 
  4.  
  5. # rpm -ql vnc 
  6. /opt/freeware/bin/Xvnc 
  7. /opt/freeware/bin/vncconnect 
  8. /opt/freeware/bin/vncpasswd 
  9. /opt/freeware/bin/vncserver 
  10. /opt/freeware/bin/vncviewer 
  11. /opt/freeware/doc/vnc-3.3.3r2 
  12. /opt/freeware/doc/vnc-3.3.3r2/LICENCE.TXT 
  13. /opt/freeware/doc/vnc-3.3.3r2/README 
  14. /opt/freeware/share/vnc/classes 
  15. /opt/freeware/share/vnc/classes/DesCipher.class 
  16. /opt/freeware/share/vnc/classes/animatedMemoryImageSource.class 
  17. /opt/freeware/share/vnc/classes/authenticationPanel.class 
  18. /opt/freeware/share/vnc/classes/clipboardFrame.class 
  19. /opt/freeware/share/vnc/classes/index.vnc 
  20. /opt/freeware/share/vnc/classes/optionsFrame.class 
  21. /opt/freeware/share/vnc/classes/rfbProto.class 
  22. /opt/freeware/share/vnc/classes/shared.vnc 
  23. /opt/freeware/share/vnc/classes/vncCanvas.class 
  24. /opt/freeware/share/vnc/classes/vncviewer.class 
  25. /opt/freeware/share/vnc/classes/vncviewer.jar 
  26. /opt/freeware/vnc 
  27. /usr/lpp/X11/bin/Xvnc 
  28. /usr/lpp/X11/bin/vncconnect 
  29. /usr/lpp/X11/bin/vncpasswd 
  30. /usr/lpp/X11/bin/vncserver 
  31. /usr/lpp/X11/bin/vncviewer 
  32.  
  33.  
  34. 二.编辑配置文件:/opt/freeware/bin/vncserver 
  35. 1.修改前: 
  36. # $cmd .= " -fp /usr/lib/X11/fonts/,/usr/lib/X11/fonts/misc/,/usr/lib/X11/fonts/75dpi/"; 
  37. 修改后:(去掉注释,即加入了fonts) 
  38. $cmd .= " -fp /usr/lib/X11/fonts/,/usr/lib/X11/fonts/misc/,/usr/lib/X11/fonts/75dpi/"
  39. $cmd .= " -ac -fp /usr/lib/X11/fonts/,/usr/lib/X11/fonts/misc/,/usr/lib/X11/fonts/75dpi/";      (若出现灰屏则设置为此) 
  40. 2.修改前: 
  41. $vncClasses = "/usr/local/vnc/classes"
  42. 修改后: 
  43. $vncClasses = "/opt/freeware/vnc/classes"
  44.  
  45. # cat /opt/freeware/bin/vncserver | egrep "font|vncClasses" | grep -v ^# 
  46. $vncClasses = "/opt/freeware/vnc/classes"
  47. $cmd .= " -fp /usr/lib/X11/fonts/,/usr/lib/X11/fonts/misc/,/usr/lib/X11/fonts/75dpi/,/usr/lib/X11/fonts/100dpi/,/usr/lib/X11/fonts/ibm850/,/usr/lib/X11/fonts/Type1/"
  48.  
  49.  
  50. 三.如果要使用CDE界面(AIX下的XWindow,类似于Redhat的GNOME) 
  51. # vi ~/.vnc/xstartup 
  52. #!/bin/sh 
  53.  
  54. xrdb $HOME/.Xresources 
  55. xsetroot -solid grey 
  56. xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & 
  57. # twm &  #注释掉原来的配置
  58. /usr/dt/bin/dtsession &  #添加CDE界面的session
  59.  
  60. 四.启动vncserver 
  61. # su oracle 
  62. $ vncserver 
  63.  
  64. You will require a password to access your desktops. 
  65.  
  66. Password:  
  67. Verify:    
  68.  
  69. New 'X' desktop is fjkf:1 
  70.  
  71. Creating default startup script /home/oracle/.vnc/xstartup 
  72. Starting applications specified in /home/oracle/.vnc/xstartup 
  73. Log file is /home/oracle/.vnc/fjkf:1.log 

 


     本文转自Vnimos51CTO博客,原文链接:http://blog.51cto.com/vnimos/1073504,如需转载请自行联系原作者