1. 程式人生 > >CentOS7安裝配置vncserver

CentOS7安裝配置vncserver

分別配置root使用者和st-jun使用者,配置略有不同

root使用者,服務名是[email protected]:1.service:

# cp /lib/systemd/system/[email protected] /etc/systemd/system/[email protected]:1.service

修改拷貝過來的模板配置檔案,主要是[Service]部分

# vim /etc/systemd/system/[email protected]\: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使用者,服務名是[email protected]:2.service:

# cp /lib/systemd/system/[email protected] /etc/systemd/system/[email protected]:2.service

# vim /etc/systemd/system/

[email protected]\: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 [email protected]:2.service failed because the control process exited with error code. See "systemctl status [email protected]:2.service" and "journalctl -xe" for details.

密碼設定完成後回到root許可權下,啟動服務

載入程序,重啟服務

# systemctl daemon-reload

# systemctl start [email protected]:1.service

# systemctl start [email protected]:2.service

# systemctl enable [email protected]:1.service   

# systemctl enable [email protected]:2.service    #開機啟動