CentOS7.6安装VNC实录

第一步:安装VNC服务软件

使用root用户执行以下命令(以下操作没有特别说明均在root用户):

yum install -y vnc

运行结果 

[root@localhost ~]# yum install -y vnc
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: ftp.sjtu.edu.cn
 * extras: ftp.sjtu.edu.cn
 * updates: ftp.sjtu.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 tigervnc.x86_64.0.1.8.0-22.el7 将被 安装
--> 正在处理依赖关系 tigervnc-icons,它被软件包 tigervnc-1.8.0-22.el7.x86_64 需要
--> 正在处理依赖关系 libfltk_images.so.1.3()(64bit),它被软件包 tigervnc-1.8.0-22.el7.x86_64 需要
--> 正在处理依赖关系 libfltk.so.1.3()(64bit),它被软件包 tigervnc-1.8.0-22.el7.x86_64 需要
--> 正在检查事务
---> 软件包 fltk.x86_64.0.1.3.4-2.el7 将被 安装
--> 正在处理依赖关系 libGLU.so.1()(64bit),它被软件包 fltk-1.3.4-2.el7.x86_64 需要
---> 软件包 tigervnc-icons.noarch.0.1.8.0-22.el7 将被 安装
--> 正在检查事务
---> 软件包 mesa-libGLU.x86_64.0.9.0.0-4.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

=======================================================================================
 Package                 架构            版本                   源                大小
=======================================================================================
正在安装:
 tigervnc                x86_64          1.8.0-22.el7           updates          236 k
为依赖而安装:
 fltk                    x86_64          1.3.4-2.el7            base             560 k
 mesa-libGLU             x86_64          9.0.0-4.el7            base             196 k
 tigervnc-icons          noarch          1.8.0-22.el7           updates           40 k

事务概要
=======================================================================================
安装  1 软件包 (+3 依赖软件包)

总下载量:1.0 M
安装大小:2.6 M
Downloading packages:
(1/4): mesa-libGLU-9.0.0-4.el7.x86_64.rpm                       | 196 kB  00:00:00     
(2/4): tigervnc-icons-1.8.0-22.el7.noarch.rpm                   |  40 kB  00:00:00     
(3/4): tigervnc-1.8.0-22.el7.x86_64.rpm                         | 236 kB  00:00:00     
(4/4): fltk-1.3.4-2.el7.x86_64.rpm                              | 560 kB  00:00:00     
---------------------------------------------------------------------------------------
总计                                                      2.3 MB/s | 1.0 MB  00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : tigervnc-icons-1.8.0-22.el7.noarch                                 1/4 
  正在安装    : mesa-libGLU-9.0.0-4.el7.x86_64                                     2/4 
  正在安装    : fltk-1.3.4-2.el7.x86_64                                            3/4 
  正在安装    : tigervnc-1.8.0-22.el7.x86_64                                       4/4 
  验证中      : mesa-libGLU-9.0.0-4.el7.x86_64                                     1/4 
  验证中      : tigervnc-icons-1.8.0-22.el7.noarch                                 2/4 
  验证中      : fltk-1.3.4-2.el7.x86_64                                            3/4 
  验证中      : tigervnc-1.8.0-22.el7.x86_64                                       4/4 

已安装:
  tigervnc.x86_64 0:1.8.0-22.el7                                                       

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

完毕!
yum install -y vnc-server

运行结果 

[root@localhost ~]# yum install -y vnc-server
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: ftp.sjtu.edu.cn
 * extras: ftp.sjtu.edu.cn
 * updates: ftp.sjtu.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 tigervnc-server.x86_64.0.1.8.0-22.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

=======================================================================================
 Package                  架构            版本                  源                大小
=======================================================================================
正在安装:
 tigervnc-server          x86_64          1.8.0-22.el7          updates          211 k

事务概要
=======================================================================================
安装  1 软件包

总下载量:211 k
安装大小:498 k
Downloading packages:
tigervnc-server-1.8.0-22.el7.x86_64.rpm                         | 211 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : tigervnc-server-1.8.0-22.el7.x86_64                                1/1 
  验证中      : tigervnc-server-1.8.0-22.el7.x86_64                                1/1 

已安装:
  tigervnc-server.x86_64 0:1.8.0-22.el7                                                

完毕!

安装后可以使用如下命令来验证是否安装成功:

rpm -qa|grep tigervnc-server

第二步:复制vnc的启动操作脚本,

vncserver@:1.service中的:1表示"桌面号",启动的端口号就是5900+桌面号,即是5901,如果再有一个就是2啦,端口号加1就是5902,以此类推:

cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service

第三步:编辑 /etc/systemd/system/vncserver@:1.service

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

按I进行编辑

找到

Type=simple

# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver_wrapper <USER> %i
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

 其中

Type=simple
​ExecStart=/usr/bin/vncserver_wrapper <USER> %i
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

 修改为

ExecStart=/usr/sbin/runuser -l root -c"/usr/bin/vncserver %1"
PIDFile=/root/.vnc/%H%i.pid

修改结果

# 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 %1"
PIDFile=/root/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

root为登录vnc的用户名,

# 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 用户名 -c"/usr/bin/vncserver %1"
PIDFile=/home/用户名/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

按Esc键退出编辑

输入:wq  保存退出(输入错误可以  :q!  强制不保存退出)

:wq

 配置多个桌面

cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:2.service
vim /etc/systemd/system/vncserver@\:2.service

编辑 /etc/systemd/system/vncserver@:1.service

​
vim /etc/systemd/system/vncserver@\:2.service

 

第四步:设置vnc密码,

执行su  用户名,切换到刚配置文件设置的用户,执行(这一步是在之前用户下操作),

切换admin用户

su admin

运行结果 

[root@localhost ~]# su admin
[admin@localhost root]$ 

切换root用户 

su root

 运行结果

[admin@localhost root]$ su root
密码:
[root@localhost ~]# 

 输入两次密码,

vncpasswd

运行结果 

[root@localhost ~]# vncpasswd
Password:
Verify:

输入完成后会提示是否设置view-only password(“View-only password”密码,只允许查看,无控制权限。)这个可设可不设:

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

第五步:启动服务:

重新加载

systemctl daemon-reload

第一次输入启动服务命令可能会要求输入(从新加载配置文件,新增和配置文件发生变化时都需要执行 daemon-reload 子命令): 

 启动服务

vncserver :1

运行结果

[root@localhost ~]# vncserver :1

New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1

Creating default startup script /root/.vnc/xstartup
Creating default config /root/.vnc/config
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:1.log

可以加入开机启动,下次开机就会自动启动啦:(待验证解决)

systemctl enable vncserver@\:1.service


第六步:查看端口是否监听:

netstat -lnpt|grep Xvnc

执行结果

[root@localhost ~]# netstat -lnpt|grep Xvnc
tcp        0      0 0.0.0.0:5901            0.0.0.0:*               LISTEN      107509/Xvnc         
tcp        0      0 0.0.0.0:6001            0.0.0.0:*               LISTEN      107509/Xvnc         
tcp6       0      0 :::5901                 :::*                    LISTEN      107509/Xvnc         
tcp6       0      0 :::6001                 :::*                    LISTEN      107509/Xvnc         

 这里我们可以看到5901端口已经被监听


第七步:开放防火墙的5901端口:

firewall-cmd --zone=public --add-port=5901/tcp --permanent
[root@localhost ~]# firewall-cmd --zone=public --add-port=5901/tcp --permanent
success

第八步:关闭SELinux,

编辑/etc/selinux/config 文件:vim /etc/selinux/config

vim /etc/selinux/config

 执行结果


# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

按i进行编辑
将selinux设置为disabled

SELINUX=enforcing
SELINUX=disabled

按Esc键退出编辑,

输入:wq 保存退出

到这里vnc服务已经安装完毕,下面就可使用vnc客户端来连接。

第九步:在vnc客户端(vnc viewer)输入服务器IP:桌面号

(如192.168.1.128:1),输入后回车:

第十步:输入IP后会弹出确认,点击contiue即可:

第十一步:输入vnc密码:

 

 

第十二步:登录成功,输入远程机器密码

(登录成功后需要输入远程机器的用户的密码,如果没有密码就可以直接进入系统):

第十三步:成功进入远程桌面:

至此整个CentOS7.x 的VNC服务安装完毕

PS:vnc服务只能在局域网使用,如果在外网,则需要有公网IP地址,VNC不仅具备内网穿透功能。

关闭vncserver

vncserver -kill :1

 执行结果

[root@localhost ~]# vncserver -kill :1
Killing Xvnc process ID 2850

vncserver -kill :n,关闭第n个vnc服务

vncserver -list

#列出当前用户所建立的所有远程桌面。

————————————————

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值