• Linux VNC server 安装配置


    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的桌面环境及输入装置。

    1.安装vnc server
    [root@pxe ~]# yum install tigervnc-server -y
     
    2.设置 vnc server 开机启动
    [root@pxe ~]# chkconfig vncserver on
     
    3.修改vncserver 配置文件
    [root@pxe ~]# vi /etc/sysconfig/vncservers
    在配置文件后添加以下内容
    VNCSERVERS="2:root"
    VNCSERVERARGS[2]="-geometry 1366x768 -nolisten tcp"
     
    设置vncserver 的密码
    [root@pxe ~]# vncpasswd 
    Password:
    Verify:
     
    4.启动sncserver 服务
    [root@pxe ~]# /etc/init.d/vncserver start
     
    5.使用VNC Viewer 远程连接
     
     
     
    CentOS7配置VNC
    centos7配置vnc远程.pdf
     
    一.安装
    以root用户运行以下命令来安装vncserver;
    yum install tigervnc-server 
    同样运行以下命令来安装vncviewer;
    yum install vnc
    停止并禁用防火墙;
    systemctl stop firewalld.service
    systemctl disable firewalld.service
     
    二.配置
    vncviewer基本上不用配置;
    vncserver的配置,创建一个新的配置文件,以开启1号窗口为例(也可以同时开启多个窗口,修改数字即可),方法如下:
    cp /lib/systemd/system/vncserver@.service /lib/systemd/system/vncserver@:1.service
    或者再增加一个窗口:
     
    cp /lib/systemd/system/vncserver@.service /lib/systemd/system/vncserver@:2.service
    编辑/lib/systemd/system/vncserver@:1.service,设置用户root相关参数
    [Service]
    Type=forking
    # Clean any existing files in /tmp/.X11-unix environment
    ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
    ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i -geometry 800x600"
    PIDFile=/root/.vnc/%H%i.pid
    ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
     
    三.应用
    更新systemctl以使其生效;
    systemctl daemon-reload 
    设置vncserver的密码;
     vncpasswd root
    按提示输入密码以及确认密码
    启动该服务用来启用vnc的1号窗口;
    systemctl start vncserver@:1.service  或者 vncserver :1
    关闭1号窗口:
    systemctl stop vncserver@:1.service   或者 vncserver -kill :1
    设置为开机自动启动;
    systemctl enable vncserver@:1.service
    End.
     
    一, 确认及安装VNCSERVER。
    1,首先确认你服务器是否配置了VNCSERVER,可以在命令行下敲入以下命令查看:
    [root@localhost: ~]#rpm -qa |grep vnc
    vnc-server-4.1.2-14.el5_3.1.i386.rpm    #返回VNCSEVER服务器端版本说明你已经安装了VNCSERVER。

    2,如果没有安装VNCSEVER,那么从光盘找到安装包进行安装。
    首先将光盘挂载(也叫解压)到某个目录这里是在/var/ftp/pub/下面建立了rhel5-64目录
    mount -o loop rhel-server-5.3-x86_64-dvd.iso /var/ftp/pub/rhel5-64/
    然后在/var/ftp/pub/rhel5-64/Server目录下找到 vnc-server-4.1.2-14.el5.x86_64.rpm安装包(也可以使用地址:
    http://centos.ustc.edu.cn/centos/5.5/os/i386/CentOS/vnc-server-4.1.2-14.el5_3.1.i386.rpm下载),使用

    RPM命令直接安装;
    rpm -ivh vnc-server-4.1.2-14.el5_3.1.i386.rpm


    或者使用yum安装:
    # yum install vnc


    二,开始配置VNCSERVER
    1,启动VNCSERVER,第一次启动VNCSERVER会提示输入密码,这里分为管理员账户及普通账户,启动方式略有所不同。
    管理员:
    [root@localhost /]# vncserver
    You will require a password to access your desktops.
    Password: 123456            #输入vnc 连接密码
    Verify: 123456                 #确认vnc密码
    xauth: creating new authority file /root/.Xauthority
    New ‘localhost.localdomain:1 (root)’ desktop is localhost.localdomain:1

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

    普通用户:
    [root@localhost /]#su ceboy    #ceboy 是用户名
    [ceboy@localhost /]$ vncserver
    You will require a password to access your desktops.
    Password: 123456            #输入vnc 连接密码
    Verify: 123456                 #确认vnc密码
    xauth: creating new authority file /home/ceboy/.Xauthority
    New ‘localhost.localdomain:2 (ceboy)’ desktop is localhost.localdomain:2
    Creating default startup script /home/ceboy/.vnc/xstartup
    Starting applications specified in /home/ceboy/.vnc/xstartup
    Log file is /home/ceboy/.vnc/localhost.localdomain:2.log

    #这里要注意:每个用户都可以启动自己的VNCSERVER远程桌面,同时每个用户可以启动多个VNCSERVER远程桌面,它们用ip加端口号:ip:1、ip:2、ip:3 来标识、区分,使用同一端口会使另外登录的用户自动退出。另,VNCSERVER的大部分配置文件及日志文件都在用户home目录下.vnc目录下。
    用户可以自定义启动号码如:
    [ceboy@localhost /]$ vncserver :2        #注意:2前面一定要有空格。
    A VNC server is already running as :2

    三,相关桌面配置,RedHat Linux支持两种图形模式:KDE模式和gnome模式。

    1,你的RH使用的什么图形模式这个一般只有登录到图形界面查看一下才能知道,或者通过ps -A命令列出所有当前运行的程序,看看有没有KDE或者gnome字样来判断一下。如果你是gnome桌面,那么你需要修改/root/.vnc/xstartup的配置文件。

    [root@localhost .vnc]# vi xstartup
    #!/bin/sh
    # Uncomment the following two lines for normal desktop:
    unset SESSION_MANAGER        #将此行的注释去掉
    exec /etc/X11/xinit/xinitrc        #将此行的注释去掉
    [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
    [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
    xsetroot -solid grey
    vncconfig -iconic &
    xterm -geometry 80X24+10+10 -ls -title "$VNCDESKTOP Desktop" &
    gnome-session gnome           #添加这一句是连接时使用gnome 桌面环境
    twm &

    设置修改完毕最好是重启一次系统,否则设置不会生效。我采用的方法是杀死VNCSERVER进程再重运行VNCSERVER。
    [root@localhost .vnc]#vncserver -kill :1      #这里你启动vncserver时是什么端口号要对应上。
    [root@localhost .vnc]#vncserver :1           #重启VNCSERVER,注意:1前面一定要有空格。

    2,设置用户信息及分辨率。

    [root@localhost: ~]#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
    # <URL:http://www.uk.research.att.com/archive/vnc/sshvnc.html >.
    # Use “-nolisten tcp” to prevent X connections to your VNC server via TCP.
    # Use “-nohttpd” to prevent web-based VNC clients connecting.
    # 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:ceboy"            #此处添加用户,一般只添加一个1:root也就行了。
    VNCSERVERARGS[1]="-geometry 800×600 -nolisten tcp -nohttpd -localhost"
    VNCSERVERARGS[2]="-geometry 1024×768 -nolisten tcp -nohttpd -localhost"
    #注意:上面是分别设置的root和ceboy两个用户的分辨率,注意是用端口号区分的。

    另外也可以通过命令行临时修改分辨率及色深,这种方式重启后就会丢失,这里暂时用不到,命令如下:
    [root@localhost: ~]#vncserver -geometry 800×600        #设置vncserver的分辨率   
    [root@localhost: ~]#vncserver -depth 16           #设置vncserver的色深

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

    四,客户端连接及使用。
    1,访问方式
    a、在linux下,运行vncviewer命令即可,服务器地址的写法形如192.168.1.11:1
    b、在windows下,运行windows版本的vncviewer即可,用法与linux下相近。
    c、用浏览器(平台无关),作为java applet来实现,以形如http://192.168.1.11: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

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

    3、配置分辨率和用户登录信息

    # vim /etc/sysconfig/vncservers

    参考最后两行添加自己的配置
    VNCSERVERS="2:root"
    VNCSERVERARGS[2]="-geometry 1024x768"

    4、配置 VNC 登录密码

    执行下列命令
    # vncserver
    首次执行提示设置密码,根据提示输入两次密码即可

    5、配置 VNC 登录桌面模式
    Centos Linux支持两种图形模式:KDE模式和gnome模式,如果是gnome桌面则需修改 /root/.vnc/xstartup 的配置相关项
    # vim /root/.vnc/xstartup

    个人理解上面的意思是用户目录下需要.vnc目录因为我的不需要配置就可以直接通过vnc viewver直接连接linux

    VNC的启动/停止/重启

    # service vncserver start/stop/restart

    关闭具体的vncserver命令:vncserver -kill :1       vncserver -kill :2

    如果没有安装采用yum安装
    yum -y install vnc
    2.
    配置VNC用户如果以root登录的话,输入
    vncpasswd
    Password:
    Verify:
    设置root用户的VNC登录用户名和密码
    3.配置vnc-server的配置文件

    /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
    #<URL:http://www.uk.research.att.com/archive/vnc/sshvnc.html>.
    # Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
    # Use "-nohttpd" to prevent web-based VNC clients connecting.
    # 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"
    # VNCSERVERS="2:myusername"
    # VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -nohttpd -localhost"
    VNCSERVERARGS[1]="-geometry 800x600"
    1.VNCSERVERS=后面可以支持多用户,以空格隔开。如:
    VNCSERVERS="1:myusername 15:otheruser"--->这里的1 和15是端口号,用于连接时的端口
    2.VNCSERVERARGS后面的[]里面的数据要与VNCSERVERS后面对应用户的值要一致。好像不一致也没有关系
    VNCSERVERARGS基本参数有:
    -geometry 桌面大小,缺省是1024x768
    -nohttpd 不监听HTTP端口
    -nolisten tcp 不监听X端口
    -localhost 只允许从本机访问
    -AlwaysShared 默认的, 同时只能有一个vncviewer连接(跟客户端配置也有关), 一旦第2个连上去, 第1个就被断开了. 此参数允许同时连多个vncviewer
    -SecurityTypes None登录不需要密码认证 VncAuth默认值,要密码认证
    启动vncserver
    /sbin/nvcserver start
    如果没有出错的话,就会启动vnc服务了
    4.修改默认桌面设置
    在root的用户目录下面的.vnc目录下面会产生一些文件,我们现在要修改xstartup
    #!/bin/sh
    # Uncomment the following two lines for normal desktop: (去掉以下两行的#就可以允许使用桌面了)
    unset SESSION_MANAGER
    exec /etc/X11/xinit/xinitrc
    [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
    [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
    xsetroot -solid grey
    vncconfig -iconic &
    #xterm -geometry 80x24 10 10 -ls -title "$VNCDESKTOP Desktop" &
    #twm & ---把这两行注释掉,加上
    #exec startxfce4
    gnome-session
    重新启动vncserver
    netstat -antpl查看可以发现有三个端口在监听。
    5901 5801 6001
    这三个端口:
    默认的, vnc 服务监听3个TCP端口
    RFB(Remote FrameBuffer)协议 默认端口 : 5900 显示器号
    HTTP协议默认端口 : 5800 显示器号
    X协议 默认端口 : 6000 显示器号
    vncserver使用的显示器编号默认从1开始, 依次使用, 也可以参数指定端口号
    我们只需要RFB协议就可以了,所以我们把5800 6000这两种端口关掉。
    需要修改/etc/sysconfig/vncservers
    在参数后面加上:
    -nohttpd 不监听HTTP端口

    -nolisten tcp 不监听X端口

    5. Windows登陆到VNC Server

    (1).从IE登录
    直接从IE浏览器中输入如下地址:
    http://xxx.xxx.xxx.xxx:5801
    输入密码即可使用。
    (2).从VNC view登录
    在windows上安装vnc view,然后输入xxx.xxx.xxx.xxx:1,连接登录,输入密码即可。
    备注:如果从vnc view登录时,提示connection refused(10061),则是因为linux防火墙的问题,登录centos系统,选择 System-->Preferences-->Remote Desktop,勾选sharing中的两项,Security两项不勾,点击关闭,然后再重新用vnc view登录即可。

  • 相关阅读:
    从零开始学VUE之组件化开发(组件数据的存放)
    从零开始学VUE之组件化开发(组件分离写法)
    从零开始学VUE之组件化开发(语法糖优化组件注册)
    进程与线程的一个简单解释
    Crontab爬虫定时执行
    接口分类复习
    最长公共子串
    最长公共子序列(力扣第1143题)
    Reduce端分组排序源码分析
    Job提交流程源码和切片源码详解
  • 原文地址:https://www.cnblogs.com/klb561/p/10371839.html
Copyright © 2020-2023  润新知