GpMall电商系统 容器化部署
Posted 云计算运维
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了GpMall电商系统 容器化部署相关的知识,希望对你有一定的参考价值。
GpMall 电商系统
0.准备
mkdir /root/gpmall
# workdir
cd gpmall
cp -rvf /opt/ChinaskillMall/* /root/gpmall/
vim /root/gpmall/ftp.repo
[centos7.5]
name=centos7.5
baseurl=ftp://172.16.0.50/centos7.5/
gpgcheck=0
enabled=1
[gpmall]
name=gpmall
baseurl=ftp://172.16.0.50/ChinaskillMall/gpmall-repo/
gpgcheck=0
enabled=1
1.MariaDB
vim /root/gpmall/init.sh
#!/bin/bash
mysql_install_db --user=root
mysqld_safe --user=root &
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"
mysql -uroot -p123456 gpmall < /root/gpmall.sql
vim /root/gpmall/Docker-mariadb
from centos:centos7.5.1804
maintainer Chinaskill
RUN rm -rf /etc/yum.repos.d/*
COPY ftp.repo /etc/yum.repos.d/ftp.repo
RUN yum clean all && yum repolist
RUN yum install -y mariadb-server
RUN sed -i "13cport = 8066" /etc/my.cnf.d/server.cnf
COPY gpmall.sql /root/gpmall.sql
COPY init.sh /root/init.sh
RUN chmod +x /root/init.sh
ENV LC_ALL en_US.UTF-8
RUN bash /root/init.sh
EXPOSE 3306 8066
CMD mysqld_safe --user=root
docker build -t chinaskillmall-mysql:v1.1 -f /root/gpmall/Docker-mariadb /root/gpmall
2.Redis
vim /root/gpmall/Docker-redis
FROM centos:centos7.5.1804
MAINTAINER chinaskill
RUN rm -rf /etc/yum.repos.d/*
COPY ftp.repo /etc/yum.repos.d/ftp.repo
RUN yum install -y redis && sed -i 's/bind 127.0.0.1/bind 0.0.0.0/' /etc/redis.conf && sed -i 's/protected-mode yes/protected-mode no/' /etc/redis.conf
EXPOSE 6379
CMD redis-server /etc/redis.conf
docker build -t chinaskillmall-redis:v1.1 -f /root/gpmall/Docker-redis /root/gpmall
3.Zookeeper
vim /root/gpmall/Docker-zookeeper
FROM centos:centos7.5.1804
MAINTAINER Chinaskill
RUN rm -rf /etc/yum.repos.d/*
COPY ftp.repo /etc/yum.repos.d/ftp.repo
RUN yum clean all && yum repolist
ADD zookeeper-3.4.14.tar.gz /opt
RUN yum -y install java-1.8.0
RUN mv /opt/zookeeper-3.4.14/conf/zoo_sample.cfg /opt/zookeeper-3.4.14/conf/zoo.cfg
EXPOSE 2181
CMD ["/opt/zookeeper-3.4.14/bin/zkServer.sh", "start-foreground"]
docker build -t chinaskillmall-zookeeper:v1.1 -f /root/gpmall/Docker-zookeeper /root/gpmall
4.Kafka
vim /root/gpmall/Docker-kafka
FROM centos:centos7.5.1804
MAINTAINER Chinaskill
RUN rm -rvf /etc/yum.repos.d/*
COPY ftp.repo /etc/yum.repos.d/ftp.repo
RUN yum clean all && yum repolist
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
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"]
docker build -t chinaskillmall-kafka:v1.1 -f /root/gpmall/Docker-kafka /root/gpmall
5.nginx
vim /root/gpmall/setup.sh
#!/bin/bash
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
vim /root/gpmall/Docker-nginx
FROM centos:centos7.5.1804
MAINTAINER chinaskill
RUN rm -rf /etc/yum.repos.d/*
COPY ftp.repo /etc/yum.repos.d/ftp.repo
RUN yum clean all && yum repolist
RUN yum -y install nginx java-1.8.0
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
COPY *.jar /root/
COPY setup.sh /root/setup.sh
RUN chmod +x /root/setup.sh
RUN rm -rf /usr/share/nginx/html/
COPY dist/ /usr/share/nginx/html/
EXPOSE 80 8081 8082 8083
CMD ["nginx","-g","daemon off;"]
docker build -t chinaskillmall-nginx:v1.1 -f /root/gpmall/Docker-nginx /root/gpmall
二. Docker-compose编排
vim /root/gpmall/docker-compose.yaml
version: '3'
services:
mall-mysql:
image: chinaskillmall-mysql:v1.1
ports:
- 13306:3306
mall-redis:
image: chinaskillmall-redis:v1.1
ports:
- 16379:6379
mall-zookeeper:
image: chinaskillmall-zookeeper:v1.1
ports:
- 12181:2181
mall-kafka:
image: chinaskillmall-kafka:v1.1
ports:
- 19092:9092
links:
- mall-zookeeper:zk1.mall
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 up -d
三. Kubernetes编排
# master
for i in `docker images|grep skill|awk 'print$1":"$2'`;do docker tag $i 172.16.0.80/library/$i;docker push 172.16.0.80/library/$i;done
# node
docker pull 172.16.0.80/library/chinaskillmall-kafka:v1.1
docker pull 172.16.0.80/library/chinaskillmall-nginx:v1.1
docker pull 172.16.0.80/library/chinaskillmall-zookeeper:v1.1
docker pull 172.16.0.80/library/chinaskillmall-mysql:v1.1
docker pull 172.16.0.80/library/chinaskillmall-redis:v1.1
cat > /root/gpmall/gpmall.yaml <<EOF
apiVersion: v1
kind: Pod
metadata:
name: chinaskill-mall
labels:
app: chinaskill-mall
spec:
containers:
- name: chinaskill-mariadb
image: 172.16.0.80/library/chinaskillmall-mysql:v1.1
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3306
- name: chinaskill-redis
image: 172.16.0.80/library/chinaskillmall-redis:v1.1
imagePullPolicy: IfNotPresent
ports:
- containerPort: 6379
- name: chinaskill-zookeeper
image: 172.16.0.80/library/chinaskillmall-zookeeper:v1.1
imagePullPolicy: IfNotPresent
ports:
- containerPort: 2181
- name: chinaskill-kafka
image: 172.16.0.80/library/chinaskillmall-kafka:v1.1
imagePullPolicy: IfNotPresent
ports:
- containerPort: 9092
- name: chinaskill-nginx
image: 172.16.0.80/library/chinaskillmall-nginx:v1.1
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
- containerPort: 443
command: ["sh","-c","nginx && /root/setup.sh"]
hostAliases:
- ip: "127.0.0.1"
hostnames:
- "mysql.mall"
- "redis.mall"
- "zk1.mall"
- "kafka1.mall"
---
apiVersion: v1
kind: Service
metadata:
name: chinaskill-mall
spec:
selector:
app: chinaskill-mall
ports:
- port: 80
targetPort: 80
nodePort: 30080
type: NodePort
EOF
# 启动服务
kubectl apply -f gpmall.yaml
# 查看刚刚启动的服务
kubectl get pods,service
# 查看刚刚启动过程详情
kubectl describe pod chinaskill-mall
另一篇笔记如下
基于docker-compose编排部署情感分析系统
https://download.csdn.net/download/weixin_45869322/85382406
以上是关于GpMall电商系统 容器化部署的主要内容,如果未能解决你的问题,请参考以下文章
github 31.6K star的Springboot开源电商系统,值得关注