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、文件内有如下提示
# 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) # 3reload`-. Run `systemctl daemon # 4. Run `systemctl enable vncserver@:<display>.service
4、复制一份文件,并改名为vncserver@:1.service
[root@localhost ~]# cp /lib/systemd/system/[email protected]/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 # configuración de muestra para el servicio iptables # puede editar esto manualmente o usar system-config-firewall # no nos pida que agreguemos puertos adicionales/servicios a esta configuración predeterminada *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m estado --estado RELATED,ESTABLISHED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -p tcp -m estado --estado NEW -m tcp --dport 22 -j ACCEPT -A INPUT -p tcp -m estado --estado NEW -m tcp --dport 5901 -j ACCEPT -A INPUT -j REJECT --rechazar-con icmp-anfitrión-prohibido -A FORWARD -j REJECT --rechazar-con icmp-anfitrión-prohibido COMMIT
Atención:
1、Si no configura y habilita el firewall, al conectarse con VNC Viewer en este momento, se informará: "connect: Time out de conexión("10060)"error."
2、Este artículo se toma como ejemplo del usuario root, si otros usuarios también necesitan ingresar, entonces, también se necesita copiar el archivo como
cp /lib/systemd/system/[email protected]/lib/systemd/system/vncserver@:2.service
Al mismo tiempo, cambie %i del archivo a2y crear vncpasswd para el usuario correspondiente.
3、Puede acceder a través de UltraVNC, TigerVNC o RealVNC Viewer, estoy en win7A continuación, utilice esto3Las herramientas en chino pueden conectarse
Gracias por leer, espero que pueda ayudar a todos, gracias por el apoyo a nuestro sitio!