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


 

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  widthx height] [-depth  depth] [-pixelformat rgb NNN|bgr NNN] [-udpinputport  port] [-rfbport  port] [-rfbwait  time] [-nocursor] [-rfbauth passwd-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  width x height
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  rgb NNN| bgr NNN
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

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM