1 問題如下
/etc/sysconfig/vncservers---配置文件作用去掉最后兩行的注釋
no route to host
是防火牆的原因---必須得研究好防火牆
本地可以vnc,本地可以訪問zhanglinux.org:1158/em
我一直以為是沒有路由導致的
route add default gw 192.168.0.254
經過一系列的測試發現是防火牆的問題。以后在研究網絡問題時,首先要注意防火牆的設置。先取消防火牆的設置,在沒有防火牆的基礎上,實現連通。之后再設置防火牆。防火牆對於網絡的安全控制,以及網絡訪問上都至關重要。這是個基礎性的問題。從今天的實踐可以看出,基礎的把握能力不夠。
2 軟件下載
windows vnc---http://download.pchome.net/php/tdownload2.php?sid=2603&url=/internet/server/remote/vnc-3.3.7-x86_win32.zip&svr=1&typ=0
linux vnc--http://mirror.etf.bg.ac.yu/fedora/development/i386/Fedora/RPMS/vnc-4.1.1-34.i386.rpm
ps: http://rpmfind.net 找需要的包。由於學校的proxy服務器設置老出問題,本來用yum install -y 通用包名--非常方便,不得不用老土的rpm -Uvh , rpm -q 這兩條命令都非常重要了。
3 安裝: rpm -Uvh *rpm
注意依賴~~~
4 在X桌面下設置服務器允許連接,同時可以設置連接密碼。
http://www.linuxsir.org/bbs/showthread.php?t=262457
上面的問題,我這里是由於firewall導致的---可在X桌面設置防火牆
--------------------具體使用方法------------
啟vncserver: vncserver即可,第一次會提示你輸入密碼;
關閉:
vncserver -kill :桌面號
或者使用系統自帶腳本:
補充VNCServer的命令行啟動、關閉方法:
1)服務器端啟動:
#vncserver
$vncserver
注意到每個用戶都可以啟動自己的vncserver,每個用戶可以啟動多個vncserver,用顯示端口號:1,:2,:3等等來標識。
2) 客戶端:
a)在linux下,運行vncviewer命令即可,服務器地址的寫法形如192.168.3.119:1
b)在windows下,運行windows版本的vncviewer即可,用法與linux下相近。
c)用瀏覽器(平台無關),作為java applet來實現,以形如http://192.168.3.119:5801的方式來啟動
3) 密碼修改:
第一次啟動vncserver會提示輸入密碼,以后要修改的話,運行:
#vncpassword
4) 停止vnc server:
#vncserver -kill :1
#vncserver -kill :2
注意到vncserver只能由啟動它的用戶來關閉,即時是root也不能關閉其它用戶開啟的vncserver,除非用kill命令暴力殺死進程。
5) 指定顯示端口號啟動VNC server:
#vncserver :3
$vncserver :6
6) 設置VNC server分辨率:
#vncserver -geometry 800x600
#vncserver -geometry 640x480
7) 設置vncserver的色深:
8位為256色,16位為64k色
#vncserver -depth 8
#vncserver -depth 16
穩定性設置:
vncserver默認在多個客戶機連接同一個vncserver的顯示端口時,vncserver端口舊連接,而為新連接服務,可通過-dontdisconnect拒絕新連接請求而保持舊的連接。
9) 設置vncserver的同一個顯示端口可以連接多個客戶機
#vncserver -alwaysshared
10) 默認遠程登陸啟動的是kde桌面(如果安裝系統時安裝了的話),如果修改登陸的圖形界面?當在oracle用戶下面啟用vncserver的時候,在oracle用戶的家目錄下會自動創建一個.vnc的文件夾,在該文件夾下面有一個文件,是xstartup,編輯這個文件,將所有的行都注釋掉,然后在最后加一行:
gnome-session &
保存文件,重啟vncserver,就會發現登陸的圖形界面已經變成了你想要的樣式了。
比如:
服務端
[root@zhanglinux .vnc]# vncserver :3
You will require a password to access your desktops.
Password:
Password must be at least 6 characters - try again
Password:
Password must be at least 6 characters - try again
Password:
Verify:
New 'zhanglinux.org:3 (root)' desktop is zhanglinux.org:3
Creating default startup script /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/zhanglinux.org:3.log
客戶端
登錄時:vncviewer ip:3
登錄之后,查看默認端口5900 對應進程名vnc-serv
[root@zhanglinux .vnc]# netstat -na | grep 5900
tcp 0 0 202.116.130.243:5900 202.116.130.241:1729 ESTABLISHED
退出vncviewer
[root@zhanglinux .vnc]# netstat -na | grep 5900
tcp 0 0 0.0.0.0:5900 0.0.0.0:* LISTEN
----------------------------------------------------------------------------
終於解決了vnc啟動時加入服務的問題 [http://bbs.chinaunix.net/viewthread.php?tid=149091]
我就沒做了,個人覺得沒多大必要,需要才啟動。
vi /etc/rc.d/init.d/vncserver 服務啟動相關設置
----------------------------------------------------------------------------
VNC Server配置實例
1) 配置允許訪問的用戶
[root@RHCE ~]# 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: [url]http://www.uk.research.att.com/archive/vnc/sshvnc.html[/url]>.
# 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: [url]http://www.uk.research.att.com/archive/vnc/sshvnc.html[/url]>.
# 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.
# 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"
# VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -nohttpd -localhost"
# 自己定義部分:運行用戶jchen遠程訪問,分辨率為800*600
VNCSERVERS="2:jchen"
VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -nohttpd"
VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -nohttpd"
# 自己定義部分:運行用戶jackie遠程訪問,分辨率為1024*768
VNCSERVERS="3:jackie"
VNCSERVERARGS[3]="-geometry 1024x768"
VNCSERVERARGS[3]="-geometry 1024x768"
2) 配置用戶VNC訪問密碼
[root@RHCE ~]# su - jackie
[jackie@RHCE ~]$ mkdir .vnc
[jackie@RHCE ~]$ cd .vnc
[jackie@RHCE .vnc]$ vncpasswd
Password: xxxxxx
Verify: xxxxxx
[jackie@RHCE ~]$ mkdir .vnc
[jackie@RHCE ~]$ cd .vnc
[jackie@RHCE .vnc]$ vncpasswd
Password: xxxxxx
Verify: xxxxxx
3) 啟動VNC服務
[root@RHCE ~]# service vncserver start
4) 配置VNC訪問方式
[root@RHCE ~]# vi /home/jackie/.vnc/xstartup
#!/bin/sh
# Uncomment the following two lines for normal desktop: (去掉以下兩行的#就可以允許使用桌面了)
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc
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 &
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
twm &
5) 配置iptables允許訪問5902端口
[root@RHCE ~]# iptables -I RH-Firewall-1-INPUT -p tcp --dport 5903 -j ACCEPT
[root@RHCE ~]# iptables -I RH-Firewall-1-INPUT -p udp --dport 5903 -j ACCEPT
[root@RHCE ~]# iptables -I RH-Firewall-1-INPUT -p udp --dport 5903 -j ACCEPT
6) Windows下測試成功
服務器端配置如下:
1)第一次啟動vncserver
會提示輸入密碼:
管理員帳戶:
[root@localhost /]# vncserver
You will require a password to access your desktops.
Password: 輸入vnc 連接密碼
Verify: 確認vnc密碼
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 /]#su huilin
[huilin@localhost /]$ vncserver
You will require a password to access your desktops.
Password: 輸入vnc 連接密碼
Verify: 確認vnc密碼
xauth: creating new authority file /home/huilin/.Xauthority
New 'localhost.localdomain:2 (huilin)' desktop is localhost.localdomain:2
Creating default startup script /home/huilin/.vnc/xstartup
Starting applications specified in /home/huilin/.vnc/xstartup
Log file is /home/huilin/.vnc/localhost.localdomain:2.log
* 注意到每個用戶都可以啟動自己的 vncserver,每個用戶可以啟動多個 vncserver,
用ip加端口號 ip:1,ip:2,ip:3 來標識。vncserver的大部分配置文件及日志文件都在用戶home目錄下.vnc目錄下
用戶可以自定義啟動號碼如:
[huilin@localhost /]$ vncserver :2
A VNC server is already running as :2
2)配置vnc的配置文件xstartup文件
如果用的是gnome 桌面環境還需要修改
[root@localhost .vnc]# vi 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 gnome
添加連接時使用 gnome 桌面環境
twm &
3)在vncserver設置登錄用戶的信息
[root@localhost: ~]#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="1:root 2:demo"
此處添加用戶
VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -nohttpd -localhost"
#vncserver -geometry 800x600
設置vncserver的分辨率
#vncserver -geometry 640x480
設置vncserver的分辨率
#vncserver -depth 8
設置vncserver的色深
#vncserver -depth 16
設置vncserver的色深
4)客戶端的連接
a、在linux下,運行vncviewer命令即可,服務器地址的寫法形如192.168.3.119:1
b、在windows下,運行windows版本的vncviewer即可,用法與linux下相近。
c、用瀏覽器(平台無關),作為java applet來實現,以形如http://192.168.3.119:5801的方式來啟動
(vnc 端口從5800 開始依次類推,一般會是5800,5900)
5)修改密碼
運行vncpasswd即可
6)停止vncserver
#vncserver -kill :1
#vncserver -kill :2
注意到vncserver只能由啟動它的用戶來關閉,即時是root也不能關閉其它用戶開啟的vncserver,
除非用kill命令暴力殺死進程。
7)穩定性設置
vncserver默認在多個客戶機連接同一個vncserver的顯示端口時,vncserver端口舊連接,而為新連接服務,可通過-dontdisconnect拒絕新連接請求而保持舊的連接。
8)同一個顯示器可以連接多個客戶