<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          macOS 使用 XQuartz 支持 X11 實現(xiàn) Linux 圖形化界面顯示

          共 3538字,需瀏覽 8分鐘

           ·

          2020-11-25 10:29


          更多奇技淫巧歡迎訂閱博客:https://fuckcloudnative.io

          前言

          在 Windows 中相信大家已經(jīng)很熟悉使用 Xmanager(Xshell), MobaXterm, SecureCRT 通過 X11 實現(xiàn) Linux 圖形化界面顯示,我的需求是在 macOS 下使用 iTerm2 作為 Terminal 實現(xiàn) X11 圖形化界面顯示,網(wǎng)上大部分教程只提到安裝 Xquartz 但并沒有結(jié)合實際問題給出完整的解決步驟,我把實踐過程做了詳細的記錄方便大家按照最簡單的步驟實現(xiàn) Linux 圖形化顯示效果。

          1. X11 介紹

          有些 Linux 服務(wù)器出于性能和效率的考慮,通常都是沒有安裝圖形化界面的,那么圖形化程序在服務(wù)器上壓根兒就跑不起來,或者無法直接顯示出來,這就很尷尬了!那么如何解決這個問題呢?可以基于 X11 Forwarding 技術(shù) + MobaXterm/Xshell/SecureCRT/XQuartz 等第三方工具,就可以輕松搞定,是不是很簡單?

          X 協(xié)議

          Linux 本身是沒有圖形化界面的,所謂的圖形化界面系統(tǒng)只不過中 Linux 下的應(yīng)用程序。這一點和 Windows 不一樣。Windows 從 Windows 95 開始,圖形界面就直接在系統(tǒng)內(nèi)核中實現(xiàn)了,是操作系統(tǒng)不可或缺的一部分。Linux 的圖形化界面,底層都是基于 X 協(xié)議。

          X 協(xié)議由 X server 和 X client 組成:

          • X server 管理主機上與顯示相關(guān)的硬件設(shè)置(如顯卡、硬盤、鼠標等),它負責屏幕畫面的繪制與顯示,以及將輸入設(shè)置(如鍵盤、鼠標)的動作告知 X client。
          • X client (即 X 應(yīng)用程序) 則主要負責事件的處理(即程序的邏輯)。

          舉個例子,如果用戶點擊了鼠標左鍵,因為鼠標歸 X server 管理,于是 X server 就捕捉到了鼠標點擊這個動作,然后它將這個動作告訴 X client,因為 X client 負責程序邏輯,于是 X client 就根據(jù)程序預(yù)先設(shè)定的邏輯(例如畫一個圓),告訴 X server 說:“請在鼠標點擊的位置,畫一個圓”。最后,X server 就響應(yīng) X client 的請求,在鼠標點擊的位置,繪制并顯示出一個圓。

          X11 Forwarding

          這么繞,有啥意義呢?當然有!

          許多時候 X server 和 X client 在同一臺主機上,這看起來沒什么。但是, X server 和 X client 完全可以運行在不同的機器上,只要彼此通過 X 協(xié)議通信即可。于是,我們就可以做一些 “神奇” 的事情,比如像本文開頭談到的,在本地顯示 (X server),運行在服務(wù)器上的 GUI 程序 (X client)。這樣的操作可以通過 SSH X11 Forwarding (轉(zhuǎn)發(fā)) 來實現(xiàn)。

          X11 中的 X 指的就是 X 協(xié)議,11 指的是采用 X 協(xié)議的第 11 個版本。

          2. macOS 實現(xiàn) X11 圖形化界面顯示

          #?macOS?安裝?xquartz
          brew?cask?install?xquartz

          #?啟動?xquartz,實測?`Allow?connections?from?clients`?選項非必須條件
          Run?Applications?>?Utilities?>?XQuartz.app

          #?設(shè)置?DISPLAY?環(huán)境變量
          export?DISPLAY=:0

          #?沒有使用?xquartz?中?terminal?的話不會自動設(shè)置?DISPLAY?環(huán)境變量,可能會出現(xiàn)以下錯誤
          [root@VM-2-11-centos?~]#?firefox
          Failed?to?open?connection?to?"session"?message?bus:?Unable?to?autolaunch?a?dbus-daemon?without?a?$DISPLAY?for?X11
          Running?without?a11y?support!
          Error:?no?DISPLAY?environment?variable?specified

          #?ssh?添加?-?Y?flag?登錄遠程主機
          ssh?-Y?user@host

          #?登錄成功后可能出現(xiàn)以下錯誤,安裝?xauth?即可解決
          [email protected]
          X11?forwarding?request?failed?on?channel?0

          #?遠程主機安裝?xauth,以?centos?為例,使用?xclock?可以測試圖形化效果
          yum?install?-y?xauth?xclock
          xclock

          #?如果需要瀏覽器支持安裝?firefox?或者?chrome?即可
          yum?install?firefox
          firefox

          yum?install?https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
          /usr/bin/google-chrome-stable?%U?--no-sandbox

          3. FAQ

          1. Why do I need to install Xquartz?

            From https://stackoverflow.com/a/50182736/6769366

            XQuartz is standard. It used to come bundled with the OS, but Apple removed it back around Mavericks.

          2. Why do I have to add environment DISPLAY?

            Please see https://askubuntu.com/a/432257/745885[1]

          3. Why do I have to use -Y instead of -X?

            I got the following error when trying to run a python script which draws some curves using matplotlib:

          X?Error?of?failed?request:??BadAccess?(attempt?to?access?private?resource?denied)
          Major?opcode?of?failed?request:??18?(X_ChangeProperty)
          Serial?number?of?failed?request:??12
          Current?serial?number?in?output?stream:??15

          This problem is sovled when using -Y instead of -X. Haven’t got enough time to find exact explanation, just post a link for those who are curious:

          Can’t run “ssh -X” on MacOS Sierra[2]

          1. How to fix X11 forwarding request failed on channel 0?

            Install X authority file utility

          $?sudo?yum?install?xauth

          參考資料

          [1]

          https://askubuntu.com/a/432257/745885: https://askubuntu.com/a/432257/745885

          [2]

          Can’t run “ssh -X” on MacOS Sierra: https://stackoverflow.com/q/39622173/6769366

          原文鏈接:https://wsgzao.github.io/post/x11/


          你可能還喜歡

          點擊下方圖片即可閱讀

          在 k8s 中使用 Kubevirt 運行管理 Windows 10 操作系統(tǒng)

          云原生是一種信仰??



          碼關(guān)注公眾號

          后臺回復(fù)?k8s?獲取史上最方便快捷的 Kubernetes 高可用部署工具,只需一條命令,連 ssh 都不需要!



          點擊?"閱讀原文"?獲取更好的閱讀體驗!

          ??給個「在看」,是對我最大的支持??
          瀏覽 129
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  人人射| 久9视频 久产久操 | 国产成人亚洲日韩欧美四虎 | 乱伦一及 | 国产伦理久久精品久久久久 |