如何将 Alpine Linux 3.17 升级到 3.18
在输入以下任何命令之前,请确保您已备份重要数据,然后再继续更新系统。保持系统的完整备份非常重要。Alpine Linux 是基于 musl libc 和 busybox 构建的。这使得它比传统的 GNU/Linux 发行版更小、更节省资源。容器所需的空间不超过 8 MB,最小安装到磁盘需要大约 130 MB 的存储空间。您不仅可以获得成熟的 Linux 环境,还可以从存储库中获得大量软件包。它也非常适合 Docker。
图 01:升级 Alpine Linux 硬盘安装
教程详细信息 | |
---|---|
难度等级 | 中间的 |
Root 权限 | 是的 |
要求 | Linux 终端 |
类别 | 包管理器 |
操作系统兼容性 | Alpine • Linux |
预计阅读时间 | 4 分钟 |
在开始升级过程之前,请备份所有关键数据、配置文件和数据库。示例或作者对任何数据丢失概不负责。
如何升级 Alpine Linux
当 Alpine Linux 安装到硬盘或云服务器时,升级到较新的稳定版本很容易:
- 通过运行以下命令将待处理的更新应用于现有安装:
# apk update
# apk upgrade - 编辑/etc/apk/repositories文件,运行:
# vi /etc/apk/repositories
- 手动更改版本号。例如,将 Alpine 3.17 更改为 3.18。
- 保存并关闭文件
- 通过运行获取最新索引
# apk update
- 升级所有 Alpine Linux 软件包:
# apk upgrade --available && sync
- 重启系统,运行:
# reboot
让我们详细了解所有命令和示例。
Alpine Linux 3.18.0 中的新功能
OpenSSL 3.0.x 现在是默认的 OpenSSL 版本。OpenSSL 1.1 可通过 openssl1.1-compat 包获得。安装脚本中的其他改进:
- Linux 内核 6.1 – 带有签名的内核模块
- musl libc 1.2.4 – 现在 DNS 解析器中具有 TCP 回退功能
- Python 3.12
- Ruby 3.2
- Node.js(当前)20.1
- GNOME 44
- Go 1.20
- KDE Plasma 5.27
- Rust 1.69
- 通过 tiny-cloud 进行无人值守安装的实验性支持
- bash 版本 5.2
- GCC 12.2
- 更好地支持 NVMe
- 管理员用户创建
- 可以添加 SSH 密钥
- 新的安装桌面脚本,可轻松安装桌面环境
- 基亚 2.2
- LLVM 15 和 16
- OpenSSL 3.1
- Perl 5.36.1
- PostgreSQL 12/13/14/15
- MariaDB 10.11
- Node.js (lts) 18.16
- Node.js(当前)20.1.0
- Ceph 17.2
- GNOME 43
- Go 1.19
- KDE Plasma 5.27
- Rust 1.69
- .NET 7.0.105
请参阅发行说明。
备份你的 LXD 容器
键入以下命令来创建容器快照:
$ lxc snapshot alpine-www01 "May112023-Before-Upgrade-To-3.18"
验证它:
$ lxc info alpine-www01
示例输出:
Name: alpine-www01 Status: RUNNING Type: container Architecture: x86_64 PID: 4660 Created: 2023/04/17 20:08 UTC Last Used: 2023/05/03 20:35 UTC Resources: Processes: 15 Disk usage: root: 92.66MiB CPU usage: CPU usage (in seconds): 586 Memory usage: Memory (current): 58.75MiB Memory (peak): 87.16MiB Network usage: eth0: Type: broadcast State: UP Host interface: veth6e30fae1 MAC address: 00:16:3e:9e:16:3e MTU: 1500 Bytes received: 126.34MB Bytes sent: 89.48MB Packets received: 412293 Packets sent: 458558 IP addresses: inet: 10.147.164.14/24 (global) inet6: fe80::216:3eff:fe9e:163e/64 (link) lo: Type: loopback State: UP MTU: 65536 Bytes received: 11.62MB Bytes sent: 11.62MB Packets received: 64980 Packets sent: 64980 IP addresses: inet: 127.0.0.1/8 (local) inet6: ::1/128 (local) Snapshots: +----------------------------------+----------------------+----------------------+----------+ | NAME | TAKEN AT | EXPIRES AT | STATEFUL | +----------------------------------+----------------------+----------------------+----------+ | autoupdate-2023-05-07-1683458842 | 2023/05/07 11:27 UTC | 2023/08/07 11:27 UTC | NO | +----------------------------------+----------------------+----------------------+----------+ | autoupdate-2023-05-09-1683636320 | 2023/05/09 12:45 UTC | 2023/08/09 12:45 UTC | NO | +----------------------------------+----------------------+----------------------+----------+ | May112023-Before-Upgrade-To-3.18 | 2023/05/10 20:55 UTC | 2023/08/10 20:55 UTC | NO | +----------------------------------+----------------------+----------------------+----------+
现在使用 ssh 命令或 lxc 命令登录到您的 Alpine Linux box/LXD VM。
了解您的 Alpine Linux 版本
键入以下cat 命令:
$ cat /etc/alpine-release
3.17.3
应用 3.17.xx 的所有待处理更新
只需运行apk 命令:
# apk update
# apk upgrade
(1/3) Upgrading bind-libs (9.16.33-r0 -> 9.16.36-r0) (2/3) Upgrading bind-tools (9.16.33-r0 -> 9.16.36-r0) (3/3) Upgrading linux-virt (5.15.84-r0 -> 5.15.85-r0) Executing busybox-1.35.0-r17.trigger Executing kmod-29-r2.trigger Executing mkinitfs-3.6.2-r0.trigger ==> initramfs: creating /boot/initramfs-virt Executing grub-2.06-r2.trigger Generating grub configuration file ... Found linux image: /boot/vmlinuz-virt Found initrd image: /boot/initramfs-virt Warning: os-prober will not be executed to detect other bootable partitions. Systems on them will not be added to the GRUB boot configuration. Check GRUB_DISABLE_OS_PROBER documentation entry. done Executing syslinux-6.04_pre1-r10.trigger /boot is device /dev/sda extlinux: no previous syslinux boot sector found OK: 270 MiB in 242 packages
# reboot
如何升级到最新版本
编辑/etc/apk/repositories文件,输入:
# vi /etc/apk/repositories
手动更改版本号。例如,3.17的默认条目如下:
http://dl-cdn.alpinelinux.org/alpine/v3.17/main
要更新到 3.18,请输入:
http://dl-cdn.alpinelinux.org/alpine/v3.18/main
保存并关闭文件。这是我使用cat 命令显示的示例配置文件:
# cat /etc/apk/repositories
这是我更新的文件:
http://dl-cdn.alpinelinux.org/alpine/v3.18/main http://dl-cdn.alpinelinux.org/alpine/v3.18/community
也可以使用存储库文件上的最后一个稳定版本。例如:
http://dl.alpinelinux.org/alpine/latest-stable/main http://dl.alpinelinux.org/alpine/latest-stable/community
当我使用 Ansible 更新我的 Alpine Linux 集群时,我避免设置最新的稳定版本。因此我需要手动验证,然后为多台服务器运行 Ansible 作业。
升级 alpine Linux
接下来,使用apk 命令获取最新索引:
# apk update
示例输出:
fetch http://dl-cdn.alpinelinux.org/alpine/v3.18/main/x86_64/APKINDEX.tar.gz fetch http://dl-cdn.alpinelinux.org/alpine/v3.18/community/x86_64/APKINDEX.tar.gz v3.18.0-46-gcefe67f85e7 [http://dl-cdn.alpinelinux.org/alpine/v3.18/main] v3.18.0-47-g3db66ae92e4 [http://dl-cdn.alpinelinux.org/alpine/v3.18/community] OK: 20323 distinct packages available
尝试通过模拟过程来检测升级问题以避免停机。因此,传递以下选项:
试运行输出:
# rm /etc/alpine-release
# apk upgrade --no-self-upgrade --available --simulate
(1/285) Upgrading musl (1.2.3-r4 -> 1.2.4-r0) (2/285) Upgrading acct (6.6.4-r1 -> 6.6.4-r2) (3/285) Upgrading alpine-baselayout-data (3.4.0-r0 -> 3.4.3-r1) (4/285) Upgrading busybox (1.35.0-r29 -> 1.36.0-r9) (5/285) Upgrading busybox-binsh (1.35.0-r29 -> 1.36.0-r9) (6/285) Upgrading alpine-baselayout (3.4.0-r0 -> 3.4.3-r1) ... .. ... (282/285) Upgrading wireguard-tools (1.0.20210914-r1 -> 1.0.20210914-r3) (283/285) Upgrading wireguard-tools-bash-completion (1.0.20210914-r1 -> 1.0.20210914-r3) (284/285) Upgrading wireguard-tools-doc (1.0.20210914-r1 -> 1.0.20210914-r3) (285/285) Purging ncurses-libs (6.3_p20221119-r0) OK: 330 MiB in 271 packages
如果没有发现问题或解决问题后,请启动正确的升级程序。因此,键入以下任一命令来升级所有软件包,运行apk 命令:
# apk upgrade --available
留意消息和警告:
Upgrading critical system libraries and apk-tools: (1/3) Upgrading musl (1.2.3-r4 -> 1.2.4-r0) (2/3) Upgrading apk-tools (2.12.10-r1 -> 2.14.0-r2) (3/3) Upgrading apk-tools-doc (2.12.10-r1 -> 2.14.0-r2) Executing busybox-1.35.0-r29.trigger Continuing the upgrade transaction with new apk-tools: (1/282) Upgrading acct (6.6.4-r1 -> 6.6.4-r2) (2/282) Upgrading alpine-baselayout-data (3.4.0-r0 -> 3.4.3-r1) (3/282) Upgrading busybox (1.35.0-r29 -> 1.36.0-r9) Executing busybox-1.36.0-r9.post-upgrade (4/282) Upgrading busybox-binsh (1.35.0-r29 -> 1.36.0-r9) (5/282) Upgrading alpine-baselayout (3.4.0-r0 -> 3.4.3-r1) .... .. ... (278/282) Upgrading ifupdown-ng-wireguard-quick (0.12.1-r1 -> 0.12.1-r2) (279/282) Upgrading wireguard-tools (1.0.20210914-r1 -> 1.0.20210914-r3) (280/282) Upgrading wireguard-tools-bash-completion (1.0.20210914-r1 -> 1.0.20210914-r3) (281/282) Upgrading wireguard-tools-doc (1.0.20210914-r1 -> 1.0.20210914-r3) (282/282) Purging ncurses-libs (6.3_p20221119-r0) Executing busybox-1.36.0-r9.trigger Executing awall-1.12.2-r0.trigger Executing ca-certificates-20230506-r0.trigger Executing kmod-30-r3.trigger Executing mkinitfs-3.8.0-r1.trigger ==> initramfs: creating /boot/initramfs-virt Executing grub-2.06-r11.trigger Generating grub configuration file ... Found linux image: /boot/vmlinuz-virt Found initrd image: /boot/initramfs-virt Warning: os-prober will not be executed to detect other bootable partitions. Systems on them will not be added to the GRUB boot configuration. Check GRUB_DISABLE_OS_PROBER documentation entry. done Executing syslinux-6.04_pre1-r13.trigger /boot is device /dev/sda extlinux: no previous syslinux boot sector found OK: 337 MiB in 284 packages
重新启动服务器/虚拟机容器:
验证它:
# sync
# reboot
$ cat /etc/alpine-release
3.18.0
请注意,在某些情况下 /etc/alpine-release 可能不会更新,因此查询:
cat /etc/alpine-release.apk-new
另一种方法是查询/etc/issue:
# cat /etc/issue
Welcome to Alpine Linux 3.18 Kernel \r on an \m (\l)
它的实际样子如下:
Welcome to Alpine Linux 3.18 Kernel 6.1.27-3-aws on an x86_64 (/dev/console) alpine-www01 login:
可以查询/etc/os-release:
# cat /etc/os-release
输出:
NAME="Alpine Linux" ID=alpine VERSION_ID=3.18.0 PRETTY_NAME="Alpine Linux v3.18" HOME_URL="https://alpinelinux.org/" BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"
检查Linux 内核版本,运行以下 uname 命令:使用grep 命令或cat 命令/tail 命令 /more 命令
检查日志文件:
使用 ss 命令或 netstat 命令确保所有端口都已打开:
# uname -mrs
Linux 5.15.85-0-virt x86_64
# tail -f /var/log/messages
# grep -i -E 'err|warn|alert' /var/log/my_app.log
# ss -tulpn
结论 - 升级 Alpine Linux
至此,Alpine Linux 从 3.17 版升级到了 3.18 版。更多信息请参见https://alpinelinux.org/。