1. 程式人生 > 其它 >【常用操作】ubuntu部署說明

【常用操作】ubuntu部署說明

一、配置遠端桌面連線

1、配置網路

  • 修改網路配置資訊
root@node253:~# cat /etc/netplan/01-network-manager-all.yaml 
# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager
  ethernets: 
    ens160: 
      dhcp4: false
      addresses: [172.16.21.243/24]
    ens192: 
      dhcp4: false
      addresses: [66.66.67.253/24]
      gateway4: 66.66.66.1
      nameservers: 
        addresses: [114.114.114.114,8.8.8.8]
root@node253:~# netplan --debug apply

2、配置ssh登入

  • 安裝openssh-server,開放22埠
sudo apt-get install openssh-server
sudo ufw allow 22
  • 配置允許root使用者遠端登入,重啟ssh服務
root@node253:~# cat /etc/ssh/sshd_config
LoginGraceTime 2m
PermitRootLogin yes
StrictModes yes
root@node253:~# systemctl restart sshd
  • Q&A
    • 使用xftp上傳檔案失敗,提示伺服器傳送了一個意外的資料包。received:3,expected:20

      檢視相關資料為新版sshd與xshell存在相容性問題,需要追加配置資訊如下,重啟sshd服務即可
root@node253:~# echo "KexAlgorithms [email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group14-sha1" >> /etc/ssh/sshd_config
root@node253:~# systemctl restart sshd

3、配置遠端桌面

注:GUI介面下執行快捷鍵Ctl + Alt + T

可調出命令列視窗

3.1、設定桌面解析度

安裝ubuntu系統之後,預設只有1024 x 768和800 x 600兩種解析度

  • 增加解析度選項配置
    新增1920x1080及1366x768解析度配置如下:
xrandr --newmode $(cvt 1920 1080 60 | grep Mode | sed -e 's/.*"/1920x1080/')
xrandr --addmode VGA-1 1920x1080

xrandr --newmode $(cvt 1366 768 60 | grep Mode | sed -e 's/.*"/1366x768/')
xrandr --addmode VGA-1 1366x768
  • 選擇設定-顯示器,設定對應解析度選項,應用配置即可

Q&A

1、xrandr:failed to get size of gamma for output default
  • 問題描述:
    在使用xrandr進行解析度設定的時候,出現錯誤“xrandr:failed to get size of gamma for output default”,嘗試多種方法無解,使用以下方法方可解決,但暫不清楚具體什麼原因,此處只做記錄,後續再研究下
  • 解決方法:
    新增以下配置檔案資訊,重啟即可
root@node254:~# cat /etc/xorg.conf 
Section "Monitor"
        Identifier   "Monitor0"
        VendorName   "Monitor Vendor"
        ModelName    "Monitor Model"
        HorizSync   28.0 - 70.0
        VertRefresh     56.0 - 75.0
EndSection


Section "Device"
        Identifier  "VMware SVGA"
        Driver      "vesa"
EndSection


Section "Screen"
        Identifier "Screen0"
        Device     "Card0"
        Monitor    "Monitor0"
        SubSection "Display"
                Viewport   0 0
                Depth     24
                Modes     "1920x1080_60.00"
        EndSubSection
EndSection

3.2、配置遠端桌面

3.2.1、開啟螢幕共享

選擇設定-共享,點選螢幕共享選項,開啟設定開關,勾選需要密碼,選擇對應網絡卡

3.2.2、安裝xrdp
sudo apt-get install xrdp -y
3.2.3、安裝dconf-editor及配置

此步驟主要用於關閉遠端連線加密請求,否則會出現“vnc連線提示不支援安全型別”錯誤

  • 安裝dcof-editor
sudo apt-get install dconf-editor
  • 配置remote-access
    啟動dconf編輯器,選擇org->gnome->desktop->remote-access,關閉"requlre-encryption"開關
3.2.3、windows遠端訪問

此時,使用windows的mstsc遠端桌面訪問即可,選擇vnc-any會話,輸入ip和密碼即可訪問ubuntu遠端桌面

二、更換系統核心版本

Ubuntu 20.04.2 LTS系統預設核心版本為5.4.0-42-generic

1、檢視當前指定版本可用軟體包

root@node254:~# apt-cache search 5.4.0-42-generic
linux-buildinfo-5.4.0-42-generic - Linux kernel buildinfo for version 5.4.0 on 64 bit x86 SMP
linux-cloud-tools-5.4.0-42-generic - Linux kernel version specific cloud tools for version 5.4.0-42
linux-headers-5.4.0-42-generic - Linux kernel headers for version 5.4.0 on 64 bit x86 SMP
linux-image-5.4.0-42-generic - Signed kernel image generic
linux-image-unsigned-5.4.0-42-generic - Linux kernel image for version 5.4.0 on 64 bit x86 SMP
linux-modules-5.4.0-42-generic - Linux kernel extra modules for version 5.4.0 on 64 bit x86 SMP
linux-modules-extra-5.4.0-42-generic - Linux kernel extra modules for version 5.4.0 on 64 bit x86 SMP
linux-tools-5.4.0-42-generic - Linux kernel version specific tools for version 5.4.0-42
linux-modules-nvidia-390-5.4.0-42-generic - Linux kernel nvidia modules for version 5.4.0-42
linux-modules-nvidia-418-server-5.4.0-42-generic - Linux kernel nvidia modules for version 5.4.0-42
linux-modules-nvidia-435-5.4.0-42-generic - Linux kernel nvidia modules for version 5.4.0-42
linux-modules-nvidia-440-5.4.0-42-generic - Linux kernel nvidia modules for version 5.4.0-42
linux-modules-nvidia-440-server-5.4.0-42-generic - Linux kernel nvidia modules for version 5.4.0-42

2、下載指定版本linux-images和linux-headers

root@node254:~# apt-get install linux-image-5.4.0-42-generic linux-headers-5.4.0-42-generic -y

3、設定系統預設啟動核心版本

  • 檢視當前系統啟動項
root@node254:~# grep menuentry /boot/grub/grub.cfg
if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
  menuentry_id_option=""
export menuentry_id_option
menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-98224eb1-df53-4a47-bc17-d2a84efd4225' {
submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-98224eb1-df53-4a47-bc17-d2a84efd4225' {
    menuentry 'Ubuntu,Linux 5.8.0-53-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.8.0-53-generic-advanced-98224eb1-df53-4a47-bc17-d2a84efd4225' {
    menuentry 'Ubuntu, with Linux 5.8.0-53-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.8.0-53-generic-recovery-98224eb1-df53-4a47-bc17-d2a84efd4225' {
    menuentry 'Ubuntu,Linux 5.8.0-43-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.8.0-43-generic-advanced-98224eb1-df53-4a47-bc17-d2a84efd4225' {
    menuentry 'Ubuntu, with Linux 5.8.0-43-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.8.0-43-generic-recovery-98224eb1-df53-4a47-bc17-d2a84efd4225' {
    menuentry 'Ubuntu,Linux 5.4.0-42-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-42-generic-advanced-98224eb1-df53-4a47-bc17-d2a84efd4225' {
    menuentry 'Ubuntu, with Linux 5.4.0-42-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-42-generic-recovery-98224eb1-df53-4a47-bc17-d2a84efd4225' {
menuentry 'Memory test (memtest86+)' {
menuentry 'Memory test (memtest86+, serial console 115200)' {

如上所示,啟動過程中GRUB選單如下,GRUB_DEFAULT預設為0,即預設使用ubuntu選項啟動系統
選項索引從0開始,當需要選擇子選單選項時,則表示為一級選單索引號> 二級選單索引號;示例需要選擇Ubuntu,Linux 5.4.0-42-generic選項啟動,則GRUB_DEFAULT1> 4
注:>後需加空格隔開

  • Ubuntu
  • Advanced options for Ubuntu
    • Ubuntu,Linux 5.8.0-53-generic
    • Ubuntu, with Linux 5.8.0-53-generic (recovery mode)
    • Ubuntu,Linux 5.8.0-43-generic
    • Ubuntu, with Linux 5.8.0-43-generic (recovery mode)
    • Ubuntu,Linux 5.4.0-42-generic
    • Ubuntu, with Linux 5.4.0-42-generic (recovery mode)
  • Memory test (memtest86+)
  • Memory test (memtest86+, serial console 115200)

注:系統引導頁面示意如下:

  • 修改啟動選項,更新grub資訊,重啟系統即可
root@node254:~# cat /etc/default/grub | grep "GRUB_DEFAULT"
GRUB_DEFAULT="1> 4"
root@node254:~# update-grub
root@node254:~# reboot