Centos7.5 minimal系统安装VNC
程序员文章站
2022-03-12 10:35:25
...
环境配置
环境配置操作都是在root
用户下进行的:
- 更新系统
yum upgrade -y
- 更新安装依赖环境,否则后面安装图形界面时会报错
check error: file /boot/efi/EFI/centos from install of fwupdate-efi-12-5.e17.centos.x86_64 conflicts with file from package grub2-common-1:2.02-0.64.el7.centos.noarch
yum update grub2-common
yum install fwupdate-efi
- 安装图形化界面
yum -y groupinstall "GNOME Desktop" "Graphical Administration Tools"
- 重启
reboot
为root用户配置VNC
当前用户为root
用户
- 安装
tigervnc-server
yum install -y tigervnc-server
我安装的版本号为:tigervnc-server.x86_64 0:1.8.0-22.el7
- 复制并重命名vnc启动文件至
/etc/systemd/system/
[[email protected] ~]# cp /lib/systemd/system/[email protected] /etc/systemd/system/[email protected]:1.service
- 设置
root
的VNC登录密码
[[email protected] ~]# vncpasswd
- 打开刚刚复制的文件
vi /etc/systemd/system/[email protected]:1.service
打开后是内容如下(未修改过):
# The vncserver service unit file
#
# Quick HowTo:
# 1. Copy this file to /etc/systemd/system/[email protected]
# 2. Replace <USER> with the actual user name and edit vncserver
# parameters in the wrapper script located in /usr/bin/vncserver_wrapper
# 3. Run `systemctl daemon-reload`
# 4. Run `systemctl enable [email protected]:<display>.service`
#
# DO NOT RUN THIS SERVICE if your local area network is
# untrusted! For a secure way of using VNC, you should
# limit connections to the local host and then tunnel from
# the machine you want to view VNC on (host A) to the machine
# whose VNC output you want to view (host B)
#
# [[email protected] ~]$ ssh -v -C -L 590N:localhost:590M hostB
#
# this will open a connection on port 590N of your hostA to hostB's port 590M
# (in fact, it ssh-connects to hostB and then connects to localhost (on hostB).
# See the ssh man page for details on port forwarding)
#
# You can then point a VNC client on hostA at vncdisplay N of localhost and with
# the help of ssh, you end up seeing what hostB makes available on port 590M
#
# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
#
# Use "-localhost" to prevent remote VNC clients connecting except when
# doing so through a secure tunnel. See the "-via" option in the
# `man vncviewer' manual page.
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=simple
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver_wrapper <USER> %i
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target
根据提示Replace <USER> with the actual user name
只需要修改<USER>
为root
即可:
ExecStart=/usr/bin/vncserver_wrapper root %i
- 接着关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
- 启动vnc服务并查看状态
systemctl daemon-reload
systemctl start [email protected]:1.service
systemctl status [email protected]:1.service
开启成功:
[[email protected] ~]# systemctl status [email protected]:1.service
● [email protected]:1.service - Remote desktop service (VNC)
Loaded: loaded (/etc/systemd/system/[email protected]:1.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2021-01-18 17:59:52 CST; 6s ago
Process: 4691 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)
Main PID: 4696 (vncserver_wrapp)
CGroup: /system.slice/system-vncserver.slice/[email protected]:1.service
├─4696 /bin/sh /usr/bin/vncserver_wrapper root :1
└─4919 sleep 0.1
- 设置开机自启动
systemctl enable [email protected]:1.service
- 如果需要修改分辨率的话,编辑
config
文件:
vi ~/.vnc/config
将geometry
设置成你想要使用的分辨率:
## 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
- 重启vnc服务:
systemctl restart [email protected]:1.service