redis 集群部署
redis 集群部署
snail_lzq 发表于9个月前
redis 集群部署
  • 发表于 9个月前
  • 阅读 7
  • 收藏 0
  • 点赞 0
  • 评论 0

华为云·免费上云实践>>>   

  1. 下载安装zlib
wget http://www.zlib.net/zlib-1.2.8.tar.gz
mkdir /usr/local/zlib
tar -zxvf zlib-1.2.8.tar.gz -C /usr/local/zlib/
cd /usr/local/zlib/zlib-1.2.8/
./configure
make
make install
  1. 下载安装ruby
wget https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.gz
mkdir /usr/local/ruby
tar -zxvf ruby-2.3.1.tar.gz -C /usr/local/ruby/
cd /usr/local/ruby/ruby-2.3.1/
./configure -prefix=/usr/local/ruby
make
make install
cp ruby /usr/local/bin
  1. 安装gem
wget https://rubygems.global.ssl.fastly.net/rubygems/rubygems-2.6.4.tgz
wget http://rubygems.global.ssl.fastly.net/rubygems/rubygems-2.6.4.tgz
mkdir /usr/local/gem
tar -zxvf rubygems-2.6.4.tgz -C /usr/local/gem
cd /usr/local/gem/rubygems-2.6.4/
ruby setup.rb
cp bin/gem /usr/local/bin
  1. 安装redis插件
gem install redis --version 3.2.1
gem source -a http://rubygems.org/
gem source -r https://rubygems.org/
gem install redis --version 3.2.1
  1. 安装redis
wget http://download.redis.io/releases/redis-3.2.1.tar.gz
mkdir /usr/local/redis
tar -zxvf redis-3.2.1.tar.gz -C /usr/local/redis/
cd /usr/local/redis/redis-3.2.1/
make
cp src/redis-server /usr/local/bin
cp src/redis-cli /usr/local/bin
cp src/redis-trib.rb /usr/local/bin
  1. 配置配置文件
vim redis-6379.conf
#包含通用配置
include /usr/local/redis/conf/redis-common.conf
#监听tcp端口
port 6379
#最大可用内存
maxmemory 3072m
#内存耗尽时采用的淘汰策略:
# 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 noeviction
#aof存储文件
appendfilename "appendonly-c1.aof"
#rdb文件,只用于动态添加slave过程
dbfilename dump-6379.rdb
#cluster配置文件(启动自动生成)
cluster-config-file nodes-c1.conf
#部署在同一机器的redis实例,把<span style="font-size: 1em; line-height: 1.5;">auto-aof-rewrite搓开>,防止瞬间fork所有redis进程做rewrite,占用大量内存</span>
auto-aof-rewrite-percentage 80-100
vim redis-common.conf
#GENERAL
daemonize no
tcp-backlog 511
timeout 0
tcp-keepalive 0
loglevel notice
databases 16
dir /usr/local/redis/data
slave-serve-stale-data yes
protected-mode no
#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

  1. 启动redis
redis-server redis-6379.conf > logs/redis-6379.log 2>&1 &
  1. 启动集群
redis-trib.rb create --replicas 0 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382
  1. 检查集群
redis-trib.rb check 127.0.0.1:6381
共有 人打赏支持
粉丝 0
博文 1
码字总数 565
×
snail_lzq
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: