JEECG containerization deployment

There is a Dockerfile in the JEECG code. The basic idea is to take CentOS as the basic image, in which nginx, jdk, MySQL and redis are installed. The compiled front-end files are copied to the designated directory of nginx, the back-end jar files are placed in the root directory, and the configuration files and script startup files of nginx are generated. Redis, nginx and Java are started in the script startup files -Jar backend service. This article takes MySQL and redis out as a rough solution to container deployment.

Why not use Alpine

Probably because something like a verification code needs to sun.awt Corresponding support. JRE of OpenJDK under alpine cannot be supported. For details, please refer to:

Step 1: start Redis

Execute command: docker run -d --name redis -p 6379:6379 -d redis:6.0.4

liumiaocn:jeecg liumiao$ docker run -d --name redis -p 6379:6379 -d redis:6.0.4
Unable to find image 'redis:6.0.4' locally
6.0.4: Pulling from library/redis
Digest: sha256:ec277acf143340fa338f0b1a9b2f23632335d2096940d8e754474e21476eae32
Status: Downloaded newer image for redis:6.0.4
29bf8656bc8b14a8ee7d64ed97f4f555246ef688cdaf2fae9bb797e92cb35814
liumiaocn:jeecg liumiao$ docker ps |grep redis
29bf8656bc8b        redis:6.0.4         "docker-entrypoint.s..."   7 seconds ago       Up 5 seconds        0.0.0.0:6379->6379/tcp   redis
liumiaocn:jeecg liumiao$ 

Step 2: start MySQL

Execute command:
docker run -d --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d liumiaocn/mysql:5.7.16

liumiaocn:jeecg liumiao$ docker run -d --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d liumiaocn/mysql:5.7.16
49ec74507aa7d70b320139ebed132424351bb7fb433c82d05945100260ea0f41
liumiaocn:jeecg liumiao$ docker ps |grep mysql
49ec74507aa7        liumiaocn/mysql:5.7.16   "docker-entrypoint.s..."   16 seconds ago       Up 15 seconds       0.0.0.0:3306->3306/tcp   mysql
liumiaocn:jeecg liumiao$

Step 3: set MySQL

After MySQL is started, you need to do the following three things:

  • Build database
  • Creating tables and initializing data
  • Set case insensitive

The first two things have SQL files, which can be completed by execution. Case sensitivity is easy to be ignored, but it is also easy to confirm through the execution log. Prepare as follows in advance, copy the following two SQL files provided under the db of JEECG to the MySQL container

liumiaocn:jeecg-boot liumiao$ docker cp 1mysql_schema.sql mysql:/tmp
liumiaocn:jeecg-boot liumiao$ docker cp 2jeecgboot_mysql5.7.sql mysql:/tmp
liumiaocn:jeecg-boot liumiao$ 

Build database

liumiaocn:jeecg-boot liumiao$ docker exec -it mysql sh
# ls /tmp
1mysql_schema.sql  2jeecgboot_mysql5.7.sql
# mysql -uroot -proot
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.16 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases
    -> ;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> source /tmp/1mysql_schema.sql
Query OK, 1 row affected (0.01 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| jeecg-boot         |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

mysql> 

Creating tables and initializing data

mysql> use jeecg-boot
Database changed
mysql> source /tmp/2jeecgboot_mysql5.7.sql
Query OK, 0 rows affected (0.00 sec)
...ellipsis
Query OK, 1 row affected (0.01 sec)
Query OK, 0 rows affected (0.00 sec)
mysql> show tables;
+-------------------------------+
| Tables_in_jeecg-boot          |
+-------------------------------+
| demo                          |
| demo_field_def_val_main       |
| demo_field_def_val_sub        |
| jeecg_monthly_growth_analysis |
| jeecg_order_customer          |
| jeecg_order_main              |
| jeecg_order_ticket            |
| jeecg_project_nature_income   |
| joa_demo                      |
| onl_cgform_button             |
| onl_cgform_enhance_java       |
| onl_cgform_enhance_js         |
| onl_cgform_enhance_sql        |
| onl_cgform_field              |
| onl_cgform_head               |
| onl_cgform_index              |
| onl_cgreport_head             |
| onl_cgreport_item             |
| onl_cgreport_param            |
| oss_file                      |
| qrtz_blob_triggers            |
| qrtz_calendars                |
| qrtz_cron_triggers            |
| qrtz_fired_triggers           |
| qrtz_job_details              |
| qrtz_locks                    |
| qrtz_paused_trigger_grps      |
| qrtz_scheduler_state          |
| qrtz_simple_triggers          |
| qrtz_simprop_triggers         |
| qrtz_triggers                 |
| sys_announcement              |
| sys_announcement_send         |
| sys_category                  |
| sys_check_rule                |
| sys_data_log                  |
| sys_data_source               |
| sys_depart                    |
| sys_depart_permission         |
| sys_depart_role               |
| sys_depart_role_permission    |
| sys_depart_role_user          |
| sys_dict                      |
| sys_dict_item                 |
| sys_fill_rule                 |
| sys_log                       |
| sys_permission                |
| sys_permission_data_rule      |
| sys_position                  |
| sys_quartz_job                |
| sys_role                      |
| sys_role_permission           |
| sys_sms                       |
| sys_sms_template              |
| sys_user                      |
| sys_user_agent                |
| sys_user_depart               |
| sys_user_role                 |
| test_demo                     |
| test_enhance_select           |
| test_order_main               |
| test_order_product            |
| test_person                   |
| test_shoptype_tree            |
+-------------------------------+
64 rows in set (0.00 sec)

mysql> 

Set case insensitive

mysql> exit
Bye
# echo "lower_case_table_names=1" >>/etc/mysql/mysql.conf.d/mysqld.cnf
# 

Restart MySQL container

Because the case insensitive setting needs to restart the MySQL container to take effect, you need to use docker restart mysql to restart the MySQL container

liumiaocn:jeecg-boot liumiao$ docker restart mysql
mysql
liumiaocn:jeecg-boot liumiao$ 

Step 4: start the jeecg container

This article uses the JEECG image based on CentOS. For simplicity, this image puts the front end and the back end together, so there will be two processes in the container, and the obsessive-compulsive patients can be further split. Please be responsible for the changes of the settings.

Execute command: docker run --name=jeecg -d -p 8080:8080 -p 8088:80 liumiaocn/jeecg:centos-2.2.0

liumiaocn:jeecg-boot liumiao$ docker run --name=jeecg -d -p 8080:8080 -p 8088:80 liumiaocn/jeecg:centos-2.2.0
16318371bb5dd33eea37f76eeabf6710dd0c0d65c43e23870d17dbde188dc655
liumiaocn:jeecg-boot liumiao$ docker ps |grep jeecg
16318371bb5d        liumiaocn/jeecg:centos-2.2.0   "/bin/sh -c '/bin/sh..."   6 seconds ago       Up 4 seconds        0.0.0.0:8080->8080/tcp, 0.0.0.0:8088->80/tcp   jeecg
liumiaocn:jeecg-boot liumiao$ 

Step 5: confirm the result

Confirm through docker logs jeecg. If the following similar results appear in the log, it indicates that it has been started successfully:

----------------------------------------------------------
	Application Jeecg-Boot is running! Access URLs:
	Local: 		http://localhost:8080/jeecg-boot/
	External: 	http://172.17.0.4:8080/jeecg-boot/
	Swagger-UI: 		http://172.17.0.4:8080/jeecg-boot/doc.html
----------------------------------------------------------
liumiaocn:jeecg-boot liumiao$ 

Login confirmation page

use http://localhost:8088 / to confirm login on this computer

Login result confirmation

matters needing attention

In order to illustrate the key point of the deployment mode of JEECG, the storage of container initiated persistent data is not listed. Please set it as required. In addition, the external Redis and MySQL services are used in the jar file, so it needs to be set according to the actual needs,

  • Directory of configuration file: jeecg boot / jeecg boot module system / SRC / main / resources
  • Set object file: application.yml
  • Modification content: the active part needs to be set to prod
liumiaocn:resources liumiao$ head -n3 application.yml 
spring:
  profiles:
    active: prod
liumiaocn:resources liumiao$ 
  • Set object file: application.yml
  • Modification content: set corresponding IP
liumiaocn:resources liumiao$ grep 192.168 application-prod.yml 
          url: jdbc:mysql://192.168.31.242:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false
    host: 192.168.31.242
liumiaocn:resources liumiao$ 

Tags: MySQL Docker Redis SQL

Posted on Thu, 04 Jun 2020 15:18:49 -0400 by nonaguy