差異處

這裏顯示兩個版本的差異處。

連向這個比對檢視

兩邊的前次修訂版 前次修改
下次修改
前次修改
tech:ubuntu18 [2021/01/27 09:08] – [網路 IP 設定] jonathantech:ubuntu18 [2025/02/05 11:07] (目前版本) – [清除系統檔案空間] jonathan
行 1: 行 1:
-====== Ubuntu 18/20 相關設定整理 ======+====== Ubuntu 18/20/22 相關設定整理 ====== 
 +===== 了解主機現況配置 ===== 
 +  * CPU核心數 / 記憶體大小 / 硬碟空間 / 作業系統版本 <cli> 
 +lscpu 
 +free -h 
 +lsblk 
 +lsb_release -a 
 +</cli> 替代方案 <cli> 
 +cat /proc/cpuinfo | grep processor | wc -l 
 +cat /proc/meminfo | grep MemTotal 
 +df -h / 
 +cat /etc/issue 
 +</cli> 
 +  * 網路相關 <cli> 
 +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 
 +</cli> 
 ===== 網路 IP 設定 ===== ===== 網路 IP 設定 =====
   * 參考    * 參考 
行 41: 行 63:
     * 可以透過 sudo netplan apply 立即生效或是 sudo reboot 重新開機後生效     * 可以透過 sudo netplan apply 立即生效或是 sudo reboot 重新開機後生效
  
-===== 更改 hostname =====+===== 設定 ufw 主機防火牆 ===== 
 +  * Exp. 設定開啟 tcp port 22(ssh), 80(http), 443(https) 以及 udp port 161(snmp) <cli> 
 +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' 
 +</cli> 
 +  * 設定後查看目前 ufw 狀態 <cli> 
 +ufw status 
 +</cli> 
 +    * ++看執行結果|<cli> 
 +~# ufw status 
 +Status: active 
 + 
 +To                         Action      From 
 +--                         ------      ---- 
 +22/tcp                     ALLOW       Anywhere 
 +22,80,443/tcp              ALLOW       Anywhere                   # Open SSH/Web ports 
 +161/udp                    ALLOW       Anywhere                   # Open SNMP ports 
 +22/tcp (v6)                ALLOW       Anywhere (v6) 
 +22,80,443/tcp (v6)         ALLOW       Anywhere (v6)              # Open SSH/Web ports 
 +161/udp (v6)               ALLOW       Anywhere (v6)              # Open SNMP ports 
 +</cli>++ 
 + 
 +===== 修改 iptables 規則, 重開機仍能自動生效  ===== 
 +  * 參考 - https://askubuntu.com/questions/1452706/problem-with-my-iptables-configuration-on-reboot/1452833#1452833 
 +  * 需要安裝 iptables-persistent 套件<cli> 
 +apt install iptables-persistent -y 
 +</cli> 
 +  * 修改 iptables 規則 Exp. <cli> 
 +iptables -I FORWARD -i br0 -p all -j ACCEPT 
 +</cli> 
 +  * 將修改後的規則寫入 /etc/iptables/rules.v4 <cli> 
 +iptables-save -c > /etc/iptables/rules.v4 
 +</cli> 
 + 
 +===== 更改 hostname (一) =====
   * 參考 - https://www.itread01.com/content/1541622152.html   * 參考 - https://www.itread01.com/content/1541622152.html
   * 先 /etc/cloud/cloud.cfg 內 preserve_hostname 為 true<code sh>sudo vi /etc/cloud/cloud.cfg</code><file>   * 先 /etc/cloud/cloud.cfg 內 preserve_hostname 為 true<code sh>sudo vi /etc/cloud/cloud.cfg</code><file>
行 51: 行 107:
 sudo hostnamectl set-hostname pve-devops1 sudo hostnamectl set-hostname pve-devops1
 </code> </code>
 +
 +===== 更改 hostname (二) =====
 +  * Exp. 設定 hostname 為 iServStorM1<code>
 +sudo su -
 +vi /etc/hosts
 +</code><file>
 +127.0.0.1       localhost
 +127.0.1.1       iServStorM1
 +:
 +</file><code sh>
 +vi /etc/hostname
 +</code><file>
 +iServStorM1
 +</file><code sh>
 +hostname -F /etc/hostname
 +</code>
 +  * 參考網址 - 
 +    * http://computer.jges.mlc.edu.tw/index.php/ubuntu/112-ubuntu-14-04-%E8%A8%AD%E5%AE%9Ahostname
  
 ===== 建立使用者命令 ===== ===== 建立使用者命令 =====
   * 參考 - https://www.cyberciti.biz/faq/create-a-user-account-on-ubuntu-linux/   * 參考 - https://www.cyberciti.biz/faq/create-a-user-account-on-ubuntu-linux/
-  * Exp. 建立 localadmin <code sh>+  * Exp. 建立 localadmin <cli>
 sudo useradd -s /bin/bash -d /home/localadmin/ -m -G sudo localadmin sudo useradd -s /bin/bash -d /home/localadmin/ -m -G sudo localadmin
 sudo passwd localadmin  sudo passwd localadmin 
 +</cli>
 +
 +  * 如果useradd 建立時沒提供 sudo 權限可以之後透過 usermod 來處理 Exp.<cli>
 +sudo usermod -aG sudo localadmin
 +</cli>
 +
 +===== 查詢安裝套件檔案路徑 =====
 +  * 參考網址 - https://www.ubuntu-tw.org/modules/newbb/viewtopic.php?post_id=81494
 +  * 語法 : dpkg -L 套件名稱 Exp. docker<cli>
 +/# dpkg -L docker
 +/.
 +/usr
 +/usr/share
 +/usr/share/doc
 +/usr/share/doc/docker
 +/usr/share/doc/docker/changelog.Debian.gz
 +/usr/share/doc/docker/copyright
 +</cli>
 +
 +===== Server 版安裝圖形操作介面 =====
 +  * <code sh>
 +sudo apt-get install --no-install-recommends ubuntu-desktop
 </code> </code>
 +  * 參考網址 -
 +    * http://www.arthurtoday.com/2012/11/ubuntu-server-install-unity-gui.html
 +
 +===== 清除系統檔案空間 =====
 +  * System Journal Logs Ref - https://ubuntuhandbook.org/index.php/2020/12/clear-systemd-journal-logs-ubuntu/
 +    * 查看目前已使用空間 <cli>
 +root@demo-77:/var/log/journal/4ad9885bb19142118fd758b3be95057e# journalctl --disk-usage
 +Archived and active journals take up 4.0G in the file system.
 +</cli>
 +    * 即時清除保留兩天 <cli>
 +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.
 +</cli>
 +    * 設定最多使用空間 Exp. 500M <cli>
 +vi /etc/systemd/journald.conf
 +</cli><file>
 +:
 +[Journal]
 +:
 +SystemMaxUse=500M
 +:
 +</file><cli>
 +systemctl daemon-reload
 +</cli>清理現有的大型 journal 檔案<cli>
 +sudo journalctl --vacuum-size=500M
 +</cli>
 +
 +
 +===== VMWare 內出現的 multipathd 異常訊息 =====
 +  * 參考 - https://askubuntu.com/questions/1242731/ubuntu-20-04-multipath-configuration
 +  * 在 VMWare 內建立 Ubuntu 20.04 的 VM , 在 /var/log/syslog 會看到以下的異常訊息<cli>
 +~# 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
 +</cli>
 +  * 解決方式 : <cli>
 +vi /etc/multipath.conf
 +</cli><cli>
 +defaults {
 +    user_friendly_names yes
 +}
 +blacklist {
 +    devnode "^(ram|raw|loop|fd|md|dm-|sr|scd|st|sda)[0-9]*"
 +}
 +</cli><cli>
 +systemctl restart multipath-tools
 +</cli>
 +
 +===== 安裝呈現即時網路連線流量工具 =====
 +  * 參考 - https://askubuntu.com/questions/257263/how-to-display-network-traffic-in-the-terminal
 +  * 直接安裝 [[https://packages.ubuntu.com/jammy/net/bmon|bmon]], [[https://packages.ubuntu.com/jammy/slurm|slurm]], [[https://packages.ubuntu.com/jammy/tcptrack|tcptrack]] 其中一套或都安裝
 +  * 安裝語法 <cli>
 +sudo apt install bmon slurm tcptrack
 +</cli>
  
 {{tag>ubuntu}} {{tag>ubuntu}}
  
  • tech/ubuntu18.1611709718.txt.gz
  • 上一次變更: 2021/01/27 09:08
  • jonathan