日常维护"/>
Redis Cluster 5.0.9 搭建、压力测试、日常维护
Redis Cluster 5.0.9 搭建、压力测试、日常维护
Redis 是非常占用 CPU、内存的,而且是单进程,就单跑一个内核,测试中发现如果在集群状态下,物理机和虚拟机在相同的配置下,物理机性能明显高于虚拟机,差不多有2倍的差距,所以建议在高性能的场景下还是用物理机。
安装
下载:wget .0.9.tar.gz
这里就不多说:
解压、安装: tar -zxvf redis-5.0.9.tar.gz ,然后 cd 到目录,再然后 make 下,到 src 目录下就能使用了
TCP监听队列大小
即TCP listen的backlog大小,“/proc/sys/net/core/somaxconn”的默认值一般较小如128,需要修改大一点,比如改成32767。立即生效还可以使用命令:sysctl -w net.core.somaxconn=32767。
要想永久生效,需要在文件/etc/sysctl.conf中增加一行:net.core.somaxconn = 32767,然后执行命令“sysctl -p”以生效。
Redis配置项tcp-backlog的值不能超过somaxconn的大小。
Cluster 搭建
集群配置
#创建目录
mkdir redis_node7001 redis_node7002 redis_node7003 redis_node7004 redis_node7005 redis_node7006cd redis_node7001
vim redis.conf
# 绑定的IP
bind 10.10.3.208
# 启动端口
port 7001
# 后台启动
daemonize yes
# pid文件位置
pidfile /var/run/redis_7001.pid#loglevel notice
# 日志文件
logfile "/root/redis_cluster_5.0/redis_node7001/redis_logfile_7001.log"
# 数据目录
dir /root/redis_cluster_5.0/redis_node7001/
# 开启redis-cluster集群
cluster-enabled yes
# 每个实例还包含存储此节点配置的文件的路径,默认情况下为nodes.conf,自动创建
cluster-config-file nodes-7001.conf
# 超时
cluster-node-timeout 15000
# 集群密码
requirepass 123456
# 开启aof
appendonly yes
# 集群同步
appendfsync no
# 保护模式,就是不能拿tcp来连接
protected-mode no
# 系统消息队列数量
tcp-backlog 32767#保存退出,执行启动
./src/redis-server redis.conf
然后将配置文件拷贝的各个文件夹中
sed -i 's/7001/7002/g' redis.conf # 修改不同的端口号
执行启动
# netstat -lntup | grep redis
tcp 0 0 10.10.3.208:7004 0.0.0.0:* LISTEN 10118/./src/redis-s
tcp 0 0 10.10.3.208:7005 0.0.0.0:* LISTEN 10140/./src/redis-s
tcp 0 0 10.10.3.208:7006 0.0.0.0:* LISTEN 10166/./src/redis-s
tcp 0 0 10.10.3.208:17001 0.0.0.0:* LISTEN 9797/./src/redis-se
tcp 0 0 10.10.3.208:17002 0.0.0.0:* LISTEN 9982/./src/redis-se
tcp 0 0 10.10.3.208:17003 0.0.0.0:* LISTEN 10052/./src/redis-s
tcp 0 0 10.10.3.208:17004 0.0.0.0:* LISTEN 10118/./src/redis-s
tcp 0 0 10.10.3.208:17005 0.0.0.0:* LISTEN 10140/./src/redis-s
tcp 0 0 10.10.3.208:17006 0.0.0.0:* LISTEN 10166/./src/redis-s
tcp 0 0 10.10.3.208:7001 0.0.0.0:* LISTEN 9797/./src/redis-se
tcp 0 0 10.10.3.208:7002 0.0.0.0:* LISTEN 9982/./src/redis-se
tcp 0 0 10.10.3.208:7003 0.0.0.0:* LISTEN 10052/./src/redis-s
创建集群
redis-cli --cluster create 10.10.3.208:7001 10.10.3.208:7002 10.10.3.208:7003 10.10.3.208:7004 10.10.3.208:7005 10.10.3.208:7006 --cluster-replicas 1 -a 123456
# create 创建一个redis集群。
# --cluster-replicas 1 表示集群创建几个副本,后面1表示 1个副本
# -a 123456 节点密码
检查集群状态
# ./src/redis-cli --cluster check 10.10.3.208:7001 -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.10.3.208:7001 (4363d70a...) -> 0 keys | 5461 slots | 1 slaves.
10.10.3.208:7003 (da6b5737...) -> 0 keys | 5461 slots | 1 slaves.
10.10.3.208:7002 (c290a233...) -> 0 keys | 5462 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 10.10.3.208:7001)
M: 4363d70af3240d07445dabf8b61855fa412b2b06 10.10.3.208:7001slots:[0-5460] (5461 slots) master1 additional replica(s)
M: da6b57377b361ae81780da7ca393307baaedbaa4 10.10.3.208:7003slots:[10923-16383] (5461 slots) master1 additional replica(s)
S: 6643131bf77b3e00d63c64685e40f35ceab14ec6 10.10.3.208:7004slots: (0 slots) slavereplicates da6b57377b361ae81780da7ca393307baaedbaa4
S: 66c91cd804336dc5e2d848721baf7aa0229fe723 10.10.3.208:7005slots: (0 slots) slavereplicates 4363d70af3240d07445dabf8b61855fa412b2b06
S: 64ee4ea79871995cce257cd302a24d7f1f5c40b8 10.10.3.208:7006slots: (0 slots) slavereplicates c290a233c9edf2bf8a74392d50578572d1d88403
M: c290a233c9edf2bf8a74392d50578572d1d88403 10.10.3.208:7002slots:[5461-10922] (5462 slots) master1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
集群压测
./redisbench -cluster=true -a 10.10.3.208:7001,10.10.3.208:7002,10.10.3.208:7003 -c 500 -n 20000 -d 10 -p 123456[root@localhost redis_cluster_5.0]# ./redisbench -cluster=true -a 10.10.3.208:7001,10.10.3.208:7002,10.10.3.208:7003,10.10.3.208:7004,10.1
0.3.208:7005,10.10.3.208:7006 -c 500 -n 50000 -d 10 -mo 3 -p 123456
2021/01/29 14:29:27 Go...
2021/01/29 14:29:27 # BENCHMARK CLUSTER (10.10.3.208:7001,10.10.3.208:7002,10.10.3.208:7003,10.10.3.208:7004,10.10.3.208:7005,10.10.3.208:7006, db:0)
2021/01/29 14:29:27 * Clients Number: 500, Testing Times: 50000, Data Size(B): 10
2021/01/29 14:29:27 * Total Times: 25000000, Total Size(B): 250000000
2021/01/29 14:30:56 # BENCHMARK DONE
2021/01/29 14:30:56 * TIMES: 25000000, DUR(s): 88.475, TPS(Hz): 282565TPS(Hz): 282565 执行的命令数(秒)
压测工具:
大家可以去这里下,然后自己编译一下 如果有需要可以留言。
更多推荐
Redis Cluster 5.0.9 搭建、压力测试、日常维护
发布评论