[zh]Update content/zh/examples/application/mysql/mysql-statefulset.yaml

[zh]Update content/zh/examples/application/mysql/mysql-statefulset.yaml

Update content/zh/examples/application/mysql/mysql-statefulset.yaml

Co-authored-by: Qiming Teng <tengqm@outlook.com>

Update content/zh/examples/application/mysql/mysql-statefulset.yaml

Co-authored-by: Qiming Teng <tengqm@outlook.com>

Update content/zh/examples/application/mysql/mysql-statefulset.yaml

Co-authored-by: Qiming Teng <tengqm@outlook.com>

Update content/zh/examples/application/mysql/mysql-statefulset.yaml

Co-authored-by: Qiming Teng <tengqm@outlook.com>

Update content/zh/examples/application/mysql/mysql-statefulset.yaml

Co-authored-by: Qiming Teng <tengqm@outlook.com>

Update content/zh/examples/application/mysql/mysql-statefulset.yaml

Co-authored-by: Qiming Teng <tengqm@outlook.com>

Update content/zh/examples/application/mysql/mysql-statefulset.yaml

Co-authored-by: Qiming Teng <tengqm@outlook.com>

Update content/zh/examples/application/mysql/mysql-statefulset.yaml

Co-authored-by: Qiming Teng <tengqm@outlook.com>

Update content/zh/examples/application/mysql/mysql-statefulset.yaml

Co-authored-by: Qiming Teng <tengqm@outlook.com>

Update content/zh/examples/application/mysql/mysql-statefulset.yaml

Co-authored-by: Qiming Teng <tengqm@outlook.com>

Update content/zh/examples/application/mysql/mysql-statefulset.yaml

Co-authored-by: Qiming Teng <tengqm@outlook.com>
This commit is contained in:
wei.wang
2022-04-27 06:10:35 +08:00
parent 6b15373d61
commit c88343d6b5
@@ -21,17 +21,18 @@ spec:
- "-c"
- |
set -ex
# Generate mysql server-id from pod ordinal index.
# 基于 Pod 序号生成 MySQL 服务器的 ID。
[[ `hostname` =~ -([0-9]+)$ ]] || exit 1
ordinal=${BASH_REMATCH[1]}
echo [mysqld] > /mnt/conf.d/server-id.cnf
# Add an offset to avoid reserved server-id=0 value.
# 添加偏移量以避免使用 server-id=0 这一保留值。
echo server-id=$((100 + $ordinal)) >> /mnt/conf.d/server-id.cnf
# Copy appropriate conf.d files from config-map to emptyDir.
# 将合适的 conf.d 文件从 config-map 复制到 emptyDir。
if [[ $ordinal -eq 0 ]]; then
cp /mnt/config-map/master.cnf /mnt/conf.d/
cp /mnt/config-map/primary.cnf /mnt/conf.d/
else
cp /mnt/config-map/slave.cnf /mnt/conf.d/
cp /mnt/config-map/replica.cnf /mnt/conf.d/
fi
volumeMounts:
- name: conf
@@ -45,15 +46,15 @@ spec:
- "-c"
- |
set -ex
# Skip the clone if data already exists.
# 如果已有数据,则跳过克隆。
[[ -d /var/lib/mysql/mysql ]] && exit 0
# Skip the clone on master (ordinal index 0).
# 跳过主实例(序号索引 0)的克隆。
[[ `hostname` =~ -([0-9]+)$ ]] || exit 1
ordinal=${BASH_REMATCH[1]}
[[ $ordinal -eq 0 ]] && exit 0
# Clone data from previous peer.
# 从原来的对等节点克隆数据。
ncat --recv-only mysql-$(($ordinal-1)).mysql 3307 | xbstream -x -C /var/lib/mysql
# Prepare the backup.
# 准备备份。
xtrabackup --prepare --target-dir=/var/lib/mysql
volumeMounts:
- name: data
@@ -88,7 +89,7 @@ spec:
timeoutSeconds: 5
readinessProbe:
exec:
# Check we can execute queries over TCP (skip-networking is off).
# 检查我们是否可以通过 TCP 执行查询(skip-networking 是关闭的)。
command: ["mysql", "-h", "127.0.0.1", "-e", "SELECT 1"]
initialDelaySeconds: 5
periodSeconds: 2
@@ -105,22 +106,22 @@ spec:
set -ex
cd /var/lib/mysql
# Determine binlog position of cloned data, if any.
# 确定克隆数据的 binlog 位置(如果有的话)。
if [[ -f xtrabackup_slave_info && "x$(<xtrabackup_slave_info)" != "x" ]]; then
# XtraBackup already generated a partial "CHANGE MASTER TO" query
# because we're cloning from an existing slave. (Need to remove the tailing semicolon!)
# XtraBackup 已经生成了部分的 “CHANGE MASTER TO” 查询
# 因为我们从一个现有副本进行克隆。(需要删除末尾的分号!)
cat xtrabackup_slave_info | sed -E 's/;$//g' > change_master_to.sql.in
# Ignore xtrabackup_binlog_info in this case (it's useless).
# 在这里要忽略 xtrabackup_binlog_info (它是没用的)。
rm -f xtrabackup_slave_info xtrabackup_binlog_info
elif [[ -f xtrabackup_binlog_info ]]; then
# We're cloning directly from master. Parse binlog position.
# 我们直接从主实例进行克隆。解析 binlog 位置。
[[ `cat xtrabackup_binlog_info` =~ ^(.*?)[[:space:]]+(.*?)$ ]] || exit 1
rm -f xtrabackup_binlog_info xtrabackup_slave_info
echo "CHANGE MASTER TO MASTER_LOG_FILE='${BASH_REMATCH[1]}',\
MASTER_LOG_POS=${BASH_REMATCH[2]}" > change_master_to.sql.in
fi
# Check if we need to complete a clone by starting replication.
# 检查我们是否需要通过启动复制来完成克隆。
if [[ -f change_master_to.sql.in ]]; then
echo "Waiting for mysqld to be ready (accepting connections)"
until mysql -h 127.0.0.1 -e "SELECT 1"; do sleep 1; done
@@ -133,11 +134,11 @@ spec:
MASTER_PASSWORD='', \
MASTER_CONNECT_RETRY=10; \
START SLAVE;" || exit 1
# In case of container restart, attempt this at-most-once.
# 如果容器重新启动,最多尝试一次。
mv change_master_to.sql.in change_master_to.sql.orig
fi
# Start a server to send backups when requested by peers.
# 当对等点请求时,启动服务器发送备份。
exec ncat --listen --keep-open --send-only --max-conns=1 3307 -c \
"xtrabackup --backup --slave-info --stream=xbstream --host=127.0.0.1 --user=root"
volumeMounts: