搭建单机版:
解压
tar -zxf redis-3.0.0.tar.gz
编译
cd redis-3.0.0
安装
make install prefix=/usr/local/redis-install
后台启动服务
将解压后的redis文件夹中redis.conf文件拷贝到redis-install/bin目录下
修改redis.conf文件中:daemonize yes 含义允许后台启动
./redis-server redis.conf
前台启动客户端
./redis-cli -p 6379
搭建集群版:
将redis解压src目录下redis-trib.rb 文件复制到安装目录/usr/local/redis-install/下
cp /home/tools/redis-3.0.0/src/redis-trib.rb /usr/local/redis-install/redis-cluster/
计划设定7001 -7006个redis 其中7001-7003时主机,7004-7006时从机,对应关系分别是1/4 2/5 3/6
cp bin redis-cluster/7001 -r
删除7001里现有的持久化文件(aof\rdb\nodes.conf)
修改7001里redis.conf的配置文件,修改点:
端口号、cluster-enable开关
分别复制出7002-7006台机器
[root@localhost redis-cluster]# cp 7001/ 7002 -r
[root@localhost redis-cluster]# cp 7001/ 7003 -r
[root@localhost redis-cluster]# cp 7001/ 7004 -r
[root@localhost redis-cluster]# cp 7001/ 7005 -r
[root@localhost redis-cluster]# cp 7001/ 7006 -r
修改端口
[root@localhost 7002]# vim /usr/local/redis-install/redis-cluster/7002/redis.conf
[root@localhost 7002]# vim /usr/local/redis-install/redis-cluster/7003/redis.conf
[root@localhost 7002]# vim /usr/local/redis-install/redis-cluster/7004/redis.conf
[root@localhost 7002]# vim /usr/local/redis-install/redis-cluster/7005/redis.conf
[root@localhost 7002]# vim /usr/local/redis-install/redis-cluster/7006/redis.conf
编写start-all.sh 启动7001-7006的redis
cd 7001
./redis-server redis.conf
cd ../7002
./redis-server redis.conf
cd ../7003
./redis-server redis.conf
cd ../7004
./redis-server redis.conf
cd ../7005
./redis-server redis.conf
cd ../7006
./redis-server redis.conf
gei start-all.sh文件赋启动权限
chmod u+x start-all.sh
统一启动:
./start-all.sh
安装ruby,使用ruby搭建集群
yum install ruby
yum install rubygems
Linux中安装接口
gem install redis-3.0.0.gem
创建集群:3主3从
./redis-trib.rb create --replicas 1 192.168.160.129:7001 192.168.160.129:7002 192.168.160.129:7003 192.168.160.129:7004 192.168.160.129:7005 192.168.160.129:7006
集群搭建完成测试:
随便启动一个redis node
127.0.0.1:7001>./redis-cli -h 127.0.0.1 -p 7001
127.0.0.1:7001> set s1 111
-> Redirected to slot [15224] located at 127.0.0.1:7003
OK
完美
查看集群信息
cluster info
查看集群节点
cluster nodes
Best Regards