VNC最初由AT&T開發的,它的源代碼是開源的。
1. 檢查vnc用戶端和伺服器是否已經安裝:
[root@localhost ~]# rpm -q vnc
package vnc is not installed
[root@localhost ~]# rpm -q vnc-server
package vnc-server is not installed
沒有安裝的話。在CD光牒裡找到rpm包安裝
[root@localhost ~]# [root@localhost ~]# mount /dev/cdrom /media/
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@localhost ~]# cd /media/CentOS/
[root@localhost CentOS]# rpm -ivh vnc-server-4.1.2-14.el5.i386.rpm
warning: vnc-server-4.1.2-14.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID e8562897
Preparing... ########################################### [100%]
1:vnc-server ########################################### [100%]
[root@localhost ~]# rpm -ivh /mnt/cdrom/CentOS/vnc-4.1.2-9.el5.i386.rpm
1:vnc ########################################### [100%]
這裡已經安裝成功。
2. 将使用者名稱加入到配置檔案:(/etc/sysconfig/vncservers)
(注:這裡的“使用者名”是指linux系統使用者的名稱)
# 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
# <URL:http://www.uk.research.att.com/archive/vnc/sshvnc.html>.
# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
# Use "-nohttpd" to prevent web-based VNC clients connecting.
# 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="1:root"
VNCSERVERARGS[1]="-geometry 800x600 "
這裡注意一下,預設系統配置裡有 –nolisten tcp 和 –nohttpd ,這兩個是阻止Xwindows登陸和HTTP方式VNC登陸的,如果需要圖形界面,那就删除這部分。
3. 設定密碼
[root@localhost ~]# vncpasswd
Password:
Verify:
[root@localhost ~]#
注意這裡設定的密碼不是root使用者的密碼,而且我們用vncview用戶端登入時的密碼。也就是這個vnc軟體的密碼。
4. 啟動VNC服務
[root@localhost ~]# /sbin/service vncserver start
Starting VNC server: 1:root xauth: creating new authority file /root/.Xauthority
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
[ OK ]
注意:此時在/root/.vnc已經有VNC登陸的啟動檔案xstartup,和日志檔案localhost:1.log。這一步很重要,之後我們才可以修改xstartup這個檔案。
5.修改xstartup
[root@localhost ~]# cd /root/.vnc/
[root@localhost .vnc]# vi 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 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
gnome-session
#startkde & #kde desktop
#twm &
注意: 這一步也很重要,如是不修改這個檔案的話也連不到桌面,是一片空白,是以要加上相應的桌面的參數。
6. 最後,需要配置一下防火牆,允許VNC用戶端連接配接VNC server。VNC server監聽的端口從5900開始,display :1的監聽5901,display :2監聽5902,以此類推。CentOs的防火牆預設是不允許連接配接這些端口的,是以需要使用下面的步驟打開防火牆(需要root權限):
[root@localhost ~]# vi /etc/sysconfig/iptables
# Firewall configuration written by system-config-securitylevel
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p 50 -j ACCEPT
-A RH-Firewall-1-INPUT -p 51 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp --dport 5353 -d 224.0.0.251 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5900:5903 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT
在此行之前,加上下面的内容:
這句話的含義是,允許其它機器通路本機的5900到5903端口,這樣,display:1, display:2, display:3的使用者就可以連接配接到本機。
然後使用root身份重新啟動防火牆和VNC:
[root@localhost ~]# /sbin/service iptables restart
Flushing firewall rules: [ OK ]
Setting chains to policy ACCEPT: filter [ OK ]
Unloading iptables modules: [ OK ]
Applying iptables firewall rules: [ OK ]
Loading additional iptables modules: ip_conntrack_netbios_n[ OK ]
[root@localhost ~]# /sbin/service vncserver resatrt
Usage: /etc/init.d/vncserver {start|stop|restart|condrestart|status}
[root@localhost ~]# /sbin/service vncserver restart
Shutting down VNC server: 1:root [ OK ]
Starting VNC server: 1:root
7. Windows登陸到VNC Server
Windows 用戶端 VNC Viewer 的配置: 1. 從 http://www.realvnc.com/download.html 下載下傳 VNC Free Edition for Windows Version 4.1.2 2. 打開 VNCViewer : 填入VNCServer 的IP:編号(1或2或...) 3. VNCViewer 切換全屏模式:F8
注意我的選項
這個密碼就是vncpasswd的密碼
哈哈。已經成功啦。
8. 允許VNC server在系統啟動過程中被啟動。這可以通過“系統設定–>伺服器設定–>服務”菜單來配置,把vncserver一項選上就可以了。
如果使用指令行的話,以root身份運作以下兩條指令:
cd /etc/rc5.d
mv K35vncserver S35vncserver
另外可以再終端裡輸入:ntsysv 找到vncserver這項勾上。
9.如果是在VMware上裝的話,還需要這樣設定一步
虛拟機——設定——選項——遠端顯示——啟用
密碼填不填都行。