@有缘人,送你一套Linux搭建redis集群宝典

1、下载redis的安装包,我用的是:redis-4.0.10.tar.gz

[root@softsec90 redis]# wget http://download.redis.io/releases/redis-4.0.10.tar.gz

2、解压redis-4.0.10.tar.gz包

[root@Centos6 redis]# tar -zxvf redis-4.0.10.tar.gz

3、编译

[root@Centos6 redis]# cd redis-4.0.10
[root@Centos6 redis-4.0.10]# make
[root@Centos6 redis-4.0.10]# make INSTALL

4、在redis目录下,新建redis-cluster目录

[root@softsec90 redis]# mkdir redis-cluster

5、在redis-cluster目录下新建7001 7002 7003 7004 7005 7006集群节点目录

[root@softsec90 redis-cluster]# mkdir 7001 7002 7003 7004 7005 7006

6、将/home/local/redis/redis-4.0.10下的redis.conf文件复制到7001节点目录下,并修改redis.conf配置文件

[root@softsec90 redis-4.0.10]# cp redis.conf /home/local/redis/redis-cluster/7001
[root@softsec90 7001]# vim redis.conf 

redis.conf文件主要修改如下:

port  7001                                   //端口7001 7002 7003 7004 7005 7006       

bind 本机ip                                  //改为其他节点机器可访问的ip 例如192.168.xxx.xx

daemonize    yes                            //redis后台运行

appendonly  yes                             //aof日志开启

pidfile  /var/run/redis_7001.pid            //pidfile文件对应7001 7002 7003 7004 7005... 

cluster-enabled  yes                        //开启集群  

cluster-config-file  nodes_7001.conf        //集群的配置 配置文件首次启动自动生成7001 7002.. 

cluster-node-timeout  15000                 //请求超时  默认15秒,可自行修改

7、再将redis.conf文件复制到其他7002 7003 7004 7005 7006节点下,替换对应节点的端口号即可。

8、启动6个节点,先将/home/local/redis/redis-4.0.10/src下的redis-server文件复制到/usr/bin下

[root@softsec90 src]# cp redis-server /usr/bin/

[root@softsec90 redis]# redis-server redis-cluster/7001/redis.conf

[root@softsec90 redis]# redis-server redis-cluster/7002/redis.conf

[root@softsec90 redis]# redis-server redis-cluster/7003/redis.conf

[root@softsec90 redis]# redis-server redis-cluster/7004/redis.conf

[root@softsec90 redis]# redis-server redis-cluster/7005/redis.conf

[root@softsec90 redis]# redis-server redis-cluster/7006/redis.conf

9、查看各个节点启动是否启动成功

[root@softsec90 redis]# ps -aux | grep redis

 

10、安装ruby环境

[root@softsec90 redis]# yum install ruby
[root@softsec90 redis]# yum install rubygems
[root@softsec90 redis]# gem install redis --version 3.0.0

11、创建集群,先将/home/local/redis/redis-4.0.10/src下redis-trib.rb文件复制到/usr/bin下

[root@softsec90 src]# cp redis-trib.rb  /usr/bin/
[root@softsec90 redis-cluster]# redis-trib.rb  create --replicas 1 192.168.101.90:7001 192.168.101.90:7002 192.168.101.90:7003 192.168.101.90:7004 192.168.101.90:7005 192.168.101.90:7006

至此,redis创建成功。

发布了79 篇原创文章 · 获赞 229 · 访问量 13万+

猜你喜欢

转载自blog.csdn.net/qq_39390545/article/details/104887537