分别配置root用户和st-jun用户,配置略有不同
root用户,服务名是vncserver@:1.service:
# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
修改拷贝过来的模板配置文件,主要是[Service]部分
# vim /etc/systemd/system/vncserver@\:1.service
[Service]
Type=forking
User=root
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=-/usr/bin/vncserver -kill %i
ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i"
PIDFile=/root/.vnc/%H%i.pid
ExecStop=-/usr/bin/vncserver -kill %i
st-jun用户,服务名是vncserver@:2.service:
# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:2.service
# vim /etc/systemd/system/vncserver@\:2.service
[Service]
Type=forking
User=st-jun
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=-/usr/bin/vncserver -kill %i
ExecStart=/usr/bin/vncserver %i
PIDFile=/home/st-jun/.vnc/%H%i.pid
ExecStop=-/usr/bin/vncserver -kill %i
普通用户的ExecStart不同于root,加/sbin/runuser则会在启动服务时报以下错误
Job for vncserver@:2.service failed because the control process exited with error code. See "systemctl status vncserver@:2.service" and "journalctl -xe" for details.
密码设置完成后回到root权限下,启动服务
加载进程,重启服务
# systemctl daemon-reload
# systemctl start vncserver@:1.service
# systemctl start vncserver@:2.service
# systemctl enable vncserver@:1.service
# systemctl enable vncserver@:2.service #开机启动
转载于:https://blog.51cto.com/11310506/2313672