1 | https://www.cnblogs.com/xuanbjut/p/14289178.html |
1. 安装桌面环境
1 2 3 4 | yum update -y sudo dnf install -y coreutils --allowerasing yum groupinstall -y "Server with GUI" sudo dnf groupinstall -y "workstation" |
2. 设置默认启动图形界面
1 | systemctl set-default graphical |
3. 重启服务器
1 | reboot |
4. 安装 VNC Server
4-1. yum 安装 tigervnc-server
1 | sudo dnf install -y tigervnc-server tigervnc-server-module |
4-2. CentOS 8 安装与 CentOS 7 不同,可以参考这个文档
1 | less /usr/share/doc/tigervnc/HOWTO.md |
4-3. 拷贝模板
1 | cp /usr/lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@.service |
不需要编辑这个模版,根据 HOWTO.md 的描述,直接编辑配置文件即可
4-4. 重新加载 systemd
1 | systemctl daemon-reload |
4-5. 编辑用户配置文件
1 | vi /etc/tigervnc/vncserver.users |
编辑后看起来是这样的
1 2 3 4 5 6 7 8 | # TigerVNC User assignment # # This file assigns users to specific VNC display numbers. # The syntax is <display>=<username>. E.g.: # # :2=andrew # :3=lisa :1=root |
说明
1. :1 表示这个启动的端口为。5901,之后一次类推 :2 为 5902;
2. :1=root 表示 5901 为 admin 用户的远程连接;
1 | :wq 保存 |
4-6. 配置 Xvnc 选项
1 | vi /etc/tigervnc/vncserver-config-defaults |
本例如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | ## Default settings for VNC servers started by the vncserver service # # Any settings given here will override the builtin defaults, but can # also be overriden by ~/.vnc/config and vncserver-config-mandatory. # # See the following manpages for more details: vncserver(1) Xvnc(1) # # Several common settings are shown below. Uncomment and modify to your # liking. # securitytypes=vncauth,tlsvnc # desktop=sandbox # geometry=2000x1200 # localhost # alwaysshared session=gnome geometry=1024x768 |
说明
1. session=gnome 表示为使用 gnome 桌面
2. geometry=1024×768 表示桌面的分辨率
这样服务的主要配置就完成了
4-7. 配置访问密码
本例使用 root 用户的桌面环境,如果使用其他用户,请先切换到 root 用户
1 2 3 4 5 | # su root $ vncpasswd Password: Verify: Would you like to enter a view-only password (y/n)? n |
4-8. 开启服务
1 | systemctl start vncserver@:1 |
这样就开启了第一个界面
注意
1. 服务的文件 /etc/systemd/system/vncserver@.service没有 :1
2. :1 使当参数启动服务器,表示启动第一个界面
4-9. 设置开机启动
1 | systemctl enable vncserver@:1 |
4-10. 打开防火墙
我们需要配置防火墙, 打开 VNC 服务
1 2 3 | firewall-cmd --zone=public --permanent --add-port=5900-5999/tcp firewall-cmd --zone=public --permanent --add-port=5900-5999/udp firewall-cmd --reload |
设置如下:
VNC Server: YOUR_SERVER_IP:1
Name: YOUR_Display_1
连接之后,输入 root 的 vpnpasswd,既可看到界面了.