English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Centos7与Centos6.x有了很大的不同。
为了给一台服务器装上远程桌面,走了不少弯路。写这篇博文,纯粹为了记录,以后如果遇到相同问题,可以追溯。
1、假定你的系统没有安装vnc的任何软件,那么,首先安装vnc
yum -y install tigervnc-server tigervnc
2、Centos7之前的系统,如果安装vnc一般都需要配置
[root@localhost ~]# cat /etc/sysconfig/vncservers # THIS FILE HAS BEEN REPLACED BY /lib/systemd/system/[email protected]
但是,如上所述,Centos7需要配置的文件在
[root@localhost ~]# ll /lib/systemd/system/[email protected] -rw-r--r--. 1 root root 1744 Jun 10 14:15 /lib/systemd/system/[email protected]
3:
、Die Datei enthält folgende Anweisungen # 1# Schneller Leitfaden: /etc/systemd/system/. Kopieren Sie diese Datei nach # 2vncserver@:<display>.service . Bearbeiten Sie <USER> und die vncserver-Parameter entsprechend -# ("runuser -l <USER> /usr/bin/c -vncserver %i1 -vncserver %i2arg # 3)-. Führen Sie `systemctl daemon` aus # 4. Führen Sie `systemctl enable vncserver@:<display>.service` aus
4、Kopieren Sie eine Datei und benennen Sie sie in vncserver@: um1.service
[root@localhost ~]# cp /lib/systemd/system/[email protected]/lib/systemd/system/vncserver@:1.service
5、Ersetzen Sie <User> durch Ihren aktuellen Benutzer und ersetzen Sie %i durch1
[Unit] Beschreibung=Remote Desktop-Dienst (VNC) After=syslog.target network.target [Service] Type=forking # Säubern Sie alle bestehenden Dateien 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、Aktualisieren Sie systemctl
systemctl daemon-reload
7、Setzen Sie ihn auf automatische Start
systemctl enable vncserver@:1.service
8、Starten Sie den VNC-Dienst
systemctl start vncserver@:1.service
9、Fügen Sie die entsprechenden Ports in iptables hinzu5901Achtung, falls andere Benutzer vorhanden sind, müssen auch die Ports hinzugefügt werden. Der Standardport für VNC ist5900 + 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/[email protected]/lib/systemd/system/vncserver@:2.service
同时,将文件内的%i改为2,并建立对应用户的vncpasswd。
3、你可以通过UltraVNC,TigerVNC或者RealVNC Viewer进行访问,我在win7下使用这3中工具均能连接
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!