SpringBoot actual combat e-commerce project mall address: github.com/macrozheng/…

Introduction to the

The simplest way to deploy mall on Linux is with two Docker-compse scripts. The first script is used to deploy the services on which the mall runs (mysql, Redis, nginx, RabbitMQ, ElasticSearch, Kibana, Mongo), The second script is used to deploy applications in the mall (mall-admin, mall-search, and mall-portal).

Docker environment construction and use

The Docker command is required for developers

Docker-compose environment construction and use

For details, see Deploying the SpringBoot application using Docker Compose

Docker-compose deployment for the Mall project

Operation Configuration Requirements

CenterOS7.6, and more than 4 gb memory is recommended

Deployment related files

  • Database script mall. SQL: github.com/macrozheng/…
  • Nginx configuration file nginx.conf: github.com/macrozheng/…
  • Docker-compose-env.yml:github.com/macrozheng/…
  • Docker-compose-app.yml:github.com/macrozheng/…

Preparing for deployment

Package and upload the mall application image

You need to package the docker images of mall-admin, mall-search, and mall-portal. For details, see: Using Maven plug-in to build a Docker image for SpringBoot

Download all the Docker images you need to install

Docker pull mysql:5.7 docker pull Redis :3.2 Docker pull nginx:1.10 Docker pull RabbitMQ :3.7.15- Management Elasticsearch :6.4.0 Docker Pull Kibana :6.4.0 Docker Pull Mongo :3.2Copy the code

elasticsearch

  • You need to set system kernel parameters; otherwise, the system cannot start due to insufficient memory.
#Change the Settings
sysctl -w vm.max_map_count=262144
#Make it effective immediately
sysctl -p
Copy the code
  • You need to create/mydata/elasticsearch/data directory and set the permissions, otherwise it will because do not have permission to access and launch failure.
#Create a directory
mkdir /mydata/elasticsearch/data/
#Create and change the directory permissions
chmod 777 /mydata/elasticsearch/data
Copy the code

nginx

You need to copy the nginx configuration file, otherwise the mount will fail because there is no configuration file.

#After creating the directory, upload the nginx.conf file to that directory
mkdir /mydata/nginx/
Copy the code

Execute the docker-comement-env.yml script

On the Linux server where the file is uploaded, run the docker-compose up command to start all the services that the Mall depends on.

version: '3'
services:
  mysql:
    image: Mysql: 5.7
    container_name: mysql
    command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: root Set the password of the root account
    ports:
      - 3306: 3306
    volumes:
      - /mydata/mysql/data/db:/var/lib/mysql Mount data files
      - /mydata/mysql/data/conf:/etc/mysql/conf.d # config file mount
      - /mydata/mysql/log:/var/log/mysql # Log file mount
  redis:
    image: Redis: 3.2
    container_name: redis
    command: redis-server --appendonly yes
    volumes:
      - /mydata/redis/data:/data Mount data files
    ports:
      - 6379: 6379
  nginx:
    image: Nginx: 1.10
    container_name: nginx
    volumes:
      - /mydata/nginx/nginx.conf:/etc/nginx/nginx.conf # config file mount
      - /mydata/nginx/html:/usr/share/nginx/html # static resource root mount
      - /mydata/nginx/log:/var/log/nginx # Log file mount
    ports:
      - 80: 80
  rabbitmq:
    image: The rabbitmq: 3.7.15 - management
    container_name: rabbitmq
    volumes:
      - /mydata/rabbitmq/data:/var/lib/rabbitmq Mount data files
      - /mydata/rabbitmq/log:/var/log/rabbitmq # Log file mount
    ports:
      - 5672: 5672
      - 15672: 15672
  elasticsearch:
    image: Elasticsearch: 6.4.0
    container_name: elasticsearch
    environment:
      - "cluster.name=elasticsearch" Set the cluster name to elasticSearch
      - "discovery.type=single-node" Start in single-node mode
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m" # set the JVM memory size to be used
    volumes:
      - /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins The plugin file is mounted
      - /mydata/elasticsearch/data:/usr/share/elasticsearch/data Mount data files
    ports:
      - 9200: 9200
  kibana:
    image: Kibana: 6.4.0
    container_name: kibana
    links:
      - elasticsearch:es You can use the es domain name to access elasticSearch
    depends_on:
      - elasticsearch # Kibana will start after ElasticSearch has started
    environment:
      - "elasticsearch.hosts=http://es:9200" Set the address to access ElasticSearch
    ports:
      - 5601: 5601
  mongo:
    image: Mongo: 3.2
    container_name: mongo
    volumes:
      - /mydata/mongo/db:/data/db Mount data files
    ports:
      - 27017: 27017
Copy the code

After the upload, run the following command in the current directory:

docker-compose -f docker-compose-env.yml up -d
Copy the code

Do the following for the dependent service

When all dependent services are started, some Settings need to be made for the following services.

mysql

You need to create the Mall database and create a reader object that can be accessed remotely.

  • Copy the mall. SQL file to the/directory of the mysql container:
docker cp /mydata/mall.sql mysql:/
Copy the code
  • Enter the mysql container and do the following:
#Enter the mysql container
docker exec -it mysql /bin/bash
#Connect to the mysql service
mysql -uroot -proot --default-character-set=utf8
#Create a remote access user
grant all privileges on *.* to 'reader' @'%' identified by '123456';
#Create mall database
create database mall character set utf8;
#Using the Mall database
use mall;
#Import the mall.sql script
source /mall.sql;
Copy the code

elasticsearch

The Chinese word analyzer, IKAnalyzer, needs to be installed and restarted.

docker exec -it elasticsearch /bin/bash
#This command needs to be run in a container
elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.4.0/elasticsearch-analysis-ik-6.4.0.zip
docker restart elasticsearch
Copy the code

rabbitmq

You need to create a mall user and set virtual host to /mall.

  • Address of management page:http://192.168.3.101:15672/
  • Enter the password and log in to: guest guest
  • Create an account and set its role to administrator: Mall Mall
  • Create a new virtual host: /mall
  • Click the mall user to enter the user configuration page
  • Assign the permission to the mall user for the virtual host

Execute the docker-comement-app. yml script

To start all mall applications, run the docker-compose up command on the Linux server where the file is uploaded.

version: '3'
services:
  mall-admin:
    image: Mall/mall - admin: 1.0 the SNAPSHOT
    container_name: mall-admin
    ports:
      - 8080: 8080
    external_links:
      - mysql:db Mysql server can be accessed using the db domain name
  mall-search:
    image: Mall/mall - search: 1.0 the SNAPSHOT
    container_name: mall-search
    ports:
      - 8081: 8081
    external_links:
      - elasticsearch:es You can use the es domain name to access elasticSearch
      - mysql:db Mysql server can be accessed using the db domain name
  mall-portal:
    image: Mall/mall - portal: 1.0 the SNAPSHOT
    container_name: mall-portal
    ports:
      - 8085: 8085
    external_links:
      - redis:redis You can access the Redis service using the domain name redis
      - mongo:mongo You can use the domain name mongo to access the Mongo service
      - mysql:db Mysql server can be accessed using the db domain name
      - rabbitmq:rabbit The rabbitMQ service can be accessed using the rabbit domain name
Copy the code

After the upload, run the following command in the current directory:

docker-compose -f docker-compose-app.yml up -d
Copy the code

After the firewall is enabled, all services can be accessed from other hosts

systemctl stop firewalld
Copy the code

All services have been started

The public,

Mall project full set of learning tutorials serialized, attention to the public number the first time access.