新手指南

当前位置:首页>新手指南

如何使用VNC远程连接麒麟(Kylin)操作系统?

时间:2022-03-08   

开发者使用麒麟(Kylin)操作系统时通常需要使用客户端工具连接操作系统以达到文件管理,执行命令以及安装应用的目的。远程连接已经安装麒麟(Kylin)操作系统的服务的方法有很多种,本文主要阐述如何使用VNC远程连接麒麟(Kylin)操作系统。


一、先决条件:

1、可以使用root或者其他有管理员权限的账号登录麒麟(Kylin)操作系统。

2、用于远程连接服务器的客户端与服务器之前网络有连通性保证;

3、服务器用于的SSH端口22可以被正常访问,用于VNC连接的端口5901、5902可以被正常访问。

二、如何连接麒麟(Kylin)操作系统

演示操作系统版本:NeoKylin Linux Advanced Server release V7Update6 (Chromium)


image.png

三、使用root权限登录操作系统安装必要软件

1、查看操作系统信息

[root@ecs-f61c-0001 ~]# nkvers############## NeoKylin Linux Version#################Release:NeoKylin Linux Advanced Server release V7Update6 (Chromium)Kernel:4.14.0-115.5.1.el7a.06.aarch64Build:NeoKylin Linux Advanced Server 
release V7Update6/(Chromium)-aarch64b06.lic/20190619

2、安装VNC Server

以root用户运行以下命令来安装vncserver

[root@ecs-f61c-0001 sysconfig]# yum install tigervnc-server


同样运行以下命令来安装vncviewer

[root@ecs-f61c-0001 sysconfig]# yum install vnc


停止并禁用防火墙,或者开放5901,5902端口


[root@ecs-f61c-0001 sysconfig]# systemctl stop firewalld.service[root@ecs-f61c-0001 sysconfig]# systemctl disable firewalld.service


3、VNC配置和应用

vncserver的配置,创建一个新的配置文件,以开启1号窗口为例(也可以同时开启多个窗口,修改数字即可),方法如下(以下命令复制了两个vncserver服务,也就是可以同时允许2个桌面启动,多个桌面以此类推):

[root@ecs-f61c-0001 sysconfig]# cp /lib/systemd/system/vncserver@.service /lib/systemd/system/vncserver@:1.service[root@ecs-f61c-0001 sysconfig]# cp /lib/systemd/system/vncserver@.service /lib/systemd/system/vncserver@:2.service


编辑/lib/systemd/system/vncserver@:1.service,设置用户root相关参数,最终内容如下(如果有多个服务,全部需要查看一下,一般不需要修改):

# The vncserver service unit file## Quick HowTo:# 1. Copy this file to /etc/systemd/system/vncserver@.service# 2. Replace <USER> with the actual user name and edit vncserver#    parameters appropriately#    (ExecStart=/usr/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"#     PIDFile=/home/<USER>/.vnc/%H%i.pid)# 3. Run `systemctl daemon-reload`# 4. Run `systemctl enable vncserver@:<display>.service`## DO NOT RUN THIS SERVICE if your local area network is# untrusted!  For a secure way of using VNC, you should# limit connections to the local host and then tunnel from# the machine you want to view VNC on (host A) to the machine# whose VNC output you want to view (host B)## [user@hostA ~]$ ssh -v -C -L 590N:localhost:590M hostB## this will open a connection on port 590N of your hostA to hostB's port 590M# (in fact, it ssh-connects to hostB and then connects to localhost (on hostB).# See the ssh man page for details on port forwarding)## You can then point a VNC client on hostA at vncdisplay N of localhost and with# the help of ssh, you end up seeing what hostB makes available on port 590M## 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.[Unit]Description=Remote desktop service (VNC)After=syslog.target network.tarGET@[Service]Type=forking# Clean any existing files in /tmp/.X11-unix environmentExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'ExecStart=/usr/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"PIDFile=/home/<USER>/.vnc/%H%i.pidExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'[Install]WantedBy=multi-user.target


更新systemctl以使其生效

[root@ecs-f61c-0001 sysconfig]# systemctl daemon-reload

设置vncserver的密码

[root@ecs-f61c-0001 sysconfig]# vncpasswd rootPassword:Verify:Would you like to enter a view-only password (y/n)? yPassword:Verify:

按提示输入密码以及确认密码


启动指定的桌面服务

[root@ecs-f61c-0001 sysconfig]# systemctl start vncserver@:1.service或者[root@ecs-f61c-0001 sysconfig]# vncserver :1

其他桌面类似


关闭指定的桌面服务

[root@ecs-f61c-0001 sysconfig]# systemctl stop vncserver@:1.service或者[root@ecs-f61c-0001 sysconfig]# vncserver -kill :1

其他桌面类似

将桌面服务设置为开机自动启动

[root@ecs-f61c-0001 sysconfig]# systemctl enable vncserver@:1.service[root@ecs-f61c-0001 sysconfig]# systemctl enable vncserver@:2.service


四、测试VNC连接

1、安装VNC客户端


RealVNC官网:https://www.realvnc.com/en/connect/download/viewer/

下载地址:https://www.realvnc.com/download/file/viewer.files/VNC-Viewer-6.20.529-Windows.exe

image.png

安装客户端(略)

启动客户端:

image.png


连接服务器桌面:

image.png

输入密码连接成功:

image.png

正常登录服务器并且进行操作:

image.png


5、可能遇到的问题(CentOS环境下)

1.设置为非root用户报错:

[root@ecs-f61c-0001 sysconfig]# systemctl status -l vncserver@:2.servicevncserver@:2.service - Remote desktop service (VNC)Loaded: loaded (/etc/systemd/system/vncserver@:2.service; enabled; vendor preset:disabled)Active: failed (Result: exit-code) since 一 2016-04-25 19:07:23 CST; 7s agoProcess: 10305 ExecStart=/usr/sbin/runuser -l fang -c /usr/bin/vncserver %i (code=exited,status=1/FAILURE)Process: 10291 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || :(code=exited, status=0/SUCCESS)
4月 25 19:07:23 localhost.localdomain systemd[1]: Starting Remote desktop service (VNC)...4月 25 19:07:23 localhost.localdomain systemd[1]: vncserver@:2.service: control processexited, code=exited status=14月 25 19:07:23 localhost.localdomain systemd[1]: Failed to start Remote desktop service(VNC).4月 25 19:07:23 localhost.localdomain systemd[1]: Unit vncserver@:2.service entered failedstate.4月 25 19:07:23 localhost.localdomain systemd[1]: vncserver@:2.service failed.

2.Type=forking报错,改为Type=simple

[root@ecs-f61c-0001 sysconfig]#  systemctl start vncserver@:2.serviceJob for vncserver@:2.service failed because the control process exited with error code. See"systemctl status vncserver@:2.service" and "journalctl -xe" for details.[root@ecs-f61c-0001 sysconfig]#  systemctl status -l vncserver@:2.service● vncserver@:2.service - Remote desktop service (VNC)Loaded: loaded (/etc/systemd/system/vncserver@:2.service; enabled; vendor preset:disabled)Active: failed (Result: exit-code) since 一 2016-04-25 19:09:41 CST; 6s agoProcess: 12367 ExecStart=/usr/sbin/runuser -l root -c /usr/bin/vncserver %i (code=exited,status=98)Process: 12354 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || :(code=exited, status=0/SUCCESS)
4月 25 19:09:41 localhost.localdomain systemd[1]: Starting Remote desktop service (VNC)...4月 25 19:09:41 localhost.localdomain systemd[1]: vncserver@:2.service: control processexited, code=exited status=984月 25 19:09:41 localhost.localdomain systemd[1]: Failed to start Remote desktop service(VNC).4月 25 19:09:41 localhost.localdomain systemd[1]: Unit vncserver@:2.service entered failedstate.4月 25 19:09:41 localhost.localdomain systemd[1]: vncserver@:2.service failed.

3.vnc viewer客户端连接黑屏,改变xstartup的权限

这个问题是很多人容易忽视的问题,也是造成连接成功后黑屏的原因之一。

在CentOS中,xstartup的文件路径为:/root/.vnc/ (可以通过locate xstartup来查看xstartup的文件路径)

所以需要执行:

[root@ecs-f61c-0001 sysconfig]# chmod 777 /root/.vnc/xstartup

关闭防火墙


[root@ecs-f61c-0001 sysconfig]# systemctl stop firewalld.service #停止[root@ecs-f61c-0001 sysconfig]# systemctl disable firewalld.service #禁用

logo_all@1.5x.png


以上内容主主要介绍通过VNC远程连接Linux操作系统(Kylin操作系统)的配置方式,希望对您有帮助。


上一篇:如何在阿里云ECS服务器中配置服务器安全策略

下一篇:O2OA快捷键