Debian 11 配置优化指南
阅读原文时间:2022年03月04日阅读:2

原文地址: Debian 11 配置优化指南 - WindSpiritIT

本文仅适用于配置 Debian 11 Bullseye

文中同时包含 Gnome 桌面和 KDE 桌面配置,其中大部分相同,不同之处分别列出

Gnome 桌面相关配置更新滞后,可能不再更新

KDE 及 Gnome 优化配置部分请根据个人喜好自行配置

文中使用 debianuser 代替用户名,执行命令或复制配置时请注意替换

文中涉及的带版本号的软件包/环境,版本号使用 xxx 代替,请根据实际情况安装最新版本或自己需要的版本

本文编辑整理时间距离实践时间相隔过长,编辑过程中可能出现不准确内容,如果在您的时间过程中发现与本文不符的情况,请尽量在评论区留言,我将尽快确认更新

该步骤中大部分操作需要重启,所以不要根据配置完成后应用是否能正常使用来判断配置应用情况

在该步骤末尾会重启一次应用所有配置

使用英文重命名 /home 目录下文件夹

cd ~
mkdir Desktop Download Templates Public Documents Music Pictures Videos
rm -rf 公共 模板 视频 图片 文档 下载 音乐 桌面
xdg-user-dirs-update --set DESKTOP ~/Desktop
xdg-user-dirs-update --set DOWNLOAD ~/Download
xdg-user-dirs-update --set TEMPLATES ~/Templates
xdg-user-dirs-update --set PUBLICSHARE ~/Public
xdg-user-dirs-update --set DOCUMENTS ~/Documents
xdg-user-dirs-update --set MUSIC ~/Music
xdg-user-dirs-update --set PICTURES ~/Pictures
xdg-user-dirs-update --set VIDEOS ~/Videos

将用户添加到 sudoers 中

该步骤需要先切换到 root 身份,有两个方案

  1. 切换到新的 tty

    Ctrl + Alt + F3 切换到纯命令行界面的新终端,并以 root 身份登录进行操作

    结束后使用 exit 退出终端,按 Ctrl + Alt + F1/F2 切换回用户身份图形界面

  2. 通过 SSH

    ssh root@localhost

    结束后使用 exit 退出终端

以下命令在 root 身份下执行

chmod +w /etc/sudoers
cat >> /etc/sudoers << EOF
debianuser ALL=(ALL:ALL) ALL
EOF
chmod -w /etc/sudoers
exit

以上命令在 root 身份下执行

更换软件源

sudo tee /etc/apt/sources.list <<-'EOF'
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free

deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
EOF
sudo apt update
sudo apt upgrade
sudo apt dist-upgrade

配置基础软件包

sudo apt install vim wget curl htop git proxychains4 screenfetch tmux bash-completion fcitx5-rime chromium fcitx5-material-color zsh fonts-powerline fzf net-tools openssh-server firewalld bat chromium

安装的软件包

包名

用途

vim

终端文本编辑器

wget

终端文件下载工具

curl

终端 URL 工具

htop

系统监控与进程管理工具

git

版本控制工具

proxychains4

终端代理

screenfetch

在终端显示系统信息

tmux

终端复用器

bash-completion

bash 自动补全

fcitx5-rime

基于 fcitx5 的 rime 输入法

fcitx5-material-color

fcitx5 主题

chromium

Chromium 浏览器

zsh

终端解释器

fonts-powerline

powerline 字体

fzf

终端模糊搜索工具

net-tools

网络配置工具

openssh-server

OpenSSH 服务器

firewalld

防火墙

bat

更强大的 cat 命令

卸载无用软件包

主要卸载一些多语言支持和游戏包,可跳过

KDE

sudo apt remove --purge ibus* xterm goldendict fcitx fcitx-* anthy anthy-* mozc-* mlterm* xiterm+thai mariadb-common
sudo apt autoremove --purge

Gnome

注意:执行时请注意要卸载的软件包中是否存在类似 gnome 之类的系统包,如果存在请尝试手动一个一个卸载

sudo apt remove --purge ibus ibus-* xterm goldendict aisleriot evolution gnome-todo gnome-klotski gnome-tetravex gnome-chess gnome-maps gnome-mines gnome-taquin gnome-sudoku gnome-robots gnome-nibbles gnome-music gnome-mahjongg gnome-2048 hitori transmission-* quadrapassel lightsoff four-in-a-row tali swell-foop five-or-more iagno fcitx fcitx-* anthy anthy-* mozc-* mlterm mlterm-* xiterm+thai
sudo apt autoremove --purge

无线网卡驱动

如果你的电脑存在无线网卡,并且在安装好操作系统之后发现无线网卡无法使用,请尝试如下步骤

sudo apt install firmware-iwlwifi
sudo modprobe -r iwlwifi
sudo modprobe iwlwifi

Nvidia 显卡驱动

如果你的电脑存在 Nvidia 显卡,并且在安装好操作系统之后发现显卡无法使用,请尝试如下步骤

sudo apt install nvidia-detect
sudo nvidia-detect

该步骤会根据硬件检测应该安装哪些驱动,请按照输出安装对应的驱动,例如提示 nvidia-driver

sudo apt install nvidia-driver

tmux 快捷键

sudo tee /etc/tmux.conf <<-'EOF'
set -g prefix C-a
unbind C-b
bind C-a send-prefix
EOF

安装 Clash for Windows

GitHub - Fndroid/clash_for_windows_pkg 下载 CFW,注意下载 Clash.for.Windows-x.xx.x-x64-linux.tar.gz

将其解压到 /usr/local/cfw

tar zxvf Clash.for.Windows-0.19.5-x64-linux.tar.gz -C cfw --strip-components 1

创建 ~/.local/share/applications/cfw.desktop 用于显示桌面图标

touch ~/.local/share/applications/cfw.desktop
tee ~/.local/share/applications/cfw.desktop <<-'EOF'
[Desktop Entry]
Version=1.0
Name=Clash For Windows
GenericName=Clash For Windows
Comment=Clash For Windows for Linux
Exec=/usr/local/cfw/cfw
Terminal=false
Type=Application
Icon=clash
Categories=Network
EOF

配置 Advanced Copy

仓库位于 GitHub - jarun/advcpmv,无需手动下载

wget http://ftp.gnu.org/gnu/coreutils/coreutils-9.0.tar.xz
tar Jxvf coreutils-9.0.tar.xz
cd coreutils-9.0/
wget https://raw.githubusercontent.com/jarun/advcpmv/master/advcpmv-0.9-9.0.patch
patch -p1 -i advcpmv-0.9-9.0.patch
./configure
make
sudo chmod +x ./src/cp ./src/mv
sudo chown root. ./src/cp ./src/mv
sudo mv ./src/cp /usr/local/bin/cpg
sudo mv ./src/mv /usr/local/bin/mvg

配置 ZSH

切换到 zsh

chsh -s /bin/zsh
sudo ln -s ~/.zshrc /root

完成以上步骤后切换到 root 用户将自动为其配置 zsh, zinit 及 .zshrc 中配置的插件

重启

sudo reboot

下载 Google Chrome

下载 Microsoft Visual Studio Code

下载 JetBrains Toolbox App

下载 Go for Linux

下载 Nodejs LTS

sudo apt install ./google-chrome-stable_current_amd64.deb
sudo apt install ./code_xxx_amd64.deb
sudo apt remove --purge 'firefox-esr*'

JetBrains Toolbox

用于管理 JetBrains IDE

建议将 IDE 安装路径配置为 /usr/local/JetBrains

tar zxvf jetbrains-toolbox-xxx.tar.gz
./jetbrains-toolbox-xxx/jetbrains-toolbox

下载 GitHub - ja-netfilter/ja-netfilter,解压到 /usr/local/JetBrains/ja-netfilter

修改 config 中配置如下

[DNS]
EQUAL,jetbrains.com
[URL]
PREFIX,https://account.jetbrains.com/lservice/rpc/validateKey.action
[Result]
EQUAL,120506319308405029943033101198259523557651500267734599270782782071425072541184605728867830395125412768750966448411447392137801711908001958831204692561738046570955709184538088569271703484602917023462976408329100293802371486063140115775311907530943821345005598057265747678100463689973450156515895355214983079672467769169324175533323801179755544364921063654340185317077965735659865485150734884110709760680757502730007505995422237875348017761382234951127263548660889969621730944377739766734765769747684457663965611896398862841334032542726392699785677440644859509166466497325071885386505404431787167239320957696896447925472784312642576835792921100239616617639216190447230487878404191838684279341834945197861631446454083984351911070798505031973496634229907567362853550735007045265430703581336189733180744888091740381912913980707537008943084904260746266383019688346709856215660232636334604552145129775009725685598798774376749830567219982166661918408832945395290223853748014160473876195098438959881711585152480525870219408398012002829112863175041709512032251930709608035158747101960447898838942705485214217426612863919268749874079707310181890737049603255938886865558759802593500502795018952114650332765839003032013708006750600413455628536259,65537,860106576952879101192782278876319243486072481962999610484027161162448933268423045647258145695082284265933019120714643752088997312766689988016808929265129401027490891810902278465065056686129972085119605237470899952751915070244375173428976413406363879128531449407795115913715863867259163957682164040613505040314747660800424242248055421184038777878268502955477482203711835548014501087778959157112423823275878824729132393281517778742463067583320091009916141454657614089600126948087954465055321987012989937065785013284988096504657892738536613208311013047138019418152103262155848541574327484510025594166239784429845180875774012229784878903603491426732347994359380330103328705981064044872334790365894924494923595382470094461546336020961505275530597716457288511366082299255537762891238136381924520749228412559219346777184174219999640906007205260040707839706131662149325151230558316068068139406816080119906833578907759960298749494098180107991752250725928647349597506532778539709852254478061194098069801549845163358315116260915270480057699929968468068015735162890213859113563672040630687357054902747438421559817252127187138838514773245413540030800888215961904267348727206110582505606182944023582459006406137831940959195566364811905585377246353->31872219281407242025505148642475109331663948030010491344733687844358944945421064967310388547820970408352359213697487269225694990179009814674781374751323403257628081559561462351695605167675284372388551941279783515209238245831229026662363729380633136520288327292047232179909791526492877475417113579821717193807584807644097527647305469671333646868883650312280989663788656507661713409911267085806708237966730821529702498972114194166091819277582149433578383639532136271637219758962252614390071122773223025154710411681628917523557526099053858210363406122853294409830276270946292893988830514538950951686480580886602618927728470029090747400687617046511462665469446846624685614084264191213318074804549715573780408305977947238915527798680393538207482620648181504876534152430149355791756374642327623133843473947861771150672096834149014464956451480803326284417202116346454345929350148770746553056995922154382822307758515805142704373984019252210715650875853634697920708113806880196144197384637328982263167395073688501517286678083973976140696077590122053014085412828620051470085033364773099146103525313018873319293728800442101520384088109603555959893639842091339193857485407672132882577840295039058621747654642202620767068924079813640067442975
EQUAL,8028659553836119901593655311677865290672387540027895708985570867455842278776015838142490556122515317003830575671206217290165955723210315889275621408086645995280770696135307020454887097794294273869941097888549275028604248332746117479367032100139091095818169444690976206636597409322539276252570779516636180497560345090851316373570301807158645002654208816162902430571101092599540795501152368695431168224953320283502815852695423193526255836776240019085157444254721864134058745605280085897450952937893645487302683006269553010996013513395044612932182772364336368242146044741660443063207438830622376694839772096688572619877,65537,21052260334349247097390263197515551021430500095747078612475171670547647379514624742422155617118382403386162585789957995106937640909858927441120214136124618650916253946431099279059999234690271861285094667690686174087562943995337813383652323725628494261414287817117703355799303086256914782640807165021059760198249458510362432176960683009890989990086614909076853502936665842869163947730574085863127445475967466399017447434906719734480523659879746056728772390182338236187070557277461449143752467418310063647027554915213099799725713708651142505590086828211040619445941301844994775362846837122335522584661592447560060751169->986236757547332986472011617696226561292849812918563355472727826767720188564083584387121625107510786855734801053524719833194566624465665316622563244215340671405971599343902468620306327831715457360719532421388780770165778156818229863337344187575566725786793391480600129482653072861971002459947277805295727097226389568776499707662505334062639449916265137796823793276300221537201727072401742985542559596685092673521228140822200236743113743661549252453726123450722876929538747702356573783116197523966334991563351853851212597377279504828784687920949198341066450537230593608440475006386024448307924665012521692416658191

.vmoptions 中写入

-javaagent:/usr/local/JetBrains/ja-netfilter/ja-netfilter.jar

使用认证服务器授权

Go & NodeJS & Java

建议将 go 和 nodejs 分别安装到 /usr/local/go/usr/local/nodejs

为 java 创建 /usr/local/java 目录,将各版本 jdk 统一解压到该目录下便于管理

sudo mkdir /usr/local/go
sudo mkdir /usr/local/nodejs
sudo chown debianuser. -R /usr/local/go
sudo chown debianuser. -R /usr/local/nodejs
tar zxvf Downloads/goxxxlinux-amd64.tar.gz -C /usr/local/go/ --strip-components=1
tar Jxvf Downloads/node-v14.17.3-linux-x64.tar.xz -C /usr/local/nodejs/ --strip-components=1
sudo tee /etc/zsh/zprofile <<-'EOF'

export NODE_HOME='/usr/local/nodejs'

export GOROOT='/usr/local/go'
export GOPATH="$HOME/.go"
export GOENV="$HOME/.config/go/env"
export GOCACHE="$HOME/.cache/go-build"

export JAVA_HOME='/usr/local/java/jdk-xxx'

export PATH="$PATH:$NODE_HOME/bin"
export PATH="$PATH:$GOROOT/bin"
export PATH="$PATH:$JAVA_HOME/bin"
EOF
source /etc/zsh/zprofile

配置 Go Modules,Go 代理并切换 npm 源

go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,https://goproxy.io,direct
npm config set registry https://registry.npmmirror.com/

安装 MySQL Server 及 MySQL Workbench

访问 MySQL Community Downloads 下载 APT 仓库管理包

由于 MySQL Workbench 依赖 Python 版本较高,MySQL 在 Debian 源中禁用了该包

访问 MySQL Product Archives 下载适用于 Ubuntu 18.04 的 8.0.22 安装包

sudo apt install ./Downloads/mysql-apt-config_xxx_all.deb
sudo apt update
sudo apt upgrade
sudo apt install mysql-server
sudo systemctl start mysql
sudo systemctl enable mysql
sudo apt install ./Downloads/mysql-workbench-community_8.0.23-1ubuntu18.04_amd64.deb

安装 VSCode 扩展

以下仅为推荐扩展,请根据自己的技术栈及个人喜好自行选择

  • Chinese (Simplified) Language Pack for Visual Studio Code
  • Markdown All in One
  • Markdown Preview Enhanced
  • markdownlint
  • Remote Development
  • Todo Tree
  • ESLint
  • Python
  • C/C++

系统设置

  • 外观

    • 全局主题

      • 获取新的全局主题: Nordic darker KDE
    • Plasma 样式: Nordic-darker

    • 应用程序样式

      • 窗口装饰: Nordic
    • 颜色: Breeze 微风暗色

    • 图标

      • 获取新图标主题: Nordic Folders icon pack Mod
  • 工作区

    • 工作区行为

      • 常规行为

        • 点击行为: 双击打开文件和文件夹
      • 锁屏

        • 自动锁定屏幕: 如果空闲 30 分钟
        • 锁屏多久后需要密码解锁: 0
    • 开机与关机

      • 登录屏幕(SDDM)

        • 获取新登录屏幕: Chili login theme for KDE Plasma
      • 欢迎屏幕: Nordic-darker

    • 搜索

      • KRunner

        • 屏幕上的位置: 居中
        • 关闭 保留先前的搜索
  • 网络

    • 网络设置

      • 代理

        • 选择 使用手动配置的代理服务器
        • HTTP 代理: 127.0.0.1 端口: 7890
        • 打开 所有协议都使用同样的代理服务器
  • 硬件

    • 电源管理

      • 节能

        • 屏幕节能: 关闭前等待时间 30 分钟

面板配置

  • 面板高度: 46

  • 在任务管理器两侧添加边距

  • 更多选项

    • 打开 最大化面板
  • 图标任务管理器

    • 外观

      • 打开 悬停任务时高亮窗口
    • 行为

      • 分组: 不分组
      • 只显示任务: 打开 来自当前屏幕
  • 数字时钟

    • 外观

      • 打开 显示秒
      • 时间显示: 24 小时制

Konsole 配置

  • 常规

    • 关闭 记住窗口大小
  • 配置方案

    • 常规

      • 初始终端尺寸: 14030
    • 外观

      • 配色方案和字体

        • 获取新的: Nordic konsole
      • 字体: Sarasa Term SC 10pt

    • 滚动

      • 回滚: 无限制

安装 Gnome 扩展

访问 GNOME Shell Extensions 启用扩展

  • Alternatetab
  • AppIndicator and KStatusNotifierItem Support
  • Dash to panel
  • User themes

安装主题 GitHub - PapirusDevelopmentTeam/papirus-icon-theme

sudo sh -c "echo 'deb http://ppa.launchpad.net/papirus/papirus/ubuntu focal main' > /etc/apt/sources.list.d/papirus-ppa.list"
sudo apt install dirmngr
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com E58A9D36647CAE7F
sudo apt update
sudo apt install papirus-icon-theme

Gnome 系统设置

  • 网络

    • 网络代理

      • 手动

        • HTTP 代理: 127.0.0.1 7890
        • HTTPS 代理: 127.0.0.1 7890
        • Socks 主机: 127.0.0.1 7890
  • 电源

    • 息屏: 15 分钟
    • 自动挂起
      • 使用电池时延迟: 30 分钟
      • 已插入电源延迟: 60 分钟
      • 电源按钮行为: 休眠
  • 键盘快捷键

    • 添加

      • 名称: Terminal
      • 命令: gnome-terminal
      • 快捷键: Ctrl + Alt + T
  • 鼠标和触摸板: 打开 轻拍以点击

Gnome 终端设置

  • 配置文件首选项

    • 常规: 关闭 启用菜单快捷键

    • 未命名

      • 文本

        • 终端起始尺寸 14030
      • 颜色

        • 调色板

          • 内置方案: GNOME
          • 开启 以亮色显示粗体字
      • 滚动: 关闭 回滚限制

Gnome 优化配置

  • 通用: 关闭 笔记本电脑盖子关闭时挂起

  • 外观

    • 应用程序: Adwaita-dark
    • 图标: Papirus
  • 字体

    • 微调: 完全
    • 抗锯齿: 子像素
  • 扩展

    • Dash to Panel

      • 位置

        • 面板屏幕位置: 顶部
        • Panel thickness: 40 px
        • 关闭 Desktop button
      • 风格

        • 应用图标边缘空白: 4 px 6 px

        • 运行指示器位置: 顶部

        • 运行指示器风格选项

          • 打开 指示器颜色 - 覆盖主题

            • 全部设置为白色
          • 打开 为未取得焦点的程序使用不同方案

            • 全部设置为灰色
        • 打开 覆盖面板主题背景不透明度

          • 面板背景不透明度 60
      • 行为

        • 打开 隔离工作区
        • 打开 隔离显示器
        • 打开 取消应用程序分组
  • 窗口标题栏

    • 打开 最大化
    • 打开 最小化
  • 键盘和鼠标: 关闭 中间点击粘贴

  • 顶栏

    • 打开 电池百分比
    • 打开 日期
    • 打开

.zshrc

CHANGE_LANG_NOGUI=true

# apt install fonts-powerline
# Download https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/Hack.zip
# Extract the files and copy all font files to user font folder like ~/.local/share/fonts
# fc-cache -f -v

### Added by Zinit's installer
if [[ ! -f $HOME/.local/share/zinit/zinit.git/zinit.zsh ]]; then
    print -P "%F{33} %F{220}Installing %F{33}ZDHARMA-CONTINUUM%F{220} Initiative Plugin Manager (%F{33}zdharma-continuum/zinit%F{220})…%f"
    command mkdir -p "$HOME/.local/share/zinit" && command chmod g-rwX "$HOME/.local/share/zinit"
    command git clone https://github.com/zdharma-continuum/zinit "$HOME/.local/share/zinit/zinit.git" && \
        print -P "%F{33} %F{34}Installation successful.%f%b" || \
        print -P "%F{160} The clone has failed.%f%b"
fi

source '/etc/zsh/zprofile'
source "$HOME/.local/share/zinit/zinit.git/zinit.zsh"
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit
### End of Zinit's installer chunk

HISTFILE="$HOME/.zsh_history"
HISTSIZE=10000
SAVEHIST=10000
setopt BANG_HIST                 # Treat the '!' character specially during expansion.
setopt EXTENDED_HISTORY          # Write the history file in the ":start:elapsed;command" format.
setopt INC_APPEND_HISTORY        # Write to the history file immediately, not when the shell exits.
setopt SHARE_HISTORY             # Share history between all sessions.
setopt HIST_EXPIRE_DUPS_FIRST    # Expire duplicate entries first when trimming history.
setopt HIST_IGNORE_DUPS          # Don't record an entry that was just recorded again.
setopt HIST_IGNORE_ALL_DUPS      # Delete old recorded entry if new entry is a duplicate.
setopt HIST_FIND_NO_DUPS         # Do not display a line previously found.
setopt HIST_IGNORE_SPACE         # Don't record an entry starting with a space.
setopt HIST_SAVE_NO_DUPS         # Don't write duplicate entries in the history file.
setopt HIST_REDUCE_BLANKS        # Remove superfluous blanks before recording entry.
setopt HIST_VERIFY               # Don't execute immediately upon history expansion.
setopt HIST_BEEP                 # Beep when accessing nonexistent history.

# apt install fzf
zinit ice depth='1' lucid wait='0' atload='_zsh_autosuggest_start'
zinit light zsh-users/zsh-autosuggestions
zinit ice depth='1' lucid wait='0'
zinit light zsh-users/zsh-syntax-highlighting
zinit ice depth='1'
zinit light zsh-users/zsh-completions
zinit ice depth='1'
zinit light romkatv/powerlevel10k
zinit ice lucid wait='0'
zinit snippet OMZ::plugins/jsontools/jsontools.plugin.zsh
zinit ice lucid wait='0'
zinit snippet OMZ::plugins/fzf/fzf.plugin.zsh
zinit ice lucid wait='0'
zinit snippet OMZ::lib/completion.zsh

autoload -U compinit && compinit

# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
if [ ${DISPLAY} ]; then
   [[ ! -f ~/.p10k.gui.zsh ]] || source ~/.p10k.gui.zsh
else
   [[ ! -f ~/.p10k.terminal.zsh ]] || source ~/.p10k.terminal.zsh
   if [ ${CHANGE_LANG_NOGUI} ]; then
       export LC_ALL="en_US.UTF-8"
   fi
fi

alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias ll='ls -lh'
alias la='ls -A'
alias l='ls -CF'
alias cp='/usr/local/bin/cpg -g'
alias mv='/usr/local/bin/mvg -g'
alias cat='batcat --paging=never -p'

Powerlevel10k 配置

Powerlevel10k 是 zsh 的主题,在 .zshrc 中我们声明了在桌面环境和终端环境下使用不同的 p10k 配置,即桌面环境使用图标更多更友好的终端主题配置,而在终端环境下使用更保守的终端主题配置以保证兼容性,以下为两个配置文件完整内容链接

p10k Config for GUI

p10k Config for Terminal