" name="sm-site-verification"/>
侧边栏壁纸
博主头像
PySuper博主等级

千里之行,始于足下

  • 累计撰写 203 篇文章
  • 累计创建 14 个标签
  • 累计收到 1 条评论

目 录CONTENT

文章目录

Docker Web | Django + MySQL + Redis + uwsgi 部署DjangoWeb

PySuper
2021-09-16 / 0 评论 / 0 点赞 / 7 阅读 / 4105 字
温馨提示:
所有牛逼的人都有一段苦逼的岁月。 但是你只要像SB一样去坚持,终将牛逼!!! ✊✊✊
  • 将项目的各个模块拆分到Docker中
    • Project
    • MySQL
    • Redis
    • Nginx

Docker

# 配置源
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo

# 安装
yum -y install docker-ce

# 开机自启 重启
systemctl enable docker && systemctl start docker

# 配置镜像下载加速器
cat > /etc/docker/daemon.json << EOF
{
    "registry-mirrors": ["https://giuzc4qh.mirror.aliyuncs.com"]
}
EOF

# 重启 查看
systemctl restart docker 

Web

yum update -y
yum install -y wget git gcc make openssl openssl-devel zlib-devel libffi-devel python3-devel
wget https://www.python.org/ftp/python/3.8.10/Python-3.8.10.tar.xz
tar -xJf Python-3.8.10.tar.xz && cd Python-3.8.10 && ./configure --prefix=/usr/local/python3

vi Modules/Setup
#############  _ssl导入问题  ##############
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=/usr/local/ssl
_ssl _ssl.c \
       -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
       -L$(SSL)/lib -lssl -lcrypto
##########################################

make && make install && rm /usr/bin/python3 -rf && rm /usr/bin/pip3 -rf
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
pip3 install --upgrade pip && pip3 install setuptools_scm
pip3 install virtualenv && pip3 install virtualenvwrapper

vi ~/.bashrc
#############  虚拟环境  ##############
# 加入4行代码
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/python3/bin/virtualenv
source /usr/local/python3/bin/virtualenvwrapper.sh
######################################
source ~/.bashrc

mkvirtualenv test	# 创建爱你虚拟环境
workon test	# 进入虚拟环境
pip3 install uwsgi && pip3 install -r requirements.txt --no-dependencies
deactivate	# 退出虚拟环境

MySQL

docker run -dit \
--name mysql\	# 容器名
-h web-mysql \	# hostname
-p 13306:3306 \	# 暴露端口
-v /root/data/mysql/conf:/etc/mysql \	# 挂载数据目录
-v /root/data/mysql/mysql-files:/var/lib/mysql-files/ \
-v /root/data/mysql/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=root \	# 添加环境变量
--restart=on-failure \	# 重启策略
mysql:5.7	# 使用的镜像

Redis

docker run -dit \
--name redis \
-h web-redis \
-p 16379:6379 \
-v /root/data/redis/redis.conf:/etc/redis/redis.conf \
-v /root/data/redis/data:/data \
redis \
redis-server /etc/redis/redis.conf

Nginx

docker run -dit \
--name nginx \
-h web-nginx \
-p 80:80 \
-v /root/data/nginx/site.conf:/etc/nginx/cond.f/site.conf \
nginx

0

评论区