跳转到主要内容

将 Ubuntu 22 升级到 Ubuntu 24

说明

本文将介绍如何将操作系统从 Ubuntu 22.04 升级到 Ubuntu 24.04

升级

警告

在升级操作系统之前,我们强烈建议对服务器上的所有数据进行完整备份。 这可作为出现问题时的保障,让您能够在紧急情况下恢复系统。

重要

OS 升级期间的所有命令都在服务器终端中以 root 用户身份执行。

拒绝系统替换配置文件的建议(默认操作)。

您操作系统中 /etc/apt/sources.list.d 内的仓库文件名称可能与本说明中使用的名称不同。

  1. 请确保 /etc/apt/sources.list 中配置了正确的仓库。 下面列出了 Ubuntu 22.04 的仓库列表。
Ubuntu 22 仓库
### Main repo for Ubuntu jammy
deb http://archive.ubuntu.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ jammy main restricted universe multiverse

### Updates repo for Ubuntu jammy
deb http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted universe multiverse

### Security repo for Ubuntu jammy
deb http://security.ubuntu.com/ubuntu jammy-security main restricted universe multiverse
deb-src http://security.ubuntu.com/ubuntu jammy-security main restricted universe multiverse

### Backports repo for Ubuntu jammy
deb http://archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse

### Proposed repo for Ubuntu jammy
deb http://archive.ubuntu.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ jammy-proposed main restricted universe multiverse
  1. 将所有当前软件包更新到最新版本
apt update && apt dist-upgrade
  1. 解决可能出现的 proftpd 和 apache2 升级错误
a2dismod php8.3

sed -e 's/^IdentLookups/#IdentLookups/' -i /etc/proftpd/proftpd.conf
  1. 运行升级
do-release-upgrade --allow-third-party

如果由于某种原因该工具未安装,您可以使用以下命令修复

apt install update-manager-core
重要

确认前请仔细阅读该工具的输出内容,确保在过程中不会删除任何不必要的内容。

如果系统提示您重启服务器,则表示升级成功。

接受重启

  1. 安装 PHP 8.3 及基础模块、PHP8.3-FPM 和 Apache2 模块
apt install -f php php-fpm libapache2-mod-php libapache2-mod-php8.3 php-common php8.3-cgi php8.3-cli php8.3-common php8.3-curl php8.3-gd php8.3-mbstring php8.3-mysql php8.3-opcache php8.3-readline php8.3-xml php8.3-xmlrpc php-imagick php-memcached

phpenmod calendar ctype curl dom exif fileinfo ftp gd gettext iconv mbstring mysqli mysqlnd pdo pdo_mysql phar posix readline shmop simplexml sockets sysvmsg sysvsem sysvshm tokenizer xml xmlreader xmlrpc xmlwriter xsl opcache imagick memcached
  1. 替换 PHP-FPM 配置
mv /opt/php83/etc/php-fpm.d/* /etc/php/8.3/fpm/pool.d/

rm /etc/php/8.1/fpm/pool.d/www.conf

mv /etc/php/8.1/fpm/pool.d/* /opt/php81/etc/php-fpm.d/
  1. 移除 PHP 8.1
apt purge php8.1*
  1. 启用 PHP 8.3
a2enmod php8.3
  1. 修正 FASTPANEL 数据库中的 PHP 版本
sqlite3 /usr/local/fastpanel2/app/db/fastpanel2.db "update site set php_version = 83 where mode = 'mpm_itk';"
  1. 安装接收邮件所需的 Dovecot 组件
apt install dovecot-lmtpd
  1. 重新配置服务
mogwai services configure -f
  1. 重启服务器
reboot
  1. 确保重启后所有服务均已启动
systemctl --failed

升级完成。