【nginx】基于ubuntu制作nginx Lua镜像

前提

在已经可以正常运行docker环境的设备上。

基本思路

设定问题:

  1. 先了解nginx安装需要什么
  2. 支持lua需要什么 LuaJIT,Ngx_devellua-nginx-module
  3. gridsf需要什么
  4. 如何编译,编译指令参数有哪些,遇到问题如何解决
  5. 运行的镜像制作镜像
  6. 如何做到容器启动则nginx运行

步骤

1、运行基础ubuntu容器

docker run -it --name ubuntu --net=host --privileged=true ubuntu

因为后续测试nginx所以网络采用host方式

2、进入容器

docker exec -it ubuntu bash

3、apt升级及安装wget及相关库

apt update

apt upgrade

apt gcc autoconf automake make

因为没有gcc-c++  安装g++

apt install g++

apt install wget  openssl

4、下载各个依赖

wget http://nginx.org/download/nginx-1.19.2.tar.gz #下载nginx

wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz  #下载LuaJIT

wget https://github.com/simplresty/ngx_devel_kit/archive/v0.3.0.tar.gz  #下载ngx_devle_kit

wget https://github.com/openresty/lua-nginx-module/archive/v0.10.13.tar.gz  #下载lua_nginx_module

 

5、解压

tar xvf nginx-1.19.2.tar.gz

tar xvf v0.3.0.tar.gz  ngx_devel_kit-0.3.0

tar xvf v0.10.13.tar.gz lua-nginx-module-0.10.13

tar xvf LuaJIT-2.0.5.tar.gz

6、编译luajit 并设置环境变量

cd LuaJIT-2.0.5
make && make install
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.0

 

7、编译nginx

./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --add-module=/root/nginx-upstream-fair-master --add-module=/root/lua-nginx-module-0.10.13  --add-module=/root/ngx_devel_kit-0.3.0 --add-module=/root/nginx-gridfs-master 

make && make install
#参数说明
#--prefix 用于指定nginx编译后的安装目录
#--add-module 为添加的第三方模块,此次添加了fdfs的nginx模块
#--with..._module 表示启用的nginx模块,如此处启用了http_ssl_module模块   

8、错误

cc1: warnings being treated as errors
/usr/local/tools/gridfs-nginx-plugin/mongo-c-driver/src/bson.c: In function
‘bson_ensure_space’:
/usr/local/tools/gridfs-nginx-plugin/mongo-c-driver/src/bson.c:632: warning: comparison between signed and unsigned
make[1]: * [objs/addon/src/bson.o] Error 1
make[1]: Leaving directory `/home/mongo/nginx-1.7.9’
make: * [build] Error 2

需要在objs/Makefile 文件中 将 -Werror 参数去掉。意思是警告当做错误中断编译。

make && make install

9、拷贝文件

cp objs/nginx /usr/sbin/

位置略有不同,自行修改

10.nginx reload或者restart 如果报错

nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory

查看文件
cat /etc/ld.so.conf

include ld.so.conf.d/*.conf
执行命令:
echo “/usr/local/lib” >> /etc/ld.so.conf
和
ldconfig
再试试nginx reload或restart

nginx: [error] invalid PID number "" in "/run/nginx.pid" 解决方法

先执行nginx -c /etc/nginx/nginx.conf  (nginx.conf文件的路径可以从nginx -t的返回中找到。)

在执行nginx -s reload

以上不行,则执行ps -ef|grep nginx 找到进程id

kill -quit 进程id 或者kill -9 进程id

重新启动nginx

whoami 查看当前用户

11、如果用户不对则添加用户

mkdir -p /lua /registry /etc/nginx/conf.d/

12、根据容器制作镜像 docker commit

13、启动nginx shell 

touch /etc/init.d/nginx.sh

#!/bin/bash
# nginx


/usr/sbin/nginx -c /etc/nginx/nginx.conf


tail -f /dev/null
exit 0

13、新的镜像启动方式      

docker run -d --privileged=true -v /etc/hosts:/etc/hosts -v /sys/fs/cgroup:/sys/fs/cgroup -v /web/nginx/conf/default.conf:/etc/nginx/conf.d/default.conf -v /web/nginx/conf/nginx.conf:/etc/nginx/nginx.conf  -v /web/nginx/lua:/lua --net=host --restart=always --name nginx registry.hi-now.com.cn/mes/web:nginx_web_1_19_2a /bin/bash /etc/init.d/nginx.sh

 

留一个小话题:

这样配置是否有点复杂,能不能通过Dockfile制作nginx镜像

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值