搭建VNC服务
一、简介(纯个人认为)
就是一款远程控制软件,跟windows的rdp差不多
二、相关软件
Liunx桌面环境:GNOME Destop,必须要安装有一个桌面环境(KDE\GNOME\Unity\Mate选一个),否则安装tigervnc-server不起任何作用(该版本操作系统已经默认安装了该桌面环境)
Vnc服务端:tigervnc-server
Vnc客户端: VNC-Viewer(windows客户端),用于远程访问Linux桌面
三、搭建
1)关闭防火墙和selinux
systemctl stop firewalld #关闭firewalld
systemctl disable firewalld #永久关闭firewalld
setenforce 0 #关闭selinux
2)永久关闭selinux
vi /etc/selinux/config #编辑selinux配置文件
修改成如下
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
3)安装服务端软件
yum install -y tigervnc-server
安装成功后,通过”vncpasswd”命令设置当前Linux用户的VNC密码,用于VNC客户端登录时的安全验证,该密码与Liunx用户本身的密码不会冲突。
[root@localhost ~]# vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
A view-only password is not used
通过”vncserver”命令启动Vnc服务,Vnc默认端口是5900+后面启动的序号
# vncserver 命令用法
# vncserver --help
usage: vncserver [:<number>] [-name <desktop-name>] [-depth <depth>]
[-geometry <width>x<height>]
[-pixelformat rgbNNN|bgrNNN]
[-fp <font-path>]
[-cc <visual>]
[-fg]
[-autokill]
[-noxstartup]
[-xstartup <file>]
[-fallbacktofreeport]
<Xvnc-options>...
vncserver -kill <X-display>
vncserver -list
# 启动1号桌面
# vncserver :1
# 启动桌面时出现的提示,启动后的日志在{用户目录}/.vnc下,我这边是用的root账号,如果是其他账号在/home/{user}/.vnc/目录下
# 如果通过vncserver -list没有发现没有启动成功,可去此处查看相关日志,同时结合"journalctl -xe"命令查看详细错误
New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:1.log
# 关闭1号桌面
# vnserver -kill :1
# 执行关闭命令时出现的提示
Killing Xvnc process ID 446228
# 查看当前用户下所有桌面
# vncserver -list
TigerVNC server sessions:
X DISPLAY # PROCESS ID
:1 22182
四、设置开机启动
cp /usr/lib/systemd/system/vncserver@.service /etc/systemd/system #拷贝服务配置文件(systemctl)至/etc/systemd/system
vim /etc/systemd/system/vncserver@.service #编辑该配置文件,修改以下内容
[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 root %i
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target
五、修改VNC服务端口号
kvm创建出的虚拟机的内部vnc也是使用的5900开始的,会与我们本机的vnc端口冲突,所以我们更改vnc的端口号
which vncserver #查询vncserver的配置文件位置
vim /usr/bin/vncserver #编辑相关配置文件
直接vim 搜索5900 替换两处5900为你想要的端口号,重启vnc服务即更改完成
文章内容仅用于作者学习使用,如果内容侵犯您的权益,请立即联系作者删除,作者不承担任何法律责任。