Redis-集群搭建
1.安装redis
1.1 下载redis
http://download.redis.io/releases/redis-3.2.9.tar.gz
1.2 安装redis
(1)解压
tar -zxvf redis-3.2.9.tar.gz
(2) 安装
cd redis-3.2.9
make
make install
2.启动redis
rm -rf /opt/redis-cluster/7000/data/ /opt/redis-cluster/7001/data/ /opt/redis-cluster/7002/data/
mkdir /opt/redis-cluster/7000/data/ /opt/redis-cluster/7001/data/ /opt/redis-cluster/7002/data/
redis-server /opt/redis-cluster/7000/redis.conf
redis-server /opt/redis-cluster/7001/redis.conf
redis-server /opt/redis-cluster/7002/redis.conf
3. 集群分片
cd redis-3.2.9/src
./redis-trib.rb create --replicas 2 192.168.11.69:7000 192.168.11.70:7000 192.168.11.71:7000 192.168.11.69:7001 192.168.11.70:7001 192.168.11.71:7001 192.168.11.69:7002 192.168.11.70:7002 192.168.11.71:7002
11.69:7000, 11.70:7000,11.71:7000做完主节点;
4. redis-trib.rb 使用问题
redis-trib.rb这个脚本,依赖ruby语言,需要在linux下安装ruby
4.1 安装ruby
cd /opt
wget https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.1.tar.gz
tar -zxvf ruby-2.5.1.tar.gz
cd ruby-2.5.1
./configure
make
make install
再执行
gem install redis -v 3.2.0(需要注意此处的版本和redis的版本不能相差太大)
到此redis集群安装完成
则需要重装openssl,参考
https://www.cnblogs.com/dinglin1/p/9047818.html
openssl不能登录,参考
https://blog.csdn.net/fanhenghui/article/details/95190925
4.2 创建集群时没有密码会报“can’t connect to node XXXX”
修改
find / -name client.rb
****/gems/redis-3.3.0/lib/redis/client.rb
该文件有个password,原本是nil,没有配置,我们改成和requirepass一样的密码,
然后,redis全部重启,再次执行创建集群,就解决了!
5.redis集群添加新的节点
5.1新增主节点
./redis-trib.rb add-node 127.0.0.1:7000 127.0.0.1:7000
5.2新增从节点
./redis-trib.rb add-node --slave 127.0.0.1:7001 127.0.0.1:7000