Cài đặt Redis Cluster 2 Server 06 Node trên Ubuntu/CentOS

I – Trên server 01: thực hiện tạo ra 3 Node Redis theo các bước sau:

Bước 1: Cài đặt các gói cần thiết

sudo apt install make gcc libc6-dev tcl

Ubuntu: 
  sudo apt install make gcc libc6-dev tcl  
CentOS:
  sudo yum install make gcc libc6-dev tcl  

Bước 2: Download file cài đặt

wget http://download.redis.io/redis-stable.tar.gz

Giải nén và tạo các Node Redis: redis_node1, redis_node2, redis_node3

tar xvzf redis-stable.tar.gz 
cd redis-stable 
mkdir -p /u01/redis/redis_node1
mkdir -p /u01/redis/redis_node2
mkdir -p /u01/redis/redis_node3

make PREFIX=/u01/redis/redis_node1 install
make PREFIX=/u01/redis/redis_node2 install
make PREFIX=/u01/redis/redis_node3 install

Sau khi chạy xong sẽ tạo được 03 Node Redis như sau:

root@sip1:~/redis-stable/src# ls /u01/redis/redis_node1/bin/
redis-benchmark  redis-check-aof  redis-check-rdb  redis-cli  redis-sentinel  redis-server

root@sip1:~/redis-stable/src# ls /u01/redis/redis_node2/bin/
redis-benchmark  redis-check-aof  redis-check-rdb  redis-cli  redis-sentinel  redis-server

root@sip1:~/redis-stable/src# ls /u01/redis/redis_node3/bin/
redis-benchmark  redis-check-aof  redis-check-rdb  redis-cli  redis-sentinel  redis-server

Để đảm bảo chạy cấu hình cluster yêu cầu cài tối thiểu trên 3 server gồm 3 node master và 3 node slave.

Một nút trong cụm Redis yêu cầu một cổng được xác định và một cổng cao hơn 10000. Trong trường hợp này, cả hai cổng TCP 6379 và 16379 đều được yêu cầu mở. Đảm bảo iptables hoặc ufw được định cấu hình đúng cách.

Tạo các thư mục: etc, log trong các Node vừa tạo:

mkdir -p /u01/redis/redis_node1/etc
mkdir -p /u01/redis/redis_node1/log
mkdir -p /u01/redis/redis_node2/etc
mkdir -p /u01/redis/redis_node2/log 
mkdir -p /u01/redis/redis_node3/etc
mkdir -p /u01/redis/redis_node3/log  

Thêm cấu hình redis vào các node: Chú ý đổi thông tin IP/Port ở mỗi node

[root@redis-01]# vi /u01/redis/redis_node1/etc/redis.conf
 Redis configuration file example.
 #
 Note that in order to read the configuration file, Redis must be
 started with the file path as first argument:
 #
 ./redis-server /path/to/redis.conf
 ############################ NETWORK
 bind 10.58.69.10
 protected-mode no
 port 8601
 tcp-backlog 511
 Close the connection after a client is idle for N seconds (0 to disable)
 timeout 120
 TCP keepalive.
 tcp-keepalive 300
 ########################### GENERAL
 daemonize no
 supervised no
 pidfile redis.pid
 loglevel notice
 logfile "log/full.log"
 databases 16
 always-show-logo yes
 ########################## SNAPSHOTTING
 save 900 1
 save 300 10
 save 60 10000
 stop-writes-on-bgsave-error yes
 rdbcompression yes
 rdbchecksum yes
 The filename where to dump the DB
 dbfilename database.rdb
 The working directory.
 dir ./
 ########################### REPLICATION
 masterauth Redis2018
 slave-serve-stale-data yes
 slave-read-only yes
 repl-diskless-sync no
 repl-diskless-sync-delay 5
 repl-disable-tcp-nodelay no
 slave-priority 100
 ############################ SECURITY
 requirepass Redis2018
 ####################### LAZY FREEING
 lazyfree-lazy-eviction no
 lazyfree-lazy-expire no
 lazyfree-lazy-server-del no
 slave-lazy-flush no
 ######################## APPEND ONLY MODE
 appendonly yes
 The name of the append only file (default: "appendonly.aof")
 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 no
 ########################## LUA SCRIPTING
 lua-time-limit 5000
 ########################## REDIS CLUSTER
 cluster-enabled yes
 cluster-config-file etc/redis_cluster.conf
 cluster-node-timeout 15000
 ############################ SLOW LOG
 slowlog-log-slower-than 10000
 slowlog-max-len 128
 ########################## LATENCY MONITOR
 latency-monitor-threshold 0
 ####################### EVENT NOTIFICATION
 notify-keyspace-events ""
 ######################### ADVANCED CONFIG
 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
 activerehashing yes
 client-output-buffer-limit normal 0 0 0
 client-output-buffer-limit slave 256mb 64mb 60
 client-output-buffer-limit pubsub 32mb 8mb 60
 hz 10
 aof-rewrite-incremental-fsync yes
 ##################### ACTIVE DEFRAGMENTATION
 Maximal effort for defrag in CPU percentage
 active-defrag-cycle-max 75
 cluster-require-full-coverage yes
 cluster-slave-validity-factor 10
[root@redis-01]# vi /u01/redis/redis_node2/etc/redis.conf
 Redis configuration file example.
 #
 Note that in order to read the configuration file, Redis must be
 started with the file path as first argument:
 #
 ./redis-server /path/to/redis.conf
 ############################ NETWORK
 bind 10.58.69.10
 protected-mode no
 port 8602
 tcp-backlog 511
 Close the connection after a client is idle for N seconds (0 to disable)
 timeout 120
 TCP keepalive.
 tcp-keepalive 300
 ########################### GENERAL
 daemonize no
 supervised no
 pidfile redis.pid
 loglevel notice
 logfile "log/full.log"
 databases 16
 always-show-logo yes
 ########################## SNAPSHOTTING
 save 900 1
 save 300 10
 save 60 10000
 stop-writes-on-bgsave-error yes
 rdbcompression yes
 rdbchecksum yes
 The filename where to dump the DB
 dbfilename database.rdb
 The working directory.
 dir ./
 ########################### REPLICATION
 masterauth Redis2018
 slave-serve-stale-data yes
 slave-read-only yes
 repl-diskless-sync no
 repl-diskless-sync-delay 5
 repl-disable-tcp-nodelay no
 slave-priority 100
 ############################ SECURITY
 requirepass Redis2018
 ####################### LAZY FREEING
 lazyfree-lazy-eviction no
 lazyfree-lazy-expire no
 lazyfree-lazy-server-del no
 slave-lazy-flush no
 ######################## APPEND ONLY MODE
 appendonly yes
 The name of the append only file (default: "appendonly.aof")
 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 no
 ########################## LUA SCRIPTING
 lua-time-limit 5000
 ########################## REDIS CLUSTER
 cluster-enabled yes
 cluster-config-file etc/redis_cluster.conf
 cluster-node-timeout 15000
 ############################ SLOW LOG
 slowlog-log-slower-than 10000
 slowlog-max-len 128
 ########################## LATENCY MONITOR
 latency-monitor-threshold 0
 ####################### EVENT NOTIFICATION
 notify-keyspace-events ""
 ######################### ADVANCED CONFIG
 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
 activerehashing yes
 client-output-buffer-limit normal 0 0 0
 client-output-buffer-limit slave 256mb 64mb 60
 client-output-buffer-limit pubsub 32mb 8mb 60
 hz 10
 aof-rewrite-incremental-fsync yes
 ##################### ACTIVE DEFRAGMENTATION
 Maximal effort for defrag in CPU percentage
 active-defrag-cycle-max 75
 cluster-require-full-coverage yes
 cluster-slave-validity-factor 10
[root@redis-01]# vi /u01/redis/redis_node3/etc/redis.conf
 Redis configuration file example.
 #
 Note that in order to read the configuration file, Redis must be
 started with the file path as first argument:
 #
 ./redis-server /path/to/redis.conf
 ############################ NETWORK
 bind 10.58.69.10
 protected-mode no
 port 8603
 tcp-backlog 511
 Close the connection after a client is idle for N seconds (0 to disable)
 timeout 120
 TCP keepalive.
 tcp-keepalive 300
 ########################### GENERAL
 daemonize no
 supervised no
 pidfile redis.pid
 loglevel notice
 logfile "log/full.log"
 databases 16
 always-show-logo yes
 ########################## SNAPSHOTTING
 save 900 1
 save 300 10
 save 60 10000
 stop-writes-on-bgsave-error yes
 rdbcompression yes
 rdbchecksum yes
 The filename where to dump the DB
 dbfilename database.rdb
 The working directory.
 dir ./
 ########################### REPLICATION
 masterauth Redis2018
 slave-serve-stale-data yes
 slave-read-only yes
 repl-diskless-sync no
 repl-diskless-sync-delay 5
 repl-disable-tcp-nodelay no
 slave-priority 100
 ############################ SECURITY
 requirepass Redis2018
 ####################### LAZY FREEING
 lazyfree-lazy-eviction no
 lazyfree-lazy-expire no
 lazyfree-lazy-server-del no
 slave-lazy-flush no
 ######################## APPEND ONLY MODE
 appendonly yes
 The name of the append only file (default: "appendonly.aof")
 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 no
 ########################## LUA SCRIPTING
 lua-time-limit 5000
 ########################## REDIS CLUSTER
 cluster-enabled yes
 cluster-config-file etc/redis_cluster.conf
 cluster-node-timeout 15000
 ############################ SLOW LOG
 slowlog-log-slower-than 10000
 slowlog-max-len 128
 ########################## LATENCY MONITOR
 latency-monitor-threshold 0
 ####################### EVENT NOTIFICATION
 notify-keyspace-events ""
 ######################### ADVANCED CONFIG
 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
 activerehashing yes
 client-output-buffer-limit normal 0 0 0
 client-output-buffer-limit slave 256mb 64mb 60
 client-output-buffer-limit pubsub 32mb 8mb 60
 hz 10
 aof-rewrite-incremental-fsync yes
 ##################### ACTIVE DEFRAGMENTATION
 Maximal effort for defrag in CPU percentage
 active-defrag-cycle-max 75
 cluster-require-full-coverage yes
 cluster-slave-validity-factor 10

II – Trên server 02: thực hiện tạo ra 3 Node Redis theo các bước sau:

Bước 3: Cài đặt trên Server 02:

mkdir -p /u01/redis/redis_node4/etc
mkdir -p /u01/redis/redis_node4/log
mkdir -p /u01/redis/redis_node5/etc
mkdir -p /u01/redis/redis_node5/log 
mkdir -p /u01/redis/redis_node6/etc
mkdir -p /u01/redis/redis_node6/log 

Download và cài đặt tương tự như Server 01:

tar xvzf redis-stable.tar.gz 
cd redis-stable 
make PREFIX=/u01/redis/redis_node4 install
make PREFIX=/u01/redis/redis_node5 install
make PREFIX=/u01/redis/redis_node6 install

Cấu hình các node: chú ý đổi IP/Port tương ứng

[root@redis-02]# vi /u01/redis/redis_node4/etc/redis.conf
 Redis configuration file example.
 #
 Note that in order to read the configuration file, Redis must be
 started with the file path as first argument:
 #
 ./redis-server /path/to/redis.conf
 ############################ NETWORK
 bind 10.58.69.11
 protected-mode no
 port 8604
 tcp-backlog 511
 Close the connection after a client is idle for N seconds (0 to disable)
 timeout 120
 TCP keepalive.
 tcp-keepalive 300
 ########################### GENERAL
 daemonize no
 supervised no
 pidfile redis.pid
 loglevel notice
 logfile "log/full.log"
 databases 16
 always-show-logo yes
 ########################## SNAPSHOTTING
 save 900 1
 save 300 10
 save 60 10000
 stop-writes-on-bgsave-error yes
 rdbcompression yes
 rdbchecksum yes
 The filename where to dump the DB
 dbfilename database.rdb
 The working directory.
 dir ./
 ########################### REPLICATION
 masterauth Redis2018
 slave-serve-stale-data yes
 slave-read-only yes
 repl-diskless-sync no
 repl-diskless-sync-delay 5
 repl-disable-tcp-nodelay no
 slave-priority 100
 ############################ SECURITY
 requirepass Redis2018
 ####################### LAZY FREEING
 lazyfree-lazy-eviction no
 lazyfree-lazy-expire no
 lazyfree-lazy-server-del no
 slave-lazy-flush no
 ######################## APPEND ONLY MODE
 appendonly yes
 The name of the append only file (default: "appendonly.aof")
 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 no
 ########################## LUA SCRIPTING
 lua-time-limit 5000
 ########################## REDIS CLUSTER
 cluster-enabled yes
 cluster-config-file etc/redis_cluster.conf
 cluster-node-timeout 15000
 ############################ SLOW LOG
 slowlog-log-slower-than 10000
 slowlog-max-len 128
 ########################## LATENCY MONITOR
 latency-monitor-threshold 0
 ####################### EVENT NOTIFICATION
 notify-keyspace-events ""
 ######################### ADVANCED CONFIG
 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
 activerehashing yes
 client-output-buffer-limit normal 0 0 0
 client-output-buffer-limit slave 256mb 64mb 60
 client-output-buffer-limit pubsub 32mb 8mb 60
 hz 10
 aof-rewrite-incremental-fsync yes
 ##################### ACTIVE DEFRAGMENTATION
 Maximal effort for defrag in CPU percentage
 active-defrag-cycle-max 75
 cluster-require-full-coverage yes
 cluster-slave-validity-factor 10 
 [root@redis-02]# vi /u01/redis/redis_node5/etc/redis.conf
 Redis configuration file example.
 #
 Note that in order to read the configuration file, Redis must be
 started with the file path as first argument:
 #
 ./redis-server /path/to/redis.conf
 ############################ NETWORK
 bind 10.58.69.11
 protected-mode no
 port 8605
 tcp-backlog 511
 Close the connection after a client is idle for N seconds (0 to disable)
 timeout 120
 TCP keepalive.
 tcp-keepalive 300
 ########################### GENERAL
 daemonize no
 supervised no
 pidfile redis.pid
 loglevel notice
 logfile "log/full.log"
 databases 16
 always-show-logo yes
 ########################## SNAPSHOTTING
 save 900 1
 save 300 10
 save 60 10000
 stop-writes-on-bgsave-error yes
 rdbcompression yes
 rdbchecksum yes
 The filename where to dump the DB
 dbfilename database.rdb
 The working directory.
 dir ./
 ########################### REPLICATION
 masterauth Redis2018
 slave-serve-stale-data yes
 slave-read-only yes
 repl-diskless-sync no
 repl-diskless-sync-delay 5
 repl-disable-tcp-nodelay no
 slave-priority 100
 ############################ SECURITY
 requirepass Redis2018
 ####################### LAZY FREEING
 lazyfree-lazy-eviction no
 lazyfree-lazy-expire no
 lazyfree-lazy-server-del no
 slave-lazy-flush no
 ######################## APPEND ONLY MODE
 appendonly yes
 The name of the append only file (default: "appendonly.aof")
 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 no
 ########################## LUA SCRIPTING
 lua-time-limit 5000
 ########################## REDIS CLUSTER
 cluster-enabled yes
 cluster-config-file etc/redis_cluster.conf
 cluster-node-timeout 15000
 ############################ SLOW LOG
 slowlog-log-slower-than 10000
 slowlog-max-len 128
 ########################## LATENCY MONITOR
 latency-monitor-threshold 0
 ####################### EVENT NOTIFICATION
 notify-keyspace-events ""
 ######################### ADVANCED CONFIG
 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
 activerehashing yes
 client-output-buffer-limit normal 0 0 0
 client-output-buffer-limit slave 256mb 64mb 60
 client-output-buffer-limit pubsub 32mb 8mb 60
 hz 10
 aof-rewrite-incremental-fsync yes
 ##################### ACTIVE DEFRAGMENTATION
 Maximal effort for defrag in CPU percentage
 active-defrag-cycle-max 75
 cluster-require-full-coverage yes
 cluster-slave-validity-factor 10  
 [root@redis-02]# vi /u01/redis/redis_node6/etc/redis.conf
 Redis configuration file example.
 #
 Note that in order to read the configuration file, Redis must be
 started with the file path as first argument:
 #
 ./redis-server /path/to/redis.conf
 ############################ NETWORK
 bind 10.58.69.11
 protected-mode no
 port 8606
 tcp-backlog 511
 Close the connection after a client is idle for N seconds (0 to disable)
 timeout 120
 TCP keepalive.
 tcp-keepalive 300
 ########################### GENERAL
 daemonize no
 supervised no
 pidfile redis.pid
 loglevel notice
 logfile "log/full.log"
 databases 16
 always-show-logo yes
 ########################## SNAPSHOTTING
 save 900 1
 save 300 10
 save 60 10000
 stop-writes-on-bgsave-error yes
 rdbcompression yes
 rdbchecksum yes
 The filename where to dump the DB
 dbfilename database.rdb
 The working directory.
 dir ./
 ########################### REPLICATION
 masterauth Redis2018
 slave-serve-stale-data yes
 slave-read-only yes
 repl-diskless-sync no
 repl-diskless-sync-delay 5
 repl-disable-tcp-nodelay no
 slave-priority 100
 ############################ SECURITY
 requirepass Redis2018
 ####################### LAZY FREEING
 lazyfree-lazy-eviction no
 lazyfree-lazy-expire no
 lazyfree-lazy-server-del no
 slave-lazy-flush no
 ######################## APPEND ONLY MODE
 appendonly yes
 The name of the append only file (default: "appendonly.aof")
 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 no
 ########################## LUA SCRIPTING
 lua-time-limit 5000
 ########################## REDIS CLUSTER
 cluster-enabled yes
 cluster-config-file etc/redis_cluster.conf
 cluster-node-timeout 15000
 ############################ SLOW LOG
 slowlog-log-slower-than 10000
 slowlog-max-len 128
 ########################## LATENCY MONITOR
 latency-monitor-threshold 0
 ####################### EVENT NOTIFICATION
 notify-keyspace-events ""
 ######################### ADVANCED CONFIG
 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
 activerehashing yes
 client-output-buffer-limit normal 0 0 0
 client-output-buffer-limit slave 256mb 64mb 60
 client-output-buffer-limit pubsub 32mb 8mb 60
 hz 10
 aof-rewrite-incremental-fsync yes
 ##################### ACTIVE DEFRAGMENTATION
 Maximal effort for defrag in CPU percentage
 active-defrag-cycle-max 75
 cluster-require-full-coverage yes
 cluster-slave-validity-factor 10  

Bước 4: Tạo các script khởi động Node Redis

 vi start_Redis.sh 
./bin/redis-server etc/redis.conf &

Copy file start_Redis.sh vào thư mục của các node:

/u01/redis/redis-node-01
/u01/redis/redis-node-02
/u01/redis/redis-node-03
/u01/redis/redis-node-04
/u01/redis/redis-node-05
/u01/redis/redis-node-06

Gán quyền chạy cho script:

chmod +x start_Redis.sh

Bước 5: Khởi động các Node trên các server

./start_Redis.sh

Bước 6: Tạo Cluster

Login vào server 01 và chạy lệnh như sau:

cd /u01/redis/redis-node-01

./redis-cli –cluster create 10.58.69.10:8601 10.58.69.10:8602 10.58.69.10:8603 10.58.69.11:8604 10.58.69.11:8605 10.58.69.11:8606 –cluster-replicas 1 -a Redis2018

Bước 7: Kiểm tra kết nối

./redis-cli -h 10.58.69.10 -p 8601 -a Redis2018 -c

10.58.69.10:8601> cluster nodes

007b96a43d9648f699847db1e282c72aca067ed0 10.58.69.10:8603@18603 slave,fail? 1f496f0586a130f9b06ca7e7a7dee3578e280452 1617248823764 1617248823763 4 connected
 5cb8e79c26d76d7c0af6cffd4592f2b71dff22fa 10.58.69.10:8602@18602 master,fail? - 1617248823764 1617248823763 2 connected 10923-16383
 21f29a5be94330c1d210d04d7b83af8147b78dc4 10.58.69.11:8606@18606 slave a4437d6b57ceeb94c2480ec80c5b91724a509719 0 1617248928915 6 connected
 a4437d6b57ceeb94c2480ec80c5b91724a509719 10.58.69.10:8601@18601 master,fail? - 1617248823764 1617248823763 1 connected 0-5460
 1f496f0586a130f9b06ca7e7a7dee3578e280452 10.58.69.11:8604@18604 master - 0 1617248929917 4 connected 5461-10922
 83221c555833022568a073ecb1fd7f2eb18ea9ea 10.58.69.11:8605@18605 myself,slave 5cb8e79c26d76d7c0af6cffd4592f2b71dff22fa 0 1617248928000 5 connected

Hãy bình luận đầu tiên

Để lại một phản hồi

Thư điện tử của bạn sẽ không được hiện thị công khai.


*