欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

CentOS7 安装 VNC 使用图形界面远程

程序员文章站 2022-07-03 13:59:11
...

安装之前检查下是否已经安装VNC

[aaa@qq.com ~]# rpm -q tigervnc tigervnc-server 
未安装软件包 tigervnc 
未安装软件包 tigervnc-server 

没有安装的话直接使用yum进行安装

[aaa@qq.com ~]# yum -y install tigervnc tigervnc-server
......
已安装:
  tigervnc.x86_64 0:1.8.0-13.el7                    tigervnc-server.x86_64 0:1.8.0-13.el7                   

作为依赖被安装:
  fltk.x86_64 0:1.3.4-1.el7    mesa-libGLU.x86_64 0:9.0.0-4.el7    tigervnc-icons.noarch 0:1.8.0-13.el7   

完毕!

复制配置模板并进行配置

[aaa@qq.com ~]# cp /lib/systemd/system/aaa@qq.com /etc/systemd/system/aaa@qq.com:1.service
[aaa@qq.com ~]# vim /etc/systemd/system/aaa@qq.com\:1.service 

将配置文件中的<user>改成对应的用户,我这里用root

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

调整为:

 41 # Clean any existing files in /tmp/.X11-unix environment
 42 ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
 43 ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver %i"
 44 PIDFile=/home/root/.vnc/%H%i.pid
 45 ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

要通知systemd重载此配置文件

[aaa@qq.com ~]# systemctl daemon-reload

现在为这个用户配置个密码

[aaa@qq.com ~]# vncpasswd 
Password:
Verify:
Would you like to enter a view-only password (y/n)? y
Password:
Verify:
[aaa@qq.com ~]# 

设置开机服务自启

[aaa@qq.com ~]# systemctl enable aaa@qq.com:1.service
Created symlink from /etc/systemd/system/multi-user.target.wants/aaa@qq.com:1.service to /etc/systemd/system/aaa@qq.com:1.service.

启动服务

[aaa@qq.com ~]# vncserver :1
A VNC server is already running as :1

New 'vijay.jump:2 (root)' desktop is vijay.jump:2

Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/vijay.jump:2.log

[aaa@qq.com ~]# 

剩下的就是按照VNCwindows客户端了,这个就不多说了,直接网上下载并安装,进去后新建连接,使用Ctrl+n打开配置,填写ip地址及端口号即可;默认端口号是从5901开始;

CentOS7 安装 VNC 使用图形界面远程