redis-cluster搭建

旧城冷巷雨未停 提交于 2020-12-19 16:46:00

#安装redis和一些要用到的工具
yum -y install gcc automake autoconf libtool make wget tcl zlib ruby rubygems
gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
gem sources -u
gem install redis

cd /usr/local
wget http://download.redis.io/releases/redis-stable.tar.gz

tar zxvf redis-stable.tar.gz

cd redis-stable
make
make install
cd utils
./install_server.sh 

#修改配置文件目录在/etc/redis下
vi 6379.conf
port=6379
pidfile /var/run/redis_6379.pid
logfile /var/log/redis_6379.log
daemonize=yes
cluster-enabled yes
cluster-config-file nodes-6379.conf
cluster-node-timeout 15000
appendonly yes
dir /var/lib/redis/6379

#redis-common.conf
#GENERAL  
daemonize no  
tcp-backlog 511  
timeout 0  
tcp-keepalive 0  
loglevel notice  
databases 16  
dir /opt/redis/data  
slave-serve-stale-data yes  
#slave只读  
slave-read-only yes  
#not use default  
repl-disable-tcp-nodelay yes  
slave-priority 100  
#打开aof持久化  
appendonly yes  
#每秒一次aof写  
appendfsync everysec  
#关闭在aof rewrite的时候对新的写操作进行fsync  
no-appendfsync-on-rewrite yes  
auto-aof-rewrite-min-size 64mb  
lua-time-limit 5000  
#打开redis集群  
cluster-enabled yes  
#节点互连超时的阀值  
cluster-node-timeout 15000  
cluster-migration-barrier 1  
slowlog-log-slower-than 10000  
slowlog-max-len 128  
notify-keyspace-events ""  
hash-max-ziplist-entries 512  
hash-max-ziplist-value 64  
list-max-ziplist-entries 512  
list-max-ziplist-value 64  
set-max-intset-entries 512  
zset-max-ziplist-entries 128  
zset-max-ziplist-value 64  
activerehashing yes  
client-output-buffer-limit normal 0 0 0  
client-output-buffer-limit slave 256mb 64mb 60  
client-output-buffer-limit pubsub 32mb 8mb 60  
hz 10  
aof-rewrite-incremental-fsync yes 


redis-ip.conf
#包含通用配置  
include /opt/redis/redis-common.conf  
#监听tcp端口  
port 6379  
#最大可用内存  
maxmemory 100m  
#内存耗尽时采用的淘汰策略:  
# volatile-lru -> remove the key with an expire set using an LRU algorithm  
# allkeys-lru -> remove any key accordingly to the LRU algorithm  
# volatile-random -> remove a random key with an expire set  
# allkeys-random -> remove a random key, any key  
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)  
# noeviction -> don't expire at all, just return an error on write operations  
maxmemory-policy allkeys-lru  
#aof存储文件  
appendfilename "appendonly-6379.aof"  
#rdb文件,只用于动态添加slave过程  
dbfilename dump-6379.rdb  
#cluster配置文件(启动自动生成)  
cluster-config-file nodes-6379.conf  
#部署在同一机器的redis实例,把<span style="font-size: 1em; line-height: 1.5;">auto-aof-rewrite搓开,防止瞬间fork所有redis进程做rewrite,占用大量内存</span>  
auto-aof-rewrite-percentage 80-100 


#创建数据文件目录
mkdir -p /var/lib/redis/6380 /var/lib/redis/6381 /var/lib/redis/6382 /var/lib/redis/6383 /var/lib/redis/6384 /var/lib/redis/6385

#查看服务是否启动
ps -ef | grep redis

#创建集群
redis-trib.rb create --replicas 1 127.0.0.1:6379 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

#检查集群状况
redis-trib.rb check 127.0.0.1:6379

#添加master节点
redis-trib.rb add-node 192.168.3.61:6379 192.168.3.88:6379

#添加slave节点
redis-trib.rb add-node 192.168.3.61:7379 192.168.3.88:6379
redis-cli -c -h 192.168.3.61 -p 7379
cluster replicate 89be535ff56586dcec56f14122add80d89a57bb3


#数据分片
redis-trib.rb reshard 192.168.3.6379


#删除节点
redis-trib.rb del-node 192.168.3.88:6399 d64223d6695fcc7e1030f219f09d7488c438cf39


http://blog.sina.com.cn/s/blog_75ad98f30102w6po.html

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!