溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

CentOS7如何安裝GUI界面及遠(yuǎn)程連接

發(fā)布時(shí)間:2021-05-31 11:08:17 來源:億速云 閱讀:747 作者:小新 欄目:服務(wù)器

這篇文章給大家分享的是有關(guān)CentOS7如何安裝GUI界面及遠(yuǎn)程連接的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過來看看吧。

用基于瀏覽器(webdriver)的selenium技術(shù)爬取數(shù)據(jù),所以程序需運(yùn)行在GUI環(huán)境下

安裝GUI界面

大多數(shù)云服務(wù)器廠商提供的鏡像都無GUI界面,所以要先安裝圖形環(huán)境。本文使用GNOME桌面環(huán)境:

yum -y groups install "GNOME Desktop"

這條命令將安裝GNOME桌面的必要軟件包,執(zhí)行完后配置X系統(tǒng)使用GNOME:

echo "exec gnome-session" >> ~/.xinitrc

安裝KDE或者M(jìn)ATE桌面環(huán)境的兩個(gè)命令稍微不一樣:

# kde
yum -y groups install "KDE Plasma Workspaces"
echo "exec startkde" >> ~/.xinitrc

# mate
yum --enablerepo=epel -y groups install "MATE Desktop"
echo "exec /usr/bin/mate-session" >> ~/.xinitrc

以上便安裝好了GUI桌面環(huán)境。

啟動(dòng)桌面環(huán)境有兩種方式:

  1. 一次性的:在終端里輸入startx;

  2. 系統(tǒng)啟動(dòng)時(shí)默認(rèn)進(jìn)入桌面環(huán)境: systemctl set-default graphical.target,然后重啟;

安裝vnc-server

有了桌面環(huán)境,一般可以通過云服務(wù)器廠商提供的web終端遠(yuǎn)程連接進(jìn)入桌面。用web終端每次都需要打開瀏覽器,然后登陸云管理后臺(tái)再連接,比較麻煩。我們采取直接從桌面客戶端遠(yuǎn)程連接的方式,省去打開瀏覽器和登錄云管理后臺(tái)的操作。

遠(yuǎn)程桌面技術(shù)有多種,例如VNC, TeamViewer, RDP等,本文使用免費(fèi)且廣泛使用的VNC。

在服務(wù)器上先安裝服務(wù)端(tigervnc是tightvnc的分支):

yum install -y tigervnc-server

接著復(fù)制一份VNC配置:

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

注意上述命令參數(shù)重的“@:1”,可以將數(shù)字1換成30000內(nèi)的任意數(shù)字,“5900+數(shù)字”即為程序的顯示(監(jiān)聽)端口,如”@:1″表示監(jiān)聽5901端口。

編輯該配置文件,將文件內(nèi)的<USER>替換成遠(yuǎn)程連接時(shí)的登錄用戶名(如果是root,注意將第二個(gè)<USER>所在行的”/home”移除掉)。以root身份的配置示例:

# The vncserver service unit file
#
# Quick HowTo:
# 1. Copy this file to /etc/systemd/system/vncserver@.service
# 2. Replace <USER> with the actual user name and edit vncserver
#  parameters appropriately
#  (ExecStart=/usr/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"
#   PIDFile=/home/<USER>/.vnc/%H%i.pid)
# 3. Run `systemctl daemon-reload`
# 4. Run `systemctl enable vncserver@:<display>.service`
#
# DO NOT RUN THIS SERVICE if your local area network is
# untrusted! For a secure way of using VNC, you should
# limit connections to the local host and then tunnel from
# the machine you want to view VNC on (host A) to the machine
# whose VNC output you want to view (host B)
#
# [user@hostA ~]$ ssh -v -C -L 590N:localhost:590M hostB
#
# this will open a connection on port 590N of your hostA to hostB's port 590M
# (in fact, it ssh-connects to hostB and then connects to localhost (on hostB).
# See the ssh man page for details on port forwarding)
#
# You can then point a VNC client on hostA at vncdisplay N of localhost and with
# the help of ssh, you end up seeing what hostB makes available on port 590M
#
# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
#
# Use "-localhost" to prevent remote VNC clients connecting except when
# doing so through a secure tunnel. See the "-via" option in the
# `man vncviewer' manual page.


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

[Service]
Type=forking

# 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

接下來設(shè)置vnc連接密碼:

vncpasswd

注意連接密碼與登錄密碼不同:連接密碼用于顯示遠(yuǎn)程桌面,登錄密碼用于用戶登錄系統(tǒng)。

設(shè)置好后,啟動(dòng)vnc服務(wù):

systemctl daemon-reload
systemctl start vncserver@:1
systemctl enable vncserver@:1

如果開啟了防火墻,注意放行相應(yīng)端口。

客戶端連接

服務(wù)端配置完畢,接下來用客戶端連接。

vnc是免費(fèi)技術(shù),許多客戶端都支持該協(xié)議。本文采用App Store上免費(fèi)的“Remote Desktop – VNC”軟件進(jìn)行連接,打開后軟件界面如下:

CentOS7如何安裝GUI界面及遠(yuǎn)程連接

在輸入框填寫服務(wù)器地址:vnc://ip:port,其中ip是服務(wù)器的ip或域名,port是監(jiān)聽的端口,例如5901。輸入后按回車,彈出密碼輸入框,輸入vncpasswd設(shè)置的密碼。密碼正確的話就可以看到服務(wù)器的圖形桌面,例如:

CentOS7如何安裝GUI界面及遠(yuǎn)程連接

按回車鍵進(jìn)入登錄界面,輸入登錄用戶名和密碼進(jìn)入系統(tǒng):

CentOS7如何安裝GUI界面及遠(yuǎn)程連接

接下來就可以做各種圖形操作了。

感謝各位的閱讀!關(guān)于“CentOS7如何安裝GUI界面及遠(yuǎn)程連接”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI