第一步:安装gnome桌面系统

安装过程:

# wget http://www.vpsyou.com/sh/xwindow.sh;

# sh ./xwindow.sh;

如果该链接下载不下来,可以直接创建xwindow.sh,并运行之,内容如下:

#!/bin/sh
# This script is FREE and written by www.vpsyou.com
# install yum-fastestmirror
yum -y install yum-fastestmirror
# Create new soft download dir
mkdir -p /backup/www.vpsyou.com;
cd /backup/www.vpsyou.com;
# Install x window softwares
yum -y groupinstall "X Window System"
yum -y  groupinstall "GNOME Desktop Environment"
yum -y  install nc expect freenx
yum -y  groupinstall chinese-support
#install firefox
yum -y install firefox
# Copy client.id_dsa.key to /backup/www.vpsyou.com/
# Please use FTP or winscp to download it
cp /etc/nxserver/client.id_dsa.key /backup/www.vpsyou.com/
chmod 755 /backup/www.vpsyou.com/client.id_dsa.key
# iptables
iptables -A INPUT -i lo -s 127.0.0.1 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A OUTPUT -p udp --sport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 5000 -j ACCEPT
iptables -A OUTPUT -p udp --sport 5000 -j ACCEPT
sed -i 's#SELINUX=enforcing#SELINUX=disabled'# /etc/selinux/config
echo "==========================="
    get_char()
    {
    SAVEDSTTY=`stty -g`
    stty -echo
    stty cbreak
    dd if=/dev/tty bs=1 count=1 2> /dev/null
    stty -raw
    stty echo
    stty $SAVEDSTTY
    }
    echo ""
    echo "======= Download FreeNX Windows software  : ======= "
        echo ""
        echo "http://www.nomachine.com/download-client-windows.php"
        echo ""
        echo ""
        echo "======= How to use FreeNX connect to your Linux X Window System: ======= "
        echo "http://www.vpsyou.com/centos-install-desktop/"
        echo ""
    echo "Install X Window System Successful,Press any key to end..."
    char=`get_char`



等待5-30分钟即可完成!

第二步:安装vnc

#yum install vnc-server(注意在root下安装)

#yum install vnc


第三步:配置并启动vncserver

1.把远程桌面的用户加入到配置文件中(下面以ROOT用户为例子)

vi /etc/sysconfig/vncservers

使用vi编辑器打开配置文件,在文件中添加下面两行命令

VNCSERVERS="1:root 2:leo"

VNCSERVERARGS[1]="-geometry 800x600"

VNCSERVERARGS[2]="-geometry 1024x768"

说明:

第一、这里的“用户名”是指linux系统用户的名称

第二、上面三行中第一行是设定可以使用VNC服务器的帐号,可以设定多个,但中间要用空格隔开。注意前面的数字“1”或是“2”,当你要从其它电脑来VNC服务器时,就需要用IP:1这种方法,而不能直接用IP。如假定你的VNC服务器IP是192.168.1.100,那想进入VNC服务器,并以peter用户登录时,需要在vncviewer里输入IP的地方输入:192.168.1.100:1,如果是root,那就是192.168.1.100:2.

第三、下面两行[1][2]最好与上面那个相对应,后面的800X600可以换成你电脑支持的分辨率。注意中间的"x"不是“*”,而是小写字母"x".


为配置的远程桌面用户设置密码

vncpasswd

说明:注意这里是为上面的root远程用户配密码,所以在root账户下配;依次类推,为别的账户配密码,就要在别的账户下配命令

2.修改远程桌面显示配置文件

cd ~/.vnc/  (/root/.vnc)

vi xstartup

原本的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" &

twm &

只要取消上面第三行第四行前的#符号,就行,当然,如果你想进入VNC服务器时看到的是图形界面,那就还需要把最后面的那行注释掉,并加上gnome-session $.

修改后的文件内容应该如下:

#!/bin/sh

# Add the following line to ensure you always have an xterm available.

# 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" &

#twm &

gnome-session &

说明:

第一、不修改此文件你看到的远程桌面很简单,相当于命令行操作,为了远程操作如同本地操作一样,务必参考以下方式进行修改

第二、只要你启用一次VNCserver,就能自动创建,方法如下:

#/sbin/service vncserver start(注意要在root下才能启动)

#/sbin/service vncserver stop(启动后再关闭,方便下面的操作)

通过上面的方法,就可以在用户家目录下的.vnc目录里创建xstartup文件.

3.相关vnc服务操作指令

#/sbin/service vncserver start(注意要在root下才能启动)

#/sbin/service vncserver stop(启动后再关闭,方便下面的操作)

#/sbin/service vncserver restart

4.iptables防火墙常常会阻止vnc远程桌面,所以需要在iptables允许,用如下命令

当你启动vnc服务后,你可以用netstat –tunlp命令来查看vnc服务所使用的端口,可以发现有5801,5901,6001等。使用下面命令开启这些端口:

vi /etc/sysconfig/iptables

添加:

-A RH-Firewall-l-INPUT -p tcp -m tcp --dport 5900:5903 -j ACCEPT

service iptables save //保存

service iptables restart //重启防火墙

或者来点狠的!!关闭防火墙!

service iptables stop

5、开机自动启动vnc

vi /etc/rc.d/rc.local

使用vi编辑器打开配置文件,并进行下列修改

/etc/init.d/vncserver start  --新增行

6、可能的问题:

a、黑屏

在Linux里安装配置完VNC服务端,发现多用户登陆会出现黑屏的情况,具体的现象为:

客户端可以通过IP与会话号登陆进入系统,但登陆进去是漆黑一片,除了一个叉形的鼠标以外,伸手不见五指。

原因:用户的VNC的启动文件权限未设置正确。

解决方法:将黑屏用户的xstartup(一般为:/home/用户名称/.vnc/xstartup)文件的属性修改为755(rwxr-xr-x)。

完后杀掉所有已经启动的VNC客户端:

vncserver -kill :1

vncserver -kill :2       (注意:-kill与:1或:2中间有一空格)

最后重启vncserver服务即可!service vncserver restart

b、Windown下如何登陆VNC Server

(1).从IE登录

直接从IE浏览器中输入如下地址:

http://xxx.xxx.xxx.xxx:5802

(2).从VNC view登录

在windows上安装vnc view,然后输入xxx.xxx.xxx.xxx:x,连接登录。

备注:

a、输入的格式为IP:号码,号码要看你自己的配置而定!!如192.168.1.111:1

b、登陆提示connection refused(10061),则是因为linux防火墙的问题,请检查防火墙设置。c、后面的尾缀 “:x” 也是不能少的,要不然老提示failed to connect : connection refused (10061) )