Centos中安装vncserver具体方法

VNC (Virtual Network Console)是虚拟网络控制台的缩写。它 是一款优秀的远程控制工具软件,由著名的 AT&T 的欧洲研究实验室开发的。VNC 是在基于 UNIX 和 Linux 操作系统的免费的开源软件,远程控制能力强大,高效实用,其性能可以和 Windows 和 MAC 中的任何远程控制软件媲美,本篇文章重点为大家讲解一下Centos中安装vncserver具体方法。

img

系统环境

  • 服务端: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/16093.html

(0)
晴川运维晴川运维
上一篇 2025年10月21日
下一篇 2025年10月21日

相关推荐

  • CentOS下如何用SMplayer播放WMV格式文件

    安装的是centos 6.6,想用来做桌面系统使用!装完后,其他的办公软件都安装好了。但是,视频播放却出问题了。 配置的yum安装的SMplayer播放器,播放其他的视频文件没问题…

    CentOS 2025年6月15日
  • CentOS6.8 SVN服务器管理多项目

    一 需求 一般来说,公司有多个项目,在搭建好SVN服务器之后,就需要使用SVN来实现不在一个项目中的开发人员不能访问其它项目中的代码。 假设: 有3个项目:project1、pro…

    CentOS 2025年10月18日
  • Eclispse Che(1):CentOS 7 安装che服务

    1,关于eclipse Che 构建工具支持:Ant、Bower、Grunt、Gulp、Maven 和 Npm 支持开发工具链:Code Mirror、Git、Orion、SSH、…

    CentOS 2025年6月8日
  • CentOS/RHEL最小化安装图形化

    图形化,一般不再服务器中安装。为了提升系统的利用率。 centos的yum源对应CentOS的源 RHEL的yum源对应RHEL的源 01、挂载ISO配置本地yum源 ISO挂载 …

    CentOS 2025年9月21日
  • CentOS 7使用Docker搭建GitLab服务器

    了解到Docker的优点,搭建快,运行要求资源低,最重要的是实现的功能和效果都能达到预期,于是决定使用Docker来搭建GitLab服务器。 效果图如下: 系统环境:centos …

    CentOS 2025年6月8日
  • CentOS7中禁用Transparent Huge Pages

    自CentOS6版本开始引入了Transparent Huge Pages(THP),从CentOS7版本开始,该特性默认就会启用。尽管THP的本意是为提升内存的性能,不过某些数据…

    CentOS 2025年9月24日
  • Mac OS X 开发环境搭建之利用 Parallel Desktop 安装 CentOS 7

    背景 在企业级软件系统中,数据库的地位是比较高的,而且一般都要求支持多种数据库,如 Oracle、 DB2、MySQL 等,它们的最新版本大多都不再支持 Mac OS X 系统,所…

    CentOS 2025年9月21日
  • CentOS7.5从零安装Python3.6.6

    Linux环境:centos7.5 安装可能需要的依赖 yum install openssl-devel bzip2-devel expat-devel gdbm-devel r…

    CentOS 2025年6月21日
  • CentOS 7环境下使用Nginx托管.Net Core应用程序

    一、安装.Net Core 1、添加dotnet产品Feed 在安装.NET Core之前,您需要注册Microsoft产品Feed。这只需要做一次。首先,注册Microsoft签…

    CentOS 2025年6月11日
  • CentOS 6.x 安装PyLucene

    centos 6.x 安装PyLucene 一、说明 安装环境 centos6.6 (64位) python2.7.10 (升级系统默认python版本的方法参见在CentOS 6…

    CentOS 2025年9月19日

发表回复

登录后才能评论