linux上安装部署vnc远程服务

本文操作环境为:

[root@localhost ~]# uname -a
Linux localhost.localdomain 4.19.90-17.ky10.aarch64 #1 SMP Sun Jun 28 14:27:40 CST 2020 aarch64 aarch64 aarch64 GNU/Linux
[root@localhost ~]# 
[root@localhost ~]# cat /etc/os-release 
NAME="Kylin Linux Advanced Server"
VERSION="V10 (Tercel)"
ID="kylin"
VERSION_ID="V10"
PRETTY_NAME="Kylin Linux Advanced Server V10 (Tercel)"
ANSI_COLOR="0;31"

[root@localhost ~]#

1、查看是否已经安装tigervnc-server

[root@localhost ~]# rpm -aq | grep tiger
tigervnc-1.10.1-2.p01.ky10.aarch64
tigervnc-server-minimal-1.10.1-2.p01.ky10.aarch64
[root@localhost ~]# 

2、安装tigervnc-server

[root@localhost ~]# yum install -y tigervnc-server
firmware for qemu, built by jenkins, fresh from git repos                                                                                     3.3 kB/s | 3.0 kB     00:00    
firmware for qemu, built by jenkins, fresh from git repos                                                                                     2.7 kB/s | 6.6 kB     00:02    
Kylin Linux Advanced Server 10 - Os                                                                                                            47 kB/s | 3.7 kB     00:00    
Dependencies resolved.
==============================================================================================================================================================================
 Package                                     Architecture                        Version                                        Repository                               Size
==============================================================================================================================================================================
Installing:
 tigervnc-server                             aarch64                             1.10.1-2.p01.ky10                              ks10-adv-os                             212 k

Transaction Summary
==============================================================================================================================================================================
Install  1 Package

Total download size: 212 k
Installed size: 605 k
Downloading Packages:
tigervnc-server-1.10.1-2.p01.ky10.aarch64.rpm                                                                                                 990 kB/s | 212 kB     00:00    
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                         981 kB/s | 212 kB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                      1/1 
  Installing       : tigervnc-server-1.10.1-2.p01.ky10.aarch64                                                                                                            1/1 
  Running scriptlet: tigervnc-server-1.10.1-2.p01.ky10.aarch64                                                                                                            1/1 
  Verifying        : tigervnc-server-1.10.1-2.p01.ky10.aarch64                                                                                                            1/1 

Installed:
  tigervnc-server-1.10.1-2.p01.ky10.aarch64                                                                                                                                   

Complete!
[root@localhost ~]# rpm -aq | grep tiger
tigervnc-1.10.1-2.p01.ky10.aarch64
tigervnc-server-minimal-1.10.1-2.p01.ky10.aarch64
tigervnc-server-1.10.1-2.p01.ky10.aarch64
[root@localhost ~]# 

3、配置vncserver服务脚本

[root@localhost ~]# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
[root@localhost ~]# 

修改该配置,按照脚本中注释部分:

# 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
# 3. Run `systemctl daemon-reload`
# 4. Run `systemctl enable vncserver@:<display>.service`

修改图中红色框路径为指定用户的home路径,user、group改为对应的用户及组即可。如果为root用户,则红框内路径都改为/root/即可,user、group也为root。

4、设置vnc密码

[root@localhost system]# vncpasswd 
Password:
Verify:
Would you like to enter a view-only password (y/n)? y
Password:
Verify:
[root@localhost system]# 

5、设置开机启动


[root@localhost system]# systemctl daemon-reload
[root@localhost ~]# systemctl enable vncserver@\:1.service 
Created symlink /etc/systemd/system/multi-user.target.wants/vncserver@:1.service → /etc/systemd/system/vncserver@:1.service.
[root@localhost ~]# 

6、开启服务

[root@localhost system]# systemctl start vncserver@\:1.service 
Job for vncserver@:1.service failed because the control process exited with error code.
See "systemctl status vncserver@:1.service" and "journalctl -xe" for details.
[root@localhost system]# 

这里启动失败的话,可以执行执行vncserver来启动vnc服务:

 
[root@localhost system]# vncserver 

New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1

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

[root@localhost system]# 

7、查看启动的vnc服务

[root@localhost system]# vncserver -list

TigerVNC server sessions:

X DISPLAY #     PROCESS ID
:1              139265
[root@localhost system]#

注:这里:1对应远程连接端口5901,如果为:2则远程连接端口为5902,依次类推。

此时可以通过ss命令查看到5901端口已经有了:


[root@localhost system]# ss -tanp | grep 590                                                     
LISTEN       0          5                             0.0.0.0:5901                           0.0.0.0:*          users:(("Xvnc",pid=139670,fd=6))                         
[root@localhost system]# 

到这里,vnc服务已经启动,如果端口没被禁的话,已经可以远程连接上来了

8、最后开端口,590x开放,以5901为例

①简单粗暴的方法就是把防火墙停掉:

[root@localhost ~]# service iptables stop
Redirecting to /bin/systemctl stop iptables.service
[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# service firewalld stop
Redirecting to /bin/systemctl stop firewalld.service
[root@localhost ~]# 

②开放指定端口

若系统使用的防火墙为iptables,则在 /etc/sysconfig/iptables 文件中添加如下规则:

-A INPUT -p tcp -m tcp --dport 5901 -j ACCEPT

之后重启iptables:

service iptables restart

若系统使用的是firewalld服务,则可以:

firewall-cmd --zone=pulic --add-port=5901/tcp --permanent

之后重载规则:

firewall-cmd --reload

9、vnc viewer连接远程

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值