一、简介
二、生产集群搭建
准备
- Linux服务器三台(三主三从)
下载
准备好Redis源码包,官网下载地址
解压
#如果可以连接网络可以使用命令下载 wget http://download.redis.io/releases/redis-6.7.0.tar.gz
tar -xvf redis-6.0.7.tar.gz -C /usr/local/redis/
[root@localhost redis]# ls
redis-6.0.7 redis-6.0.7.tar.gz
解压后目录如下
[root@localhost redis]# cd redis-6.0.7/
[root@localhost redis-6.0.7]# ll
total 272
-rw-rw-r--. 1 root root 91880 Sep 1 06:27 00-RELEASENOTES
-rw-rw-r--. 1 root root 51 Sep 1 06:27 BUGS
-rw-rw-r--. 1 root root 2381 Sep 1 06:27 CONTRIBUTING
-rw-rw-r--. 1 root root 1487 Sep 1 06:27 COPYING
-rw-rw-r--. 1 root root 11 Sep 1 06:27 INSTALL
-rw-rw-r--. 1 root root 6888 Sep 1 06:27 MANIFESTO
-rw-rw-r--. 1 root root 151 Sep 1 06:27 Makefile
-rw-rw-r--. 1 root root 21010 Sep 1 06:27 README.md
-rw-rw-r--. 1 root root 3055 Sep 1 06:27 TLS.md
drwxrwxr-x. 6 root root 124 Sep 1 06:27 deps
-rw-rw-r--. 1 root root 84642 Sep 1 06:27 redis.conf
-rwxrwxr-x. 1 root root 275 Sep 1 06:27 runtest
-rwxrwxr-x. 1 root root 280 Sep 1 06:27 runtest-cluster
-rwxrwxr-x. 1 root root 721 Sep 1 06:27 runtest-moduleapi
-rwxrwxr-x. 1 root root 281 Sep 1 06:27 runtest-sentinel
-rw-rw-r--. 1 root root 10743 Sep 1 06:27 sentinel.conf
drwxrwxr-x. 3 root root 4096 Sep 1 06:27 src
drwxrwxr-x. 11 root root 182 Sep 1 06:27 tests
drwxrwxr-x. 9 root root 4096 Sep 1 06:27 utils
编译
cd redis-6.0.7/
make
编译成功
Hint: It's a good idea to run 'make test' ;)
make[1]: Leaving directory `/usr/local/redis/redis-6.0.7/src'
成功会在src目录下创建可执行文件, 如下:
redis-benchmark
redis-check-aof
redis-check-rdb
redis-cli
redis-sentinel
redis-server
redis-trib.rb
安装
cd redis-6.0.7/
make install
安装成功
cd src && make install
make[1]: Entering directory `/usr/local/redis/redis-6.0.7/src'
Hint: It's a good idea to run 'make test' ;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
make[1]: Leaving directory `/usr/local/redis/redis-6.0.7/src'
创建集群配置目录
# 规划好自己的安装目录
mkdir -p /usr/local/redis/cluster
cd /usr/local/redis/cluster
mkdir 7000 7001 7002 7003 7004 7005
修改配置文件
cp ../redis-6.0.7/redis.conf ./7000/
cd 7000/
mv redis.conf 7000.conf
vim 7000.conf
port 7000:指定当前Redis服务的端口,默认为6379
daemonize yes:配置redis作为守护进程运行
cluster-enabled yes:开启集群功能
bind 10.252.21.154 127.0.0.1:绑定本地回环地址
appendonly yes:配置数据持久化 aof模式
pidfile /usr/local/redis/cluster/7000/redis_7000.pid: 修改pid位置
logfile "redis_7000.log" : 日志文件名
dir /usr/local/redis/cluster/7000/:数据存储位置
按照以上修改所有配置文件,注意不同IP和端口,配置文件放在不同目录下。
启动Redis
cd /usr/local/redis/cluster/
redis-server 7000/7000.conf
redis-server 7001/7001.conf
redis-server 7002/7002.conf
redis-server 7003/7003.conf
redis-server 7004/7004.conf
redis-server 7005/7005.conf
启动成功
[root@localhost cluster]# ps -ef |grep redis
root 3282 1 0 02:46 ? 00:00:00 redis-server 127.0.0.1:7000
root 3293 1 0 02:47 ? 00:00:00 redis-server 127.0.0.1:7001
root 3303 1 0 02:48 ? 00:00:00 redis-server 127.0.0.1:7002
root 3310 1 0 02:48 ? 00:00:00 redis-server 127.0.0.1:7003
root 3317 1 0 02:48 ? 00:00:00 redis-server 127.0.0.1:7004
root 3322 1 0 02:48 ? 00:00:00 redis-server 127.0.0.1:7005
root 3333 2522 0 02:49 pts/0 00:00:00 grep --color=auto redis
RedisCluster搭建
redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 --cluster-replicas 1
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 127.0.0.1:7004 to 127.0.0.1:7000
Adding replica 127.0.0.1:7005 to 127.0.0.1:7001
Adding replica 127.0.0.1:7003 to 127.0.0.1:7002
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: ca740ec583a2c7e876aec63854089c1ec71318d4 127.0.0.1:7000
slots:[0-5460] (5461 slots) master
M: 2960b8b2af9ab5e304bc9b2136f0f60e21888f0f 127.0.0.1:7001
slots:[5461-10922] (5462 slots) master
M: 746587bbb2b392f73925a1eb18b4989810084936 127.0.0.1:7002
slots:[10923-16383] (5461 slots) master
S: 7c49edb0b958a28d9ac23dd073faf74833de1e61 127.0.0.1:7003
replicates ca740ec583a2c7e876aec63854089c1ec71318d4
S: 264965aff3c7469617b36db38818711fddc15eec 127.0.0.1:7004
replicates 2960b8b2af9ab5e304bc9b2136f0f60e21888f0f
S: 7cfd6dd5c88942bbe44110ec898d4c731af58ae8 127.0.0.1:7005
replicates 746587bbb2b392f73925a1eb18b4989810084936
Can I set the above configuration? (type 'yes' to accept): yes
输入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 127.0.0.1:7000)
M: ca740ec583a2c7e876aec63854089c1ec71318d4 127.0.0.1:7000
slots:[0-5460] (5461 slots) master
1 additional replica(s)
S: 264965aff3c7469617b36db38818711fddc15eec 127.0.0.1:7004
slots: (0 slots) slave
replicates 2960b8b2af9ab5e304bc9b2136f0f60e21888f0f
M: 2960b8b2af9ab5e304bc9b2136f0f60e21888f0f 127.0.0.1:7001
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
M: 746587bbb2b392f73925a1eb18b4989810084936 127.0.0.1:7002
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
S: 7cfd6dd5c88942bbe44110ec898d4c731af58ae8 127.0.0.1:7005
slots: (0 slots) slave
replicates 746587bbb2b392f73925a1eb18b4989810084936
S: 7c49edb0b958a28d9ac23dd073faf74833de1e61 127.0.0.1:7003
slots: (0 slots) slave
replicates ca740ec583a2c7e876aec63854089c1ec71318d4
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
至此集群搭建成功!!!
查看集群信息
redis-cli --cluster info 127.0.0.1:7000
127.0.0.1:7000 (ca740ec5...) -> 0 keys | 5461 slots | 1 slaves.
127.0.0.1:7001 (2960b8b2...) -> 0 keys | 5462 slots | 1 slaves.
127.0.0.1:7002 (746587bb...) -> 0 keys | 5461 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.
检查集群
redis-cli --cluster check 127.0.0.1:7000
127.0.0.1:7000 (ca740ec5...) -> 0 keys | 5461 slots | 1 slaves.
127.0.0.1:7001 (2960b8b2...) -> 0 keys | 5462 slots | 1 slaves.
127.0.0.1:7002 (746587bb...) -> 0 keys | 5461 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 127.0.0.1:7000)
M: ca740ec583a2c7e876aec63854089c1ec71318d4 127.0.0.1:7000
slots:[0-5460] (5461 slots) master
1 additional replica(s)
S: 264965aff3c7469617b36db38818711fddc15eec 127.0.0.1:7004
slots: (0 slots) slave
replicates 2960b8b2af9ab5e304bc9b2136f0f60e21888f0f
M: 2960b8b2af9ab5e304bc9b2136f0f60e21888f0f 127.0.0.1:7001
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
M: 746587bbb2b392f73925a1eb18b4989810084936 127.0.0.1:7002
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
S: 7cfd6dd5c88942bbe44110ec898d4c731af58ae8 127.0.0.1:7005
slots: (0 slots) slave
replicates 746587bbb2b392f73925a1eb18b4989810084936
S: 7c49edb0b958a28d9ac23dd073faf74833de1e61 127.0.0.1:7003
slots: (0 slots) slave
replicates ca740ec583a2c7e876aec63854089c1ec71318d4
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
网友评论