安裝VNC服務端
[root@rhel6 ~]# rpm -q tigervnc-server
tigervnc-server-1.0.90-0.17.20110314svn4359.el6.x86_64
啟動VNC服務
[root@rhel6 ~]# vncserver #第一次啟動display :1(第一張虛拟紙,依次類推),可通過vncserver :2 啟動display:2
New 'rhel6.xfcy.org:1 (root)' desktop is rhel6.xfcy.org:1
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/rhel6.xfcy.org:1.log
[root@rhel6 ~]# /etc/init.d/vncserver status
Xvnc (pid 2182) is running...
修改VNC Server配置檔案
[root@rhel6 ~]# cat /etc/sysconfig/vncservers #啟動vncserver後才生成
# The VNCSERVERS variable is a list of display:user pairs.
#
# Uncomment the lines below to start a VNC server on display :2
# as my 'myusername' (adjust this to your own). You will also
# need to set a VNC password; run 'man vncpasswd' to see how
# to do that.
# DO NOT RUN THIS SERVICE if your local area network is
# untrusted! For a secure way of using VNC, see this URL:
# http://kbase.redhat.com/faq/docs/DOC-7028
# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
# Use "-localhost" to prevent remote VNC clients connecting except when
# doing so through a secure tunnel. See the "-via" option in the
# `man vncviewer' manual page.
# VNCSERVERS="2:myusername"
# VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -nohttpd -localhost"
VNCSERVERS="2:xfcy 3:root" #設定在vncserver啟動2個display,且display:2,:3的使用者權限分别為xfcy,root
VNCSERVERARGS[2]="-geometry 800x600"
VNCSERVERARGS[3]="-geometry 800x600 -localhost" #設定display:2的分辨率為800×600且隻監聽本地
設定VNC密碼(儲存在~/.vnc/passwd中),同時自動生成~/.vnc/xstartup(在每次啟動VNC服務時候,都會讀取該檔案中的配置資訊)
[root@rhel6 ~]# vncpasswd
Password:
Verify:
修改xstartup配置檔案
[root@rhel6 ~]# cat ~/.vnc/xstartup
#!/bin/sh
[ -r /etc/sysconfig/i18n ] && . /etc/sysconfig/i18n
export LANG
export SYSFONT
vncconfig -iconic &
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
OS=`uname -s`
if [ $OS = 'Linux' ]; then
case "$WINDOWMANAGER" in
*gnome*)
if [ -e /etc/SuSE-release ]; then
PATH=$PATH:/opt/gnome/bin
export PATH
fi
;;
esac
fi
if [ -x /etc/X11/xinit/xinitrc ]; then
exec /etc/X11/xinit/xinitrc
if [ -f /etc/X11/xinit/xinitrc ]; then
exec sh /etc/X11/xinit/xinitrc
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
#xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & #注釋掉這兩行避免出現黑屏
#twm &
gnome-session & #登入到GNOME桌面環境
#startkde & #登入到KDE桌面環境
配置Display:2(即使用者權限為xfcy的共享桌面,配置方法同上)
[root@rhel6 .vnc]# su - xfcy #必須在對應的使用者下設定密碼
[xfcy@rhel6 ~]$ vncserver :2
You will require a password to access your desktops.
New 'rhel6.xfcy.org:2 (xfcy)' desktop is rhel6.xfcy.org:2
Creating default startup script /home/xfcy/.vnc/xstartup
Starting applications specified in /home/xfcy/.vnc/xstartup
Log file is /home/xfcy/.vnc/rhel6.xfcy.org:2.log
[xfcy@rhel6 ~]$ vi .vnc/xstartup
#xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
gnome-session &
重新開機VNC Server服務
[root@rhel6 ~]# /etc/init.d/vncserver restart
Shutting down VNC server: 2:xfcy 3:root [ OK ]
Starting VNC server: 2:xfcy
3:root
New 'rhel6.xfcy.org:3 (root)' desktop is rhel6.xfcy.org:3
Log file is /root/.vnc/rhel6.xfcy.org:3.log
[ OK ]
[root@rhel6 .vnc]# netstat -lntp | grep 590 #VNC server監聽的端口從5900開始,display :1的監聽5901,display :2監聽5902,以此類推
tcp 0 0 0.0.0.0:5902 0.0.0.0:* LISTEN 3567/Xvnc
tcp 0 0 127.0.0.1:5903 0.0.0.0:* LISTEN 3649/Xvnc
用戶端通路
[root@rhel5 ~]# vncviewer 192.168.1.119:3
VNC Viewer Free Edition 4.1.2 for X - built Jan 26 2009 11:52:08
Copyright (C) 2002-2005 RealVNC Ltd.
See http://www.realvnc.com for information on VNC.
Sun Nov 18 23:17:16 2012
CConn: connected to host 192.168.1.119 port 5903
CConnection: Server supports RFB protocol version 3.8
CConnection: Using RFB protocol version 3.8
Sun Nov 18 23:17:18 2012
TXImage: Using default colormap and visual, TrueColor, depth 16.
CConn: Using pixel format depth 6 (8bpp) rgb222
CConn: Using ZRLE encoding
Sun Nov 18 23:17:21 2012
CConn: Throughput 20476 kbit/s - changing to hextile encoding
CConn: Throughput 20476 kbit/s - changing to full colour
CConn: Using pixel format depth 16 (16bpp) little-endian rgb565
CConn: Using hextile encoding
通過SSH加密VNC的遠端連接配接
[root@rhel5 ~]# vncviewer -via 192.168.1.119 :2
The authenticity of host 'rhel6 (192.168.1.119)' can't be established.
RSA key fingerprint is 1a:cf:92:de:28:7d:f2:e0:e8:e6:ad:f1:7c:40:6a:67.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'rhel6' (RSA) to the list of known hosts.
root@rhel6's password:
Tue Nov 20 01:12:37 2012
CConn: connected to host localhost port 5599
Tue Nov 20 01:12:39 2012
Tue Nov 20 01:12:41 2012
CConn: Throughput 20588 kbit/s - changing to hextile encoding
CConn: Throughput 20588 kbit/s - changing to full colour
<a href="http://blog.51cto.com/attachment/201211/220954381.png" target="_blank"></a>
關閉已啟用的display:2
[xfcy@rhel6 ~]$ vncserver -kill :2 #必須以相應的使用者進行操作
Killing Xvnc process ID 3567
Xvnc seems to be deadlocked. Kill the process manually and then re-run
/usr/bin/vncserver -kill :2
to clean up the socket files.
[root@rhel6 ~]# netstat -lntp | grep 590
tcp 0 0 127.0.0.1:5903 0.0.0.0:* LISTEN 6585/Xvnc
附:AIX上部署VNC Server
一.安裝VNC
# rpm -ivh vnc-3.3.3r2-6.aix5.1.ppc.rpm
vnc ##################################################
# rpm -ql vnc
/opt/freeware/bin/Xvnc
/opt/freeware/bin/vncconnect
/opt/freeware/bin/vncpasswd
/opt/freeware/bin/vncserver
/opt/freeware/bin/vncviewer
/opt/freeware/doc/vnc-3.3.3r2
/opt/freeware/doc/vnc-3.3.3r2/LICENCE.TXT
/opt/freeware/doc/vnc-3.3.3r2/README
/opt/freeware/share/vnc/classes
/opt/freeware/share/vnc/classes/DesCipher.class
/opt/freeware/share/vnc/classes/animatedMemoryImageSource.class
/opt/freeware/share/vnc/classes/authenticationPanel.class
/opt/freeware/share/vnc/classes/clipboardFrame.class
/opt/freeware/share/vnc/classes/index.vnc
/opt/freeware/share/vnc/classes/optionsFrame.class
/opt/freeware/share/vnc/classes/rfbProto.class
/opt/freeware/share/vnc/classes/shared.vnc
/opt/freeware/share/vnc/classes/vncCanvas.class
/opt/freeware/share/vnc/classes/vncviewer.class
/opt/freeware/share/vnc/classes/vncviewer.jar
/opt/freeware/vnc
/usr/lpp/X11/bin/Xvnc
/usr/lpp/X11/bin/vncconnect
/usr/lpp/X11/bin/vncpasswd
/usr/lpp/X11/bin/vncserver
/usr/lpp/X11/bin/vncviewer
二.編輯配置檔案:/opt/freeware/bin/vncserver
1.修改前:
# $cmd .= " -fp /usr/lib/X11/fonts/,/usr/lib/X11/fonts/misc/,/usr/lib/X11/fonts/75dpi/";
修改後:(去掉注釋,即加入了fonts)
$cmd .= " -fp /usr/lib/X11/fonts/,/usr/lib/X11/fonts/misc/,/usr/lib/X11/fonts/75dpi/";
$cmd .= " -ac -fp /usr/lib/X11/fonts/,/usr/lib/X11/fonts/misc/,/usr/lib/X11/fonts/75dpi/"; (若出現灰屏則設定為此)
2.修改前:
$vncClasses = "/usr/local/vnc/classes";
修改後:
$vncClasses = "/opt/freeware/vnc/classes";
# cat /opt/freeware/bin/vncserver | egrep "font|vncClasses" | grep -v ^#
$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/";
三.如果要使用CDE界面(AIX下的XWindow,類似于Redhat的GNOME)
# vi ~/.vnc/xstartup
xrdb $HOME/.Xresources
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
# twm & #注釋掉原來的配置
/usr/dt/bin/dtsession & #添加CDE界面的session
四.啟動vncserver
# su oracle
$ vncserver
Password:
Verify:
New 'X' desktop is fjkf:1
Creating default startup script /home/oracle/.vnc/xstartup
Starting applications specified in /home/oracle/.vnc/xstartup
Log file is /home/oracle/.vnc/fjkf:1.log
本文轉自Vnimos51CTO部落格,原文連結:http://blog.51cto.com/vnimos/1073504,如需轉載請自行聯系原作者