Linux遠端桌面,linux
在機房折磨很久弄好的自己 Mark 一下。(測試環境rhel5.5)
vnc 之獨立服務配置
步驟1:
(1)查看系統是否安裝vnc服務(也可以在 系統-管理員-服務 裡查看並勾選開機自啟)
# rpm -qa | grep vnc
(如果有傳回值,類似於vnc-server的值,說明已經安裝了vnc-server此步驟就可跳過。)
(2)安裝vnc:
(進入掛載目錄) # cd /rhdvd/Server (安裝 vnc-server)# rpm -ivh vnc-server-4.1.2-14.el5_6.6.x86_64.rpm(安裝 vnc-viewer)# rpm -ivh vnc-4.1.2-14.el5_6.6.x86_64.rpm
View Code
(3)驗證vnc-server包是否安裝成功:
# rpm -qa vnc-server-4(顯示 vnc-server-4.1.2-14.el5_6.6)
View Code
步驟2:
(1)運行vnc服務
# vncservers
(首次運行需要輸入vnc密碼,此密碼為目前使用者root的vnc密碼)
(2)添加使用者和設定密碼並設定vnc密碼:
# useradd user001 (添加使用者)# passwd user001 (設定使用者密碼)# su - user001 (切換使用者)# vncpasswd (設定vnc密碼,密碼檔案在 /使用者/.vnc/passwd)
(注意,這裡的vncpass只能在vnc本使用者下面來運行。比如要是想配置使用者名稱為user001的vnc認證密碼,需要先切換到user001使用者,之後再運行vncpasswd命令)
(3)重複建立user002、user003.......
步驟3:
在配置VNC前,必須瞭解VNC的運行機制
Linux下的VNC可以同時啟動多個vncserver,各個vncserver之間用顯示編號(display number)來區分,每個vncserver服務監聽3個連接埠,它們分別是:
HTTP協議預設連接埠 5800+顯示編號 : VNC的http監聽連接埠,如果VNC用戶端為IE,Firefox等非vncviewer時必須開放。
RFB協議預設連接埠 5900+顯示編號 : VNC服務端與用戶端通訊的真正連接埠,必須無條件開放。
X協議預設連接埠 6000+顯示編號 : X監聽連接埠,可選。
顯示編號、開放的連接埠分別由/etc/sysconfig/vncservers檔案中的VNCSERVERS和VNCSERVERARGS控制。
(1)配置vnc服務的設定檔
# vi /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="2:myusername"# VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -nohttpd -localhost"VNCSERVERS="1:user001 2:user002 3:user003 4:user004" (添加)VNCSERVERARGS[1]="-geometry 1366x768 -AlwaysShared" (添加)VNCSERVERARGS[2]="-geometry 1366x768 -AlwaysShared" (添加)VNCSERVERARGS[3]="-geometry 1366x768 -AlwaysShared" (添加)VNCSERVERARGS[4]="-geometry 1366x768 -AlwaysShared" (添加)
View Code
說明:【1】VNCSERVERS=後面可以支援多使用者,以空格隔開,數字為連接埠號碼即案頭號。
【2】VNCSERVERARGS後面的[]裡面的資料要與VNCSERVERS後面對應使用者的值要一致。VNCSERVERARGS基本參數有:
-geometry 案頭大小,預設是1024x768解析度-nohttpd 不監聽HTTP連接埠,58xx連接埠(建議不寫) -nolisten tcp 不監聽X連接埠,60xx連接埠(建議不寫) -localhost 只允許從本機訪問(不寫)-SecurityTypes None 登入不要求輸入密碼認證VncAuth,預設要密碼認證-depth 表示色深,參數有8,16,24,32-AlwaysShared 預設只能有一個vncviewer串連(跟用戶端配置也有關),一旦第2個連上去,第1個就被斷開了,此參數允許同時連多個vncviewer
View Code
步驟四:
(1)啟動vncserver
# service vncserver start (即時開啟服務並生效)# /etc/init.d/vncserver start# service vncserver stop (即時關閉服務並生效)# /etc/init.d/vncserver stop# chkconfig vncserver on (將vncserver設定為開機啟動,重啟生效)# chkconfig vncserver off (將vncserver設定為開機不啟動,重啟生效)
步驟五:
(1)配置VNC圖形案頭環境
vnc都配置完畢並且正常運行,但是用VNC-Viewer登入後顯示的螢幕卻為灰色(也有黑色的),並且無法進行任何操作。
原來VNC xstartup程式中預設的設定值是啟動twm,而不是GNOME或KDE。
【1】修改xstart檔案:
# vi /home/使用者/.vnc/xstartup (root使用者為 /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/.Xresourcesxsetroot -solid greyvncconfig -iconic &# xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & (註解此行)gnome-session & (添加)# twm & (註解此行)
View Code
說明: 也可只註解最後一行 twm & ,並添加一行 gnome-session &。
也可只去掉3、4句註解。
最好方式是都改一下。
【2】修改完需重啟vncserver:
# service vncserver restart (重啟全部vnc案頭,不建議用此條命令)# vncserver -kill :1 (停止第一個案頭)# vncserver :1 (啟動第一個案頭)
步驟六:
(1)配置防火牆
# 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 5901 -j ACCEPT (添加)-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5902 -j ACCEPT (添加)-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5903 -j ACCEPT (添加)-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5904 -j ACCEPT (添加)-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibitedCOMMIT
View Code
也可關閉防火牆(不建議):
# service iptables stop (即時關閉防火牆,重啟失效)# chkconfig iptables off (永久關閉防火牆,重啟有效)
View Code
步驟七:
192.168.10.131:1——這裡的:1就是連接埠號碼,指的是5900+1,這個1是在/etc/sysconfig/vncservers裡面指定的。
這個數字在100以下,不含100的時候可以直接用192.168.10.131:1來表示。
如果在vncservers裡面指定的數值大於100 包含100的時候,在串連的時候就需要用到完整的連接埠數值。
如:在vncservers裡面指定的是100,那麼在串連的時候就應該是這樣的:192.168.10.131:6000。
如有錯誤還請指出,如有侵權還請告知,如需轉載請註明出處!
本人部落格:http://www.cnblogs.com/yllinux/