配置域名
192.168.241.101 paascloud-redis-001
192.168.241.102 paascloud-redis-002
192.168.241.103 paascloud-redis-003
下载
wget http://download.redis.io/releases/redis-4.0.8.tar.gz
解压
# tar -zxvf redis-4.0.8.tar.gz -C /usr/local
# mv redis-4.0.8 redis
创建集群配置文件夹
# mkdir -p /usr/local/redis/cluster-conf/7001
# mkdir -p /usr/local/redis/cluster-conf/7002
# cp /usr/local/redis/redis.conf /usr/local/redis/cluster-conf/7001
# cp /usr/local/redis/redis.conf /usr/local/redis/cluster-conf/7002
修改集群配置
vim /usr/local/redis/cluster-conf/7001/redis.conf
port 7001
daemonize yes
/var/run/redis-7001.pid
logfile "/usr/local/redis/cluster-conf/7001/redis.log"
dir /usr/local/redis/cluster-conf/7002/
cluster-enabled yes
cluster-config-file /usr/local/redis/cluster-conf/7001/nodes.conf
cluster-node-timeout 15000
appendonly yes
bind 0.0.0.0
vim /usr/local/redis/cluster-conf/7002/redis.conf
port 7002
daemonize yes
pidfile /var/run/redis-7002.pid
logfile "/usr/local/redis/cluster-conf/7002/redis.log"
dir /usr/local/redis/cluster-conf/7002/
cluster-enabled yes
cluster-config-file /usr/local/redis/cluster-conf/7002/nodes.conf
cluster-node-timeout 15000
appendonly yes
bind 0.0.0.0
远程拷贝redis
scp -r /usr/local/redis/ root@192.168.241.102:/usr/local/
scp -r /usr/local/redis/ root@192.168.241.103:/usr/local/
安装依赖
yum install -y gcc tcl ruby rubygems
安装redis
make install PREFIX=/usr/local/redis
错误
- redis编译报致命错误:jemalloc/jemalloc.h:没有那个文件或目录
make MALLOC=libc
- redis requires Ruby version >= 2.2.2的报错
http://blog.csdn.net/liu_zhaoming/article/details/79354420
启动服务
/usr/local/redis/bin/redis-server /usr/local/redis/cluster-conf/7001/redis.conf &
/usr/local/redis/bin/redis-server /usr/local/redis/cluster-conf/7002/redis.conf &
gem 安装 redis ruby 接口
# gem install redis
创建集群
# /usr/local/redis/src/redis-trib.rb create --replicas 1 192.168.241.101:7001 192.168.241.102:7001 192.168.241.103:7001 192.168.241.101:7002 192.168.241.102:7002 192.168.241.103:7002
查看节点信息
# /usr/loca/redis/bin/redis-cli -c -p 7001
127.0.0.1:7001> cluster nodes
配置选项 | 选项值 | 说明 |
---|---|---|
daemonize | yes | 是否作为守护进程运行 |
pidfile | /var/run/redis-7001.pid | 如以后台进程运行,则需指定一个pid 默认为/var/run/redis.pid |
port | 7001 | 监听端口,默认为6379注意:集群通讯端口值默认为此端口值+10000,如17111 |
cluster-config-file | /usr/local/redis/cluster-conf/7001/nodes.conf | 集群配置文件(启动自动生成),不用人为干涉 |
cluster-node-timeout | 15000 | 节点互连超时时间。毫秒 |
appendonly | yes | 启用aof持久化方式 |
dir | yes | 打开redis集群 |
cluster-enabled | /usr/local/redis/cluster-conf/7001 | 节点数据持久化存放目录 |