wordpress编排
在master 节点上编写/root/wordpress/docker-compose.yaml文件,具体要求如下:
(1)容器名称:wordpress;镜像:wordpress:latest;端口映射:82:80;
(2)容器名称:mysql;镜像:mysql:5.6;
(3)MySQL root 用户密码:123456;
(4)创建数据库wordpress。
version: '3.3'
services:
mysql:
image: mysql:5.6
expose:
- 3306
restart: always
environment:
- MYSQL_ROOT_PASSWORD=123456
wordpress:
image: wordpress
ports:
- 82:80
restart: always
environment:
- WORDPRESS_DB_HOST=mysql
- WORDPRESS_DB_USER=root
- WORDPRESS_DB_PASSWORD=123456
web 商城应用编排
容器化部署MariaDB
在master 节点上编写/root/mariadb/Dockerfile 文件,基于提供的软件包gpmall-single.tar 构建chinaskill-mariadb:v1.1 镜像,具体要求如下:
(1)基础镜像:centos:centos7.5.1804;
(2)作者:Chinaskill;
(3)设置数据库密码:123456;
(4)创建数据库gpmall 并导入数据库文件gpmall.sql;
(5)设置字符编码:UTF-8;
(6)开放端口:3306;
(7)设置服务开机自启。
FROM centos:centos7.5.1804
MAINTAINER Chinaskill
RUN rm -rf /etc/yum.repos.d/*
ADD ftp.repo /etc/yum.repos.d/
RUN yum clean all && yum list
RUN yum install -y mariadb-server
ADD gpmall.sql .
ADD init.sh .
RUN chmod +x init.sh
ENV LC_ALL en_US.UTF-8
RUN sed -i "13cport = 8066" /etc/my.cnf.d/server.cnf
RUN ./init.sh
EXPOSE 3306 8066
CMD ["mysqld_safe"]
mysql_install_db --user=mysql
mysqld_safe &
sleep 3s
mysqladmin -u root password '123456'
sleep 3s
mysql -uroot -p123456 -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456'"
sleep 3s
mysql -uroot -p123456 -e "create database gpmall;use gpmall;"
mysql -uroot -p123456 gpmall < gpmall.sql
容器化部署Redis
在master 节点上编写/root/redis/Dockerfile 文件,基于提供的软件包gpmall-single.tar 构建chinaskill-redis:v1.1 镜像,具体要求如下:
(1)基础镜像:centos:centos7.5.1804;
(2)作者:Chinaskill;
(3)修改配置文件中的bind 127.0.0.1 为bind 0.0.0.0;
(4)设置Redis 免密,并关闭保护模式;
(5)开放端口:6379;
(6)设置服务开机自启。
FROM centos:centos7.5.1804
MAINTAINER Chinaskill
RUN rm -rf /etc/yum.repos.d/*
ADD ftp.repo /etc/yum.repos.d/
RUN yum clean all && yum list
RUN yum install redis -y
RUN sed -i 's/bind 127.0.0.1/bind 0.0.0.0/g' /etc/redis.conf
RUN sed -i 's/protected-mode yes/protected-mode no/g' /etc/redis.conf
EXPOSE 6379
ENTRYPOINT redis-server /etc/redis.conf
CMD ["redis-server"]
容器化部署Zookeeper
在master 节点上编写/root/zookeeper/Dockerfile 文件,基于提供的软件包gpmall-single.tar 构建chinaskill-zookeeper:v1.1镜像,具体要求如下:
(1)基础镜像:centos:centos7.5.1804;
(2)作者:Chinaskill;
(3)开放端口:2181;
(4)设置服务开机自启。
FROM centos:centos7.5.1804
MAINTAINER Chinaskill
EXPOSE 2181
RUN rm -rf /etc/yum.repos.d/*
COPY ftp.repo /etc/yum.repos.d/ftp.repo
ADD zookeeper-3.4.14.tar.gz /opt
RUN yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel
RUN mv /opt/zookeeper-3.4.14/conf/zoo_sample.cfg /opt/zookeeper-3.4.14/conf/zoo.cfg
CMD ["/opt/zookeeper-3.4.14/bin/zkServer.sh", "start-foreground"]
容器化部署Kafka
在master 节点上编写/root/kafka/Dockerfile 文件,基于提供的软件包gpmall-single.tar 构建chinaskill-kafka:v1.1 镜像,具体要求如下:
(1)基础镜像:centos:centos7.5.1804;
(2)作者:Chinaskill;
(3)开放端口:9092;
(4)设置服务开机自启。
FROM centos:centos7.5.1804
MAINTAINER Chinaskill
RUN rm -rvf /etc/yum.repos.d/*
COPY ftp.repo /etc/yum.repos.d/local.repo
RUN yum clean all
RUN yum list
RUN yum -y install java-1.8.0
ADD kafka_2.11-1.1.1.tgz /usr/local
RUN sed -i 's/localhost:2181/zk1.mall:2181/g' /usr/local/kafka_2.11-1.1.1/config/server.properties #单节点
#RUN sed -i 's/localhost:2181/zk1.mall:2181,zk2.mall:2181,zk3.mall:2181/g' /usr/local/kafka_2.11-1.1.1/config/server.properties #多节点集群
EXPOSE 9092
CMD ["/usr/local/kafka_2.11-1.1.1/bin/kafka-server-start.sh", "/usr/local/kafka_2.11-1.1.1/config/server.properties"]
容器化部署Nginx
在master 节点上编写/root/nginx/Dockerfile 文件,基于提供的软件包gpmall-single.tar 构建chinaskill-nginx:v1.1 镜像,具体要求如下:
(1)基础镜像:centos:centos7.5.1804;
(2)作者:Chinaskill;
(3)编写/etc/nginx/conf.d/default.conf 文件,配置反向代
理,将80 端口请求转发到8081、8082 和8083;
(4)将dist.tar 解压并复制到/usr/share/nginx/html/目录下;
(5)开放端口:80、443、8081、8082、8083;
(6)设置服务开机自启。
FROM centos:centos7.5.1804
MAINTAINER chinaskill
RUN rm -rf /etc/yum.repos.d/*
ADD ftp.repo /etc/yum.repos.d/
ADD *.jar /root/
ADD setup.sh /root/
RUN yum -y install nginx java-1.8.0-openjdk java-1.8.0-openjdk-devel
RUN sed -i '1a location /shopping { proxy_pass http://127.0.0.1:8081 ;}' /etc/nginx/conf.d/default.conf
RUN sed -i '2a location /user { proxy_pass http://127.0.0.1:8082 ;}' /etc/nginx/conf.d/default.conf
RUN sed -i '3a location /cashier { proxy_pass http://127.0.0.1:8083 ;}' /etc/nginx/conf.d/default.conf
RUN chmod +x /root/setup.sh
RUN rm -rf /usr/share/nginx/html/
EXPOSE 80 8081 8082 8083
ADD dist/ /usr/share/nginx/html/
CMD ["nginx","-g","daemon off;"]
sleep 5
nohup java -jar /root/shopping-provider-0.0.1-SNAPSHOT.jar &
sleep 30
nohup java -jar /root/user-provider-0.0.1-SNAPSHOT.jar &
sleep 30
nohup java -jar /root/gpmall-shopping-0.0.1-SNAPSHOT.jar &
sleep 30
nohup java -jar /root/gpmall-user-0.0.1-SNAPSHOT.jar &
sleep 30
while [[ true ]]; do
sleep 1
done
编排部署GPMall 商城
在master 节点上编写/root/chinaskillmall/docker-compose.yaml 文件,具体要求如下:
(1)容器1 名称:mysql;镜像:chinaskill-mariadb:v1.1;
端口映射:3306:3306;
(2)容器2 名称:redis;镜像:chinaskill-redis:v1.1;端
口映射:6379:6379;
(3)容器3 名称:kafka;镜像:chinaskill-kafka:v1.1;端
口映射:9092:9092;
(4)容器4 名称:zookeeper;镜像:chinaskill-zookeeper:v1.1;
端口映射:2181:2181;
(5)容器5 名称:nginx;镜像:chinaskill-nginx:v1.1;端
口映射:80:80,443:443。
docker-compose单节点编排
version: '3'
services:
mall-mysql:
image: chinaskillmall-mysql:v1.1
ports:
- 13306:3306
mall-redis:
image: chinaskillmall-redis:v1.1
ports:
- 16379:6379
mall-kafka:
image: chinaskillmall-kafka:v1.1
ports:
- 19092:9092
links:
- mall-zookeeper:zk1.mall
mall-zookeeper:
image: chinaskillmall-zookeeper:v1.1
ports:
- 12181:2181
mall-nginx:
image: chinaskillmall-nginx:v1.1
links:
- mall-mysql:mysql.mall
- mall-redis:redis.mall
- mall-kafka:kafka1.mall
- mall-zookeeper:zk1.mall
ports:
- 83:80
- 1443:443
command: ["sh","-c","nginx && /root/setup.sh"]
docker-compose多节点集群编排
version: '3'
services:
mall-mysql:
image: chinaskillmall-mysql:v1.1
ports:
- 13306:3306
mall-redis:
image: chinaskillmall-redis:v1.1
ports:
- 16379:6379
mall-kafka:
image: chinaskillmall-kafka:v1.2
ports:
- 19092:9092
links:
- mall-zookeeper1:zk1.mall
- mall-zookeeper2:zk2.mall
- mall-zookeeper3:zk3.mall
mall-zookeeper1:
image: chinaskillmall-zookeeper:v1.1
mall-zookeeper2:
image: chinaskillmall-zookeeper:v1.1
mall-zookeeper3:
image: chinaskillmall-zookeeper:v1.1
mall-nginx:
image: chinaskillmall-nginx:v1.1
links:
- mall-mysql:mysql.mall
- mall-redis:redis.mall
- mall-kafka:kafka1.mall
- mall-zookeeper1:zk1.mall
- mall-zookeeper2:zk2.mall
- mall-zookeeper3:zk3.mall
ports:
- 83:80
- 1443:443
command: ["sh","-c","nginx && /root/setup.sh"]
k8s编排
借助kompose工具将docker-compose转换k8s模板
安装kompose
curl -L https://github.com/kubernetes/kompose/releases/download/v1.1.0/kompose-linux-amd64 -o kompose
chmod +x kompose
sudo mv ./kompose /usr/local/bin/kompose
转换
kompose -f docker-compose.yml convert