阿里云ECS ubuntu 14.04.5 LTS升级到ubuntu 16.04.2 LTS

ubuntu 16.04.2 LTS版本提供了PHP 7.0,这个版本的PHP拥有更好的性能,更低的资源开销,考虑了很久,终于决定还是把目前的ubuntu 14.04.5 LTS升级到ubuntu 16.04.2 LTS


一切顺利的话,简单执行如下命令即可:

$ sudo apt-get update

$ sudo apt-get upgrade

$ sudo apt-get dist-upgrade

$ sudo do-release-upgrade

但是,比较遗憾的是,我在执行升级的时候出错了,出错信息如下:

Calculating the changes

Could not calculate the upgrade

An unresolvable problem occurred while calculating the upgrade.

This can be caused by:

* Upgrading to a pre-release version of Ubuntu

* Running the current pre-release version of Ubuntu

* Unofficial software packages not provided by Ubuntu

If none of this applies, then please report this bug using the

command 'ubuntu-bug ubuntu-release-upgrader-core' in a terminal.

Restoring original system state

Aborting

Reading package lists... Done

Building dependency tree

Reading state information... Done

Building data structures... Done

=== Command detached from window (Sun May 21 15:33:44 2017) ===

执行如下命令,查看出错日志:

$ cat /var/log/dist-upgrade/main.log | grep failed

可以看到如下内容:

2017-05-21 15:33:15,901 DEBUG failed to SystemUnLock() (E:Not locked)

2017-05-21 15:33:36,116 ERROR Dist-upgrade failed: 'The essential package 'mount' is marked for removal.'

2017-05-21 15:33:36,118 DEBUG failed to SystemUnLock() (E:Not locked)

这说明mount这个包被锁定了,被锁定的原因是由于从ubuntu 12.04 LTS上阿里云设定的锁定,而恰好我的服务器就是先从ubuntu 12.04 LTS升级到ubuntu 14.04 LTS,因此这个设置被保留在了系统里面。
执行如下命令,查看包管理策略:

$ apt-cache policy

可以看到如下信息:

Pinned packages:

     mount -> 2.20.1-1ubuntu3

     linux-image-3.2.0-29-generic -> (not found)

信息显示,mount被锁定到了版本2.20.1上,导致无法升级替换。

我们执行如下命令移除锁定策略:

$ sudo mv /etc/apt/preferences.d /etc/apt/preferences.d.old

接下来继续执行升级命令:

$ sudo do-release-upgrade

一路回车,什么都不填,一切都不更改,大约20-30分钟之后,系统提示重启。
重启完成后,清理无用的安装包:

$ sudo apt-get autoremove

移除无效的php5-fpm(PHP已经升级到7.0版本,因此5.x版本的php-fpm已经可以移除)

$ sudo apt-get purge --auto-remove php5-fpm

$ sudo apt-get purge --auto-remove php-fpm

重新安装php-fpm

$ sudo apt-get install php7.0-fpm

$ sudo service php7.0-fpm start

接下来修改Apache的配置文件,更正php-fpmUnix Domain Socket路径:

$ sudo vim /etc/apache2/sites-enabled/000-default.conf

在文件中查找并修改如下信息:

SetHandler "proxy:unix:/var/run/php5-fpm.sock|fcgi://localhost"

修改为:

SetHandler "proxy:unix:/run/php/php7.0-fpm.sock|fcgi://localhost"

继续修改HTTPS的配置,这个配置文件可能是名为000-default-le-ssl.conf,也可能是default-ssl.conf,或者两个都存在,因此两个都要修改,并且保持一致。

$ sudo vim /etc/apache2/sites-enabled/000-default-le-ssl.conf

在文件中查找并修改如下信息:

SetHandler "proxy:unix:/var/run/php5-fpm.sock|fcgi://localhost"

修改为:

 SetHandler "proxy:unix:/run/php/php7.0-fpm.sock|fcgi://localhost"

继续

$ sudo vim /etc/apache2/sites-enabled/default-ssl.conf

在文件中查找并修改如下信息:

SetHandler "proxy:unix:/var/run/php5-fpm.sock|fcgi://localhost"

修改为:

SetHandler "proxy:unix:/run/php/php7.0-fpm.sock|fcgi://localhost"

启动Apache服务

$ sudo service apache2 start

注意,此时Apache默认被切换到了Prefork MPM工作模式,我们需要手工切换回到Event MPM工作模式。

正常情况下,这个版本的Apache可能默认启用了内嵌的PHP 7.0支持,可是这些默认的模块是不能在Event MPM模块下工作的,切换后启动时候会报告如下错误:

$ cat /var/log/syslog | grep Apache

May 22 10:46:12 apache2[25403]: [Mon May 22 10:46:12.731909 2017] [:crit] [pid 25414:tid 139656381421440] Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe.  You need to recompile PHP.

由于我们使用Proxy的方式来调用,因此,我们实际上是不需要Apache内置PHP解析模块的,那么我们需要卸载这些模块:

$ sudo apt-get remove libapache2-mod-php7.0

$ sudo apt-get remove libapache2-mod-php

这个版本(Apache 2.4.18)已经默认内置Event MPM了,因此,我们只需要简单的启用这个模块即可:

$ sudo a2dismod mpm_prefork

$ sudo a2enmod mpm_event

$ sudo service apache2 restart

切换完成后执行

$ a2query -M

即可查询到当前启用的模型了。

参考链接


[基础常识]将Ubuntu 14.04系统升级到 Ubuntu 16.04

发布者

《阿里云ECS ubuntu 14.04.5 LTS升级到ubuntu 16.04.2 LTS》上有4条评论

  1. 谢谢大神!今天给服务器从12.04升级到14.04,再从14.04升级到16.04,都是看的你的文章。所以,真的非常感谢!
    我比较好奇的一点是,你是怎么知道要使用 `apt-cache policy` 来查看被锁住的package的呢?然后发现 `mount` 被锁定了之后,你是怎么知道要使用 `sudo mv /etc/apt/preferences.d /etc/apt/preferences.d.old` 来解除锁定的呢?希望能了解一下你的思路是怎么样的。

    1. 报告的错误信息中有‘lock’相关的内容的,只是提示非常不明确而已,也是试过很多,最后到目录下逐个分析配置文件才找到的原因

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注