Linux系统安装和配置 VNC 服务器

文章目录

    • [1.安装 GNOME 桌面环境](#1.安装 GNOME 桌面环境)
    • [2.安装 VNC 服务器(tigervnc-server)](#2.安装 VNC 服务器(tigervnc-server))
    • [3.为本地用户设置 VNC 密码](#3.为本地用户设置 VNC 密码)
    • [4.设置 VNC 服务器配置文件](#4.设置 VNC 服务器配置文件)
    • [5.启动 VNC 服务并允许防火墙中的端口](#5.启动 VNC 服务并允许防火墙中的端口)

1.安装 GNOME 桌面环境

shell 复制代码
[root@server6 ~]# dnf groupinstall "workstation" -y

成功安装上面的包后,请运行以下命令启用图形模式

[root@server6 ~]# systemctl set-default graphical

重启一下系统

shell 复制代码
[root@server6 ~]# reboot

重启后,取消注释 /etc/gdm/custom.conf文件 中的 WaylandEnable=false,以使通过 vnc 进行的远程桌面会话请求由 GNOME 桌面的 xorg 处理,来代替 Wayland 显示管理器

shell 复制代码
[root@server6 ~]# vim /etc/gdm/custom.conf

2.安装 VNC 服务器(tigervnc-server)

shell 复制代码
[root@server6 ~]# dnf install tigervnc-server tigervnc-server-module -y

3.为本地用户设置 VNC 密码

shell 复制代码
[root@server6 ~]# vncpasswd

4.设置 VNC 服务器配置文件

shell 复制代码
/etc/systemd/system/vncserver@.service
shell 复制代码
[root@linuxtechi ~]# vim /etc/systemd/system/vncserver@.service
[Unit]
Description=Remote Desktop VNC Service
After=syslog.target network.target

[Service]
Type=forking
WorkingDirectory=/home/pkumar
User=pkumar
Group=pkumar

ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver -autokill %i
ExecStop=/usr/bin/vncserver -kill %i

[Install]
WantedBy=multi-user.target

5.启动 VNC 服务并允许防火墙中的端口

shell 复制代码
[root@server6 ~]# systemctl daemon-reload
[root@server6 ~]# systemctl start vncserver@:1.service
[root@server6 ~]# systemctl enable vncserver@:1.service
Created symlink /etc/systemd/system/multi-user.target.wants/vncserver@:1.service → /etc/systemd/system/vncserver@.service.
[root@server6 ~]# netstat -tunlp | grep 5901
tcp        0      0 0.0.0.0:5901            0.0.0.0:*               LISTEN      56182/Xvnc          
tcp6       0      0 :::5901                 :::*                    LISTEN      56182/Xvnc          
[root@server6 ~]# ss -tunlp | grep -i 5901
tcp   LISTEN 0      5             0.0.0.0:5901       0.0.0.0:*    users:(("Xvnc",pid=56182,fd=6))                          
tcp   LISTEN 0      5                [::]:5901          [::]:*    users:(("Xvnc",pid=56182,fd=7))                          

使用下面的 systemctl 命令验证 VNC 服务器的状态

shell 复制代码
[root@server6 ~]# systemctl status vncserver@:1.service
相关推荐
默默在路上2 分钟前
CentOS Stream 9 安装mysql8.0
linux·mysql·centos
❀͜͡傀儡师1 小时前
docker部署filebrowser轻量级个人云盘
运维·docker·容器
游戏23人生1 小时前
QT linux下 虚拟键盘使用及注意事项
linux·qt·计算机外设
AAA.建材批发刘哥1 小时前
03--C++ 类和对象中篇
linux·c语言·开发语言·c++·经验分享
hellodaoyan1 小时前
网络技术企业级交换机配置
运维
softshow10261 小时前
使用 Windows 子系统 WSL 安装 Ubuntu 22.04
linux·windows·ubuntu
wadesir1 小时前
简易制作LinuxShell完全指南(深入解析原理、设计与实践步骤)
linux·运维·服务器
BigBigHang2 小时前
【docker】ollama的docker-compose及一些启动踩坑
运维·docker·容器
水天需0102 小时前
HISTFILE 介绍
linux
CreasyChan3 小时前
VirtualBox 安装 CentOS 7.2
linux·运维·centos