Redis非关系型数据库群集

Redis非关系型数据库群集

部署及安装Redis

1) 上传redis程序包
在这里插入图片描述

2)解压缩redis程序包到/usr/src/目录
[root@centos01 ~]# ls
anaconda-ks.cfg initial-setup-ks.cfg redis-3.2.9.tar.gz
[root@centos01 ~]# tar zxvf redis-3.2.9.tar.gz -C /usr/src/

3)进入/usr/src/目录,将redis-3.2.9程序剪切到redis目录
[root@centos01 ~]# cd /usr/src/
[root@centos01 src]# ls
debug kernels redis-3.2.9
[root@centos01 src]# mv redis-3.2.9/ redis
[root@centos01 src]# ls
debug kernels redis

4)进入redis目录,编译及安装redis(若想更改安装路径,可以使用make PREFIX=安装路径 install命令格式来进行安装)
[root@centos01 src]# cd redis/
[root@centos01 redis]# make && make install

5)初始化redis
[root@centos01 redis]# cd utils/
[root@centos01 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]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
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/6379.conf => /etc/init.d/redis_6379
Installing service…
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server…
Installation successful!

6)编辑redis主配置文件
[root@centos01 ~]# vim /etc/redis/6379.conf
bind 192.168.100.10
port 6379
daemonize yes
pidfile /var/run/redis_6379.pid
loglevel notice
logfile “/var/log/redis_6379.log”

6)启动redis,监听redis是否启动成功
[root@centos01 ~]# /etc/init.d/redis_6379 start
[root@centos01 ~]# netstat -anptu | grep redis
tcp 0 0 192.168.100.10:6379 0.0.0.0:* LISTEN 5687/redis-server 1

7)添加新的redis实例
[root@centos01 ~]# cp -rf /usr/src/redis /usr/src/redis01/

8)修改redis新实例监听的端口号及守护进程方式运行
[root@centos01 redis01]# vim redis.conf
port 6378
daemonize yes

9)启动新添加的redis实例
[root@centos01 ~]# redis-server /usr/src/redis01/redis.conf
[root@centos01 ~]# netstat -anptu | grep redis
tcp 0 0 192.168.100.10:6379 0.0.0.0:* LISTEN 5687/redis-server 1
tcp 0 0 127.0.0.1:6378 0.0.0.0:* LISTEN 5141/redis-server 1

10)使用help命令获取命令类型的帮助
[root@centos01 ~]# redis-cli
192.168.100.10:6379> help @list

BLPOP key [key …] timeout
summary: Remove and get the first element in a list, or block until one is available
since: 2.0.0

BRPOP key [key …] timeout
summary: Remove and get the last element in a list, or block until one is available
since: 2.0.0

BRPOPLPUSH source destination timeout
summary: Pop a value from a list, push it to another list and return it; or block until one is available
since: 2.2.0

LINDEX key index
summary: Get an element from a list by its index
since: 1.0.0

LINSERT key BEFORE|AFTER pivot value
summary: Insert an element before or after another element in a list
since: 2.2.0

LLEN key
summary: Get the length of a list
since: 1.0.0

LPOP key
summary: Remove and get the first element in a list
since: 1.0.0

LPUSH key value [value …]
summary: Prepend one or multiple values to a list
since: 1.0.0

LPUSHX key value
summary: Prepend a value to a list, only if the list exists
since: 2.2.0

LRANGE key start stop
summary: Get a range of elements from a list
since: 1.0.0

LREM key count value
summary: Remove elements from a list
since: 1.0.0

LSET key index value
summary: Set the value of an element in a list by its index
since: 1.0.0

LTRIM key start stop
summary: Trim a list to the specified range
since: 1.0.0

RPOP key
summary: Remove and get the last element in a list
since: 1.0.0

RPOPLPUSH source destination
summary: Remove the last element in a list, prepend it to another list and return it
since: 1.2.0

RPUSH key value [value …]
summary: Append one or multiple values to a list
since: 1.0.0

RPUSHX key value
summary: Append a value to a list, only if the list exists
since: 2.2.0

127.0.0.1:6379> help set

SET key value [EX seconds] [PX milliseconds] [NX|XX]
summary: Set the string value of a key
since: 1.0.0
group: string

127.0.0.1:6379> help get

GET key
summary: Get the value of a key
since: 1.0.0
group: string

redis-cli命令行工具使用

1) 登录本地redis
[root@centos01 ~]# redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> exit

2)登录本地修改过端口的redis实例
[root@centos01 ~]# redis-cli -p 6378
127.0.0.1:6378> ping
PONG
127.0.0.1:6378> exit

3)登录远程主机100.10的6379端口redis实例
[root@centos01 ~]# redis-cli -h 192.168.100.10 -p 6379

Redis-benchmark性能测试工具使用

1) 针对100.10的redis服务器进行性能检测,发送100个并发连接与10000个请求测试性能
[root@centos01 ~]# redis-benchmark -h 192.168.100.10 -p 6379 -c 100 -n 10000
…………
5165.29 requests per second

====== MSET (10 keys) ======
10000 requests completed in 0.18 seconds
100 parallel clients
3 bytes payload
keep alive: 1

0.01% <= 1 milliseconds
98.93% <= 2 milliseconds
100.00% <= 2 milliseconds
55555.55 requests per second

2)测试100.10的redis服务器存取大小为100B的数据包的性能
[root@centos01 ~]# redis-benchmark -h 192.168.100.10 -p 6379 -q -d 100
PING_INLINE: 100603.62 requests per second
PING_BULK: 98231.83 requests per second
SET: 87412.59 requests per second
GET: 90991.81 requests per second
INCR: 94786.73 requests per second
LPUSH: 86206.90 requests per second
RPUSH: 82987.55 requests per second
LPOP: 84245.99 requests per second
RPOP: 87108.02 requests per second
SADD: 90744.10 requests per second
SPOP: 90661.83 requests per second
LPUSH (needed to benchmark LRANGE): 85251.49 requests per second
LRANGE_100 (first 100 elements): 23912.00 requests per second
LRANGE_300 (first 300 elements): 6502.37 requests per second
LRANGE_500 (first 450 elements): 3816.07 requests per second
LRANGE_600 (first 600 elements): 2778.09 requests per second
MSET (10 keys): 54141.85 requests per second

3)测试100.10的redis服务器在进行set与lpush操作时的性能
[root@centos01 ~]# redis-benchmark -t set,lpush -n 100000 -q
SET: 81037.28 requests per second
LPUSH: 88652.48 requests per second

Redis数据库常用命令

Set和get相关命令

1)在当前数据库存放一个key为xingming,value为liyanxin的数据
[root@centos01 ~]# redis-cli
192.168.100.10:6379> set xingming liyanxin
OK
192.168.100.10:6379> set xingbie nan
OK

2)查看数据
192.168.100.10:6379> get xingming
“liyanxin”

192.168.100.10:6379> get xingbie
“nan”

Key相关命令

1)使用keys命令获取符合规则的键值列表,结合*、?等选项来操作
192.168.100.10:6379> set k1 1
OK
192.168.100.10:6379> set k2 2
OK
192.168.100.10:6379> set v1 3
OK
192.168.100.10:6379> set v2 4
OK
192.168.100.10:6379> set v33 6
OK
192.168.100.10:6379> KEYS *

  1. “xingming”
  2. “xingbie”
  3. “k1”
  4. “k2”
  5. “v1”
  6. “v2”
  7. “v33”
    192.168.100.10:6379> KEYS v*
  8. “v1”
  9. “v2”
  10. “v33”
    192.168.100.10:6379> KEYS v?
  11. “v1”
  12. “v2”
    192.168.100.10:6379> KEYS v??
  13. “v33”
    192.168.100.10:6379> KEYS k*
  14. “k2”
  15. “k1”
    192.168.100.10:6379> KEYS k?
  16. “k2”
  17. “k1”

2)使用exists命令判断键值是否存在
192.168.100.10:6379> EXISTS xingming
(integer) 1
192.168.100.10:6379> EXISTS xingbie
(integer) 1
192.168.100.10:6379> EXISTS danwei
(integer) 0
192.168.100.10:6379> EXISTS nianling
(integer) 0

3)使用del命令删除当前数据库的指定key
192.168.100.10:6379> KEYS *

  1. “xingming”
  2. “xingbie”
  3. “k1”
  4. “k2”
  5. “v1”
  6. “v2”
  7. “v33”
    192.168.100.10:6379> del k2
    (integer) 1
    192.168.100.10:6379> del v2
    (integer) 1

4)使用type命令获取key对应的value值类型
192.168.100.10:6379>> type v33
string
192.168.100.10:6379> type xingbie
string

5)使用rename命令对已有key进行重命名。(使用rename命令进行重命名时,无论目标key是否存在都进行重命名,且源key的值会覆盖目标key的值;在实际工作当中,建议先使用exists命令查看目标key是否存在,再决定是否执行rename命令,以避免覆盖重要数据)
192.168.100.10:6379> KEYS *

  1. “xingming”
  2. “xingbie”
  3. “k1”
  4. “k2”
  5. “v1”
  6. “v2”
  7. “v33”
    192.168.100.10:6379> rename v33 v3
    OK
    192.168.100.10:6379> keys v*
  8. “v1”
  9. “v3”
    192.168.100.10:6379> get v1
    “3”
    192.168.100.10:6379> get v3
    “6”
    192.168.100.10:6379> rename v1 v3
    OK
    192.168.100.10:6379> get v1
    (nil)
    192.168.100.10:6379> get v3
    “3”

6)使用renamenx命令对已有key进行重命名,并检测新名是否存在。(使用renamenx命令进行重命名时,如果目标key存在则不进行重命名)
192.168.100.10:6379> KEYS *

  1. “xingming”
  2. “xingbie”
  3. “k1”
  4. “v3”
    192.168.100.10:6379> get xingming
    “liyanxin”
    192.168.100.10:6379> get k1
    “1”
    127.0.0.1:6379> renamenx k1 xingming
    (integer) 0
    192.168.100.10:6379> KEYS *
  5. “xingming”
  6. “xingbie”
  7. “k1”
  8. “v3”
    192.168.100.10:6379> get k1
    “1”

7)使用dbsize命令查看当前数据库中key的数目
192.168.100.10:6379> dbsize
(integer) 6

多数据库常用命令

1)多数据库之间切换
192.168.100.10:6379> select 5
OK
192.168.100.10:6379 [5]> keys *
(empty list or set)
192.168.100.10:6379 [5]> select 10
OK
192.168.100.10:6379 [10]> keys *
(empty list or set)
192.168.100.10:6379 [10]> select 0
OK
192.168.100.10:6379> keys *

  1. “k1”
  2. “xingming”
  3. “v3”
  4. “key:rand_int
  5. “xingbie”
  6. “mylist”

2)多数据库之间移动数据
192.168.100.10:6379> set w1 100
OK
192.168.100.10:6379> get w1
“100”
192.168.100.10:6379> select 1
OK
192.168.100.10:6379 [1]> get w1
(nil)
192.168.100.10:6379 [1]> select 0
OK
192.168.100.10:6379> get w1
“100”
192.168.100.10:6379> move w1 1
(integer) 1
192.168.100.10:6379> select 1
OK
192.168.100.10:6379 [1]> get w1
“100”
192.168.100.10:637979[1]> select 0
OK
192.168.100.10:6379> get w1
(nil)

3)清空数据库内所有数据
192.168.100.10:6379> FLUSHALL
OK

部署redis群集

部署第一台redis服务器

1)上传redis程序包,解压缩到/usr/src/目录
[root@centos01 ~]# ls
anaconda-ks.cfg initial-setup-ks.cfg redis-3.2.9.tar.gz
[root@centos01 ~]# tar zxvf redis-3.2.9.tar.gz -C /usr/src/

2)将redis所有配置文件剪切到/usr/src/redis/目录
[root@centos01 ~]# mv /usr/src/redis-3.2.9/ /usr/src/redis/
[root@centos01 ~]# cd /usr/src/redis/
[root@centos01 redis]# ls
00-RELEASENOTES COPYING Makefile redis.conf runtest-sentinel tests
BUGS deps MANIFESTO runtest sentinel.conf utils
CONTRIBUTING INSTALL README.md runtest-cluster src

3)编辑及安装redis
[root@centos01 redis]# make && make install

4)初始化redis
[root@centos01 redis]# cd utils/
[root@centos01 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]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
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/6379.conf => /etc/init.d/redis_6379
Installing service…
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server…
Installation successful!

5)修改redis主配置文件启动群集功能
[root@centos01 ~]# vim /etc/redis/6379.conf
62 bind 192.168.100.10
85 port 6379
129 daemonize yes
164 logfile /var/log/redis_6379.log
722 cluster-enabled yes
730 cluster-config-file nodes-6379.conf
736 cluster-node-timeout 15000
813 cluster-require-full-coverage no

6)启动redis服务,并查看6379和16379端口是否已经正常启动
[root@centos01 ~]# /etc/init.d/redis_6379 start
Starting Redis server…
[root@centos01 ~]# netstat -anptu | grep redis
tcp 0 0 192.168.100.10:6379 0.0.0.0:* LISTEN 4662/redis-server 1
tcp 0 0 192.168.100.10:16379 0.0.0.0:* LISTEN 4662/redis-server 1

7)挂载操作系统光盘,删除系统自动yum源
[root@centos01 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos01 ~]# rm -rf /etc/yum.repos.d/CentOS-*

8)安装群集所需依赖程序
[root@centos01 ~]# yum -y install ruby rubygems

9)上传准备好的gem软件包
在这里插入图片描述

10)安装gem工具
[root@centos01 ~]# ls
anaconda-ks.cfg initial-setup-ks.cfg redis-3.2.0.gem redis-3.2.9.tar.gz
[root@centos01 ~]# gem install redis --version 3.2.0

11)将redis程序包远程复制到100.20、30、40、50、60服务器的根目录
[root@centos01 ~]# scp redis-3.2.9.tar.gz root@192.168.100.20:/root
The authenticity of host ‘192.168.100.20 (192.168.100.20)’ can’t be established.
ECDSA key fingerprint is SHA256:PUueT9fU9QbsyNB5NC5hbSXzaWxxQavBxXmfoknXl4I.
ECDSA key fingerprint is MD5:6d:f7:95:0e:51:1a:d8:9e:7b:b6:3f:58:51:51:4b:3b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘192.168.100.20’ (ECDSA) to the list of known hosts.
root@192.168.100.20’s password:
redis-3.2.9.tar.gz 100% 1511KB 44.5MB/s 00:00

[root@centos01 ~]# scp redis-3.2.9.tar.gz root@192.168.100.30:/root
The authenticity of host ‘192.168.100.30 (192.168.100.30)’ can’t be established.
ECDSA key fingerprint is SHA256:PUueT9fU9QbsyNB5NC5hbSXzaWxxQavBxXmfoknXl4I.
ECDSA key fingerprint is MD5:6d:f7:95:0e:51:1a:d8:9e:7b:b6:3f:58:51:51:4b:3b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘192.168.100.30’ (ECDSA) to the list of known hosts.
root@192.168.100.30’s password:
redis-3.2.9.tar.gz 100% 1511KB 48.7MB/s 00:00

[root@centos01 ~]# scp redis-3.2.9.tar.gz root@192.168.100.40:/root
The authenticity of host ‘192.168.100.40 (192.168.100.40)’ can’t be established.
ECDSA key fingerprint is SHA256:PUueT9fU9QbsyNB5NC5hbSXzaWxxQavBxXmfoknXl4I.
ECDSA key fingerprint is MD5:6d:f7:95:0e:51:1a:d8:9e:7b:b6:3f:58:51:51:4b:3b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘192.168.100.40’ (ECDSA) to the list of known hosts.
root@192.168.100.40’s password:
redis-3.2.9.tar.gz 100% 1511KB 72.2MB/s 00:00

[root@centos01 ~]# scp redis-3.2.9.tar.gz root@192.168.100.50:/root
The authenticity of host ‘192.168.100.50 (192.168.100.50)’ can’t be established.
ECDSA key fingerprint is SHA256:PUueT9fU9QbsyNB5NC5hbSXzaWxxQavBxXmfoknXl4I.
ECDSA key fingerprint is MD5:6d:f7:95:0e:51:1a:d8:9e:7b:b6:3f:58:51:51:4b:3b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘192.168.100.50’ (ECDSA) to the list of known hosts.
root@192.168.100.50’s password:
redis-3.2.9.tar.gz 100% 1511KB 47.3MB/s 00:00

[root@centos01 ~]# scp redis-3.2.9.tar.gz root@192.168.100.60:/root
The authenticity of host ‘192.168.100.60 (192.168.100.60)’ can’t be established.
ECDSA key fingerprint is SHA256:PUueT9fU9QbsyNB5NC5hbSXzaWxxQavBxXmfoknXl4I.
ECDSA key fingerprint is MD5:6d:f7:95:0e:51:1a:d8:9e:7b:b6:3f:58:51:51:4b:3b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘192.168.100.60’ (ECDSA) to the list of known hosts.
root@192.168.100.60’s password:
redis-3.2.9.tar.gz 100% 1511KB 3.5MB/s 00:00

部署第二台redis服务器

1)挂载操作系统光盘,删除系统自动yum源
[root@centos02 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos02 ~]# rm -rf /etc/yum.repos.d/CentOS-*

2)安装redis群集所需依赖程序
[root@centos02 ~]# yum -y install ruby rubygems

3)解压缩redis程序包,剪切到/usr/src/redis/目录
[root@centos02 ~]# ls
anaconda-ks.cfg initial-setup-ks.cfg redis-3.2.9.tar.gz
[root@centos02 ~]# tar zxvf redis-3.2.9.tar.gz
[root@centos02 ~]# mv redis-3.2.9 /usr/src/redis/

4)进入redis目录,编辑及安装redis
[root@centos02 ~]# cd /usr/src/redis/
[root@centos02 redis]# make && make install

5)初始化redis
[root@centos02 redis]# cd utils/
[root@centos02 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]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
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/6379.conf => /etc/init.d/redis_6379
Installing service…
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server…
Installation successful!

6)在第一台redis服务器上将redis主配置文件远程复制到剩下五台服务器上
[root@centos01 ~]# scp /etc/redis/6379.conf root@192.168.100.20:/etc/redis/

root@192.168.100.20’s password:
6379.conf 100% 46KB 37.4MB/s 00:00
[root@centos01 ~]# scp /etc/redis/6379.conf root@192.168.100.30:/etc/redis/

root@192.168.100.30’s password:
6379.conf 100% 46KB 27.9MB/s 00:00
[root@centos01 ~]# scp /etc/redis/6379.conf root@192.168.100.40:/etc/redis/

root@192.168.100.40’s password:
6379.conf 100% 46KB 13.5MB/s 00:00
[root@centos01 ~]# scp /etc/redis/6379.conf root@192.168.100.50:/etc/redis/

root@192.168.100.50’s password:
6379.conf 100% 46KB 35.4MB/s 00:00
[root@centos01 ~]# scp /etc/redis/6379.conf root@192.168.100.60:/etc/redis/

root@192.168.100.60’s password:
6379.conf 100% 46KB 44.7MB/s 00:00

7)第二台redis服务器修改主配置文件监听的IP地址
[root@centos02 ~]# vim /etc/redis/6379.conf
bind 192.168.100.20

8)启动redis服务,监听redis服务是否正常启动
[root@centos02 ~]# redis-server /etc/redis/6379.conf
[root@centos02 ~]# netstat -anptu | grep redis
tcp 0 0 192.168.100.20:6379 0.0.0.0:* LISTEN 6224/redis-server 1
tcp 0 0 192.168.100.20:16379 0.0.0.0:* LISTEN 6224/redis-server 1

剩下四台安装第二台的操作步骤做同样的配置即可,修改主配置文件监听的IP地址设置成服务器自己的IP地址即可

使用脚本创建群集

1)在第一台redis服务器上使用脚本创建群集
[root@centos01 ~]# /usr/src/redis/src/redis-trib.rb create --replicas 1 192.168.100.10:6379 192.168.100.20:6379 192.168.100.30:6379 192.168.100.40:6379 192.168.100.50:6379 192.168.100.60:6379

Creating cluster
Performing hash slots allocation on 6 nodes…
Using 3 masters:
192.168.100.10:6379
192.168.100.20:6379
192.168.100.30:6379
Adding replica 192.168.100.40:6379 to 192.168.100.10:6379
Adding replica 192.168.100.50:6379 to 192.168.100.20:6379
Adding replica 192.168.100.60:6379 to 192.168.100.30:6379
M: 53a7082afe52d1216a447bd505f1828e8c04c7b6 192.168.100.10:6379
slots:0-5460 (5461 slots) master
M: 7023c518c9bde44e137db167abcaf3ef6302ef5c 192.168.100.20:6379
slots:5461-10922 (5462 slots) master
M: 82196443876dd7a7dba2cbda237064577e6996e5 192.168.100.30:6379
slots:10923-16383 (5461 slots) master
S: b86a7228dc45da696a9e95f6593cf28e9d350643 192.168.100.40:6379
replicates 53a7082afe52d1216a447bd505f1828e8c04c7b6
S: 2ef78b8d7e4174c7cb8ff6c9c7834e8e0e97e6fc 192.168.100.50:6379
replicates 7023c518c9bde44e137db167abcaf3ef6302ef5c
S: 161c231d36b342103ff1524d027e131e66da06ef 192.168.100.60:6379
replicates 82196443876dd7a7dba2cbda237064577e6996e5
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.100.10:6379)
M: 53a7082afe52d1216a447bd505f1828e8c04c7b6 192.168.100.10:6379
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 7023c518c9bde44e137db167abcaf3ef6302ef5c 192.168.100.20:6379
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: b86a7228dc45da696a9e95f6593cf28e9d350643 192.168.100.40:6379
slots: (0 slots) slave
replicates 53a7082afe52d1216a447bd505f1828e8c04c7b6
M: 82196443876dd7a7dba2cbda237064577e6996e5 192.168.100.30:6379
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 161c231d36b342103ff1524d027e131e66da06ef 192.168.100.60:6379
slots: (0 slots) slave
replicates 82196443876dd7a7dba2cbda237064577e6996e5
S: 2ef78b8d7e4174c7cb8ff6c9c7834e8e0e97e6fc 192.168.100.50:6379
slots: (0 slots) slave
replicates 7023c518c9bde44e137db167abcaf3ef6302ef5c
[OK] All nodes agree about slots configuration.

Check for open slots…
Check slots coverage…
[OK] All 16384 slots covered.

2)查看群集状态
[root@centos01 ~]# cd /usr/src/redis/src/
[root@centos01 src]# ./redis-trib.rb check 192.168.100.10:6379

Performing Cluster Check (using node 192.168.100.10:6379)
M: 53a7082afe52d1216a447bd505f1828e8c04c7b6 192.168.100.10:6379
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 7023c518c9bde44e137db167abcaf3ef6302ef5c 192.168.100.20:6379
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: b86a7228dc45da696a9e95f6593cf28e9d350643 192.168.100.40:6379
slots: (0 slots) slave
replicates 53a7082afe52d1216a447bd505f1828e8c04c7b6
M: 82196443876dd7a7dba2cbda237064577e6996e5 192.168.100.30:6379
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 161c231d36b342103ff1524d027e131e66da06ef 192.168.100.60:6379
slots: (0 slots) slave
replicates 82196443876dd7a7dba2cbda237064577e6996e5
S: 2ef78b8d7e4174c7cb8ff6c9c7834e8e0e97e6fc 192.168.100.50:6379
slots: (0 slots) slave
replicates 7023c518c9bde44e137db167abcaf3ef6302ef5c
[OK] All nodes agree about slots configuration.

Check for open slots…
Check slots coverage…
[OK] All 16384 slots covered.

3)测试群集

[root@centos01 ~]# redis-cli -h 192.168.100.10 -p 6379 -c
192.168.100.10:6379> set centos 7.4
OK
192.168.100.10:6379> get centos
“7.4”
192.168.100.10:6379> quit
[root@centos01 ~]# redis-cli -h 192.168.100.40 -p 6379 -c
192.168.100.40:6379> get centos
-> Redirected to slot [467] located at 192.168.100.10:6379
“7.4”
192.168.100.10:6379> quit
[root@centos01 ~]# redis-cli -h 192.168.100.60 -p 6379 -c
192.168.100.60:6379> get centos
-> Redirected to slot [467] located at 192.168.100.10:6379
“7.4”
192.168.100.10:6379> quit

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值