NeoKylin Linux Advanced Server release V7Update6 (Chromium)

image.png

查看操作系统信息

[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.aarch64

Build:
NeoKylin Linux Advanced Server 
release V7Update6/(Chromium)-aarch64
b06.lic/20190619

安装vncserver

以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

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  with the actual user name and edit vncserver
#    parameters appropriately
#    (ExecStart=/usr/sbin/runuser -l  -c "/usr/bin/vncserver %i"
#     PIDFile=/home//.vnc/%H%i.pid)
# 3. Run `systemctl daemon-reload`
# 4. Run `systemctl enable vncserver@:.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 environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l  -c "/usr/bin/vncserver %i"
PIDFile=/home//.vnc/%H%i.pid
ExecStop=/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 root
Password:
Verify:
Would you like to enter a view-only password (y/n)? y
Password:
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连接

安装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

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

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

[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:07:23 CST; 7s ago
Process: 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 process
exited, code=exited status=1
4月 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 failed
state.
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.service
Job 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 ago
Process: 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 process
exited, code=exited status=98
4月 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 failed
state.
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 #禁用

results matching ""

    No results matching ""