Chinaunix首页 | 论坛 | 博客
  • 博客访问: 990632
  • 博文数量: 481
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 5078
  • 用 户 组: 普通用户
  • 注册时间: 2018-03-07 14:48
个人简介

分享工作和学习中的点点滴滴,包括前端、后端、运维、产品等各个方面,欢迎您来关注订阅!

文章分类

全部博文(481)

文章存档

2023年(26)

2022年(97)

2021年(119)

2020年(153)

2019年(70)

2018年(16)

我的朋友

分类: LINUX

2020-09-29 19:44:59

虚拟网络控制台(VNC)是一个图形桌面共享软件,允许您使用键盘和鼠标远程控制另一台计算机。
系统环境
  • 服务端:7.7 Minimal
  • 客户端:Windows10
  • 客户端VNC-Viewer 6.20下载地址:
安装桌面环境

本实验中安装的系统没有安装桌面环境,我们需要自己安装,如果已经安装桌面了清跳过这一步。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/vncserver@.service /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,输入地址和会话端口号:
Centos7.7安装vncserver虚拟网络控制台Centos7.7安装vncserver虚拟网络控制台
Centos7.7安装vncserver虚拟网络控制台Centos7.7安装vncserver虚拟网络控制台
Centos7.7安装vncserver虚拟网络控制台Centos7.7安装vncserver虚拟网络控制台

总结

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

阅读(1043) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~