祗疼妳一个 发表于 2024-6-15 03:46:53

Linux 小本领:在 CentOS7 安装 XRDP 长途桌面服务器

1)图形界面安装

   CentOS7 没有图形化操纵可能对很多人来说都不太风俗,下面我们来为 CentOS7 安装图形化界面,本文以安装 GNOME 图形化为例
**写在安装前: **假如你的 CentOS7 是最小化安装,默认都是不带 XWINDOWS 的

[*]配置公网 Yum 源
mkdir /etc/yum.repos.d/backup
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup

cat > /etc/yum.repos.d/base.repo <<EOF

name=base
baseurl=https://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/
      https://mirrors.huaweicloud.com/centos/\$releasever/os/\$basearch/
      https://mirrors.cloud.tencent.com/centos/\$releasever/os/\$basearch/
      https://mirrors.tuna.tsinghua.edu.cn/centos/\$releasever/os/\$basearch/
      http://mirrors.163.com/centos/\$releasever/os/\$basearch/
      http://mirrors.sohu.com/centos/\$releasever/os/\$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-\$releasever


name=epel
baseurl=https://mirrors.aliyun.com/epel/\$releasever/\$basearch/
      https://mirrors.huaweicloud.com/epel/\$releasever/\$basearch/
      https://mirrors.cloud.tencent.com/epel/\$releasever/\$basearch/
      https://mirrors.tuna.tsinghua.edu.cn/epel/\$releasever/\$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-\$releasever


name=extras
baseurl=https://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch/
      https://mirrors.huaweicloud.com/centos/\$releasever/extras/\$basearch/
      https://mirrors.cloud.tencent.com/centos/\$releasever/extras/\$basearch/
      https://mirrors.tuna.tsinghua.edu.cn/centos/\$releasever/extras/\$basearch/
      http://mirrors.163.com/centos/\$releasever/extras/\$basearch/
      http://mirrors.sohu.com/centos/\$releasever/extras/\$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-\$releasever


name=updates
baseurl=https://mirrors.aliyun.com/centos/\$releasever/updates/\$basearch/
      https://mirrors.huaweicloud.com/centos/\$releasever/updates/\$basearch/
      https://mirrors.cloud.tencent.com/centos/\$releasever/updates/\$basearch/
      https://mirrors.tuna.tsinghua.edu.cn/centos/\$releasever/updates/\$basearch/
      http://mirrors.163.com/centos/\$releasever/updates/\$basearch/
      http://mirrors.sohu.com/centos/\$releasever/updates/\$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-\$releasever


name=centosplus
baseurl=https://mirrors.aliyun.com/centos/\$releasever/centosplus/\$basearch/
      https://mirrors.huaweicloud.com/centos/\$releasever/centosplus/\$basearch/
      https://mirrors.cloud.tencent.com/centos/\$releasever/centosplus/\$basearch/
      https://mirrors.tuna.tsinghua.edu.cn/centos/\$releasever/centosplus/\$basearch/
      http://mirrors.163.com/centos/\$releasever/centosplus/\$basearch/
      http://mirrors.sohu.com/centos/\$releasever/centosplus/\$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-\$releasever
EOF

yum clean all
yum repolist
输入安装 GNOME Desktop 命令
// < '桌面二选一' >
1. yum groupinstall -y "GNOME Desktop"         # GNOME DESKTOP
2. yum groupinstall -y "MATE Desktop"                # MATE DESKTOP
https://img-blog.csdnimg.cn/img_convert/4a1f10e388a1720bb9d2796bd8c8546a.png
安装完毕后,必要 设置默认从图形化界面启动
// 设置成图形模式
systemctl set-default graphical.target
重启系统
reboot
2)VNC 服务安装

   Linux 系统在服务器上一样平常都直接最小化安装,并未安装图形界面,但是有时候,有一些特别情况,必要使用图形界面。< 当然,实在我们也可以直接通过 XServer 转发至 Windows 显示 >
下面我将使用 VNC 来实现类似 Windows 的长途桌面功能。
    首先,系统必要有图形界面,可以在安装系统的时候一起安装 GNOME,或者背面再安装也行,下面即安装方法。

[*]配置公网 Yum 源
mkdir /etc/yum.repos.d/backup
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup

cat > /etc/yum.repos.d/base.repo <<EOF

name=base
baseurl=https://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/
      https://mirrors.huaweicloud.com/centos/\$releasever/os/\$basearch/
      https://mirrors.cloud.tencent.com/centos/\$releasever/os/\$basearch/
      https://mirrors.tuna.tsinghua.edu.cn/centos/\$releasever/os/\$basearch/
      http://mirrors.163.com/centos/\$releasever/os/\$basearch/
      http://mirrors.sohu.com/centos/\$releasever/os/\$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-\$releasever


name=epel
baseurl=https://mirrors.aliyun.com/epel/\$releasever/\$basearch/
      https://mirrors.huaweicloud.com/epel/\$releasever/\$basearch/
      https://mirrors.cloud.tencent.com/epel/\$releasever/\$basearch/
      https://mirrors.tuna.tsinghua.edu.cn/epel/\$releasever/\$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-\$releasever


name=extras
baseurl=https://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch/
      https://mirrors.huaweicloud.com/centos/\$releasever/extras/\$basearch/
      https://mirrors.cloud.tencent.com/centos/\$releasever/extras/\$basearch/
      https://mirrors.tuna.tsinghua.edu.cn/centos/\$releasever/extras/\$basearch/
      http://mirrors.163.com/centos/\$releasever/extras/\$basearch/
      http://mirrors.sohu.com/centos/\$releasever/extras/\$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-\$releasever


name=updates
baseurl=https://mirrors.aliyun.com/centos/\$releasever/updates/\$basearch/
      https://mirrors.huaweicloud.com/centos/\$releasever/updates/\$basearch/
      https://mirrors.cloud.tencent.com/centos/\$releasever/updates/\$basearch/
      https://mirrors.tuna.tsinghua.edu.cn/centos/\$releasever/updates/\$basearch/
      http://mirrors.163.com/centos/\$releasever/updates/\$basearch/
      http://mirrors.sohu.com/centos/\$releasever/updates/\$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-\$releasever


name=centosplus
baseurl=https://mirrors.aliyun.com/centos/\$releasever/centosplus/\$basearch/
      https://mirrors.huaweicloud.com/centos/\$releasever/centosplus/\$basearch/
      https://mirrors.cloud.tencent.com/centos/\$releasever/centosplus/\$basearch/
      https://mirrors.tuna.tsinghua.edu.cn/centos/\$releasever/centosplus/\$basearch/
      http://mirrors.163.com/centos/\$releasever/centosplus/\$basearch/
      http://mirrors.sohu.com/centos/\$releasever/centosplus/\$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-\$releasever
EOF

yum clean all
yum repolist

[*]安装 GNOME 桌面
// 列出的组软件包列表// < '桌面二选一' >yum grouplistyum groupinstall -y "GNOME Desktop"                        // 安装 GNOME DESKTOPyum groupinstall -y "MATE Desktop"                        // 安装 MATE Desktop# 安装完成后, 修改默认启动方式为图形化界面// 设置成图形模式
systemctl set-default graphical.target
# 假如要换返来// 设置成命令模式systemctl set-default multi-user.target   然后重启即可。

[*]安装 VNC SERVER
yum install tigervnc-server -y

[*]将 root 用户的 VNC 端口 设置为 Service 服务
// 复制一个 Service 服务设置模板
cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service

// 修改此服务配置
# 以下为 root 用户的配置, 每一个用户, 都需要单独设置一个监听服务, 且配置不同
vim /etc/systemd/system/vncserver@\:1.service

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


Type=forking
User=root

# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=-/usr/bin/vncserver -kill %i
ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i"
PIDFile=/root/.vnc/%H%i.pid
ExecStop=-/usr/bin/vncserver -kill %i


WantedBy=multi-user.target

[*]设置 VNC 暗码,VNC 的暗码跟系统的用户暗码不一样,是使用 VNC 客户端登陆时必要使用的暗码。
vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? n                # 这里不添加只读账号密码
A view-only password is not used

[*]启动服务,验证端口
# 设为开机启动
systemctl start vncserver@:1
systemctl enable vncserver@:1

# 查看服务监听的端口
netstat -lnpt | grep Xvnc

# 根据监听的端口
# 进行端口开放
# 每个用户会对应一个端口, 第一个用户默认为 5901 端口, 我这里是 root 用户
firewall-cmd --add-port=5901/tcp --permanent
firewall-cmd --reload
https://img-blog.csdnimg.cn/img_convert/6003074c6c5161536203939ad5975033.png

[*]到此 VNC 服务就已经安装完成了。然后必要使用 VNC 客户端进行连接。
https://img-blog.csdnimg.cn/img_convert/b44b3fd1cb4aa9d163f1733b8c059a75.png
**注意:MATE DESKTOP **桌面可能会出现如下状态
https://img-blog.csdnimg.cn/img_convert/03db6ead5c0a0f976b71fe764fc9bc01.png
办理
< '解决' >
vim ~/.vnc/xstartup
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS

/usr/bin/mate-session &
https://img-blog.csdnimg.cn/img_convert/c747dc78e987c9f8b5e059fbfaabfd78.png
重启 ROOT 端口服务
systemctl restart vncserver@:1
https://img-blog.csdnimg.cn/img_convert/42d761904a9d20c8621aca565396777e.png
   完成 VNC 连接~
3)XRDP 服务安装

CentOS7 提供了 “Cinnamon Desktop”,“MATE Desktop”,“GNOME Desktop”,“KDE Plasma Workspaces”,“LXQt Desktop”,**“Xfce” ** 让我们安装。

[*]我们可以选择自己喜欢的桌面环境,在这里选择安装 MATE DESKTOP 桌面:
// < '桌面二选一' >
yum groupinstall Xfce -y
yum groupinstall "MATE Desktop" -y

[*]安装 XRDP
yum -y install xrdp

[*]安装完成之后,设置开机默认启动 XRDP
systemctl start xrdp
systemctl enable xrdp

// 验证端口
netstat -nltp | grep 3389
https://img-blog.csdnimg.cn/img_convert/f652e1ce39a0dead6bce2fd78293c616.png

[*]创建 ~/.Xclients,设置默认启动 xfce4 桌面
// xfce Desktop
echo "xfce4-session" > ~/.Xclients
chmod +x .Xclients

// mate Desktop
echo "mate-session" > ~/.Xclients
chmod +x .Xclients

[*]在 Windows 客户端长途连接
https://img-blog.csdnimg.cn/img_convert/895e0b54234554522aa7fb1b38fcde79.png
输入 **Linux 系统 **的账户认证
https://img-blog.csdnimg.cn/img_convert/0cd77f5f3311a97c4c7a480edc941153.png
https://img-blog.csdnimg.cn/img_convert/897ad3ddfb1efe4104a1b0aa6d23c913.png
   大功告成~

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: Linux 小本领:在 CentOS7 安装 XRDP 长途桌面服务器