CentOS遠程桌面

 nohup java RFrun > HX_PsePSSM.log 2>&1 &


環境:

CentOS 6.3 Final,桌面安裝了除KDE的所有組件


1、安裝服務

[plain] view plaincopy
  1. yum install tigervnc-server  

名字有點怪哦,CentOS5前叫vnc-server


2、運行並設置密碼

[plain] view plaincopy
  1. vncserver[:1]  

輸入密碼,會生成相關的文件

[plain] view plaincopy
  1. xauth:  creating new authority file /root/.Xauthority  
  2.   
  3. New 'centos6-244:1 (root)' desktop is centos6-244:1  
  4.   
  5. Starting applications specified in /root/.vnc/xstartup  
  6. Log file is /root/.vnc/centos6-244:1.log  

3、配置用戶

[plain] view plaincopy
  1. vim /etc/sysconfig/vncservers  
最後一行加入:

VNCSERVERS="1:root" 多個用戶用空格分開,並要先su - 到那個用戶運行vncserver[:n]來設定配置文件和密碼


4、實用命令

usage: vncserver [:<number>] [-name <desktop-name>] [-depth <depth>]
                 [-geometry <width>x<height>]
                 [-pixelformat rgbNNN|bgrNNN]
                 [-fp <font-path>]
                 [-fg]
                 <Xvnc-options>...


       vncserver -kill <X-display>
       vncserver -list

vncserver[:n] 開服務

vncserver -list 看有幾個在運行

vncserver -kill :n   殺掉第幾個x-display

vncpasswd           修改密碼


5、服務管理

service vncserver restart

其它用法:/etc/init.d/vncserver {start|stop|restart|try-restart|status|force-reload}

chkconfig vncserver on 加入到自啓動(chkconfig --level 35 vncserver on)


6、客戶端連接

CentOS:使用TigerVNC Viewer 連接 ip:1

Windows:使用Real VNC Viewer 連接ip:1

輸入密碼即可訪問


===============================================================================================

必須明白:
vncserver在調用的時候,會根據你的配置來啓用server端的監聽端口,
端口默認是從5900開始,再加上你的桌面號。
比如你的桌面號爲1,則vnc的連接端口號爲5900+1=5901
比如你的桌面號爲10000,則vnc的連接端口號爲5900+10000=15900
======================================================================
下面配置VNC服務器,使用戶(root)能夠通過vnc客戶端遠程連接到linux系統的圖形界面(前提是你的服務器要安裝桌面)

1、檢查linux系統是否安裝VNC
在終端窗口輸入命令:

rpm -q vnc-server

返回信息如下

package vnc-server is not installed

說明vnc服務器沒有安裝
2、運行以下命令進行安裝:

yum install vnc vnc-server

3、啓動VNC服務

vncserver
You will require a password to access your desktops.
Password:
Verify:

會提示輸入密碼,這個密碼是遠程登錄時所需要輸入的密碼,輸入密碼,回車
4、切換到root賬號:su root然後輸入root賬號的密碼

vi /etc/sysconfig/vncservers  #vnc配置文件
VNCSERVERS="10000:root"  # 把前面的#取消了   10000:root (桌面號:用戶)
# VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -localhost"

最後保存退出
5、配置防火牆,允許10000+5900=15900端口通過防火牆(否則遠程連不上VNC服務器)

vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 15900 -j ACCEPT(允許15900端口通過防火牆)

保存退出
6、重啓vnc服務器

 /etc/init.d/vncserver restart
或者
service vncserver restart

7、重啓防火牆,使剛纔的端口配置生效

/etc/init.d/iptables restart
service iptables restart

8、 設置vnc服務器開機自動啓動
第一種方法:使用“ntsysv”命令啓動圖形化服務配置程序,在vncserver服務前加上星號,點擊確定,配置完成。
第二種方法:使用“chkconfig”在命令行模式下進行操作,命令使用如下

chkconfig vncserver on
chkconfig --list vncserver
vncserver       0:off   1:off   2:on    3:on    4:on    5:on    6:off

9、更改vnc連接密碼
vncpasswd
到此,VNC服務端設置完成,用VNC客戶端可以連接了
vnc服務器:你的ip:15900

注意:如果在連接上之後,出現灰屏,可以按照下面的方法設置
進入用戶的home目錄, cd /home/user
如果是用root賬號登錄的,那麼當前目錄就是用戶根目錄

cd ~/.vnc
vi xstartup  #編輯
#twm &    #註釋掉這一行
gnome-session &   #添加這一行

保存退出即可正常連接!

做到這裏,總算是大功告成了,接下來你可以用http://IP:port的方式來WEB登錄比如說

http://IP:5801,也可以在vncviewer裏用IP:1這種來登錄。

發佈了59 篇原創文章 · 獲贊 17 · 訪問量 34萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章