VNC 安装 (适用Redhat 9.0 和 CentOS 7.0+)

Remote Service
本文转自https://www.cnblogs.com/yjscloud/p/6695388.html

VNC 安装 (适用Redhat 9.0 和 CentOS 7.0+)

  • 目的: VNC来实现远程我们的linux服务器
  • 实验环境: Red Hat Enterprise Linux Server release 7.6 (Maipo)
    cat /etc/redhat-release

    1. 安装VNC Server (tigervnc-server)

    yum -y install vnc-server

    2. 复制vnc server的配置模板

    cd /lib/systemd/system
    cp [email protected] vncserver@:1.service
    注:VNC 服务本身使用的是5900端口。鉴于有不同的用户使用 VNC ,每个人的连接都会获得不同的端口。配置文件名里面的数字告诉 VNC 服务器把服务运行在5900的子端口上。在我们这个例子里,第一个 VNC 服务会运行在5901(5900 + 1)端口上,之后的依次增加,运行在5900 + x 号端口上。其中 x 是指之后用户的配置文件名 vncserver@:x.service 里面的 x 。
    如果要用更多的用户连接,需要创建配置文件和端口,添加一个新的用户和端口。你需要创建 vncserver@:2.service 并替换配置文件里的用户名和之后步骤里相应的文件名、端口号。请确保你登录 VNC 服务器用的是你之前配置 VNC 密码的时候使用的那个用户名。

    3. 编辑配置模板:vim vncserver@:1.service

    vim vncserver@:1.service

    修改后内容如下: (替换< USER >为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=/usr/sbin/runuser -l root -c "/usr/bin/vncserver %i -geometry 1376x730"
PIDFile=/home/root/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

4. 重新载入 systemd,扫描新的或有变动的单元:

systemctl daemon-reload

5. 启动vnc桌面

vncserver :1

You will require a password to access your desktops.

Password:输入你的密码
Verify:再次输入你的密码

6. 开启自启动服务

systemctl enable vncserver@:1.service

7. 配置防火墙 (:1 默认5901 端口)

firewall-cmd --permanent --zone=public --add-port=5901/tcp
firewall-cmd --reload

8. VNC Viewer 访问即可

### 备注

关闭vnc服务:

systemctl stop vncserver@:1.service

禁止 VNC 服务开机启动:

systemctl disable vncserver@:1.service

关闭防火墙:

systemctl stop firewalld.service


猜你喜欢

转载自www.cnblogs.com/sonnet/p/10333632.html