跳转到主要内容

将 Ubuntu 18 升级到 Ubuntu 20

说明

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

升级

警告

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

重要

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

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

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

  1. 请确保 /etc/apt/sources.list 中的仓库配置正确。 Ubuntu 18.04 的仓库列表见下方。
Ubuntu 18 仓库
### Main repo for Ubuntu bionic
deb http://archive.ubuntu.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ bionic main restricted universe multiverse

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

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

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

### Proposed repo for Ubuntu bionic
deb http://archive.ubuntu.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ bionic-proposed main restricted universe multiverse
  1. 将当前所有软件包更新到最新版本
apt update && apt dist-upgrade
  1. 解决可能出现的 proftpd 和 apache2 升级错误
a2dismod php7.2
sed -e 's/^IdentLookups/#IdentLookups/' -i /etc/proftpd/proftpd.conf
  1. 从 mysql 配置中删除所有 query-cache 条目,并调整 mysql 仓库:
sed -i 's/^query[_,-]cache[^ ]*//' /etc/mysql/my.cnf.fastpanel/99-fastpanel.cnf
  1. 运行更新
do-release-upgrade --allow-third-party

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

apt install update-manager-core
重要

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

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

接受重启

  1. 安装 PHP 7.4、基础模块、PHP7.4-FPM 以及 Apache2 的模块
apt-get install -f php php-fpm libapache2-mod-php libapache2-mod-php7.4 php-common php7.4-cgi php7.4-cli php7.4-common php7.4-curl php7.4-gd php7.4-json php7.4-mbstring php7.4-mysql php7.4-opcache php7.4-readline php7.4-xml php7.4-xmlrpc php-imagick php-memcached

phpenmod calendar ctype curl dom exif fileinfo ftp gd gettext json 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/php74/etc/php-fpm.d/* /etc/php/7.4/fpm/pool.d/
rm /etc/php/7.2/fpm/pool.d/www.conf
mv /etc/php/7.2/fpm/pool.d/* /etc/php/7.4/fpm/pool.d/
  1. 修正 FASTPANEL 数据库中的 PHP 版本
sqlite3 /usr/local/fastpanel2/app/db/fastpanel2.db "update site set php_version = 74 where mode = 'mpm_itk';"
  1. 安装接收邮件所需的 Dovecot 组件
apt install dovecot-lmtpd
  1. 重新配置服务
mogwai services configure -f
  1. 根据所使用的数据库服务器进行附加配置

对于 MySQL 8 - 添加兼容性设置

echo 'disable-log-bin
mysqlx = OFF
default-authentication-plugin = mysql_native_password
character-set-server = utf8
collation-server = utf8_unicode_ci
' >> /etc/mysql/my.cnf.fastpanel/99-fastpanel.cnf

对于 MariaDB - 运行 mysql_upgrade

mysql_upgrade
  1. 重启服务器
reboot
  1. 确保所有服务在重启后均已启动
systemctl --failed

升级完成。