# 下载并解压
wget https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.2.tar.gz
tar -zxvf ruby-3.1.2.tar.gz
# 编译安装
yum -y install openssl-devel gcc gcc-c++ zlib
cd ruby-3.1.2
./configure --prefix=/usr/local/ruby-3.1.2 --with-openssl-dir=/usr/include/openssl
make
make install
# 配置环境变量
vi /etc/profile
export RUBY_HOME=/usr/local/ruby-3.1.2
export REDIS_HOME=/usr/local/redis-6.2.7
export REDISCLI_AUTH=123456
export PATH=$RUBY_HOME/bin:$PATH
source /etc/profile
# 验证
ruby -v
gem -v
# 安装redis
gem install redis -v 4.5.1
下载并解压
wget https://download.redis.io/releases/redis-6.2.7.tar.gz
tar -zxvf redis-6.2.7.tar.gz -C /usr/local/
安装
cd /usr/local/redis-6.2.7/
make && make install
# 创建数据目录
mkdir -p cluster/{7000,7001}
# 安装服务
cd utils/
./install_server.sh
如果出现以下报错:
This systems seems to use systemd.
Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!
解决方法:
vi ./install_server.sh
# 注释以下内容
#bail if this system is managed by systemd
# _pid_1_exe="$(readlink -f /proc/1/exe)"
# if [ "${_pid_1_exe##*/}" = systemd ]
# then
# echo "This systems seems to use systemd."
# echo "Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!"
# exit 1
# fi
再次执行安装
./install_server.sh
执行过程如下:
# 安装7000服务
[root@bogon utils]# ./install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379] 7000
Please select the redis config file name [/etc/redis/7000.conf] /usr/local/redis-6.2.7/cluster/7000/nodes_7000.conf
Please select the redis log file name [/var/log/redis_7000.log] /usr/local/redis-6.2.7/logs/redis_7000.log
Please select the data directory for this instance [/var/lib/redis/7000] /usr/local/redis-6.2.7/cluster/7000
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port : 7000 # 端口
Config file : /usr/local/redis-6.2.7/cluster/7000/nodes_7000.conf # 配置文件
Log file : /usr/local/redis-6.2.7/logs/redis_7000.log # 日志文件
Data dir : /usr/local/redis-6.2.7/cluster/7000 # 数据目录
Executable : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/7000.conf => /etc/init.d/redis_7000
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
# 安装7001服务
[root@bogon utils]# ./install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379] 7001
Please select the redis config file name [/etc/redis/7001.conf] /usr/local/redis-6.2.7/cluster/7000/nodes_7001.conf
Please select the redis log file name [/var/log/redis_7001.log] /usr/local/redis-6.2.7/logs/redis_7001.log
Please select the data directory for this instance [/var/lib/redis/7001] /usr/local/redis-6.2.7/cluster/7001
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port : 7001 # 端口
Config file : /usr/local/redis-6.2.7/cluster/7001/nodes_7001.conf # 配置文件
Log file : /usr/local/redis-6.2.7/logs/redis_7001.log # 日志文件
Data dir : /usr/local/redis-6.2.7/cluster/7001 # 数据目录
Executable : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/7001.conf => /etc/init.d/redis_7001
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
查看服务
chkconfig --list | grep redis
...
redis_7000 0:off 1:off 2:on 3:on 4:on 5:on 6:off
redis_7001 0:off 1:off 2:on 3:on 4:on 5:on 6:off
分别修改redis_7000、redis_7001启动脚本:
vi /etc/init.d/redis_7000
# 添加变量
REDISCLI_AUTH="123456" # 连接master密码
# 将$CLIEXEC -p $REDISPORT shutdown修改为如下
$CLIEXEC -p $REDISPORT -a $REDISCLI_AUTH shutdown 2>/dev/null
服务启停
service redis_7000 start
service redis_7001 start
service redis_7000 stop
service redis_7001 stop
service redis_7000 restart
service redis_7001 restart
netstat -lnpt | grep 7000
netstat -lnpt | grep 7000
修改配置文件
分别修改节点1、节点2的nodes_7000.conf、nodes_7001.conf文件。
# 修改7000.conf
vi /usr/local/redis-6.2.7/cluster/7000/nodes_7000.conf
################################## NETWORK #####################################
bind 192.168.16.135
protected-mode no
port 7000
tcp-backlog 511
unixsocket /run/redis.sock
unixsocketperm 700
timeout 0
tcp-keepalive 300
################################# GENERAL #####################################
daemonize yes
pidfile /var/run/redis_7000.pid
loglevel notice
logfile /usr/local/redis-6.2.7/logs/redis_7000.log
databases 16
always-show-logo no
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
################################ SNAPSHOTTING ################################
save 900 1
save 300 100
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
rdb-del-sync-files no
dir /usr/local/redis-6.2.7/cluster/7000
################################# REPLICATION #################################
masterauth 123456
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
################################## SECURITY ###################################
acllog-max-len 128
requirepass 123456
################################### CLIENTS ####################################
maxclients 5000
############################## MEMORY MANAGEMENT ################################
maxmemory 512mb
############################# LAZY FREEING ####################################
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
lazyfree-lazy-user-flush no
############################ KERNEL OOM CONTROL ##############################
oom-score-adj no
oom-score-adj-values 0 200 800
#################### KERNEL transparent hugepage CONTROL ######################
disable-thp yes
############################## APPEND ONLY MODE ###############################
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
################################ LUA SCRIPTING ###############################
lua-time-limit 5000
################################ REDIS CLUSTER ###############################
cluster-enabled yes
cluster-config-file /usr/local/redis-6.2.7/cluster/7000/nodes-7000.conf
cluster-node-timeout 15000
cluster-replica-validity-factor 10
cluster-migration-barrier 1
cluster-allow-replica-migration yes
cluster-require-full-coverage yes
cluster-replica-no-failover no
cluster-allow-reads-when-down no
################################## SLOW LOG ###################################
slowlog-log-slower-than 10000
slowlog-max-len 128
################################ LATENCY MONITOR ##############################
latency-monitor-threshold 0
############################# EVENT NOTIFICATION ##############################
notify-keyspace-events ""
############################### GOPHER SERVER #################################
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
########################### ACTIVE DEFRAGMENTATION #######################
jemalloc-bg-thread yes
# 修改7001.conf
vi /usr/local/redis-6.2.7/cluster/7001/nodes_7001.conf
################################## NETWORK #####################################
bind 192.168.16.135
protected-mode no
port 7001
tcp-backlog 511
unixsocket /run/redis.sock
unixsocketperm 700
timeout 0
tcp-keepalive 300
################################# GENERAL #####################################
daemonize yes
pidfile /var/run/redis_7001.pid
loglevel notice
logfile /usr/local/redis-6.2.7/logs/redis_7001.log
databases 16
always-show-logo no
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
################################ SNAPSHOTTING ################################
save 900 1
save 300 100
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
rdb-del-sync-files no
dir /usr/local/redis-6.2.7/cluster/7001
################################# REPLICATION #################################
masterauth 123456
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
################################## SECURITY ###################################
acllog-max-len 128
requirepass 123456
################################### CLIENTS ####################################
maxclients 5000
############################## MEMORY MANAGEMENT ################################
maxmemory 512mb
############################# LAZY FREEING ####################################
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
lazyfree-lazy-user-flush no
############################ KERNEL OOM CONTROL ##############################
oom-score-adj no
oom-score-adj-values 0 200 800
#################### KERNEL transparent hugepage CONTROL ######################
disable-thp yes
############################## APPEND ONLY MODE ###############################
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
################################ LUA SCRIPTING ###############################
lua-time-limit 5000
################################ REDIS CLUSTER ###############################
cluster-enabled yes
cluster-config-file /usr/local/redis-6.2.7/cluster/7001/nodes-7001.conf
cluster-node-timeout 15000
cluster-replica-validity-factor 10
cluster-migration-barrier 1
cluster-allow-replica-migration yes
cluster-require-full-coverage yes
cluster-replica-no-failover no
cluster-allow-reads-when-down no
################################## SLOW LOG ###################################
slowlog-log-slower-than 10000
slowlog-max-len 128
################################ LATENCY MONITOR ##############################
latency-monitor-threshold 0
############################# EVENT NOTIFICATION ##############################
notify-keyspace-events ""
############################### GOPHER SERVER #################################
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
########################### ACTIVE DEFRAGMENTATION #######################
jemalloc-bg-thread yes
重启服务
kill -9 $(cat /var/run/redis_6379.pid)
rm -rf /var/run/redis_6379.pid
service redis_6379 start
redis-cli --cluster create \
192.168.16.135:7000 \
192.168.16.135:7001 \
192.168.16.136:7000 \
192.168.16.136:7001 \
192.168.16.137:7000 \
192.168.16.137:7001 \
-a 123456 \
--cluster-replicas 1
执行过程如下:
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.16.136:7001 to 192.168.16.135:7000
Adding replica 192.168.16.137:7001 to 192.168.16.136:7000
Adding replica 192.168.16.135:7001 to 192.168.16.137:7000
M: 84b6a68b6f26aa277102e53ab03352b21b4f6e23 192.168.16.135:7000
slots:[0-5460] (5461 slots) master
S: 6e739365de3f8b9c4d2e540b5ff3e974e1e584d2 192.168.16.135:7001
replicates 3e13efe0501cc12f9c328d4f7c13458854593e65
M: a1c1000b4fa3252c4ba1020f1b9ae6acb554a589 192.168.16.136:7000
slots:[5461-10922] (5462 slots) master
S: de8020d2fc230f05002b971bdb49a79acfd05334 192.168.16.136:7001
replicates 84b6a68b6f26aa277102e53ab03352b21b4f6e23
M: 3e13efe0501cc12f9c328d4f7c13458854593e65 192.168.16.137:7000
slots:[10923-16383] (5461 slots) master
S: 060a2efd27d6a8ca9c564d4ee4e2f4d1f499303c 192.168.16.137:7001
replicates a1c1000b4fa3252c4ba1020f1b9ae6acb554a589
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
.
>>> Performing Cluster Check (using node 192.168.16.135:7000)
M: 84b6a68b6f26aa277102e53ab03352b21b4f6e23 192.168.16.135:7000
slots:[0-5460] (5461 slots) master
1 additional replica(s)
M: 3e13efe0501cc12f9c328d4f7c13458854593e65 192.168.16.137:7000
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
S: 060a2efd27d6a8ca9c564d4ee4e2f4d1f499303c 192.168.16.137:7001
slots: (0 slots) slave
replicates a1c1000b4fa3252c4ba1020f1b9ae6acb554a589
M: a1c1000b4fa3252c4ba1020f1b9ae6acb554a589 192.168.16.136:7000
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
S: 6e739365de3f8b9c4d2e540b5ff3e974e1e584d2 192.168.16.135:7001
slots: (0 slots) slave
replicates 3e13efe0501cc12f9c328d4f7c13458854593e65
S: de8020d2fc230f05002b971bdb49a79acfd05334 192.168.16.136:7001
slots: (0 slots) slave
replicates 84b6a68b6f26aa277102e53ab03352b21b4f6e23
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
查看集群信息
[root@bogon redis-6.2.7]# redis-cli --cluster info -a 123456 192.168.16.135:7000
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.16.135:7000 (84b6a68b...) -> 0 keys | 5461 slots | 1 slaves.
192.168.16.137:7000 (3e13efe0...) -> 0 keys | 5461 slots | 1 slaves.
192.168.16.136:7000 (a1c1000b...) -> 0 keys | 5462 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.
检查集群
[root@bogon redis-6.2.7]# redis-cli --cluster check -a 123456 192.168.16.135:7000 --cluster-search-multiple-owners
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.16.135:7000 (84b6a68b...) -> 0 keys | 5461 slots | 1 slaves.
192.168.16.137:7000 (3e13efe0...) -> 0 keys | 5461 slots | 1 slaves.
192.168.16.136:7000 (a1c1000b...) -> 0 keys | 5462 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.16.135:7000)
M: 84b6a68b6f26aa277102e53ab03352b21b4f6e23 192.168.16.135:7000
slots:[0-5460] (5461 slots) master
1 additional replica(s)
M: 3e13efe0501cc12f9c328d4f7c13458854593e65 192.168.16.137:7000
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
S: 060a2efd27d6a8ca9c564d4ee4e2f4d1f499303c 192.168.16.137:7001
slots: (0 slots) slave
replicates a1c1000b4fa3252c4ba1020f1b9ae6acb554a589
M: a1c1000b4fa3252c4ba1020f1b9ae6acb554a589 192.168.16.136:7000
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
S: 6e739365de3f8b9c4d2e540b5ff3e974e1e584d2 192.168.16.135:7001
slots: (0 slots) slave
replicates 3e13efe0501cc12f9c328d4f7c13458854593e65
S: de8020d2fc230f05002b971bdb49a79acfd05334 192.168.16.136:7001
slots: (0 slots) slave
replicates 84b6a68b6f26aa277102e53ab03352b21b4f6e23
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Check for multiple slot owners...
[OK] No multiple owners found.