CentOS7安裝配置vncserver

系統環境:CentOS Linux release 7.4.1708vim

Kernel:3.10.0-693.el7.x86_64session

系統現狀:最小化安裝,沒有安裝任何圖形支持軟件 tcp

安裝圖形化支持

不建議安裝GNOME Desktop,它會佔用大量系統資源,安裝完後大約要佔用1G左右的空間,並且安裝過程也較長。以root權限安裝「X Window System」便可spa

# yum groups install "X Window System" # yum install gnome-classic-session gnome-terminal nautilus-open-terminal control-center liberation-mono-fonts

修改系統啓動級別

# systemctl set-default graphical.target  #graphical.target至關於level5,multi-user.target至關於level3

安裝vncserver

# yum install tigervnc-server

配置vncserver實例

分別配置root用戶和st-jun用戶,配置略有不一樣unix

root用戶,服務名是vncserver@:1.service:code

# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service

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

複製代碼
# 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:blog

# 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.資源

設置vncpasswd

# vncpasswd    #root用戶實例的vnc密碼
# su - st-jun $ vncpasswd #普通用戶必定要切換到用戶本身的環境下

密碼設置完成後回到root權限下,啓動服務

加載進程,重啓服務

# systemctl daemon-reload
# systemctl start vncserver@:1.service # systemctl start vncserver@:2.service # systemctl enable vncserver@:1.service # systemctl enable vncserver@:2.service #開機啓動

配置系統防火牆

# firewall-cmd --zone=public --add-port=5901/tcp # firewall-cmd --zone=public --add-port=5902/tcp# firewall-cmd --reload
相關文章
相關標籤/搜索