redis-cluster安装与配置

集群的配置:
tar xzvf redis-3.2.5.tar.gz -C /usr/local/software/


[[email protected] redis-3.2.5]# make
[[email protected] redis-3.2.5]# make install


[[email protected] redis-3.2.5]# echo "vm.overcommit_memory=1">>/etc/sysctl.conf
[[email protected] redis-3.2.5]# /sbin/sysctl -p


mkdir -p /usr/local/software/redis/{bin,conf}


cp /usr/local/software/redis-3.2.5/src/redis-server /usr/local/software/redis/bin/
cp /usr/local/software/redis-3.2.5/src/redis-cli /usr/local/software/redis/bin/
cp /usr/local/software/redis-3.2.5/src/redis-benchmark /usr/local/software/redis/bin/
cp /usr/local/software/redis-3.2.5/src/redis-sentinel /usr/local/software/redis/bin/


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


sudo yum install curl


yum update nss


gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3


安装RVM
[[email protected] /]# curl -L get.rvm.io | bash -s stable 
[[email protected] /]# source /usr/local/rvm/scripts/rvm
 查看rvm库中已知的ruby版本
[[email protected] /]# rvm list known
安装一个ruby版本
[[email protected] /]# rvm install 2.3.4
使用一个ruby版本
[[email protected] /]# rvm use 2.3.4
Using /usr/local/rvm/gems/ruby-2.3.4
卸载一个已知版本
[[email protected] /]# rvm remove 2.0.0
ruby-2.0.0-p648 - #already gone
Using /usr/local/rvm/gems/ruby-2.3.4


首先需要进行 redis 的编译操作:
[[email protected] /]# 
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


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


/usr/local/software/redis/bin/redis-trib.rb create --replicas 1 192.168.68.139:6379 192.168.68.139:6380 192.168.68.139:6381 192.168.68.139:6382 192.168.68.139:6383 


192.168.68.139:6384 192.168.68.139:6385 192.168.68.139:6386


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


/usr/local/software/redis/bin/redis-cli -h 192.168.68.139 -p 6381 -c


----------------------------------------------------------------------------------------


单节点的配置:


tar xzvf redis-3.0.0.tar.gz -C /usr/local/software/


[[email protected] redis-3.0.0]# make
[[email protected] redis-3.0.0]# make install


mkdir -p /usr/local/software/redis1/{bin,conf}


cp /usr/local/software/redis-3.0.0/src/redis-server /usr/local/software/redis1/bin/
cp /usr/local/software/redis-3.0.0/src/redis-cli /usr/local/software/redis1/bin/
cp /usr/local/software/redis-3.0.0/src/redis-benchmark /usr/local/software/redis1/bin/
cp /usr/local/software/redis-3.0.0/src/redis-sentinel /usr/local/software/redis1/bin/


mkdir -p /usr/local/software/data/redis1/redis-6379/{run,logs,dbcache}


cp redis.conf /usr/local/software/redis1/conf/


vi redis.conf


daemonize yes
pidfile /usr/local/software/data/redis1/redis-6379/run/redis_6379.pid
logfile "/usr/local/software/data/redis1/redis-6379/logs/redis_6379.log"
dir /usr/local/software/data/redis1/redis-6379/dbcache

猜你喜欢

转载自blog.csdn.net/GANWEI793089452/article/details/80210729