redis集群的搭建

[[email protected] redis]# cd /user/local
[[email protected] local]# mkdir redis-cluster
[[email protected] local]# cd redis

[[email protected] redis]# cp -r bin ../redis-cluster/redis01
[[email protected] redis]# cd ../redis-cluster/
[[email protected] redis-cluster]# ll
总用量 4
drwxr-xr-x. 2 root root 4096 3月  25 11:17 redis01
[[email protected] redis-cluster]# cd redis01/
[[email protected] redis01]# ll
总用量 15528
-rw-r--r--. 1 root root      25 3月  25 11:17 dump.rdb
-rw-r--r--. 1 root root       0 3月  25 11:17 redis
-rwxr-xr-x. 1 root root 4587142 3月  25 11:17 redis-benchmark
-rwxr-xr-x. 1 root root   22225 3月  25 11:17 redis-check-aof
-rwxr-xr-x. 1 root root   45443 3月  25 11:17 redis-check-dump
-rwxr-xr-x. 1 root root 4690041 3月  25 11:17 redis-cli
-rw-r--r--. 1 root root   41404 3月  25 11:17 redis.conf
-rw-r--r--. 1 root root   41403 3月  25 11:17 redis.conf~
lrwxrwxrwx. 1 root root      12 3月  25 11:17 redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root 6448193 3月  25 11:17 redis-server

redis集群的搭建

 

2.

第一步:创建6个redis实例,端口号从7001~7006

第二步:修改redis的配置文件

1、修改端口号

第一步:创建6个redis实例,端口号从7001~7006

第二步:修改redis的配置文件

[[email protected] redis01]# vim redis.conf

redis集群的搭建

3.复制6个节点

[[email protected] redis-cluster]# cp -r redis01/ redis02

redis集群的搭建

4.依次改剩下5个节点的端口号7002-7006

[[email protected] redis-cluster]# vim redis02/redis.conf

redis集群的搭建

5.把创建集群的ruby脚本复制到redis-cluster目录下。

[[email protected] /]# cd /usr/local/redis-3.0.0
[[email protected] redis-3.0.0]# cd src
[[email protected] src]# cp *.rb /usr/local/redis-cluster/
redis集群的搭建

6.启动6个redis实例

[[email protected] redis-cluster]# vim startall.sh

进入后复制6个节点

cd redis02
./redis-server redis.conf
cd ..

redis集群的搭建

[[email protected] redis-cluster]# vim startall.sh
[[email protected] redis-cluster]# chmod +x startall.sh
[[email protected] redis-cluster]# ./startall.sh
[[email protected] redis-cluster]# ps aux|grep redis
redis集群的搭建

7.创建集群。

[[email protected] redis-cluster]# ./redis-trib.rb create --replicas 1 192.168.0.23:7001 192.168.0.23:7002 192.168.0.23:7003 192.168.0.23:7004 192.168.0.23:7005  192.168.0.23:7006

其中192.168.0.23是linux的ip地址。

redis集群的搭建redis集群的搭建

8.测试集群

[[email protected] redis-cluster]# redis01/redis-cli -h 192.168.0.23 -p 7002 -c

结果如上图所示。

9.关闭集群

1)在/usr/local/redis下:普通命令关闭

redis集群的搭建

redis集群的搭建

2)写个脚本shutdown.sh来关:
[[email protected] redis-cluster]# vim shutdown.sh
[[email protected] redis-cluster]# chmod +x shutdown.sh
[[email protected] redis-cluster]# ./shutdown.sh
[[email protected] redis-cluster]# ps aux|grep redis

其中shutdown.sh内容:redis01/redis-cli -p 7001 shutdown

redis集群的搭建

关闭结果,7001-7006端口全部关闭:

redis集群的搭建

以后关闭直接用命令: ./shutdown

开启: ./startall.sh