1:檢查系統
檢查是否已安裝vncserver
[root@localhost oradisk]# rpm -qa|grep vnc
上句檢查已經安裝過的rpm包,下面這句檢查rpm包中的信息,都可以證明一個程序已經安裝成功。
yum info tigervnc-server
發現光盤里已經安裝了:
gtk-vnc-python-0.3.10-3.el6.x86_64
tigervnc-1.0.90-0.17.20110314svn4359.el6.x86_64
gtk-vnc-0.3.10-3.el6.x86_64
tigervnc-server-1.0.90-0.17.20110314svn4359.el6.x86_64
一開始程序安裝的不好使,我又重新安裝了一遍,卸載的方法如下:
yum -y remove realvnc-vnc-server-5.0.3.37046-1.x86_64
檢測是否已經安裝vnc
[root@localhost oradisk]# rpm -q vnc vnc-server
這步我檢查時是(可是就算是我都已經可以遠程訪問了,這個命令的結果還是沒有安裝,很奇怪)
package vnc is not installed
package vnc-server is not installed
2:安裝
我試過用直接用rpm -ivh VNC-Server-5.0.3-Linux-x64.rpm,但是出現了以下錯誤(外加缺少xterm 依賴):
error: Failed dependencies:
tightvnc conflicts with realvnc-vnc-server-5.0.3.37046-1.x86_64
tigervnc conflicts with realvnc-vnc-server-5.0.3.37046-1.x86_64
tigervnc-server conflicts with realvnc-vnc-server-5.0.3.37046-1.x86_64
這個可以通過在rpm命令中添加 --nodeps --force 參數解決,安裝后並沒有直接影響到程序的使用。
[root@localhost oradisk]# tar -zxvf VNC-5.0.3-Linux-x64-RPM.tar.gz
[root@localhost oradisk]# rpm -ivh VNC-Server-5.0.3-Linux-x64.rpm
這里有依賴包,需要安裝xterm,如下
[root@localhost oradisk]# yum install xterm
[root@localhost oradisk]# rpm -ivh VNC-Server-5.0.3-Linux-x64.rpm
[root@localhost oradisk]# vncserver :1(中間有空格)
無法啟動,會要求輸入license
[root@localhost oradisk]# vnclicense -add VKUPN-MTHHC-UDHGS-UWD76-6N36A
相關license如下:
VKUPN-MTHHC-UDHGS-UWD76-6N36A
69NCN-JRLBC-QD28Y-5KLY2-UEE6A
6GQQQ-HXLBS-U2H8Q-B6UB7-R7R6A
8XWCU-ZRJBF-U7BXZ-G5EAE-ZPQ2A
6XQQQ-WXL4Q-NN4KX-NUTC6-8ZK6A
PGUFQ-HTZBB-WNHU7-YHDQC-A7R6A
3:配置VNC
全都安裝完畢之后
[root@localhost oradisk]#vncserver
發現錯誤提示:
xauth: (argv):1: bad display name "KVM-A-05:1" in "add" command
Error: could not run xauth
在網上查資料發現這個錯誤是由於/etc/hosts文件中缺少配置造成的
[root@localhost oradisk]#vi /etc/hosts
添加一句127.0.0.1 localhost的語句在最后。
配置顯示分辨率、商品和用戶,編輯 /etc/sysconfig/vncservers,參考注釋掉的最后兩行,添加 2 行(添加-alwaysshared可以允許多個終端同時登錄服務器,-depth指顏色分辨率,可以是8,16,24,32)
VNCSERVERS="1:root 2:myname"
VNCSERVERARGS[1]="-geometry 1024x768 -nolisten tcp"
VNCSERVERARGS[2]="-geometry 1024x768 -nolisten tcp"
開啟防火牆端口5900到5910
[root@localhost ~]# vim /etc/sysconfig/iptables
加入如下內容,開啟vnc的5900到5910連接端口,然后保存
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5900:5910 -j ACCEPT
:wq 保存退出
關於添加這句的位置,網上有說應該加在第四行,
查看防火牆
先查看端口 服務端口 netstat -ntlp
把防火牆端口打開 vi /etc/sysconfig/iptables
重啟防火牆
[root@localhost ~]# service iptables restart
修改登錄畫面可選KDE 和GNOME,注意:每個用戶都需要改否則出現畫面是VNC自帶的界面
#!/bin/sh
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc
[ -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
啟動vnc服務:
1、/etc/init.d/vncserver start (stop reload restart等)
2、service vncserver start (stop restart等)
3、設置開機自動啟動:chkconfig vncserver on
(檢查開機自動啟動設置:chkconfig --list vncserver)
附錄:
#
# 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:[url]http://www.uk.research.att.com/vnc/sshvnc.html[/url]>.
VNCSERVERS="1:root"
VNCSERVERARGS[1]=”-geometry 800×600 -alwaysshared -depth 24″
#!/bin/sh
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc
[ -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
附一些常見的問題:(轉)
VNC Viewer下載地址:http://download.csdn.net/source/1080853
以后如果服務器重新啟動過,就要重新輸入 vncserver 后才能登錄。如果服務器一直沒有重啟過,就不用了。如果要殺掉 vncserver 進程,可執行 vncserver :1 kill ,1表示 display 的 ID 號。
(1) 重設VNC密碼
[root@localhost ~]# vncpasswd
Password:
Verify:
(2) 啟動和kill vncserver
[root@localhost ~]# vncserver :23
New ‘localhost.localdomain:23 (root)’ desktop is localhost.localdomain:23
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:23.log
如下:kill display 的 ID 1,1的pid是:6653
[root@localhost ~]# ps -auxwf|grep vnc|grep -v grep
Warning: bad syntax, perhaps a bogus ‘-’? See /usr/share/doc/procps-3.2.7/FAQ
root 6653 0.0 1.3 13660 6836 pts/0 S 04:44 0:00 Xvnc :1 -desktop localhost.localdomain:1 (root) -httpd /usr/share/vnc/classes -auth /root/.Xauthority -geometry 1024×768 -depth 16 -rfbwait 30000 -rfbauth /root/.vnc/passwd -rfbport 5901 -pn
root 6661 0.0 0.2 4276 1304 pts/0 S 04:44 0:00 vncconfig -iconic
root 6716 0.1 2.1 20972 11276 pts/0 S 04:51 0:01 Xvnc :2 -desktop localhost.localdomain:2 (root) -httpd /usr/share/vnc/classes -auth /root/.Xauthority -geometry 1024×768 -depth 16 -rfbwait 30000 -rfbauth /root/.vnc/passwd -rfbport 5902 -pn
root 6936 0.4 2.1 20856 11116 pts/0 S 05:06 0:00 Xvnc :23 -desktop localhost.localdomain:23 (root) -httpd /usr/share/vnc/classes -auth /root/.Xauthority -geometry 1024×768 -depth 16 -rfbwait 30000 -rfbauth /root/.vnc/passwd -rfbport 5923 -pn
[root@localhost ~]# kill -9 6653
[root@localhost ~]# ps -auxwf|grep vnc|grep -v grep
Warning: bad syntax, perhaps a bogus ‘-’? See /usr/share/doc/procps-3.2.7/FAQ
root 6716 0.1 2.1 20972 11276 pts/0 S 04:51 0:01 Xvnc :2 -desktop localhost.localdomain:2 (root) -httpd /usr/share/vnc/classes -auth /root/.Xauthority -geometry 1024×768 -depth 16 -rfbwait 30000 -rfbauth /root/.vnc/passwd -rfbport 5902 -pn
root 6936 0.3 2.1 20856 11116 pts/0 S 05:06 0:00 Xvnc :23 -desktop localhost.localdomain:23 (root) -httpd /usr/share/vnc/classes -auth /root/.Xauthority -geometry 1024×768 -depth 16 -rfbwait 30000 -rfbauth /root/.vnc/passwd -rfbport 5923 -pn
當然,vncserver -kill :2也可以了,
[root@localhost ~]# vncserver -kill :2
Killing Xvnc process ID 6716
[root@localhost ~]# ps -auxwf|grep vnc|grep -v grep
Warning: bad syntax, perhaps a bogus ‘-’? See /usr/share/doc/procps-3.2.7/FAQ
root 6936 0.2 2.1 20856 11116 pts/0 S 05:06 0:00 Xvnc :23 -desktop localhost.localdomain:23 (root) -httpd /usr/share/vnc/classes -auth /root/.Xauthority -geometry 1024×768 -depth 16 -rfbwait 30000 -rfbauth /root/.vnc/passwd -rfbport 5923 -pn
(3)重新啟動一個手動kill的vncserver
[root@localhost ~]# vncserver :1
Warning: localhost.localdomain:1 is taken because of /tmp/.X1-lock
Remove this file if there is no X server localhost.localdomain:1
A VNC server is already running as :1
[root@localhost ~]# rm -rf /tmp/.X1-lock
[root@localhost ~]# vncserver :1
Warning: localhost.localdomain:1 is taken because of /tmp/.X11-unix/X1
Remove this file if there is no X server localhost.localdomain:1
A VNC server is already running as :1
[root@localhost ~]# rm -rf /tmp/.X11-unix/X1
[root@localhost ~]# vncserver :1
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 ~]#
[root@localhost ~]# ps -auxwf|grep vnc|grep -v grep
Warning: bad syntax, perhaps a bogus ‘-’? See /usr/share/doc/procps-3.2.7/FAQ
root 6936 0.0 2.4 22296 12680 pts/0 S 05:06 0:00 Xvnc :23 -desktop localhost.localdomain:23 (root) -httpd /usr/share/vnc/classes -auth /root/.Xauthority -geometry 1024×768 -depth 16 -rfbwait 30000 -rfbauth /root/.vnc/passwd -rfbport 5923 -pn
root 7337 1.0 2.1 20252 10856 pts/0 S 05:19 0:00 Xvnc :1 -desktop localhost.localdomain:1 (root) -httpd /usr/share/vnc/classes -auth /root/.Xauthority -geometry 1024×768 -depth 16 -rfbwait 30000 -rfbauth /root/.vnc/passwd -rfbport 5901 -pn
說明:因是手動刪除的,所以也要把.lock刪除掉,才能重新啟動了.
(4).VNC服務使用的端口號與桌面號的關系
VNC服務使用的端口號與桌面號相關,VNC使用TCP端口從5900開始,對應關系如下
桌面號為“1” —- 端口號為5901
桌面號為“2” —- 端口號為5902
桌面號為“3” —- 端口號為5903
……
基於Java的VNC客戶程序Web服務TCP端口從5800開始,也是與桌面號相關,對應關系如下
桌面號為“1” —- 端口號為5801
桌面號為“2” —- 端口號為5802
桌面號為“3” —- 端口號為5803
……
基於上面的介紹,如果Linux開啟了防火牆功能,就需要手工開啟相應的端口,以開啟桌面號為“1”相應的端口為例,命令如下
[root@localhost~]# iptables -I INPUT -p tcp –dport 5901 -j ACCEPT
[root@localhost ~]# iptables -I INPUT -p tcp –dport 5801 -j ACCEPT
(5)配置VNC圖形桌面環境為KDE或GNOME桌面環境
[root@localhost ~]# cat /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 80×24+10+10 -ls -title “$VNCDESKTOP Desktop” &
twm &
將這個xstartup文件的最后一行修改為“startkde &”,再重新啟動vncserver服務后就可以登陸到KDE桌面環境
將這個xstartup文件的最后一行修改為“gnome-session &”,再重新啟動vncserver服務后就可以登陸到GNOME桌面環境
重新啟動vncserver服務的方法:
[root@localhost ~]# vncserver -kill :1
[root@localhost ~]# vncserver :1
(6) 配置多個桌面
可以使用如下的方法啟動多個桌面的VNC
vncserver :1
vncserver :2
……
但是這種手工啟動的方法在服務器重新啟動之后將失效,因此,下面介紹如何讓系統自動管理多個桌面的VNC,方法是將需要自動管理的信息添加到/etc/sysconfig/vncservers配置文件中,
先以桌面1為test用戶桌面2為test1用戶為例進行配置如下:
格式為:VNCSERVERS=”桌面號:使用的用戶名 桌面號:使用的用戶名”
[root@localhost ~]# vi /etc/sysconfig/vncservers
VNCSERVERS=”1:test 2:test1″
VNCSERVERARGS[1]=”-geometry 1024×768″
VNCSERVERARGS[2]=”-geometry 1024×768″
(7) 設置VNC服務隨系統啟動自動加載
第一種方法:使用“ntsysv”命令啟動圖形化服務配置程序,在vncserver服務前加上星號,點擊確定,配置完成。
第二種方法:使用“chkconfig”在命令行模式下進行操作,命令使用如下:
[root@localhost ~]# chkconfig vncserver on
[root@testdb ~]# chkconfig –list vncserver
vncserver 0:off 1:off 2:on 3:on 4:on 5:on 6:off
第三種方法:把這行命令/etc/init.d/vncserver start加到/etc/rc.local啟動項里。
