在两台虚拟机上搭建redis集群
yum -y install gcc ruby ruby-devel rubygems rpm-build curl
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
curl -L get.rvm.io | bash -s stable
rvm install 2.3.3
source /usr/local/rvm/scripts/rvm
rvm use 2.3.3
cd /tmp
wget dachun.red/tools/redis-3.0.7.tar.gz
tar -zxvf redis-3.0.7.tar.gz
cd redis-3.0.7
make
make install PREFIX=/opt/redis
cd src
cp redis-trib.rb /usr/local/bin/
cp redis-server /usr/local/bin/
cd /opt/redis
mkdir redis_cluster
cd redis_cluster
mkdir 7001 7002 7003
cp /tmp/redis-3.0.7/redis.conf /opt/redis/redis_cluster/7001/
cp /tmp/redis-3.0.7/redis.conf /opt/redis/redis_cluster/7002/
cp /tmp/redis-3.0.7/redis.conf /opt/redis/redis_cluster/7003/
gem install redis
修改每个配置文件
port 7000 //端口7000,7002,7003 bind 本机ip //默认ip为127.0.0.1 需要改为其他节点机器可访问的ip 否则创建集群时无法访问对应的端口,无法创建集群 daemonize yes //redis后台运行 pidfile /var/run/redis_7000.pid //pidfile文件对应7000,7001,7002 cluster-enabled yes //开启集群 把注释#去掉 cluster-config-file nodes_7000.conf //集群的配置 配置文件首次启动自动生成7000,7001,7002 cluster-node-timeout 15000 //请求超时 默认15秒,可自行设置 appendonly yes //aof日志开启 有需要就开启,它会每次写操作都记录一条日志
#启动
redis-server /opt/redis/redis_cluster/7001/redis.conf &
redis-server /opt/redis/redis_cluster/7002/redis.conf &
redis-server /opt/redis/redis_cluster/7003/redis.conf &
另一台服务器同样执行上面的操作。接下来创建集群
redis-trib.rb
create --replicas 1 10.2.1.118:7001 10.2.1.118:7002 10.2.1.118:7003
10.2.1.119:7004 10.2.1.119:7005 10.2.1.119:7006
转载地址:https://www.cnblogs.com/wuxl360/p/5920330.html
https://www.cnblogs.com/carryping/p/7447823.html
阅读(1124) | 评论(0) | 转发(0) |