一.安装
以root用户运行以下命令来安装vncserver;
yum install tigervnc-server
同样运行以下命令来安装vncviewer;
yum install vnc
停止并禁用防火墙;
systemctl stop firewalld.service
systemctldisable firewalld.service
二.配置
vncviewer基本上不用配置;
vncserver的配置,创建一个新的配置文件,以开启1号窗口为例(也可以同时开启多个窗口,修改数字即可),方法如下:
cp/lib/systemd/system/vncserver@.service/lib/systemd/system/vncserver@:1.service
或者再增加一个窗口:
cp/lib/systemd/system/vncserver@.service/lib/systemd/system/vncserver@:2.service
编辑/lib/systemd/system/vncserver@:1.service,设置用户root相关参数,最终内容如下:
[Unit]
Description=Remotedesktopservice(VNC)
After=syslog.targetnetwork.target
[Service]
Type=forking
#Cleananyexistingfilesin/tmp/.X11-unixenvironment
ExecStartPre=
/bin/sh
-c
'/usr/bin/vncserver-kill%i>/dev/null2>&1||:'
ExecStart=
/sbin/runuser
-lroot-c
"/usr/bin/vncserver%i"
PIDFile=
/root/
.vnc/%H%i.pid
ExecStop=
'/usr/bin/vncserver-kill%i>/dev/null2>&1||:'
|
vncserver@:1.service-Remotedesktopservice(VNC)
Loaded:loaded(
/usr/lib/systemd/system/vncserver
@:1.service;enabled)
Process:3258ExecStart=
-lsysadmin-c
/usr/bin/vncserver
%i(code=exited,status=1
/FAILURE
)
Process:3254ExecStartPre=
-c
-
kill
%i>
/dev/null
2>&1||:(code=exited,status=0
/SUCCESS
)
Apr1410:09:24F1A-VMHOST-SWPEsystemd[1]:StartingRemotedesktopservice(VNC)...
Apr1410:09:24F1A-VMHOST-SWPErunuser[3258]:Password:
Apr1410:09:24F1A-VMHOST-SWPEsystemd[1]:vncserver@:1.service:controlprocessexited,code=exitedstatus=1
Apr1410:09:24F1A-VMHOST-SWPEsystemd[1]:FailedtostartRemotedesktopservice(VNC).
Apr1410:09:24F1A-VMHOST-SWPEsystemd[1]:Unitvncserver@:1.serviceenteredFailedstate.
Warning:Unit
file
changedondisk,
'systemctldaemon-reload'
recommended.
|
三.应用
更新systemctl以使其生效;
systemctl daemon-reload
设置vncserver的密码;
vncpasswd root
按提示输入密码以及确认密码
启动该服务用来启用vnc的1号窗口;
systemctlstartvncserver@:1.service或者vncserver:1
关闭1号窗口:
systemctlstopvncserver@:1.service或者vncserver-kill:1
设置为开机自动启动;
systemctlenablevncserver@:1.service
在/etc/sysconfig/iptables 添加5901端口
.在iptables中加入对应的端口5901(注意,如果有其他用户,那么也需要将端口加上。vnc的端口默认是5900 + n)
[root@localhost system]# cat /etc/sysconfig/iptablesEnd.