Home > Archives > Centos7配置VNC实战

Centos7配置VNC实战

Publish:

配置服务端

[root@localhost ~]# yum -y install tigervnc-server tigervnc
[root@localhost ~]# ll /lib/systemd/system/vncserver@.service
[root@localhost ~]# cp /lib/systemd/system/vncserver@.service /lib/systemd/system/vncserver@:1.service
[root@localhost ~]# vim /lib/systemd/system/vncserver@\:1.service

Before

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=forking //forking to simple
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :' //%i to :1
ExecStart=/usr/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i" //<USER> to root
PIDFile=/home/<USER>/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :' //%i to :1

[Install]
WantedBy=multi-user.target

After

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=simple
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :1 > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver :1"
PIDFile=/home/<USER>/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill :1 > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target

重新加载启动

[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl enable vncserver@:1.service
[root@localhost ~]# vncpasswd //需要到对应的用户下面运行这个命令
[root@localhost ~]# systemctl start vncserver@:1.service
[root@localhost ~]# chmod 777 /root/.vnc/xstartup
[root@localhost ~]# systemctl status vncserver@:1.service
[root@localhost ~]# netstat -lnt | grep 590*
[root@localhost ~]# grep vnc /var/log/messages
[root@localhost ~]# vim /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 5901 -j ACCEPT
[root@localhost ~]# service iptables restart

配置客户端

  1. 安装UltraVNC
  2. VNC Server:192.168.10.68:5901
  3. Key in password.

参考资料:

  1. @ Centos7 安装vnc
  2. Centos7远程桌面 vnc/vnc-server的设置
  3. CentOS7安装vncserver(启动失败及连接黑屏解决办法)

声明: 本文采用 BY-NC-SA 授权。转载请注明转自: Ding Bao Guo