etcd: confirmar está fuera de rango [último índice]. ¿El registro de la balsa se corrompió, se truncó o se perdió?

etcd: confirmar está fuera de rango [último índice]. ¿El registro de la balsa se corrompió, se truncó o se perdió?


Autopista:

No es necesario leer mis tonterías——

https://github.com/etcd-io/etcd/issues/13509#issuecomment-980506247

El disparate es el siguiente:


1. Versión del entorno

Sistema operativo:

[test1280@node1 ~]$ cat /etc/redhat-release 
CentOS release 6.8 (Final)
[test1280@node1 ~]$ uname -a
Linux node1 2.6.32-642.el6.x86_64 #1 SMP Tue May 10 17:27:01 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

Versión del software:

[test1280@node1 ~]$ etcd --version
etcd Version: 3.4.18
Git SHA: 72d3e382e
Go Version: go1.12.17
Go OS/Arch: linux/amd64

Información del anfitrión:

Anfitrión IP
nodo1 192.168.75.128
nodo2 192.168.75.129
nodo3 192.168.75.130

2. Recurrencia de errores

2.1 Instalación e implementación
2.1.1.Inyectar nombre de dominio

Edite la configuración de /etc/hosts en node1-node3 y agregue lo siguiente:

192.168.75.128 etcd1.test1280
192.168.75.129 etcd2.test1280
192.168.75.130 etcd3.test1280

Verifique la configuración de /etc/hosts en nodo1-nodo3, el resultado final es el siguiente:

nodo1

[root@node1 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.75.128 etcd1.test1280
192.168.75.129 etcd2.test1280
192.168.75.130 etcd3.test1280

nodo2

[root@node2 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.75.128 etcd1.test1280
192.168.75.129 etcd2.test1280
192.168.75.130 etcd3.test1280

nodo3

[root@node3 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.75.128 etcd1.test1280
192.168.75.129 etcd2.test1280
192.168.75.130 etcd3.test1280
2.1.2 Descargar e instalar

Cargue el paquete de instalación de etcd en nodo1-nodo3 y descomprímalo.

Dirección de descarga de la versión de etcd: https://github.com/etcd-io/etcd/releases

Estoy usando: etcd-v3.4.18-linux-amd64.tar.gz

Descomprima el paquete de instalación:

[test1280@node1 ~]$ tar zxf etcd-v3.4.18-linux-amd64.tar.gz
[test1280@node2 ~]$ tar zxf etcd-v3.4.18-linux-amd64.tar.gz
[test1280@node3 ~]$ tar zxf etcd-v3.4.18-linux-amd64.tar.gz
2.1.3 Editar guión

secuencia de comandos del nodo1: start-etcd1.sh

#/bin/bash

nohup etcd \
 --name etcd1 \
 --initial-advertise-peer-urls http://etcd1.test1280:2380 \
 --listen-peer-urls http://0.0.0.0:2380 \
 --listen-client-urls http://0.0.0.0:2379 \
 --advertise-client-urls http://etcd1.test1280:2379 \
 --auto-compaction-retention '1' \
 --initial-cluster-token test1280 \
 --initial-cluster etcd1=http://etcd1.test1280:2380,etcd2=http://etcd2.test1280:2380,etcd3=http://etcd3.test1280:2380 \
 --initial-cluster-state new >etcd.log 2>&1 &

secuencia de comandos del nodo2: start-etcd2.sh

#/bin/bash

nohup etcd \
 --name etcd2 \
 --initial-advertise-peer-urls http://etcd2.test1280:2380 \
 --listen-peer-urls http://0.0.0.0:2380 \
 --listen-client-urls http://0.0.0.0:2379 \
 --advertise-client-urls http://etcd2.test1280:2379 \
 --auto-compaction-retention '1' \
 --initial-cluster-token test1280 \
 --initial-cluster etcd1=http://etcd1.test1280:2380,etcd2=http://etcd2.test1280:2380,etcd3=http://etcd3.test1280:2380 \
 --initial-cluster-state new >etcd.log 2>&1 &

secuencia de comandos nodo3: start-etcd3.sh

#/bin/bash

nohup etcd \
 --name etcd2 \
 --initial-advertise-peer-urls http://etcd2.test1280:2380 \
 --listen-peer-urls http://0.0.0.0:2380 \
 --listen-client-urls http://0.0.0.0:2379 \
 --advertise-client-urls http://etcd2.test1280:2379 \
 --auto-compaction-retention '1' \
 --initial-cluster-token test1280 \
 --initial-cluster etcd1=http://etcd1.test1280:2380,etcd2=http://etcd2.test1280:2380,etcd3=http://etcd3.test1280:2380 \
 --initial-cluster-state new >etcd.log 2>&1 &
2.1.4.Configurar RUTA

Edite la variable PATH en $HOME/.bash_profile en nodo1-nodo3:

export PATH=$HOME/etcd-v3.4.18-linux-amd64:$PATH
2.1.5 Empezar a correr

nodo1:

[test1280@node1 ~]$ ./start-etcd1.sh

nodo2:

[test1280@node2 ~]$ ./start-etcd2.sh

nodo3:

[test1280@node3 ~]$ ./start-etcd3.sh
2.1.6 Verificar estado

Ejecutar en cualquier host nodo1-nodo3:

etcdctl --endpoints=http://etcd1.test1280:2379,http://etcd2.test1280:2379,http://etcd3.test1280:2379 endpoint status -w table

Se pueden observar los siguientes resultados:

[test1280@node3 ~]$ etcdctl --endpoints=http://etcd1.test1280:2379,http://etcd2.test1280:2379,http://etcd3.test1280:2379 endpoint status -w table
+----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
|          ENDPOINT          |        ID        | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| http://etcd1.test1280:2379 | 8d8f805c54155c1f |  3.4.18 |   20 kB |      true |      false |         4 |          9 |                  9 |        |
| http://etcd2.test1280:2379 | b2a96233e99da684 |  3.4.18 |   20 kB |     false |      false |         4 |          9 |                  9 |        |
| http://etcd3.test1280:2379 | 427c1e146435064e |  3.4.18 |   20 kB |     false |      false |         4 |          9 |                  9 |        |
+----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+

Actualmente el grupo etcd es normal.

Para obtener más información sobre la instalación, consulte: Linux: instalar el clúster etcd .

2.2 Detener etc.

Utilice el comando kill -9 para detener el proceso etcd de cualquier nodo. Tomamos el nodo nodo1 como ejemplo:

[test1280@node1 ~]$ ps -ef | grep etcd
test1280   6017      1  1 10:36 pts/0    00:00:03 etcd --name etcd1 --initial-advertise-peer-urls http://etcd1.test1280:2380 --listen-peer-urls http://0.0.0.0:2380 --listen-client-urls http://0.0.0.0:2379 --advertise-client-urls http://etcd1.test1280:2379 --auto-compaction-retention 1 --initial-cluster-token test1280 --initial-cluster etcd1=http://etcd1.test1280:2380,etcd2=http://etcd2.test1280:2380,etcd3=http://etcd3.test1280:2380 --initial-cluster-state new
test1280   6031   5952  0 10:41 pts/0    00:00:00 grep --color=always etcd

El PID del proceso etcd del nodo1 nodo = 6017, use el comando kill -9 para detenerlo:

[test1280@node1 ~]$ kill -9 6017
2.3 Eliminar archivos de datos etcd

Elimine el archivo de datos etcd en el nodo1; en nuestro ejemplo actual, es etcd1.etcd:

[test1280@node1 ~]$ ll
total 17044
drwx------. 3 test1280 test1280     4096 Mar 18 10:36 etcd1.etcd【***这个***】
-rw-rw-r--. 1 test1280 test1280     9540 Mar 18 10:36 etcd.log
drwxr-xr-x. 3 test1280 test1280     4096 Oct 15 06:53 etcd-v3.4.18-linux-amd64
-rw-r--r--. 1 test1280 test1280 17414708 Mar 18 01:38 etcd-v3.4.18-linux-amd64.tar.gz
-rwxr-xr-x. 1 test1280 test1280      478 Mar 18 10:24 start-etcd1.sh
-rwxr-xr-x. 1 test1280 test1280      478 Mar 18 10:26 start-etcd2.sh
-rwxr-xr-x. 1 test1280 test1280      478 Mar 18 10:26 start-etcd3.sh
[test1280@node1 ~]$ rm -rf etcd1.etcd/
2.4 Modificar el script de inicio de etcd

Modifique el script de inicio de etcd en el nodo1:

antes de arreglar:

 --initial-cluster-state new >etcd.log 2>&1 &

Después de la modificación:

 --initial-cluster-state existing >etcd.log 2>&1 &

Es decir, simplemente cambie --initial-cluster-state a existente.

2.5 Reiniciar etc.

Reinicie etcd del nodo1 y ejecute su script start-etcd1.sh:

[test1280@node1 ~]$ ./start-etcd1.sh

En este momento, el etcd del nodo 1 no se puede iniciar. Puede ver etcd.log:

raft2022/03/18 11:02:20 INFO: 8d8f805c54155c1f [term: 0] received a MsgHeartbeat message with higher term from 427c1e146435064e [term: 5]
raft2022/03/18 11:02:20 INFO: 8d8f805c54155c1f became follower at term 5
raft2022/03/18 11:02:20 tocommit(11) is out of range [lastIndex(0)]. Was the raft log corrupted, truncated, or lost?
panic: tocommit(11) is out of range [lastIndex(0)]. Was the raft log corrupted, truncated, or lost?

goroutine 155 [running]:
log.(*Logger).Panicf(0xc0001426e0, 0x10e77d8, 0x5d, 0xc0003960a0, 0x2, 0x2)
    /home/remote/sbatsche/.gvm/gos/go1.12.17/src/log/log.go:219 +0xc1
...

El error vuelve a aparecer.


3.Solución

Alguien ya ha dado una solución al problema de github :

Este problema se debe a que el proceso etcd falla y, al mismo tiempo, su archivo de datos se pierde y se producirá un error al reiniciar.

Es razonable que esta situación extrema requiera intervención manual para su recuperación.

Paso 1: eliminar el nodo etcd del nodo1 del clúster

El ID de etcd del nodo1 es: 8d8f805c54155c1f

Insertar descripción de la imagen aquí
Elimine el etcd del nodo1 en el etcd del nodo2 y el nodo3:

[test1280@node2 ~]$ etcdctl --endpoints=http://etcd2.test1280:2379,http://etcd3.test1280:2379 member remove 8d8f805c54155c1f
Member 8d8f805c54155c1f removed from cluster 6ee07b66b4556e33
Paso 2: agregue nuevamente el nodo etcd del nodo1 al clúster

Vuelva a agregar el etcd del nodo1 al etcd del nodo2 y el nodo3:

[test1280@node2 ~]$ etcdctl --endpoints=http://etcd2.test1280:2379,http://etcd3.test1280:2379 member add etcd1 --peer-urls=http://etcd1.test1280:2380
Member 3662f03eb0a523d9 added to cluster 6ee07b66b4556e33

ETCD_NAME="etcd1"
ETCD_INITIAL_CLUSTER="etcd1=http://etcd1.test1280:2380,etcd3=http://etcd3.test1280:2380,etcd2=http://etcd2.test1280:2380"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://etcd1.test1280:2380"
ETCD_INITIAL_CLUSTER_STATE="existing"

Tenga en cuenta que debe especificar el nombre y las URL de pares de etcd del nodo1.

Paso 3: modifique el script de inicio etcd del nodo1

Por último, inicie el miembro nuevamente; tenga en cuenta que debe configurar --initial-cluster-state como "existente" en este caso.

Tenga en cuenta que el último --initial-cluster-state existe, no es nuevo:

[test1280@node1 ~]$ cat start-etcd1.sh 
#/bin/bash

nohup etcd \
 --name etcd1 \
 --initial-advertise-peer-urls http://etcd1.test1280:2380 \
 --listen-peer-urls http://0.0.0.0:2380 \
 --listen-client-urls http://0.0.0.0:2379 \
 --advertise-client-urls http://etcd1.test1280:2379 \
 --auto-compaction-retention '1' \
 --initial-cluster-token test1280 \
 --initial-cluster etcd1=http://etcd1.test1280:2380,etcd2=http://etcd2.test1280:2380,etcd3=http://etcd3.test1280:2380 \
 --initial-cluster-state existing>etcd.log 2>&1 &
Paso 4: Limpiar los datos originales del etcd del nodo1 (si corresponde)

Eliminar: etcd1.etcd (si corresponde)

[test1280@node1 ~]$ ll
total 17040
drwx------. 3 test1280 test1280     4096 Mar 18 11:11 etcd1.etcd
-rw-rw-r--. 1 test1280 test1280     4565 Mar 18 11:11 etcd.log
drwxr-xr-x. 3 test1280 test1280     4096 Oct 15 06:53 etcd-v3.4.18-linux-amd64
-rw-r--r--. 1 test1280 test1280 17414708 Mar 18 01:38 etcd-v3.4.18-linux-amd64.tar.gz
-rwxr-xr-x. 1 test1280 test1280      482 Mar 18 11:00 start-etcd1.sh
-rwxr-xr-x. 1 test1280 test1280      478 Mar 18 10:26 start-etcd2.sh
-rwxr-xr-x. 1 test1280 test1280      478 Mar 18 10:26 start-etcd3.sh
[test1280@node1 ~]$ rm -rf etcd1.etcd/
Paso 5: reiniciar la verificación

Insertar descripción de la imagen aquí
Se puede observar que el etcd del nodo1 se ha agregado normalmente al clúster.


4. Referencias

https://github.com/etcd-io/etcd/issues/13509

Guess you like

Origin blog.csdn.net/test1280/article/details/123579775