作業系統: CentOS6.3
vncserver: yum安裝源
一.環境部署:
1.關閉iptables和SELINUX
# service iptables stop
# setenforce 0
# vi /etc/sysconfig/selinux
---------------
SELINUX=disabled
2.安裝vncserver:
# yum install "*vnc*" pixman pixman-devel libXfont -y
二.單使用者root配置方法:
1.安裝完畢後,啟動 VNC Server,這時會要求你輸入兩次進行連接配接的初始密碼。
# vncserver
------------------------
You will require a password to access your desktops.
Password: //輸入密碼
Verify: //再次輸入密碼
xauth: creating new authority file /root/.XauthorityNew ‘localhost.localdomain:1 (root)’ desktop is localhost.localdomain:1Creating default startup script /root/.vnc/xstartupStarting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:1.log
--------------------------------
注:每個使用者都可以啟動多個 VNC Server 遠端桌面,它們用 ip 加端口号:ip:1、ip:2、ip:3 來辨別區分,使用同一端口會使另外登入的使用者自動退出。另,VNC Server 的大部配置設定置檔案及日志檔案都在使用者 home 目錄的.vnc 目錄下。
使用者可以自定義啟動号碼如:
# vncserver :1
注:前面一定要有空格
-----------------------
A VNC server is already running as :1
2.Red Hat Linux 支援兩種圖形模式:KDE 模式和 gnome 模式。
你的 Redh Hat 使用的什麼圖形模式這個一般隻有登入到圖形界面檢視一下才能知道,或者通過以下的指令來判斷。
# ps -aux | grep gnome
如果是 gnome 桌面,那麼需要修改/root/.vnc/xstartup的配置檔案。
使用 vi 打開 xstartup 檔案,如下:
# cd /root/.vnc
# vi xstartup
删除全部内容,然後添加如下内容:
注: 這裡第一行添加的字型變量需與系統i18n檔案内的變量一緻,否則會出現亂碼
-------------------------
LANG="zh_CN.UTF-8"
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 &
gnome-session &
注:若啟動黑屏則添加如下腳本内容
-------------------------------
#[-x /etc/vnc/xstartup]]&& exec /etc/vnc/xstartup
xterm -gemetry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
3.添加root系統環境配置
# vi /etc/sysconfig/vncservers
VNCSERVERS="1:root"
VNCSERVERARGS[2]="-geometry 1280x1024 -nolisten tcp "
4.重新啟動 VNC Server
# vncserver -kill :1
--------------------
Killing Xvnc process ID 21198
--------------------------
New ‘localhost.localdomain:1 (root)’ desktop is localhost.localdomain:1Starting applications specified in /root/.vnc/xstartupLog file is /root/.vnc/localhost.localdomain:1.log
----------------------------------------
或直接利用系統服務重新開機:
# /etc/init.d/vncserver restart
注: 在防火牆上打開 VNC Server 的監聽端口
VNC Server 用到了三個端口:5801、5901、6001
5901為VNC用戶端連接配接的端口号,其中的1代表開放的第一個系統使用者root,和上面啟動提示的
1 (root)一緻,如果添加其他系統使用者則為2(testuser),testuser的vnc連接配接端口為5902,以此類推.
5.将vncserver設為自啟動:
# chkconfig --level 345 vncserver on
6.若打開防火牆,則需添加如下防火牆政策:
# iptables -A INPUT -p tcp --dport 5801 -j ACCEPT
# iptables -A INPUT -p tcp --dport 5901 -j ACCEPT
# iptables -A INPUT -p tcp --dport 6001 -j ACCEPT
儲存并重新開機
# service iptables save
# /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 ]
---------------------------------------------
在 Windows 機器上使用 VNC Viewer 連接配接 VNC Server
下載下傳 VNC Viewer,運作然後輸入IP:5901,輸入剛才設定的密碼,進入 RHEL 桌面。
<a href="http://blog.51cto.com/attachment/201311/114144171.jpg" target="_blank"></a>
<a href="http://blog.51cto.com/attachment/201311/114144646.jpg" target="_blank"></a>
<a href="http://blog.51cto.com/attachment/201311/114144418.jpg" target="_blank"></a>
7.vncserver使用者密碼修改:
# vncpasswd
Password:
Verify:
三.多使用者配置方法:
1、修改配置檔案,設定可通過VNC用戶端登陸的使用者:
#vi /etc/sysconfig/vncservers
修改vnc配置檔案為:
---------------------------
# 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"
VNCSERVERS="1:root 2:test1 3:test2"
VNCSERVERARGS[1]="-geometry 800x600"
VNCSERVERARGS[2]="-geometry 800x600"
VNCSERVERARGS[3]="-geometry 800x600"
----------------------------
# VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -nohttpd -localhost"說明:VNCSERVERS為可通過VNC用戶端遠端登陸的使用者
格式為:1:使用者1 2:使用者2 3:使用者3
但這樣做了,僅僅使用者1才能登陸,使用者2、使用者3是無法登陸的。
2、修改每個使用者宿主目錄下的vnc配置檔案,允許多使用者登陸
# su - root
$ mkdir .vnc //*建立.vnc目錄,用于儲存此使用者的vnc配置檔案*//
$ vncpasswd //*設定root使用者的vnc遠端連接配接密碼*//
#vi xstartup
# su - test1
$ vncpasswd //*設定test1使用者的vnc遠端連接配接密碼*//
-------------
同理test2
3.更新X11字型包(支援centos預設更新源更新)
yum install pixman pixman-devel libXfont
4.重新開機VNC服務
# service vncserver restart
6.修改權限
# chmod 755 .vnc/xstartup
# su - test2
5. 關閉防火牆對VNC端口的限制
如果需要從外網控制内網的某台Linux,則需要打開防火牆相應的端口,并在路由器上進行端口映射。
VNC給浏覽器的端口是5800+N,給vncviewer的端口是5900+N,N是設定的display号。
如果不想打開防火牆,但是仍需要VNC這項服務,則需要:
編輯vi /etc/sysconfig/iptables
在裡邊加入如下兩行:
-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
這裡需要的是,display N 對應的端口就是 5900+N,是以不建議設的太多。
6. 停止vncserver:
停止 vncserver 的方法是執行:vncserver -kill :1
注意:“:1”,表示停止第一個vnc桌面,1代表目前啟用的VNCserver序号,“:1”之前是有一個空格的。如果目前啟動的序号是2,若要關閉其,則應該使用“vncserver -kill :2”.
7. 修改vnc密碼:(選讀)
修改vnc密碼的方法是執行:vncpasswd
輸入兩次密碼即可。
8:檢查伺服器端VNC Server是否正常運作中:
執行:ps -ef|grep vnc
如果vnc在執行,可以看到類似的消息:
# ps -ef|grep vnc
root 3605 1 0 Jul13 ? 00:13:51 Xvnc :1 -desktop MyIMS.local:1 (root) -httpd /usr/share/vnc/classes -auth /root/.Xauthority -geometry 800x600 -depth 16 -rfbwait 30000 -rfbauth /root/.vnc/passwd -rfbport 5901 -pn
說明是序号為":1"vnc程序在端口為5901上進行監聽。
9.VNC 用戶端伺服器端運作正常後,我們方可以考慮使用VNC用戶端與其相連。
Windows 用戶端 VNC Viewer 的配置:
a. 從 http://www.realvnc.com/download.html 下載下傳 VNC Free Edition for Windows Version 4.1.2
b. 打開 VNCViewer :
填入VNCServer 的IP:編号(1或2或…)
c. VNCViewer 切換全屏模式:F8
10 一些配置檔案:
/etc/X11/xorg.conf 設定螢幕分辨率
到這裡,您的VNC應該已經能夠連上,但有可能出現黑屏的問題:
a、檢視/root/.vnc/下的log日志,有沒有報錯;有可能是xstartup權限不夠。“chmod xstartup 777”更改下權限,重新開機後再進。
b、重新啟動下電腦,試一試。我就是各種配置之後,始終黑屏,重新開機電腦後OK。
11.檢視VNC登陸日志:
通路在你登陸使用者所在家目錄的 .vnc/主機名:1.log 檔案
例如:
/root/.vnc/www.test.com:1.log
----------其他配置-------------
VNCServer配置
redhat 一般都自動安裝了vncserver了 隻要在服務清單中選中啟動一下就可以.
通過編輯檔案$HOME/.vnc/xstartup來啟動你喜歡的視窗管理器。使用
startkde & 來啟動KDE,使用 gnome-session & 來啟動GNOME.
首次建立 ~/.vnc/xstartup 時,指定的視窗管理器是 twm ,它是一個極小的視窗管理器,幾乎每台 X Window 系統機器上都有 twm。twm 不具備完整“桌面管理器”(象 KDE、GNOME 或 WindowMaker)的大部分花哨功能。下面是修改過的示例:
#!/bin/sh
[ -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" &
#exec wmaker
#exec startkde
gnome-session &
上面的示例中,注釋掉了預設 twm 和 xterm 的預設啟動。配置了這個桌面來避免背景和标題欄上的顔色漸變,并使用極少的動畫效果。
關閉伺服器上自己的vnc連接配接
vncserver -kill :桌面号
開機自動運作vncserver
1.設定vncserver啟動腳本(/etc/init.d/vncserver)實作系統自啟動時啟動vncserver.
2.編輯/etc/sysconfig/vncservers
VNCSERVERS="1:user1"
ARGS="-geometry 800x600 -alwaysshared "
在ARGS 中修改"800x600"來适應自己的X桌面實際參數配置。可以在這裡添加任何其他VNC伺服器參數配置。在VNCSERVERS中修改 user1為你希望運作VNC桌面的使用者。VNCSERVERS中的1表示VNC以桌面1運作,如果希望添加其他的桌面,可以修改配置如下:
VNCSERVERS="1:user1 2:user2 3:user3"
3.設定vnc server的通路密碼
vncpasswd
在RedHat系統上,使用以下指令啟動VNC:
/etc/init.d/vncserver start
----------------
<a href="http://www.cnblogs.com/fengqingtao/archive/2010/05/28/1746640.html" target="_blank">更改root與vnc密碼,配置vnc</a>
更改root密碼。
登入到root使用者下
#passwd
更改vnc密碼
#vncpasswd
配置vnc
找到vncservers="1:myusername"這個字元串,去掉注釋,把myusername改為你的登入使用者名。然後儲存退出。
#service vncserver start //這一步是讓他生成xstatup檔案
exec /etc/X11/xinit/xinitrc(去掉注釋)
#vi /etc/sysconfig/iptables
在其中加入5901端口,然後儲存退出
#service iptables restart
#service vncserver restart
完成
如果要設定除去root使用者以外的使用者
首先建立一個使用者
如果連接配接VNC出現too many security failures這個問題:可能是因為VNC關閉了,重新啟動一下VNC服務。#service vncserver restart
本文轉自 showerlee 51CTO部落格,原文連結:http://blog.51cto.com/showerlee/1127490,如需轉載請自行聯系原作者