下载:
wget http://download.redis.io/releases/redis-4.0.10.tar.gz
编译安装:
安装gcc:
yum install gcc
编译:
make
make install
报错:
zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory
zmalloc.h:55:2: error: #error "Newer version of jemalloc required"
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/data0/src/redis-2.6.2/src'
make: *** [all] Error 2
解决方法:
make MALLOC=libc
You need tcl 8.5 or newer in order to run the Redis test”
解决方法:
yum install tcl
配置:
安装成功后可以在/usr/local/bin下看到相关文件
使用
redis-server
可以启动redis服务(单机)
集群配置:
将redis编译后redis的src目录下的redis-trib.rb拷贝到/usr/local/bin
在/usr/local/bin下:
mkdir redis-cluster
mkdir redis-logs
切换到/usr/local/bin/redis-cluster目录下,为每个redis服务编写配置文件:
port 6380
loglevel notice
daemonize yes
logfile "/usr/local/bin/redis-logs/redis6380_log.txt"
appendonly yes
appendfilename "appendonly.6380.aof"
pidfile /usr/local/bin/redis.6380.pid
protected-mode no
cluster-enabled yes
cluster-config-file nodes.6380.conf
cluster-node-timeout 15000
cluster-slave-validity-factor 10
cluster-migration-barrier 1
cluster-require-full-coverage yes
其余的只需把6380该文相应的638X即可
为方便启动和停止redis进程,编写脚本:
start.sh
redis-server /usr/local/bin/redis-cluster/redis-6380.conf
redis-server /usr/local/bin/redis-cluster/redis-6381.conf
redis-server /usr/local/bin/redis-cluster/redis-6382.conf
redis-server /usr/local/bin/redis-cluster/redis-6383.conf
redis-server /usr/local/bin/redis-cluster/redis-6384.conf
redis-server /usr/local/bin/redis-cluster/redis-6385.conf
stop.sh
redis-cli -p 6380 shutdown
redis-cli -p 6381 shutdown
redis-cli -p 6382 shutdown
redis-cli -p 6383 shutdown
redis-cli -p 6384 shutdown
redis-cli -p 6385 shutdown
安装ruby:
yum -y install ruby ruby-devel rubygems rpm-build
下载驱动:
下载地址:https://rubygems.org/gems/redis/versions/3.2
安装驱动:
gem install redis-3.2.2.gem
启动集群:
redis-trib.rb create --replicas 1 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 127.0.0.1:6385
出现错误:[ERR] Node 127.0.0.1:6380 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.
解决方法:
清理redis-cluster文件夹下的*.aof文件和node*文件