Skip to content

Commit df07454

Browse files
authored
Merge pull request #33233 from kinzhi/kinzhi38
[zh]Update content/zh/examples/application/mysql/mysql-statefulset.yaml
2 parents 3ae803b + c88343d commit df07454

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,18 @@ spec:
2121
- "-c"
2222
- |
2323
set -ex
24-
# Generate mysql server-id from pod ordinal index.
24+
# 基于 Pod 序号生成 MySQL 服务器的 ID。
2525
[[ `hostname` =~ -([0-9]+)$ ]] || exit 1
2626
ordinal=${BASH_REMATCH[1]}
2727
echo [mysqld] > /mnt/conf.d/server-id.cnf
28-
# Add an offset to avoid reserved server-id=0 value.
28+
# 添加偏移量以避免使用 server-id=0 这一保留值。
2929
echo server-id=$((100 + $ordinal)) >> /mnt/conf.d/server-id.cnf
3030
# Copy appropriate conf.d files from config-map to emptyDir.
31+
# 将合适的 conf.d 文件从 config-map 复制到 emptyDir。
3132
if [[ $ordinal -eq 0 ]]; then
32-
cp /mnt/config-map/master.cnf /mnt/conf.d/
33+
cp /mnt/config-map/primary.cnf /mnt/conf.d/
3334
else
34-
cp /mnt/config-map/slave.cnf /mnt/conf.d/
35+
cp /mnt/config-map/replica.cnf /mnt/conf.d/
3536
fi
3637
volumeMounts:
3738
- name: conf
@@ -45,15 +46,15 @@ spec:
4546
- "-c"
4647
- |
4748
set -ex
48-
# Skip the clone if data already exists.
49+
# 如果已有数据,则跳过克隆。
4950
[[ -d /var/lib/mysql/mysql ]] && exit 0
50-
# Skip the clone on master (ordinal index 0).
51+
# 跳过主实例(序号索引 0)的克隆。
5152
[[ `hostname` =~ -([0-9]+)$ ]] || exit 1
5253
ordinal=${BASH_REMATCH[1]}
5354
[[ $ordinal -eq 0 ]] && exit 0
54-
# Clone data from previous peer.
55+
# 从原来的对等节点克隆数据。
5556
ncat --recv-only mysql-$(($ordinal-1)).mysql 3307 | xbstream -x -C /var/lib/mysql
56-
# Prepare the backup.
57+
# 准备备份。
5758
xtrabackup --prepare --target-dir=/var/lib/mysql
5859
volumeMounts:
5960
- name: data
@@ -88,7 +89,7 @@ spec:
8889
timeoutSeconds: 5
8990
readinessProbe:
9091
exec:
91-
# Check we can execute queries over TCP (skip-networking is off).
92+
# 检查我们是否可以通过 TCP 执行查询(skip-networking 是关闭的)。
9293
command: ["mysql", "-h", "127.0.0.1", "-e", "SELECT 1"]
9394
initialDelaySeconds: 5
9495
periodSeconds: 2
@@ -105,22 +106,22 @@ spec:
105106
set -ex
106107
cd /var/lib/mysql
107108
108-
# Determine binlog position of cloned data, if any.
109+
# 确定克隆数据的 binlog 位置(如果有的话)。
109110
if [[ -f xtrabackup_slave_info && "x$(<xtrabackup_slave_info)" != "x" ]]; then
110-
# XtraBackup already generated a partial "CHANGE MASTER TO" query
111-
# because we're cloning from an existing slave. (Need to remove the tailing semicolon!)
111+
# XtraBackup 已经生成了部分的 “CHANGE MASTER TO” 查询
112+
# 因为我们从一个现有副本进行克隆。(需要删除末尾的分号!)
112113
cat xtrabackup_slave_info | sed -E 's/;$//g' > change_master_to.sql.in
113-
# Ignore xtrabackup_binlog_info in this case (it's useless).
114+
# 在这里要忽略 xtrabackup_binlog_info (它是没用的)。
114115
rm -f xtrabackup_slave_info xtrabackup_binlog_info
115116
elif [[ -f xtrabackup_binlog_info ]]; then
116-
# We're cloning directly from master. Parse binlog position.
117+
# 我们直接从主实例进行克隆。解析 binlog 位置。
117118
[[ `cat xtrabackup_binlog_info` =~ ^(.*?)[[:space:]]+(.*?)$ ]] || exit 1
118119
rm -f xtrabackup_binlog_info xtrabackup_slave_info
119120
echo "CHANGE MASTER TO MASTER_LOG_FILE='${BASH_REMATCH[1]}',\
120121
MASTER_LOG_POS=${BASH_REMATCH[2]}" > change_master_to.sql.in
121122
fi
122123
123-
# Check if we need to complete a clone by starting replication.
124+
# 检查我们是否需要通过启动复制来完成克隆。
124125
if [[ -f change_master_to.sql.in ]]; then
125126
echo "Waiting for mysqld to be ready (accepting connections)"
126127
until mysql -h 127.0.0.1 -e "SELECT 1"; do sleep 1; done
@@ -133,11 +134,11 @@ spec:
133134
MASTER_PASSWORD='', \
134135
MASTER_CONNECT_RETRY=10; \
135136
START SLAVE;" || exit 1
136-
# In case of container restart, attempt this at-most-once.
137+
# 如果容器重新启动,最多尝试一次。
137138
mv change_master_to.sql.in change_master_to.sql.orig
138139
fi
139140
140-
# Start a server to send backups when requested by peers.
141+
# 当对等点请求时,启动服务器发送备份。
141142
exec ncat --listen --keep-open --send-only --max-conns=1 3307 -c \
142143
"xtrabackup --backup --slave-info --stream=xbstream --host=127.0.0.1 --user=root"
143144
volumeMounts:

0 commit comments

Comments
 (0)