1.首先查詢是否安裝VNC Server
rpm -qa |grep vnc
如果有類似於:
vnc-server-
的值返回說明已經安裝了vnc-server
如果沒有安裝採用yum安裝
yum -y install vnc
2.配置VNC使用者如果以root登入的話,輸入
vncpasswd
Password:
Verify:
設定root使用者的VNC登入使用者名稱和密碼
3.配置vnc-server的設定檔
/etc/sysconfig/vncservers
內容如下:
# 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="1:root"
# VNCSERVERS="2:myusername"
# VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -nohttpd -localhost"
VNCSERVERARGS[1]="-geometry 800x600"
1.VNCSERVERS=後面可以支援多使用者,以空格隔開。如:
VNCSERVERS="1:myusername 15:otheruser"--->這裡的1 和15是連接埠號碼,用於串連時的連接埠
2.VNCSERVERARGS後面的[]裡面的資料要與VNCSERVERS後面對應使用者的值要一致。好像不一致也沒有關係
VNCSERVERARGS基本參數有:
-geometry 案頭大小,預設是1024x768
-nohttpd 不監聽HTTP連接埠
-nolisten tcp 不監聽X連接埠
-localhost 只允許從本機訪問
-AlwaysShared 預設的, 同時只能有一個vncviewer串連(跟用戶端配置也有關), 一旦第2個連上去, 第1個就被斷開了. 此參數允許同時連多個vncviewer
-SecurityTypes None登入不要求輸入密碼認證 VncAuth預設值,要密碼認證
啟動vncserver
/sbin/nvcserver start
如果沒有出錯的話,就會啟動vnc服務了
4.修改預設案頭設定
在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 80x24 10 10 -ls -title "$VNCDESKTOP Desktop" &
#twm & ---把這兩行注釋掉,加上
#exec startxfce4
gnome-session
重新啟動vncserver
netstat -antpl查看可以發現有三個連接埠在監聽。
5901 5801 6001
這三個連接埠:
預設的, vnc 服務監聽3個TCP連接埠
RFB(Remote FrameBuffer)協議 預設連接埠 : 5900 顯示器號
HTTP協議預設連接埠 : 5800 顯示器號
X協議 預設連接埠 : 6000 顯示器號
vncserver使用的顯示器編號預設從1開始, 依次使用, 也可以參數指定連接埠號碼
我們只需要RFB協議就可以了,所以我們把5800 6000這兩種連接埠關掉。
需要修改/etc/sysconfig/vncservers
在參數後面加上:
-nohttpd 不監聽HTTP連接埠
-nolisten tcp 不監聽X連接埠
5. Windows登陸到VNC Server
(1).從IE登入
直接從IE瀏覽器中輸入如下地址:
http://xxx.xxx.xxx.xxx:5801
輸入密碼即可使用。
(2).從VNC view登入
在windows上安裝vnc view,然後輸入xxx.xxx.xxx.xxx:1,串連登入,輸入密碼即可。
備忘:如果從vnc view登入時,提示connection refused(10061),則是因為linux防火牆的問題,登入centos系統,選擇 System-->Preferences-->Remote Desktop,勾選sharing中的兩項,Security兩項不勾,點擊關閉,然後再重新用vnc view登入即可。