Mall project is a set of e-commerce system, including front office mall system and background management system. It is implemented based on SpringBoot+MyBatis and deployed in Docker container. The front desk mall system includes home page portal, commodity recommendation, commodity search, commodity display, shopping cart, order process, member center, customer service, help center and other modules. The background management system includes commodity management, order management, member management, promotion management, operation management, content management, statistical report, financial management, authority management, setting and other modules.
1, Learning website
[source address]
- Background item mall:https://github.com/macrozheng/mall
- Front end project: mal admin https://github.com/macrozheng/mall-admin-web
- Micro Service Mall Swarm: https://github.com/macrozheng/mall-swarm
- [learning contents] https://mp.weixin.qq.com/s/s_dKL9aAFXgtQi0VO1Ovdw
- [learning address] https://zhuanlan.zhihu.com/p/450915863
2, docker deployment of mall
[docker deployment address]
- https://mp.weixin.qq.com/s?__biz=MzU1Nzg4NjgyMw==&mid=2247483786&idx=1&sn=33052d6967de1a2c9592b2a1c58b8bef&scene=21#wechat_redirect
1) docker environment installation
#Install Yum utils yum install -y yum-utils device-mapper-persistent-data lvm2 #Add docker warehouse location for yum source: yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo #To install docker: yum install docker-ce -y #Start docker: systemctl start docker systemctl enable docker
2) Deploy harbor
#To create an image, first build the image docker run -d -p 5000:5000 --restart=always --name registry2 registry:2
After downloading the image, I want you to open the remote API
[root@localhost ~]# vim /usr/lib/systemd/system/docker.service #Before modification ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock #After modification ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
#Let Docker support http upload image echo '{ "insecure-registries":["192.168.4.116:5000"] }' >> /etc/docker/daemon.json #After modifying the configuration, you need to use the following commands to make the configuration effective systemctl daemon-reload #Restart Docker service systemctl stop docker systemctl start docker #Open the Docker build port of the firewall firewall-cmd --zone=public --add-port=2375/tcp --permanent firewall-cmd --reload #Log in to harbor docker login -uadmin -pHarbor 192.168.4.116:5000
Modify POM when maven builds Warehouse address in XML file
Before modification <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <skipTests>true</skipTests> <docker.host>unix:///var/run/docker.sock</docker.host> After modification #Change to your own harbor Address; <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <skipTests>true</skipTests> <!--Change to your own Docker Service remote access address--> <docker.host>http://192.168.4.116:2375</docker.host>
Note: it must be written according to the format, otherwise the construction may be wrong. At the same time, do not enter the error, which has been put into the pit
3) Mysql installation
#Download mysql docker pull mysql:5.7 #mysql start docker run -p 3306:3306 --name mysql \ --restart=always \ -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 the 3306 port of the container to the 3306 port of the host
- -v /mydata/mysql/conf:/etc/mysql: hang the configuration folder to 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 MYSQLROOTPASSWORD=root: initialize the password of the root user
#sql address yum install git -y git clone https://gitee.com/aliyunfc/mall #Put mall Copy the SQL file to the / opt directory of the mysql container docker cp document/sql/mall.sql mysql:/opt #Enter the docker container running mysql docker exec -it mysql /bin/bash #Open the client with mysql command mysql -uroot -proot --default-character-set=utf8 #Create a mall database create database mall character set utf8; #Import sql file into database: use mall; source /opt/mall.sql; #Create a reader account and modify the permissions so that any ip can access: grant all privileges on *.* to 'reader' @'%' identified by '123456'; flush privileges; exit
4) Deploy redis
#Download redis3 docker image of 2 docker pull redis:3.2 #Start with docker command docker run -p 6379:6379 --name redis \ --restart=always \ -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
[root@localhost sql]# docker exec -it redis redis-cli 127.0.0.1:6379> set a 100 OK 127.0.0.1:6379> get a "100" 127.0.0.1:6379> exit
5) nginx installation
#Download nginx1 docker image of 10 docker pull nginx:1.10 #Run the container once first (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 file name: mv /mydata/nginx/nginx/ /mydata/nginx/conf #Terminate and delete container: docker stop nginx docker rm nginx #Start with docker command: docker run -p 80:80 --name nginx \ --restart=always \ -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
6) RabbitMQ installation
#Download rabbitmq3 docker image of 7.15 docker pull rabbitmq:3.7.15 #Start with docker command: docker run -d --name rabbitmq \ --restart=always \ --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 turn on the management function: docker exec -it rabbitmq /bin/bash rabbitmq-plugins enable rabbitmq_management exit
[root@localhost nginx]# docker exec -it rabbitmq /bin/bash root@d2c6e05857e5:/# rabbitmq-plugins enable rabbitmq_management Enabling plugins on node rabbit@d2c6e05857e5: rabbitmq_management The following plugins have been configured: rabbitmq_management rabbitmq_management_agent rabbitmq_web_dispatch Applying plugin configuration to rabbit@d2c6e05857e5... The following plugins have been enabled: rabbitmq_management rabbitmq_management_agent rabbitmq_web_dispatch
#Open firewall port 15672: firewall-cmd --zone=public --add-port=15672/tcp --permanent firewall-cmd --reload
visit: http://192.168.4.116:15672/
[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-arjrhk2l-1653057559891)( http://m.qpic.cn/psc?/V53GU2po3e4Vc929i8d01BP45G32VjvB/ruAMsa53pVQWN7FLK88i5rvcmOCSIWSdd6V3jg7KEGM7eLgtJvZJNKxknWsQm0JfeBMuPjMQ *O6fP1Em6s6tHDetvaiAstTf57Zh9Hn7UCo!/ b&bo=PgKOAD4CjgADFzI!& rf=viewer_ 4&t=5)]
Enter the account and password and log in: guest guest
[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-6zyngiyn-1653057559892)( http://m.qpic.cn/psc?/V53GU2po3e4Vc929i8d01BP45G32VjvB/ruAMsa53pVQWN7FLK88i5rvcmOCSIWSdd6V3jg7KEGNMZdlrkHyb.Z1piHR4kaSAvw3kXqNGlj.w0aztjX90XY0r9.zGiM2Ja2l8mSPdY !/ b&bo=PgJLAT4CSwEDFzI!& rf=viewer_ 4&t=5)]
Create an account and set its role as administrator: mall mall
[the external chain picture transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the picture and upload it directly (img-kjqbanqr-1653057559893)( http://m.qpic.cn/psc?/V53GU2po3e4Vc929i8d01BP45G32VjvB/ruAMsa53pVQWN7FLK88i5syHFThBnru1qq1h.GWNYsqWXCSWBpJySalNN2F2RvVmQ6mM8PGQ7lNzZhbn01qelauOmpB *DZN5otCnEMnFw!/ b&bo=PgLHAT4CxwEDFzI!& rf=viewer_ 4&t=5)]
Create a new virtual host with: / mall
[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (IMG mipjuqt1-1653057559893)( http://m.qpic.cn/psc?/V53GU2po3e4Vc929i8d01BP45G32VjvB/ruAMsa53pVQWN7FLK88i5syHFThBnru1qq1h.GWNYuifQGpS2L8obqtRO7NLs6IifIaozrPzKjA5ve7Vosl5exv0LPYnk8Sra5ghRaZbc !/ b&bo=PgKYAD4CmAADFzI!& rf=viewer_ 4&t=5)]
Click "mall" to enter the user configuration page
[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-elxjnhxg-1653057559893)( http://m.qpic.cn/psc?/V53GU2po3e4Vc929i8d01BP45G32VjvB/ruAMsa53pVQWN7FLK88i5qulVCkBQiVOnkvnEEL.m4DT8ncWtYJHfG5ln5LV5tk5vD.QWdBLEjmLfVj3 *TnDjWSjvG16bmlS8bqVLBG19BU!/ b&bo=PgLSAD4C0gADFzI!& rf=viewer_ 4&t=5)]
Configure the permissions of the virtual host for the mall user
[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (IMG hwjgvmo0-1653057559894)( http://m.qpic.cn/psc?/V53GU2po3e4Vc929i8d01BP45G32VjvB/ruAMsa53pVQWN7FLK88i5qulVCkBQiVOnkvnEEL.m4Awz11gNc7DVZz27esr6X3UMJxAB6JOOa1KN7SwiI5DBHNB7E8D8yNCE679d7szM !/ b&bo=PgI. AT4CPgEDFzI!& rf=viewer_ 4&t=5)]
Create a mall user to grant the / mall host. The result is shown in the figure.
[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-hcdd3thm-1653057559894)( http://m.qpic.cn/psc?/V53GU2po3e4Vc929i8d01BP45G32VjvB/ruAMsa53pVQWN7FLK88i5r0SPNyPsWTUhUCVVn0k4.I2YjM.tKH **VTuAwxT*. TmSzH1jnVxgUgKrtskY4yonIkKvNgqEgtrxcVVJRhznlo!/ b&bo=PgLsAD4C7AADFzI!& rf=viewer_ 4&t=5)]
[Alibaba cloud usage] http://www.macrozheng.com/mall/deploy/mall_deploy_windows.html#%E5%88%9B%E5%BB%BA%E5%AD%98%E5%82%A8%E7%A9%BA%E9%97%B4
7) Elasticsearch installation
#Download elasticsearch6 docker image of 4.0: docker pull elasticsearch:6.4.0 #Modify the size of the virtual memory area, otherwise it will be too small to start: sysctl -w vm.max_map_count=262144 #Start with docker command: docker run -p 9200:9200 -p 9300:9300 --name elasticsearch \ --restart=always \ -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 starting, you will find that / usr/share/elasticsearch/data directory does not have access permission. You only need to modify the permission of / mydata/elasticsearch/data directory and restart. chmod 777 /mydata/elasticsearch/data/ #Install the Chinese word splitter IKAnalyzer and restart: docker exec -it elasticsearch /bin/bash #This command needs to be run in the container elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.4.0/elasticsearch-analysis-ik-6.4.0.zip
[root@32144efeca9c elasticsearch]# elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.4.0/elasticsearch-analysis-ik-6.4.0.zip -> Downloading https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.4.0/elasticsearch-analysis-ik-6.4.0.zip [=================================================] 100%?? @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: plugin requires additional permissions @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ * java.net.SocketPermission * connect,resolve See http://docs.oracle.com/javase/8/docs/technotes/guides/security/permissions.html for descriptions of what these permissions allow and the associated risks. Continue with installation? [y/N]y -> Installed analysis-ik [root@32144efeca9c elasticsearch]# exit
#Re mirror docker restart elasticsearch #Turn on the firewall: firewall-cmd --zone=public --add-port=9200/tcp --permanent firewall-cmd --reload
Access will return version information: http://192.168.4.116:9200/
# Access return information { "name" : "aQomelU", "cluster_name" : "elasticsearch", "cluster_uuid" : "3ZdM5rTpSqSBFqtIZkXJ_g", "version" : { "number" : "6.4.0", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "595516e", "build_date" : "2018-08-17T23:18:47.308994Z", "build_snapshot" : false, "lucene_version" : "7.4.0", "minimum_wire_compatibility_version" : "5.6.0", "minimum_index_compatibility_version" : "5.0.0" }, "tagline" : "You Know, for Search"
8) Logstash installation
#Load logstash7 6.2 docker image: docker pull logstash:7.6.2 docker pull logstash:6.5.1 #Modify the configuration file of Logstash The Elasticsearch connection address under the output node in conf is es:9200, and the configuration file address is: https://github.com/macrozheng/mall/blob/master/document/elk/logstash.conf output { elasticsearch { hosts => "es:9200" index => "mall-%{type}-%{+YYYY.MM.dd}" } } #Create the / mydata/logstash directory and the Logstash configuration file Logstash Conf copy to this directory; mkdir /mydata/logstash $ vim /mydata/logstash/logstash.conf #After creating the configuration file, start the Logstash service; docker run --name logstash -p 4560:4560 -p 4561:4561 -p 4562:4562 -p 4563:4563 \ --restart=always \ --link elasticsearch:es \ -v /mydata/logstash/logstash.conf:/usr/share/logstash/pipeline/logstash.conf \ -d logstash:7.6.2 #Go inside the container and install json_lines plug-in. docker exec -it logstash /bin/bash logstash-plugin install logstash-codec-json_lines
#logstash.conf details [root@localhost logstash]# cat logstash.conf input { tcp { mode => "server" host => "0.0.0.0" port => 4560 codec => json_lines type => "debug" } tcp { mode => "server" host => "0.0.0.0" port => 4561 codec => json_lines type => "error" } tcp { mode => "server" host => "0.0.0.0" port => 4562 codec => json_lines type => "business" } tcp { mode => "server" host => "0.0.0.0" port => 4563 codec => json_lines type => "record" } } filter{ if [type] == "record" { mutate { remove_field => "port" remove_field => "host" remove_field => "@version" } json { source => "message" remove_field => ["message"] } } } output { elasticsearch { hosts => "es:9200" index => "mall-%{type}-%{+YYYY.MM.dd}" } }
9) kibana installation
#Download kibana6 docker image of 4.0: docker pull kibana:6.4.0 #Start with docker command: docker run --name kibana -p 5601:5601 \ --restart=always \ --link elasticsearch:es \ -e "elasticsearch.hosts=http://es:9200" \ -d kibana:6.4.0 #Turn on the firewall: firewall-cmd --zone=public --add-port=5601/tcp --permanent firewall-cmd --reload
Access address to test: http://192.168.4.116:5601
[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-ua7irnk3-1653057559894)( http://m.qpic.cn/psc?/V53GU2po3e4Vc929i8d01BP45G32VjvB/ruAMsa53pVQWN7FLK88i5qCaveFxPzKFUckU5v.KbzJLrFk7hz3oKTjRlcQCD0mZftxlGcn3l8ZYMccj1Il0he4StxoJG7gOxZHTaU41.lc !/ b&bo=PgJdAT4CXQEDFzI!& rf=viewer_ 4&t=5)]
10) Mongodb installation
#Download mongo3 docker image of 2: docker pull mongo:3.2 #Start with docker command: docker run -p 27017:27017 --name mongo \ --restart=always \ -v /mydata/mongo/db:/data/db \ -d mongo:3.2
11) Install minio
docker pull minio/minio docker run -p 9000:9000 --name minio \ -d --restart=always \ -e "MINIO_ACCESS_KEY=minioadmin" \ -e "MINIO_SECRET_KEY=minioadmin" \ -v /mydata/minio/data:/data \ -v /mydata/minio/config:/root/.minio \ minio/minio server /data \ --console-address ":9000" --address ":9090"
- visit: http://192.168.4.116:9000/login
- [oss storage] https://blog.csdn.net/weixin_45879810/article/details/117108821
firewall-cmd --zone=public --add-port=9090/tcp --permanent firewall-cmd --zone=public --add-port=9000/tcp --permanent firewall-cmd --reload
12) Docker all environments completed
#Image used [root@localhost nginx]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE mysql 5.7 8aa4b5ffb001 2 days ago 462MB rabbitmq 3.7.15 b3639fca0afd 2 years ago 149MB mongo 3.2 fb885d89ea5c 3 years ago 300MB redis 3.2 87856cc39862 3 years ago 76MB kibana 6.4.0 a7e4cd1a7b45 3 years ago 667MB elasticsearch 6.4.0 1ac676545731 3 years ago 791MB nginx 1.10 0346349a1a64 5 years ago 182MB #Started docker container [root@localhost nginx]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6d6ff9700259 mongo:3.2 "docker-entrypoint.s..." 11 seconds ago Up 9 seconds 0.0.0.0:27017->27017/tcp, :::27017->27017/tcp mongo 1a43beb74905 kibana:6.4.0 "/usr/local/bin/kiba..." 8 minutes ago Up 8 minutes 0.0.0.0:5601->5601/tcp, :::5601->5601/tcp kibana 32144efeca9c elasticsearch:6.4.0 "/usr/local/bin/dock..." 25 minutes ago Up 11 minutes 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp elasticsearch d2c6e05857e5 rabbitmq:3.7.15 "docker-entrypoint.s..." 50 minutes ago Up 50 minutes 0.0.0.0:4369->4369/tcp, :::4369->4369/tcp, 0.0.0.0:5671-5672->5671-5672/tcp, :::5671-5672->5671-5672/tcp, 0.0.0.0:15671-15672->15671-15672/tcp, :::15671-15672->15671-15672/tcp, 0.0.0.0:25672->25672/tcp, :::25672->25672/tcp rabbitmq 50f6143a02fb nginx:1.10 "nginx -g 'daemon of..." 53 minutes ago Up 53 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp, 443/tcp nginx 84a749f56bd3 redis:3.2 "docker-entrypoint.s..." About an hour ago Up About an hour 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp redis 2ad5695e156f mysql:5.7 "docker-entrypoint.s..." About an hour ago Up About an hour 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql
3, SpringBoot application deployment
1) Pull source code
#Enter / opt to download the source code cd /opt/ #Pull #git clone https://github.com/macrozheng/mall-swarm #git clone https://github.com/macrozheng/mall-admin-web git clone https://github.com/macrozheng/mall #Use source code here git clone https://gitee.com/aliyunfc/mall
[[old version] #Clone code warehouse git clone https://github.com/hryang/mall #Domestic access to the github network is not good. If the clone is too slow, you can use the Gitee address. git clone https://gitee.com/aliyunfc/mall
2) Organizational structure
root@k8s-master-01 mall]# cd /opt/mall/mall mall ├── mall-common -- Tools and general codes ├── mall-mbg -- MyBatisGenerator Generated database operation code ├── mall-security -- SpringSecurity Encapsulated common module ├── mall-admin -- Backstage mall management system interface ├── mall-search -- be based on Elasticsearch Commodity search system ├── mall-portal -- Front desk mall system interface └── mall-demo -- Test code during framework construction
3) Deploy maven
#Deploy maven yum install maven -y #Modify mvn configuration source to Ali source configuration [Address] https://developer.aliyun.com/mvn/guide [root@k8s-master-01 ~]# vim /etc/maven/settings.xml 159 Row join --> ##################Add content## <mirror> <id>aliyunmaven</id> <mirrorOf>*</mirrorOf> <name>Alibaba cloud public warehouse</name> <url>https://maven.aliyun.com/repository/public</url> </mirror> ####################Add content## </mirrors> <!-- profiles
4) Modify harbor Address
Open POM Comments on using docker plug-in in XML:
Before modification <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <skipTests>true</skipTests> <docker.host>unix:///var/run/docker.sock</docker.host> After modification #Change to your own harbor Address; <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <skipTests>true</skipTests> <!--Change to your own Docker Service remote access address--> <docker.host>http://192.168.4.116:2375</docker.host> <docker.maven.plugin.version>1.2.2</docker.maven.plugin.version> <pagehelper-starter.version>1.3.0</pagehelper-starter.version>
5) Configure harbor warehouse authentication (https is temporarily problematic)
#All harbor warehouses need to be configured cat >>/etc/docker/daemon.json<<EOF #{"registry-mirrors": ["https://docker.gayj.cn"]} {"insecure-registries":["docker.gayj.cn"]} EOF #Create ca authentication directory mkdir -p /etc/docker/certs.d/docker.gayj.cn echo "192.168.x.x docker.gayj.cn" >>/etc/hosts #Copy authentication key scp -r /data/cert/ssl/docker.gayj.cn.crt root@192.168.4.119:/etc/docker/certs.d/docker.gayj.cn/ #Restart docker systemctl daemon-reload systemctl restart docker.service #Login warehouse docker login -uadmin -pHarbor docker.gayj.cn
Log in to the harbor warehouse to create the image directory
- https://docker.gayj.cn/harbor/sign-in
- Account: admin
- Password: Harbor 12345
- Create mall private warehouse directory
- The name of the packaged image is docker gayj. cn/mall/xxx:xxx
5) Modify the configuration of the mall application
modify
- mall-admin/src/main/resources/application-prod.yml
- mall-portal/src/main/resources/application-prod.yml
- mall-search/src/main/resources/application-prod.yml
- Change the host field to the public ip of the node where you installed MySQL and other software in step 1.
#Batch modify replace IP with db find . -name "*application-prod.yml" |xargs -i sed -i "s/112.124.39.109/db/g" {} #Batch view find . -name "application-prod.yml" |xargs -i cat {}
Note: all addresses in yaml files need to be modified, so batch modification is not allowed.
6) Generate the image of the mall application container
- Execute the maven package command to generate a docker image.
- The local environment can be either java8 or java11
#POM in application Add the dependency details of docker Maven plugin in the XML file (it exists in the source code and does not need to be added) <build> <pluginManagement> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>${docker.maven.plugin.version}</version> <executions> <execution> <id>build-image</id> <phase>package</phase> <goals> <goal>build</goal> </goals> </execution> </executions> <configuration> <imageName>mall/${project.artifactId}:${project.version}</imageName> <dockerHost>${docker.host}</dockerHost> <baseImage>java:8</baseImage> <entryPoint>["java", "-jar", "-Dspring.profiles.active=prod","/${project.build.finalName}.jar"] </entryPoint> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </resource> </resources> </configuration> </plugin> </plugins> </pluginManagement> </build>
- executions.execution.phase: it is configured here to build a docker image when maven packages the application;
- imageName: used to specify the image name. mall is the warehouse name, p r o j e c t . a r t i f a c t I d by mirror image name call , {project.artifactId} is the image name, project.artifactId is the image name and {project.version} is the image version number;
- dockerHost: the address of the docker server uploaded after packaging;
- baseImage: the basic image on which the application depends. Here is java;
- entryPoint: the command executed when the docker container is started;
- resources.resource.targetPath: copy the packaged resource file to this directory;
- resources.resource.directory: the directory where the files to be copied are located. The application jar package packaged by maven is saved under the target directory;
- resources.resource.include: files to be copied and packaged application jar packages.
#Deploy Java environment yum install java-1.8.0-openjdk maven -y #Clean up build cd /opt/mall/ mvn clean package -Dmaven.test.skip=true
[Error reporting] [ERROR] Failed to execute goal com.spotify:docker-maven-plugin:1.2.2:build (build-image) on project mall-admin: Exception caught: url has null scheme -> [Help 1] [[reason] Docker 2375 port is not open [[solution] $ vim /usr/lib/systemd/system/docker.service #Before modification ExecStart=/usr/bin/dockerd #After modification ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
systemctl daemon-reload systemctl restart docker firewall-cmd --zone=public --add-port=2375/tcp --permanent firewall-cmd --reload
If you can't solve the problem, you need to check POM Is the docker address in XML correct
<docker.host>http://192.168.4.116:2375</docker.host>
[root@localhost mall]# mvn clean package -Dmaven.test.skip=true . . . . . . [INFO] mall-security ..................................... SUCCESS [1.073s] [INFO] mall-demo ......................................... SUCCESS [6.960s] [INFO] mall-admin ........................................ SUCCESS [22.166s] [INFO] mall-search ....................................... SUCCESS [10.760s] [INFO] mall-portal ....................................... SUCCESS [9.791s] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1:32.102s [INFO] Finished at: Sat Apr 30 17:22:06 CST 2022 [INFO] Final Memory: 87M/1056M [INFO] ------------------------------------------------------------------------ #Generate image [root@localhost mall]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE mall/mall-portal 1.0-SNAPSHOT 1f4d35e6800f 5 minutes ago 708MB mall/mall-search 1.0-SNAPSHOT a900979ac21b 5 minutes ago 727MB mall/mall-admin 1.0-SNAPSHOT 18c25905a078 5 minutes ago 707MB <none> <none> 976fdd88297e 19 minutes ago 707MB mysql 5.7 8aa4b5ffb001 2 days ago 462MB registry 2 2e200967d166 3 weeks ago 24.2MB java 8 d23bdf5b1b1b 5 years ago 643MB
7) Deploy mall admin
docker run -p 8080:8080 --name mall-admin \ --restart=always \ --link mysql:db \ -v /etc/localtime:/etc/localtime \ -v /mydata/app/admin/logs:/var/logs \ -d mall/mall-admin:1.0-SNAPSHOT
Note: centeros7 Version 2 needs to add this line, otherwise the container time zone and the host cannot be synchronized
- -v /etc/timezone:/etc/timezone \
8) Deploy mall search
docker run -p 8081:8081 --name mall-search \ --restart=always \ --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
9) Deploy mall port
docker run -p 8085:8085 --name mall-portal \ --restart=always \ --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
#Turn on 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
10) Access test
api interface document address of all admin: http://192.168.4.116:8080/swagger-ui.html
[the external chain image transfer fails. The source station may have anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-rs1t7xvu-1653057559895)( http://m.qpic.cn/psc?/V53GU2po3e4Vc929i8d01BP45G32VjvB/ruAMsa53pVQWN7FLK88i5tnhRI48U4WtGgJmwH3SPlonv7m2DhtmhDXHFt1SrX7cusC0ZGAu0fNE2x308opJC7kY9vMPYOh9ref4WStpRyU !/ b&bo=PgLkAT4C5AEDFzI!& rf=viewer_ 4&t=5)]
api interface document address of mall search: http://192.168.4.116:8081/swagger-ui.html
[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-hhs6ldju-1653057559895)( http://m.qpic.cn/psc?/V53GU2po3e4Vc929i8d01BP45G32VjvB/ruAMsa53pVQWN7FLK88i5tnhRI48U4WtGgJmwH3SPlokFNMHq8pE4SntxA6X5eOmcmKy0ikIzLDV2UeZg2KO8RPeQNICj7nudwo9VOb *VC0!/ b&bo=PgKqAT4CqgEDFzI!& rf=viewer_ 4&t=5)]
api interface document address of mall portal: http://192.168.4.116:8085/swagger-ui.html
[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-rafcute5-1653057559895)( http://m.qpic.cn/psc?/V53GU2po3e4Vc929i8d01BP45G32VjvB/ruAMsa53pVQWN7FLK88i5tnhRI48U4WtGgJmwH3SPlqIzDZQJLTyzz6lWMsFIlAySbiLY9Dt7sAUnhleikg2BgJ2TWHiwnT5a12xUIl9I !/ b&bo=PgLqAT4C6gEDFzI!& rf=viewer_ 4&t=5)]
4, Mall tiny docker
[source address] https://github.com/macrozheng/mall-learning.git
- https://github.com/macrozheng/mall-learning/tree/master/mall-tiny-docker
[deployment reference] - http://www.macrozheng.com/mall/reference/docker_maven.html#docker-registry
[publish deployment document] - https://github.com/macrozheng/mall-learning/commit/d7f571f8f817229583f89b239976551e6dc85a8c
1) Download source code
#To / opt cd /opt git clone https://github.com/macrozheng/mall-learning.git mvn clean package -Dmaven.test.skip=true
2) Modify warehouse address
#Modify warehouse address $ vim /opt/mall-learning/mall-tiny-docker/pom.xml <configuration> <imageName>mall-tiny/${project.artifactId}:${project.version}</imageName> <dockerHost>http://192.168.4.116:2375</dockerHost> <baseImage>java:8</baseImage> <entryPoint>["java", "-jar","/${project.build.finalName}.jar"]
3) Modify mysql database connection name
When the container is running, you can refer to the name of mysql - dock, which can be used to access the virtual machine in the container. When the container is running, you can refer to the name of mysql - dock, which can be used to access the virtual machine.
#Modify application YML, change localhost to 192.168.4.116 #Batch modification find /opt/mall-learning/mall-tiny-docker/ -name "*application.yml" |xargs -i sed -i "s/localhost:3306/192.168.4.116:3306/g" {} #Batch view find /opt/mall-learning/mall-tiny-docker/ -name "application.yml" |xargs -i cat {}
Note that you need to test whether mysql can connect remotely. The remote address is the IP address.
#View details [root@localhost mall-portal]# cat /opt/mall-learning/mall-tiny-docker/src/main/resources/application.yml server: port: 8080 spring: datasource: url: jdbc:mysql://192.168.4.116:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai username: root password: root mybatis: mapper-locations: - classpath:mapper/*.xml - classpath*:com/**/mapper/*.xml
4) Authorize mysql
Because the user name and password to connect to the database are root
#Enter mysql docker exec -it mysql /bin/bash mysql -uroot -proot --default-character-set=utf8 #Modify the permissions of the root account so that any ip can access: grant all privileges on *.* to 'root'@'%'; flush privileges; exit
5) Build image
#structure cd /opt/mall-learning/mall-tiny-docker [root@localhost mall-tiny-docker]# mvn clean package -Dmaven.test.skip=true . . . . . . Successfully built d24b0dd74bdf Successfully tagged mall-tiny/mall-tiny-docker:0.0.1-SNAPSHOT [INFO] Built mall-tiny/mall-tiny-docker:0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1:16.588s [INFO] Finished at: Sat Apr 30 20:27:29 CST 2022 [INFO] Final Memory: 55M/369M [INFO] ------------------------------------------------------------------------
6) Deploy the mall tiny docker application service
docker run -p 8080:8083 --name mall-tiny-docker \ --restart=always \ --link mysql:db \ -v /etc/localtime:/etc/localtime \ -v /mydata/app/mall-tiny-docker/logs:/var/logs \ -d mall-tiny/mall-tiny-docker:0.0.1-SNAPSHOT
Due to the 8080 port occupation conflict, start 8083
- visit: http://192.168.4.116:8083/swagger-ui.html
[external link image transfer failed. The source station may have anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-beomof7x-1653057559896)( http://m.qpic.cn/psc?/V53GU2po3e4Vc929i8d01BP45G32VjvB/ruAMsa53pVQWN7FLK88i5vLz3PAnnghodxmas9UmQFMwKTMdX6N7QggCgr5Jacy6UKTQP7Fagri.4T.rPxpaSU *zLP7XX1CZcTjzpegFHak!/ b&bo=PgIKAT4CCgEDFzI!& rf=viewer_ 4&t=5)]
5, mall front end deployment
1) Install npm command
wget -c https://nodejs.org/dist/v12.14.0/node-v12.14.0-linux-x64.tar.xz tar xvf node-v12.14.0-linux-x64.tar.xz -C /usr/local/ ln -s /usr/local/node-v12.14.0-linux-x64/bin/node /usr/local/bin/node ln -s /usr/local/node-v12.14.0-linux-x64/bin/npm /usr/local/bin/npm #Since the official image is relatively slow, directly execute the following command to change the image address to the npm image address of Taobao npm install -g cnpm --registry=https://registry.npm.taobao.org npm -v #Global Update npm install npm -g
2) Modify prod.env JS configuration
- Note: if you don't change it, use the API address provided by the online author.
- If the mall background is not set up, you need to use the online API to access it. The online API address is: https://admin-api.macrozheng.com
#Modify to your own background API address [root@localhost config]# cat /opt/mall-admin-web/config/prod.env.js 'use strict' module.exports = { NODE_ENV: '"production"', BASE_API: '"https://admin-api.macrozheng.com"' }
The backend API address this time is 192.168.4.116
[root@localhost opt]# sed -i 's#https://admin-api.macrozheng.com#http://192.168.4.116:8080#g' /opt/mall-admin-web/config/prod.env.js [root@localhost config]# cat /opt/mall-admin-web-master/config/prod.env.js 'use strict' module.exports = { NODE_ENV: '"production"', BASE_API: '"http://192.168.4.116:8080"' }
3) Build packaged code
cd /opt/mall-admin-web #Clear cache npm cache clean --force npm install npm run build
#Installation details [root@localhost mall-admin-web]# npm install up to date, audited 1275 packages in 47s 1 package is looking for funding run `npm fund` for details 123 vulnerabilities (5 low, 70 moderate, 39 high, 9 critical) To address issues that do not require attention, run: npm audit fix To address all issues (including breaking changes), run: npm audit fix --force Run `npm audit` for details.
#Build details [root@localhost mall-admin-web]# npm run build ....... static/tinymce4.7.5/tinymce.min.js 834 kB [emitted] [big] Build complete. Tip: built files are meant to be served over an HTTP server. Opening index.html over file:// won't work.
#Packaged code [root@localhost mall-admin-web]# ll /opt/mall-admin-web/dist/ Total consumption 4 -rw-r--r-- 1 root root 1159 4 June 30-22:44 index.html drwxr-xr-x 7 root root 71 4 June 30-22:44 static
4) Modify Nginx release code
#Find the publication directory of Nginx [root@localhost mall-admin-web]# ls /mydata/nginx/html/ [root@localhost mall-admin-web]# mv dist html #Put the packaged front-end files in nginx directory [root@localhost mall-admin-web]# mv /opt/mall-admin-web/html/ /mydata/nginx/ mv: Overwrite"/mydata/nginx/html"? yes [root@localhost mall-admin-web]# ls /mydata/nginx/html/ index.html static
#restart docker restart mall-admin docker restart nginx
visit: http://192.168.4.116
[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-pt2lnsea-1653057559896)( http://m.qpic.cn/psc?/V53GU2po3e4Vc929i8d01BP45G32VjvB/ruAMsa53pVQWN7FLK88i5kD3tGoiX64SCzyQEi7siYA78sMR.rmTH3OwdnCGG0LEDeC6m1NrCuETtSE4QLRlEuKL1aZmvHsqxYDmucH9Y !/ b&bo=PgJUAT4CVAEDFzI!& rf=viewer_ 4&t=5)]
Login operation
- Account: admin
- Password: macro123
[the external chain picture transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the picture and upload it directly (img-yhsnjwu0-1653057559896)( http://m.qpic.cn/psc?/V53GU2po3e4Vc929i8d01BP45G32VjvB/ruAMsa53pVQWN7FLK88i5kD3tGoiX64SCzyQEi7siYBRIfXL0ppLlCEWWHban1AY3fKbn8j29jRwANgwStn2cdJS0rZ74BXAlQ01LyLf6o0 !/ b&bo=PgKaAT4CmgEDFzI!& rf=viewer_ 4&t=5)]
View the login process. At this time, it is the author's back-end address
[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-gxxrk3uj-1653057559897)( http://m.qpic.cn/psc?/V53GU2po3e4Vc929i8d01BP45G32VjvB/ruAMsa53pVQWN7FLK88i5nTTecQWogYjuNlPtJPfhn *KNwVjZAnHMtyEYusbz6b1vV0VXlUsorwomi366Sw84sGdcNXKyCPTAxJKKxzuDxY!/ b&bo=PgKuAj4CrgIDJwI!& rf=viewer_ 4&t=5)]
When modifying to your own back-end API address, log in as shown in the figure below
[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-zptg5iyv-1653057559897)( http://m.qpic.cn/psc?/V53GU2po3e4Vc929i8d01BP45G32VjvB/ruAMsa53pVQWN7FLK88i5iXOh8tIZtZvixQDhdf07vrsgLCxVx2FsaNnOwKkld77jeaALg1Eagdeu.QUleyCZaTtdSUkPYqedvDOBFv7yhY !/ b&bo=MALiATAC4gEDFzI!& rf=viewer_ 4&t=5)]
Back end test
[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-eh63iflz-1653057559897)( http://m.qpic.cn/psc?/V53GU2po3e4Vc929i8d01BP45G32VjvB/ruAMsa53pVQWN7FLK88i5hZHi9wPSAqmZlX9Jrk7K6OyFaSEEsyKqQpBvmAx2R7n30j7zoxqsmRUDi *BVd2sL7. ipEIiozb4m. ghSMxoE!/ b&bo=PgIuAT4CLgEDFzI!& rf=viewer_ 4&t=5)]
6, mall backend and backend reference address
[reference for image making]
- https://www.icode9.com/content-4-847241.html
- https://www.cnblogs.com/wangluf/p/15674509.html
- https://blog.csdn.net/qq_46162321/article/details/122462429
[key reference]
- https://www.cnblogs.com/jinsheng1027/p/12232927.html
- http://www.macrozheng.com/mall/deploy/mall_deploy_docker_compose.html#%E9%83%A8%E7%BD%B2%E7%9B%B8%E5%85%B3%E6%96%87%E4%BB%B6
- [build image] http://www.macrozheng.com/mall/reference/docker_maven.html#docker-registry
[official deployment document] - https://www.macrozheng.com/mall/catalog/mall_catalog.html#%E5%8F%8B%E6%83%85%E6%8F%90%E7%A4%BA
- [official mirror address] https://hub.docker.com/
- This document is originally created by the blogger, and the reprint needs to be attached with the address. The commercial use needs to obtain the consent of the blogger. If there is any problem, you can contact jiawanchao 666666 via wechat. Simple problems can be solved or left a message for free, and the whole process operation can be guided with compensation. If you are the one.
- The author has completed k8s deploying mall microservices, which can be provided for a fee.
visit: http://192.168.4.116 [External chain picture transfer...(img-Pt2lnsEA-1653057559896)] Login operation - Account: admin - password: macro123 [External chain picture transfer...(img-YHSNJwU0-1653057559896)] View the login process. At this time, it is the author's back-end address [External chain picture transfer...(img-GxxRK3UJ-1653057559897)] Modify to own backend API The login address is shown in the figure below [External chain picture transfer...(img-ZpTG5iyV-1653057559897)] Back end test [External chain picture transfer...(img-EH63iFlZ-1653057559897)] ### 6, mall backend and backend reference address [Making image [for reference] - https://www.icode9.com/content-4-847241.html - https://www.cnblogs.com/wangluf/p/15674509.html - https://blog.csdn.net/qq_46162321/article/details/122462429 [[key reference] - https://www.cnblogs.com/jinsheng1027/p/12232927.html - http://www.macrozheng.com/mall/deploy/mall_deploy_docker_compose.html#%E9%83%A8%E7%BD%B2%E7%9B%B8%E5%85%B3%E6%96%87%E4%BB%B6 - [[build image] http://www.macrozheng.com/mall/reference/docker_maven.html#docker-registry [Official deployment document] - https://www.macrozheng.com/mall/catalog/mall_catalog.html#%E5%8F%8B%E6%83%85%E6%8F%90%E7%A4%BA - [Official mirror address] https://hub.docker.com/ **- This document is the original of blogger, and the address should be attached for reprint. Commercial use can only be done with the consent of blogger. If you have any questions, please contact wechat jiawenchao666666,Simple problems can be solved or left a message for free, and the whole process operation can be guided with compensation. If you are the one.** **- Author completed k8s deploy mall Microservices,Can be paid**