自学内容网 自学内容网

redis集群主备模式的快速搭建

一,下载redis

    此处下载的是redis-5.0.14.tar.gz

二,编译安装redis

mkdir -p /home/redis_cluster
cp /opt/redis-5.0.14.tar.gz /home/redis_cluster
tar -zxvf /home/redis__cluster/redis-5.0.14.tar.gz
cd /home/redis_cluster/redis-5.0.14
make
make install PREFIX=/home/redis_cluster


三,配置redis 集群服务

    此处用三台机器实现集群,每台机器本地实现master-slave

    在每个节点服务器上执行

mkdir /home/redis_cluster/7001
mkdir /home/redis_cluster/7002
cp -R /home/redis_cluster/bin /home/redis_cluster/redis01
cp -R /home/redis_cluster/bin /home/redis_cluster/redis02

    配置配置文件

cd /home/redis_cluster/7001/
vi redis.conf

daemonize yes
pidfile /home/redis_cluster/7001/redis_7001.pid
port 7001
cluster-enabled yes
cluster-config-file node7001.conf
bind=65.29.102.45
logfile /home/redis_cluster/7001/7001.log

cd /home/redis_cluster/7001/
vi redis.conf

daemonize yes
pidfile /home/redis_cluster/7002/redis_7002.pid
port 7002
cluster-enabled yes
cluster-config-file node7002.conf
bind=65.29.102.45
logfile /home/redis_cluster/7002/7002log


    启动redis(每个节点都执行)

/home/redis_cluster/redis01/redis-server /home/redis_cluster/7001/redis.conf
/home/redis_cluster/redis02/redis-server /home/redis_cluster/7002/redis.conf


四,搭建集群

/home/redis_cluster/redis01/redis-cli --cluster create --cluster-replicas 0 192.168.1.10:7001 192.168.1.11:7001 192.168.1.12:7001

    查看集群节点id信息,然后加入slave节点

/home/redis_cluster/redis01/redis-cli --cluster add-node 192.168.1.10:7002 192.168.1.10:7001 ---cluster-slave --cluster-master-id 719313131adabaadf23
/home/redis_cluster/redis01/redis-cli --cluster add-node 192.168.1.11:7002 192.168.1.11:7001 ---cluster-slave --cluster-master-id 71931afdasfda1adabaa
/home/redis_cluster/redis01/redis-cli --cluster add-node 192.168.1.12:7002 192.168.1.12:7001 ---cluster-slave --cluster-master-id 719b145131adafdafasdf


五,集群验证

/home/redis_cluster/redis01/redis-cli -h 192.168.1.10 -p 7001 -c
cluster info
cluster nodes


原文地址:https://blog.csdn.net/tpc4289/article/details/143720964

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!