系统版本
[root@aaaaaa etcd]# cat /etc/redhat-release
Red Hat Enterprise Linux release 8.4 (Ootpa)
etcd 版本
[root@aaaaaa etcd]# /data/etcd/etcd-v3.5.15-linux-amd64/etcdctl version
etcdctl version: 3.5.15
API version: 3.5
etcd 配置文件
[ root@aaaaaa etcd]
name : node1
data-dir : /data/etcd1/etcddata
listen-client-urls : 'http://192.168.73.114:12379'
advertise-client-urls : 'http://192.168.73.114:12379'
listen-peer-urls : 'http://192.168.73.114:12380'
initial-advertise-peer-urls : 'http://192.168.73.114:12380'
initial-cluster : node1=http: //192.168.73.114: 12380
initial-cluster-token : etcd- cluster- 1
initial-cluster-state : new
etcd 启动脚本
[ root@aaaaaa etcd]
nohup /data/etcd/etcd-v3.5.15-linux-amd64/etcd \
--auto-compaction-retention= 1 \
--max-request-bytes= 10485760 \
--auth-token jwt \
--config-file= /data/etcd/ceshinodefile.yml \
>> /data/etcd/etcd.log 2 >&1 &
etcd 状态查看脚本
[ root@aaaaaa etcd]
export ETCDCTL_API = 3
ENDPOINTS = "http://192.168.73.114:12379"
/data/etcd/etcd-v3.5.15-linux-amd64/etcdctl \
--endpoints = ${ENDPOINTS} \
member list
/data/etcd/etcd-v3.5.15-linux-amd64/etcdctl \
--endpoints = ${ENDPOINTS} \
endpoint status --write-out= table
etcd 数据压缩清理脚本
[ root@aaaaaa etcd]
export ETCDCTL_DIAL_TIMEOUT = 30s
rev = $( ETCDCTL_API = 3 /data/etcd/etcd-v3.5.15-linux-amd64/etcdctl --endpoints http://192.168.73.114:12379 endpoint status --write-out= "json" | egrep -o '"revision":[0-9]*' | egrep -o '[0-9]*' )
ETCDCTL_API = 3 /data/etcd/etcd-v3.5.15-linux-amd64/etcdctl --endpoints http://192.168.73.114:12379 compact $rev
ETCDCTL_API = 3 /data/etcd/etcd-v3.5.15-linux-amd64/etcdctl --endpoints http://192.168.73.114:12379 defrag
ETCDCTL_API = 3 /data/etcd/etcd-v3.5.15-linux-amd64/etcdctl --endpoints http://192.168.73.114:12379 alarm disarm
ETCDCTL_API = 3 /data/etcd/etcd-v3.5.15-linux-amd64/etcdctl --endpoints http://192.168.73.114:12379 put key0 1234
etcd 批量测试数据写入脚本
from concurrent. futures import ThreadPoolExecutor
from pyetcd import MultiEndpointEtcd3Client, Endpoint
from pyetcd. exceptions import ConnectionFailedError
import json
import time
etcd = Endpoint( host= "192.168.73.114" , port= 12379 , secure= False , time_retry= 30 )
client = MultiEndpointEtcd3Client( [ etcd] , failover= True )
l = client. lease( 10 )
data = { "data" : 8000 }
client. put( "/test_ttl" , json. dumps( data) . encode( "utf-8" ) , lease= l)
time. sleep( 5 )
b = client. get( "/test_ttl" )
print ( b)
def write_data ( etcd, start_index, count) :
for i in range ( count) :
key = f"key { start_index + i} "
value = 'x' * 1024 * 1024
etcd. put( key, value)
num_threads = 10
records_per_thread = 1000000
with ThreadPoolExecutor( max_workers= num_threads) as executor:
futures = [ ]
for j in range ( num_threads) :
start_index = j * records_per_thread
print ( start_index)
futures. append( executor. submit( write_data, client, start_index, records_per_thread) )
for future in futures:
future. result( )
print ( "数据写入完成。" )
启动etcd
[ root@aaaaaa etcd]
+ nohup /data/etcd/etcd-v3.5.15-linux-amd64/etcd --auto-compaction-mode= revision --auto-compaction-retention= 1000 --config-file= /data/etcd/ceshinodefile.yml
[ root@aaaaaa etcd]
root 210091 1 1 18 :14 pts/8 00:00:00 /data/etcd/etcd-v3.5.15-linux-amd64/etcd --auto-compaction-mode= revision --auto-compaction-retention= 1000 --config-file= /data/etcd/ceshinodefile.yml
root 211266 3550 0 18 :15 pts/8 00:00:00 grep --color = auto /data/etcd
etcd 状态查看
[ root@aaaaaa etcd]
+ export ETCDCTL_API = 3
+ ETCDCTL_API = 3
+ ENDPOINTS = http://192.168.73.114:12379
+ /data/etcd/etcd-v3.5.15-linux-amd64/etcdctl --endpoints = http://192.168.73.114:12379 member list
5dd99bf7560a9ed0, started, node1, http://192.168.73.114:12380, http://192.168.73.114:12379, false
+ /data/etcd/etcd-v3.5.15-linux-amd64/etcdctl --endpoints = http://192.168.73.114:12379 endpoint status --write-out= table
+-----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+-----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| http://192.168.73.114:12379 | 5dd99bf7560a9ed0 | 3.5 .15 | 20 kB | true | false | 2 | 4 | 4 | |
+-----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
安装python脚本依赖包
[ root@aaaaaa etcd]
etcd测试数据写入
[ root@aaaaaa etcd]
( b'{"data": 8000}' , < pyetcd.client.KVMetadata object at 0x7f7fc9daaa00 >)
0
1000000
2000000
3000000
4000000
5000000
6000000
7000000
8000000
9000000
Traceback ( most recent call last) :
File "/data/etcd/test-data-to-etcd.py" , line 53 , in < module>
future.result( )
更改etcd的启动文件,设置存储为8G
[ root@aaaaaa etcd]
name: node1
data-dir: /data/etcd1/etcddata
listen-client-urls: 'http://192.168.73.114:12379'
advertise-client-urls: 'http://192.168.73.114:12379'
listen-peer-urls: 'http://192.168.73.114:12380'
initial-advertise-peer-urls: 'http://192.168.73.114:12380'
initial-cluster: node1 = http://192.168.73.114:12380
initial-cluster-token: etcd-cluster-1
initial-cluster-state: new
quota-backend-bytes: 8589934592
查看etcd状态
[ root@aaaaaa etcd]
+ export ETCDCTL_API = 3
+ ETCDCTL_API = 3
+ ENDPOINTS = http://192.168.73.114:12379
+ /data/etcd/etcd-v3.5.15-linux-amd64/etcdctl --endpoints = http://192.168.73.114:12379 member list
5dd99bf7560a9ed0, started, node1, http://192.168.73.114:12380, http://192.168.73.114:12379, false
+ /data/etcd/etcd-v3.5.15-linux-amd64/etcdctl --endpoints = http://192.168.73.114:12379 endpoint status --write-out= table
+-----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------------------------------+
| ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+-----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------------------------------+
| http://192.168.73.114:12379 | 5dd99bf7560a9ed0 | 3.5 .15 | 2.2 GB | true | false | 2 | 1996 | 1996 | memberID:6762607802076274384 |
| | | | | | | | | | alarm:NOSPACE |
+-----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------------------------------+
对etcd数据进行压缩
[ root@aaaaaa etcd]
+ export ETCDCTL_DIAL_TIMEOUT = 30s
+ ETCDCTL_DIAL_TIMEOUT = 30s
++ ETCDCTL_API = 3
++ /data/etcd/etcd-v3.5.15-linux-amd64/etcdctl --endpoints http://192.168.73.114:12379 endpoint status --write-out= json
++ egrep -o '"revision":[0-9]*'
++ egrep -o '[0-9]*'
+ rev = 1982
+ ETCDCTL_API = 3
+ /data/etcd/etcd-v3.5.15-linux-amd64/etcdctl --endpoints http://192.168.73.114:12379 compact 1982
compacted revision 1982
+ ETCDCTL_API = 3
+ /data/etcd/etcd-v3.5.15-linux-amd64/etcdctl --endpoints http://192.168.73.114:12379 defrag
{ "level" : "warn" ,"ts" : "2024-08-22T18:28:27.470669+0800" ,"logger" : "etcd-client" ,"caller" : "v3@v3.5.15/retry_interceptor.go:63" ,"msg" : "retrying of unary invoker failed" ,"target" : "etcd-endpoints://0xc00053a000/192.168.73.114:12379" ,"attempt" :0,"error" : "rpc error: code = DeadlineExceeded desc = context deadline exceeded" }
Failed to defragment etcd member[ http://192.168.73.114:12379] ( context deadline exceeded)
+ ETCDCTL_API = 3
+ /data/etcd/etcd-v3.5.15-linux-amd64/etcdctl --endpoints http://192.168.73.114:12379 alarm disarm
memberID:6762607802076274384 alarm:NOSPACE
+ ETCDCTL_API = 3
+ /data/etcd/etcd-v3.5.15-linux-amd64/etcdctl --endpoints http://192.168.73.114:12379 put key0 1234
OK
查看etcd状态
[ root@aaaaaa etcd]
+ export ETCDCTL_API = 3
+ ETCDCTL_API = 3
+ ENDPOINTS = http://192.168.73.114:12379
+ /data/etcd/etcd-v3.5.15-linux-amd64/etcdctl --endpoints = http://192.168.73.114:12379 member list
5dd99bf7560a9ed0, started, node1, http://192.168.73.114:12380, http://192.168.73.114:12379, false
+ /data/etcd/etcd-v3.5.15-linux-amd64/etcdctl --endpoints = http://192.168.73.114:12379 endpoint status --write-out= table
+-----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+-----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| http://192.168.73.114:12379 | 5dd99bf7560a9ed0 | 3.5 .15 | 2.1 GB | true | false | 5 | 2015 | 2015 | |
+-----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
重启etcd
[ root@aaaaaa etcd]
[ root@aaaaaa etcd]
+ nohup /data/etcd/etcd-v3.5.15-linux-amd64/etcd --auto-compaction-mode= revision --auto-compaction-retention= 1000 --config-file= /data/etcd/ceshinodefile.yml
查看etcd日志
在日志中能够找到相关的后端信息
"quota-backend-bytes":8589934592
这个为后端存储为8G,说明已经改到8G了
测试数据写入测试
[ root@aaaaaa etcd]
( b'{"data": 8000}' , < pyetcd.client.KVMetadata object at 0x7ff5ca679a00 >)
0
1000000
2000000
3000000
4000000
5000000
6000000
7000000
8000000
9000000
Traceback ( most recent call last) :
File "/data/etcd/test-data-to-etcd.py" , line 53 , in < module>
future.result( )
查看etcd状态
[ root@aaaaaa etcd]
+ export ETCDCTL_API = 3
+ ETCDCTL_API = 3
+ ENDPOINTS = http://192.168.73.114:12379
+ /data/etcd/etcd-v3.5.15-linux-amd64/etcdctl --endpoints = http://192.168.73.114:12379 member list
5dd99bf7560a9ed0, started, node1, http://192.168.73.114:12380, http://192.168.73.114:12379, false
+ /data/etcd/etcd-v3.5.15-linux-amd64/etcdctl --endpoints = http://192.168.73.114:12379 endpoint status --write-out= table
+-----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------------------------------+
| ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+-----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------------------------------+
| http://192.168.73.114:12379 | 5dd99bf7560a9ed0 | 3.5 .15 | 8.6 GB | true | false | 6 | 8007 | 8007 | memberID:6762607802076274384 |
| | | | | | | | | | alarm:NOSPACE |
+-----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------------------------------+