1. 程式人生 > >CentOS 6.5 安裝VNC

CentOS 6.5 安裝VNC

http協議 ram service stat lis pack frame www. 技術分享

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

fi

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

exec sh /etc/X11/xinit/xinitrc

fi

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

xsetroot -solid grey

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

#twm &

gnome-session &

修改用戶配置文件:/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.


VNCSERVERS="2:root"

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

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客戶端登錄

技術分享圖片

技術分享圖片


CentOS 6.5 安裝VNC