centos7 远程桌面vnc

Centos7 采用mini安装,如果想远程桌面,那就需要安装图形界面

# yum check-update
# yum groupinstall "X Window System"
# yum install gnome-classic-session gnome-terminal nautilus-open-terminal control-center liberation-mono-fonts
# unlink /etc/systemd/system/default.target
# ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target
# reboot

下面开始安装:
1、安装tigervnc

# yum install tigervnc-server -y

2、从VNC备份库中复制service文件到系统service服务管理目录

# cp /lib/systemd/system/[email protected] /etc/systemd/system/vncserver@:1.service

3、修改配置文件

# vim /etc/systemd/system/vncserver@:1.service

#改成root用户启动,配置文件看起来这样的

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

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

[Install]
WantedBy=multi-user.target

4、启动服务
重启进程

# systemctl daemon-reload

设置VNC密码

[root@local ~]# vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
A view-only password is not used

设置开机启动及启动进程

[root@local ~]# systemctl enable vncserver@:1.service
Created symlink from /etc/systemd/system/multi-user.target.wants/vncserver@:1.service to /etc/systemd/system/vncserver@:1.service.
[root@local ~]# systemctl start vncserver@:1.service
[root@local ~]# systemctl status vncserver@:1.service
● vncserver@:1.service - Remote desktop service (VNC)
   Loaded: loaded (/etc/systemd/system/vncserver@:1.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-02-05 00:06:57 GMT; 7s ago
  Process: 58790 ExecStart=/usr/sbin/runuser -l root -c /usr/bin/vncserver %i (code=exited, status=0/SUCCESS)
  Process: 58778 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)
 Main PID: 58831 (Xvnc)
   CGroup: /system.slice/system-vncserver.slice/vncserver@:1.service
           ‣ 58831 /usr/bin/Xvnc :1 -auth /root/.Xauthority -desktop cfl-lab.communit...

Feb 05 00:06:53 cfl-lab.communityfibre.co.uk systemd[1]: Starting Remote desktop ser....
Feb 05 00:06:57 cfl-lab.communityfibre.co.uk systemd[1]: Started Remote desktop serv....
Hint: Some lines were ellipsized, use -l to show in full.

5、防火墙设置
关闭防火墙,或者放行5901端口。

6、VNC远程连接
现在用VNC可以远程连接了,VNC Server那里填写的是<服务器IP地址>:5901

猜你喜欢

转载自www.cnblogs.com/hang1368/p/11369212.html