Ubuntu
跳至導覽
跳至搜尋
Ubuntu是一種Linux作業系統。
移除
目前社群的建議都是先移除掉Snap:
sudo apt purge -y snapd; sudo apt autoremove --purge -y; sudo apt clean
並且移除掉Ubuntu Pro的廣告:
sudo systemctl disable apt-news.service; sudo systemctl disable esm-cache.service; sudo mv /etc/apt/apt.conf.d/20apt-esm-hook.conf /etc/apt/apt.conf.d/20apt-esm-hook.conf.bak
安裝
apt
先更新系統的套件庫以及系統:
sudo apt update; sudo apt upgrade -y
這邊列出常用的套件:
sudo apt install -y apache2-utils apt-transport-https aptitude bash-completion bpfcc-tools build-essential curl dnsutils dstat git jc jq locales moreutils most mtr-tiny net-tools netcat-openbsd p7zip-full pigz prometheus-node-exporter rsync sharutils software-properties-common sysstat telnet ubuntu-minimal unrar unzip vim-nox vim-scripts wget zstd; sudo apt clean
另外建議每台機器都把除錯用的套件裝起來,遇到狀況時可以馬上處理[1]:
sudo apt install -y bpfcc-tools bpftrace cpuid ethtool gdb iproute2 linux-tools-common msr-tools nicstat numactl procps sysstat tcpdump tiptop trace-cmd util-linux; sudo apt clean
在Ubuntu 24.04上面沒有cpuid與msr-tools,所以變成:
sudo apt install -y bpfcc-tools bpftrace ethtool gdb iproute2 linux-tools-common nicstat numactl procps sysstat tcpdump tiptop trace-cmd util-linux; sudo apt clean
跳板機會多裝這些:
sudo apt install -y byobu keychain mosh zsh zsh-syntax-highlighting; sudo apt clean
開發機可以裝這些,要注意這邊裝的是系統的版本,可能會偏舊:
sudo apt install -y build-essential bison byobu cmake cvs debhelper default-jdk devscripts git-flow golang mercurial nasm python3-minimal subversion tig; sudo apt clean
設定
有些機器沒有對應的locale,可以讓系統產生:
sudo locale-gen en_US.UTF-8 zh_TW.UTF-8
在VPS或是雲端上的機器通常會利用swapfile增加一些記憶體使用空間:
sudo fallocate -l 512M /swapfile; sudo chmod 600 /swapfile; sudo mkswap /swapfile; sudo swapon /swapfile; echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
但還是要避免使用到Swap:
echo "vm.swappiness=1" | sudo tee /etc/sysctl.d/99-vm.conf; sudo sysctl -p /etc/sysctl.d/99-vm.conf
然後設定TCP BBR,需要Linux Kernel 4.9+(如果是Ubuntu 16.04,預設是4.4,會需要安裝linux-image-generic-hwe-16.04
):
echo -e "net.core.default_qdisc=fq\nnet.ipv4.tcp_congestion_control=bbr" | sudo tee /etc/sysctl.d/99-tcp.conf; sudo sysctl -p /etc/sysctl.d/99-tcp.conf
如果無法使用TCP BBR,可以改用Westwood:
echo -e "net.ipv4.tcp_congestion_control=westwood" | sudo tee /etc/sysctl.d/99-tcp.conf; sudo sysctl -p /etc/sysctl.d/99-tcp.conf
Vim打開secure-modelines:
echo -e "set runtimepath+=/usr/share/vim/vimfiles/pack/dist-bundle/opt/secure-modelines\npackadd! secure-modelines" | sudo tee /etc/vim/vimrc.local
使用者
這邊是增加我自己的帳號(以及Sudo權限),然後設定密碼:
echo "gslin ALL = (ALL:ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/gslin; sudo useradd -g staff -G adm,sudo -m -s /bin/bash gslin; sudo passwd gslin
總結
一般性的快速安裝:
sudo fallocate -l 512M /swapfile; sudo chmod 600 /swapfile; sudo mkswap /swapfile; sudo swapon /swapfile; echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab; echo "vm.swappiness=1" | sudo tee /etc/sysctl.d/99-vm.conf; sudo sysctl -p /etc/sysctl.d/99-vm.conf; echo -e "net.core.default_qdisc=fq\nnet.ipv4.tcp_congestion_control=bbr" | sudo tee /etc/sysctl.d/99-tcp.conf; sudo sysctl -p /etc/sysctl.d/99-tcp.conf; sudo apt purge -y snapd; sudo systemctl disable apt-news.service; sudo systemctl disable esm-cache.service; sudo mv /etc/apt/apt.conf.d/20apt-esm-hook.conf /etc/apt/apt.conf.d/20apt-esm-hook.conf.bak; sudo apt update; sudo apt dist-upgrade -y; sudo apt install -y apache2-utils apt-transport-https aptitude bash-completion bpfcc-tools bpfcc-tools bpftrace build-essential cpuid curl dnsutils dstat ethtool gdb git iproute2 jc jq linux-tools-common locales moreutils most msr-tools mtr-tiny net-tools netcat-openbsd nicstat numactl p7zip-full pigz procps prometheus-node-exporter rsync sharutils software-properties-common sysstat sysstat tcpdump telnet tig tiptop trace-cmd ubuntu-minimal unrar unzip util-linux vim-nox vim-scripts wget zstd; sudo apt autoremove --purge -y; sudo apt clean; sudo locale-gen en_US.UTF-8 zh_TW.UTF-8; echo -e "set runtimepath+=/usr/share/vim/vimfiles/pack/dist-bundle/opt/secure-modelines\npackadd! secure-modelines" | sudo tee /etc/vim/vimrc.local
Ubuntu 24.04上面沒有cpuid與msr-tools,所以變成:
sudo fallocate -l 512M /swapfile; sudo chmod 600 /swapfile; sudo mkswap /swapfile; sudo swapon /swapfile; echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab; echo "vm.swappiness=1" | sudo tee /etc/sysctl.d/99-vm.conf; sudo sysctl -p /etc/sysctl.d/99-vm.conf; echo -e "net.core.default_qdisc=fq\nnet.ipv4.tcp_congestion_control=bbr" | sudo tee /etc/sysctl.d/99-tcp.conf; sudo sysctl -p /etc/sysctl.d/99-tcp.conf; sudo apt purge -y snapd; sudo systemctl disable apt-news.service; sudo systemctl disable esm-cache.service; sudo mv /etc/apt/apt.conf.d/20apt-esm-hook.conf /etc/apt/apt.conf.d/20apt-esm-hook.conf.bak; sudo apt update; sudo apt dist-upgrade -y; sudo apt install -y apache2-utils apt-transport-https aptitude bash-completion bpfcc-tools bpfcc-tools bpftrace build-essential curl dnsutils dstat ethtool gdb git iproute2 jc jq linux-tools-common locales moreutils most mtr-tiny net-tools netcat-openbsd nicstat numactl p7zip-full pigz procps prometheus-node-exporter rsync sharutils software-properties-common sysstat sysstat tcpdump telnet tig tiptop trace-cmd ubuntu-minimal unrar unzip util-linux vim-nox vim-scripts wget zstd; sudo apt autoremove --purge -y; sudo apt clean; sudo locale-gen en_US.UTF-8 zh_TW.UTF-8; echo -e "set runtimepath+=/usr/share/vim/vimfiles/pack/dist-bundle/opt/secure-modelines\npackadd! secure-modelines" | sudo tee /etc/vim/vimrc.local
伺服器的部分可以停掉自動更新:
sudo apt purge -y unattended-upgrades; sudo systemctl disable apt-daily.timer; sudo systemctl disable --now packagekit.service
參考文獻
- ↑ Brendan Gregg 推薦平常在 Linux 上先裝好的工具. 2024-03-25 [2024-03-25] (中文(臺灣)).
外部連結
- 官方網站 (英文)