vnc 连接linux centos 7 系统的桌面

一些 VNC 服务器的优点:

  • 远程的图形管理方式让工作变得简单方便。
  • 剪贴板可以在 CentOS 服务器主机和 VNC 客户端机器之间共享。
  • CentOS 服务器上也可以安装图形工具,让管理能力变得更强大。
  • 只要安装了 VNC 客户端,通过任何操作系统都可以管理 CentOS 服务器了。
  • 比 ssh 图形转发和 RDP 连接更可靠。

那么,让我们开始安装 VNC 服务器之旅吧。我们需要按照下面的步骤一步一步来搭建一个可用的 VNC。

首先,我们需要一个可用的桌面环境(X-Window),如果没有的话要先安装一个。

注意:以下命令必须以 root 权限运行。要切换到 root ,请在终端下运行“sudo -s”,当然不包括双引号(“”)

1. 安装 X-Window

首先我们需要安装 X-Window,在终端中运行下面的命令,安装会花费一点时间。

--(我是图形界面机器 我没有安装这个)

 
 
  1. # yum check-update
  2. # yum groupinstall "X Window System"

installing x windows

installing x windows

 
 
  1. #yum install gnome-classic-session gnome-terminal nautilus-open-terminal control-center liberation-mono-fonts

install gnome classic session

install gnome classic session

 
 
  1. ### 设置默认启动图形界面
  2. # unlink /etc/systemd/system/default.target
  3. # ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target

configuring graphics

configuring graphics

 
 
  1. # reboot

在服务器重启之后,我们就有了一个工作着的 CentOS 7 桌面环境了。

现在,我们要在服务器上安装 VNC 服务器了。

2. 安装 VNC 服务器

现在要在我们的 CentOS 7 上安装 VNC 服务器了。我们需要执行下面的命令。

 
 
  1. # yum install tigervnc-server -y

vnc server

vnc server

3. 配置 VNC

然后,我们需要在 /etc/systemd/system/ 目录里创建一个配置文件。我们可以将/lib/systemd/sytem/[email protected] 拷贝一份配置文件范例过来。

 
 
  1. # cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service

copying vnc server configuration

copying vnc server configuration

接着我们用自己最喜欢的编辑器(这儿我们用的 nano )打开 /etc/systemd/system/vncserver@:1.service,找到下面这几行,用自己的用户名替换掉 。举例来说,我的用户名是 linoxide 所以我用 linoxide 来替换掉 :

 
 
  1. ExecStart=/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"
  2. PIDFile=/home/<USER>/.vnc/%H%i.pid

替换成

 
 
  1. ExecStart=/sbin/runuser -l linoxide -c "/usr/bin/vncserver %i"
  2. PIDFile=/home/linoxide/.vnc/%H%i.pid

如果是 root 用户则

 
 
  1. ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i"
  2. PIDFile=/root/.vnc/%H%i.pid

configuring user

configuring user

好了,下面重启 systemd 。

 
 
  1. # systemctl daemon-reload

最后还要设置一下用户的 VNC 密码。要设置某个用户的密码,必须要有能通过 sudo 切换到用户的权限,这里我用 linoxide 的权限,执行“su linoxide”就可以了。

 
 
  1. # su linoxide
  2. $ sudo vncpasswd

setting vnc password

setting vnc password

确保你输入的密码多于6个字符

4. 开启服务

用下面的命令(永久地)开启服务:

 
 
  1. $ sudo systemctl enable vncserver@:1.service

启动服务。

 
 
  1. $ sudo systemctl start vncserver@:1.service

5. 防火墙设置

我们需要配置防火墙来让 VNC 服务正常工作。

 
 
  1. $ sudo firewall-cmd --permanent --add-service vnc-server
  2. $ sudo systemctl restart firewalld.service

allowing firewalld

allowing firewalld

现在就可以用 IP 和端口号(LCTT 译注:例如 192.168.1.1:1 ,这里的端口不是服务器的端口,而是视 VNC 连接数的多少从1开始排序)来连接 VNC 服务器了。

6. 用 VNC 客户端连接服务器

好了,现在已经完成了 VNC 服务器的安装了。要使用 VNC 连接服务器,我们还需要一个在本地计算机上安装的仅供连接远程计算机使用的 VNC 客户端。



--之间遇到了个问题:


systemctl daemon-reload 


我还改了个这个,不过没研究


原文地址:https://linux.cn/article-5335-1.html

猜你喜欢

转载自blog.csdn.net/YINHAOXU1/article/details/72528579