当前位置: 首页 > 工具软件 > TigerVNC > 使用案例 >

CentOS7.9离线安装TigerVNC Server并设置开机启动

艾嘉石
2023-12-01

一 挂载系统镜像配置为本地yum源

1 创建挂载目录

[root@localhost home]# mkdir /mnt/iso
[root@localhost home]# mount -o loop CentOS-7.9-x86_64-DVD-2009.iso /mnt/iso
mount: /dev/loop0 写保护,将以只读方式挂载
[root@localhost home]# ls /mnt/iso
CentOS_BuildTag  EFI  EULA  GPL  images  isolinux  LiveOS  Packages  repodata  RPM-GPG-KEY-CentOS-7  RPM-GPG-KEY-CentOS-Testing-7  TRANS.TBL

2 备份原有的yum源信息并修改配置本地yum源信息

[root@localhost home]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# mkdir ./bak
[root@localhost yum.repos.d]# mv ./*.repo ./bak/
[root@localhost yum.repos.d]# cp ./bak/CentOS-Media.repo .
[root@localhost yum.repos.d]# vi CentOS-Media.repo
# CentOS-Media.repo
#
#  This repo can be used with mounted DVD media, verify the mount point for
#  CentOS-7.  You can use this repo and yum to install items directly off the
#  DVD ISO that we release.
#
# To use this repo, put in your DVD and use it with the other repos too:
#  yum --enablerepo=c7-media [command]
#  
# or for ONLY the media repo, do this:
#
#  yum --disablerepo=\* --enablerepo=c7-media [command]

[c7-media]
name=CentOS-$releasever - Media
baseurl=file:///media/CentOS/
		file:///mnt/iso
		file:///media/cdrecorder/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

3 清理并重新读取yum源信息

[root@localhost yum.repos.d]# yum clean all
已加载插件:fastestmirror, langpacks
正在清理软件源: c7-media
Cleaning up list of fastest mirrors
[root@localhost yum.repos.d]# yum repolist 

二 安装TigerVNC并设置开机启动

1 使用yum安装TigerVNC

[root@localhost yum.repos.d]# yum install -y tigervnc tigervnc-server
正在安装    : tigervnc-icons-1.8.0-21.el7.noarch                                                                                                                                                                                   1/4 
正在安装    : fltk-1.3.4-2.el7.x86_64                                                                                                                                                                                              2/4 
正在安装    : tigervnc-1.8.0-21.el7.x86_64                                                                                                                                                                                         3/4 
正在安装    : tigervnc-server-1.8.0-21.el7.x86_64                                                                                                                                                                                  4/4 
验证中      : tigervnc-1.8.0-21.el7.x86_64                                                                                                                                                                                         1/4 
验证中      : fltk-1.3.4-2.el7.x86_64                                                                                                                                                                                              2/4 
验证中      : tigervnc-icons-1.8.0-21.el7.noarch                                                                                                                                                                                   3/4 
验证中      : tigervnc-server-1.8.0-21.el7.x86_64                                                                                                                                                                                  4/4 

已安装:
tigervnc.x86_64 0:1.8.0-21.el7                                                                                  tigervnc-server.x86_64 0:1.8.0-21.el7                                                                                 

作为依赖被安装:
fltk.x86_64 0:1.3.4-2.el7                                                                                     tigervnc-icons.noarch 0:1.8.0-21.el7                                                                                    

完毕!

2 设置VNC管理密码和访客密码

[root@localhost system]# vncpasswd 
Password:
Verify:
Would you like to enter a view-only password (y/n)? y
Password:
Verify:

3 复制配置文件到/etc/systemd/system/目录,新文件名"@"后面一定要加冒号 : 否则后续服务不会正常启动

[root@localhost system]# cp /usr/lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service

4 编辑复制后的新配置文件,将部分改为指定用户名

[root@localhost system]# vi vncserver@:1.service 
	# The vncserver service unit file
	#
	# Quick HowTo:
	# 1. Copy this file to /etc/systemd/system/vncserver@.service
	# 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 vncserver@:<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)
	#
	# [user@hostA ~]$ 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/sbin/runuser -l root -c "/usr/bin/vncserver %i"
	PIDFile=/root/.vnc/%H%i.pid
	ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
	
	[Install]
	WantedBy=multi-user.target

5 重读配置文件并启动VNC实例

[root@localhost system]# systemctl daemon-reload 
	[root@localhost system]# systemctl status vncserver@1.service
	[root@localhost system]# systemctl start vncserver@1.service
	[root@localhost system]# systemctl status vncserver@1.service

6 添加防火墙放行端口,5901开始想用几个实例就开几个端口

[root@localhost system]# firewall-cmd --add-port=5901-5905/tcp --permanent 
	[root@localhost system]# systemctl restart firewalld.service
	[root@localhost system]# firewall-cmd --list-all
	public (active)
	target: default
	icmp-block-inversion: no
	interfaces: eno1
	sources: 
	services: dhcpv6-client ssh
	ports: 5901-5905/tcp
	protocols: 
	masquerade: no
	forward-ports: 
	source-ports: 
	icmp-blocks: 
	rich rules: 

7 设置vnc实例1开机启动

[root@localhost system]# systemctl enable vncserver@:1.service
	Created symlink from /etc/systemd/system/multi-user.target.wants/vncserver@:1.service to /etc/systemd/system/vncserver@:1.service.

8 VNC常用命令
vncserver -list 查看正在运行的实例
vncserver -kill :1 关闭实例1
vncpasswd 修改当前用户的VNC密码
vncpasswd user 修改user用户的VNC密码
netstat -tunpl |grep :590 查看VNC服务端口状态

 类似资料: