Redis Cluster 5.0.9 build, stress test, daily maintenance
Redis occupies a lot of CPU and memory, and it is a single process. It runs a single kernel. In the test, it is found that if the physical machine and the virtual machine are in the same configuration in the cluster state, the performance of the physical machine is significantly higher than that of the virtual machine. There is a gap of 2 times, so it is recommended to use a physical machine in high-performance scenarios.
installation
Download: wget https://download.redis.io/releases/redis-5.0.9.tar.gz
Not much to say here:
Unzip and install: tar -zxvf redis-5.0.9.tar.gz, then cd to the directory, and then under make, you can use it under the src directory
TCP listen queue size
That is, the backlog size of TCP listen. The default value of "/proc/sys/net/core/ somaxconn " is generally smaller, such as 128, and needs to be modified to be larger, such as 32767. You can also use the command to take effect immediately: sysctl -w net.core.somaxconn=32767.
To take effect permanently, you need to add a line in the file /etc/sysctl.conf: net.core.somaxconn = 32767, and then execute the command "sysctl -p" to take effect.
The value of the Redis configuration item tcp-backlog cannot exceed the size of somaxconn .
Cluster construction
Cluster configuration
#创建目录
mkdir redis_node7001 redis_node7002 redis_node7003 redis_node7004 redis_node7005 redis_node7006
cd 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
Then copy the configuration file to each folder
sed -i's/7001/7002/g' redis.conf # modify different port numbers
Execute start
# 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
Create a cluster
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 节点密码
Check cluster status
# ./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:7001
slots:[0-5460] (5461 slots) master
1 additional replica(s)
M: da6b57377b361ae81780da7ca393307baaedbaa4 10.10.3.208:7003
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
S: 6643131bf77b3e00d63c64685e40f35ceab14ec6 10.10.3.208:7004
slots: (0 slots) slave
replicates da6b57377b361ae81780da7ca393307baaedbaa4
S: 66c91cd804336dc5e2d848721baf7aa0229fe723 10.10.3.208:7005
slots: (0 slots) slave
replicates 4363d70af3240d07445dabf8b61855fa412b2b06
S: 64ee4ea79871995cce257cd302a24d7f1f5c40b8 10.10.3.208:7006
slots: (0 slots) slave
replicates c290a233c9edf2bf8a74392d50578572d1d88403
M: c290a233c9edf2bf8a74392d50578572d1d88403 10.10.3.208:7002
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
Cluster pressure test
./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): 282565
TPS(Hz): 282565 执行的命令数(秒)
Pressure measurement tools:
You can download it here and compile it yourself https://github.com/panjiang/redisbench If you need it, you can leave a message.