在CentOS7上安装xrdp远程桌面环境

xrdp是Microsoft远程桌面协议(RDP)服务的开源实现。它允许您以图形方式控制远程计算机。使用xrdp,您可以登录到与Microsoft远程桌面协议(RDP)相同的远程计算机。本教程描述如何在CentOS7系统上安装xrdp(远程桌面),安装之前需要检查服务器网络及yum源正常。

安装软件包

在CentOS7中,有多种桌面环境可选:

[root@centos7 ~]# yum grouplist|grep -i desktop
   Cinnamon Desktop
   MATE Desktop
   GNOME Desktop
   General Purpose Desktop
   KDE Desktop
   LXQt Desktop
[root@centos7 ~]#

以root用户身份运行以下命令在远程服务器上安装Gnome:

[root@centos7 ~]# yum -y groupinstall "GNOME Desktop"
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
epel                                                     | 4.7 kB     00:00     
extras                                                   | 2.9 kB     00:00     
os                                                       | 3.6 kB     00:00     
updates                                                  | 2.9 kB     00:00     
(1/3): epel/7/x86_64/updateinfo                            | 1.0 MB   00:00     
(2/3): updates/7/x86_64/primary_db                         | 4.5 MB   00:01     
(3/3): epel/7/x86_64/primary_db                            | 6.9 MB   00:01     
Resolving Dependencies
--> Running transaction check
---> Package ModemManager.x86_64 0:1.6.10-3.el7_6 will be installed
--> Processing Dependency: ModemManager-glib(x86-64) = 1.6.10-3.el7_6 for package: ModemManager-1.6.10-3.el7_6.x86_64
--> Processing Dependency: libqmi-utils for package: ModemManager-1.6.10-3.el7_6.x86_64
--> Processing Dependency: libmbim-u
……
 xorg-x11-xkb-utils.x86_64 0:7.7-14.el7                                        
  yelp-libs.x86_64 2:3.28.1-1.el7                                               
  yelp-xsl.noarch 0:3.28.0-1.el7                                                
  zenity.x86_64 0:3.28.1-1.el7                                                  
Complete!
[root@centos7 ~]#

安装xrdp软件包:

[root@centos7 ~]# yum -y install xrdp

配置并启动xrdp服务

安装完成后,您需要启动xrdp服务并在系统启动时启用它:

[root@centos7 ~]# systemctl enable xrdp --now
Created symlink from /etc/systemd/system/multi-user.target.wants/xrdp.service to /usr/lib/systemd/system/xrdp.service.
[root@centos7 ~]#

检查xrdp服务状态

查看xrdp服务是否运行,关注“Active: active (running)”字段输出 :

[root@centos7 ~]# systemctl status xrdp
* xrdp.service - xrdp daemon
   Loaded: loaded (/usr/lib/systemd/system/xrdp.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2020-09-17 23:58:48 CST; 1min 5s ago
     Docs: man:xrdp(8)
           man:xrdp.ini(5)
 Main PID: 26961 (xrdp)
    Tasks: 1
   CGroup: /system.slice/xrdp.service
           `-26961 /usr/sbin/xrdp --nodaemon

Sep 17 23:58:48 centos7 systemd[1]: Started xrdp daemon.
Sep 17 23:58:48 centos7 xrdp[26961]: (26961)(140270469716416)[INFO ] starti...61
Sep 17 23:58:48 centos7 xrdp[26961]: (26961)(140270469716416)[INFO ] addres... 1
Sep 17 23:58:48 centos7 xrdp[26961]: (26961)(140270469716416)[INFO ] listen....0
Sep 17 23:58:48 centos7 xrdp[26961]: (26961)(140270469716416)[INFO ] xrdp_l...ne
Hint: Some lines were ellipsized, use -l to show in full.
[root@centos7 ~]#

查看xrdp服务监听状态,有3350和3389两个端口,其中3350监听内网回环地址127.0.0.1,3389监听0.0.0.0。

[root@centos7 ~]# netstat -ntpl|grep xrdp
tcp        0      0 127.0.0.1:3350          0.0.0.0:*               LISTEN      26960/xrdp-sesman   
tcp        0      0 0.0.0.0:3389            0.0.0.0:*               LISTEN      26961/xrdp          
[root@centos7 ~]# 

登录远程桌面服务器

通过以上设置,就可以使用windows远程桌面工具(mstsc)像登录windows远程桌面一样远程登录centos7桌面服务了。

注意事项:如果通过以上设置依旧不能登录centos7远程桌面,请注意检查您当前服务器的iptables规则及其他安全策略。