在已经可以正常运行docker环境的设备上。
设定问题:
LuaJIT
,Ngx_devel
和lua-nginx-module
docker run -it --name ubuntu --net=host --privileged=true ubuntu
因为后续测试nginx所以网络采用host方式
docker exec -it ubuntu bash
apt update
apt upgrade
apt gcc autoconf automake make
因为没有gcc-c++ 安装g++
apt install g++
apt install wget openssl
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
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
cd LuaJIT-2.0.5
make && make install
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.0
./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模块
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
cp objs/nginx /usr/sbin/
位置略有不同,自行修改
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镜像