====== 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
===== 網路 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 sudo vi /etc/netplan/00-installer-config.yaml
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
* Exp. 兩張網卡指定 default route 為 eth0 sudo vi /etc/netplan/00-installer-config.yaml
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
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
* 可以透過 sudo netplan apply 立即生效或是 sudo reboot 重新開機後生效
===== 設定 ufw 主機防火牆 =====
* 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
* ++看執行結果|
~# 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
++
===== 修改 iptables 規則, 重開機仍能自動生效 =====
* 參考 - https://askubuntu.com/questions/1452706/problem-with-my-iptables-configuration-on-reboot/1452833#1452833
* 需要安裝 iptables-persistent 套件
apt install iptables-persistent -y
* 修改 iptables 規則 Exp.
iptables -I FORWARD -i br0 -p all -j ACCEPT
* 將修改後的規則寫入 /etc/iptables/rules.v4
iptables-save -c > /etc/iptables/rules.v4
===== 更改 hostname (一) =====
* 參考 - https://www.itread01.com/content/1541622152.html
* 先 /etc/cloud/cloud.cfg 內 preserve_hostname 為 truesudo vi /etc/cloud/cloud.cfg
:
preserve_hostname: true
:
* 執行 hostnamectl 設定 hostname Exp. 更改為 pve-devops1
sudo hostnamectl set-hostname pve-devops1
===== 更改 hostname (二) =====
* Exp. 設定 hostname 為 iServStorM1
sudo su -
vi /etc/hosts
127.0.0.1 localhost
127.0.1.1 iServStorM1
:
vi /etc/hostname
iServStorM1
hostname -F /etc/hostname
* 參考網址 -
* 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
sudo useradd -s /bin/bash -d /home/localadmin/ -m -G sudo localadmin
sudo passwd localadmin
* 如果useradd 建立時沒提供 sudo 權限可以之後透過 usermod 來處理 Exp.
sudo usermod -aG sudo localadmin
===== 查詢安裝套件檔案路徑 =====
* 參考網址 - https://www.ubuntu-tw.org/modules/newbb/viewtopic.php?post_id=81494
* 語法 : dpkg -L 套件名稱 Exp. docker
/# 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
===== Server 版安裝圖形操作介面 =====
*
sudo apt-get install --no-install-recommends ubuntu-desktop
* 參考網址 -
* 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/
* 查看目前已使用空間
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
清理現有的大型 journal 檔案
sudo journalctl --vacuum-size=500M
===== VMWare 內出現的 multipathd 異常訊息 =====
* 參考 - https://askubuntu.com/questions/1242731/ubuntu-20-04-multipath-configuration
* 在 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
===== 安裝呈現即時網路連線流量工具 =====
* 參考 - 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]] 其中一套或都安裝
* 安裝語法
sudo apt install bmon slurm tcptrack
{{tag>ubuntu}}