【Linux】教你一步一步在CentOS Linux release 7.1上安装配置vncserver

来源:互联网 发布:蓝格软件 编辑:程序博客网 时间:2024/04/28 21:15

1.查看系统中是否安装了vncserver

 rpm -qa | grep vnc

[root@localhost ~]# rpm -qa | grep vnc
libvncserver-0.9.9-9.el7_0.1.x86_64
gvnc-0.5.2-7.el7.x86_64
gtk-vnc2-0.5.2-7.el7.x86_64

上面查出来的列表并不是vncserver的安装包。而是一些vncserver开发包。具体每个包是干什么用,你可以使用yum search 命令来查看:

[root@localhost ~]# yum search libvncserver
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.btte.net
 * extras: mirrors.aliyun.com
 * updates: mirror.bit.edu.cn
===================================================== N/S matched: libvncserver ======================================================
libvncserver-devel.i686 : Development files for libvncserver
libvncserver-devel.x86_64 : Development files for libvncserver
libvncserver.i686 : Library to make writing a vnc server easy
libvncserver.x86_64 : Library to make writing a vnc server easy
  名称和简介匹配 only,使用“search all”试试。

[root@localhost ~]# yum search gvnc
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.btte.net
 * extras: mirrors.aliyun.com
 * updates: mirror.bit.edu.cn
========================================================= N/S matched: gvnc ==========================================================
gvnc-devel.i686 : Libraries, includes, etc. to compile with the gvnc library
gvnc-devel.x86_64 : Libraries, includes, etc. to compile with the gvnc library
gvncpulse-devel.i686 : Libraries, includes, etc. to compile with the gvncpulse library
gvncpulse-devel.x86_64 : Libraries, includes, etc. to compile with the gvncpulse library
gvnc.i686 : A GObject for VNC connections
gvnc.x86_64 : A GObject for VNC connections
gvnc-tools.x86_64 : Command line VNC tools
gvncpulse.i686 : A Pulse Audio bridge for VNC connections
gvncpulse.x86_64 : A Pulse Audio bridge for VNC connections

  名称和简介匹配 only,使用“search all”试试。
[root@localhost ~]# yum search gtk-vnc
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.btte.net
 * extras: mirrors.aliyun.com
 * updates: mirror.bit.edu.cn
======================================================== N/S matched: gtk-vnc ========================================================
gtk-vnc-devel.i686 : Development files to build GTK2 applications with gtk-vnc
gtk-vnc-devel.x86_64 : Development files to build GTK2 applications with gtk-vnc
gtk-vnc-python.x86_64 : Python bindings for the gtk-vnc library
gtk-vnc2-devel.i686 : Development files to build GTK3 applications with gtk-vnc
gtk-vnc2-devel.x86_64 : Development files to build GTK3 applications with gtk-vnc
gtk-vnc.i686 : A GTK2 widget for VNC clients
gtk-vnc.x86_64 : A GTK2 widget for VNC clients
gtk-vnc2.i686 : A GTK3 widget for VNC clients
gtk-vnc2.x86_64 : A GTK3 widget for VNC clients
  名称和简介匹配 only,使用“search all”试试。
[root@localhost ~]#

可以确定,当前的系统没有安装vncserver,因此接着进行下面步骤。

2.安装vncserver

安装前,我们先用命令查看一下当前的vnc-server版本

[root@localhost ~]# yum search vnc-server
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.btte.net
 * extras: mirrors.aliyun.com
 * updates: mirror.bit.edu.cn
====================================================== N/S matched: vnc-server =======================================================
tigervnc-server.x86_64 : A TigerVNC server
tigervnc-server-applet.noarch : Java TigerVNC viewer applet for TigerVNC server
tigervnc-server-minimal.x86_64 : A minimal installation of TigerVNC server
tigervnc-server-module.x86_64 : TigerVNC module to Xorg
  名称和简介匹配 only,使用“search all”试试。
[root@localhost ~]#

tigervnc-server.x86_64正是这里我们需要安装的。下面执行安装命令,如下:

[root@localhost ~]# yum install tigervnc-server.x86_64
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.btte.net
 * extras: mirrors.aliyun.com
 * updates: mirror.bit.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 tigervnc-server.x86_64.0.1.3.1-3.el7 将被 安装
--> 正在处理依赖关系 tigervnc-server-minimal,它被软件包 tigervnc-server-1.3.1-3.el7.x86_64 需要
--> 正在检查事务
---> 软件包 tigervnc-server-minimal.x86_64.0.1.3.1-3.el7 将被 安装
--> 正在处理依赖关系 tigervnc-license,它被软件包 tigervnc-server-minimal-1.3.1-3.el7.x86_64 需要
--> 正在处理依赖关系 libxshmfence.so.1()(64bit),它被软件包 tigervnc-server-minimal-1.3.1-3.el7.x86_64 需要
--> 正在检查事务
---> 软件包 libxshmfence.x86_64.0.1.2-1.el7 将被 安装
---> 软件包 tigervnc-license.noarch.0.1.3.1-3.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
====================================================================================================================================
 Package                                    架构                      版本                              源                       大小
====================================================================================================================================
正在安装:
 tigervnc-server                            x86_64                    1.3.1-3.el7                       base                    202 k
为依赖而安装:
 libxshmfence                               x86_64                    1.2-1.el7                         base                    7.2 k
 tigervnc-license                           noarch                    1.3.1-3.el7                       base                     25 k
 tigervnc-server-minimal                    x86_64                    1.3.1-3.el7                       base                    1.0 M
事务概要
====================================================================================================================================
安装  1 软件包 (+3 依赖软件包)
总下载量:1.2 M
安装大小:3.0 M
Is this ok [y/d/N]: y
Downloading packages:
(1/4): tigervnc-license-1.3.1-3.el7.noarch.rpm                                                                 |  25 kB  00:00:00
(2/4): tigervnc-server-1.3.1-3.el7.x86_64.rpm                                                                  | 202 kB  00:00:00
(3/4): libxshmfence-1.2-1.el7.x86_64.rpm                                                                       | 7.2 kB  00:00:01
(4/4): tigervnc-server-minimal-1.3.1-3.el7.x86_64.rpm                                                          | 1.0 MB  00:00:09
--------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                  139 kB/s | 1.2 MB  00:00:09
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : libxshmfence-1.2-1.el7.x86_64                                                                                     1/4
  正在安装    : tigervnc-license-1.3.1-3.el7.noarch                                                                               2/4
  正在安装    : tigervnc-server-minimal-1.3.1-3.el7.x86_64                                                                        3/4
  正在安装    : tigervnc-server-1.3.1-3.el7.x86_64                                                                                4/4
  验证中      : tigervnc-license-1.3.1-3.el7.noarch                                                                               1/4
  验证中      : tigervnc-server-minimal-1.3.1-3.el7.x86_64                                                                        2/4
  验证中      : libxshmfence-1.2-1.el7.x86_64                                                                                     3/4
  验证中      : tigervnc-server-1.3.1-3.el7.x86_64                                                                                4/4
已安装:
  tigervnc-server.x86_64 0:1.3.1-3.el7
作为依赖被安装:
  libxshmfence.x86_64 0:1.2-1.el7       tigervnc-license.noarch 0:1.3.1-3.el7       tigervnc-server-minimal.x86_64 0:1.3.1-3.el7
完毕!
[root@localhost ~]#

到此处,tigervnc-server已经安装完成了。

3.vncserver启动以及密码设置方法

启动vncserver,设置登录的密码。这里的密码并非是linux系统账号,而仅仅是vncviewer的登录密码。

设置 VNC密码,输入:(在某用户下输入则登陆用户就是它,如果su imiss切换到imiss用户,输入vncserver则启动的是另一个桌面,同样要设置密码,以后在该账户下启动的vncserver登陆就需要在此用户下设置的密码了。)

[root@localhost ~]# vncserver
You will require a password to access your desktops.
Password:
Verify:
New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1

Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:1.log


[root@localhost ~]#

以后修改密码的方法:

[root@localhost ~]# vncpasswd
Password:

4.配置桌面类型

就像第3节中红色字体描述的,也可不做配置,缺省也能使用。这里就先不研究如何配置了。

Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:1.log

5.防火墙配置使得vncserver使用的端口可用(一般端口都是5900逐次加1)

首先查看当前Xvnc所使用的监听端口,从下面的查询结果看到端口号是5901,为什么是5901呢?原因是:

−rfbport port

Specifies the TCP port on which Xvnc listens for connections from viewers (the protocol used in VNC is called RFB - "remote framebuffer"). The default is 5900 plus the display number.



[root@localhost ~]# ps -ef|grep Xvnc
root      4591     1  0 14:21 pts/0    00:00:04 /usr/bin/Xvnc :1 -desktop localhost.localdomain:1 (root) -auth /root/.Xauthority -geometry 1024x768 -rfbwait 30000 -rfbauth /root/.vnc/passwd-rfbport 5901 -fp catalogue:/etc/X11/fontpath.d -pn
root      8823  8366  0 14:40 pts/1    00:00:00 grep --color=auto Xvnc
[root@localhost ~]#

因此需要进行下面的防火墙配置:

[root@localhost ~]# firewall-cmd --zone=public --add-port=5901/tcp --permanent
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# firewall-cmd --list-all
public (default, active)
  interfaces: eno16777736
  sources:
  services: dhcpv6-client ftp http https ssh
  ports: 2121/tcp 8080/tcp 5901/tcp
  masquerade: no
  forward-ports:
  icmp-blocks:
  rich rules:
[root@localhost ~]# 

6.使用VNC viewer远程登录到系统

服务器:192.168.11.112:1 或者 192.168.11.112:5901

密码就是vncserver里面配置的密码,注意不是linux系统用户的密码。如果忘记了,可以使用vncpasswd修改。

7.其他用法

tigervnc相关的配置命令主要包括下面的,使用下面的命令进行详细配置的时候,几乎可以满足使用者的任何要求。

例如:

a.可以开多个display,这样就可以让多人同时登陆图形化界面,且不冲突。

方法 如:执行 vncserver :2 当然,你这里开了第二个,那么此时端口是5900+2 ,那么5902这个端口需要在防火墙配置一下,功能才能正常。

b.杀掉vncserver 某个display的方法是:vncserver -kill :1  vncserver -kill :2  等等。

vncserver -list 还可以查看当前用户一共起了多少个display

c.Xvnc命令还可以配置服务占用的端口号。

等等情况,如果你有什么需求,不妨仔细查看一下帮助,相信是都能满足的。

The man pages for the different programs are available here in HTML form:

  • vncconfig
  • vncpasswd
  • vncserver
  • vncviewer
  • x0vncserver
  • Xvnc
详细使用方法,可以参考man手册,以及TigerVnc的官方说明

8.参考资料

blog:http://www.centoscn.com/image-text/install/2014/0504/2905.html

官方资料:http://tigervnc.org/

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/ch-TigerVNC.html

0 0
原创粉丝点击