Redis维护笔记
Redis维护笔记
一、单机Redis Cluster安装(Windows,CentOS)
1.Windows单机Redis
https://www.cnblogs.com/peteremperor/p/6635767.html
http://blog.csdn.net/baidu_15060875/article/details/54970663
https://www.cnblogs.com/tuojunjie/p/6227027.html
https://www.cnblogs.com/weiqinl/p/6490372.html
2.Windows单机Redis Cluster
Windows 部署 Redis 群集 https://www.cnblogs.com/Leo_wl/p/5357338.html
3.CentOS单机Redis
yum -y install gcc
cd /usr/local/src/
wget http://download.redis.io/releases/redis-3.2.11.tar.gz
tar -zxvf redis-3.2.11.tar.gz
cd redis-3.2.11/deps/
编译依赖
make geohash-int hiredis jemalloc linenoise lua
cd ..
编译Redis
make && make install
使用脚本安装服务
cd utils/
./install_server.sh
启动服务
systemctl start redis_6379
systemctl status redis_6379
4.CentOS单机Redis Cluster
cd /usr/local/src/
wget http://download.redis.io/releases/redis-3.2.11.tar.gz
tar -zxvf redis-3.2.11.tar.gz
cd redis-3.2.11/deps/
make geohash-int hiredis jemalloc linenoise lua
cd ..
make && make install PREFIX=/usr/local/redis
cd /usr/local/
mkdir -p redis/redis_cluster //创建集群目录
cd redis/redis_cluster
mkdir 7000 7001 7002 //分别代表三个节点 其对应端口 7000 7001 7002
cp /usr/local/src/redis-3.2.11/redis.conf ./7000/
cp /usr/local/src/redis-3.2.11/redis.conf ./7001/
cp /usr/local/src/redis-3.2.11/redis.conf ./7002/
#分别对7001,7002、7003文件夹中的3个文件修改对应的配置
root@localhost redis_cluster]# vi ./7000/redis.conf
daemonize yes //redis后台运行
pidfile /var/run/redis_7000.pid //pidfile文件对应7000,7002,7003
bind 192.168.1.106 //设置为当前机器在局域网的IP
port 7000 //端口7000,7002,7003
cluster-enabled yes //开启集群 把注释#去掉
cluster-config-file nodes_7000.conf //集群的配置 配置文件首次启动自动生成 7000,7001,7002
cluster-node-timeout 5000 //请求超时 设置5秒够了
appendonly yes //aof日志开启 有需要就开启,它会每次写操作都记录一条日志
启动
cd /usr/local/redis/
./bin/redis-server redis_cluster/7000/redis.conf
./bin/redis-server redis_cluster/7001/redis.conf
./bin/redis-server redis_cluster/7002/redis.conf
创建集群
yum -y install ruby ruby-devel rubygems rpm-build
gem install redis
/usr/local/redis-3.2.11/src/redis-trib.rb create --replicas 1 192.168.1.106:7000 192.168.1.106:7001 192.168.1.106:7002 192.168.1.107:7000 192.168.1.107:7001 192.168.1.107:7002
https://www.cnblogs.com/yuanermen/p/5717885.html
二、Redis Cluster动态添加删除重分配节点
1.增加主节点
[root@localhost src]# ./redis-trib.rb add-node 127.0.0.1:7006 127.0.0.1:7001
注释:
127.0.0.1:7006 是新增的节点
127.0.0.1:7001 集群任一个旧节点
2.增加从节点
添加7007成为7006的slave
查看 7006节点的node id
127.0.0.1:7001> cluster nodes
[root@localhost src]# ./redis-trib.rb add-node --slave --master-id 5da7b4b37f4e14638d9558e66166c042b752d417 127.0.0.1:7007 127.0.0.1:7001
注释:
–slave,表示添加的是从节点
–master-id 5da7b4b37f4e14638d9558e66166c042b752d417 ,主节点的node id,在这里是前面新添加的7006的node id
127.0.0.1:7007,新节点
127.0.0.1:7001集群任一个旧节点
redis-trib.rb reshard 127.0.0.1:7001 //下面是主要过程
3.删除从节点
redis-trib.rb del-node 127.0.0.1:7001 '9c240333476469e8e2c8e80b089c48f389827265'
4.删除主节点
127.0.0.1:7007> cluster replicate 49ed626134079dc301f586ff4edb1670a3a42a8c
注:49ed626134079dc301f586ff4edb1670a3a42a8c 为master节点7003的node id
如果主节点有slot,去掉分配的slot,然后在删除主节点
# redis-trib.rb reshard 127.0.0.1:7006 //取消分配的slot,下面是主要过程
How many slots do you want to move (from 1 to 16384)? 1000 //被删除master的所有slot数量
What is the receiving node ID? 5d8ef5a7fbd72ac586bef04fa6de8a88c0671052 //接收7007节点slot的master
Please enter all the source node IDs.
Type 'all' to use all the nodes as source nodes for the hash slots.
Type 'done' once you entered all the source nodes IDs.
Source node #1:03ccad2ba5dd1e062464bc7590400441fafb63f2 //被删除master的node-id
Source node #2:done
Do you want to proceed with the proposed reshard plan (yes/no)? yes //取消slot后,reshard
注意:source node 要用 ‘done’,如果用all 则会全部洗牌,7006还是会得到slot.
最后删除主节点7006:
redis-trib.rb del-node 127.0.0.1:7001 '5da7b4b37f4e14638d9558e66166c042b752d417'
1
注:
127.0.0.1:7001 代表cluster的一个node
5da7b4b37f4e14638d9558e66166c042b752d417 为要删除的7006这个节点的id.
5.重新分配
三、参考资料
如何停止/重启/启动redis服务
如果是用apt-get或者yum install安装的redis,可以直接通过下面的命令停止/启动/重启redis
/etc/init.d/redis-server stop
/etc/init.d/redis-server start
/etc/init.d/redis-server restart
如果是通过源码安装的redis,则可以通过redis的客户端程序redis-cli的shutdown命令来重启redis
redis-cli -h 127.0.0.1 -p 6379 shutdown
如果上述方式都没有成功停止redis,则可以使用终极武器 kill -9
《Redis官方教程》-Redis的配置 http://ifeve.com/redis-config/
Redis Cluster 原理与管理 https://zhuanlan.zhihu.com/p/25060071
[ERR] Not all 16384 slots are covered by nodes.
http://blog.csdn.net/vtopqx/article/details/50235891
redis 动态添加移除节点
http://blog.csdn.net/tengdazhang770960436/article/details/49925873
redis集群环境的搭建和错误分析
http://blog.csdn.net/jaryle/article/details/51757874
redis cluster管理工具redis-trib.rb详解
http://blog.csdn.net/huwei2003/article/details/50973967
redis3.0 运维(动态增加、删除、重新分配节点)
http://blog.csdn.net/donggang1992/article/details/50965599
redis集群删除master节点
https://www.cnblogs.com/mantian2020/p/6239264.html
redis集群动态增加或者删除节点
http://blog.csdn.net/xu470438000/article/details/42972123
redis主从集群搭建及容灾部署(哨兵sentinel)
http://www.cnblogs.com/linuxbug/p/5131504.html
Redis+Sentinel集群安装与配置
http://blog.csdn.net/xuxile/article/details/52213854
redis-cluster一台机器宕机后集群不可用
http://blog.csdn.net/zlfprogram/article/details/74225305
Redis3.0 Cluster集群的搭建与实践四,节点管理
http://blog.sina.com.cn/s/blog_53b45c4d0102wg13.html
redis cluster 添加 删除 重分配 节点 http://blog.51yip.com/nosql/1726.html
Redis 3.2.1集群搭建 https://www.cnblogs.com/yuanermen/p/5717885.html
Redis维护笔记 http://xiaoz5919.iteye.com/blog/2183833
Redis单机多节点集群实验
http://blog.csdn.net/dbreawbpcj/article/details/76360099
docker:搭建单机redis主从集群
http://blog.csdn.net/zcc_heu/article/details/78628066
windows本地安装redis单机和集群配置
http://blog.csdn.net/springlovejava/article/details/78712693
绝对干货-Redis集群的优化
http://www.imooc.com/article/14592
redis演练(9) redis Cluster 集群快速部署&failover情况
http://blog.51cto.com/dba10g/1852140
Redis学习笔记17Redis Cluster人工故障转移
https://www.cnblogs.com/coe2coe/p/7239516.html
Redis 高可用架构最佳实践
http://blog.csdn.net/tengxing007/article/details/77150380
Redis上踩过的一些坑-美团
http://blog.csdn.net/chenleixing/article/details/50530419
redis密码设置、访问权限控制等安全设置
https://www.cnblogs.com/langtianya/p/5189234.html
【精华分享】如何部署高可用的Redis集群架构
http://rdc.hundsun.com/portal/article/669.html