標籤:
先囉嗦一下VNC是什麼( Virtual Network Computing)VNC允許Linux系統可以類似實現像Windows中的遠端桌面訪問那樣訪問Linux案頭。本文配置機器是興寧市網路資訊中心的一台Centos 7 HP伺服器環境下運行。
首先試試伺服器裝了VNC沒
[[email protected] ~]# rpm -q tigervnc tigervnc-server
沒安裝的話會直接出現
package tigervnc is not installedpackage tigervnc-server is not installed
如果沒有安裝X-Windows 案頭的話要先安裝Xwindows
[[email protected] ~]# yum check-update[[email protected] ~]# yum groupinstall "X Window System"[[email protected] ~]# yum install gnome-classic-session gnome-terminal nautilus-open-terminal control-center liberation-mono-fonts[[email protected] ~]# unlink /etc/systemd/system/default.target[[email protected] ~]# ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target[[email protected] ~]# reboot
第一步,安裝VNC packages:
[[email protected] ~]# yum install tigervnc-server -y
第二步,修改配置資訊,在/etc/systemd/system/下建立檔案夾[email protected]:1.service 把example config 檔案從/lib/systemd/system/[email protected]複製到裡面
[[email protected] ~]# cp /lib/systemd/system/[email protected] /etc/systemd/system/[email protected]:1.service
然後開啟這個設定檔/etc/systemd/system/[email protected]:1.service替換掉預設使用者名
找到這一行
ExecStart=/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"PIDFile=/home/<USER>/.vnc/%H%i.pid
這裡我直接用root 使用者登入,所以我替換成
ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i"PIDFile=/root/.vnc/%H%i.pid
如果是其他使用者的話比如linoxide替換如下
ExecStart=/sbin/runuser -l linoxide -c "/usr/bin/vncserver %i"PIDFile=/home/linoxide/.vnc/%H%i.pid
第三步,重載入 systemd
[[email protected] ~]# systemctl daemon-reload
第四步,為VNC設密碼
[[email protected] ~]# vncpasswd
第五步,由於我這邊的Centos 7 是用iptable防火牆的所以
vim /etc/sysconfig/iptables
在合適位置加上
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5900:5903 -j ACCEPT
重啟iptable
service iptables restart
如果是用Centos 7 預設防火牆的可能需要
[[email protected] ~]# firewall-cmd --permanent --add-service vnc-server[[email protected] ~]# systemctl restart firewalld.service
第六步,設預設啟動並開啟VNC
[[email protected] ~]# systemctl enable [email protected]:1.service[[email protected] ~]# systemctl start [email protected]:1.service
這樣基本上Centos 端就設好了,Windows 端要去下一個VNC Viewer 的軟體。串連一下試試看著有點簡陋但是上去了的
Centos 7 安裝VNC步驟