DockerCompose+SpringBoot+Nginx+Mysql实践

DockerCompose+SpringBoot+Nginx+Mysql实践

1、Spring Boot案例

首先我们先准备一个 Spring Boot 使用 Mysql 的小场景,我们做这样一个示例,使用 Spring Boot 做一个 Web 应

用,提供一个按照 IP 地址统计访问次数的方法,每次请求时将统计数据存入 Mysql 并展示到页面中。

1.1 pom依赖


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0modelVersion>

    <groupId>com.neogroupId>
    <artifactId>dockercompose-springboot-mysql-nginxartifactId>
    <version>1.0version>
    <packaging>jarpackaging>

    <name>dockercompose-springboot-mysql-nginxname>
    <description>Demo project for Spring Bootdescription>

    <parent>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-parentartifactId>
        <version>2.0.0.RELEASEversion>
    parent>

    <properties>
        <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
        <java.version>1.8java.version>
    properties>

    <dependencies>

        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
        dependency>

        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-data-jpaartifactId>
        dependency>

        <dependency>
            <groupId>mysqlgroupId>
            <artifactId>mysql-connector-javaartifactId>
        dependency>

        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-testartifactId>
            <scope>testscope>
        dependency>

    dependencies>

    <build>
        <defaultGoal>compiledefaultGoal>
        <plugins>
            <plugin>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-maven-pluginartifactId>
            plugin>
        plugins>
    build>


project>

主要添加了 Spring Boot Web 支持,使用 Jpa 操作数据库、添加 Myql 驱动包等。

1.2 配置文件

application.properties

spring.jpa.properties.hibernate.hbm2ddl.auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.show-sql=true

spring.profiles.active=dev
server.port=8090

application-dev.properties

spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
server.port=8090

application-docker.properties

spring.datasource.url=jdbc:mysql://mysql:3306/test
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
server.port=8090

配置了数据库的链接信息,以及 Jpa 更新表模式、方言和是否显示Sql。

1.3 核心代码

核心代码很简单,每过来一个请求,判断是否已经统计过,如果没有统计新增数据,如果有统计数据更新数据。

package com.neo.controller;

import com.neo.entity.Visitor;
import com.neo.repository.VisitorRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class VisitorController {

    @Autowired
    private VisitorRepository repository;

    @RequestMapping("/")
    public String index(HttpServletRequest request) {
        String ip = request.getRemoteAddr();
        Visitor visitor = repository.findByIp(ip);
        if (visitor == null) {
            visitor = new Visitor();
            visitor.setIp(ip);
            visitor.setTimes(1);
        } else {
            visitor.setTimes(visitor.getTimes() + 1);
        }
        repository.save(visitor);
        return "I have been seen ip " + visitor.getIp() + " " + visitor.getTimes() + " times.";
    }
}

实体类和 Repository 层代码比较简单。

package com.neo.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity
public class Visitor {
    @Id
    @GeneratedValue
    private long id;
    @Column(nullable = false)
    private long times;
    @Column(nullable = false)
    private String ip;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public long getTimes() {
        return times;
    }

    public void setTimes(long times) {
        this.times = times;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }
}
package com.neo.repository;

import com.neo.entity.Visitor;
import org.springframework.data.jpa.repository.JpaRepository;

public interface  VisitorRepository extends JpaRepository<Visitor, Long> {
    Visitor findByIp(String ip);
}
package com.neo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class ComposeApplication {

    public static void main(String[] args) {
        SpringApplication.run(ComposeApplication.class, args);
    }
}

以上内容都完成后,启动项目,访问:http://localhost:8090/ 我们就可以看到这样的返回结果:

I have been seen ip 0:0:0:0:0:0:0:1 1 times.

再访问一次会变成

I have been seen ip 0:0:0:0:0:0:0:1 2 times.

多次访问一直叠加,说明演示项目开发完成。

2、Docker化改造

首先我们将目录改造成这样一个结构

DockerCompose+SpringBoot+Nginx+Mysql实践_第1张图片

我们先从最外层说起:

  • docker-compose.yaml:docker-compose 的核心文件,描述如何构建整个服务。

  • nginx:有关 nginx 的配置。

  • app:Spring Boot 项目地址。

如果我们需要对 Mysql 有特殊的定制,也可以在最外层创建 mysql 文件夹,在此目录下进行配置。

2.1 docker-compose.yaml 文件详解

version: '3'
services:
  nginx:
    container_name: v-nginx
    image: nginx:1.13
    restart: always
    ports:
      - 80:80
      - 443:443
    volumes:
      - ./nginx/conf.d:/etc/nginx/conf.d

  mysql:
    container_name: v-mysql
    image: mysql/mysql-server:5.7
    environment:
      MYSQL_DATABASE: test
      MYSQL_ROOT_PASSWORD: root
      MYSQL_ROOT_HOST: '%'
    ports:
      - "3306:3306"
    restart: always

  app:
    container_name: app
    restart: always
    build: ./app
    working_dir: /app
    volumes:
      - ./app:/app
      - /home/zhangshixing/maven/m2:/root/.m2
    expose:
      - "8090"
    depends_on:
      - nginx
      - mysql
    command: mvn clean spring-boot:run -Dspring-boot.run.profiles=docker
  • version: '3': 表示使用第三代语法来构建 docker-compose.yaml 文件。

  • services:用来表示 compose 需要启动的服务,我们可以看出此文件中有三个服务分别为:nginx、

    mysql、app。

  • container_name:容器名称

  • environment:此节点下的信息会当作环境变量传入容器,此示例中 mysql 服务配置了数据库、密码和权限

    信息。

  • ports:表示对外开放的端口

  • restart: always:表示如果服务启动不成功会一直尝试。

  • volumes:加载本地目录下的配置文件到容器目标地址下

  • depends_on:可以配置依赖服务,表示需要先启动 depends_on 下面的服务后,再启动本服务。

  • command: mvn clean spring-boot:run -Dspring-boot.run.profiles=docker :表示以这个命令来启

    动项目,-Dspring-boot.run.profiles=docker表示使用 application-docker.properties文件配置信

    息进行启动。

2.2 Nginx 文件解读

nginx 在目录下有一个文件 app.conf,主要配置了服务转发信息。

server {
    listen 80;
    charset utf-8;
    access_log off;

    location / {
        proxy_pass http://app:8090;
        proxy_set_header Host $host:$server_port;
        proxy_set_header X-Forwarded-Host $server_name;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location /static {
        access_log   off;
        expires      30d;

        alias /app/static;
    }
}

这块内容比较简单,配置请求转发,将80端口的请求转发到服务 app 的8090端口。其中proxy_pass

http://app:8090这块的配置信息。

需要解释一下,这里使用是app而不是localhost,是因为他们没有在一个容器中,在一组 compose 的服务通

讯需要使用 services 的名称进行访问。

2.3 Spring Boot 项目改造

app目录下也就是和pom.xm文件同级添加Dockerfile文件,文件内容如下:

FROM maven:3.5-jdk-8

只有一句,依赖于基础镜像maven3.5jdk1.8。因为在docker-compose.yaml文件设置了项目启动命令,这

里不需要再添加启动命令。

在项目的resources目录下创建application-dev.propertiesapplication-docker.properties文件

  • application-dev.properties 中的配置信息和上面一致

  • application-docker.properties 中的配置信息做稍微的改造,将数据库的连接信息由

    jdbc:mysql://localhost:3306/test改为jdbc:mysql://mysql:3306/test

这样我们所有的配置都已经完成。

2.4 部署

我们将项目拷贝到服务器中进行测试,服务器需要先安装 Docker 和 Docker Compos 环境。

将项目拷贝到服务器中,进入目录:cd dockercompose-springboot-mysql-nginx

启动服务:docker-compose up

[root@zsx dockercompose-springboot-mysql-nginx]# docker-compose up
[+] Running 4/4
 ⠿ Network dockercompose-springboot-mysql-nginx_default  Created                                                               0.2s
 ⠿ Container v-mysql                                     Created                                                               0.1s
 ⠿ Container v-nginx                                     Created                                                               0.1s
 ⠿ Container app                                         Created                                                               0.3s
Attaching to app, v-mysql, v-nginx
v-mysql  | [Entrypoint] MySQL Docker Image 5.7.41-1.2.11-server
v-mysql  | [Entrypoint] Initializing database
v-mysql  | 2024-01-28T04:06:28.932555Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
v-mysql  | 2024-01-28T04:06:29.181788Z 0 [Warning] InnoDB: New log files created, LSN=45790
v-mysql  | 2024-01-28T04:06:29.273310Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
v-mysql  | 2024-01-28T04:06:29.408225Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 9d205946-bd92-11ee-a298-0242ac120003.
v-mysql  | 2024-01-28T04:06:29.416618Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
v-mysql  | 2024-01-28T04:06:29.767946Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
v-mysql  | 2024-01-28T04:06:29.770248Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
v-mysql  | 2024-01-28T04:06:29.770782Z 0 [Warning] CA certificate ca.pem is self signed.
v-mysql  | 2024-01-28T04:06:29.825640Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
app      | [INFO] Scanning for projects...
app      | [INFO]
app      | [INFO] ------------< com.neo:dockercompose-springboot-mysql-nginx >------------
app      | [INFO] Building dockercompose-springboot-mysql-nginx 1.0
app      | [INFO] --------------------------------[ jar ]---------------------------------
app      | [INFO]
app      | [INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ dockercompose-springboot-mysql-nginx ---
app      | [INFO] Deleting /app/target
app      | [INFO]
app      | [INFO] >>> spring-boot-maven-plugin:2.0.0.RELEASE:run (default-cli) > test-compile @ dockercompose-springboot-mysql-nginx >>>
app      | [INFO]
app      | [INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ dockercompose-springboot-mysql-nginx ---
app      | [INFO] Using 'UTF-8' encoding to copy filtered resources.
app      | [INFO] Copying 3 resources
app      | [INFO] Copying 0 resource
app      | [INFO]
app      | [INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ dockercompose-springboot-mysql-nginx ---
app      | [INFO] Changes detected - recompiling the module!
app      | [INFO] Compiling 4 source files to /app/target/classes
app      | [INFO]
app      | [INFO] --- maven-resources-plugin:3.0.1:testResources (default-testResources) @ dockercompose-springboot-mysql-nginx ---
app      | [INFO] Using 'UTF-8' encoding to copy filtered resources.
app      | [INFO] skip non existing resourceDirectory /app/src/test/resources
app      | [INFO]
app      | [INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ dockercompose-springboot-mysql-nginx ---
app      | [INFO] Nothing to compile - all classes are up to date
app      | [INFO]
app      | [INFO] <<< spring-boot-maven-plugin:2.0.0.RELEASE:run (default-cli) < test-compile @ dockercompose-springboot-mysql-nginx <<<
app      | [INFO]
app      | [INFO]
app      | [INFO] --- spring-boot-maven-plugin:2.0.0.RELEASE:run (default-cli) @ dockercompose-springboot-mysql-nginx ---
v-mysql  | [Entrypoint] Database initialized
v-mysql  | 2024-01-28T04:06:36.934640Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
v-mysql  | 2024-01-28T04:06:36.935929Z 0 [Note] mysqld (mysqld 5.7.41) starting as process 50 ...
v-mysql  | 2024-01-28T04:06:36.947967Z 0 [Note] InnoDB: PUNCH HOLE support available
v-mysql  | 2024-01-28T04:06:36.947993Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
v-mysql  | 2024-01-28T04:06:36.947996Z 0 [Note] InnoDB: Uses event mutexes
v-mysql  | 2024-01-28T04:06:36.947999Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
v-mysql  | 2024-01-28T04:06:36.948001Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.12
v-mysql  | 2024-01-28T04:06:36.948003Z 0 [Note] InnoDB: Using Linux native AIO
v-mysql  | 2024-01-28T04:06:36.948198Z 0 [Note] InnoDB: Number of pools: 1
v-mysql  | 2024-01-28T04:06:36.948282Z 0 [Note] InnoDB: Using CPU crc32 instructions
v-mysql  | 2024-01-28T04:06:36.960215Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
v-mysql  | 2024-01-28T04:06:36.994304Z 0 [Note] InnoDB: Completed initialization of buffer pool
v-mysql  | 2024-01-28T04:06:36.996097Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
v-mysql  | 2024-01-28T04:06:37.009968Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
v-mysql  | 2024-01-28T04:06:37.062369Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
v-mysql  | 2024-01-28T04:06:37.062444Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
v-mysql  | 2024-01-28T04:06:37.109205Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
v-mysql  | 2024-01-28T04:06:37.109985Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
v-mysql  | 2024-01-28T04:06:37.109993Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
v-mysql  | 2024-01-28T04:06:37.110223Z 0 [Note] InnoDB: Waiting for purge to start
v-mysql  | 2024-01-28T04:06:37.166911Z 0 [Note] InnoDB: 5.7.41 started; log sequence number 2762314
v-mysql  | 2024-01-28T04:06:37.167162Z 0 [Note] Plugin 'FEDERATED' is disabled.
v-mysql  | 2024-01-28T04:06:37.176325Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
v-mysql  | 2024-01-28T04:06:37.176340Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
v-mysql  | 2024-01-28T04:06:37.176344Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
v-mysql  | 2024-01-28T04:06:37.176346Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
v-mysql  | 2024-01-28T04:06:37.177082Z 0 [Warning] CA certificate ca.pem is self signed.
v-mysql  | 2024-01-28T04:06:37.177140Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
v-mysql  | 2024-01-28T04:06:37.178061Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
v-mysql  | 2024-01-28T04:06:37.179303Z 0 [Note] InnoDB: Buffer pool(s) load completed at 240128  4:06:37
v-mysql  | 2024-01-28T04:06:37.218314Z 0 [Note] Event Scheduler: Loaded 0 events
v-mysql  | 2024-01-28T04:06:37.218444Z 0 [Note] mysqld: ready for connections.
v-mysql  | Version: '5.7.41'  socket: '/var/lib/mysql/mysql.sock'  port: 0  MySQL Community Server (GPL)
v-mysql  | 2024-01-28T04:06:37.291814Z 3 [Note] InnoDB: Stopping purge
v-mysql  | 2024-01-28T04:06:37.300043Z 3 [Note] InnoDB: Resuming purge
v-mysql  | 2024-01-28T04:06:37.317607Z 3 [Note] InnoDB: Stopping purge
v-mysql  | 2024-01-28T04:06:37.333861Z 3 [Note] InnoDB: Resuming purge
v-mysql  | 2024-01-28T04:06:37.348331Z 3 [Note] InnoDB: Stopping purge
v-mysql  | 2024-01-28T04:06:37.402247Z 3 [Note] InnoDB: Resuming purge
v-mysql  | 2024-01-28T04:06:37.440636Z 3 [Note] InnoDB: Stopping purge
v-mysql  | 2024-01-28T04:06:37.463372Z 3 [Note] InnoDB: Resuming purge
v-mysql  | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
v-mysql  | Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
app      |
app      |   .   ____          _            __ _ _
app      |  /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
app      | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
app      |  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
app      |   '  |____| .__|_| |_|_| |_\__, | / / / /
app      |  =========|_|==============|___/=/_/_/_/
app      |  :: Spring Boot ::        (v2.0.0.RELEASE)
app      |
app      | 2024-01-28 04:06:42.640  INFO 1 --- [           main] com.neo.ComposeApplication               : Starting ComposeApplication on 5a1fd4d2cc5a with PID 1 (/app/target/classes started by root in /app)
app      | 2024-01-28 04:06:42.664  INFO 1 --- [           main] com.neo.ComposeApplication               : The following profiles are active: docker
v-mysql  | Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
v-mysql  | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
v-mysql  | Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
v-mysql  |
v-mysql  | [Entrypoint] ignoring /docker-entrypoint-initdb.d/*
v-mysql  |
v-mysql  | 2024-01-28T04:06:43.208244Z 0 [Note] Giving 0 client threads a chance to die gracefully
v-mysql  | 2024-01-28T04:06:43.208267Z 0 [Note] Shutting down slave threads
v-mysql  | 2024-01-28T04:06:43.208275Z 0 [Note] Forcefully disconnecting 0 remaining clients
v-mysql  | 2024-01-28T04:06:43.208281Z 0 [Note] Event Scheduler: Purging the queue. 0 events
v-mysql  | 2024-01-28T04:06:43.208699Z 0 [Note] Binlog end
v-mysql  | 2024-01-28T04:06:43.209084Z 0 [Note] Shutting down plugin 'ngram'
v-mysql  | 2024-01-28T04:06:43.209092Z 0 [Note] Shutting down plugin 'partition'
v-mysql  | 2024-01-28T04:06:43.209094Z 0 [Note] Shutting down plugin 'BLACKHOLE'
v-mysql  | 2024-01-28T04:06:43.209097Z 0 [Note] Shutting down plugin 'ARCHIVE'
v-mysql  | 2024-01-28T04:06:43.209099Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
v-mysql  | 2024-01-28T04:06:43.209121Z 0 [Note] Shutting down plugin 'MRG_MYISAM'
v-mysql  | 2024-01-28T04:06:43.209125Z 0 [Note] Shutting down plugin 'MyISAM'
v-mysql  | 2024-01-28T04:06:43.209132Z 0 [Note] Shutting down plugin 'INNODB_SYS_VIRTUAL'
v-mysql  | 2024-01-28T04:06:43.209135Z 0 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
v-mysql  | 2024-01-28T04:06:43.209137Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
v-mysql  | 2024-01-28T04:06:43.209139Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
v-mysql  | 2024-01-28T04:06:43.209141Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
v-mysql  | 2024-01-28T04:06:43.209142Z 0 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
v-mysql  | 2024-01-28T04:06:43.209144Z 0 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
v-mysql  | 2024-01-28T04:06:43.209146Z 0 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
v-mysql  | 2024-01-28T04:06:43.209148Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
v-mysql  | 2024-01-28T04:06:43.209149Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
v-mysql  | 2024-01-28T04:06:43.209151Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
v-mysql  | 2024-01-28T04:06:43.209153Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
v-mysql  | 2024-01-28T04:06:43.209154Z 0 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
v-mysql  | 2024-01-28T04:06:43.209156Z 0 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
v-mysql  | 2024-01-28T04:06:43.209158Z 0 [Note] Shutting down plugin 'INNODB_FT_DELETED'
v-mysql  | 2024-01-28T04:06:43.209160Z 0 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
v-mysql  | 2024-01-28T04:06:43.209161Z 0 [Note] Shutting down plugin 'INNODB_METRICS'
v-mysql  | 2024-01-28T04:06:43.209163Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO'
v-mysql  | 2024-01-28T04:06:43.209165Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
v-mysql  | 2024-01-28T04:06:43.209167Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
v-mysql  | 2024-01-28T04:06:43.209169Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
v-mysql  | 2024-01-28T04:06:43.209170Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
v-mysql  | 2024-01-28T04:06:43.209172Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
v-mysql  | 2024-01-28T04:06:43.209174Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
v-mysql  | 2024-01-28T04:06:43.209176Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM'
v-mysql  | 2024-01-28T04:06:43.209178Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET'
v-mysql  | 2024-01-28T04:06:43.209179Z 0 [Note] Shutting down plugin 'INNODB_CMP'
v-mysql  | 2024-01-28T04:06:43.209181Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
v-mysql  | 2024-01-28T04:06:43.209183Z 0 [Note] Shutting down plugin 'INNODB_LOCKS'
v-mysql  | 2024-01-28T04:06:43.209184Z 0 [Note] Shutting down plugin 'INNODB_TRX'
v-mysql  | 2024-01-28T04:06:43.209186Z 0 [Note] Shutting down plugin 'InnoDB'
v-mysql  | 2024-01-28T04:06:43.209230Z 0 [Note] InnoDB: FTS optimize thread exiting.
v-mysql  | 2024-01-28T04:06:43.209911Z 0 [Note] InnoDB: Starting shutdown...
app      | 2024-01-28 04:06:43.222  INFO 1 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@301dca64: startup date [Sun Jan 28 04:06:43 UTC 2024]; root of context hierarchy
v-mysql  | 2024-01-28T04:06:43.311419Z 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
v-mysql  | 2024-01-28T04:06:43.311649Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 240128  4:06:43
v-mysql  | 2024-01-28T04:06:45.025243Z 0 [Note] InnoDB: Shutdown completed; log sequence number 12184554
v-mysql  | 2024-01-28T04:06:45.029495Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
v-mysql  | 2024-01-28T04:06:45.029524Z 0 [Note] Shutting down plugin 'MEMORY'
v-mysql  | 2024-01-28T04:06:45.029554Z 0 [Note] Shutting down plugin 'CSV'
v-mysql  | 2024-01-28T04:06:45.029560Z 0 [Note] Shutting down plugin 'sha256_password'
v-mysql  | 2024-01-28T04:06:45.029563Z 0 [Note] Shutting down plugin 'mysql_native_password'
v-mysql  | 2024-01-28T04:06:45.029660Z 0 [Note] Shutting down plugin 'binlog'
v-mysql  | 2024-01-28T04:06:45.031085Z 0 [Note] mysqld: Shutdown complete
v-mysql  |
v-mysql  | [Entrypoint] Server shut down
v-mysql  |
v-mysql  | [Entrypoint] MySQL init process done. Ready for start up.
v-mysql  |
v-mysql  | [Entrypoint] Starting MySQL 5.7.41-1.2.11-server
v-mysql  | 2024-01-28T04:06:45.507704Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
v-mysql  | 2024-01-28T04:06:45.509088Z 0 [Note] mysqld (mysqld 5.7.41) starting as process 1 ...
v-mysql  | 2024-01-28T04:06:45.516922Z 0 [Note] InnoDB: PUNCH HOLE support available
v-mysql  | 2024-01-28T04:06:45.516954Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
v-mysql  | 2024-01-28T04:06:45.516958Z 0 [Note] InnoDB: Uses event mutexes
v-mysql  | 2024-01-28T04:06:45.516961Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
v-mysql  | 2024-01-28T04:06:45.516964Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.12
v-mysql  | 2024-01-28T04:06:45.516968Z 0 [Note] InnoDB: Using Linux native AIO
v-mysql  | 2024-01-28T04:06:45.517232Z 0 [Note] InnoDB: Number of pools: 1
v-mysql  | 2024-01-28T04:06:45.517330Z 0 [Note] InnoDB: Using CPU crc32 instructions
v-mysql  | 2024-01-28T04:06:45.518750Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
v-mysql  | 2024-01-28T04:06:45.536989Z 0 [Note] InnoDB: Completed initialization of buffer pool
v-mysql  | 2024-01-28T04:06:45.538826Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
v-mysql  | 2024-01-28T04:06:45.550984Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
v-mysql  | 2024-01-28T04:06:45.600284Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
v-mysql  | 2024-01-28T04:06:45.600371Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
v-mysql  | 2024-01-28T04:06:45.624539Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
v-mysql  | 2024-01-28T04:06:45.625242Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
v-mysql  | 2024-01-28T04:06:45.625253Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
v-mysql  | 2024-01-28T04:06:45.625514Z 0 [Note] InnoDB: Waiting for purge to start
v-mysql  | 2024-01-28T04:06:45.677312Z 0 [Note] InnoDB: 5.7.41 started; log sequence number 12184554
v-mysql  | 2024-01-28T04:06:45.677578Z 0 [Note] Plugin 'FEDERATED' is disabled.
v-mysql  | 2024-01-28T04:06:45.682869Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
v-mysql  | 2024-01-28T04:06:45.682882Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
v-mysql  | 2024-01-28T04:06:45.682886Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
v-mysql  | 2024-01-28T04:06:45.682888Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
v-mysql  | 2024-01-28T04:06:45.686229Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
v-mysql  | 2024-01-28T04:06:45.700961Z 0 [Warning] CA certificate ca.pem is self signed.
v-mysql  | 2024-01-28T04:06:45.701031Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
v-mysql  | 2024-01-28T04:06:45.701413Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
v-mysql  | 2024-01-28T04:06:45.701481Z 0 [Note] IPv6 is available.
v-mysql  | 2024-01-28T04:06:45.701506Z 0 [Note]   - '::' resolves to '::';
v-mysql  | 2024-01-28T04:06:45.701526Z 0 [Note] Server socket created on IP: '::'.
v-mysql  | 2024-01-28T04:06:45.703079Z 0 [Note] InnoDB: Buffer pool(s) load completed at 240128  4:06:45
v-mysql  | 2024-01-28T04:06:45.750076Z 0 [Note] Event Scheduler: Loaded 0 events
v-mysql  | 2024-01-28T04:06:45.750210Z 0 [Note] mysqld: ready for connections.
v-mysql  | Version: '5.7.41'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server (GPL)
app      | 2024-01-28 04:06:45.863  INFO 1 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$ddc5732] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
app      | 2024-01-28 04:06:46.407  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8090 (http)
app      | 2024-01-28 04:06:46.493  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
app      | 2024-01-28 04:06:46.494  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.28
app      | 2024-01-28 04:06:46.511  INFO 1 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib]
app      | 2024-01-28 04:06:46.758  INFO 1 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
app      | 2024-01-28 04:06:46.759  INFO 1 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3563 ms
app      | 2024-01-28 04:06:47.011  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
app      | 2024-01-28 04:06:47.014  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
app      | 2024-01-28 04:06:47.025  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
app      | 2024-01-28 04:06:47.025  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
app      | 2024-01-28 04:06:47.025  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
app      | 2024-01-28 04:06:47.411  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
app      | Sun Jan 28 04:06:47 UTC 2024 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
v-mysql  | 2024-01-28T04:06:48.144546Z 2 [Warning] Accepted a connection with deprecated protocol 'TLSv1.1' for account `root`@`%` from host `172.18.0.4`. Client supplied username `root`
app      | 2024-01-28 04:06:48.229  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
app      | Sun Jan 28 04:06:48 UTC 2024 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
app      | 2024-01-28 04:06:48.390  INFO 1 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
v-mysql  | 2024-01-28T04:06:48.429374Z 3 [Warning] Accepted a connection with deprecated protocol 'TLSv1.1' for account `root`@`%` from host `172.18.0.4`. Client supplied username `root`
app      | 2024-01-28 04:06:48.450  INFO 1 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
app      |      name: default
app      |      ...]
app      | Sun Jan 28 04:06:48 UTC 2024 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
v-mysql  | 2024-01-28T04:06:48.516220Z 4 [Warning] Accepted a connection with deprecated protocol 'TLSv1.1' for account `root`@`%` from host `172.18.0.4`. Client supplied username `root`
app      | Sun Jan 28 04:06:48 UTC 2024 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
v-mysql  | 2024-01-28T04:06:48.579164Z 5 [Warning] Accepted a connection with deprecated protocol 'TLSv1.1' for account `root`@`%` from host `172.18.0.4`. Client supplied username `root`
app      | Sun Jan 28 04:06:48 UTC 2024 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
v-mysql  | 2024-01-28T04:06:48.630329Z 6 [Warning] Accepted a connection with deprecated protocol 'TLSv1.1' for account `root`@`%` from host `172.18.0.4`. Client supplied username `root`
app      | Sun Jan 28 04:06:48 UTC 2024 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
app      | 2024-01-28 04:06:48.686  INFO 1 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.2.14.Final}
app      | 2024-01-28 04:06:48.687  INFO 1 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
v-mysql  | 2024-01-28T04:06:48.696303Z 7 [Warning] Accepted a connection with deprecated protocol 'TLSv1.1' for account `root`@`%` from host `172.18.0.4`. Client supplied username `root`
app      | Sun Jan 28 04:06:48 UTC 2024 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
v-mysql  | 2024-01-28T04:06:48.760458Z 8 [Warning] Accepted a connection with deprecated protocol 'TLSv1.1' for account `root`@`%` from host `172.18.0.4`. Client supplied username `root`
app      | 2024-01-28 04:06:48.797  INFO 1 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
app      | Sun Jan 28 04:06:48 UTC 2024 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
v-mysql  | 2024-01-28T04:06:48.845433Z 9 [Warning] Accepted a connection with deprecated protocol 'TLSv1.1' for account `root`@`%` from host `172.18.0.4`. Client supplied username `root`
app      | Sun Jan 28 04:06:49 UTC 2024 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
v-mysql  | 2024-01-28T04:06:49.049553Z 10 [Warning] Accepted a connection with deprecated protocol 'TLSv1.1' for account `root`@`%` from host `172.18.0.4`. Client supplied username `root`
app      | Sun Jan 28 04:06:49 UTC 2024 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
v-mysql  | 2024-01-28T04:06:49.106481Z 11 [Warning] Accepted a connection with deprecated protocol 'TLSv1.1' for account `root`@`%` from host `172.18.0.4`. Client supplied username `root`
app      | 2024-01-28 04:06:49.236  INFO 1 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
app      | Hibernate: create table hibernate_sequence (next_val bigint) engine=InnoDB
app      | Hibernate: insert into hibernate_sequence values ( 1 )
app      | Hibernate: create table visitor (id bigint not null, ip varchar(255) not null, times bigint not null, primary key (id)) engine=InnoDB
app      | 2024-01-28 04:06:50.312  INFO 1 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
app      | 2024-01-28 04:06:52.119  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@301dca64: startup date [Sun Jan 28 04:06:43 UTC 2024]; root of context hierarchy
app      | 2024-01-28 04:06:52.213  WARN 1 --- [           main] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
app      | 2024-01-28 04:06:52.283  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/]}" onto public java.lang.String com.neo.controller.VisitorController.index(javax.servlet.http.HttpServletRequest)
app      | 2024-01-28 04:06:52.294  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
app      | 2024-01-28 04:06:52.294  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
app      | 2024-01-28 04:06:52.358  INFO 1 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
app      | 2024-01-28 04:06:52.364  INFO 1 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
app      | 2024-01-28 04:06:52.431  INFO 1 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
app      | 2024-01-28 04:06:52.826  INFO 1 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
app      | 2024-01-28 04:06:52.827  INFO 1 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'dataSource' has been autodetected for JMX exposure
app      | 2024-01-28 04:06:52.849  INFO 1 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
app      | 2024-01-28 04:06:53.015  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8090 (http) with context path ''
app      | 2024-01-28 04:06:53.030  INFO 1 --- [           main] com.neo.ComposeApplication               : Started ComposeApplication in 13.495 seconds (JVM running for 23.292)
app      | 2024-01-28 04:07:05.300  INFO 1 --- [nio-8090-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
app      | 2024-01-28 04:07:05.301  INFO 1 --- [nio-8090-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
app      | 2024-01-28 04:07:05.329  INFO 1 --- [nio-8090-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 28 ms
app      | 2024-01-28 04:07:05.435  INFO 1 --- [nio-8090-exec-1] o.h.h.i.QueryTranslatorFactoryInitiator  : HHH000397: Using ASTQueryTranslatorFactory
app      | Hibernate: select visitor0_.id as id1_0_, visitor0_.ip as ip2_0_, visitor0_.times as times3_0_ from visitor visitor0_ where visitor0_.ip=?
app      | Hibernate: select next_val as id_val from hibernate_sequence for update
app      | Hibernate: update hibernate_sequence set next_val= ? where next_val=?
app      | Hibernate: insert into visitor (ip, times, id) values (?, ?, ?)

看到信息Tomcat initialized with port(s): 8090 (http)表示服务启动成功。

也可以使用docker-compose up -d后台启动:

[root@zsx dockercompose-springboot-mysql-nginx]# docker-compose up -d
[+] Running 3/3
 ⠿ Container v-nginx  Started                                                                                                  0.8s
 ⠿ Container v-mysql  Started                                                                                                  0.7s
 ⠿ Container app      Started                                                                                                  1.6s

访问服务器地址:http://192.168.136.195/,返回:I have been seen ip 172.19.0.2 1 times.

表示整体服务启动成功。

使用docker-compose ps查看项目中目前的所有容器:

[root@zsx dockercompose-springboot-mysql-nginx]# docker ps
CONTAINER ID   IMAGE                                      COMMAND                  CREATED         STATUS                             PORTS                                                                      NAMES
5a1fd4d2cc5a   dockercompose-springboot-mysql-nginx-app   "/usr/local/bin/mvn-…"   3 minutes ago   Up 24 seconds                      8090/tcp                                                                   app
576607ed0dda   mysql/mysql-server:5.7                     "/entrypoint.sh mysq…"   3 minutes ago   Up 25 seconds (health: starting)   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp                       v-mysql
11ae3ff42704   nginx:1.13                                 "nginx -g 'daemon of…"   3 minutes ago   Up 25 seconds                      0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp   v-nginx

可以看到项目中服务的状态、命令、端口等信息。

关闭服务docker-compose down

[root@zsx dockercompose-springboot-mysql-nginx]# docker-compose down
[+] Running 4/4
 ⠿ Container app                                         Removed                                                                                                                                                 0.3s
 ⠿ Container v-mysql                                     Removed                                                                                                                                                 3.9s
 ⠿ Container v-nginx                                     Removed                                                                                                                                                 0.2s
 ⠿ Network dockercompose-springboot-mysql-nginx_default  Removed            

2.5 docker-compose 顺序

在使用 docker-compose 启动的时候经常会出现项目报 Mysql 连接异常,跟踪了一天终于发现了问题。 docker-

compose 虽然可以通过depends_on 来定义服务启动的顺序,但是无法确定服务是否启动完成,因此会出现这

样一个现象,Mysql 服务启动比较慢,当 Spring Boot 项目已经启动起来,但是 Mysql 还没有初始化好,这样当

项目连接 Mysql 数据库的时候,就会出现连接数据库的异常。

针对这样的问题,有两种解决方案:

1、足够的容错和重试机制,比如连接数据库,在初次连接不上的时候,服务消费者可以不断重试,直到连接上服

务。也就是在服务中定义: restart: always

2、同步等待,使用wait-for-it.sh或者其他shell脚本将当前服务启动阻塞,直到被依赖的服务加载完毕。这

种方案后期可以尝试使用。

3、总结

没有对比就没有伤害,在没有使用 Docker 之前,我们需要搭建这样一个环境的话,需要安装 Nginx、Mysql ,再

进行一系列的配置调试,还要担心各种环境问题;使用 Docker 之后简单两个命令就完成服务的上线、下线。

# 初始化并启动容器
$ docker-compose up
# 停止容器并且删除容器
$ docker-compose down
# 停止容器
$ docker-compose stop
# 启动容器
$ docker-compose start

其实容器技术对部署运维的优化还有很多,这只是刚刚开始,后面使用了 Swarm 才会真正感受到它的便利和强

大。

你可能感兴趣的:(spring,boot,spring,boot)