VNC常用操作及常見問題解決辦法彙總

滄海一滴發表於2014-05-31

 

VNC登入使用者預設是root,但在安裝oracle時必須用oracle使用者的身份登入,下面我們就以oracle為例說明如何配置VNC,從而可以使用不同的使用者登入到主機。
步驟描述如下:
    步驟一:修改/etc/sysconfig/vncservers,新增oracle使用者,修改後內容如下:
        VNCSERVERS="1:root 2:root 3:oracle"
        VNCSERVERARGS[1]="-geometry 1024x768"
        VNCSERVERARGS[2]="-geometry 1024x768"
        VNCSERVERARGS[3]="-geometry 1024x768"

    步驟二:在系統中新建oracle使用者
        useradd oracle
        passwd oracle
        
    步驟三:將root使用者下的路徑複製到oracle使用者的home路徑下,並修改路徑所屬使用者及組:
        cp -r /root/.vnc ~oracle/.vnc
        chown oracle ~oracle/.vnc/
        chown oracle.oinstall -R ~oracle/.vnc/
        chown oracle ~oracle/.vnc/*
        chown oracle.oinstall -R ~oracle/.vnc/*
       
    步驟四:重啟VNC,觀察id為3的埠是否啟動
        service vncserver restart
        netstat -anlpt | grep 5903
        vnc的埠從5901開始,每增加一個使用者,埠號就在5901上加1。如果要單獨關閉指定id的埠,可以使用命令:
        vncserver -kill :id
        如:
        vncserver -kill :1
        vncserver -kill :2
        就將關閉5901和5902兩個VNC埠

http://blog.sina.com.cn/s/blog_4a0a14170100f5lo.html

http://www.hackbase.com/tech/2012-03-21/66032.html





 

 

 

 

 

 

 

1、安裝
yum install vnc*
2、啟動
/etc/init.d/vncserver start
Starting VNC server: no displays configured                [  OK  ]
3、配置使用者名稱
CODE:[root@localhost ~]#  vi /etc/sysconfig/vncservers
# The VNCSERVERS variable is a list of display:user pairs.
#
# Uncomment the line below to start a VNC server on display :1
# 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/vnc/sshvnc.html
                                                                                            
# VNCSERVERS="1:myusername"
VNCSERVERS="1:root" (注意:root是CentOS使用者名稱)
如果建2個,可以用VNCSERVERS="1:root 2:linglong"來配置
3.用vncpasswd建立一個vnc的口令

注意這將同時在你的home目錄下,建立一個隱藏的目錄.vnc,其中有一個檔案passwd儲存著你的vnc口令.
CODE:
[root@localhost ~]# vncpasswd
Password:
Verify:
[root@localhost ~]# ls -d .vnc
.vnc
[root@localhost ~]# ls .vnc
passwd
4.啟動vnc服務.
CODE:[root@localhost ~]#  /sbin/service vncserver restart
Shutting down VNC server: 1:root                          [ OK ]
Starting VNC server: 1:root perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
       LANGUAGE = (unset),
       LC_ALL = (unset),
       LANG = "zh_EN.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:1.log
                                                      [ OK ]
察看一下.vnc這個目錄的內容,應該類似於下面的東西.
注:在這裡我剛開始出現“Warning: *****   is taken because of /tmp/.X1-lock”
在網上找了好多方法,終於找到解決辦法了!
   我直接將: /tmp/.X1-lock 刪除就可以 了 ,命令式: rm /tmp/.X1-lock
如果還出現其他的檔案錯誤 也可照樣操作!
CODE:[root@localhost ~]# cd .vnc
[root@localhost .vnc]# ls
localhost.localdomain:1.log localhost.localdomain:2.log passwd
localhost.localdomain:1.pid localhost.localdomain:2.pid xstartup
[root@localhost .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

因為我們已經修改了啟動指令碼,現在來重新啟動vncserver.
CODE:[root@localhost .vnc]#   /sbin/service vncserver restart
Shutting down VNC server: 1:root                          [ OK ]
Starting VNC server: 1:root perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
       LANGUAGE = (unset),
       LC_ALL = (unset),
       LANG = "zh_EN.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:1.log
                                                      [ OK ]
[root@localhost .vnc]#
5.防火牆埠設定
在使用防火牆的情況下來連線到一個遠端系統,需要開啟埠5901.
加入以下紅色的部分,然後重啟iptables服務。
[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   ]
[root@localhost ~]#

 

 

 

vim      /root/.vnc/xstartup   oracle使用者 (/home/oracle/.vnc/xstartup)
twm &(預設文字型別桌面)修改為gnome-session(GNOME風格的桌面環境) startkde & (KDE風格桌面) 

 

 

 

Redhat下VNC SERVER的配置

1、啟動VNC SERVER

輸入vncserver,第一次啟動會要求輸入驗證密碼,完成後,VNC SERVER就啟動了

    [root@localhost ~]# vncserver

    You will require a password to access your desktops.

    Password:            //輸入密碼
    Verify:                  //再次輸入密碼
    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

    [root@localhost ~]#

2、編輯.vnc/xstartup

使用VI開啟xstartup檔案,如下:

    [root@localhost /]# cd /root/.vnc
    [root@localhost .vnc]# vi xstartup

刪除全部內容,然後新增如下內容:

    unset SESSION_MANAGER
    exec /etc/X11/xinit/xinitrc


3、重啟動VNC SERVER

    [root@localhost ~]# vncserver -kill :1
    Killing Xvnc process ID 21198

    [root@localhost ~]# vncserver

    New ‘localhost.localdomain:1 (root)’ desktop is localhost.localdomain:1

    Starting applications specified in /root/.vnc/xstartup
    Log file is /root/.vnc/localhost.localdomain:1.log

    [root@localhost ~]#

4、檢視VNC的監聽埠

如下,VNC用到了三個埠:5801、5901、6001。
    [root@localhost /]# netstat -nat
    Active Internet connections (servers and established)
    Proto Recv-Q Send-Q Local Address               Foreign Address             State
    tcp        0      0 127.0.0.1:2208              0.0.0.0:*                   LISTEN
    tcp        0      0 0.0.0.0:5801                0.0.0.0:*                   LISTEN
    tcp        0      0 0.0.0.0:5901                0.0.0.0:*                   LISTEN
    tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN
    tcp        0      0 0.0.0.0:6001                0.0.0.0:*                   LISTEN
    tcp        0      0 0.0.0.0:724                 0.0.0.0:*                   LISTEN
    tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN
    tcp        0      0 127.0.0.1:2207              0.0.0.0:*                   LISTEN
    tcp        0      0 172.200.102.3:5901          181.181.181.51:1669         ESTABLISHED
    tcp        0      0 :::6001                     :::*                        LISTEN
    tcp        0      0 :::22                       :::*                        LISTEN
    tcp        0   1364 ::ffff:172.200.102.3:22     ::ffff:181.181.181.51:1599  ESTABLISHED
    [root@localhost /]#
5、在防火牆上開啟VNC用到的上面三個埠
    [root@localhost /]# cd /etc/sysconfig
    [root@localhost sysconfig]# vi iptables

新增如下三行:
    -A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 5801 -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 6001 -j ACCEPT
重記動IPTABLES
    [root@localhost sysconfig]# /etc/rc.d/init.d/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_ns ip_conntrack_ftp [  OK  ]



    [root@localhost sysconfig]#
6、使用VNC VIEW連線VNC SERVER
下載VNC VIEW,執行,然後輸入IP:埠號,輸入剛才設定的密碼,進入REDHAT桌面。
http://www.aixchina.net/club/archiver/tid-27685.html

1、安裝VNC

yum install vnc-server
2、新增多個使用者
useradd user1  //新增使用者user1
passwd user1  //設定使用者的linux登入密碼

su - user1          //切換到使用者user1
vncpasswd      //設定使用者的user1登入密碼
exit

useradd user2  //新增使用者user2
passwd user2  //設定使用者的linux登入密碼

su - user2         //切換到使用者user2
vncpasswd     //設定使用者的user2登入密碼
exit
3、編輯vnc配置檔案
vi /etc/sysconfig/vncservers
在最後加上:
VNCSERVERS="1:user1 2:user2"
VNCSERVERARGS[1]="-geometry 1024x768 -alwaysshared"  
VNCSERVERARGS[2]="-geometry 1024x768 -alwaysshared"
注意:-geometry 1024x768表示解析度;-alwaysshared 表示允許多終端同時登陸

配置多個桌面
Linux下VNC配置多個桌面和修改密碼

可以使用如下的方法啟動多個桌面的VNC   
vncserver :1   vncserver :2   vncserver :3   ……   
但是這種手工啟動的方法在伺服器重新啟動之後將失效,因此,下面介紹如何讓系統自動管理多個桌面的VNC,
方法是將需要自動管理的資訊新增到/etc/sysconfig/vncservers配置檔案中,先以桌面1為root使用者桌面2為oracle使用者為例進行配置如下:   
格式為:VNCSERVERS="桌面號:使用的使用者名稱 桌面號:使用的使用者名稱"   
[root@testdb ~]# vi /etc/sysconfig/vncservers   
VNCSERVERS="1:root 2:oracle"   
VNCSERVERARGS[1]="-geometry 1024x768"   
VNCSERVERARGS[2]="-geometry 1024x768"   
修改VNC訪問的密碼   
使用命令vncpasswd對不同使用者的VNC的密碼進行修改,一定要注意,如果配置了不同使用者的VNC需要分別到各自使用者中進行修改,例如在我的這個實驗中,root使用者和oracle使用者需要分別修改,修改過程如下:   
[root@testdb ~]# vncpasswd   
Password:   
Verify:
或vncpasswd oracle
vncpasswd root
 

 

4、開啟對應的埠

開啟5901至5902 埠用於vnc  //如果需要配置更多的桌面,增加埠即可
iptables -I INPUT -p tcp --dport 5901:5902 -j ACCEPT
iptables -A INPUT -p tcp --dport 5901:5902 -j ACCEPT
永久儲存
service iptables save
4.啟動vncserver服務

service vncserver restart後vncview仍無法連線到vncserver,
此時可使用vncserver -list檢視桌面,然後使用vncserver -kill :桌面號,最後使用vncserver :桌面號啟動即可

 


1)啟動全部桌面
   service vncserver start 
2)啟動某一桌面
   vncserver :1   //這裡1表示第一個桌面

5、停止vncserver服務

1)停止全部桌面
   service vncserver stop
2) 停止某一桌面
    vncserver -kill :1   //停止第1個介面,要用kill命令來殺掉介面1的程式

6、檢視當前有幾個桌面在執行

    service vncserver status

7、讓vncserver服務隨機啟動

預設狀態下,vncserver服務不是開機自動啟動,需要手工啟動。
chkconfig --list vncserver
chkconfig vncserver on
儲存後,重啟測試。

8.客戶端登入vncserver服務

(1)先安裝vncviewer來遠端登入,
(2)然後在位址列輸入“主機地址:1”(即主機IP加介面號的方式)

 http://blog.sina.com.cn/s/blog_4ab088470100x605.html

http://blog.csdn.net/jkxsanger/article/details/8897306

1.安裝VNC

# rpm -ivh rpm -ivh vnc-server-4.1.2-9.el5.i386.rpm

# rpm -ivh vnc-4.1.2-9.el5.i386.rpm

 

VNC是Virtual Network Computing(虛擬網路計算機)的縮寫。VNC是由AT&T的歐洲研究實驗室開發的一款優秀的跨平臺遠端桌面控制軟體,支援 Linux,Unix,Windows等作業系統跨平臺遠端桌面控制。VNC有兩部分組成,分別是:服務端(vncserver)和客戶端 (vncviewer)

1. 在配置VNC前,必須瞭解VNC的執行機制

Linux下的VNC可以同時啟動多個vncserver,各個vncserver之間用顯示編號(display number)來區分,每個vncserver服務監聽3個埠,它們分別是:
5800+顯示編號:  VNC的httpd監聽埠,如果VNC客戶端為IE,Firefox等非vncviewer時必須開放。
5900+顯示編號:  VNC服務端與客戶端通訊的真正埠,必須無條件開放。
6000+顯示編號:  X監聽埠,可選。

顯示編號開放的埠分別由/etc/sysconfig/vncservers檔案中的VNCSERVERSVNCSERVERARGS控制。

VNCSERVERS的設定方式為
“VNCSERVERS="顯示編號1:使用者名稱1 …"”,如:VNCSERVERS="1:root 2:aiezu"。

VNCSERVERARGS的設定方式為
VNCSERVERARGS[顯示編號1]="引數一 引數值一 引數二 引數值二  ……",
如VNCSERVERARGS[2]="-geometry 800x600 -nohttpd",

VNCSERVERARGS的詳細引數有:
-geometry    桌面解析度,預設1024x768;
-nohttpd    不監聽HTTP埠(58xx埠);
-nolisten tcp    不監聽X埠(60xx埠);
-localhost    只允許從本機訪問;
-AlwaysShared    預設只同時允許一個vncviewer連線,此引數允許同時連多個vncviewer;
-SecurityTypes None    登入不需要密碼認證VncAuth預設值,要密碼認證。

 2. 修改/etc/sysconfig/vncserver檔案

vi /etc/sysconfig/vncserver

VNCSERVERS="1:root"
VNCSERVERARGS[1]="-geometry 1024x768 -nolisten tcp"

 

本例我們開啟兩個vncserver,分別是root使用者,顯示編號為1和使用者user2,顯示編號為3,並且全不開啟X監聽埠60xx。

vi /etc/sysconfig/vncserver,新增如下三行:

VNCSERVERS="1:root 3:user2"

VNCSERVERARGS[1]="-geometry 800x600 -nolisten tcp -nohttpd -alwaysshared"

VNCSERVERARGS[3]="-geometry 1024x768 -nolisten tcp -nohttpd -alwaysshared"

 

防火牆相關:

如果Linux啟用了防火牆,必須允許VNC的相關埠(58xx,59xx,60xx)。具體的埠,請參照第2大步驟的①小步驟的VNC執行機制介紹,本例開啟,5901,5903埠就可以。在Linux命令提示符下輸入"system-config-securitylevel-tui"啟動防火牆配置工具,點"Customize",在"Other Port"中輸入" 5901:tcp 5903:tcp",然後點"OK"既可。

3. 設定VNC使用者密碼

接下來設定VNC的密碼,此步驟不可跳過,否則VNC Server將無法啟動,在Linux Shell下執行下列命令:

# vncpasswd

 

設定VNC使用者密碼:此步驟不可跳過,否則VNC Server將無法啟動

# su - user2

# vncpasswd

# su - root

# vncpasswd

4. 啟動VNC

# service vncserver start

執行上面命令後,會在使用者根目錄($HOME)下的".vnc"資料夾下生成一系列檔案。其中passwd為vnc使用者密碼檔案,由vncpasswd生成。其他的都由vnc初次啟動時生成,xstartup為VNC客戶端連線時啟動的指令碼

5. 修改".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 &

就是去掉相關行的註釋即可。

修改下面配置完成介面化的實現...
   vi /root/.vnc/xstartup 去除註釋下面兩行的注釋,使之生效。
   unset SESSION_MANAGER
   exec /etc/X11/xinit/xinitrc
最後一行修改為:gnome-session &

 

執行到上面步驟後,VNC Server已經能正常執行。但是預設設定下,客戶連線時啟動的是xterm,我們如果想看到桌面,必須將使用者根目錄下的".vnc/xstartup"檔案中的最後兩行註釋掉,然後根據你安裝的桌面壞境,新增一行"startkde &"或者"gnome-session &"。如下:

#!/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 &

startkde &

# gnome-session &

配置完各個使用者根目錄下的".vnc/xstartup"後,執行service vncserver restart 重新啟動vncserver使配置生效。

6. 如果Linux啟用了防火牆,必須允許VNC的相關埠(58xx,59xx,60xx)

7. 在windows下使用IE進行遠端控制連線:

使用瀏覽器連線時,服務端的VNCSERVERARGS設定必須沒有"-nohttpd引數",並且防火牆允許VNC的58xx和59xx埠通過。瀏覽器必須安裝了Java支援外掛,Java外掛下載地址:http://www.java.com/zh_CN/download/manual.jsp

8. 如何使得linux啟動時,vnc服務自動啟動...
   a. 系統設定>伺服器設定>服務 中把 vncserver 打勾
   b. chkconfig vncserver on

常見問題:

問:為什麼成功連線後,沒有顯示桌面,而只是現實一個Terminal視窗? 答:在未修改使用者根目錄下的".vnc/xstartup"檔案,xstartup的預設設定即是此情況。請按上面檔案修改xstartup,然後執行"service vncserver restart"重新啟動vncserver服務即可。

問:如何檢視VNC正在執行的顯示編號埠號? 答:在Linux命令提示符下執行"netstat -tlup|grep vnc",即可以檢視到埠號,埠號的後兩位即顯示編號。

問:如何關閉指定的顯示編號? 答:vncserver -kill :number 即可以關閉指定的顯示編號和對應的埠號。

問:為何我通過瀏覽器連線VNC 埠時,瀏覽器顯示了一個紅叉。 答:那是因為你的瀏覽器沒裝Java外掛的緣故,下載Java外掛安裝即可。

問:客戶端連線時"Connetcion timed out(10060)"是怎麼回事? 答:對於客戶端連線時出現"Connetcion timed out(10060)"或者"No route to host:connect",請檢查防火牆是否開啟了58xx,59xx,vncserver是否正常執行,以及/etc/sysconfig /vncserver檔案配置是否正確。

 

 

 

客戶端的配置
如客戶端為windows ,用putty詳見SSH配置一文
客戶端為linux:
1.vncviewer localhost:2 在本機執行
2.用ssh
ssh -L 5901:localhost:5901 -l foo myserver
需在sudo vi /etc/sysconfig/iptables中開啟5901埠,
然後重啟iptables
sudo /sbin/service iptables restart
或者直接用ip地址

ssh -L 5901:localhost:5901 -l foo 192.168.x.x

 

1.設定vncserver啟動指令碼(/etc/init.d/vncserver)實現系統自啟動時啟動vncserver.
# 在/etc/rc.d/rc.local檔案中加入下面行
寫道
/etc/init.d/vncserver start
#也可以用chkconfig命令實現系統自啟動時啟動vncserver
[root@CPAYNET005 ~]# chkconfig --level 2345 vncserver on

2、編輯/etc/sysconfig/vncservers 

VNCSERVERS="1:root"
VNCSERVERARGS[1]="-geometry 1024x768"
 
在ARGS 中修改"1024x768"來適應自己的X桌面實際引數配置。可以在這裡新增任何其他VNC伺服器引數配置。在VNCSERVERS中修改 root 為你希望執行VNC桌面的使用者。VNCSERVERS中的1表示VNC以桌面1執行,如果希望新增其他的桌面,可以修改配置如下:

 寫道

VNCSERVERS="1:user1 2:user2 3:user3" 
3.設定vnc server的訪問密碼
使用vncpasswd命令
4、在RedHat系統上,使用以下命令啟動VNC:
/etc/init.d/vncserver start
5、檢視VNC Server啟動情況
[root@CPAYNET005 ~]# netstat -tulnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 0.0.0.0:5801                0.0.0.0:*                   LISTEN      5248/Xvnc
tcp        0      0 0.0.0.0:5901                0.0.0.0:*                   LISTEN      5248/Xvnc
tcp        0      0 0.0.0.0:6001                0.0.0.0:*                   LISTEN      5248/Xvnc
tcp        0      0 :::6001                     :::*                        LISTEN      5248/Xvnc
注:如果在瀏覽器中通過web方式訪問VNC則 埠為:5801,如果通過VNC客戶端(比如VNC Viewer)來訪問VNC則埠為:5901
 

NAME

Xvnc - an X server providing VNC connectivity

SYNOPSIS

Xvnc
[:display] [-geometry widthxheight] [-depth depth] [-pixelformat rgbNNN|bgrNNN] [-udpinputport port] [-rfbport port] [-rfbwait time] [-nocursor] [-rfbauthpasswd-file] [-httpd dir] [-httpport port] [-deferupdate time] [-economictranslate] [-lazytight] [-desktop name] [-alwaysshared] [-nevershared] [-dontdisconnect] [-viewonly] [-localhost] [-interface ipaddr] [-inetd] [-compatiblekbd] [X-options...]

DESCRIPTION

Xvnc is a VNC (Virtual Network Computing) server. It acts like an X server with a virtual display. The display can be seen by a VNC viewer application, which may be running on a different machine: see vncviewer(1). Xvnc is built inside the source code tree of XFree86, and shares many options with it.

Normally, you don't need to start Xvnc manually; use the vncserver(1) wrapper script instead. This script sets reasonable defaults for Xvnc session, checks many error conditions etc.

Please read the BUGS section if you plan to use VNC on an untrusted network.

OPTIONS

Xvnc supports many standard X server options and a number of VNC-specific options. To see what standard X server options are supported, please look at the Xvnc -help output and read the Xserver(1) manual page for details on those options.

The VNC-specific options are as follows:

-geometry widthxheight
Set desktop width and height.
-depth depth
Set the colour depth of the visual to provide, in bits per pixel. Must be a value between 8 and 32.
-pixelformat rgbNNN|bgrNNN
Set colour format for pixels representation. The viewer can do the conversion to any other pixel format, but it is faster if the depth and pixel format of the server is the same as the equivalent values on the viewer display.
-udpinputport port
UDP port for keyboard/pointer data.
-rfbport port
TCP port for RFB protocol. The RFB protocol is used for commnunication between VNC server and clients.
-rfbwait time
Maximum time, in milliseconds, to wait for an RFB client (VNC viewer).
-nocursor
Don't put up a pointer cursor on the desktop.
-rfbauth passwd-file
Use authentication on RFB protocol from the specified file. The passwd-file can be created using the vncpasswd(1) utility.
-httpd dir
Serve files via HTTP protocol from the specified directory. Normally, Java viewer classes are stored in such directory.
-httpport port
TCP port on which Xvnc should listen for incoming HTTP connections (to allow access to the desktop from any Java-capable browser).
-deferupdate time
Time in milliseconds, to defer screen updates (default 40). Deferring updates helps to coalesce many small desktop changes into a few larger updates thus saving network bandwidth.
-economictranslate
Use less memory-hungry pixel format translation.
-lazytight
Disable the "gradient" filter in Tight encoding (TightVNC-specific). The "gradient" filter often helps to improve data compression ratios, but may slow down the server performance. Please note that this filter is never used when a client enables JPEG compression in the Tight encoding.
-desktop name
Set VNC desktop name ("x11" by default).
-alwaysshared
Always treat new clients as shared, never disconnect existing client on a new client connection.
-nevershared
Never treat new clients as shared, do not allow several simultaneous client connections.
-dontdisconnect
Don't disconnect existing clients when a new non-shared connection comes in, refuse new connection instead.
-viewonly
Don't accept keboard and pointer events from clients. All clients will be able to see the desktop but won't be able to control it.
-localhost
Only allow loopback connections from localhost. This option is useful in conjunction with SSH tunneling.
-interface ipaddr
Listen for client connections only on the network interface with given ipaddr.
-inetd
Xvnc is launched by inetd. This option causes Xvncto redirect network input/output to stdin/stdout.
-compatiblekbd
Set META and ALT keys to the same X modifier flag, as in the original version of Xvnc by AT&T labs (TightVNC-specific).

BUGS

There are many security problems in current Xvnc implementation. It's recommended to restrict network access to Xvnc servers from untrusted network adresses. Probably, the best way to secure Xvnc server is to allow only loopback connections from the server machine (the -localhost option) and to use SSH tunneling for remote access to the Xvnc server. For details on SSH tunneling, see <URL:http://www.uk.research.att.com/vnc/sshvnc.html> .

SEE ALSO

vncserver(1), vncviewer(1), vncpasswd(1),vncconnect(1), sshd(1)

AUTHORS

Original VNC was developed in AT&T Laboratories Cambridge. TightVNC additions were implemented by Constantin Kaplinsky. Many other people participated in development, testing and support.

Man page authors: 
Marcus Brinkmann <Marcus.Brinkmann at ruhr-uni-bochum.de>, 
Tim Waugh <twaugh at redhat.com>, 
Constantin Kaplinsky <const at tightvnc.com>

http://www.tightvnc.com/Xvnc.1.html
 
 
 
1. 在Linux下安裝VNC
將Red Hat Enterprise Linux AS 5 DVD安裝盤放入DVD光碟機,執行下列命令進行安裝:
  1. # mkdir -p /mnt/cdrom  
  2. # mount -t auto /dev/cdrom /mnt/cdrom  
  3. # cd /mnt/cdrom/Server  
  4. # rpm -ivh rpm -ivh vnc-server-4.1.2-9.el5.i386.rpm  
  5. # rpm -ivh vnc-4.1.2-9.el5.i386.rpm 

2. 配置Linux下的VNC Server ①. VNC的執行機制介紹:   在配置VNC前,必須瞭解VNC的執行機制。Linux下的VNC可以同時啟動多個vncserver,各個vncserver之間用顯示編號(display number)來區分,每個vncserver服務監聽3個埠,它們分別是: 5800+顯示編號:  VNC的httpd監聽埠,如果VNC客戶端為IE,Firefox等非vncviewer時必須開放。 5900+顯示編號:  VNC服務端與客戶端通訊的真正埠,必須無條件開放。 6000+顯示編號:  X監聽埠,可選。   顯示編號、開放的埠分別由/etc/sysconfig/vncservers檔案中的VNCSERVERS和VNCSERVERARGS控制。VNCSERVERS的設定方式為“VNCSERVERS="顯示編號1:使用者名稱1 …"”,如:VNCSERVERS="1:root 2:aiezu"。VNCSERVERARGS的設定方式為VNCSERVERARGS[顯示編號1]="引數一 引數值一 引數二 引數值二  ……",如VNCSERVERARGS[2]="-geometry 800x600 -nohttpd",VNCSERVERARGS的詳細引數有:

-geometry 桌面解析度,預設1024x768;
-nohttpd 不監聽HTTP埠(58xx埠);
-nolisten tcp 不監聽X埠(60xx埠);
-localhost 只允許從本機訪問;
-AlwaysShared 預設只同時允許一個vncviewer連線,此引數允許同時連多個vncviewer;
-SecurityTypes None 登入不需要密碼認證VncAuth預設值,要密碼認證。

 

②. 修改/etc/sysconfig/vncserver檔案:   熟悉Linux下VNC的執行機制後,開始正式配置VNC Server。vi /etc/sysconfig/vncserver,新增如下三行:

  1. VNCSERVERS="1:root 3:aiezu" 
  2. VNCSERVERARGS[1]="-geometry 800x600 -nolisten tcp" 
  3. VNCSERVERARGS[3]="-geometry 1024x768 -nolisten tcp" 

本例我們開啟兩個vncserver,分別是root使用者,顯示編號為1和使用者aiezu,顯示編號為3,並且全不開啟X監聽埠60xx。

③. 設定VNC使用者密碼:   接下來設定VNC的密碼,此步驟不可跳過,否則VNC Server將無法啟動,在Linux Shell下執行下列命令:

  1. # su - aiezu  
  2. # vncpasswd  
  3. Password: 
  4. Verify:  
  5. # su - root  
  6. # vncpasswd  
  7. Password:  
  8. Verify: 
  9. service vncserver start  //啟動vncserver

執行上面命令後,會在使用者根目錄($HOME)下的".vnc"資料夾下生成一系列檔案。其中passwd為vnc使用者密碼檔案,由vncpasswd生成。其他的都由vnc初次啟動時生成,xstartup為VNC客戶端連線時啟動的指令碼。

 

④. 修改".vnc/xstartup"檔案:   執行到上面步驟後,VNC Server已經能正常執行。但是預設設定下,客戶連線時啟動的是xterm,我們如果想看到桌面,必須將使用者根目錄下的".vnc/xstartup"檔案中的最後兩行註釋掉,然後根據你安裝的桌面壞境,新增一行"startkde &"或者"gnome-session &"。如下:

  1. #!/bin/sh  
  2.  
  3. # Uncomment the following two lines for normal desktop:  
  4. # unset SESSION_MANAGER  
  5. # exec /etc/X11/xinit/xinitrc  
  6. [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup  
  7. [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources  
  8. xsetroot -solid grey  
  9. vncconfig -iconic &  
  10. #xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &  
  11. #twm &  
  12. startkde &  
  13. # gnome-session & 

配置完各個使用者根目錄下的".vnc/xstartup"後,執行service vncserver restart 重新啟動vncserver使配置生效。

⑤. 配置防火牆:
  如果Linux啟用了防火牆,必須允許VNC的相關埠(58xx,59xx,60xx)。具體的埠,請參照第2大步驟的①小步驟的VNC執行機制介紹,本例開啟5801,5803,5901,5903埠就可以。在Linux命令提示符下輸入"system-config-securitylevel-tui"啟動防火牆配置工具,點"Customize",在"Other Port"中輸入"5801:tcp 5803:tcp 5901:tcp 5903:tcp",然後點"OK"既可。

 
 

VNC全屏和視窗模式的互換

⑴視窗轉全屏:在調出的伺服器端視窗的左上角圖示處單擊左鍵,或在工作列伺服器端視窗所在地單擊右鍵,均可得出一個如下圖的功能選單,選其中的“Full screen”(全屏)即可由視窗轉為全屏模式。
⑵全屏轉視窗:按組合鍵“Ctrl+Esc”或直接按鍵盤上的視窗鍵均可現出本機的開始選單和工作列,再在工作列伺服器端視窗所在地單擊右鍵,在如上圖的功能選單中再選其中的“Full screen”(全屏)即可由全屏轉回視窗模式。

 http://blog.sina.com.cn/s/blog_53864cba0100hrc3.html

VNC怎麼和宿主機共享貼上板
vncconfig  -iconic
假設目標主機是linux,終端主機是windows(就是在windows上使用VNC登陸linux)

在linux中執行vncconfig -nowin&
在linux選中文字後,無需其他按鍵,直接在windows中可以黏貼。
在windows中選中文字,Ctrl+C,在linux中按中鍵黏貼。

具體表現為:
在使用vncconfig &命令後,上面的VNC config出現後,就可以按照上面說的進行復制貼上了。

我的工作環境是這樣的:伺服器端使用Rays1.5r2,開了vncserver,桌面端使用WinXP,通過vncviewer訪問伺服器。
vncviewer支援server和viewer之間的剪貼簿傳輸。但現在這項在我的環境下不管用。我猜是gnome的剪貼簿管理機制的問題,如果單純使用X環境,應該沒問題。
以前使用vncviewer時有vncconfig這個命令,開啟這個命令就可以啟用剪貼簿傳輸了。現在不知怎麼搞的找不到這個命令了。經過查詢RealVNC的maillist,找到了如下方法支援clipboard傳輸:
在xstartup的最後一行加入命令:
xcutsel &
這樣在gnome桌面環境啟動後會出現一個小小的程式,裡面有3項:
1、quit
2、copy primary to 0
3、copy 0 to primary
在WinXP中複製ASCII內容後,點選3:copy 0 to primary,然後在gnome環境中點選滑鼠中鍵,即可實現clipboard transfer。
同理,在gnome環境中複製ASCII內容後,點選2:copy primary to 0,然後就可以複製到WinXP中了。

http://blog.sina.com.cn/s/blog_6cef0cb50100rdbo.html

 

 此OS下的vncserver如果要通過oracle登陸,需要在oracle帳戶下執行vncserver :桌面號。/etc/sysconfig/vncservers中配置的VNCSERVERS引數不能決定使用vncviewer登陸後的帳戶
 
 

PS:偶以前基本不用Linux的遠端圖形桌面,前幾天有開發的同事配置CentOS的vnc有問題,找我解決,就順便記錄總結一下,這個總結是比較完整的。下面的配置在CentOS5.x和6.x、SUSE企業版親測驗證,其他發行版按理也通用:

一、安裝相應桌面環境與vnc服務端和客戶端:

# yum groupinstall "GNOME Desktop Environment"(CentOS 5.x安裝GNOME桌面環境)
# yum groupinstall "X Window System" "Desktop"(CentOS 6.x安裝GNOME桌面環境)
# yum groupinstall Xfce(CentOS安裝Xfce桌面環境,可選)
# yum install vnc-server vnc* (CentOS 5.x裡)
# yum install tigervnc-server tigervnc (CentOS 6.x裡)

說明:Xfce與KDE,Gnome都是圖形桌面環境,其特點是佔用資源更小資源佔用情況大致為:Gnome>KDE>Xfce。具體情況與版本有關。一般版本越新,資源佔用越大。

二、VNC的啟動和重啟:
# /etc/init.d/vncserver restart
注:有時候上面的命令啟動會報錯,直接執行就可以:
# vncserver
注:關閉具體的vncserver命令:vncserver -kill :1 vncserver -kill :2

三、設定遠端登陸到gnome桌面的配置:
# vim /etc/sysconfig/vncservers(SUSE企業版不用配置此檔案)
再最後面加入如下兩行:

VNCSERVERS="1:root"
VNCSERVERARGS[1]="-geometry 1024x768 -alwaysshared -depth 24"

說明:

1、-alwaysshared表示同一個顯示埠允許多使用者同時登入 -depth代為色深,引數有8、16、24、32;
2、這裡的“使用者名稱”是指linux系統使用者的名稱;
3、上面三行中第一行是設定可以使用VNC伺服器的帳號,可以設定多個,但中間要用空格隔開。注意前面的數字“1”或是“2”,當你要從其它電腦來VNC伺服器時,就需要用IP:1這種方法,而不能直接用IP。如假定你的VNC伺服器IP是192.168.1.100,那想進入VNC伺服器,並以peter使用者登入時,需要在vncviewer裡輸入IP的地方輸入:192.168.1.100:1,如果是root,那就是192.168.1.100:2;
4、下面兩行[1][2]最好與上面那個相對應,後面的800X600可以換成你電腦支援的解析度。注意中間的”x”不是“*”,而是小寫字母”x”。

四、設定vnc訪問密碼:
# vncpasswd
說明:這裡是為上面的root遠端使用者配密碼,所以在root賬戶下配;依次類推,為別的賬戶配密碼,就要在別的賬戶下設密碼

五:修改遠端桌面顯示配置檔案:
# vim /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" &
gnome-session & #set starting GNOME desktop
#startkde & #kde desktop
#twm & #Text interface
#/usr/bin/startxfce4
#exec /usr/bin/fluxbox

說明:
1、不修改此檔案你看到的遠端桌面很簡單,相當於命令列操作,為了遠端操作如同本地操作一樣,務必參考以上方式進行修改;
2、只要你啟用一次VNCserver,就能自動建立,方法如下:
# vncserver
通過上面的方法,就可以在使用者家目錄下的.vnc目錄裡建立xstartup檔案。

六、vnc客戶端登陸:
在vnc客戶端中輸入:伺服器端IP:1 或 伺服器端IP:2

iptables防火牆預設會阻止vnc遠端桌面,所以需要在iptables允許通過。當你啟動vnc服務後,你可以用netstat –tunlp命令來檢視vnc服務所使用的埠,可以發現有5801,5901,6001等。使用下面命令開啟這些埠:
# vim /etc/sysconfig/iptables
新增:
-A RH-Firewall-l-INPUT -p tcp -m tcp –dport 5801 -j ACCEPT
-A RH-Firewall-l-INPUT -p tcp -m tcp –dport 5901 -j ACCEPT
-A RH-Firewall-l-INPUT -p tcp -m tcp –dport 6001 -j ACCEPT
重啟防火牆:
# /etc/init.d/iptables restart
或者直接關閉防火牆:
# /etc/init.d/iptables stop

七、開機自啟動vncserver服務:
# chkconfig vncserver on

八、vnc的反向連線設定:

在大多數情況下,vncserver總處於監聽狀態,vnc client主動向伺服器發出請求從而建立連線。然而在
一些特殊的場合,需要讓vnc客戶機處於監聽狀態,vncsrever主動向客戶機發出連線請求,此謂vnc的
反向連線。
主要步驟:
a、啟動vnc client,使vncviewer處於監聽狀態;
# vncviewer -listen
b、啟動vncserver
# vncserver
c、在vncserver端執行vncconnect命令,發起server到client的請求;
# vncconnect -display :1 192.168.80.135

九、可能遇到的問題:

a、黑屏
在Linux裡安裝配置完VNC服務端,發現多使用者登陸會出現黑屏的情況,具體的現象為:
客戶端可以通過IP與會話號登陸進入系統,但登陸進去是漆黑一片,除了一個叉形的滑鼠以外,伸手不見五指。

原因:使用者的VNC的啟動檔案許可權未設定正確。
解決方法:將黑屏使用者的xstartup(一般為:/使用者目錄/.vnc/xstartup)檔案的屬性修改為755(rwxr-xr-x)。
完後殺掉所有已經啟動的VNC客戶端:
vncserver -kill :1
vncserver -kill :2 (注意:-kill與:1或:2中間有一空格)
最後重啟vncserver服務即可! # /etc/init.d/vncserver restart

注意:vncserver只能由啟動它的使用者來關閉,即時是root也不能關閉其它使用者開啟的vncserver,
除非用kill命令暴力殺死程式。

b、Windown下如何登陸VNC Server
(1)從瀏覽器登入(瀏覽器需要安裝JAVA支援庫,作為java applet來實現,才能登入控制VNC伺服器,可以yum install java*安裝)
直接從瀏覽器中輸入如下地址:

http://xxx.xxx.xxx.xxx:5801

(2)從VNC客戶端登入
windows上安裝vnc客戶端,然後輸入xxx.xxx.xxx.xxx:x,連線登入。

備註:
a、輸入的格式為IP:號碼,號碼要看你自己的配置而定。如192.168.80.128:1
b、登陸提示connection refused(10061),則是因為linux防火牆的問題,請檢查防火牆設定。
c、後面的尾綴”:x”也是不能少的,要不然老提示failed to connect : connection refused (10061)
http://www.ha97.com/4634.html 
黑屏則將1024×768 改為800×600 後重啟

[root@centos66 init.d]# vncserver :3

You will require a password to access your desktops.

Password:
Verify:
xauth: creating new authority file /root/.Xauthority

New ‘centos66:3 (root)’ desktop is centos66:3

Creating default startup script /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/centos66:3.log

 

 

相關文章