顯示頁面舊版反向連結Fold/unfold all回到頁頂 本頁是唯讀的,您可以看到原始碼,但不能更動它。您如果覺得它不應被鎖上,請詢問管理員。 ====== 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 設定 ===== * 參考 - https://www.opencli.com/linux/ubuntu-18-04-netplan-setup-static-ip - https://blog.toright.com/posts/6293/ubuntu-18-04-%E9%80%8F%E9%81%8E-netplan-%E8%A8%AD%E5%AE%9A%E7%B6%B2%E8%B7%AF%E5%8D%A1-ip.html - https://askubuntu.com/questions/1042582/how-to-set-default-route-with-netplan-ubuntu-18-04-server-2-nic * Exp. 更改 IP 設定為 192.168.11.204 <code sh>sudo vi /etc/netplan/00-installer-config.yaml</code><file> network: ethernets: ens18: addresses: [192.168.11.204/24] gateway4: 192.168.11.1 nameservers: addresses: [8.8.8.8,8.8.4.4] dhcp4: no version: 2 </file> * Exp. 兩張網卡指定 default route 為 eth0 <code sh>sudo vi /etc/netplan/00-installer-config.yaml</code><file> network: ethernets: eth0: dhcp4: true eth1: addresses: [192.168.7.101/24] routes: - to: 192.168.7.0/24 via: 192.168.7.1 metric: 40 table: 200 nameservers: addresses: [8.8.8.8,168.95.192.1] dhcp4: no version: 2 </file><cli> localadmin@iiidevops-1:~$ ip route default via 172.17.13.177 dev eth0 proto dhcp src 172.17.13.189 metric 100 172.17.13.176/28 dev eth0 proto kernel scope link src 172.17.13.189 172.17.13.177 dev eth0 proto dhcp scope link src 172.17.13.189 metric 100 192.168.7.0/24 dev eth1 proto kernel scope link src 192.168.7.101 </cli> * 可以透過 sudo netplan apply 立即生效或是 sudo reboot 重新開機後生效 ===== 設定 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 * 先 /etc/cloud/cloud.cfg 內 preserve_hostname 為 true<code sh>sudo vi /etc/cloud/cloud.cfg</code><file> : preserve_hostname: true : </file> * 執行 hostnamectl 設定 hostname Exp. 更改為 pve-devops1<code sh> sudo hostnamectl set-hostname pve-devops1 </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/ * Exp. 建立 localadmin <cli> sudo useradd -s /bin/bash -d /home/localadmin/ -m -G sudo 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> * 參考網址 - * 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}} tech/ubuntu18.txt 上一次變更: 2025/02/05 11:07由 jonathan