赞
踩
将该公司开发的基于微服务架构的web应用系统Chinaskillmall实现全容器化部署,Chinaskillmall应用系统架构图如下:
模块 使用技术 备注
gpmall.sql Mysql 网站的数据库
dist目录 Nginx 网站的前端项目
gpmall-shopping web项目 8081端口,商品/购物车/首页渲染等交互
gpmall-user 8082端口,提供用户相关的交互,如登录、注册、个人中心等
user-provider 后端服务 提供用户相关服务
shopping-provider 提供购物车、推荐商品、商品等服务
在 master 节点上编写/root/redis/Dockerfile 文件,构建 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)设置服务开机自启。
[root@master ~]# tar -xzvf /opt/gpmall-single.tar.gz -C /opt/ [root@master ~]# mkdir redis [root@master ~]# cd redis/ [root@master redis]# cat local.repo [centos] name=centos gpgcheck=0 enabled=1 baseurl=ftp://192.168.100.10/centos [k8s] name=k8s gpgcheck=0 enabled=1 baseurl=ftp://192.168.200.103/kubernetes-repo [gpmall] name=gpmall gpgcheck=0 enabled=1 baseurl=ftp://192.168.200.103/ChinaskillMall/gpmall-repo [root@master redis]# cat Dockerfile FROM centos:centos7.5.1804 MAINTAINER Chinaskill RUN rm -f /etc/yum.repos.d/* COPY ./local.repo /etc/yum.repos.d/ RUN yum install redis -y && sed -i "s/^bind 127.0.0.1/bind 0.0.0.0/g;s/^protected-mode\ yes/protected-mode\ no/g" /etc/redis.conf EXPOSE 6379 CMD ["redis-server","/etc/redis.conf"] [root@master redis]# docker build -t chinaskill-redis:v1.1 .
在 master 节点上编写/root/mariadb/Dockerfile 文件,构建 chinaskill-mariadb:v1.1 镜像,具体要求 如下:
(1)基础镜像:centos:centos7.5.1804;
(2)作者:Chinaskill;
(3)设置数据库密码:123456;
(4)创建数据库 gpmall 并导入数据库文件 gpmall.sql;
(5)设置字符编码:UTF-8;
(6)开放端口:3306;
(7)设置服务开机自启。
[root@master ~]# mkdir mariadb [root@master ~]# cd mariadb/ [root@master mariadb]# cp /opt/gpmall-single/gpmall.sql ./ [root@master mariadb]# cat local.repo [centos] name=centos gpgcheck=0 enabled=1 baseurl=ftp://192.168.100.10/centos [k8s] name=k8s gpgcheck=0 enabled=1 baseurl=ftp://192.168.200.103/kubernetes-repo [gpmall] name=gpmall gpgcheck=0 enabled=1 baseurl=ftp://192.168.200.103/ChinaskillMall/gpmall-repo [root@master mariadb]# cat Dockerfile FROM centos:centos7.5.1804 MAINTAINER Chinaskill RUN rm -rf /etc/yum.repos.d/* COPY local.repo /etc/yum.repos.d/ COPY gpmall.sql /var/ RUN yum install -y mariadb-server ENV LC_ALL en_US.UTF-8 RUN sed -i '/\[mysqld\]/a\port=3306' /etc/my.cnf.d/server.cnf \ && sed -i '/\[mysqld\]/a\character-set-server=utf8' /etc/my.cnf.d/server.cnf RUN mysql_install_db --user=root \ && chown -R mysql:mysql /var/lib/mysql RUN mysqld_safe >/dev/null & sleep 5; mysql -e "grant all privileges on *.* to 'root'@'%' identified by '123456'; grant all privileges on *.* to ' root'@'localhost' identified by '123456'; create database gpmall character set utf8; use gpmall; source /var/gpmall.sql;" EXPOSE 3306 CMD ["mysqld_safe"] [root@master mariadb]# docker build -t chinaskill-mariadb:v1.1 . 查看容器内部数据库字符编码 MariaDB [(none)]> show variables like 'character%'; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+
在 master 节点上编写/root/zookeeper/Dockerfile 文件,构建 chinaskill-zookeeper:v1.1 镜像,具体要求如下:
(1)基础镜像:centos:centos7.5.1804;
(2)作者:Chinaskill;
(3)开放端口:2181;
(4)设置服务开机自启。
[root@master ~]# mkdir /root/zookeeper/ [root@master ~]# cd zookeeper/ [root@master zookeeper]# cp /opt/gpmall-single/zookeeper-3.4.14.tar.gz ./ [root@master zookeeper]# cp /opt/gpmall-single/jdk-8u77-linux-x64.tar.gz ./ [root@master zookeeper]# cat Dockerfile FROM centos:centos7.5.1804 MAINTAINER Chinaskill COPY ./*.tar.gz /var/ RUN tar -xf /var/jdk-8u77-linux-x64.tar.gz -C /usr/local/ && tar -xf /var/zookeeper-3.4.14.tar.gz -C /usr/local/ ENV JAVA_HOME /usr/local/jdk1.8.0_77 ENV PATH $JAVA_HOME/bin:$PATH ENV PATH /usr/local/zookeeper-3.4.14/bin:$PATH RUN cp /usr/local/zookeeper-3.4.14/conf/zoo_sample.cfg /usr/local/zookeeper-3.4.14/conf/zoo.cfg EXPOSE 2181 CMD ["/usr/local/zookeeper-3.4.14/bin/zkServer.sh","start-foreground"] [root@master zookeeper]# docker build -t chinaskill-zookeeper:v1.1 .
在 master 节点上编写/root/kafka/Dockerfile 文件,构建 chinaskill-kafka:v1.1 镜像,具体要求如下:
(1)基础镜像:centos:centos7.5.1804;
(2)作者:Chinaskill;
(3)开放端口:9092;
(4)设置服务开机自启。
[root@master ~]# mkdir /root/kafka/ [root@master ~]# cd kafka/ [root@master kafka]# cp /opt/gpmall-single/kafka_2.11-1.1.1.tgz ./ [root@master kafka]# cp /opt/gpmall-single/jdk-8u77-linux-x64.tar.gz ./ [root@master kafka]# cat Dockerfile FROM centos:centos7.5.1804 MAINTAINER Chinaskill COPY ./*gz /var/ RUN tar -xf /var/jdk-8u77-linux-x64.tar.gz -C /usr/local/ &&\ tar -xf /var/kafka_2.11-1.1.1.tgz -C /usr/local/ ENV JAVA_HOME /usr/local/jdk1.8.0_77 ENV PATH $JAVA_HOME/bin:$PATH RUN sed -i 's%zookeeper.connect=.*$%zookeeper.connect=192.168.200.103:2181%g' /usr/local/kafka_2.11-1.1.1/config/server.properties EXPOSE 9092 WORKDIR /usr/local/kafka_2.11-1.1.1/ CMD ["bin/kafka-server-start.sh","config/server.properties"] [root@master kafka]# docker build -t chinaskill-kafka:v1.1 .
在 master 节点上编写/root/nginx/Dockerfile 文件,构建 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)设置服务开机自启。
[root@master ~]# mkdir /root/nginx [root@master ~]# cd nginx/ [root@master nginx]# cp -r /opt/gpmall-single/dist/ ./ [root@master nginx]# cp /opt/gpmall-single/*.jar ./ [root@master nginx]# cat local.repo [centos] name=centos gpgcheck=0 enabled=1 baseurl=ftp://192.168.100.10/centos [k8s] name=k8s gpgcheck=0 enabled=1 baseurl=ftp://192.168.200.103/kubernetes-repo [gpmall] name=gpmall gpgcheck=0 enabled=1 baseurl=ftp://192.168.200.103/ChinaskillMall/gpmall-repo [root@nginx ~]# cat start.sh #!/bin/bash java -jar /root/shopping-provider-0.0.1-SNAPSHOT.jar & sleep 5 java -jar /root/user-provider-0.0.1-SNAPSHOT.jar & sleep 5 java -jar /root/gpmall-shopping-0.0.1-SNAPSHOT.jar & sleep 5 java -jar /root/gpmall-user-0.0.1-SNAPSHOT.jar & sleep 5 nginx -g "daemon off;" [root@master nginx]# cat Dockerfile FROM centos:centos7.5.1804 MAINTAINER Chinaskill RUN rm -rf /etc/yum.repos.d/* ADD local.repo /etc/yum.repos.d/ ADD *.jar /root/ ADD start.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 \ && sed -i '2a location /user { proxy_pass http://127.0.0.1:8082 ;}' /etc/nginx/conf.d/default.conf \ && sed -i '3a location /cashier { proxy_pass http://127.0.0.1:8083 ;}' /etc/nginx/conf.d/default.conf \ && chmod +x /root/start.sh \ && rm -rf /usr/share/nginx/html/ ADD dist/ /usr/share/nginx/html/ EXPOSE 80 443 8081 8082 8083 CMD ["sh","-c","/root/start.sh"] [root@master nginx]# ll total 376448 drwxr-xr-x 3 root root 38 Sep 20 00:55 dist -rw-r--r-- 1 root root 686 Sep 20 00:57 Dockerfile -rw-r--r-- 1 root root 47765224 Sep 20 00:55 gpmall-shopping-0.0.1-SNAPSHOT.jar -rw-r--r-- 1 root root 39005468 Sep 20 00:55 gpmall-user-0.0.1-SNAPSHOT.jar -rw-r--r-- 1 root root 259 Sep 20 00:57 local.repo -rw-r--r-- 1 root root 54936064 Sep 20 00:55 shopping-provider-0.0.1-SNAPSHOT.jar -rw-r--r-- 1 root root 275 Sep 20 00:58 start.sh -rw-r--r-- 1 root root 62386947 Sep 20 00:55 user-provider-0.0.1-SNAPSHOT.jar [root@master nginx]# docker build -t chinaskill-nginx:v1.1 .
在 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。
[root@master ~]# mkdir /root/chinaskillmall/ [root@master ~]# cd chinaskillmall/ [root@master chinaskillmall]# cat docker-compose.yaml version: '2.0' services: mysql: hostname: mall-mysql container_name: mall-mysql image: chinaskill-mariadb:v1.1 ports: - 3306:3306 restart: always redis: hostname: mall-redis container_name: mall-redis image: chinaskill-redis:v1.1 ports: - 6379:6379 restart: always zookeeper: hostname: mall-zookeeper container_name: mall-zookeeper image: chinaskill-zookeeper:v1.1 ports: - 2181:2181 restart: always kafka: hostname: mall-kafka container_name: mall-kafka image: chinaskill-kafka:v1.1 ports: - 9092:9092 restart: always nginx: hostname: nginx.mall container_name: nginx.mall image: chinaskill-nginx:v1.1 restart: always ports: - 83:80 - 443:443 extra_hosts: - "mysql.mall:192.168.200.103" - "zookeeper.mall:192.168.200.103" - "kafka.mall:192.168.200.103" - "redis.mall:192.168.200.103"
启动docker-compose + 检查容器状态
[root@master chinaskillmall]# docker-compose up -d
[root@master chinaskillmall]# docker ps |grep china
完成后去浏览器访问ip:83
至此,web购物平台搭建完成!!!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。