Ubuntu 18/20/22 相關設定整理

  • CPU核心數 / 記憶體大小 / 硬碟空間 / 作業系統版本

    lscpu
    free -h
    lsblk
    lsb_release -a

    替代方案

    cat /proc/cpuinfo | grep processor | wc -l
    cat /proc/meminfo | grep MemTotal
    df -h /
    cat /etc/issue

  • 網路相關

    curl https://ip.im
    sudo ufw status
    ip a
    ip r
    ip link show
    cat /etc/resolv.conf | grep nameserver
    tracepath -n 1.1.1.1

  • Exp. 設定開啟 tcp port 22(ssh), 80(http), 443(https) 以及 udp port 161(snmp)

    ufw allow proto tcp from any to any port 22,80,443 comment 'Open SSH/Web ports'
    ufw allow proto udp from any to any port 161 comment 'Open SNMP ports'

  • 設定後查看目前 ufw 狀態

    ufw status

    • 看執行結果
  • 先 /etc/cloud/cloud.cfg 內 preserve_hostname 為 true
    sudo vi /etc/cloud/cloud.cfg
    :
    preserve_hostname: true
    :
  • 執行 hostnamectl 設定 hostname Exp. 更改為 pve-devops1
    sudo hostnamectl set-hostname pve-devops1
  • 如果useradd 建立時沒提供 sudo 權限可以之後透過 usermod 來處理 Exp.

    sudo usermod -aG sudo localadmin

    • 查看目前已使用空間

      root@demo-77:/var/log/journal/4ad9885bb19142118fd758b3be95057e# journalctl --disk-usage
      Archived and active journals take up 4.0G in the file system.

    • 即時清除保留兩天

      root@demo-77:/var/log/journal/4ad9885bb19142118fd758b3be95057e# journalctl --rotate
      root@demo-77:/var/log/journal/4ad9885bb19142118fd758b3be95057e# journalctl --vacuum-time=2days
      :
      root@demo-77:/var/log/journal/4ad9885bb19142118fd758b3be95057e# journalctl --disk-usage
      Archived and active journals take up 16.0M in the file system.

    • 設定最多使用空間 Exp. 500M

      vi /etc/systemd/journald.conf

      :
      [Journal]
      :
      SystemMaxUse=500M
      :
      systemctl daemon-reload
  • 在 VMWare 內建立 Ubuntu 20.04 的 VM , 在 /var/log/syslog 會看到以下的異常訊息

    ~# tail -f /var/log/syslog
    Aug 31 10:43:07 iiidevops4 multipathd[747]: sda: add missing path
    Aug 31 10:43:09 iiidevops4 multipathd[747]: sda: failed to get udev uid: Invalid argument
    Aug 31 10:43:11 iiidevops4 multipathd[747]: sda: failed to get sysfs uid: Invalid argument
    Aug 31 10:43:12 iiidevops4 multipathd[747]: sda: failed to get sgio uid: No such file or directory
    Aug 31 10:43:17 iiidevops4 multipathd[747]: sda: add missing path

  • 解決方式 :

    vi /etc/multipath.conf
    defaults {
        user_friendly_names yes
    }
    blacklist {
        devnode "^(ram|raw|loop|fd|md|dm-|sr|scd|st|sda)[0-9]*"
    }
    systemctl restart multipath-tools

  • tech/ubuntu18.txt
  • 上一次變更: 2024/12/26 10:29
  • jonathan