如何将云服务器上的Ubuntu升级到最新版

第一步是购买服务器。国内有很多云服务器厂商,可以购买阿里或者腾讯的云服务器,速度不错。购买时会要求选择一个默认的操作系统,windows就不考虑了,因为Windows占用了太多的系统资源,速度慢,土豪请随意。考虑到我过去的经验,Ubuntu用起来比较熟悉,所以选择Ubuntu

第二步是配置操作系统。

https://cloud.tencent.com/developer/article/1174343

这里提供了升级操作系统的教程。基本套路也都很常规,先备份数据,然后升级系统,最后恢复数据。

腾讯的教程说可以利用腾讯云的快照来备份数据,但是我还是倾向于下载回来备份到本地。

更新当前安装的软件包

在开始版本升级之前,最安全的是更新到当前版本的所有软件包的最新版本。首先更新包列表:

sudo apt-get update

接下来,将已安装的软件包升级到其最新版本:

sudo apt-get upgrade

您将看到升级列表,并提示继续。回答y表示是,然后按Enter键。

此过程可能需要一些时间。一旦完成后,使用apt-get的dist-upgrade命令,它将执行涉及更改依赖关系,根据需要添加或删除新包的任何其他升级。

sudo apt-get dist-upgrade

再次,在提示继续时回答y,并等待升级完成。现在您已经安装了最新的软件包,您可以使用do-release-upgrade升级到18.04版本。

使用Ubuntu的do-release-upgrade工具进行升级

Ubuntu版本可以通过更改Apt /etc/apt/sources.list(可指定软件包存储库)以及apt-get dist-upgrade用于执行升级本身来升级。但Ubuntu提供了一个工具do-release-upgrade,可以更安全,更轻松升级。

do-release-upgrade处理检查新版本,更新sources.list和一系列其他任务。

首先运行do-release-upgrade

sudo do-release-upgrade

如果新的Ubuntu版本尚未正式发布,您可能会得到以下输出:

Checking for a new Ubuntu release
No new release found

如果是这种情况,请添加-d选项以升级到开发版本:

sudo do-release-upgrade -d

如果您通过SSH连接到系统,系统会询问您是否要继续。对于虚拟机或托管服务器,您应该记住,丢失SSH连接是一种风险,特别是如果您没有其他方法可以远程连接到系统的控制台。请记住,只有在您可以直接物理访问机器时才能最安全地执行主要操作系统升级。

在提示符下,键入y并按Enter继续:

Reading cache
​
Checking package manager
​
Continue running under SSH?
​
This session appears to be running under ssh. It is not recommended
to perform a upgrade over ssh currently because in case of failure it
is harder to recover.
​
If you continue, an additional ssh daemon will be started at port
'1022'.
Do you want to continue?
​
Continue [yN] y

接下来,您将被告知do-release-upgrade正在1022端口上启动sshd的新实例:

Starting additional sshd
​
To make recovery in case of failure easier, an additional sshd will
be started on port '1022'. If anything goes wrong with the running
ssh you can still connect to the additional one.
If you run a firewall, you may need to temporarily open this port. As
this is potentially dangerous it's not done automatically. You can
open the port with e.g.:
'iptables -I INPUT -p tcp --dport 1022 -j ACCEPT'
​
To continue please press [ENTER]

按Enter。接下来,可能会警告您找不到镜像条目。在腾讯云系统上,可以安全地忽略此警告并继续升级,因为18.04的本地镜像实际上是可用的。输入y

Updating repository information
​
No valid mirror found
​
While scanning your repository information no mirror entry for the
upgrade was found. This can happen if you run an internal mirror or
if the mirror information is out of date.
​
Do you want to rewrite your 'sources.list' file anyway? If you choose
'Yes' here it will update all 'xenial' to 'bionic' entries.
If you select 'No' the upgrade will cancel.
​
Continue [yN] y

下载新的软件包列表并计算更改,系统会询问您是否要开始升级。再次,输入y继续:

Do you want to start the upgrade?
​
​
6 installed packages are no longer supported by Canonical. You can
still get support from the community.
​
9 packages are going to be removed. 104 new packages are going to be
installed. 399 packages are going to be upgraded.
​
You have to download a total of 232 M. This download will take about
46 seconds with your connection.
​
Installing the upgrade can take several hours. Once the download has
finished, the process cannot be canceled.
​
 Continue [yN]  Details [d]y

现在系统将检索,解压缩和安装新包。即使您的系统处于快速连接状态,也需要一段时间。

在安装过程中,您可能会收到各种问题的交互式对话框。例如,系统可能会询问您是否要在需要时自动重新启动服务:

在这种情况下,回答“是”。在其他情况下,系统可能会询问您是否要替换已修改的配置文件。这通常是一个判断调用,可能需要有关本教程范围之外的特定软件的知识。

新软件包安装完成后,系统会询问您是否准备好删除过时的软件包。在没有自定义配置的库存系统上,在此处输入y。在您进行了大量修改的系统上,您可能希望输入d并检查要删除的软件包列表,以防它包含您稍后需要重新安装的任何内容。

Remove obsolete packages?
​
​
53 packages are going to be removed.
​
 Continue [yN]  Details [d]y

最后,一切顺利,您将被告知升级已完成并需要重新启动。输入y继续:

System upgrade is complete.
​
Restart required
​
To finish the upgrade, a restart is required.
If you select 'y' the system will be restarted.
​
Continue [yN] y

在SSH会话中,您可能会看到如下内容,您的SSH会话将在服务器端终止。:

Connection to 203.0.113.241 closed by remote host.
Connection to 203.0.113.241 closed.

等待服务器重启,然后重新连接。在登录时,您应该收到一条消息,

Welcome to Ubuntu 18.04 LTS (GNU/Linux 4.15.0-19-generic x86_64)

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值