安装配置VNC服务,使得可以通过图形界面来管理控制linux主机:

目前比较流行的方式:XDM(X display manager)方案和VNC方案,个人感觉VNC方案比较方便;

一是因为VNC方案配置起来相对简单,二是VNC方案支持多种连接方式,比如通过浏览器方式访问

linux桌面,免去需要安装客户端的麻烦。


安装配置VNC前期准备,一台linux RedHat服务器,接下来进入具体配置说明


一,确认及安装VNC SERVER

 1.首先确认服务器是否安装配置了VNC server ,可以通过命令查看;

[root@johntest ~]# rpm -qa vnc*  #查看是否安装VNC server

vnc-4.1.2-14.el5_3.1           #VNC客户端

vnc-server-4.1.2-14.el5_3.1      #vnc服务端

 2.如果没有安装VNC SERVER,RedHad系统光盘自带有安装包,配置光盘yum源直接安装即可 

[root@johntest ~]# yum -y install vnc*

Loaded plugins: rhnplugin, security

.............

Running Transaction

  Installing     : vnc                                                                           1/1 

Installed:

  vnc.x86_64 0:4.1.2-14.el5_3.1                                

Complete!

安装完成,启动VNC服务!


二,开始配置VNC SERVER

[root@johntest ~]# vncpasswd          #设定当前用户登录VNC的密码

Password:

Verify:


[root@johntest ~]# vncserver           #启动VNCSERVER


New 'johntest.com:2 (root)' desktop is johntest.com:1     #访问VNC方式用户名:1


Starting applications specified in /root/.vnc/xstartup

Log file is /root/.vnc/johntest.com:1.log

通过远端windows客户端VNC软件连接当前VNCserver

wKiom1joT6iihqEuAAGD0hogug0245.jpg

wKiom1joT6jRVqtXAAER6hOlzTc761.jpg

此时已经通过vnc远端登录了linux系统,但是此时的桌面只是简单的界面,如果需要启用gnome桌面

程序需要通过以下设置:


[root@johntest ~]# cd .vnc     #进入到vnc服务的文件夹进行配置启动脚本

[root@johntest .vnc]# ls

johntest.com:1.log  johntest.com:1.pid  johntest.com:2.log  johntest.com:2.pid  passwd  xstartup

[root@johntest .vnc]# vim xstartup     #修改如下图

wKiom1joUS3Rpz-2AAJZTh6g2Xo743.jpg  

 修改设置完毕后,需重新启动系统,否则设置不会生效,或者把所有开启的VNC远端桌面进程

终止掉后再重新运行vncserver服务。

 先查看vnc服务运行了几个进程:

[root@johntest ~]# ps -aux |grep vnc   #查看vnc进程

Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQ

root      2514  0.1  0.8  47540  7432 pts/0    S    10:56   0:00 Xvnc :1 -desktop johntest.com:1 (root) -httpd /usr/share/vnc/classes -auth /root/.Xauthority -geometry 1024x768 -depth 16 -rfbwait 30000 -rfbauth /root/.vnc/passwd -rfbport 5901 -pn

root      2713  2.0  0.8  47544  7424 pts/0    S    10:58   0:00 Xvnc :2 -desktop johntest.com:2 (root) -httpd /usr/share/vnc/classes -auth /root/.Xauthority -geometry 1024x768 -depth 16 -rfbwait 30000 -rfbauth /root/.vnc/passwd -rfbport 5902 -pn

通过查看发现运行了2个vnc进程,需要终止这2个vnc运行进程:

[root@johntest ~]# vncserver -kill :1  #关闭第一个vnc进程

Killing Xvnc process ID 4289

[root@johntest ~]# vncserver -kill :2  #关闭第二个vnc进程

Killing Xvnc process ID 4338

[root@johntest ~]# vncserver    #重新启动vncserver

New 'johntest.com:1 (root)' desktop is johntest.com:1


Starting applications specified in /root/.vnc/xstartup

Log file is /root/.vnc/johntest.com:1.log

再次通过远端windows连接测试,是否现在桌面是否正常:

wKiom1joVhLwuVa-AAjH3Y4DRew771.jpg

到这里VNC server服务器端配置就完成了。

以下是进一步多vnc服务器端进行配置:

 1、设置用户信息及分辨率;(永久生效)

编辑vncserver配置文档:

[root@johntest ~]# vim /etc/sysconfig/vncservers  #在最后面添加以下几行设置


VNCSERVERS=”1:root 2:ceboy”   #此处添加用户,一般只添加一个1:root也就行了。

VNCSERVERARGS[1]=”-geometry 800×600 -nolisten tcp -nohttpd -localhost”

VNCSERVERARGS[2]=”-geometry 1024×768 -nolisten tcp -nohttpd -localhost”

#注意:上面是分别设置的root和ceboy两个用户的分辨率,注意是用端口号区分的。

另外也可以通过命令行临时修改分辨率及色深,这种方式重启后失效,命令如下:

[root@johntest ~]# vncserver -geometry 800x600  #设置vncserver的分辨率

[root@johntest ~]# vncserver -depth 16    #设置vncserver的色深


三、客户端连接及使用;

1、访问方式

    a.在linux下,运行vncviewer命令即可,服务器地址写法形式如10.109.134.249:1 使用vncviewer命令的linux系统必须安装过vnc应用程式,否则无法使用

    b.在windows下,运行windows版本的vnc程序即可。

    c.用浏览器访问,http://10.109.134.249:5801的方式连接(vnc端口从5800开始依次类推,一      般会是5800,5900)


2,修改密码
运行vncpasswd即可


3,停止vncserver
#vncserver -kill :1
#vncserver -kill :2
注意到vncserver只能由启动它的用户来关闭,即时是root也不能关闭其它用户开启的vncserver,只能用kill命令暴力杀死进程。

4,稳定性设置
vncserver默认在多个客户机连接同一个vncserver的显示端口时,vncserver端口旧连接,而为新连接服务,可通过-dontdisconnect拒绝新连接请求而保持旧的连接。

5,同一个显示器可以连接多个客户机
#vncserver -alwaysshared

6,重启服务
service vncserver restart

vncserver  启动vncserver

7,让系统启动时自动启动VNCSERVER。
使用VNC连接登录到RedHat Linux图形界面,点击“系统”——“管理”——“服务器设置”——“服务”,在“后台服务”中找到VNCSERVER后勾选它,点击保存即可。