安装完成后的基本配置
1 - timeshift
备注:安装完成之后,第一时间安装 timeshift 进行备份,后续操作中出现任何失误都可以通过 timeshift 来选择性的恢复到中间状态,避免出错后需要重新安装。
具体操作参考:
https://skyao.io/learning-ubuntu-server/docs/installation/timeshift/
安装
先 su 到 root,再进行安装:
su root
apt install timeshift
配置
找到 timeshift 分区的 UUID:
lsblk -f
例如这个机器有三块硬盘, /var/timeshift
所在的分区 UUDI 为 3c5ad47e-4318-4797-8342-7e602ac524d2
:
$ lsblk -f
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
nvme1n1
`-nvme1n1p1 ext4 1.0 ccae6bf3-d4cd-422d-b67a-b5b8dfe83fc6 782.2G 0% /var/data2
nvme0n1
`-nvme0n1p1 ext4 1.0 eff3a45e-be5e-4f5e-a969-0998a8a10e33 782.2G 0% /var/data
nvme2n1
|-nvme2n1p1 vfat FAT32 C4B5-2470 505.1M 1% /boot/efi
|-nvme2n1p2 ext4 1.0 41949492-a351-4770-80f6-d4c7dc5b23bc 171.2G 1% /
`-nvme2n1p3 ext4 1.0 3c5ad47e-4318-4797-8342-7e602ac524d2 48G 0% /var/timeshift
然后设置 backup_device_uuid ,注意 timeshift 在第一次使用时会读取 default.json 文件:
vi /etc/timeshift/default.json
验证一下:
timeshift --list
这个时候还没有进行备份,没有 snapshot:
timeshift --list
First run mode (config file not found)
Selected default snapshot type: RSYNC
Mounted '/dev/nvme2n1p3' at '/run/timeshift/3424/backup'
Device : /dev/nvme2n1p3
UUID : 3c5ad47e-4318-4797-8342-7e602ac524d2
Path : /run/timeshift/3424/backup
Mode : RSYNC
Status : No snapshots on this device
First snapshot requires: 0 B
No snapshots found
此时会自动创建配置文件 /etc/timeshift/timeshift.json
,后续修改配置就要修改这个文件。
配置 excludes
除了基本的 backup_device_uuid 外,还需要配置 excludes 以排除不需要 timeshift 进行备份的内容。
{
"backup_device_uuid" : "3c5ad47e-4318-4797-8342-7e602ac524d2",
......
"exclude" : [
"/root/**",
"/home/**",
"/timeshift/**",
"/var/data/**",
"/var/data2/**",
"/var/data3/**"
],
......
}
需要排除的内容通常包括用户目录(/root/
和 /home/
),以及资料存储如我这里的 "/var/data/
等几块用来存储的硬盘,以及 timeshift 自身所在目录 /timeshift/
(取决于安装debian时选择的timeshift分区的挂载路径)。
配置自动备份
设置每天/每周/每月的自动备份:
{
......
"schedule_monthly" : "true",
"schedule_weekly" : "true",
"schedule_daily" : "true",
......
"count_monthly" : "2",
"count_weekly" : "3",
"count_daily" : "5",
......
}
创建快照
先不做任何操作,在操作系统安装完成之后,第一时间进行备份:
timeshift --create --comments "first backup after install"
第一次备份大概要消耗2.3g的存储空间。
2 - path修改
问题描述
debian 12 默认的 PATH 路径有点少:
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/games
很多常见的命令都会因为不包含在 PATH 中而无法使用,报错 “command not found”:
$ usermod -aG sudo sky
bash: usermod: command not found
打开 /etc/profile
文件看到:
if [ "$(id -u)" -eq 0 ]; then
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
fi
export PATH
看上去像是没有自动 source /etc/profile
,比如我用 su 到 root 账号后执行 source,那就正常的得到上面的 PATH:
$ su root
Password:
$ id
uid=0(root) gid=0(root) groups=0(root)
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/games
$ source /etc/profile
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
普通账号的修复
对于普通账号,比如我安装时建立的 sky 账号,只要简单在 .zshrc 中加入:
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
export PATH=$HOME/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
重新登录 sky 账号,验证即可:
$ echo $PATH
/home/sky/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
这个需要先安装 zsh 和 oh-my-zsh,bash 应该类似,只是我目前基本只用 zsh。
root 账号的修复
貌似没有找到解决不自动 source /etc/profile
的办法,所以只能手工执行
source /etc/profile
来解决。或者,类似 sky 账号那样,安装 zsh 和 oh-my-zsh,但发现 root 账号不能改成默认使用 zsh,只能在 su 到 root 账号之后,手工执行 zsh
来从 bash 换到 zsh。
3 - sudo设置
安装
先 su 到 root 账号,安装 sudo:
apt install sudo
问题
安装时默认的 sky 账号是没有 sudo 权限的:
$ id
uid=1000(sky) gid=1000(sky) groups=1000(sky),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),100(users),106(netdev)
$ sudo ls
[sudo] password for sky:
sky is not in the sudoers file.
解决方案
先 su 为 root,然后为 sky 账号加入 sudo:
# 如果没有修复 path 的问题,则会报错找不到 usermod
# export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
usermod -aG sudo sky
退出 sky 账号,再次登录就可以 sudo 了:
$ ls
[sudo] password for sky:
bin debian12 temp work
$ id
uid=1000(sky) gid=1000(sky) groups=1000(sky),24(cdrom),25(floppy),27(sudo),29(audio),30(dip),44(video),46(plugdev),100(users),106(netdev)
4 - git
直接 apt 安装:
apt install git
检查版本:
$ git version
git version 2.39.5
配置代理
mkdir -p ~/.ssh/
vi ~/.ssh/config
增加内容为:
# for github
Host github.com
HostName github.com
User git
# for HTTP proxy
#ProxyCommand socat - PROXY:192.168.0.1:%h:%p,proxyport=7890
#ProxyCommand socat - PROXY:192.168.2.1:%h:%p,proxyport=7890
#ProxyCommand socat - PROXY:192.168.3.1:%h:%p,proxyport=7890
#ProxyCommand socat - PROXY:192.168.5.1:%h:%p,proxyport=7890
# for socks5 proxy
#ProxyCommand nc -v -x 192.168.0.1:7891 %h %p
#ProxyCommand nc -v -x 192.168.2.1:7891 %h %p
#ProxyCommand nc -v -x 192.168.3.1:7891 %h %p
#ProxyCommand nc -v -x 192.168.5.1:7891 %h %p
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_github
其他设置参考: https://skyao.io/learning-git/docs/installation/initial/
5 - zsh
安装配置 zsh
安装zsh
首先安装 zsh:
sudo apt install zsh zsh-doc
安装 Oh my zsh!
在 zsh 终端执行:
# 如果被墙则增加代理设置
# export all_proxy=socks5://192.168.2.1:7891
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
DNS 污染问题:
如果遇到 DNS 污染,导致 raw.githubusercontent.com 被解析到 127.0.0.1 或者 0.0.0.1 导致无法访问。需要修改 hosts 文件:
sudo vi /etc/hosts
增加一行:
199.232.68.133 raw.githubusercontent.com
中途询问是否把zsh作为默认 shell 时选择Y:
Do you want to change your default shell to zsh? [Y/n] Y
Changing the shell...
安装字体和主题
在这里下载并安装几个字体
https://github.com/romkatv/powerlevel10k#meslo-nerd-font-patched-for-powerlevel10k
- MesloLGS NF Regular.ttf
- MesloLGS NF Bold.ttf
- MesloLGS NF Italic.ttf
- MesloLGS NF Bold Italic.ttf
mkdir -p ~/.fonts
wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Regular.ttf -O ~/.fonts/MesloLGS_NF_Regular.ttf
wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold.ttf -O ~/.fonts/MesloLGS_NF_Bold.ttf
wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Italic.ttf -O ~/.fonts/MesloLGS_NF_Italic.ttf
wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold%20Italic.ttf -O ~/.fonts/MesloLGS_NF_Bold_Italic.ttf
执行
$ ls ~/.fonts
可以看到下载好的字体文件:
MesloLGS_NF_Bold_Italic.ttf MesloLGS_NF_Bold.ttf MesloLGS_NF_Italic.ttf MesloLGS_NF_Regular.ttf
执行
fc-cache -f -v
可以看到字体缓存成功:
Font directories:
/root/.local/share/fonts
/usr/local/share/fonts
/usr/share/fonts
/root/.fonts
......
/root/.fonts: caching, new cache contents: 4 fonts, 0 dirs
......
fc-cache: succeeded
下载安装 Powerlevel10k 主题:
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
修改
vi ~/.zshrc
增加内容:
ZSH_THEME="powerlevel10k/powerlevel10k"
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(history)
POWERLEVEL9K_SHORTEN_DIR_LENGTH=1
# User configuration
export LS_COLORS="rs=0:no=00:mi=00:mh=00:ln=01;36:or=01;31:di=01;34:ow=04;01;34:st=34:tw=04;34:pi=01;33:so=01;33:do=01;33:bd=01;33:cd=01;33:su=01;35:sg=01;35:ca=01;35:ex=01;32:"
安装插件
安装 wd 插件:
sh -c "$(curl -fsSL https://github.com/mfaerevaag/wd/raw/master/install.sh)"
配置以下插件:
git clone https://github.com/zsh-users/zsh-autosuggestions.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-history-substring-search.git $ZSH_CUSTOM/plugins/history-substring-search
git clone https://github.com/Pilaton/OhMyZsh-full-autoupdate.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/ohmyzsh-full-autoupdate
修改 zsh 配置
vi ~/.zshrc
注释掉这一行:
DISABLE_MAGIC_FUNCTIONS="true"
修改 plugins 为
plugins=(
git
golang
rust
docker
docker-compose
kubectl
npm
node
mvn
sudo
helm
redis-cli
wd
zsh-autosuggestions
zsh-syntax-highlighting
history-substring-search
ohmyzsh-full-autoupdate
)
# User configuration
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern cursor root line)
ZSH_HIGHLIGHT_PATTERNS=('rm -rf *' 'fg=white,bold,bg=red')
重启 zsh。
Updating plugins and themes Oh My ZSH
--------------------------------------
Updating Plugin — ohmyzsh-full-autoupdate -> https://github.com/Pilaton/OhMyZsh-full-autoupdate
Already up to date.
Updating Plugin — zsh-autosuggestions -> https://github.com/zsh-users/zsh-autosuggestions
Already up to date.
Updating Plugin — zsh-syntax-highlighting -> https://github.com/zsh-users/zsh-syntax-highlighting
Already up to date.
Updating Theme — powerlevel10k -> https://github.com/romkatv/powerlevel10k
Already up to date.
备注: 这个自动更新可能会因为 github.com 被墙无法访问而失败。可以修改 .zshrc 的设置,默认开启代理避免更新时被墙:
# auto start proxy on
export all_proxy=socks5://192.168.2.1:7891;export http_proxy=http://192.168.2.1:7890;export https_proxy=http://192.168.2.1:7890;export no_proxy=127.0.0.1,localhost,local,.local,.lan,192.168.0.0/16,10.0.0.0/16
然后手工更新 ohmyzsh:
# proxyon
omz update
执行完 ohmyzsh 的更新之后,关闭所有的终端,再重新打开,就会触发 zsh plugins 的自动更新。
配置网络代理
修改 zsh 配置
vi ~/.zshrc
增加以下内容:
# set proxy for different locations
alias proxyon-nansha='export all_proxy=socks5://192.168.0.1:7891;export http_proxy=http://192.168.0.1:7890;export https_proxy=http://192.168.0.1:7890;export no_proxy=127.0.0.1,localhost,local,.local,.lan,192.168.0.0/16,10.0.0.0/16'
alias proxyon-tianhe='export all_proxy=socks5://192.168.2.1:7891;export http_proxy=http://192.168.2.1:7890;export https_proxy=http://192.168.2.1:7890;export no_proxy=127.0.0.1,localhost,local,.local,.lan,192.168.0.0/16,10.0.0.0/16'
alias proxyon-fenghu='export all_proxy=socks5://192.168.3.1:7891;export http_proxy=http://192.168.3.1:7890;export https_proxy=http://192.168.3.1:7890;export no_proxy=127.0.0.1,localhost,local,.local,.lan,192.168.0.0/16,10.0.0.0/16'
alias proxyon-local='export all_proxy=socks5://127.0.0.1:7897;export http_proxy=http://127.0.0.1:7897;export https_proxy=http://127.0.0.1:7897;export no_proxy=127.0.0.1,localhost,local,.local,.lan,192.168.0.0/16,10.0.0.0/16'
# set default proxy by this line
alias proxyon='proxyon-local'
alias proxyoff='unset all_proxy http_proxy https_proxy no_proxy'
# uncomment next line to enable proxy by default when zsh is opened
# proxyon
6 - 网络代理
设置网络代理
我通常在 openwrt 上安装 openclash,支持 socks5 和 http 代理,因此设置很简单:
vi ~/.zshrc
加入以下内容:
# set proxy for different locations
alias proxyon-nansha='export all_proxy=socks5://192.168.0.1:7891;export http_proxy=http://192.168.0.1:7890;export https_proxy=http://192.168.0.1:7890;export no_proxy=127.0.0.1,localhost,local,.local,.lan,192.168.0.0/16,10.0.0.0/16'
alias proxyon-tianhe='export all_proxy=socks5://192.168.2.1:7891;export http_proxy=http://192.168.2.1:7890;export https_proxy=http://192.168.2.1:7890;export no_proxy=127.0.0.1,localhost,local,.local,.lan,192.168.0.0/16,10.0.0.0/16'
alias proxyon-shanghai='export all_proxy=socks5://192.168.3.1:7891;export http_proxy=http://192.168.3.1:7890;export https_proxy=http://192.168.3.1:7890;export no_proxy=127.0.0.1,localhost,local,.local,.lan,192.168.0.0/16,10.0.0.0/16'
alias proxyon-cudy='export all_proxy=socks5://192.168.5.1:7891;export http_proxy=http://192.168.5.1:7890;export https_proxy=http://192.168.5.1:7890;export no_proxy=127.0.0.1,localhost,local,.local,.lan,192.168.0.0/16,10.0.0.0/16'
# set default proxy by this line
alias proxyon='proxyon-nansha'
alias proxyoff='unset all_proxy http_proxy https_proxy no_proxy'
# uncomment next line to enable proxy by default when zsh is opened
# proxyon
开启网络代理
需要开启代理时,输入 proxyon 命令就设置好代理了。不使用时 proxyoff 关闭。
7 - 安装其他软件
安装操作系统相关的软件
sudo apt install dkms
这个过程中会自动安装 linux-headers 。
常用工具软件
sudo apt install htop unzip zip curl
网络速度测试软件:
sudo apt install iperf iperf3
修复 locale 报错
默认安装之后经常在执行各种命令时看到如下的警告:
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_CTYPE = "UTF-8",
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
可以通过执行 locale
命令来重现这个警告:
解决方案,
vi ~/.zshrc
增加内容:
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
执行
source ~/.zshrc
验证结果。
参考: