redis-cluster笔记

[root@localhost redis]# rm -r *
rm -r /usr/local/software/data/redis

mkdir -p /usr/local/software/data/redis/{redis-6379,redis-6380,redis-6381,redis-6382,redis-6383,redis-6384,redis-6385,redis-6386}/{run,logs,dbcache}

redis-6379.conf配置文件:

#bind 127.0.0.1 //取消本地IP绑定
protected-mode no //在配置之前一定要取消保护模式
port 6379 //监听端口
daemonize yes //后台运行
pidfile /usr/local/software/data/redis/redis-6379/run/redis_6379.pid //定义pid保存路径
logfile "/usr/local/software/data/redis/redis-6379/logs/redis_6379.log" //定义日志保存路径
dir /usr/local/software/data/redis/redis-6379/dbcache //数据保存目录
(不要配置密码 # requirepass mldnjava 注释掉)
cluster-enabled yes //打开RedisCluster集群
cluster-config-file nodes-6379.conf //定义 cluster 配置的保存文件
cluster-node-timeout 15000 //定义节点的超时时间(超过这个时间认为节点已经挂掉)

复制文件:  cp /usr/local/software/redis/conf/redis-6379.conf /usr/local/software/redis/conf/redis-6380.conf
整版替换:  1,$s/6379/6380/g

/usr/local/software/redis/bin/redis-server /usr/local/software/redis/conf/redis-6379.conf
/usr/local/software/redis/bin/redis-server /usr/local/software/redis/conf/redis-6380.conf
/usr/local/software/redis/bin/redis-server /usr/local/software/redis/conf/redis-6381.conf
/usr/local/software/redis/bin/redis-server /usr/local/software/redis/conf/redis-6382.conf
/usr/local/software/redis/bin/redis-server /usr/local/software/redis/conf/redis-6383.conf
/usr/local/software/redis/bin/redis-server /usr/local/software/redis/conf/redis-6384.conf
/usr/local/software/redis/bin/redis-server /usr/local/software/redis/conf/redis-6385.conf
/usr/local/software/redis/bin/redis-server /usr/local/software/redis/conf/redis-6386.conf

如果要想配置redis集群,请一定要先保证你的主机上拥有ruby权限
乌班图下:  apt-get install ruby ruby-dev rubygems
CentOS下:  yum install ruby ruby-dev rubygems

gem install redis

执行到此会报错:
[root@localhost /]# gem install redis
ERROR:  Error installing redis:
redis requires Ruby version >= 2.2.2.
[root@localhost /]# sudo yum install curl

解决问题的第一步,但会遇到另一个问题:
[root@localhost /]# curl -L get.rvm.io | bash -s stable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 24090  100 24090    0     0   1707      0  0:00:14  0:00:14 --:--:--  5179
Downloading https://github.com/rvm/rvm/archive/1.29.3.tar.gz
curl: (35) SSL connect error

Could not download 'https://github.com/rvm/rvm/archive/1.29.3.tar.gz'.
  curl returned status '35'.

解决的办法升级网络安全服务
[root@localhost /]# yum update nss
安装RVM
[root@localhost /]# curl -L get.rvm.io | bash -s stable 
[root@localhost /]# source /usr/local/rvm/scripts/rvm
 查看rvm库中已知的ruby版本
[root@localhost /]# rvm list known
安装一个ruby版本
[root@localhost /]# rvm install 2.3.4
使用一个ruby版本
[root@localhost /]# rvm use 2.3.4
Using /usr/local/rvm/gems/ruby-2.3.4
卸载一个已知版本
[root@localhost /]# rvm remove 2.0.0
ruby-2.0.0-p648 - #already gone
Using /usr/local/rvm/gems/ruby-2.3.4

首先需要进行 redis 的编译操作:
[root@localhost /]# 
gem install redis

复制一个 redis 集群的配置工具到 redis 的主目录之中:
cp /usr/local/software/redis-3.2.5/src/redis-trib.rb /usr/local/software/redis/bin/

/usr/local/software/redis/bin/redis-trib.rb help

/usr/local/software/redis/bin/redis-trib.rb create --replicas 1 192.168.68.131:6379 192.168.68.131:6380 192.168.68.131:6381 192.168.68.131:6382 192.168.68.131:6383 192.168.68.131:6384 192.168.68.131:6385 192.168.68.131:6386

Using 4 masters:
192.168.68.131:6379
192.168.68.131:6380
192.168.68.131:6381
192.168.68.131:6382
Adding replica 192.168.68.131:6383 to 192.168.68.131:6379
Adding replica 192.168.68.131:6384 to 192.168.68.131:6380
Adding replica 192.168.68.131:6385 to 192.168.68.131:6381
Adding replica 192.168.68.131:6386 to 192.168.68.131:6382

[root@localhost redis]# ./bin/redis-cli -h 192.168.68.131 -p 6379
192.168.68.131:6379> config set protected-mode yes
OK
192.168.68.131:6379> config set requirepass mldnjava
OK
192.168.68.131:6379> auth mldnjava
OK
192.168.68.131:6379> config set masterauth mldnjava
OK
192.168.68.131:6379> config rewrite
OK
192.168.68.131:6379> shutdown

[root@localhost /]# vi /usr/local/rvm/gems/ruby-2.3.4/gems/redis-4.0.1/lib/redis/client.rb
修改密码:"mldnjava"

/usr/local/software/redis/bin/redis-trib.rb check 192.168.68.131:6379

/usr/local/software/redis/bin/redis-cli -h 192.168.68.131 -p 6381 -a mldnjava -c





































评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值