差異處

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

連向這個比對檢視

下次修改
前次修改
tech:ubuntu18 [2020/09/04 11:23] – 建立 jonathan_tsaitech:ubuntu18 [2023/10/22 22:31] (目前版本) – [修改 iptables 規則, 重開機仍能自動生效] jonathan
行 1: 行 1:
 +====== Ubuntu 18/20 相關設定整理 ======
 +===== 網路 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 重新開機後生效
 +
 +===== 修改 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>
 +
 +===== 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>
 +
 +{{tag>ubuntu}}