天天看點

CentOS 6.5 安裝VNC

CentOS 6.5 安裝VNC  

在Linux下用VNC遠端桌面是個很不錯的玩意。但在CentOS中預設沒有安裝VNC的。可以用下面語句查詢,如果出現下面情況說明沒有安裝vnc

一、檢查桌面程式是否已安裝

#rpm -q “X Window System” “Desktop” “Chinese Support”

#yum groupinstall -y "X Window System" "Desktop" "Chinese Support" 

二、檢查vnc相關服務是否安裝

#rpm -q tigervnc tigervnc-server  vnc vnc-server 

package tigervnc is not installed

package tigervnc-server is not installed

1、安裝VNC服務

#yum install tigervnc tigervnc-server  vnc vnc-server 

然後就等待安裝完成。

2、為vncserver設定周密碼

[[email protected] ~]# vncserver  或者vncpasswd

You will require a password to access your desktops.

Password:<輸入vnc登入密碼> 

Verify:<再次輸入vnc登入密碼> 

啟動服務:#service vncserver restart

注:如果出現FAILED那一般是配置檔案寫錯了,如果檢查後問題依舊,并且錯誤提示與下圖類似那麼則是版本原因。安裝或更新x11.

指令:yum install pixman pixman-devel libXfont -y

請注意libXfont 裡面的X是大寫的哦。

3、 配置VNC

為了防黑屏,需要修改一下/root/.vnc/xstartup。

注釋下面兩行

#xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &

#twm &

然後再添加下面一行

gnome-session &

[root@GUOKE ~]# vi /root/.vnc/xstartup

#!/bin/sh

[ -r /etc/sysconfig/i18n ] && . /etc/sysconfig/i18n

export LANG

export SYSFONT

vncconfig -iconic &

unset SESSION_MANAGER

unset DBUS_SESSION_BUS_ADDRESS

OS=`uname -s`

if [ $OS = 'Linux' ]; then

  case "$WINDOWMANAGER" in

    *gnome*)

      if [ -e /etc/SuSE-release ]; then

        PATH=$PATH:/opt/gnome/bin

        export PATH

      fi

      ;;

  esac

fi

if [ -x /etc/X11/xinit/xinitrc ]; then

  exec /etc/X11/xinit/xinitrc

if [ -f /etc/X11/xinit/xinitrc ]; then

  exec sh /etc/X11/xinit/xinitrc

[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources

xsetroot -solid grey

修改使用者配置檔案:/etc/sysconfig/vncservers

去掉下面這兩行前的“#”,也就是說把這兩行的注釋給去掉。

VNCSERVERS="2:root"

VNCSERVERARGS[2]="-geometry 1024x768 -depth 32"

改完後的配置檔案如下

[root@GUOKE ~]# 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 this URL:

# http://kbase.redhat.com/faq/docs/DOC-7028

# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.

# 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.

4、改變xstartup的權限

chmod 777 /root/.vnc/xstartup

5、防火牆開端口,netstat -antpl檢視可以發現有三個端口在監聽。

5901 5801 6001

這三個端口:

預設的, vnc 服務監聽3個TCP端口

RFB(Remote FrameBuffer)協定 預設端口 : 5900 顯示器号

HTTP協定預設端口 : 5800 顯示器号

X協定 預設端口 : 6000 顯示器号

vncserver使用的顯示器編号預設從1開始, 依次使用, 也可以參數指定端口号

我們隻需要RFB協定就好了,是以,我們在防火牆中加5900到5903這幾個,這樣就可以開3個了。

vi /etc/sysconfig/iptables 找到下面的語句:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT

在這之後填加:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 5900:5903 -j ACCEPT

重起防火牆

service iptables restart

6、起動vnc伺服器

/etc/init.d/vncserver start

然後在windows中用vnc用戶端登入

本文轉自 Bill_Xing 51CTO部落格,原文連結:http://blog.51cto.com/zhanx/2059026

繼續閱讀