1. 以root角色运行以下命令来安装TigerVNC server
yum install tigervnc-server
|
yum install vnc
|
2. 配置VNC Server
创建一个新的配置文件
cp /lib/systemd/system/vncserver@.service /lib/systemd/system/vncserver@:1.service
|
编辑/lib/systemd/system/vncserver@:1.service,设置用户root相关参数,最终内容如下:
[Unit]
Description=Remote desktop service (VNC) After=syslog.target network.target
[Service]
#Type=forking 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=/sbin/runuser -l root -c "/usr/bin/vncserver :1 -geometry 1280x720 -depth 24" PIDFile=/home/root/.vnc/%H%i.pid ExecStop=/bin/sh -c '/usr/bin/vncserver -kill :1 > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target |
更新systemctl来确保其生效
systemctl daemon-reload
|
设置为开机自启动
systemctl enable vncserver@:1.service
|
启动服务
systemctl start vncserver@:1.service
过程中遇到的错误:
执行systemctl start vncserver@:1.service启动服务是报错
Job for vncserver@:1.service failed. See ‘systemctl status vncserver@:1.service’ and ‘journ
alctl -xn’ for details.
解决方式:将vncserver@:1.service中Type参数改为simple后,再执行systemctl daemon-reload,启动成功。(centos7的默认防火墙手动关闭了)。
连接成功后的效果图:
参考文章:http://www.centoscn.com/image-text/config/2014/0829/3594.html