(?Virtual Network Computing)VNC允許Linux系統可以類似實現像Windows中的遠程桌面訪問那樣訪問Linux桌面。本文配置機器是興寧市網絡信息中心的一臺Centos 7 HP服務器環境下運行。
首先試試服務器裝了VNC沒
[root@wic?~]#?rpm?-q?tigervnc?tigervnc-server
沒安裝的話會直接出現
package?tigervnc?is?not?installed package?tigervnc-server?is?not?installed
如果沒有安裝X-Windows 桌面的話要先安裝Xwindows
[root@wic?~]#?yum?check-update [root@wic?~]#?yum?groupinstall?"X?Window?System" [root@wic?~]#?yum?install?gnome-classic-session?gnome-terminal?nautilus-open-terminal?control-center?liberation-mono-fonts [root@wic?~]#?unlink?/etc/systemd/system/default.target [root@wic?~]#?ln?-sf?/lib/systemd/system/graphical.target?/etc/systemd/system/default.target [root@wic?~]#?reboot
第一步,安裝VNC packages:
[root@wic?~]#?yum?install?tigervnc-server?-y
第二步,修改配置信息,在/etc/systemd/system/下建立文件夾vncserver@:1.service 把example config 文件從/lib/systemd/system/vncserver@.service復制到里面
[root@wic?~]#?cp?/lib/systemd/system/vncserver@.service?/etc/systemd/system/vncserver@:1.service
然后打開這個配置文件/etc/systemd/system/vncserver@: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
[root@wic?~]#?systemctl?daemon-reload
第四步,為VNC設密碼
[root@wic?~]#?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 默認防火墻的可能需要
[root@wic?~]#?firewall-cmd?--permanent?--add-service?vnc-server [root@wic?~]#?systemctl?restart?firewalld.service
如果還是有問題可以試試關閉防火墻
停止并禁用防火墻; systemctl?stop?firewalld.service systemctl?disable?firewalld.service
第六步,設默認啟動并開啟VNC
[root@wic?~]#?systemctl?enable?vncserver@:1.service [root@wic?~]#?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和啟動開啟VNC
這樣基本上Centos 端就設好了,Windows 端要去下一個VNC Viewer 的軟件。連接一下試試看著有點簡陋但是上去了的
本文轉自 Mr_sheng 51CTO博客,原文鏈接:http://blog.51cto.com/sf1314/1978785