Un cadre de développement rapide pour organiser et déployer des microservices basés sur docker-compose

insérez la description de l'image ici
insérez la description de l'image ici

insérez la description de l'image ici

Préparation de base

Docker et Docker Compose ont été installés, chargez le package fourni Pig.tar.gz dans le répertoire master node /root et extrayez-le.

Page d'accueil du blog pour les ressources
insérez la description de l'image ici

Mise en œuvre du cas

1. Préparation de base de l'environnement

(1) Importer le package

Téléchargez et extrayez le package :

[root@master ~]# tar -xf Pig.tar.gz
[root@master ~]# ll Pig
total 206752
-rw------- 1 root root 211696640 Jan 12 17:24 CentOS_7.9.2009.tar
drwxr-xr-x 2 root root        85 Jan  5 08:58 mysql
drwxr-xr-x 3 root root        37 Jan  5 08:56 nginx
drwxr-xr-x 2 root root        97 Jan  5 08:56 service
drwxr-xr-x 3 root root     12288 Jan  5 08:56 yum

Importez l'image CentOS:7.9.2009 :

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

(2) Démarrer le cluster Kubernetes

Initialiser le cluster Kubernetes :
[root@master ~]# init-cluster
Afficher l'état du cluster :
[root@master ~]# kubectl cluster-info
Le plan de contrôle Kubernetes s'exécute sur https://apiserver.cluster.local:6443
CoreDNS s'exécute sur https://apiserver.cluster.local:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

Pour déboguer et diagnostiquer davantage les problèmes de cluster, utilisez "kubectl cluster-info dump".

2. Déploiement conteneurisé de MariaDB

(1) Ecrire Dockerfile

Écrivez le script init.sh :

[root@master ~]# cd Pig/
[root@master Pig]# 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 "source /opt/pig.sql;source /opt/pig_codegen.sql;source /opt/pig_config.sql;source /opt/pig_job.sql;"

Écrivez yum source :

[root@master Pig]# vi local.repo
[pig]
name=pig
baseurl=file:///root/yum
gpgcheck=0
enabled=1

Écrivez le Dockerfile :

[root@master Pig]# 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 /opt/
COPY mysql_init.sh /opt/
RUN bash /opt/mysql_init.sh
EXPOSE 3306
CMD ["mysqld_safe","--user=root"]

(2) Créer une image

Construisez l'image :

[root@master Pig]# docker build -t pig-mysql:v1.0 -f Dockerfile-mariadb .
Sending build context to Docker daemon  890.9MB
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
 ---> 4f07e082cc00
Step 5/12 : COPY yum /root/yum
 ---> Using cache
 ---> 7042f9e7f455
Step 6/12 : ENV LC_ALL en_US.UTF-8
 ---> Using cache
 ---> df0aa8985d61
Step 7/12 : RUN yum -y install mariadb-server
 ---> Using cache
 ---> 9ad09d62d373
Step 8/12 : COPY mysql /opt/
 ---> Using cache
 ---> 75adb0e3bbb0
Step 9/12 : COPY mysql_init.sh /opt/
 ---> Using cache
 ---> 3cc10e8ca0cc
Step 10/12 : RUN bash /opt/mysql_init.sh
 ---> Using cache
 ---> f7fe9f822cc3
Step 11/12 : EXPOSE 3306
 ---> Using cache
 ---> 70f2274acbeb
Step 12/12 : CMD ["mysqld_safe","--user=root"]
 ---> Using cache
 ---> f088fb18dedf
Successfully built f088fb18dedf
Successfully tagged pig-mysql:v1.0

3. Déploiement conteneurisé de Redis

(1) Ecrire Dockerfile


编写Dockerfile文件:
[root@master Pig]# vi Dockerfile-redis
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 -y install redis
RUN sed -i 's/127.0.0.1/0.0.0.0/g' /etc/redis.conf && \
     sed -i 's/protected-mode yes/protected-mode no/g' /etc/redis.conf
EXPOSE 6379
CMD ["/usr/bin/redis-server","/etc/redis.conf"]

(2) Créer une image

[root@master Pig]# docker build -t pig-redis:v1.0 -f Dockerfile-redis .
Sending build context to Docker daemon  890.9MB
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
 ---> 4f07e082cc00
Step 5/9 : COPY yum /root/yum
 ---> Using cache
 ---> 7042f9e7f455
Step 6/9 : RUN yum -y install redis
 ---> Using cache
 ---> 2d0b65ca48f0
Step 7/9 : RUN sed -i 's/127.0.0.1/0.0.0.0/g' /etc/redis.conf &&     sed -i 's/protected-mode yes/protected-mode no/g' /etc/redis.conf
 ---> Using cache
 ---> fcb84f12d0cf
Step 8/9 : EXPOSE 6379
 ---> Using cache
 ---> 37ac24f680d6
Step 9/9 : CMD ["/usr/bin/redis-server","/etc/redis.conf"]
 ---> Using cache
 ---> ee5f16785493
Successfully built ee5f16785493
Successfully tagged pig-redis:v1.0

4. Déploiement conteneurisé de Pig

(1) Ecrire Dockerfile

(2) Créer une image

5. Déploiement conteneurisé de services frontaux

(1) Ecrire Dockerfile

(2) Créer une image

6. Orchestrer et déployer la plateforme de développement rapide Pig

(1) Ecrire Dockerfile

(2) Créer une image

Je suppose que tu aimes

Origine blog.csdn.net/qq_45714272/article/details/124434333
conseillé
Classement