Centos7遠程桌面 vnc/vnc-server的設置詳解
Centos7與Centos6.x有了很大的不同。
為了給一臺服務器裝上遠程桌面,走了不少彎路。寫這篇博文,純粹為了記錄,以后如果遇到相同問題,可以追溯。
1、假定你的系統(tǒng)沒有安裝vnc的任何軟件,那么,首先安裝vnc
yum -y install tigervnc-server tigervnc
2、Centos7之前的系統(tǒng),如果安裝vnc一般都需要配置
[root@localhost ~]# cat /etc/sysconfig/vncservers # THIS FILE HAS BEEN REPLACED BY /lib/systemd/system/vncserver@.service
但是,如上所述,Centos7需要配置的文件在
[root@localhost ~]# ll /lib/systemd/system/vncserver@.service -rw-r--r--. 1 root root 1744 Jun 10 14:15 /lib/systemd/system/vncserver@.service
3、文件內有如下提示
# Quick HowTo:
# 1. Copy this file to /etc/systemd/system/vncserver@:<display>.service
# 2. Edit <USER> and vncserver parameters appropriately
# ("runuser -l <USER> -c /usr/bin/vncserver %i -arg1 -arg2")
# 3. Run `systemctl daemon-reload`
# 4. Run `systemctl enable vncserver@:<display>.service
4、復制一份文件,并改名為vncserver@:1.service
[root@localhost ~]# cp /lib/systemd/system/vncserver@.service/lib/systemd/system/vncserver@:1.service
5、將文件中的<User>用你當前的用戶替換,將%i替換為1
[Unit] Description=Remote desktop service (VNC) After=syslog.target network.target [Service] Type=forking # Clean any existing files in /tmp/.X11-unix environment ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :1 > /dev/null 2>&1 || :' ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver :1 -geometry 1280x720 -depth 24" PIDFile=/root/.vnc/%H%i.pid ExecStop=/bin/sh -c '/usr/bin/vncserver -kill :1 > /dev/null 2>&1 || :' [Install] WantedBy=multi-user.target
6、更新systemctl
systemctl daemon-reload
7、設置為自動啟動
systemctl enable vncserver@:1.service
8、啟動vnc服務
systemctl start vncserver@:1.service
9、在iptables中加入對應的端口5901(注意,如果有其他用戶,那么也需要將端口加上。vnc的端口默認是5900 + n)
[root@localhost system]# cat /etc/sysconfig/iptables # sample configuration for iptables service # you can edit this manually or use system-config-firewall # please do not ask us to add additional ports/services to this default configuration *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 5901 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT
注意:
1、如果你不配置和啟用防火墻,此時用VNC Viewer連接的話,會報:"connect:Connection timed out(10060)"錯誤。
2、本文是以root用戶為例,如果其他用戶也需要登錄,那么,還需要將文件復制為
cp /lib/systemd/system/vncserver@.service/lib/systemd/system/vncserver@:2.service
同時,將文件內的%i改為2,并建立對應用戶的vncpasswd。
3、你可以通過UltraVNC,TigerVNC或者RealVNC Viewer進行訪問,我在win7下使用這3中工具均能連接
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關文章
Linux中查看指定文件夾內各個子文件夾內的文件數(shù)量
今天小編就為大家分享一篇關于Linux中查看指定文件夾內各個子文件夾內的文件數(shù)量,小編覺得內容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-01-01
CentOS6.5與CentOS7 ssh修改默認端口號的方法
這篇文章主要介紹了CentOS6.5與CentOS7 ssh修改默認端口號的方法,結合實例形式分別描述了CentOS6.5及CentOS7針對ssh修改默認端口號的具體操作步驟、相關命令與使用技巧,需要的朋友可以參考下2018-04-04
Service Temporarily Unavailable的503錯誤是怎么回事?
一般來說,出現(xiàn)Service Temporarily Unavailable錯誤多半是因為網(wǎng)站訪問量大,造成了流量超限或者并發(fā)數(shù)大引起的資源超限出現(xiàn)的錯誤2013-05-05

