基于docker-compose+Django编排部署博客系统

基于docker-compose+Django编排部署博客系统

  • 基础准备
  • 实施
  • 1.基础环境准备
    • (1)导入软件包
    • (2)启动Kubernetes集群
  • 2.容器化部署Memcached
    • (1)编写Dockerfile
    • (2)构建镜像
  • 3. 容器化部署MariaDB
    • (1)编写Dockerfile
    • (2)构建镜像
  • 4.容器化部署前端服务
    • (1)编写Dockerfile
    • (2)构建镜像
  • 5.容器化部署博客系统
    • (1)编写Dockerfile
    • (2)构建镜像
  • 6.编排部署DjangoBlog
    • (1)编写docker-compose.yaml
    • (2)构建镜像

基于docker-compose+Django编排部署博客系统_第1张图片

基于docker-compose+Django编排部署博客系统_第2张图片

基础准备

Docker和Docker Compose已安装完成,将提供的软件包DjangoBlog.tar.gz上传至master节点/root目录下并解压。

博客主页获取资源
基于docker-compose+Django编排部署博客系统_第3张图片

实施

1.基础环境准备

(1)导入软件包

下载并解压软件包:
[root@master ~]# tar -xf DjangoBlog.tar.gz
[root@master ~]# ll DjangoBlog
total 229260
drwxr-xr-x 4 root root       219 Jan 10 01:48 accounts
drwxr-xr-x 3 root root        60 Jan 10 01:48 bin
drwxr-xr-x 6 root root       301 Jan 10 01:49 blog
-rw------- 1 root root 211696640 Jan 12 16:49 CentOS_7.9.2009.tar
drwxr-xr-x 9 root root       105 Jan 10 01:50 collectedstatic
drwxr-xr-x 4 root root       190 Jan 10 01:50 comments
drwxr-xr-x 2 root root       292 Jan 10 01:50 djangoblog
-rw-r--r-- 1 root root       808 Jan  7 15:34 manage.py
-rw-r--r-- 1 root root      1090 Jan  7 09:58 nginx.conf
drwxr-xr-x 4 root root       197 Jan 10 01:50 oauth
drwxr-xr-x 3 root root       138 Jan 10 01:50 owntracks
-rw-r--r-- 1 root root  22994617 Jan  7 15:35 Python-3.6.5.tgz
drwxr-xr-x 2 root root      4096 Jan 10 01:50 Python-pip
-rw-r--r-- 1 root root       493 Jan  7 15:35 requirements.txt
drwxr-xr-x 4 root root       191 Jan 10 01:50 servermanager
-rw-r--r-- 1 root root     32061 Jan 12 00:40 sqlfile.sql
drwxr-xr-x 9 root root       113 Jan 10 01:50 templates
drwxr-xr-x 6 root root     16384 Jan 10 01:52 yum

导入CentOS:7.9.2009镜像:

[root@master ~]# docker load -i DjangoBlog/CentOS_7.9.2009.tar 
Loaded image: centos:centos7.9.2009

(2)启动Kubernetes集群

初始化Kubernetes集群:

[root@master ~]# init-cluster

查看集群状态:

[root@master ~]# kubectl cluster-info
Kubernetes control plane is running at https://apiserver.cluster.local:6443
CoreDNS is running at https://apiserver.cluster.local:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

2.容器化部署Memcached

(1)编写Dockerfile

编写yum源配置文件:

[root@master ~]# cd DjangoBlog/
[root@master DjangoBlog]# vi local.repo 
[yum]
name=yum
baseurl=file:///root/yum
gpgcheck=0
enabled=1
编写Dockerfile:
[root@master DjangoBlog]# vi Dockerfile-memcached
FROM centos:centos7.9.2009
MAINTAINER Chinaskills
RUN rm -rf /etc/yum.repos.d/*
COPY local.repo /etc/yum.repos.d/
COPY yum /root/yum
RUN yum install libevent libevent-devel -y
RUN yum install memcached -y
EXPOSE 11211
ENTRYPOINT /usr/bin/memcached -u root

(2)构建镜像

构建镜像:
[root@master DjangoBlog]# docker build -t blog-memcached:v1.0 -f Dockerfile-memcached .
Sending build context to Docker daemon    606MB
Step 1/9 : FROM centos:centos7.9.2009
 ---> eeb6ee3f44bd
Step 2/9 : MAINTAINER Chinaskills
 ---> Using cache
 ---> 815a4a5f2242
Step 3/9 : RUN rm -rf /etc/yum.repos.d/*
 ---> Using cache
 ---> 6afa0315cb5b
Step 4/9 : COPY local.repo /etc/yum.repos.d/
 ---> Using cache
 ---> 140618900604
Step 5/9 : COPY yum /root/yum
 ---> Using cache
 ---> ad30591b1d15
Step 6/9 : RUN yum install libevent libevent-devel -y
 ---> Using cache
 ---> 8299be2cb3bf
Step 7/9 : RUN yum install memcached -y
 ---> Using cache
 ---> 439f91db606c
Step 8/9 : EXPOSE 11211
 ---> Using cache
 ---> c56ab6056bac
Step 9/9 : ENTRYPOINT /usr/bin/memcached -u root
 ---> Using cache
 ---> 9945bb68cac2
Successfully built 9945bb68cac2
Successfully tagged blog-memcached:v1.0

3. 容器化部署MariaDB

(1)编写Dockerfile

编写数据库初始化脚本:
[root@master DjangoBlog]# vi mysql_init.sh 
#!/bin/bash
mysql_install_db --user=root
mysqld_safe --user=root &
sleep 8
mysqladmin -u root password 'root'
mysql -uroot -proot -e "grant all on *.* to 'root'@'%' identified by 'root';flush privileges;"
mysql -uroot -proot -e "create database djangoblog;use djangoblog;source /opt/sqlfile.sql;"
编写Dockerfile文件:
[root@master DjangoBlog]# vi Dockerfile-mariadb 
FROM centos:centos7.9.2009
MAINTAINER Chinaskills
RUN rm -rf /etc/yum.repos.d/*
COPY local.repo /etc/yum.repos.d/
COPY yum /root/yum
ENV LC_ALL en_US.UTF-8
RUN yum -y install mariadb-server
COPY mysql_init.sh /opt/
COPY sqlfile.sql /opt
RUN bash /opt/mysql_init.sh
EXPOSE 3306
CMD ["mysqld_safe","--user=root"]

(2)构建镜像

构建镜像:
[root@master DjangoBlog]# docker build -t blog-mysql:v1.0 -f Dockerfile-mariadb .
Sending build context to Docker daemon    606MB
Step 1/12 : FROM centos:centos7.9.2009
 ---> eeb6ee3f44bd
Step 2/12 : MAINTAINER Chinaskills
 ---> Using cache
 ---> 815a4a5f2242
Step 3/12 : RUN rm -rf /etc/yum.repos.d/*
 ---> Using cache
 ---> 6afa0315cb5b
Step 4/12 : COPY local.repo /etc/yum.repos.d/
 ---> Using cache
 ---> 140618900604
Step 5/12 : COPY yum /root/yum
 ---> Using cache
 ---> ad30591b1d15
Step 6/12 : ENV LC_ALL en_US.UTF-8
 ---> Using cache
 ---> 026865489eec
Step 7/12 : RUN yum -y install mariadb-server
 ---> Using cache
 ---> c691328d736e
Step 8/12 : COPY mysql_init.sh /opt/
 ---> Using cache
 ---> 34b4926a933f
Step 9/12 : COPY sqlfile.sql /opt
 ---> Using cache
 ---> ad9022ea65b5
Step 10/12 : RUN bash /opt/mysql_init.sh
 ---> Using cache
 ---> c5aee98993f5
Step 11/12 : EXPOSE 3306
 ---> Using cache
 ---> 0a4e28e2bcdb
Step 12/12 : CMD ["mysqld_safe","--user=root"]
 ---> Using cache
 ---> 387f6dcb21bb
Successfully built 387f6dcb21bb
Successfully tagged blog-mysql:v1.0

4.容器化部署前端服务

(1)编写Dockerfile

(2)构建镜像

5.容器化部署博客系统

(1)编写Dockerfile

(2)构建镜像

6.编排部署DjangoBlog

(1)编写docker-compose.yaml

(2)构建镜像

你可能感兴趣的:(#,微服务,django,docker,容器,云原生,kubernetes)