十七日尾灯 發表於 2021-8-21 13:40:00

Debian 11 “bullseye” 安装笔记

<p>Debian 11 “bullseye” 安装笔记</p>
<p>请访问原文链接:https://sysin.org/blog/debian-11-install/ 查看最新版。原创作品,转载请保留出处。</p>
<p>作者主页:sysin.org</p>
<p>ISO 下载:Debian 11</p>
<p>OVF 下载:Debian 11 OVF</p>
<p>Debian 版本:11<br>
代号:bullseye<br>
发布日期:2021.08.14<br>
内核版本:5.10</p>
<pre><code class="language-shell">$ uname -a
Linux debian 5.10.0-8-amd64 #1 SMP Debian 5.10.46-4 (2021-08-03) x86_64 GNU/Linux
</code></pre>
<p>Debian 11 是 LTS 长期支持版本,长达 5 年的生命周期,适合在生产环境运行。</p>
<h2 id="1-debian-版本历史">1. Debian 版本历史</h2>
<p>Debian 是最早的 Linux 发行版之一,由 Ian Murdock(伊恩 · 默多克)创立。Ian Murdock 于 1973 年 4 月 28 日出生于德国的君斯坦市 (Konstanz, Germany)。他是 Debian GNU/Linux 发行版的创始人,也是商用 Linux 发行商 Progeny 公司的创始人。他曾就职于 Sun Microsystems, Inc,负责 Sun 公司的操作系统平台发展战略。在加入 Sun 公司之前,Ian Murdock 是 Linux 基金会 (Linux Foundation) 的首席技术长官 (CTO),以及 Linux 平台交互标准 LSB (Linux Standard Base) 的主席,最后受聘于 Docker 公司,非常令人遗憾的是 Ian Murdock 于美国时间 2015 年 12 月 28 日 逝世,开源界和 Linux 业界痛失一位真正的天才!</p>
<p>Debian 于 1993 年 8 月 16 日由当时还在美国普渡大学念书的 Ian Murdock 首次发表。Debian 的名称中的 “deb” 取自他的女友(现在为其妻子) Debra,“ian” 取自 Ian Murdock 自己的名字。Ian Murdock 最初把他的系统称为 “Debian Linux Release”。在定义文件 Debian Manifesto 中,Ian Murdock 宣布将以开源的方式,本着 Linux 及 GNU 的精神发行一套 GNU/Linux 发行版。Ian Murdock 的目的是创建一个任何人都可以免费下载和使用的稳定的发行版,而不是让用户一个一个地收集应用程序并自己编译。</p>
<p>-- Debian GNU/Linux 的发展简史</p>
<p>以下是最近的基本版本的发布日期:</p>
<p>• 2021-08-14: Distribution Release: Debian 11<br>
• 2019-07-07: Distribution Release: Debian 10<br>
• 2017-06-18: Distribution Release: Debian 9<br>
• 2015-04-26: Distribution Release: Debian GNU/Linux 8.0<br>
• 2013-05-05: Distribution Release: Debian GNU/Linux 7.0<br>
• 2011-02-06: Distribution Release: Debian GNU/Linux 6.0<br>
• 2009-02-15: Distribution Release: Debian GNU/Linux 5.0<br>
• 2007-04-08: Distribution Release: Debian GNU/Linux 4.0</p>
<p>详见:DebianReleases</p>
<h2 id="2-debian-11-的新变化">2. Debian 11 的新变化</h2>
<h3 id="21-支持的架构">2.1. 支持的架构</h3>
<p>下面是 Debian bullseye 官方支持的架构:</p>
<ul>
<li>32 位 PC 机(<code>i386</code>)和 64 位 PC 机(<code>amd64</code>)</li>
<li>64 位 ARM(<code>arm64</code>)</li>
<li>ARM EABI(<code>armel</code>)</li>
<li>ARMv7(EABI 硬浮点 ABI,<code>armhf</code>)</li>
<li>小端序 MIPS(<code>mipsel</code>)</li>
<li>64 位小端序 MIPS(<code>mips64el</code>)</li>
<li>64 位小端序 PowerPC(<code>ppc64el</code>)</li>
<li>IBM System z(<code>s390x</code>)</li>
</ul>
<p>您可以在 Debian 移植页面 阅读更多的关于您的架构的移植状态和移植细节的信息。</p>
<h3 id="22-这次发布中有什么新变化">2.2. 这次发布中有什么新变化?</h3>
<p>Debian 的这次发行再次带来了比上一版本 buster 更多的软件;本次发行包括 11294 个新软件包,软件包的总数达到了 59551 个。这个发行版的多数软件包得到了更新:更新了 42821 个软件包(占 buster 软件包总数的 72%)。而且,由于各种原因,有相当数量的软件包(9519 个,占 buster 软件包总数的 16%)从这次发行中被删除了。您将不会看到这些包有任何更新,而且在包管理软件中它们会被标记为 “过时的”;参见 第 4.8 节 “过时的软件包”。</p>
<p>2.2.1. 桌面和知名软件包</p>
<p>如往常一样,Debian 也提供了多个桌面程序和环境。提供的桌面环境包括 GNOME 3.38,KDE Plasma 5.20,LXDE 11,LXQt 0.16,MATE 1.24,以及 Xfce 4.16。</p>
<p>生产力应用也得到了升级,包括办公套件:</p>
<ul>
<li>LibreOffice 已升级到 7.0 版;</li>
<li>Calligra 已升级到 3.2 版;</li>
<li>GNUcash 已升级到 4.4 版;</li>
</ul>
<p>这次发行包含了许多软件的更新,其中包括:</p>
<table>
<thead>
<tr>
<th>软件包</th>
<th>在 10(buster)中的版本</th>
<th>在 11(bullseye)中的版本</th>
</tr>
</thead>
<tbody>
<tr>
<td>Apache</td>
<td>2.4.38</td>
<td>2.4.48</td>
</tr>
<tr>
<td>BIND DNS 服务器</td>
<td>9.11</td>
<td>9.16</td>
</tr>
<tr>
<td>Cryptsetup</td>
<td>2.1</td>
<td>2.3</td>
</tr>
<tr>
<td>Dovecot MTA</td>
<td>2.3.4</td>
<td>2.3.13</td>
</tr>
<tr>
<td>Emacs</td>
<td>26.1</td>
<td>27.1</td>
</tr>
<tr>
<td>Exim 默认邮件服务器</td>
<td>4.92</td>
<td>4.94</td>
</tr>
<tr>
<td>GNU 编译器套件(默认编译器)</td>
<td>8.3</td>
<td>10.2</td>
</tr>
<tr>
<td>GIMP</td>
<td>2.10.8</td>
<td>2.10.22</td>
</tr>
<tr>
<td>GnuPG</td>
<td>2.2.12</td>
<td>2.2.20</td>
</tr>
<tr>
<td>Inkscape</td>
<td>0.92.4</td>
<td>1.0.2</td>
</tr>
<tr>
<td>GNU C 函数库</td>
<td>2.28</td>
<td>2.31</td>
</tr>
<tr>
<td>lighttpd</td>
<td>1.4.53</td>
<td>1.4.59</td>
</tr>
<tr>
<td>Linux 内核映像</td>
<td>4.19 系列</td>
<td>5.10 系列</td>
</tr>
<tr>
<td>LLVM/Clang 工具链</td>
<td>6.0.1 和 7.0.1(默认)</td>
<td>9.0.1 和 11.0.1(默认)</td>
</tr>
<tr>
<td>MariaDB</td>
<td>10.3</td>
<td>10.5</td>
</tr>
<tr>
<td>Nginx</td>
<td>1.14</td>
<td>1.18</td>
</tr>
<tr>
<td>OpenJDK</td>
<td>11</td>
<td>11</td>
</tr>
<tr>
<td>OpenSSH</td>
<td>7.9p1</td>
<td>8.4p1</td>
</tr>
<tr>
<td>Perl</td>
<td>5.28</td>
<td>5.32</td>
</tr>
<tr>
<td>PHP</td>
<td>7.3</td>
<td>7.4</td>
</tr>
<tr>
<td>Postfix MTA</td>
<td>3.4</td>
<td>3.5</td>
</tr>
<tr>
<td>PostgreSQL</td>
<td>11</td>
<td>13</td>
</tr>
<tr>
<td>Python 3</td>
<td>3.7.3</td>
<td>3.9.1</td>
</tr>
<tr>
<td>Rustc</td>
<td>1.41(<code>armel</code> 则为 1.34)</td>
<td>1.48</td>
</tr>
<tr>
<td>Samba</td>
<td>4.9</td>
<td>4.13</td>
</tr>
<tr>
<td>Vim</td>
<td>8.1</td>
<td>8.2</td>
</tr>
</tbody>
</table>
<p>2.2.2. 无驱动扫描和打印</p>
<p>使用 <code>CUPS</code> 打印以及使用 <code>SANE</code> 扫描对于越来越多的硬件型号已经可以实现无需任何驱动程序(通常是非自由驱动程序)即可正常操作,尤其是过去五年以来出现在市场上的新设备。</p>
<p>2.2.2.1. CUPS 和无驱动打印</p>
<p>使用以太网或无线网络连接的现代打印机已经可以使用 无驱动打印功能,由 <code>CUPS</code> 和 <code>cups-filters</code> 软件包提供支持,此功能已在 Debian buster 发行注记 中描述。Debian 11 “bullseye” 提供了新软件包 <code>ipp-usb</code>;它使用许多现代打印机所支持的、供应商中立的 IPP-over-USB 协议,且 <code>cups-daemon</code> 推荐安装该软件包。它使得 USB 设备可被视作网络设备,以将无驱动打印扩展至包括 USB 连接的打印机。详情 在维基上 有更多描述。</p>
<p>在 <code>ipp-usb</code> 软件包中包含的 systemd 服务文件将在使用 USB 的打印机连接到系统时启动 <code>ipp-usb</code> 守护程序,以使其可用于打印任务。默认情况下 <code>cups-browsed</code> 软件包应当可以自动完成配置,或者可以 手动设置本地无驱动打印队列。</p>
<p>2.2.2.2. SANE 和无驱动扫描</p>
<p>官方的 <code>SANE</code> 无驱动后端在 <code>libsane1</code> 软件包中由 <code>sane-escl</code> 提供。另有一独立开发的无驱动后端 <code>sane-airscan</code>。两个后端均可使用 eSCL 协议,但 <code>sane-airscan</code> 另外也可使用 WSD 协议。用户应该考虑在系统上同时安装两个后端。</p>
<p><code>eSCL</code> 和 <code>WSD</code> 均为网络协议。因此,它们在设备是 <code>IPP-over-USB</code> 设备的情况下也可经由 USB 连接生效(参见上文)。请注意 <code>libsane1</code> 推荐安装 <code>ipp-usb</code> 软件包。在软件包已安装的情况下,合适的设备可以在使用 USB 端口连接到系统的同时自动设置使用无驱动后端。</p>
<p>2.2.3. 新的通用 open 命令</p>
<p>新增加的 <strong>open</strong> 命令将作为 <strong>xdg-open</strong>(默认)或者 <strong>run-mailcap</strong> 的别名出现,具体实现则由 update-alternatives(1) 系统管理。它旨在作为命令行交互工具,帮助用户使用默认的应用程序打开文件;所使用的程序按照具体情况可以是图形界面程序。</p>
<p>2.2.4. 控制组 v2</p>
<p>在 bullseye 中,systemd 默认使用控制组 v2(cgroupv2),它提供了统一的资源控制层级架构。如果有需要,可以使用内核命令行参数重新启用旧有的 cgroups;请参见 第 5.1.9 节 “OpenStack 和 cgroups v1”一节中适用于 OpenStack 的注记。</p>
<p>2.2.5. 持久化 systemd 日志</p>
<p>在 bullseye 中的 systemd 默认启用了持久日志的功能,日志文件存放于 <code>/var/log/journal/</code>。请参见 systemd-journald.service(8) 以了解细节;请注意 Debian 中的日志除了默认的 <code>systemd-journal</code> 组外,还可以被 <code>adm</code> 用户组内的成员阅读。</p>
<p>这项改动应该不会对任何已有的传统日志守护程序(例如 <code>rsyslog</code>)产生任何干扰,但是不依赖这些守护程序所提供的特别功能的用户应当考虑将传统日志程序卸载并切换到仅使用新的 systemd 日志工具。</p>
<p>2.2.6. 新的 Fcitx 5 输入法</p>
<p>Fcitx 5 是用于中文、日语、韩语和其它许多语言的一个输入法。它是 buster 提供的 Fcitx 4 的后续版本。新版本增加了对 Wayland 的支持并改进了扩展支持。您可以在 维基页面上 阅读更多信息以及从旧版本迁移的方法。</p>
<p>2.2.7. 来自 Debian Med Blend 团队的新闻</p>
<p>Debian Med 团队正在积极打包用于研究病毒序列以及与流行病学研究相关的软件以抗击 <code>COVID-19</code> 和疫情大流行。下一个发行周期中,团队将继续进行这项任务,并专注于打包可以应用于这两个领域的机器学习工具。</p>
<p>除了添加生命科学和医药领域的新软件包之外,许多已有的软件包也得到了持续集成支持。</p>
<p>一些性能关键的应用程序现在受益于 SIMD Everywhere 的实现。该软件库可以帮助软件包既支持更多的硬件平台(尤其是 <code>arm64</code>),又受益于处理器所提供的向量运算扩展带来的性能提升,例如 <code>amd64</code> 上的 <code>AVX</code>,或 <code>arm64</code> 上的 <code>NEON</code>。</p>
<p>如需安装由 Debian Med 团队维护的软件包,您可以安装名为 <code>med-*</code>*<code>*</code> 的元软件包;在 Debian bullseye 中,其版本号为 3.6.x。您还可以访问 Debian Med 任务页面 以查看 Debian 中全部可用的生物和医疗软件。</p>
<p>2.2.8. 内核 exFAT 支持</p>
<p>bullseye 是第一个提供支持 exFAT 文件系统的 Linux 内核的发行版本,且它默认使用该实现挂载 exFAT 文件系统。因此,用户不再需要使用 <code>exfat-fuse</code> 软件包所提供的用户空间文件系统实现。如果您要继续使用用户空间文件系统的实现,您需要在挂载 exFAT 文件系统时直接调用 <strong>mount.exfat-fuse</strong> 命令。</p>
<p>创建和检查 exFAT 文件系统的工具位于 <code>exfatprogs</code> 软件包,它由 Linux 内核 exFAT 实现的作者编写。由已有的 <code>exfat-utils</code> 软件包提供的独立实现仍然可用,但它不能与新的实现共同安装在系统上。我们推荐您迁移到使用 <code>exfatprogs</code> 软件包,尽管您需要注意并处理两者可能不互相兼容的命令行选项。</p>
<p>2.2.9. 改进的 man page 翻译</p>
<p>部分项目,例如 systemd、 util-linux、 OpenSSH 和 Mutt 的部分语言的手册页 (sysin),例如法语、西班牙语和马其顿语,得到了明显改进。欲获得此项改进,请安装 <code>manpages-*</code>xx<code>*</code>(其中 <code>*</code>xx<code>*</code> 是您所需的自然语言的代码)。</p>
<p>在 bullseye 的生命周期中,进一步的翻译改进将会通过 <code>backports</code> 仓库提供。</p>
<h2 id="3-安装摘要">3. 安装摘要</h2>
<p>本例使用 Debian 11 AMD64(x86_64)CD:debian-11.0.0-amd64-netinst.iso 进行安装。</p>
<ol>
<li>语言选择,选择 English,Location 选择 China</li>
<li>设定 root 账号密码,并提示新建一个账号(普通用户)并设置密码</li>
<li>分区,默认 ext4 文件系统,可选 LVM</li>
<li>软件包管理,可以选择本地镜像源</li>
<li>组件:默认选择 GNOME 桌面环境(这里取消)和 Standard System Utilities(保持勾选),勾选 SSH server</li>
</ol>
<h2 id="4-默认没有安装-sudo">4. 默认没有安装 sudo</h2>
<p>Debian 在安装过程中设置 root 密码,并提示创建一个普通用户,SSH server 需要手动勾选安装,root 默认不允许 SSH 登录,同时默认并没有 sudo,所以第一步必须配置 sudo,或者开启 root 账号 SSH 登录(存在安全性风险,不推荐)。</p>
<p>本例中安装时创建了一个名为 sa 的用户:</p>
<pre><code class="language-shell">$ id sa
uid=1000(sa) gid=1000(sa) groups=1000(sa),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),109(netdev)
</code></pre>
<p>安装 sudo:</p>
<pre><code class="language-shell">apt install sudo
</code></pre>
<p>将之前创建的普通用户添加到 sudo 组,即可获得管理员权限:</p>
<pre><code class="language-shell">usermod -a -G sudo sa
# -a=append,不改变原有附加组
</code></pre>
<p>附:<code>/etc/sudoers</code> 默认配置如下。</p>
<pre><code class="language-shell">#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults      env_reset
Defaults      mail_badpass
Defaults      secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "@include" directives:

@includedir /etc/sudoers.d
</code></pre>
<h2 id="5-软件包管理入门">5. 软件包管理入门</h2>
<p>Debian 软件包管理叫做 Advanced Packaging Tool (APT),是一套管理软件包和相关依赖的机制,可以实现应用程序的安装、移除和更新等。</p>
<p>如果您已经有了 Linux(RHEL、Ubuntu)或者 Unix(macOS、FreeBSD)任一产品的软件包管理工具使用经验,对于其他系统可以参看下表快速入门:</p>
<table>
<thead>
<tr>
<th>命令功能 / 系统</th>
<th>Darwin (macOS)</th>
<th>FreeBSD</th>
<th>Debian/Ubuntu</th>
<th>RHEL(dnf = yum)</th>
</tr>
</thead>
<tbody>
<tr>
<td>搜索和查找软件包</td>
<td>brew search</td>
<td>pkg search</td>
<td>apt list</td>
<td>yum list</td>
</tr>
<tr>
<td>查看软件包信息</td>
<td>brew info</td>
<td>pkg info</td>
<td>apt show</td>
<td>yum info</td>
</tr>
<tr>
<td>安装</td>
<td>brew install</td>
<td>pkg install</td>
<td>apt install</td>
<td>yum install</td>
</tr>
<tr>
<td>删除</td>
<td>brew uninstall/remove/rm</td>
<td>pkg delete/remove</td>
<td>apt remove</td>
<td>yum remove</td>
</tr>
<tr>
<td>删除不在使用的软件包</td>
<td>brew autoremove</td>
<td>pkg autoremove</td>
<td>apt autoremove</td>
<td>yum autoremove</td>
</tr>
<tr>
<td>更新 repo 列表</td>
<td>brew update</td>
<td>pkg update</td>
<td>apt update</td>
<td>yum makecache</td>
</tr>
<tr>
<td>更新软件包</td>
<td>brew upgrade</td>
<td>pkg upgrade</td>
<td>apt upgrade</td>
<td>yum upgrade/update</td>
</tr>
<tr>
<td>清理缓存临时文件等</td>
<td>brew cleanup</td>
<td>pkg clean</td>
<td>apt autoclean</td>
<td>yum clean all</td>
</tr>
</tbody>
</table>
<blockquote>
<p>备注 1:RHEL 8 开始,使用 dnf,但 yum 仍然可用,实际上两个命令都是相同的文件链接,等价。</p>
<p>备注 2:RHEL 此处用词包含其免费兼容发行版 AlmaLinux、Rocky Linux 以及退役的 CentOS。</p>
</blockquote>
<p>可以看到,RHEL 中更新 repo 列表的命令与其他不同,其他命令几乎都是相同或者极为类似。</p>
<p>当然 Ubuntu 是基于 Debian 构建,apt 使用方式是一样的。</p>
<p><strong>注意事项:</strong> 应该尽量避免以下行为。</p>
<ul>
<li>在 “<code>/etc/apt/sources.list</code>” 中不要包含 <strong><code>testing</code></strong> 或 <strong><code>unstable</code></strong> 。</li>
<li>在 “<code>/etc/apt/sources.list</code>” 里不要在标准的 Debian 中混合使用其它非 Debian 的档案库,例如 Ubuntu 。</li>
<li>不要建立 “<code>/etc/apt/preferences</code>” 。</li>
<li>不了解会造成的全部影响,就不要通过配置文件改变软件包管理工具的默认行为。</li>
<li>不要使用 “<code>dpkg -i &lt;random_package&gt;</code>” 安装任何软件包。</li>
<li>绝不使用 “<code>dpkg --force-all -i &lt;random_package&gt;</code>” 安装任何软件包。</li>
<li>不要删除或修改 “<code>/var/lib/dpkg/</code>” 中的文件。</li>
<li>不要让从源码直接安装的程序覆盖系统文件。如果需要的话,将它们安装到 “<code>/usr/local</code>” 或 “<code>/opt</code>” 中。</li>
</ul>
<h2 id="6-创建一个管理员账号">6. 创建一个管理员账号</h2>
<p>默认配置下,创建一个管理员账号,即有 sudo 权限执行所有命令的用户:</p>
<pre><code class="language-shell">useradd -m -s /bin/bash -G sudo sysin#sysin 为用户名
passwd sysin#为 sysin 设置密码
</code></pre>
<p>备注:</p>
<p>-m 创建同名 home 目录</p>
<p>-s 指定 shell</p>
<p>-G 修改附加属组</p>
<h2 id="7-配置-vi">7. 配置 vi</h2>
<p>系统自带 vi 即 vim 8.2.2434,默认配置有点难用,使用 .vimrc 配置文件后报错,竟然不支持语法高亮:</p>
<pre><code class="language-shell">E319: Sorry, the command is not available in this version: syntax on
</code></pre>
<p>安装最新的 vim:</p>
<pre><code class="language-shell">sudo apt install vim
</code></pre>
<p>虽然版本并没有更新,安装了附件组件,已经正常了。</p>
<p><code>.vimrc</code> 配置文件参考如下:</p>
<h2 id="8-开启-root-账号登录的方法">8. 开启 root 账号登录的方法</h2>
<blockquote>
<p>不建议开启,以下步骤仅供参考。</p>
</blockquote>
<p>Debian 默认禁用 root SSH 密码登录(Pubkey 认证不受此限,默认启用),安装时候创建特定用户作为管理员帐号(通过 sudo 执行特权命令),启用 root 用户步骤如下:</p>
<ul>
<li>修改 root 密码(设置密码后可以通过控制台登录)</li>
</ul>
<pre><code class="language-shell">sudo passwd root
</code></pre>
<ul>
<li>修改配置文件(启用 SSH 密码登录)</li>
</ul>
<pre><code class="language-shell">sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
sudo vi /etc/ssh/sshd_config
</code></pre>
<p>找到下面相关配置:</p>
<pre><code class="language-shell"># Authentication:

#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile   .ssh/authorized_keys .ssh/authorized_keys2
</code></pre>
<p>修改如下:</p>
<pre><code class="language-shell">#PermitRootLogin prohibit-password
# 增加一句
PermitRootLogin yes
</code></pre>
<p>补充:</p>
<pre><code class="language-shell">PermitRootLogin prohibit-password#允许 root 登录,但禁止使用密码认证
可以配合使用 Pubkey 认证,默认 `PubkeyAuthentication yes`
</code></pre>
<ul>
<li>或者直接快速配置</li>
</ul>
<pre><code class="language-shell">sudo sed -i.bak "/^#PermitRootLogin/c"PermitRootLogin""yes"" /etc/ssh/sshd_config
# 或者
sudo sed -i.bak '/^#PermitRootLogin/c\PermitRootLogin yes' /etc/ssh/sshd_config
</code></pre>
<ul>
<li>重启服务生效</li>
</ul>
<pre><code class="language-shell">sudo systemctl restart ssh
</code></pre>
<h2 id="9-格式化网卡命名">9. 格式化网卡命名</h2>
<p>从 Debian 9 开始,(CentOS 7 开始,Ubuntu 16.04 开始),安装好后网卡名称变成了类似 ensxxx 这种随机名称(本例为 ens33,可能是其他数字)。</p>
<pre><code class="language-shell"># 编辑 grub 配置文件
sudo vi /etc/default/grub
修改 GRUB_CMDLINE_LINUX=""为 GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"

# 直接使用 sed 编辑
sudo sed -i "/^GRUB_CMDLINE_LINUX=""/c GRUB_CMDLINE_LINUX=\"net.ifnames=0 biosdevname=0\"" /etc/default/grub
# 更新 grub 配置文件
sudo update-grub
# 然后下一节编辑配置文件并重启生效
vi /etc/network/interfaces
# 将 ensxxx 修改为 eth0
# 重启系统生效
reboot
</code></pre>
<h2 id="10-网络配置">10. 网络配置</h2>
<p>查看 IP 地址信息:</p>
<pre><code class="language-shell">ip address
# 简写 ip a (sysin)
# 或者使用 ifconfig
ifconfig
</code></pre>
<p>Debian 11 网络配置文件为:<code>/etc/network/interfaces</code> 。</p>
<p>默认配置使用 DHCP,安装过程并没有手动配置提示。内容如下:</p>
<pre><code class="language-shell">$ cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug ens33#ens33 修改为 eth0
iface ens33 inet dhcp#ens33 修改为 eth0
</code></pre>
<p>修改 IP 地址:</p>
<pre><code class="language-shell">sudo vi /etc/network/interfaces
# 修改为以下内容:
iface lo inet loopback
auto lo

auto eth0
iface eth0 inet static
address 10.10.1.5
netmask 255.255.255.0
#broadcast 10.10.1.255 #可选,上述配置了掩码
#network 10.10.1.0 #可选,上述配置了掩码
gateway 10.10.1.1
#dns-domain sysin.org
# domain 和 search 不能共存;如果同时存在,后面出现的将会被使用。
dns-search sysin.org
dns-nameservers 10.10.1.1 8.8.8.8 #注意 debian 11 默认没有安装 resolvconf,所以需要手动在 resolv.conf 中编辑 DNS
# 或者安装 resolvconf 后,在这里配置,将自动更新 resolv.conf
sudo apt install resolvconf
# iface eth0 inet6 auto #ipv6 自动配置,不写则表示禁用了

# DHCP 配置如下:
auto eth0
iface eth0 inet dhcp

# 配置 DNS
cat /etc/resolv.conf #如果已经安装 resolvconf,不要手动编辑,直接在上述 interfaces 中编辑 dns

# 重启网络
sudo systemctl restart networking
#sudo service networking restart
</code></pre>
<blockquote>
<p>可以看到 Debian 网络配置方法并没有变更,Ubuntu 16.04 也是这样配置,但是 18.04 开始使用 netplan,20.04 同样使用 netplan 但是默认配置文件名称再次变更。</p>
</blockquote>
<p>配置多个 IP:</p>
<pre><code class="language-shell">auto eth0:0
iface eth0:0 inet static
    address 192.168.1.90
    netmask 255.255.255.0

auto eth0:1
iface eth0:1 inet static
    address 192.168.1.91
    netmask 255.255.255.0
</code></pre>
<p>添加静态路由(Linux 通用,临时,重启消失):</p>
<pre><code class="language-shell">route add -net 10.10.11.0/24 gw 10.10.1.1
</code></pre>
<p>Debian 配置永久静态路由:</p>
<pre><code class="language-shell">#添加
cat &gt;&gt; /etc/network/interfaces &lt;&lt;EOF
# static routes
up ip route add 10.10.12.0/24 via 10.10.1.1 dev eth0
up ip route add 10.10.13.0/24 via 10.10.1.1 dev eth0
up ip route add 10.10.14.0/24 via 10.10.1.1 dev eth0
up ip route add 10.10.15.0/24 via 10.10.1.1 dev eth0
up ip route add 10.10.16.0/24 via 10.10.1.1 dev eth0
EOF

#重启网络
systemctl restart networking

#验证
ip route
</code></pre>
<h2 id="11-修改主机名">11. 修改主机名</h2>
<p>设置主机名:</p>
<pre><code class="language-shell">hostnamectl set-hostname debian01 --static
# 修改为主机名 ubuntu01
</code></pre>
<p>或者:</p>
<pre><code class="language-shell">sudo vi /etc/hostname
# 修改为主机名 debian01
debian01
</code></pre>
<p>添加 domain name:</p>
<pre><code class="language-shell">sudo vi /etc/hosts
# 添加一行
127.0.0.1debian01.sysin.org debian01
# 注意这里的格式,IP 后面先写 FQDN 再写主机名,与 CentOS 相同
# 先写 FQDN 后写主机名,顺序反了不影响解析,但是'hostname -f'命令无法显示 FQDN,只能显示主机名
</code></pre>
<p>查看 FQDN:</p>
<pre><code class="language-shell">hostname -f
# 正确显示如下
debian01.sysin.org
</code></pre>
<h2 id="12-设置时区">12. 设置时区</h2>
<p>我们默认安装是已经正确设置时区,但是如果是第三方云主机时区就未必符合本地要求。</p>
<pre><code class="language-shell"># 查看时区,有 CST 正确
date
# 设置
sudo timedatectl set-timezone Asia/Shanghai
# 或者使用向导选择
tzselect
</code></pre>
<h2 id="13-修改镜像源">13. 修改镜像源</h2>
<p>安装的时候已经可以选择 mirror,加速本地访问,可以访问 Debian worldwide mirror sites 查看选择可用的镜像站点。</p>
<pre><code class="language-shell"># 模板使用 mirror.sjtu.edu.cn

# 备份
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

# 比如将默认官方中国像源 ftp.cn.debian.org 替换为 mirror.sjtu.edu.cn
sudo sed -i 's/ftp.cn.debian.org/mirror.sjtu.edu.cn/' /etc/apt/sources.list
## 中国可选镜像站点如下
ftp.cn.debian.org
mirrors.bfsu.edu.cn
mirrors.hit.edu.cn
mirror.sjtu.edu.cn
mirrors.tuna.tsinghua.edu.cn
mirrors.ustc.edu.cn
# 可以 ping 站点名称,对比一下延迟来选择
</code></pre>
<p>更新:</p>
<pre><code class="language-shell">sudo apt update #更新源
sudo apt upgrade #更新已安装的包
sudo apt dist-upgrade #升级系统
sudo apt clean &amp;&amp; sudo apt autoclean #清理下载文件的存档
# apt 是新版命令,替代 apt-get,apt-get 将来会淘汰
</code></pre>
<h2 id="14-安装-snmp">14. 安装 SNMP</h2>
<pre><code class="language-shell">sudo apt install snmpd snmp
</code></pre>
<p>(模板仅仅安装,未配置)</p>
<h2 id="15-配置-ntp">15. 配置 NTP</h2>
<p>这里使用 chrony 替代传统的 ntp,当然 ntp 也是可用的,两种默认都没有安装。</p>
<p>安装 chrony:</p>
<pre><code class="language-shell">sudo apt install chrony

sudo systemctl enable chrony
sudo systemctl start chrony
sudo systemctl status chrony

# 查看配置文件,暂使用默认配置
cat /etc/chrony/chrony.conf
</code></pre>
<p>chrony 自带一个交互式工具 chronyc,在配置文件中指定了时间服务器之后,如果想查看同步状态,可以进入这个交互式工具的交互界面。</p>
<pre><code class="language-shell">chronyc 有很多的子命令,可以输入 help 来查看
chronyc&gt; help
    选项:
    sources [-v]    显示关于当前来源的信息
    sourcestats [-v]      显示时间同步状态(如时间偏移了多少之类)
</code></pre>
<p>查看:</p>
<pre><code class="language-shell">chronyc sources -v
chronyc sourcestats -v
</code></pre>
<p>最基本配置:</p>
<pre><code class="language-shell">$ cat /etc/chrony/chrony.conf
# Welcome to the chrony configuration file. See chrony.conf(5) for more
# information about usable directives.

# Include configuration files found in /etc/chrony/conf.d.
confdir /etc/chrony/conf.d

# Use Debian vendor zone.
pool 2.debian.pool.ntp.org iburst
</code></pre>
<p>修改 <code>pool 2.debian.pool.ntp.org iburst</code> 为指定的 NTP 服务器。</p>
<p>通常是修改为内网中的 NTP,保持时间的统一和可靠同步,否则一般不用修改。</p>
<p>例如 Ubuntu 中默认的是:</p>
<pre><code class="language-shell">pool ntp.ubuntu.com      iburst maxsources 4
pool 0.ubuntu.pool.ntp.org iburst maxsources 1
pool 1.ubuntu.pool.ntp.org iburst maxsources 1
pool 2.ubuntu.pool.ntp.org iburst maxsources 2
</code></pre>
<p>这里的 pool 表示一组服务器,也可以用 sever 指令替代,标识一台服务器,可以是域名也可以是 IP 地址。</p>
<h2 id="16-虚机安装-vmware-tools">16. 虚机安装 VMware Tools</h2>
<p>默认自动安装,查看状态如下:</p>
<pre><code class="language-shell"># 查看版本
vmtoolsd -v
# 查看运行状态
systemctl status vmtoolsd
</code></pre>
<p>如果未安装,执行如下命令安装:</p>
<pre><code class="language-shell">apt install open-vm-tools
</code></pre>
<h2 id="17-安装必备工具">17. 安装必备工具</h2>
<p>根据需要安装自己常用的必备工具:</p>
<pre><code class="language-shell">sudo apt install zip unzip
sudo apt install lrzsz
sudo apt install htop #已经收录
sudo apt install lnav
sudo apt install fd-find #fd 命令,已经收录,命令为 fdfind
sudo ln -s /usr/bin/fdfind /usr/local/bin/fd
sudo apt install ripgrep #rg 命令,已经收录
sudo apt install tree
sudo apt install build-essential #Following command will install essential commands like gcc, make etc.
#sudo apt install net-tools #ifconfig、netstat、route 等命令集,默认安装
sudo apt install ntp ntpdate ntpstat #可选,模板未安装
# nc lsof 系统自带
# pstree
sudo apt install psmisc
# ncdu:NCurses Disk Usage
sudo apt install ncdu
# dstat 监控 CPU、磁盘和网络使用率
sudo apt install dstat
</code></pre>
<h2 id="18-shell-配置">18. Shell 配置</h2>
<p>Zsh</p>
<p>以下针对当前用户有效,建议使用全局配置,参看 其他文章。</p>
<pre><code class="language-shell"># Zsh
sudo apt install zsh

sudo chsh -s /bin/zsh

sudo apt install git

#通过 https://www.ipaddress.com 查询,美国地址有效
sudo sh -c "echo'199.232.96.133 raw.githubusercontent.com'&gt;&gt; /etc/hosts"

sudo sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

sed -i '/^ZSH_THEME=.*/c ZSH_THEME="ys"' ~/.zshrc

echo 'alias ll="ls -lahF --color=auto --time-style=long-iso"' &gt;&gt; ~/.zshrc

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

sed -i '/^plugins=.*/c plugins=(git zsh-syntax-highlighting)' ~/.zshrc

source~/.zshrc
</code></pre>
<h2 id="19-清理并制作镜像模板">19. 清理并制作镜像模板</h2>
<p>清理 apt 缓存</p>
<pre><code class="language-shell">sudo apt clean &amp;&amp; sudo apt autoclean #清理下载文件的存档
</code></pre>
<p>清理临时文件夹</p>
<pre><code class="language-shell">rm -rf /tmp/*# 清空临时文件夹
</code></pre>
<p>清空历史记录</p>
<p>至此,Debian 的基本配置已经完成,可以制作模板了。</p>
<h2 id="20-gnome-桌面环境">20. Gnome 桌面环境</h2>
<p>如果需要在命令行下安装桌面环境,操作如下:</p>
<pre><code class="language-shell">sudo apt update
# GNOME 3 and GNOME Classic desktop environment
sudo tasksel install desktop gnome-desktop
# 要安装 KDE 桌面环境将 以上命令中的 gnome-desktop 替换为 kde-desktop
# laptop tools (optional)
sudo tasksel install laptop
# start the graphical desktop environment by default on boot
sudo systemctl set-default graphical.target
# start desktop in console
startx
</code></pre>
<h2 id="21-关于防火墙或者包过滤">21. 关于防火墙或者包过滤</h2>
<p>Debian 11 默认使用 nftables 作为 netfilter 前端,使用 nft 命令进行管理,但是默认并没有启用。</p>
<p>Linux 内核嵌入了 netfilter 防火墙,可以从用户空间使用 iptables、ip6tables、arptables 和 ebtables 命令对其进行控制。然而,Netfilter iptables 命令正在被 nftables 取代,这避免了它的许多问题。它的设计涉及较少的代码重复,并且只需使用 nft 命令即可对其进行管理。</p>
<p>Debian Buster(即 Debian 10,包括 11)默认使用 nftables 框架。</p>
<p>要在 Debian 中启用默认防火墙,请执行:</p>
<pre><code class="language-shell"># apt install -y nftables
Reading package lists... Done
...
# systemctl enable nftables.service
Created symlink /etc/systemd/system/sysinit.target.wants/nftables.service → /lib/systemd/system/nftables.service.
</code></pre>
<p>关于 <code>nft</code> 命令的语法和用例,参看其他文章。</p><br><br>
来源:https://www.cnblogs.com/sysin/p/15169372.html
頁: [1]
查看完整版本: Debian 11 “bullseye” 安装笔记