Centos7.7安装vncserver具体方法

VNC Server是一款跨平台使用的远程控制访问软件,可以帮助人们进行远程工作,从任何设备随时控制远程计算机。我们跨平台远程访问软件的最新版本(6+),用于个人和商业用途。

系统环境

服务端:Centos7.7 Minimal
客户端:Windows10
客户端VNC-Viewer 6.20下载地址:https://www.realvnc.com/en/connect/download/viewer/

安装桌面环境

本实验中安装的系统没有安装桌面环境,我们需要自己安装,如果已经安装桌面了清跳过这一步。Centos7提供了”Cinnamon Desktop”,”MATE Desktop”,”GNOME Desktop”,”KDE Plasma Workspaces”,”LXQt Desktop”,”Xfce”让我们安装。

下面的命令列出可用环境组:

[root@localhost ~]# yum grouplist
Loaded plugins: fastestmirror
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
* base: mirrors.tuna.tsinghua.edu.cn
* epel: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Available Environment Groups:
  Minimal Install
  Compute Node
  Infrastructure Server
  File and Print Server
  Cinnamon Desktop
  MATE Desktop
  Basic Web Server
  Virtualization Host
  Server with GUI
  GNOME Desktop
  KDE Plasma Workspaces
  Development and Creative Workstation
Available Groups:
  Cinnamon
  Compatibility Libraries
  Console Internet Tools
  Development Tools
  Educational Software
  Electronic Lab
  Fedora Packager
  General Purpose Desktop
  Graphical Administration Tools
  Haskell
  LXQt Desktop
  Legacy UNIX Compatibility
  MATE
  Milkymist
  Scientific Support
  Security Tools
  Smart Card Support
  System Administration Tools
  System Management
  TurboGears application framework
  Xfce
Done

我们可以选择自己喜欢的桌面环境,在这里选择安装Xfce桌面:

[root@localhost ~]# yum -y install epel-release && yum groupinstall Xfce

创建一个用户

[root@localhost ~]# useradd user1
[root@localhost ~]# echo '123456'|passwd --stdin user1
[root@localhost ~]# usermod -a -G wheel user1

安装VNC Server

在Centos仓库默认提供的是TigerVNC安装包,我们就安装这个:

[root@localhost ~]# yum -y install tigervnc-server tigervnc-server-module

切换到user1用户,运行vncserver命令创建一个初始配置并设置密码:

[root@localhost ~]# su - user1
[user1@localhost ~]$ vncserver :2

You will require a password to access your desktops.

Password:
Verify:
Would you like to enter a view-only password (y/n)? n
A view-only password is not used

New 'localhost.localdomain:2 (user1)' desktop is localhost.localdomain:2

Starting applications specified in /home/user1/.vnc/xstartup
Log file is /home/user1/.vnc/localhost.localdomain:2.log

然后停止vncserver服务,目的就是创建密码和.vnc下面的文件。

[user1@localhost ~]$ vncserver -kill :2

配置VNC Server

编辑用户家目录下面的.vnc/xstartup文件

[user1@localhost ~]$ vim ~/.vnc/xstartup

#!/bin/sh 
xrdb $HOME/.Xresources
#xsetroot -solid grey
#xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#twm &
startxfce4 &

如果需要修改屏幕分辨率,可以修改~/.vnc/config文件,取消gemoetry前面的注释。

[user1@localhost ~]$ vim .vnc/config

## Supported server options to pass to vncserver upon invocation can be listed
## in this file. See the following manpages for more: vncserver(1) Xvnc(1).
## Several common ones are shown below. Uncomment and modify to your liking.
##
# securitytypes=vncauth,tlsvnc
# desktop=sandbox
geometry=1920x1080
# localhost
# alwaysshared

创建 Systemd Unit文件

Unit文件方便快速的启动,停止,重启服务

[user1@localhost ~]$ sudo cp /usr/lib/systemd/system/[email protected] /etc/systemd/system/vncserver@:2.service

编辑vncserver@:2.service,替换文件里面的为user1用户, Type由默认的forking改为simple

[user1@localhost ~]$ vim /etc/systemd/system/vncserver\@\:2.service

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=simple
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l user1 -c "/usr/bin/vncserver %i"
PIDFile=/home/user1/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target

启动vncserver服务

#重新加载管理器配置
[user1@localhost ~]$ sudo systemctl daemon-reload
#启动vncserver
[user1@localhost ~]$ sudo systemctl start vncserver@:2

客户端远程连接测试

在windows10客户端打开VNC Viewer,输入地址和会话端口号:

总结

如果需要将VNC服务器配置为多个用户启动显示,请使用vncserver命令创建初始配置并设置密码,然后使用其他端口创建新的服务文件。

原创文章,作者:晴川运维,如若转载,请注明出处:https://baike.qcidc.com/8728.html

(0)
晴川运维晴川运维
上一篇 2025年6月13日
下一篇 2025年6月13日

相关推荐

  • CentOS 7下Redis5集群的搭建和使用

    1、简要说明 Redis5.0版是Redis产品的重大版本发布,推出了各种新特性,其中一点是放弃 Ruby的集群方式,改为 使用 C语言编写的 redis-cli的方式,是集群的构…

    CentOS 2025年6月24日
  • CentOS 7.2中磁盘iowait过高解决

    (一)简述每天都收到磁盘iowait告警信息,尤其是日志服务器在进行大量的读写操作过程中,从而造成系统处于崩溃边缘,为查找磁盘iowait由于什么原因造成的以及后续的系统的优化点。…

    CentOS 2025年7月9日
  • CentOS中通过ISO镜像文件制作本地yum源

    Yum(全称为 Yellow dogUpdater, Modified)是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器。基于RPM包管理,能够从指…

    CentOS 2025年10月23日
  • centos中安装Dropbox

    Dropbox是一个提供同步本地文件的网络存储在线应用。支持在多台电脑多种操作中自动同步。并可当作大容量的网络硬盘使用。Dropbox采用免费试用+高级服务收费的Freemium模…

    CentOS 2025年6月22日
  • CentOS 6.x的安装过程详解

    我们首先看一下CentOS安装光盘的目录: 我们解释一下这些目录的作用(文件没有什么作用,都是一些KEY文件,GPL信息等等) EFI    #关于EFI引导使…

    CentOS 2025年10月25日
  • CentOS7.4脱机安装SQL Server 2017

    SQL Server on Linux也发布一段时间了,官方上支持Red Hat, SUSE, Ubuntu。手上没有以上Linux版本,选用了与Red Hat最接近的CentOS…

    CentOS 2025年10月22日
  • CentOS yum的配置文件 repo文件详解

    什么是repo文件?repo文件是Fedora中yum源(软件仓库)的配置文件,通常一个repo文件定义了一个或者多个软件仓库的细节内容,例如我们将从哪里下载需要安装或者升级的软件…

    CentOS 2025年7月3日
  • CentOS 7.0 重置root的密码

    Linux系统:CentOS 7.0,如何重置root的密码,首先进入开启菜单,按下e键进入编辑现有的内核,如下图所示 然后滚动列表,找到ro,将它替换成rw,并加上init=/s…

    CentOS 2025年10月5日
  • CentOS 7下yum成功安装 MySQL 5.7

    第一部分:centos 7安装mysql 5.7 1.下载yum库 shell > wget http://dev.mysql.com/get/mysql57-communi…

    CentOS 2025年6月17日
  • CentOS 7.5单机安装Kubernetes

    1.系统配置 centos 7.5 Docker 1.13.1 2.关闭防火墙,selinux,swapoff systemctl disable firewalldsystemc…

    CentOS 2025年6月9日

发表回复

登录后才能评论