6.3 查看日志

有助于调试和查找相关日志信息的信息。

日志位置包括每个 InnoDBCluster Pod,它们被分成一组容器。有两个操作容器(mysql、 和sidecar)和三个初始化容器(initconfinitmysqlfixdatadir),如下所述:

表 6.1 与 InnoDBCluster Pod 关联的容器

容器名称 描述
sidecar

初始化,包括数据的初始设置 (initDB) 和特定实例的持续维护任务,例如 TLS 认证更新

mysql

MySQL 服务器本身

initconf

它为特定主机准备 MySQL 配置文件。例如查看其ConfigMap: kubectl get cm {cluster_name}-initconf -o json

initmysql

初始化 MySQL 服务器,包括它的数据目录。

fixdatadir

在初始化时设置 MySQL 数据目录的适当权限和所有权。


还有用于 Kubernetes 和 MySQL Router pod 的动态 MySQL Operator。

假定基本设置的示例 samples/sample-cluster.yaml如下所示:

$> kubectl get pods

NAME                                READY   STATUS    RESTARTS   AGE
mycluster-0                         2/2     Running   0          99m
mycluster-1                         2/2     Running   0          99m
mycluster-2                         2/2     Running   0          99m
mycluster-router-6d49485474-ftw9r   1/1     Running   0          97m

$> kubectl get pods --namespace mysql-operator

NAME                              READY   STATUS    RESTARTS   AGE
mysql-operator-586f9f5d5b-7wtgl   1/1     Running   0          3h48m

查看运行 Pod 日志以调试活动操作:

$> kubectl logs mycluster-0 -c sidecar
...
[2022-04-21 19:15:08,571] sidecar              [INFO    ] My pod is mycluster-0 in default
[2022-04-21 19:15:08,571] sidecar              [INFO    ] Bootstrapping
[2022-04-21 19:15:10,600] sidecar              [INFO    ] Configuring mysql pod default/mycluster-0, configured=None datadir=/var/lib/mysql
[2022-04-21 19:15:10,626] sidecar              [INFO    ] Creating root account root@%
[2022-04-21 19:15:10,670] sidecar              [INFO    ] Creating account mysqladmin@%
[2022-04-21 19:15:10,694] sidecar              [INFO    ] Admin account created
...
$> kubectl logs mycluster-0 -c mysql

[Entrypoint] MySQL Docker Image 8.0.29-1.2.8-server
2022-04-21T19:15:05.969998Z 0 [Note] [MY-010747] [Server] Plugin 'FEDERATED' is disabled.
2022-04-21T19:15:05.971625Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'MyISAM'
2022-04-21T19:15:05.971700Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'CSV'
[Entrypoint] Starting MySQL 8.0.29-1.2.8-server
2022-04-21T19:15:07.085923Z 0 [Note] [MY-010949] [Server] Basedir set to /usr/.
2022-04-21T19:15:07.085959Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.29) starting as process 1
2022-04-21T19:15:07.094129Z 0 [Note] [MY-012366] [InnoDB] Using Linux native AIO
2022-04-21T19:15:07.094464Z 0 [Note] [MY-010747] [Server] Plugin 'FEDERATED' is disabled.
2022-04-21T19:15:07.155815Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
...
$> kubectl logs mycluster-router-6d49485474-ftw9r
...
# Bootstrapping MySQL Router instance at '/tmp/mysqlrouter'...
...
## MySQL Classic protocol
- Read/Write Connections: localhost:6446
- Read/Only Connections:  localhost:6447
...
$> kubectl logs mysql-operator-586f9f5d5b-7wtgl -n mysql-operator
...
2022-04-21 17:06:13: Info: Credential store mechanism is going to be disabled.
2022-04-21 17:06:13: Info: Loading startup files...
2022-04-21 17:06:13: Info: Loading plugins...
[2022-04-21 17:06:14,758] kopf.activities.star [INFO    ] MySQL Operator/operator.py=2.0.4 timestamp=2022-04-21T14:43:15 kopf=1.31.0 uid=2
[2022-04-21 17:06:14,758] kopf.activities.star [INFO    ] OPERATOR_VERSION   =2.0.4
[2022-04-21 17:06:14,758] kopf.activities.star [INFO    ] OPERATOR_EDITION   =community
[2022-04-21 17:06:14,758] kopf.activities.star [INFO    ] OPERATOR_EDITIONS  =['community', 'enterprise']
[2022-04-21 17:06:14,758] kopf.activities.star [INFO    ] SHELL_VERSION      =8.0.29
[2022-04-21 17:06:14,758] kopf.activities.star [INFO    ] DEFAULT_VERSION_TAG=8.0.29
[2022-04-21 17:06:14,758] kopf.activities.star [INFO    ] SIDECAR_VERSION_TAG=8.0.29-2.0.4
...
Incremental state recovery is now in progress.

* Waiting for distributed recovery to finish...
...
[2022-04-21 19:15:54,926] kopf.objects         [INFO    ] cluster probe: status=ClusterDiagStatus.ONLINE 
                                                          online=[<MySQLPod mycluster-0>, <MySQLPod mycluster-1>, <MySQLPod mycluster-2>]
[2022-04-21 19:15:54,930] kopf.objects         [INFO    ] Handler 'on_pod_event' succeeded.
...

查看特定于 InnoDBCluster 初始化的 Pod:

$> kubectl logs mycluster-0 -c initmysql
...
[Entrypoint] Initializing database
2022-04-21T19:14:40.315937Z 0 [Note] [MY-010949] [Server] Basedir set to /usr/.
2022-04-21T19:14:40.315977Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.29) initializing of server in progress as process 19
2022-04-21T19:14:40.317974Z 0 [Note] [MY-010458] [Server] --initialize specified on an existing data directory.
2022-04-21T19:14:40.323039Z 0 [Note] [MY-010938] [Server] Generating a new UUID: 4af9d5b7-c1a7-11ec-9663-0242ac110007.
2022-04-21T19:14:40.329396Z 0 [Note] [MY-012366] [InnoDB] Using Linux native AIO
2022-04-21T19:14:40.330470Z 0 [Note] [MY-010747] [Server] Plugin 'FEDERATED' is disabled.
2022-04-21T19:14:40.398051Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
...
2022-04-21T19:14:42.103049Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-04-21T19:14:42.201557Z 1 [Note] [MY-011088] [Server] Data dictionary initializing version '80023'.
2022-04-21T19:14:43.367575Z 1 [Note] [MY-010007] [Server] Installed data dictionary with version 80023
2022-04-21T19:14:43.678363Z 2 [Note] [MY-011019] [Server] Created system views with I_S version 80023.
...
[Entrypoint] running /docker-entrypoint-initdb.d/initdb-localroot.sql
...
2022-04-21T19:15:01.834127Z 12 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.29).
...
2022-04-21T19:15:03.832074Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.29)
[Entrypoint] Server shut down
[Entrypoint] MySQL init process done. Ready for start up.
[Entrypoint] MYSQL_INITIALIZE_ONLY is set, exiting without starting MySQL...
$> kubectl logs mycluster-0 -c initconf

2022-04-21 19:14:35: Info: Credential store mechanism is going to be disabled.
2022-04-21 19:14:35: Info: Loading startup files...
2022-04-21 19:14:35: Info: Loading plugins...
2022-04-21T19:14:37 - [INFO] [initmysql] MySQL Operator/init_main.py=2.0.4 timestamp=2022-04-21T14:43:15 kopf=1.31.0 uid=27
2022-04-21T19:14:37 - [INFO] [initmysql] Configuring mysql pod default/mycluster-0, datadir=/var/lib/mysql
total 0
/mnt:
total 8
drwxrwsrwx 3 root mysql 4096 Apr 21 19:14 initconf
drwxrwsrwx 2 root mysql 4096 Apr 21 19:14 mycnfdata

/mnt/initconf:
total 0
lrwxrwxrwx 1 root mysql 19 Apr 21 19:14 00-basic.cnf -> ..data/00-basic.cnf
lrwxrwxrwx 1 root mysql 31 Apr 21 19:14 01-group_replication.cnf -> ..data/01-group_replication.cnf
lrwxrwxrwx 1 root mysql 17 Apr 21 19:14 02-ssl.cnf -> ..data/02-ssl.cnf
lrwxrwxrwx 1 root mysql 19 Apr 21 19:14 99-extra.cnf -> ..data/99-extra.cnf
lrwxrwxrwx 1 root mysql 27 Apr 21 19:14 initdb-localroot.sql -> ..data/initdb-localroot.sql
lrwxrwxrwx 1 root mysql 23 Apr 21 19:14 livenessprobe.sh -> ..data/livenessprobe.sh
lrwxrwxrwx 1 root mysql 16 Apr 21 19:14 my.cnf.in -> ..data/my.cnf.in
lrwxrwxrwx 1 root mysql 24 Apr 21 19:14 readinessprobe.sh -> ..data/readinessprobe.sh

/mnt/mycnfdata:
total 0
2022-04-21T19:14:38 - [INFO] [initmysql] Setting up configurations for mycluster-0 server_id=1000 
                                         report_host=mycluster-0.mycluster-instances.default.svc.cluster.local
2022-04-21T19:14:38 - [INFO] [initmysql] Configuration done

对于initconf,您可能会查看他们的 ConfigMap,例如:

$> kubectl get configmap mycluster-initconf -o yaml

这里复制的是 [data] 对象:

data:
  00-basic.cnf: |
    # Basic configuration.
    # Do not edit.
    [mysqld]
    plugin_load_add=auth_socket.so
    loose_auth_socket=FORCE_PLUS_PERMANENT
    skip_log_error
    log_error_verbosity=3
  01-group_replication.cnf: |
    # GR and replication related options
    # Do not edit.
    [mysqld]
    log_bin=mycluster
    enforce_gtid_consistency=ON
    gtid_mode=ON
    relay_log_info_repository=TABLE
    skip_slave_start=1
  02-ssl.cnf: |
    # SSL configurations
    # Do not edit.
    [mysqld]
    # ssl-ca=/etc/mysql-ssl/ca.pem
    # ssl-crl=/etc/mysql-ssl/crl.pem
    # ssl-cert=/etc/mysql-ssl/tls.crt
    # ssl-key=/etc/mysql-ssl/tls.key

    loose_group_replication_recovery_use_ssl=1
    # loose_group_replication_recovery_ssl_verify_server_cert=1

    # loose_group_replication_recovery_ssl_ca=/etc/mysql-ssl/ca.pem
    ## loose_group_replication_recovery_ssl_crl=/etc/mysql-ssl/crl.pem
    # loose_group_replication_recovery_ssl_cert=/etc/mysql-ssl/tls.crt
    # loose_group_replication_recovery_ssl_key=/etc/mysql-ssl/tls.key
  99-extra.cnf: |
    # Additional user configurations taken from spec.mycnf in InnoDBCluster.
    # Do not edit directly.
    [mysqld]
    innodb_buffer_pool_size=200M
    innodb_log_file_size=2G
  my.cnf.in: |
    # Server identity related options (not shared across instances).
    # Do not edit.
    [mysqld]
    server_id=@@SERVER_ID@@
    report_host=@@HOSTNAME@@
    datadir=/var/lib/mysql
    loose_mysqlx_socket=/var/run/mysqld/mysqlx.sock
    socket=/var/run/mysqld/mysql.sock
    local-infile=1

    [mysql]
    socket=/var/run/mysqld/mysql.sock

    [mysqladmin]
    socket=/var/run/mysqld/mysql.sock

    !includedir /etc/my.cnf.d