使用VNC连接CentOS桌面

PS:对于用惯了WIN系统的朋友来说,没有图形化操作界面的Linux用起来实在太难受了。实际上,Linux也是有图形化操作界面的,这就是VNC。接下来本文将告诉大家如何在CentOS 6.5minimal 下安装和配置 VNC图形化操作界面。

  1. VNC简介

    VNC是一款优秀的远程控制工具软件,由著名的AT&T的欧洲研究实验室开发的。VNC是在基于UNIX和Linux操作系统的免费的开放源码软件,远程控制能力强大,高效实用,其性能可以和Windows和MAC中的任何远程控制软件媲美。

    VNC(Virtual Network Computing)虚拟网络计算工具,它是一个桌面共享系统。它的功能类似于windows中的远程桌面功能。VNC使用了RFB(Remote Frame Buffer,远程帧缓冲)协议来实现远程控制另外一台计算机。它把键盘、鼠标动作发送到远程计算机,并把远程计算机的屏幕发回到本地

    VNC基本上由两部分组成:客户端的应用程序(vncviewer);服务器端的应用程序(vncserver)。

    VNC运行的工作流程如下:

    (1) VNC客户端通过浏览器或VNC Viewer连接至VNC Server。

    (2) VNC Server传送一对话窗口至客户端,要求输入连接密码,以及存取的VNC Server显示装置。

    (3) 在客户端输入联机密码后,VNC Server验证客户端是否具有存取权限。

    (4) 若是客户端通过VNC Server的验证,客户端即要求VNC Server显示桌面环境。

    (5) VNC Server通过X Protocol 要求X Server将画面显示控制权交由VNC Server负责。

    (6) VNC Server将来由 X Server的桌面环境利用VNC通信协议送至客户端,并且允许客户端控制VNC Server的桌面环境及输入装置。

  2. 作业环境

            #服务器端:
            #操作系统:CentOS-6.5-x86_64-minimal
            
  3. 初始化常用环境变量

            # vi .bashrc
            alias servnc='service vncserver'
            配置生效
            # source .bashrc
  4. centos桌面安装

    vncserver依赖拥有桌面系统的centos,centos min系统无桌面系统需要安装整个桌面系统

    使用环境:centos6.2 x64 min yum可用

            #gnome桌面安装
            yum groupinstall -y   "Desktop"   "Desktop Platform"   "Desktop Platform Development"  "Fonts"  "General Purpose Desktop"  "Graphical Administration Tools"  "Graphics Creation Tools"  "Input Methods"  "X Window System"  "Chinese Support [zh]" "Internet Browser"
            #KDE桌面环境
            yum groupinstall "X Window System" "KDE (K Desktop Environment)"
  5. 安装VNC服务器

    centos6 以上 vncvnc-server源已经改成tigervnc-server了

            yum -y install tigervnc-server
  6. vnc服务器配置文件

    1. 查看配置文件

                      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:myusername"
                      # VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -localhost"
    2. 单用户root配置方法

      #VNCSERVERS参数的格式为:

      VNCSERVERS=”1:root”

      VNCSERVERARGS[1]=”-geometry 分辨率 …”

                      [root@localhost ~]# echo 'VNCSERVERS="1:root"' >> /etc/sysconfig/vncservers;echo 'VNCSERVERARGS[1]="-geometry 1024x768"' >> /etc/sysconfig/vncservers;
    3. 多用户配置方法

      #VNCSERVERS参数的格式为:

      VNCSERVERS=”1:root 2:user01 …”

      VNCSERVERARGS[1]=”-geometry 分辨率 …”

      VNCSERVERARGS[2]=”-geometry 分辨率 …”

                      [root@localhost ~]# echo 'VNCSERVERS="1:root 2:user01"' >> /etc/sysconfig/vncservers;
                      [root@localhost ~]# echo -e 'VNCSERVERARGS[1]="-geometry 1024x768"\nVNCSERVERARGS[2]="-geometry 1024x768"' >> /etc/sysconfig/vncservers;
                      #或者
                      [root@localhost ~]# echo 'VNCSERVERARGS[1]="-geometry 1024x768">> /etc/sysconfig/vncservers;echo 'VNCSERVERARGS[2]="-geometry 1024x768">> /etc/sysconfig/vncservers;

      注意vnc远程的时候,默认第一个端口是5901,第二个界面是5902依次类推。所以在使用vnc客户端远程的时候,要注意。否则连接不上的

    4. 若用户user01不存在,需添加用户

                      [root@localhost ~]# useradd user01;
                      [root@localhost ~]#  passwd user01;
                      Changing password for user user01.
                      New password:
                      Retype new password:
                      passwd: all authentication tokens updated successfully
  7. 逐个用户运行vncserver

    它将完成两项工作:

    1.为用户创建所需.vnc 文件夹;

    2.用户设置登录密码 (如需要修改密码用vncpasswd)

    以root用户为例:

    如果使用root用户执行,则生成root用户的vnc配置

            #设置vnc登录密码
            #会在当前用户主目录下生成.vnc目录和配置文件
            [root@localhost ~]# vncserver
            You will require a password to access your desktops.
            Password:    #设置密码
            Verify:      #再次设置密码
            xauth:  creating new authority file /root/.Xauthority
            New 'localhost:1 (root)' desktop is localhost:1
            Creating default startup script /root/.vnc/xstartup
            Starting applications specified in /root/.vnc/xstartup
            Log file is /root/.vnc/localhost:1.log
            #localhost:1 (root)中的"1"表示1号桌面,对应端口号为5900+1即5901端口
            #同理若桌面号为2,对应端口号为5902

    修改 xstartup 文件

            #修改 xstartup 文件 把最后一行的 twm & 替换成 gnome-session &
            [root@localhost ~]# sed -i 's/twm \&/gnome-session \&/' /root/.vnc/xstartup

    提示:重复按照上面步骤,必须给所有/etc/sysconfig/vncservers中的设置的用户增加vnc设置,否则重启报错

  8. 重启动VNC SERVER(多用户配置为例)

    1. 管理所有桌面

                      #所有选项
                      [root@localhost ~]# service vncserver
                      Usage: /etc/init.d/vncserver {start|stop|restart|try-restart|status|force-reload}
                      #停止所有桌面
                      [root@localhost ~]# service vncserver stop
                      Shutting down VNC server: 1:root 2:user01       [  OK  ]
                      #启动所有桌面
                      [root@localhost ~]# service vncserver start
                      Starting VNC server: 1:root
                      New 'localhost:1 (root)' desktop is localhost:1
                      Starting applications specified in /root/.vnc/xstartup
                      Log file is /root/.vnc/localhost:1.log
      
                      2:user01
                      New 'localhost:2 (user01)' desktop is localhost:2
                      Starting applications specified in /home/user01/.vnc/xstartup
                      Log file is /home/user01/.vnc/localhost:2.log
                                                                      [  OK  ]
                      #查看启动端口
                      [root@localhost ~]# netstat -tunl
                      Active Internet connections (only servers)
                      Proto Recv-Q Send-Q Local Address               Foreign Address             State
                      tcp        0      0 0.0.0.0:5901                0.0.0.0:*                   LISTEN
                      tcp        0      0 0.0.0.0:5902                0.0.0.0:*                   LISTEN
                      tcp        0      0 0.0.0.0:6001                0.0.0.0:*                   LISTEN
                      tcp        0      0 0.0.0.0:6002                0.0.0.0:*                   LISTEN
    2. 单个桌面管理

                      #关掉1号桌面
                      [root@localhost ~]# vncserver -kill :1 #(kill和:1之间有一个空格)
                      Killing Xvnc process ID 2184
                      #vncserver[:n] 开启1号桌面
                      [root@localhost ~]# vncserver :1
                      New 'localhost:1 (user01)' desktop is localhost:1
                      Starting applications specified in /root/.vnc/xstartup
                      Log file is /root/.vnc/localhost:1.log
                      #vncpasswd 修改密码当前用户所开启桌面的vnc密码
                      [root@localhost ~]# vncpasswd
                      Password:    #设置密码
                      Verify:      #再次设置密码
  9. 在防火墙上打开VNC用到的上面两个端口

            #若打开防火墙,则需添加如下防火墙策略:
            iptables -A INPUT -p tcp --dport 5901 -j ACCEPT
            iptables -A INPUT -p tcp --dport 5902 -j ACCEPT
  10. windows上使用VNC Viewer客户端登录

    使用VNC VIEWER连接VNC SERVER

    下载VNC VIEWER运行,然后输入IP:端口号,输入刚才设定的密码,进入REDHAT桌面。

    注:如果在浏览器中通过web方式访问VNC则 端口为:6001,如果通过VNC客户端(比如VNC Viewer)来访问VNC则端口为:5901。

    下载RealVNC

  11. 可能的异常情况:

    连接提示10060:VNC客户端与VNC服务端可能存在网络故障!

    连接提示10061: VNC连接出错failed to connect:Connection refused(10061),设备正常能Ping通。服务器端的vnc services服务没起来 或 端口输入错误。

    连接提示10065: 可能是防火墙的关系,尝试关闭掉防火墙, VNC可以正常连接,开启后就不行 !不建议关闭防火墙,可以使用 iptables -A INPUT -p tcp –dport 5901 -j ACCEPT 与 iptables -A OUTPUT -p udp –sport 5901 -j ACCEPT 进行规则添加!

 

参考:

1.RealVNC 5.1注册码+官方原版下载(含VNC Viewer和VNC Server)

2.realvnc官网

3.centOS6.2 VNCserver搭建

4.windows下使用vnc viewer远程连接Linux桌面

 

200-120
210-260
200-310
SY0-401
810-403
300-320
400-101
70-533
N10-006
MB2-707
210-060
400-201
350-018
ADM-201
CISSP
1Z0-060
400-051
300-075
MB2-704
100-101
9L0-012
642-999
300-115
MB5-705
70-461
1V0-601
300-206
352-001
70-486
300-135
NS0-157
PR000041
300-101
70-346
CCA-500
70-480
300-208
70-462
EX200
1Z0-803
EX300
ICBB
1Z0-808
AWS-SYSOPS
1Z0-434
300-070
CAS-002
220-801
SSCP
PMP
642-997
70-410
101-400
ITILFND
AX0-100
2V0-621
102-400
101
1Z0-067
220-802
70-463
C_TAW12_731
70-494
CISM
700-501
NSE4
NSE7
70-483
70-488
相关文章
  1. windows7系统下fis3安装教程
  2. tar分卷压缩与解压缩
  3. fis3-smarty 安装使用详解
  4. 对Web静态资源缓存自动更新的思考与实践的总结
  5. crontab 定时任务
  6. CentOS 6.* 64位系统升级gcc4.4.7升级gcc5.1详解
本站版权
1、本站所有主题由该文章作者发表,该文章作者与尘埃享有文章相关版权
2、其他单位或个人使用、转载或引用本文时必须同时征得该文章作者和尘埃的同意
3、本帖部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责
4、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
5、原文链接:
二维码
Posted in linux技术, VNC
Comments are closed.