【问题标题】:docker stack mysql service start then stop againdocker stack mysql 服务启动然后再次停止
【发布时间】:2021-12-03 05:32:14
【问题描述】:

我的 mysql 服务有问题,它在我部署堆栈时启动然后停止。我不太确定出了什么问题。日志上没有错误。它在 docker-compose 上运行良好我不确定为什么在我部署它时它会一直关闭。从错误日志中我在第 191 行得到这个:47 Killed "$@" --initialize-insecure --default-time-zone=SYSTEM 这可能是问题的根源吗?我用的是这个版本的mysqlmysql official image

services:
  db: 
    image: mysql
    #container_name: mysql_db
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    secrets:
      - mysql_root_password
      - mysql_database
      - mysql_user
      - mysql_password
    environment:
      MYSQL_ROOT_PASSWORD_FILE: /run/secrets/mysql_root_password
      MYSQL_DATABASE_FILE: /run/secrets/mysql_database
      MYSQL_USER_FILE: /run/secrets/mysql_user
      MYSQL_PASSWORD_FILE: /run/secrets/mysql_password
    ports:
      - "9906:3306"
 
    networks:
      - back-tier

    volumes:
      - alpine-db_backup:/var/lib/mysql
      - alpine-mysql_logs:/var/log/mysql
      - alpine-mysql_cnf:/etc/mysql
    deploy:
      replicas: 3
      restart_policy:
        condition: on-failure
        delay: 30s
        max_attempts: 10
        window: 60s
      update_config:
        parallelism: 1
        delay: 10s
        max_failure_ratio: 0.3
      resources:
        limits:
          cpus: '0.50'
          memory: 90M
        reservations:
          cpus: '0.25'
          memory: 50M
       

networks:
    front-tier:
      driver: overlay
    back-tier:
      driver: overlay

错误日志

client_db.1.vvhd3rxc245e@worker-1    | 2021-12-02 04:45:01+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
client_db.1.vvhd3rxc245e@worker-1    | 2021-12-02 04:45:01+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
client_db.1.vvhd3rxc245e@worker-1    | 2021-12-02 04:45:01+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
client_db.2.88e3qb36ensi@worker-1    | 2021-12-02 04:44:50+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
client_db.2.88e3qb36ensi@worker-1    | 2021-12-02 04:44:50+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
client_db.2.88e3qb36ensi@worker-1    | 2021-12-02 04:44:50+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
client_db.1.x4976pxrrumi@worker-2    | 2021-12-02 04:43:57+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
client_db.1.x4976pxrrumi@worker-2    | 2021-12-02 04:43:57+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
client_db.1.x4976pxrrumi@worker-2    | 2021-12-02 04:43:57+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
client_db.3.my3k6agifuun@worker-2    | 2021-12-02 04:44:07+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
client_db.3.my3k6agifuun@worker-2    | 2021-12-02 04:44:07+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
client_db.3.my3k6agifuun@worker-2    | 2021-12-02 04:44:07+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
client_db.3.yu9cgxx0jn1b@worker-2    | 2021-12-02 04:43:35+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
client_db.3.yu9cgxx0jn1b@worker-2    | 2021-12-02 04:43:36+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
client_db.3.yu9cgxx0jn1b@worker-2    | 2021-12-02 04:43:36+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
client_db.2.y2pd68ny9yn5@worker-2    | 2021-12-02 04:44:18+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
client_db.2.y2pd68ny9yn5@worker-2    | 2021-12-02 04:44:18+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
client_db.2.y2pd68ny9yn5@worker-2    | 2021-12-02 04:44:18+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
client_db.2.tx9luw14iylo@worker-2    | 2021-12-02 04:33:40+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
client_db.2.tx9luw14iylo@worker-2    | 2021-12-02 04:33:40+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
client_db.2.tx9luw14iylo@worker-2    | 2021-12-02 04:33:40+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
client_db.2.tx9luw14iylo@worker-2    | 2021-12-02 04:33:40+00:00 [Note] [Entrypoint]: Initializing database files
client_db.2.tx9luw14iylo@worker-2    | 2021-12-02T04:33:40.858385Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
client_db.2.tx9luw14iylo@worker-2    | 2021-12-02T04:33:40.858893Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.27) initializing of server in progress as process 45
client_db.2.tx9luw14iylo@worker-2    | 2021-12-02T04:33:40.870822Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
client_db.2.tx9luw14iylo@worker-2    | 2021-12-02T04:33:44.274928Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
client_db.2.tx9luw14iylo@worker-2    | /usr/local/bin/docker-entrypoint.sh: line 191:    45 Killed                  "$@" --initialize-insecure --default-time-zone=SYSTEM

【问题讨论】:

    标签: docker docker-swarm


    【解决方案1】:

    事实证明,我没有使 mysql 服务在我的堆栈应用程序中持久化,这导致 mysql 容器在我部署堆栈时不断关闭。因此,我通过将约束设置为在管理器节点上运行来使 mysql 服务持久化,因为我已经在管理器节点上创建了卷,然后将节点映射到容器,以便容器可以拥有持久数据。这样就解决了问题。

    db: 
        image: mysql
        #container_name: mysql_db
        command: --default-authentication-plugin=mysql_native_password
        restart: always
        secrets:
          - mysql_root_password
          - mysql_database
          - mysql_user
          - mysql_password
        environment:
          MYSQL_ROOT_PASSWORD_FILE: /run/secrets/mysql_root_password
          MYSQL_DATABASE_FILE: /run/secrets/mysql_database
          MYSQL_USER_FILE: /run/secrets/mysql_user
          MYSQL_PASSWORD_FILE: /run/secrets/mysql_password
        ports:
          - "9906:3306"
     
        networks:
          - back-tier
    
        volumes:
          - alpine-db_backup:/var/lib/mysql
          - alpine-mysql_logs:/var/log/mysql
          - alpine-mysql_cnf:/etc/mysql
        deploy:
          replicas: 3
          placement:
            constraints: [node.role == manager]
          resources:
            reservations:
              memory: 128M
            limits:
              memory: 256M
          restart_policy:
            condition: on-failure
            delay: 30s
            max_attempts: 10
            window: 60s
          update_config:
            parallelism: 1
            delay: 10s
            max_failure_ratio: 0.3
          

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-24
      • 1970-01-01
      相关资源
      最近更新 更多