拉取镜像
docker pull centos
准备容器环境
在容器中操作
更新yum
yum update
安装环境
yum install -y python36 python36-devel gcc libevent-devel openssl-devel libffi-devel wget
pip3 install uwsgi gevent
安装uwsgi
pip3 install uwsgi gevent
复制文件到容器
docker cp 本地路径 容器id:容器路径
安装依赖
pip3 install -r requirements.txt --trusted-host https://repo.huaweicloud.com -i https://repo.huaweicloud.com/repository/pypi/simple
安装nginx
安装编译工具及库文件
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
安装 PCRE
PCRE 作用是让 Nginx 支持 Rewrite 功能
下载
cd /usr/local/src/
wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
解压
tar zxvf pcre-8.35.tar.gz
编译安装
cd pcre-8.35
./configure
make && make install
查看PCRE版本
pcre-config --version
安装nginx
安装
wget http://nginx.org/download/nginx-1.6.2.tar.gz
tar zxvf nginx-1.6.2.tar.gz
cd nginx-1.6.2
./configure
make && make install
启动nginx
cd /usr/local/nginx/sbin #nginx安装目录
./nginx
查看是否启动
ps -aux | grep nginx
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-vZDmqyTf-1630031646500)(http://markdowntc.wanqqq29.cn//image-20210811154044582.png)]
修改配置文件
vi /usr/local/nginx/conf/nginx.conf
server
{
listen 80;
listen 443 ssl http2;
server_name 你的域名;
charset urf-8;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8001; #8001对应uwsgi配置中的socket
}
}
刷新配置文件
./nginx -s reload
报错处理
1删除
make -f objs/Makefile
make[1]: Entering directory '/usr/local/src/nginx-1.6.2'
cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I /usr/local/src/pcre-8.35 -I objs \
-o objs/src/core/ngx_murmurhash.o \
src/core/ngx_murmurhash.c
src/core/ngx_murmurhash.c: In function 'ngx_murmur_hash2':
src/core/ngx_murmurhash.c:37:11: error: this statement may fall through [-Werror=implicit-fallthrough=]
h ^= data[2] << 16;
~~^~~~~~~~~~~~~~~~
src/core/ngx_murmurhash.c:38:5: note: here
case 2:
^~~~
src/core/ngx_murmurhash.c:39:11: error: this statement may fall through [-Werror=implicit-fallthrough=]
h ^= data[1] << 8;
~~^~~~~~~~~~~~~~~
src/core/ngx_murmurhash.c:40:5: note: here
case 1:
^~~~
cc1: all warnings being treated as errors
make[1]: *** [objs/Makefile:446: objs/src/core/ngx_murmurhash.o] Error 1
make[1]: Leaving directory '/usr/local/src/nginx-1.6.2'
make: *** [Makefile:8: build] Error 2
解决:进入到nginx-1.6.2目录下(解压的目录)
找到当前目录下找到objs文件夹,并进入,打开文件Makefile,找到有一下内容的这行:
vi objs/Makefile
CFLAGS = -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g
-Werror: gcc将所有的警告当成错误进行处理
把这行内容中的 “-Werror”去掉
2注释
sh-4.4# make && make install
make -f objs/Makefile
make[1]: Entering directory '/usr/local/src/nginx-1.6.2'
cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I /usr/local/src/pcre-8.35 -I objs \
-o objs/src/os/unix/ngx_user.o \
src/os/unix/ngx_user.c
src/os/unix/ngx_user.c: In function 'ngx_libc_crypt':
src/os/unix/ngx_user.c:35:7: error: 'struct crypt_data' has no member named 'current_salt'
cd.current_salt[0] = ~salt[0];
^
make[1]: *** [objs/Makefile:726: objs/src/os/unix/ngx_user.o] Error 1
make[1]: Leaving directory '/usr/local/src/nginx-1.6.2'
make: *** [Makefile:8: build] Error 2
解决:
进入到对应文件把报错行注释掉
编写运行脚本
#!/bin/bash
cd /usr/local/nginx/sbin
./nginx # 启动nginx进程
# 确认ngixn启动成功
ps -aux | grep nginx
#启动uwsgi确认
uwsgi -i /uwsgi.ini
netstat -tunlp
#tail 输出日志持续化
tail -f /tmp/uwsgi.log
提交容器
docker commit 容器id 镜像名
运行
docker run -p 80:80 容器id ./go.sh
访问ip
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-fgvwDf2p-1630031646503)(http://markdowntc.wanqqq29.cn//image-20210812134652921.png)]
?问题
-
执行django并暴露端口可以使用,uwsgi无效
解决:方案 使用tail命令对日志进行持续输出 保证在前台运行
-
保存docker镜像到本地
docker save 镜像id>本地路径\xxx.tar
-
导入docker镜像
docker load < xxx.tar
g-fgvwDf2p-1630031646503)]
?问题
-
执行django并暴露端口可以使用,uwsgi无效
解决:方案 使用tail命令对日志进行持续输出 保证在前台运行
-
保存docker镜像到本地
docker save 镜像id>本地路径\xxx.tar
-
导入docker镜像
docker load < xxx.tar