[每周一更]-(第6期):Ubuntu 16.04 升级nginx 1.10到nginx1.22历程

  • Post author:
  • Post category:其他


在这里插入图片描述



ubuntu 系统升级:Ubuntu 16.04 64位 升级

注意事项

ECS实例更换操作系统后,云盘ID会变更,原系统盘会被释放,数据会丢失且无法找回。

请注意:

您原系统盘的用户快照会保留,自动快照则根据您该系统盘属性值“自动快照是否随云盘释放”的选项来判断是否保留或随云盘删除;您可以进入云盘列表点击“修改属性”查看或修改属性值。

自动快照策略将失效,需要重新设置。

您在操作前可通过创建快照做好相关备份,以免数据丢失给你造成损失。

  • 在阿里云平台进行停机升级操作系统

第一步由于升级系统造成系统丢失,即便有快照,但是带来的问题未知,所以采用下面的方案:



Ubuntu nginx 源码编译升级



1、下载最新版

wget https://nginx.org/download/nginx-1.22.0.tar.gz



2、开始配置

  • 由于旧版本是默认nginx安装路径,这里我们不更换
  • make失败
./configure --prefix=/usr/share/nginx --group=www-data --user=www-data --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log  --pid-path=/run/nginx.pid --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module --with-stream --without-http_rewrite_module  --with-pcre=/home/humx/nginx-1.22.0/auto/lib/pcre
  • 禁用模块 http_rewrite_module – make失败
./configure --prefix=/usr/share/nginx --group=www-data --user=www-data --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log  --pid-path=/run/nginx.pid --without-http_rewrite_module
  • 下载新的pcre,make成功- 采用这个
# pcre2
./configure --prefix=/usr/share/nginx --group=www-data --user=www-data --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log  --pid-path=/run/nginx.pid --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module --with-stream --without-http_rewrite_module  --with-pcre=/home/humx/pcre2-10.40
# pcre
./configure --prefix=/usr/share/nginx --group=www-data --user=www-data --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log  --pid-path=/run/nginx.pid --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module --with-stream --without-http_rewrite_module  --with-pcre=/home/humx/pcre-8.45
  • configure 成功:
Configuration summary
  + using PCRE library: /home/humx/pcre2-10.40
  + using system OpenSSL library
  + using system zlib library

  nginx path prefix: "/usr/share/nginx"
  nginx binary file: "/usr/sbin/nginx"
  nginx modules path: "/usr/share/nginx/modules"
  nginx configuration prefix: "/etc/nginx"
  nginx configuration file: "/etc/nginx/nginx.conf"
  nginx pid file: "/run/nginx.pid"
  nginx error log file: "/var/log/nginx/error.log"
  nginx http access log file: "/var/log/nginx/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"



3、升级nginx

  • 命令执行
make
  • 完成后进行如下操作升级

    • 1、备份旧nginx执行文件: mv /usr/sbin/nginx /usr/sbin/nginx_$(date +%F)
    • 2、拷贝新nginx执行文件: cp /home/humx/nginx-1.22.0/objs/nginx /usr/sbin/
    • 3、杀死旧的nginx,重启新的nginx
    • 3、nginx -V,看到新版本



make完结果,这里表示成功,不要make install

sed -e "s|%%PREFIX%%|/usr/share/nginx|" \
	-e "s|%%PID_PATH%%|/run/nginx.pid|" \
	-e "s|%%CONF_PATH%%|/etc/nginx/nginx.conf|" \
	-e "s|%%ERROR_LOG_PATH%%|/var/log/nginx/error.log|" \
	< man/nginx.8 > objs/nginx.8
make[1]: Leaving directory '/home/humx/nginx-1.16.1'



报错汇总



错误0:配置项目http跳转https

nginx: [emerg] "return" directive is not allowed here in /etc/nginx/clinical/community_backend.conf:39

  • 还需要基础排查找原因,待处理,现在http跳转https待完善



报错1:

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

解决方案:

原因:缺少 pcre

  • 1、安装pcre

本地找不到,接着换方案

apt-get install pcre-devel
apt-get install libpcre3-dev


sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev

apt-get install openssl libssl-dev
  • 2、安装pcre失败,就手动指定

查询一下,发现nginx已经有了自带pcre

find / -name "pcre"

于是指定pcre路径运行 ./configure
./configure --with-pcre=/usr/local/nginx/nginx-1.13.6/auto/lib/pcre
- make失败,换方案
  • 3、禁用 –without-http_rewrite_module

    • make失败,换方案
  • 4、下载新的pcre,重新configure

下载pcre2:wget https://github.com/PCRE2Project/pcre2/releases/download/pcre2-10.40/pcre2-10.40.tar.gz  - 对应nginx1.22.0

解压指定目录,在configure中指定配置位置:--with-pcre=/home/humx/pcre

下载pcre:wget https://sourceforge.net/projects/pcre/files/pcre/8.45/pcre-8.45.tar.gz/download - 对应nginx1.16

https://sourceforge.net/projects/pcre/files/pcre/8.45/pcre-8.45.tar.gz/download

解压指定目录,在configure中指定配置位置:--with-pcre=/home/humx/pcre-8.45



报错2:

看到这个错误,说明第一个错误已解决,这个错误缺少GD库就继续指定;

find / -name "gd"

./configure: error: the HTTP image filter module requires the GD library.
You can either do not enable the module or install the libraries.

解决方案

  • 直接安装失败,找不到
apt install gd gd-devel
-----

E: Unable to locate package gd
E: Unable to locate package gd-devel
  • 如果在安装libgd-dev时提示找不到 还是失败
在 vim /etc/apt/sources.list 中添加一行ubuntu 的镜像源
deb http://security.ubuntu.com/ubuntu trusty-security main
  • 去掉:–with-http_image_filter_module



其他采用apt-get方式更新(版本原因未生效)

这种只能更新系统默认的nginx 1.10

# 先在/etc/apt/sources.list添加下面两行

deb http://nginx.org/packages/ubuntu/ lucid nginx
deb-src http://nginx.org/packages/ubuntu/ lucid nginx

apt-get install nginx 



在终端上执行以下命令。

cd /tmp

wget http://nginx.org/keys/nginx_signing.key

sudo apt-key add nginx_signing.key

sudo sh -c "echo 'deb http://nginx.org/packages/stable/ubuntu/ '$(lsb_release -cs)' nginx' > /etc/apt/sources.list.d/Nginx.list"

sudo apt-get update

sudo apt-get dist-upgrade



版权声明:本文为hmx224_2014原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。