redis-cluster搭建

2016-12-05 09:40:59来源:oschina作者:starhq人点击

#安装redis和一些要用到的工具 yum -y install gcc automake autoconf libtool make wget tcl zlib ruby rubygems gem sources --add /2014th7cj/d/file/p/20161205/tmpafv5glgr --remove /2014th7cj/d/file/p/20161205/i4ovg5tnbzy gem sources -u gem install redis wget /2014th7cj/d/file/p/20161205/wvxgfb1lifq.gz 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 #GENERALdaemonize notcp-backlog 511timeout 0tcp-keepalive 0loglevel noticedatabases 16dir /opt/redis/dataslave-serve-stale-data yes#slave只读slave-read-only yes#not use defaultrepl-disable-tcp-nodelay yesslave-priority 100#打开aof持久化appendonly yes#每秒一次aof写appendfsync everysec#关闭在aof rewrite的时候对新的写操作进行fsyncno-appendfsync-on-rewrite yesauto-aof-rewrite-min-size 64mblua-time-limit 5000#打开redis集群cluster-enabled yes#节点互连超时的阀值cluster-node-timeout 15000cluster-migration-barrier 1slowlog-log-slower-than 10000slowlog-max-len 128notify-keyspace-events ""hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-entries 512list-max-ziplist-value 64set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-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 operationsmaxmemory-policy allkeys-lru#aof存储文件appendfilename "appendonly-6379.aof"#rdb文件,只用于动态添加slave过程dbfilename dump-6379.rdb#cluster配置文件(启动自动生成)cluster-config-file nodes-6379.conf#部署在同一机器的redis实例,把auto-aof-rewrite搓开,防止瞬间fork所有redis进程做rewrite,占用大量内存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


/2014th7cj/d/file/p/20161205/1q3vyl05sml

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台