电商后台管理系统

所需软件包mall-swarm.tar.gz

云梦公司开发了一套基于SpringBoot+MyBatis微服务架构的ChinaSkillsMall电商系统,并实现全容器化部署,ChinaSkillsMall电商应用系统架构图如下:

*模块* *说明*
mall-monitor 监控中心
mall-gateway 微服务网关
mall-auth 认证中心
mall-admin 商城后台服务
mall-portal 商城前台服务

img

请将MariaDB数据库组件、Redis消息组件、RabbitMQ消息组件、Nacos-Registry注册中心服务组件和前端Nginx组件按照要求进行容器化(镜像mall/mall-gateway:1.0-SNAPSHOT、mall/mall-admin:1.0-SNAPSHOT、mall/mall-auth:1.0-SNAPSHOT已提供)

容器化部署MariaDB

在master节点上编写/root/mall-swarm/Dockerfile-mariadb文件构建chinaskillmall-mariadb:v1.1镜像,具体要求如下:

(1)基础镜像:centos:centos7.5.1804;

(2)作者:Chinaskill;

(3)安装并初始化mariadb,密码:root;

(4)设置数据库编码为UTF-8;

(5)开放端口:3306

(6)设置mariadb开机自启。

完成后构建镜像。

[root@master ~]# tar zxvf mall-swarm.tar.gz
###解压后删除mall-swarm.tar.gz文件,防止构建镜像,文件过大

[root@master ~]# cd mall-swarm
###编写yum源
[root@master mall-swarm]# vim local.repo
[mall]
name=mall
baseurl=file:///opt/mall-repo
gpgcheck=0

###编写初始化脚本init.sh
[root@master mall-swarm]# vim 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 'reader'@'%' identified by '123456';"
mysql -uroot -proot -e "flush privileges;"
mysql -uroot -proot -e "create database mall;use mall;source /opt/mall.sql;"

编写Dockerfile文件

[root@master mall-swarm]# vim Dockerfile-mariadb
FROM 192.168.1.30/library/centos:centos7.5.1804
MAINTAINER Chinaskill
RUN rm -rf /etc/yum.repos.d/*
COPY local.repo /etc/yum.repos.d/local.repo
COPY mall-repo /opt/mall-repo
COPY mall.sql /opt/mall.sql
COPY init.sh /opt/init.sh
ENV LC_ALL en_US.UTF-8
RUN yum -y install mariadb-server && bash /opt/init.sh
EXPOSE 3306
CMD ["mysqld_safe","--user=root"]

###构建镜像
[root@master mall-swarm]# docker build -t chinaskillmall-mariadb:v1.1 -f Dockerfile-mariadb .

容器化部署 Redis

在 master 节 点 上 编 写 /root/mall-swarm/Dockerfile-redis 文 件 构 建chinaskillmallredis:v1.1 镜像,具体要求为 :

(1) 基础镜像:centos:centos7.5.1804;

(2) 作者:Chinaskill;

(3) 安装 redis 服务;

(4) 修改配置文件中的 bind 127.0.0.1 为 bind 0.0.0.0;

(5) 设置 redis 免密,并关闭保护模式;

(6) 开放端口:6379;

(7) 设置服务开机自启

编写dockerfile文件

[root@master mall-swarm]# vim Dockerfile-redis
FROM 192.168.1.30/library/centos:centos7.5.1804
MAINTAINER chinaskill
RUN rm -rf /etc/yum.repos.d/*
COPY mall-repo /opt/mall-repo
COPY local.repo /etc/yum.repos.d/local.repo
RUN yum install redis -y
RUN sed -i "s/127.0.0.1/0.0.0.0/g" /etc/redis.conf
RUN sed -i "s/protected-mode yes/protected-mode no/g" /etc/redis.conf
EXPOSE 6379
CMD ["/usr/bin/redis-server","/etc/redis.conf"]

###构建镜像
[root@master mall-swarm]# docker build -t chinaskillmall-redis:v1.1 -f Dockerfile-redis .

容器化部署 Nacos-Registry

在 master 节点上编写 /root/mall-swarm/Dockerfile-nacos 文件构建 chinaskillmallnacos:v1.1 镜像,具体要求为

(1) 基础镜像:centos:centos7.5.1804;

(2) 作者:Chinaskill;

(3) 安装 jdk 工具和 nacos-server 工具;

(4) 设置 nacos 服务开机自启。

编写run.sh运行文件

[root@master mall-swarm]# vim run.sh
#!/bin/bash
/usr/local/bin/nacos/bin/startup.sh -m standalone          ###地址不要写错
tail -f /usr/local/bin/nacos/logs/start.out

dockerfile文件

[root@master mall-swarm]# vim Dockerfile-nacos
FROM 192.168.1.30/library/centos:centos7.5.1804
MAINTAINER Chinaskill
RUN rm -rf /etc/yum.repos.d/*
COPY mall-repo /opt/mall-repo
COPY local.repo /etc/yum.repos.d/local.repo
COPY run.sh /opt/run.sh
ADD jdk-8u121-linux-x64.tar.gz /usr/local/bin/
ADD nacos-server-1.1.0.tar.gz /usr/local/bin/
ENV JAVA_HOME /usr/local/bin/jdk1.8.0_121
EXPOSE 8848:8848
CMD ["/bin/bash","/opt/run.sh"]

###构建镜像
[root@master mall-swarm]# docker build -t chinaskillmall-nacos:v1.1 -f Dockerfile-nacos .

容器化部署前端服务

在master节点上安装node工具,对mall-admin-web项目进行打包,然后编写/root/mall-swarm/Dockerfile-nginx文件构建chinaskillmall-nginx:v1.1镜像,具体要求如下:(需要用到的软件包在/桌面/附件/容器云附件/Mall-swarm.tar.gz)

(1)基础镜像:centos:centos7.5.1804;

(2)作者:Chinaskill;

(3)安装nginx服务;

(4)将mall-admin-web项目打包后的文件拷贝到/usr/share/nginx/html目录下;

(5)设置nginx服务开机自启。

完成后构建镜像。

[root@master mall-swarm]# tar zxvf mall-admin-web.tar
[root@master mall-swarm]# vim mall-admin-web/config/prod.env
###改环境ip
'use strict'
module.exports = {
NODE_ENV: '"production"',
BASE_API: '"http://192.168.1.10:8201/mall-admin"'
}

[root@master mall-swarm]# tar zxvf node-v6.17.1-linux-x64.tar.gz
[root@master mall-swarm]# mv node-v6.17.1-linux-x64 /usr/local/node
[root@master mall-swarm]# vim /etc/profile
###配置文件最后添加环境变量
export NODE_HOME=/usr/local/node
export PATH=$NODE_HOME/bin/:$PATH
[root@master mall-swarm]# source /etc/profile
[root@master mall-swarm]# node -v
v6.17.1

###npm打包项目
[root@master mall-swarm]# cd mall-admin-web
[root@master mall-admin-web]# npm run build

###打包好之后,网页在dist目录下
[root@master mall-admin-web]# mv dist/ ../

编辑dockerfile文件

[root@master nginx]# vim Dockerfile-nginx
FROM 192.168.1.30/library/centos:centos7.5.1804
MAINTAINER Chinaskill
RUN rm -rf /etc/yum.repos.d/*
COPY local.repo /etc/yum.repos.d/local.repo
COPY mall-repo /opt/mall-repo
RUN yum install -y nginx
COPY dist/ /usr/share/nginx/html/
EXPOSE 80
CMD ["nginx","-g","daemon off;"]

###构建镜像
[root@master mall-swarm]# docker build -t chinaskillmall-nginx:v1.1 -f Dockerfile-nginx .

编排部署ChinaSkillsMall商城

在master节点上编写/root/mall-swarm/docker-compose.yaml文件,具体要求如下:

(1)容器1名称:chinaskillmall-admin;镜像:mall/mall-admin:1.0-SNAPSHOT;端口映射:8080:8080;

(2)容器2名称: chinaskillmall-auth;镜像:mall/mall-auth:1.0-SNAPSHOT;端口映射:8401:8401;

(3)容器3名称:chinaskillmall-gateway;镜像:mall/mall-gateway:1.0-SNAPSHOT;端口映射:8201:8201;

(4)容器4名称:chinaskillmall-mysql;镜像:chinaskillmall-mariadb:v1.1;端口映射:3306:3306;

(5)容器5名称:chinaskillmall-nacos;镜像:chinaskillmall-nacos:v1.1;端口映射:8848:8848;

(6)容器6名称:chinaskillmall-nginx;镜像:chinaskillmall-nginx:v1.1;端口映射:8888:80;

(7)容器1名称:chinaskillmall-redis;镜像:chinaskillmall-redis:v1.1;端口映射:6379:6379。

完成后编排部署ChinaSkillsMall商城。

###将所需镜像解压
[root@master mall-swarm]# docker load -i images/mall_mall-admin_1.0-SNAPSHOT.tar
[root@master mall-swarm]# docker load -i images/mall_mall-auth_1.0-SNAPSHOT.tar
[root@master mall-swarm]# docker load -i images/mall_mall-gateway_1.0-SNAPSHOT.tar

编写docker-compose文件

[root@master mall-swarm]# vim docker-compose
version: '3'
services:
  mysql:
    image: chinaskillmall-mariadb:v1.1
    container_name: chinaskillmall-mysql
    restart: always
    ports:
    - 3306:3306
  redis:
    image: chinaskillmall-redis:v1.1
    container_name: chinaskillmall-redis
    restart: always
    ports:
    - 6379:6379
  nginx:
    image: chinaskillmall-nginx:v1.1
    container_name: chinaskillmall-nginx
    restart: always
    ports:
    - 8888:80
  nacos-registry:
    image: chinaskillmall-nacos:v1.1
    container_name: chinaskillmall-nacos
    restart: always
    ports:
    - 8848:8848
  mall-admin:
    image: mall/mall-admin:1.0-SNAPSHOT
    container_name: chinaskillmall-admin
    restart: always
    ports:
    - 8080:8080
    links:
    - mysql:db
  mall-gateway:
    image: mall/mall-gateway:1.0-SNAPSHOT
    container_name: chinaskillmall-gateway
    restart: always
    ports:
    - 8201:8201
    links:
    - redis:redis
    - nacos-registry:nacos-registry
  mall-auth:
    image: mall/mall-auth:1.0-SNAPSHOT
    container_name: chinaskillmall--auth
    ports:
    - 8401:8401
    links:
    - nacos-registry:nacos-registry

###启动
[root@node mall-swarm]# docker-compose up -d
1.使用 docker-compose ps 命令查看所有容器是否正常启动,
2.查看商城页面,ip:8888 账号admin/macro123登录

img

标题: 电商后台管理系统

链接: https://zhiyong0389.github.io/2023/03/11/%E7%94%B5%E5%95%86%E5%90%8E%E5%8F%B0%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F/

版权声明: 若无特殊标注皆为 智勇 原创版权, 转载请以链接形式注明作者及原始出处

最后编辑时间: 2023-06-29

本站由免费云加速(FreeCDN)提供网站加速和攻击防御服务