您的位置:首页 > 运维架构 > Linux

linux如何安装与配置Linux VNC服务

2015-07-15 10:15 676 查看
说明:
文章前半部分是转载别人的文章,具体详看:http://gushiren.blog.51cto.com/3392832/1673788
一、Redhat上VNC Server配置
前提:连接到互联网,将使用yum在线安装VNC服务器
1.安装 TigerVNC Server
# yum searchtigervnc-server
  返回大概如下内容:
tigervnc-server.x86_64: A TigerVNC Server
tigervnc-server-applet.noarch: Java TigerVNC Viewer applet for TigerVNC Server
tigervnc-server-module.x86._64: TigerVNC Mode to Xorg

  第一行即是我们要安装的VNS服务器,第二行是客户端,执行
# yum installtigervnc-server.x86_64 或者yum install tigervnc*回车后会有一次安装确认,输入y后回车即可安装,安装完毕命令行输入光标,执行# vncserver会提示输入验证密码,至少6位,该密码是客户端连接时用到的。2.配置图形界面  修改配置文件,激活图形界面,执行命令:# vi /root/.vnc/xstartup  注释掉这行#twm & // 注释该行  末尾增加一行gnome-session & // 增加该行  保存退出3.启动VNC服务  执行命令# /etc/init.d/vncserver start  或# service vncserver start  启动后提示:Starting VNC server: no displays configured [FAILED]  解决方法:  执行命令# vim /etc/sysconfig/vncservers  修改最后两行如:VNCSERVERS="1:root"VNCSERVERARGS[1]="-geometry 1024x768"  说明:  第一行为服务配置,当前只配置了一个VNC服务,使用用户root启动,如果还需要使用其他用户登陆,可以修改VNCSERVERS的值如:“1:root 2:tiger”(tiger为系统另一存在用户)。第二行可以注释,是配置窗口分辨率的,需要去掉后面的-localhostVNC Server随系统自动启动  执行命令# sudo chkconfig --level 345 vncserver on4.停止VNC服务  执行命令# /etc/init.d/vncserver stop  或# service vncserver stop  二、Windows借助VNC Viewer访问Linux  首先安装RealVNC,从互联网下载获得  开始 - Run VNC Viewer,输入IP地址,后面的:1代表使用root用户登陆,在RH上配置的1:root,如果想使用其他用户登陆则调整冒号后的数字即可,密码就是先前配置的。格式:IP地址:1  解决连接不上问题的方法  执行命令,查看VNC监听的端口是什么,在防火墙中开放端口即可或者停止防火墙# netstat -ntupl|grep vnc  返回列表如:1. tcp 0 0 0.0.0.0:59010.0.0.0:* LISTEN 4411/Xvnc2. tcp 0 0 0.0.0.0:60010.0.0.0:* LISTEN 4411/Xvnc3. tcp 0 0 :::6001 :::* LISTEN 4411/Xvnc  修改防火墙配置文件,开放5901端口即可# vi /etc/sysconfig/iptables  可以复制22端口一行,黏贴修改即可,重新启动防火墙服务# service iptables restart完整命令 [root@localhost ~]#yum install tigervnc* ======》yum在线安装软件已加载插件:fastestmirror, product-id, refresh-packagekit, subscription-managerThis system isnot registered to Red Hat Subscription Management. You can usesubscription-manager to register.设置安装进程Loading mirrorspeeds from cached hostfile解决依赖关系--> 执行事务检查---> Packagetigervnc.x86_64 0:1.1.0-16.el6.centoswill be 安装---> Packagetigervnc-server.x86_64 0:1.1.0-16.el6.centoswill be 安装---> Packagetigervnc-server-applet.noarch 0:1.1.0-16.el6.centoswill be 安装---> Packagetigervnc-server-module.x86_64 0:1.1.0-16.el6.centoswill be 安装--> 完成依赖关系计算依赖关系解决============================================== 软件包 架构 版本 仓库 大小================================================================正在安装: tigervnc x86_64 1.1.0-16.el6.centos updates 185 k tigervnc-server x86_64 1.1.0-16.el6.centos updates 1.0 M tigervnc-server-applet noarch 1.1.0-16.el6.centos updates 108 k tigervnc-server-module x86_64 1.1.0-16.el6.centos updates 213 k事务概要==============================================================Install 4 Package(s)总下载量:1.5 MInstalled size:3.7 M确定吗?[y/N]:y下载软件包:(1/4): tigervnc-1.1.0-16.el6.centos.x86_64.rpm | 185 kB 00:01 (2/4):tigervnc-server-1.1.0-16.el6.centos.x86_64.rpm | 1.0 MB 00:03 (3/4):tigervnc-server-applet-1.1.0-16.el6.centos.noarch| 108 kB 00:00 (4/4):tigervnc-server-module-1.1.0-16.el6.centos.x86_64| 213 kB 00:00 --------------------------------------------------------------------------------总计 228kB/s | 1.5 MB 00:06 运行 rpm_check_debug执行事务测试事务测试成功执行事务 正在安装 : tigervnc-server-1.1.0-16.el6.centos.x86_64 1/4 正在安装 : tigervnc-server-applet-1.1.0-16.el6.centos.noarch 2/4 正在安装 : tigervnc-1.1.0-16.el6.centos.x86_64 3/4 正在安装 : tigervnc-server-module-1.1.0-16.el6.centos.x86_64 4/4 Verifying : tigervnc-server-module-1.1.0-16.el6.centos.x86_64 1/4 Verifying : tigervnc-server-1.1.0-16.el6.centos.x86_64 2/4 Verifying : tigervnc-server-applet-1.1.0-16.el6.centos.noarch 3/4 Verifying : tigervnc-1.1.0-16.el6.centos.x86_64 4/4已安装: tigervnc.x86_64 0:1.1.0-16.el6.centos tigervnc-server.x86_64 0:1.1.0-16.el6.centos tigervnc-server-applet.noarch 0:1.1.0-16.el6.centos tigervnc-server-module.x86_64 0:1.1.0-16.el6.centos 完毕![root@localhost ~]# vncserver ======》设置登录密码,输入验证密码,至少6位,该密码是客户端连接时用到的You will requirea password to access your desktops.Password:1103324414Verify:1103324414xauth: creating new authority file /root/.XauthorityNew'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1Creating defaultstartup script /root/.vnc/xstartupStartingapplications specified in /root/.vnc/xstartupLog file is/root/.vnc/localhost.localdomain:1.log[root@localhost ~]# vim /root/.vnc/xstartup =====》开启图形界面#!/bin/sh[ -r/etc/sysconfig/i18n ] && . /etc/sysconfig/i18nexport LANGexport SYSFONTvncconfig-iconic &unsetSESSION_MANAGERunsetDBUS_SESSION_BUS_ADDRESSOS=`uname -s`if [ $OS ='Linux' ]; then case "$WINDOWMANAGER" in *gnome*) if [ -e /etc/SuSE-release ]; then PATH=$PATH:/opt/gnome/bin export PATH fi ;; esacfiif [ -x/etc/X11/xinit/xinitrc ]; then exec /etc/X11/xinit/xinitrcfiif [ -f/etc/X11/xinit/xinitrc ]; then exec sh /etc/X11/xinit/xinitrcfi[ -r$HOME/.Xresources ] && xrdb $HOME/.Xresourcesxsetroot -solidgreyxterm -geometry80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &#twm &gnome-session &".vnc/xstartup"30L, 671C 已写入 [root@localhost~]# service vncserver statusXvnc (pid 3968) 正在运行...[root@localhost~]# service vncserver restart关闭 VNC 服务器:[失败]正在启动 VNC 服务器:nodisplays configured [失败] [root@localhost ~]# service vncserver stop关闭 VNC 服务器:[失败][root@localhost~]# service vncserver start正在启动 VNC 服务器:nodisplays configured [失败][root@localhost ~]# vim /etc/sysconfig/vncservers ======》编辑登录用户,修改分辨率 # The VNCSERVERSvariable is a list of display:user pairs.## Uncomment thelines below to start a VNC server on display :2# as my'myusername' (adjust this to your own). You will also# need to set aVNC password; run 'man vncpasswd' to see how# to do that.## DO NOT RUNTHIS SERVICE if your local area network is#untrusted! For a secure way of usingVNC, see this URL:#https://access.redhat.com/knowledge/solutions/7027 # Use"-nolisten tcp" to prevent X connections to your VNC server via TCP. # Use"-localhost" to prevent remote VNC clients connecting except when# doing sothrough a secure tunnel. See the"-via" option in the# `manvncviewer' manual page. VNCSERVERS="1:root"# VNCSERVERARGS[1]="-geometry 1024x768 ""/etc/sysconfig/vncservers"19L, 745C 已写入 [root@localhost ~]# chkconfig --level 345 vncserver on========》开机启动[root@localhost ~]# /etc/init.d/vncserver restart ====》注意启动失败的提示关闭 VNC 服务器:[确定]正在启动 VNC 服务器:1:rootWarning:localhost.localdomain:1 is taken because of /tmp/.X1-lockRemove this fileif there is no X server localhost.localdomain:1A VNC server isalready running as :1[失败] [root@localhost ~]# cd/tmp/ ======?进入到失败提示的目录[root@localhost tmp]# lskeyring-I5r3Uo pulse-Bj8Ca1cagmpn virtual-root.4aswhI VMwareDnDkeyring-lU5Juj pulse-hvB4wFMaeoLd virtual-root.HVHL6f vmware-rootorbit-gdm ssh-aICQHU3879 virtual-root.ijnIyc vmware-root-860006770orbit-root uptime.sh virtual-root.wPiLgI[root@localhosttmp]# ls -al总用量 92drwxrwxrwt. 20root root 4096 7月 15 09:29 .dr-xr-xr-x. 27root root 4096 7月 15 09:14 ..drwx------. 2 root root 4096 7月 15 09:15 .esd-0drwx------. 2 sandu sandu 4096 5月 5 17:23 .esd-500drwxrwxrwt. 2 root root 4096 7月 15 09:24 .ICE-unixdrwx------. 2 root root 4096 7月 15 09:24 keyring-I5r3Uodrwx------. 2 root root 4096 7月 15 09:15 keyring-lU5Jujdrwx------. 2 gdm gdm 4096 7月 15 09:15 orbit-gdmdrwx------. 2 root root 4096 7月 15 09:29 orbit-rootdrwx------. 2 gdm gdm 4096 7月 15 09:15 pulse-Bj8Ca1cagmpndrwx------. 2 root root 4096 7月 15 09:24 pulse-hvB4wFMaeoLddrwx------. 2 root root 4096 7月 15 09:21 ssh-aICQHU3879-rw-r--r--. 1 root root 235 6月 8 09:39 uptime.shdrwx------. 2 root root 4096 7月 15 09:24 virtual-root.4aswhIdrwx------. 2 root root 4096 7月 15 09:15 virtual-root.HVHL6fdrwx------. 2 root root 4096 6月 9 08:28 virtual-root.ijnIycdrwx------. 2 root root 4096 6月 24 08:54 virtual-root.wPiLgIdrwxrwxrwt. 2 root root 4096 6月 9 08:26 VMwareDnDdrwx------. 2 root root 4096 7月 15 09:24 vmware-rootdrwx------. 2 root lp 4096 6月 9 08:25 vmware-root-860006770-r--r--r--. 1 root root 11 7月 15 09:14 .X0-lockdrwxrwxrwt. 2 root root 4096 7月 15 09:24 .X11-unix-r--r--r--. 1 root root 11 7月 15 09:24 .X1-lock[root@localhost tmp]# rm -rf .X1-lock ======》删除启动失败提示的文件[root@localhost tmp]# /etc/init.d/vncserver start ======》启动还是失败,继续删除提示的文件正在启动 VNC 服务器:1:rootWarning:localhost.localdomain:1 is taken because of /tmp/.X11-unix/X1Remove this fileif there is no X server localhost.localdomain:1A VNC server isalready running as :1[失败][root@localhosttmp]# ls -al总用量 88drwxrwxrwt. 20root root 4096 7月 15 09:34 .dr-xr-xr-x. 27root root 4096 7月 15 09:14 ..drwx------. 2 root root 4096 7月 15 09:15 .esd-0drwx------. 2 sandu sandu 4096 5月 5 17:23 .esd-500drwxrwxrwt. 2 root root 4096 7月 15 09:24 .ICE-unixdrwx------. 2 root root 4096 7月 15 09:24 keyring-I5r3Uodrwx------. 2 root root 4096 7月 15 09:15 keyring-lU5Jujdrwx------. 2 gdm gdm 4096 7月 15 09:15 orbit-gdmdrwx------. 2 root root 4096 7月 15 09:29 orbit-rootdrwx------. 2 gdm gdm 4096 7月 15 09:15 pulse-Bj8Ca1cagmpndrwx------. 2 root root 4096 7月 15 09:24 pulse-hvB4wFMaeoLddrwx------. 2 root root 4096 7月 15 09:21 ssh-aICQHU3879-rw-r--r--. 1 root root 235 6月 8 09:39 uptime.shdrwx------. 2 root root 4096 7月 15 09:24 virtual-root.4aswhIdrwx------. 2 root root 4096 7月 15 09:15 virtual-root.HVHL6fdrwx------. 2 root root 4096 6月 9 08:28 virtual-root.ijnIycdrwx------. 2 root root 4096 6月 24 08:54 virtual-root.wPiLgIdrwxrwxrwt. 2 root root 4096 6月 9 08:26 VMwareDnDdrwx------. 2 root root 4096 7月 15 09:24 vmware-rootdrwx------. 2 root lp 4096 6月 9 08:25 vmware-root-860006770-r--r--r--. 1 root root 11 7月 15 09:14 .X0-lockdrwxrwxrwt. 2 root root 4096 7月 15 09:24 .X11-unix[root@localhost tmp]# rm -rf .X* =====》删除提示的文件[root@localhost tmp]# ls -al总用量 80drwxrwxrwt. 19root root 4096 7月 15 09:34 .dr-xr-xr-x. 27root root 4096 7月 15 09:14 ..drwx------. 2 root root 4096 7月 15 09:15 .esd-0drwx------. 2 sandu sandu 4096 5月 5 17:23 .esd-500drwxrwxrwt. 2 root root 4096 7月 15 09:24 .ICE-unixdrwx------. 2 root root 4096 7月 15 09:24 keyring-I5r3Uodrwx------. 2 root root 4096 7月 15 09:15 keyring-lU5Jujdrwx------. 2 gdm gdm 4096 7月 15 09:15 orbit-gdmdrwx------. 2 root root 4096 7月 15 09:29 orbit-rootdrwx------. 2 gdm gdm 4096 7月 15 09:15 pulse-Bj8Ca1cagmpndrwx------. 2 root root 4096 7月 15 09:24 pulse-hvB4wFMaeoLddrwx------. 2 root root 4096 7月 15 09:21 ssh-aICQHU3879-rw-r--r--. 1 root root 235 6月 8 09:39 uptime.shdrwx------. 2 root root 4096 7月 15 09:24 virtual-root.4aswhIdrwx------. 2 root root 4096 7月 15 09:15 virtual-root.HVHL6fdrwx------. 2 root root 4096 6月 9 08:28 virtual-root.ijnIycdrwx------. 2 root root 4096 6月 24 08:54 virtual-root.wPiLgIdrwxrwxrwt. 2 root root 4096 6月 9 08:26 VMwareDnDdrwx------. 2 root root 4096 7月 15 09:24 vmware-rootdrwx------. 2 root lp 4096 6月 9 08:25 vmware-root-860006770[root@localhost tmp]# /etc/init.d/vncserver start =====》正常启动正在启动 VNC 服务器:1:rootNew'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1Startingapplications specified in /root/.vnc/xstartupLog file is/root/.vnc/localhost.localdomain:1.log [确定][root@localhosttmp]# cd[root@localhost ~]# netstat -tulnp | grep vnc ======》查看服务侦听的端口tcp 0 00.0.0.0:5801 0.0.0.0:* LISTEN 4858/Xvnc tcp 0 0 0.0.0.0:5901 0.0.0.0:* LISTEN 4858/Xvnc tcp 0 0 0.0.0.0:6001 0.0.0.0:* LISTEN 4858/Xvnc tcp 0 0 :::6001 :::* LISTEN 4858/Xvnc [root@localhost ~]# service iptables stop ======》停用防火墙或者修改防火墙配置使服务侦听的端口放行iptables:将链设置为政策 ACCEPT:filter [确定]iptables:清除防火墙规则:[确定]iptables:正在卸载模块:[确定][root@localhost~]# yum search tigervnc-server已加载插件:fastestmirror, product-id, refresh-packagekit, subscription-managerThis system isnot registered to Red Hat Subscription Management. You can usesubscription-manager to register.Loading mirrorspeeds from cached hostfile=========================================N/S Matched: tigervnc-server ==========================================tigervnc-server.x86_64: A TigerVNC servertigervnc-server-applet.noarch: Java TigerVNC viewer applet for TigerVNC servertigervnc-server-module.x86_64: TigerVNC module to Xorg Name and summary matches only, use"search all" for everything. 桌面登录:

格式:“IP地址:1”若未出现下面这个界面或者有各种各样的错误提示,一般是linux系统防火墙的问题,按照上面的所说修改防火墙配置即可


输入配置的密码

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Linux VNC