• centos安装vnc


    安装环境:
    vnc服务端:

    [root@localhost ~]# cat /etc/issue
    CentOS release 6.8 (Final)
    Kernel 
     on an m

    vnc客户端: win7-64

    1、安装VNC

    [root@localhost ~]# yum install tigervnc-server tigervnc -y
    

    2、配置vncservers文件

    [root@localhost ~]# vim /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:
    # 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 so through a secure tunnel.  See the "-via" option in the
    # `man vncviewer' manual page.
    
    
    VNCSERVERS="1:root 2:lqs2"
    VNCSERVERARGS[1]="-geometry  1024x768 -nolisten tcp"
    VNCSERVERARGS[2]="-geometry  1024x768 -nolisten tcp"
    
    ~                                                       

    VNCSERVERS 是用来设定可以使用VNC的服务器账号,可以设定多个,例如上面root、lqs2,但是中间要用空格隔开。使用VNCVIEWER登录时,192.168.255.130:1表示是以root账号登录,以此类推。

    关于参数配置说明:

    1:-geometry 表示桌面分辨率,默认为1024x768,所以上面的1024x768也可以不写。

    2:-nohttpd 表示不监听HTTP端口(58xx)。

    3:-nolisten tcp 表示不监听TCP端口(60xx)

    4:-localhost 只运行从本机访问。

    5:AlwaysShared 默认只允许一个VNCVIEWER连接,此参数表示同一个显示端口允许多用户同时登录.

    6:-depth 表示色深,参数有8,16,24,32.

    7: SecurityTypes None 登录不需要密码认证VncAuth默认值,要密码认证。

    3、设置VNC用户密码

    如果此时不设置VNC用户密码,启动vncserver服务,则会报如下错误:

    [root@localhost ~]# service vncserver start
    Starting VNC server: 1:root 
    You will require a password to access your desktops.
    
    getpassword error: Inappropriate ioctl for device
    Password:2:lqs2 
    You will require a password to access your desktops.
    
    getpassword error: Inappropriate ioctl for device
    Password:                                                  [FAILED]
    

    设置密码

    [root@localhost ~]# vncpasswd
    Password:
    Verify:
    [root@localhost ~]# su lqs2
    [lqs2@localhost root]$ vncpasswd
    Password:
    Verify:
    

    4、启动vncserver服务

    [lqs2@localhost root]$ su
    Password: 
    
    [root@localhost ~]# vncserver 
    [root@localhost .vnc]# ls
    localhost.localdomain:3.log  localhost.localdomain:3.pid  passwd  xstartup
    

    VNC会在用户根目录($HOME)下的”.vnc”文件夹下生成一系列文件。其中passwd为vnc用户密码文件,由vncpasswd生成。其他的都由vnc初次启动时生成,xstartup为VNC客户端连接时启动的脚本

    5、配置xstartup文件
    只需修改最后一行

    [root@localhost .vnc]# vim xstartup 
    #!/bin/sh
    
    [ -r /etc/sysconfig/i18n ] && . /etc/sysconfig/i18n
    export LANG
    export SYSFONT
    vncconfig -iconic &
    unset SESSION_MANAGER
    unset DBUS_SESSION_BUS_ADDRESS
    OS=`uname -s`
    if [ $OS = 'Linux' ]; then
      case "$WINDOWMANAGER" in
        *gnome*)
          if [ -e /etc/SuSE-release ]; then
            PATH=$PATH:/opt/gnome/bin
            export PATH
          fi
          ;;
      esac
    fi
    if [ -x /etc/X11/xinit/xinitrc ]; then
      exec /etc/X11/xinit/xinitrc
    fi
    if [ -f /etc/X11/xinit/xinitrc ]; then
          exec sh /etc/X11/xinit/xinitrc
    fi
    [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
    xsetroot -solid grey
    xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
    gnome-session &
                                                                  29,1          Bot
    
    

    切换到用户lqs2,并修改

    [root@localhost .vnc]# su lqs2
    [lqs2@localhost .vnc]$ 
    [lqs2@localhost .vnc]$ vim /home/lqs2/.vnc/xstartup 
    export SYSFONT
    vncconfig -iconic &
    unset SESSION_MANAGER
    unset DBUS_SESSION_BUS_ADDRESS
    OS=`uname -s`
    if [ $OS = 'Linux' ]; then
      case "$WINDOWMANAGER" in
        *gnome*)
          if [ -e /etc/SuSE-release ]; then
            PATH=$PATH:/opt/gnome/bin
            export PATH
          fi
          ;;
      esac
    fi
    if [ -x /etc/X11/xinit/xinitrc ]; then
      exec /etc/X11/xinit/xinitrc
    fi
    if [ -f /etc/X11/xinit/xinitrc ]; then
      exec sh /etc/X11/xinit/xinitrc
    fi
    [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
    xsetroot -solid grey
    xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
    gnome-session &
    

    启动vnc-server

    [root@localhost .vnc]# service vncserver restart
    Shutting down VNC server: 1:root 2:lqs2                    [  OK  ]
    Starting VNC server: 1:root 
    Warning: localhost.localdomain:1 is taken because of /tmp/.X1-lock
    Remove this file if there is no X server localhost.localdomain:1
    A VNC server is already running as :1
    2:lqs2 
    New 'localhost.localdomain:2 (lqs2)' desktop is localhost.localdomain:2
    
    Starting applications specified in /home/lqs2/.vnc/xstartup
    Log file is /home/lqs2/.vnc/localhost.localdomain:2.log
    
                                                               [  OK  ]
    

    6、配置防火墙

    [root@localhost ~]# iptables -I INPUT -p tcp --dport 5901 -j ACCEPT
    [root@localhost ~]# iptables -I INPUT -p tcp --dport 5902 -j ACCEPT

    关于VNC服务使用的端口号与桌面号相关,VNC使用TCP端口从5900开始,对应关系如下
    桌面号为“1” —- 端口号为5901
    桌面号为“2” —- 端口号为5902
    桌面号为“3” —- 端口号为5903
    ……
    基于Java的VNC客户程序Web服务TCP端口从5800开始,也是与桌面号相关,对应关系如下
    桌面号为“1” —- 端口号为5801
    桌面号为“2” —- 端口号为5802
    桌面号为“3” —- 端口号为5803

    开机自启动vncserver

    [root@localhost ~]# chkconfig vncserver on
    

    win7下载vnc viewer,连接访问
    [参考资料]:
    http://www.cnblogs.com/kerrycode/p/3315793.html
    http://www.ha97.com/4634.html

  • 相关阅读:
    block的使用
    控制器的多种创建方式
    指针函数和函数指针
    UIScrollView实现图片轮播器及其无限循环效果
    如何按顺序执行两个动画
    代理、通知、KVO的应用
    CAlayer层的属性
    UIView的autoresizingMask和autoresizesSubviews属性的剖析
    面向对象编程思想(OOP)总结
    scala中闭包的使用
  • 原文地址:https://www.cnblogs.com/fanren224/p/8457296.html
Copyright © 2020-2023  润新知