SpringBoot actual combat e-commerce project mall address: github.com/macrozheng/…
Abstract
This article mainly introduces the deployment of mall in Linux environment, including installation of Mysql, Redis, Nginx, RabbitMQ, Elasticsearch, Mongodb and SpringBoot application in Docker container. Based on CenterOS7.6.
Docker environment installation
- Install yum – utils:
yum install -y yum-utils device-mapper-persistent-data lvm2
Copy the code
- Add docker repository location to yum source:
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Copy the code
- Install the docker:
yum install docker-ce
Copy the code
- Start the docker:
systemctl start docker
Copy the code
Mysql installation
- Download mysql5.7 docker image:
Docker pull mysql: 5.7Copy the code
- 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.7Copy the code
- Parameters that
- -p 3306:3306: maps port 3306 of a container to port 3306 of a host
- – v/mydata/mysql/conf: / etc/mysql: the configuration folder to hang on to the host
- – v/mydata/mysql/log: / var/log/mysql: mount the log files to the host
- – v/mydata/mysql/data: / var/lib/mysql/data folder mount to the host
- -e MYSQL_ROOT_PASSWORD=root: initializes the password of user root
- Enter the docker container running mysql:
docker exec -it mysql /bin/bash
Copy the code
- Open client with mysql command:
mysql -uroot -proot --default-character-set=utf8
Copy the code
- Create mall database:
create database mall character set utf8
Copy the code
- Install docment/ SQL /mall. SQL to Linux server:
yum -y install lrzsz
Copy the code
- Copy the mall. SQL file to the/directory of the mysql container:
docker cp /mydata/mall.sql mysql:/
Copy the code
- Import SQL file into database:
use mall;
source /mall.sql;
Copy the code
- Create a Reader account and modify permissions so that any IP can access it:
grant all privileges on*. *to 'reader' @The '%' identified by '123456';
Copy the code
Redis installation
- Download redis3.2 docker image:
Docker pull redis: 3.2Copy the code
- Start with the docker command:
Docker run -p 6379:6379 --name redis \ -v /mydata/redis/data:/data \ -d redis:3.2 redis-server --appendonly yesCopy the code
- Enter the redis container and run the redis-cli command to connect:
docker exec -it redis redis-cli
Copy the code
Nginx installation
Download nginx1.10 docker image:
Docker pull nginx: 1.10Copy the code
Copy the nginx configuration from the container
- Run the container first (to copy configuration files) :
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.10Copy the code
- Copy the configuration file in the container to the specified directory:
docker container cp nginx:/etc/nginx /mydata/nginx/
Copy the code
- Change the file name:
mv nginx conf
Copy the code
- Terminating and deleting containers:
docker stop nginx
docker rm nginx
Copy the code
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.10Copy the code
The RabbitMQ installation
- Download rabbitmq3.7.15 docker image:
Docker pull the rabbitmq: 3.7.15Copy the code
- Start with the docker command:
docker run -d --name rabbitmq \ --publish 5671:5671 --publish 5672:5672 --publish 4369:4369 \ --publish 25672:25672 --publish 15672:15671 --publish 15672:15672 \ rabbitMQ :3.7.15Copy the code
- Enter the container and enable the management function:
docker exec -it rabbitmq /bin/bash
rabbitmq-plugins enable rabbitmq_management
Copy the code
- Enable firewall:
firewall-cmd --zone=public --add-port=15672/tcp --permanent
firewall-cmd --reload
Copy the code
- Visit the address to check whether the installation is successful: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
Elasticsearch installation
- Download elasticsearch6.4.0 docker image:
Docker pull elasticsearch: 6.4.0Copy the code
- Change the size of the virtual memory area, otherwise it will not start because it is too small:
sysctl -w vm.max_map_count=262144
Copy the code
- 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.0Copy the code
- Start will find/usr/share/elasticsearch/data directory access permissions, only need to modify/mydata/elasticsearch/data directory permissions, restart again.
chmod 777 /mydata/elasticsearch/data/
Copy the code
- Install the Chinese word analyzer IKAnalyzer and restart it:
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
- Enable firewall:
firewall-cmd --zone=public --add-port=9200/tcp --permanent
firewall-cmd --reload
Copy the code
- Access will return version information:http://192.168.3.101:9200/
Kibana installation
- Download kibana6.4.0 Docker image:
Docker pull kibana: 6.4.0Copy the code
- 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.0Copy the code
- Enable firewall:
firewall-cmd --zone=public --add-port=5601/tcp --permanent
firewall-cmd --reload
Copy the code
- Access the address to test:http://192.168.3.101:5601
Mongo installation
- Download Mongo3.2 docker image:
Docker pull mongo: 3.2Copy the code
- Start with the docker command:
Docker run - p - 27017-27017 the name mongo \ - v/mydata/mongo/db: / data/db \ - d mongo: 3.2Copy the code
Docker all environment installation completed
- All downloaded image files:
- All applications running in the container:
SpringBoot application deployment
Build all Docker images and upload them
- Open a comment in POM.xml using the Docker plug-in:
- Modify dockerHost to your own docker server address:
- Build an image and upload it:
Deploy the mall – admin
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 the SNAPSHOTCopy the code
Note: CenterOS7.2 needs to be added to this line, otherwise the container time zone and the host will not be synchronized
-v /etc/timezone:/etc/timezone \
Copy the code
Deploy the mall – search
docker run -p 8081:8081 --name mall-search \ --link elasticsearch:es \ --link mysql:db \ -v The/etc/localtime: / etc/localtime \ v/mydata/app/search/logs: / var/logs \ - d mall/mall - search: 1.0 the SNAPSHOTCopy the code
Deploy the 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 the SNAPSHOTCopy the code
Enabling the 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
Copy the code
Access the interface for testing
- Mall-admin APIhttp://192.168.3.101:8080/swagger-ui.html
- Mall-search APIhttp://192.168.3.101:8081/swagger-ui.html
- Mall-portal API document address:http://192.168.3.101:8085/swagger-ui.html
The public,
Mall project full set of learning tutorials serialized, attention to the public number the first time access.