mall deployment in Linux environment (based on Docker container)

SpringBoot e-commerce project mall (20k+star) address: https://github.com/macrozheng/mall

abstract

This paper mainly illustrates mall deployment in Linux environment in the form of graphics and text. It involves installing Mysql, Redis, Nginx, RabbitMQ, Elastic search, Mongodb and SpringBook application deployment in Docker container based on enterOS 7.6.

Docker Environment Installation

  • Install yum-utils:
yum install -y yum-utils device-mapper-persistent-data lvm2
  • Add docker repository location for yum source:
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
  • Install docker:
yum install docker-ce
  • Start docker:
systemctl start docker

Mysql installation

  • Download the docker image of MySQL 5.7:
docker pull mysql:5.7
  • Start with the docker command:
  docker run -p 3306:3306 --name mysql \
  -v /mydata/mysql/log:/var/log/mysql \
  -v /mydata/mysql/data:/var/lib/mysql \
  -v /mydata/mysql/conf:/etc/mysql \
  -e MYSQL_ROOT_PASSWORD=root  \
  -d mysql:5.7
  • Parameter description

    • - p 3306:3306: Map port 3306 of container to port 3306 of host computer
    • - v/mydata/mysql/conf:/etc/mysql: Hang the configuration folder on the host
    • - v/mydata/mysql/log:/var/log/mysql: Mount the log folder to the host
    • - v/mydata/mysql/data:/var/lib/mysql/: Mount the data folder to the host
    • - e MYSQL_ROOT_PASSWORD=root: Initialize the password of the root user
  • Enter the docker container running mysql:
docker exec -it mysql /bin/bash
  • Open the client using the mysql command:
mysql -uroot -proot --default-character-set=utf8
  • Create mall database:
create database mall character set utf8
  • Install the upload and download Plug-in and upload doction/sql/mall.sql to the Linux server:
yum -y install lrzsz
  • Copy mall.sql file to mysql container/directory:
docker cp /mydata/mall.sql mysql:/
  • Import sql file into database:
use mall;
source /mall.sql;
  • Create a reader account and modify permissions so that any ip can access:
grant all privileges on *.* to 'reader' @'%' identified by '123456';

Redis installation

  • Download the docker image of redis 3.2:
docker pull redis:3.2
  • Start with the docker command:
  docker run -p 6379:6379 --name redis \
  -v /mydata/redis/data:/data \
  -d redis:3.2 redis-server --appendonly yes
  • Enter the redis container and use the redis-cli command to connect:
docker exec -it redis redis-cli

Nginx installation

Download the docker image of nginx 1.10:

docker pull nginx:1.10

Copy nginx configuration from container

  • Run the container once (to copy the configuration file):
  docker run -p 80:80 --name nginx \
  -v /mydata/nginx/html:/usr/share/nginx/html \
  -v /mydata/nginx/logs:/var/log/nginx  \
  -d nginx:1.10
  • Copy the configuration file in the container to the specified directory:
docker container cp nginx:/etc/nginx /mydata/nginx/
  • Modify the file name:
mv nginx conf
  • Terminate and delete containers:
docker stop nginx
docker rm nginx

Start with the docker command:

docker run -p 80:80 --name nginx \
-v /mydata/nginx/html:/usr/share/nginx/html \
-v /mydata/nginx/logs:/var/log/nginx  \
-v /mydata/nginx/conf:/etc/nginx \
-d nginx:1.10

RabbitMQ installation

  • Download the docker image of rabbitmq3.7.15:
docker pull rabbitmq:3.7.15
  • Start with the docker command:
  docker run -d --name rabbitmq \
  --publish 5671:5671 --publish 5672:5672 --publish 4369:4369 \
  --publish 25672:25672 --publish 15671:15671 --publish 15672:15672 \
  rabbitmq:3.7.15
  • Enter the container and open the management function:
docker exec -it rabbitmq /bin/bash
rabbitmq-plugins enable rabbitmq_management

  • Open the firewall:
firewall-cmd --zone=public --add-port=15672/tcp --permanent
firewall-cmd --reload

  • Enter your account password and log in: guest
  • Create an account and set its role as administrator: mall mall

  • Create a new virtual host as: / mall

  • Click on mall user to enter user configuration page

  • Configure the permissions of the virtual host to mall users

Elastic search installation

  • Download the docker image of elastic search 6.4.0:
docker pull elasticsearch:6.4.0
  • Modify the virtual memory area size, otherwise it will be too small to start:
sysctl -w vm.max_map_count=262144
  • Start with the docker command:
  docker run -p 9200:9200 -p 9300:9300 --name elasticsearch \
  -e "discovery.type=single-node" \
  -e "cluster.name=elasticsearch" \
  -v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
  -v /mydata/elasticsearch/data:/usr/share/elasticsearch/data \
  -d elasticsearch:6.4.0
  • When startup, it will be found that the / usr/share/elasticsearch/data directory has no access rights, only need to modify the permissions of / mydata/elasticsearch/data directory, and restart.
chmod 777 /mydata/elasticsearch/data/
  • Install Chinese Word Segmenter IKAnalyr and restart:
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
  • Open the firewall:
firewall-cmd --zone=public --add-port=9200/tcp --permanent
firewall-cmd --reload

kibana installation

  • Download the docker image of kibana 6.4.0:
docker pull kibana:6.4.0
  • Start with the docker command:
  docker run --name kibana -p 5601:5601 \
  --link elasticsearch:es \
  -e "elasticsearch.hosts=http://es:9200" \
  -d kibana:6.4.0
  • Open the firewall:
firewall-cmd --zone=public --add-port=5601/tcp --permanent
firewall-cmd --reload

Mongodb Installation

  • Download the docker image of Mongo 3.2:
docker pull mongo:3.2
  • Start with the docker command:

    docker run -p 27017:27017 --name mongo \
    -v /mydata/mongo/db:/data/db \
    -d mongo:3.2

## Docker complete environment installation
- All downloaded mirror files:
![Show pictures](http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/blog/refer_screen_82.png)
- All applications running in containers:
![Show pictures](http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/blog/refer_screen_83.png)

## SpringBoot application deployment

### Build and upload all Docker images
- open pom.xml Use in docker Notes for plug-ins:
![Show pictures](http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/blog/refer_screen_84.png)
- modify dockerHost For your own sake docker Server address:
- Build a mirror and upload:  
![Show pictures](http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/blog/refer_screen_85.png)
![Show pictures](http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/blog/refer_screen_86.png)

### Deployment of mall-admin
‚Äč```shell
docker run -p 8080:8080 --name mall-admin \
--link mysql:db \
-v /etc/localtime:/etc/localtime \
-v /mydata/app/admin/logs:/var/logs \
-d mall/mall-admin:1.0-SNAPSHOT

Note: Version 7.2 of CenterOS needs to add this line, otherwise the container time zone and the host cannot be synchronized

-v /etc/timezone:/etc/timezone \

Deployment of mall-search

docker run -p 8081:8081 --name mall-search \
--link elasticsearch:es \
--link mysql:db \
-v /etc/localtime:/etc/localtime \
-v /mydata/app/search/logs:/var/logs \
-d mall/mall-search:1.0-SNAPSHOT

Deployment of mall-port

docker run -p 8085:8085 --name mall-portal \
--link mysql:db \
--link redis:redis \
--link mongo:mongo \
--link rabbitmq:rabbit \
-v /etc/localtime:/etc/localtime \
-v /mydata/app/portal/logs:/var/logs \
-d mall/mall-portal:1.0-SNAPSHOT

Open Firewall

firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --zone=public --add-port=8081/tcp --permanent
firewall-cmd --zone=public --add-port=8085/tcp --permanent
firewall-cmd --reload

Access Interface for Testing

Public address

mall project In the whole series of learning courses, we pay attention to the first time acquisition of the public number.

Tags: Java Docker MySQL Nginx ElasticSearch

Posted on Tue, 10 Sep 2019 19:23:23 -0700 by triponline