标签:redis reids集群部署 redis安装 redis分片 甘兵
1、环境说明在此文章中不对redis做详细介绍,如果对redis不太了解的朋友可以参考此链接 http://www.runoob.com/redis/redis-tutorial.html
要让redis集群正常工作至少需要3个主节点,在这里我们要创建6个redis节点,其中三个为主节点,三个为从节点,对应的redis节点的ip和端口对应关系如下:
主机和端口 |
192.168.102.51:6379、192.168.102.51:6380 |
192.168.102.52:6379、192.168.102.52:6380 |
192.168.102.53:6379、192.168.102.53:6380 |
说明:3台服务器部署redis集群环境,如果你只用于测试部署,可在1台服务器上配置,不过端口别重复就行。
2、准备redis相关依赖包
( 在这3台服务器都需要安装)
包名 | 下载地址 |
zlib-1.2.8.tar.gz | http://nchc.dl.sourceforge.net/project/libpng/zlib/1.2.8/zlib-1.2.8.tar.gz |
ruby-2.2.4.tar.bz2 | https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.4.tar.bz2 |
rubygems-2.5.1.tgz | https://rubygems.global.ssl.fastly.net/rubygems/rubygems-2.5.1.tgz |
redis-3.2.2.gem | https://rubygems.global.ssl.fastly.net/gems/redis-3.2.2.gem |
redis-3.2.3.tar.gz | http://download.redis.io/releases/redis-3.2.3.tar.gz |
2.1 安装zlib
# gunzip zlib-1.2.8.tar.gz # tar -xvf zlib-1.2.8.tar # cd zlib-1.2.8 # ./configure # make # make install |
2.2 安装ruby
# bunzip2 ruby-2.2.4.tar.bz2 # tar -xvf ruby-2.2.4.tar # cd ruby-2.2.4 # ./configure -prefix=/usr/local/ruby # make Generating RDoc documentation Parsing sources... 100% [967/967] vsnprintf.c Generating RI format into /root/ruby-2.2.4/.ext/rdoc... Files: 967 Classes: 1411 ( 581 undocumented) Modules: 280 ( 108 undocumented) Constants: 2160 ( 594 undocumented) Attributes: 1156 ( 255 undocumented) Methods: 10488 (2187 undocumented) Total: 15495 (3725 undocumented) 75.96% documented Elapsed: 744.0s # make install # cp ruby /bin |
2.3 安装rubygems
# tar -zxvf rubygems-2.5.1.tgz # cd rubygems-2.5.1 # ruby setup.rb # cp bin/gem /bin |
注意:编译中出现in 'require': cannot load such file -- json/pure (LoadError)的解决方法:
# gem install json_pure
Fetching: json_pure-1.8.3.gem (100%)
Successfully installed json_pure-1.8.3
Parsing documentation for json_pure-1.8.3
Installing ri documentation for json_pure-1.8.3
1 gem installed
2.4 安装gem-redis
# gem install -l redis-3.2.2.gem Successfully installed redis-3.2.2 Parsing documentation for redis-3.2.2 Installing ri documentation for redis-3.2.2 1 gem installed |
3、安装redis( 在这3台服务器都需要安装)
解压、编译
# tar -zxvf redis-3.2.3.tar.gz # cd redis-3.2.3 # make |
创建redis所需目录
#mkdir -p /usr/local/redis/{bin,conf,data,logs} ##创建redis相关目录 # cp src/redis-server /usr/local/redis/bin/ ##Redis服务器的daemon启动程序 # cp src/redis-cli /usr/local/redis/bin/ ##Redis命令行操作工具 # cp src/redis-trib.rb /usr/local/redis/bin/ ##Redis Cluster工具 # cp src/redis-benchmark /usr/local/redis/bin/ ##Redis性能测试工具 # cp src/redis-check-aof /usr/local/redis/bin/ ##修复坏损坏的aof文件 # cp src/redis-check-dump /usr/local/redis/bin/ ##检查导出工具 # cp src/redis-sentinel /usr/local/redis/bin/ ##Redis集群的管理工具 |
说明:如果你不想跟上面那样麻烦操作,也可直接复制src目录下所有的文件至 /usr/local/redis/bin/中
比如:cp src/* /usr/local/redis/bin/
复制redis配置文件
# cp redis.conf /usr/local/redis/conf/redis-6379.conf # cp redis.conf /usr/local/redis/conf/redis-6380.conf |
修改redis配置文件(修改红色字体部分)
bind 0.0.0.0 #redis服务监听的地址 protected-mode yes port 6379 #如果是redis-6380.conf配置文件,修改为6380 tcp-backlog 511 timeout 0 tcp-keepalive 300 daemonize yes #修改为yes,让redis在后台运行 supervised no pidfile /var/run/redis_6379.pid #如果是redis-6380.conf配置文件,修改为redis_6380.pid loglevel notice logfile /usr/local/redis/logs/redis-6379.log #如果是redis-6380.conf配置文件,修改为redis_6380.pid databases 16 save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename dump.rdb dir ./ slave-serve-stale-data yes slave-read-only yes repl-diskless-sync no repl-diskless-sync-delay 5 repl-disable-tcp-nodelay no slave-priority 100 appendonly no appendfilename "appendonly.aof" appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb aof-load-truncated yes lua-time-limit 5000 cluster-enabled yes cluster-config-file nodes-51-6379.conf #如果是redis-6380.conf配置文件,修改为nodes-51-6380.conf cluster-node-timeout 5000 slowlog-log-slower-than 10000 slowlog-max-len 128 latency-monitor-threshold 0 notify-keyspace-events "" hash-max-ziplist-entries 512 hash-max-ziplist-value 64 list-max-ziplist-size -2 list-compress-depth 0 set-max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value 64 hll-sparse-max-bytes 3000 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 |
cluster-config-file nodes-51-6379.conf #这条配置要特别说明一下
一定要注意,这3台服务器这条配置的名字最好不要取一样的,建议按下面的方式取名(当然你可以自己规定):
192.168.102.51:nodes-51-6379.conf nodes-51-6380.conf
192.168.102.52:nodes-52-6379.conf nodes-52-6380.conf
192.168.102.53:nodes-53-6379.conf nodes-53-6380.conf
说明:如果需要了解redis更多配置文件的详细说明,请参考下面的链接
http://blog.csdn.net/neubuffer/article/details/17003909
4、redis集群启动
4.1 redis实例启动(按顺序挨个启动,先启动6379、后启动6380):
#/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis-6379.conf #分别按相顺序启动这3台服务器的6379实例 #/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis-6380.conf #分别按相顺序启动3台服务器的6380实例 |
然后检查实例是否启动正常:
#ps -ef | grep redis |
4.2 创建集群 (在第1台redis服务器上创建,并执行以下命令)
#/usr/local/redis/bin//bin/redis-trib.rb create --replicas 1 192.168.102.51:6379 192.168.102.52:6379 192.168.102.53:6379 192.168.102.51:6380 192.168.102.52:6380 192.168.102.53:6380 |
Can I set the above configuration? (type 'yes' to accept): yes #这里要输入yes
查看集群节点:
检测集群:
查看集群主节点:
如出现以上这些信息,说明集群安装成功。
标签:redis reids集群部署 redis安装 redis分片 甘兵
原文地址:http://blog.51cto.com/ganbing/2051023