站长视角
用户至上

如何将搬瓦工VPS服务器从 Ubuntu 20.04 升级到 Ubuntu 22.04?

优质广告位招租,欢迎联系站长

前几天介绍了搬瓦工后台已经新增了 Ubuntu 22.04,那么如果我们目前使用的是 Ubuntu 20.04,也可以直接升级到 Ubuntu 22.04,但是一般不建议生产环境下直接这么升级,可能会出现问题。本文介绍 Ubuntu 22.04 升级教程,主要是从 Ubuntu 20.04 升级到 Ubuntu 22.04 的教程。如果是更老的 Ubuntu 版本,可能需要先升级到 Ubuntu 20.04 或者是建议备份一下建站环境和数据之后直接安装 Ubuntu 22.04 吧。

如何将搬瓦工VPS服务器从 Ubuntu 20.04 升级到 Ubuntu 22.04?

重要提醒:

  1. 不建议直接在生产环境进行升级
  2. 升级前一定要做好数据备份

Ubuntu 22.04 升级前准备

除非你是物理服务器,以及没有用过奇奇怪怪定制或修改的内核的 KVM 构架的 VPS 和云主机,否则升级大版本更新内核是有一定机率导致 Grub 加载失败的,切记备份重要数据!

以下操作需要在 root 用户下完成,请使用 sudo -i 或 su root 切换到 root 用户进行操作。

首先升级系统到最新状态:

apt update
apt upgrade -y
apt dist-upgrade -y
apt autoclean
apt autoremove -y

升级之后需要进行重启,建议重启让最新的内核生效。

Ubuntu 22.04 升级方法一

第一种方法是使用 do-release-upgrade 命令,这个方法比较简单,一般来说可以首选这个方法。

首先安装 update-manager-core 软件包:

apt install update-manager-core

然后运行 do-release-upgrade -d 即可更新。按照提示操作即可。

Ubuntu 22.04 升级方法二

还有一种就是手工修改 apt 源文件:

首先更新 apt 源,替换 focal 为 jammy:

sed -i 's/focal/jammy/g' /etc/apt/sources.list
sed -i 's/focal/jammy/g' /etc/apt/sources.list.d/*.list

默认的系统 apt 源文件 /etc/apt/sources.list 应该是类似这样的:

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://archive.ubuntu.com/ubuntu/ jammy main restricted
# deb-src http://archive.ubuntu.com/ubuntu/ jammy main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted
# deb-src http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://archive.ubuntu.com/ubuntu/ jammy universe
# deb-src http://archive.ubuntu.com/ubuntu/ jammy universe
deb http://archive.ubuntu.com/ubuntu/ jammy-updates universe
# deb-src http://archive.ubuntu.com/ubuntu/ jammy-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://archive.ubuntu.com/ubuntu/ jammy multiverse
# deb-src http://archive.ubuntu.com/ubuntu/ jammy multiverse
deb http://archive.ubuntu.com/ubuntu/ jammy-updates multiverse
# deb-src http://archive.ubuntu.com/ubuntu/ jammy-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
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

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu jammy partner
# deb-src http://archive.canonical.com/ubuntu jammy partner

deb http://archive.ubuntu.com/ubuntu jammy-security main restricted
# deb-src http://archive.ubuntu.com/ubuntu jammy-security main restricted
deb http://archive.ubuntu.com/ubuntu jammy-security universe
# deb-src http://archive.ubuntu.com/ubuntu jammy-security universe
deb http://archive.ubuntu.com/ubuntu jammy-security multiverse
# deb-src http://archive.ubuntu.com/ubuntu jammy-security multiverse

国内服务器可以替换 archive.ubuntu.com 为 mirrors.tuna.tsinghua.edu.cn

然后我们再次执行更新系统:

apt update
apt upgrade -y
apt dist-upgrade -y

更新过程种会提示一些软件是否需要自动重启,选 Yes 即可,以及一些软件的配置文件是否需要更新,按照自己的情况选择即可,默认回车即视为使用旧的配置文件,一般会出现在 OpenSSH 等软件的更新上。

更新后删除不必要的软件和依赖:

apt autoclean
apt autoremove -y

然后使用 reboot 命令重启系统,耐心等待后,查看最新的系统版本:

root@ubuntu ~ # lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04 LTS
Release:        22.04
Codename:       jammy
root@ubuntu ~ # uname -a
Linux ubuntu 5.15.0-25 #4-Ubuntu SMP Fri Apr 1 07:36:38 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

这时我们就已经更新到了最新的 Ubuntu 22.04 Jammy 和内核了。

参考:https://u.sb/ubuntu-upgrade/

Ubuntu 桌面版升级教程

在 2022 年 4 月 21 日当天或之后,直到 2022 年 07 月第一次修正版本发布,Ubuntu 都不会给予你任何可视化的升级提示,因为第一个修改版本被认为是初始错误被消除后最稳定的版本。

这意味着,你要么等到 7 月,你要么强制升级。如何强制升级?打开“软件和更新 Software and Updates”,转到“更新 Updates”标签页。更改“通知我有新的 Ubuntu 版本 Settings notify me of new ubuntu version” 为 “任意新的 Ubuntu 版本 any new version”。

在完成后,你应该会在桌面上看到一个升级提示。遵循屏幕上的指示,接着继续升级过程。

这个提示也会计算升级系统所列软件包所需的时间,因此,仔细的阅读更新程序的输出内容。在你准备好了以后,开始升级过程。

最后,在升级过程完成后,重新启动系统,享受全新的 Ubuntu 22.04 LTS Jammy Jellyfish。

参考:https://os.51cto.com/article/706965.html

搬瓦工推荐方案

温馨提醒 如果您有选择困难症,直接选中间的 CN2 GIA-E方案,季付 $49.99,多达 12 个机房任意切换
方案 内存 CPU 硬盘 流量/月 带宽 机房 价格 购买
CN2
(最便宜)
1GB 1核 20GB 1TB 1Gbps DC3 CN2
DC8 ZNET
$49.99/年 直达
CN2 2GB 1核 40GB 2TB 1Gbps $52.99/半年
$99.99/年
直达
CN2 GIA-E
(最推荐)
1GB 2核 20GB 1TB 2.5Gbps DC6 CN2 GIA-E
DC9 CN2 GIA
日本软银 JPOS_1
荷兰 EUNL_9
$49.99/季度
$169.99/年
直达
CN2 GIA-E 2GB 3核 40GB 2TB 2.5Gbps $89.99/季度
$299.99/年
直达
HK 2GB 2核 40GB 0.5TB 1Gbps 中国香港 CN2 GIA $89.99/月
$899.99/年
直达
HK 4GB 4核 80GB 1TB 1Gbps $155.99/月
$1559.99/年
直达
TOKYO 2GB 2核 40GB 0.5TB 1.2Gbps 日本东京 CN2 GIA $89.99/月
$899.99/年
直达
TOKYO 4GB 4核 80GB 1TB 1.2Gbps $155.99/月
$1559.99/年
直达
搬瓦工优惠码:BWH3HYATVBJW 搬瓦工全方案实时库存检测
赞(1)
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权, 转载请注明出处。
文章名称:《如何将搬瓦工VPS服务器从 Ubuntu 20.04 升级到 Ubuntu 22.04?》
文章链接:https://cnidc.co/31032.html
【声明】:国外主机测评仅分享信息,不参与任何交易,也非中介,所有内容仅代表个人观点,均不作直接、间接、法定、约定的保证,读者购买风险自担。一旦您访问国外主机测评,即表示您已经知晓并接受了此声明通告。
【关于安全】:任何 IDC商家都有倒闭和跑路的可能,备份永远是最佳选择,服务器也是机器,不勤备份是对自己极不负责的表现,请保持良好的备份习惯。
香港110M(含10M CN2)大带宽独服限量促销,香港E3-8G-1T硬盘-3IP,月付仅799!

登录

找回密码

注册