首页 > 代码库 > Redis集群

Redis集群


安装redis源码包,需要gcc环境支持

yum install -y gcc tcl

mkdir /opt/{app,software,datas,moudles,tools}

chown huiyunltd:huiyunltd /opt/{app,software,datas,moudles,tools}


[huiyunltd@hadoop-senior softwares]$ wget http://download.redis.io/releases/redis-3.2.9.tar.gz

[huiyunltd@hadoop-senior softwares]$ tar xf redis-3.2.9.tar.gz -C /opt/app/

[huiyunltd@hadoop-senior softwares]$ cd /opt/app/redis-3.2.9/



make

make PREFIX=/opt/app/redis install


bin/redis-server   //启动



集群结点规划

192.168.1.111 huiyunltd-redis-01

192.168.1.112 huiyunltd-redis-02

192.168.1.113 huiyunltd-redis-03

192.168.1.114 huiyunltd-redis-04

192.168.1.115 huiyunltd-redis-05

192.168.1.116 huiyunltd-redis-06


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>3主+3从<<<<<<<<<<<<<<<<<<<<<<<<<<

M 192.168.1.111:7111 M 192.168.1.112:7112 M 192.168.1.113:7113

S 192.168.1.114:7114 S 192.168.1.115:7115 S 192.168.1.116:7116



主机名 IP     服务端口 集群端口 主/从

huiyunltd-redis-01 192.168.1.111 7111 17111

huiyunltd-redis-02 192.168.1.112 7112 17112

huiyunltd-redis-03 192.168.1.113 7113 17113

huiyunltd-redis-04 192.168.1.114 7114 17114

huiyunltd-redis-05 192.168.1.115 7115 17115

huiyunltd-redis-06 192.168.1.116 7116 17116


防火墙打开端口

192.168.1.111

-A INPUT -m state --state NEW -m tcp -p tcp --dport 7111 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 17111 -j ACCEPT


192.168.1.112

-A INPUT -m state --state NEW -m tcp -p tcp --dport 7112 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 17112 -j ACCEPT


192.168.1.113

-A INPUT -m state --state NEW -m tcp -p tcp --dport 7113 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 17113 -j ACCEPT

192.168.1.114

-A INPUT -m state --state NEW -m tcp -p tcp --dport 7114 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 17114 -j ACCEPT

192.168.1.115

-A INPUT -m state --state NEW -m tcp -p tcp --dport 7115 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 17115 -j ACCEPT

192.168.1.116

-A INPUT -m state --state NEW -m tcp -p tcp --dport 7116 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 17116 -j ACCEPT



安装目录 /opt/app/redis


[huiyunltd@hadoop-senior softwares]$ tar xf redis-3.2.9.tar.gz -C /opt/app/

[huiyunltd@hadoop-senior softwares]$ cd /opt/app/redis-3.2.9/

[huiyunltd@hadoop-senior redis-3.2.9]$ make PREFIX=/opt/app/redis install


创建集群配置目录,并拷贝redis.conf 到各节点配置目录

192.168.1.111

makdir -p /opt/app/redis/cluster/7111

[huiyunltd@hadoop-senior redis-3.2.9]$ cp /opt/app/redis-3.2.9/redis.conf /opt/app/redis/cluster/7111/redis-7111.conf

192.168.1.112

makdir -p /opt/app/redis/cluster/7112

[huiyunltd@hadoop-senior redis-3.2.9]$ cp /opt/app/redis-3.2.9/redis.conf /opt/app/redis/cluster/7112/redis-7112.conf

192.168.1.113

makdir -p /opt/app/redis/cluster/7113

[huiyunltd@hadoop-senior redis-3.2.9]$ cp /opt/app/redis-3.2.9/redis.conf /opt/app/redis/cluster/7113/redis-7113.conf

192.168.1.114

makdir -p /opt/app/redis/cluster/7114

[huiyunltd@hadoop-senior redis-3.2.9]$ cp /opt/app/redis-3.2.9/redis.conf /opt/app/redis/cluster/7114/redis-7114.conf

192.168.1.115

makdir -p /opt/app/redis/cluster/7115

[huiyunltd@hadoop-senior redis-3.2.9]$ cp /opt/app/redis-3.2.9/redis.conf /opt/app/redis/cluster/7115/redis-7115.conf

192.168.1.116

makdir -p /opt/app/redis/cluster/7116

[huiyunltd@hadoop-senior redis-3.2.9]$ cp /opt/app/redis-3.2.9/redis.conf /opt/app/redis/cluster/7116/redis-7116.conf




port                       7111

databases                     1

cluster-enabled yes           yes

cluster-config-file    /opt/app/redis/cluster/7111/redis-7111.conf

cluster-node-timeout     15000

cluser-migration-barrier    1

cluser-reguire-full-converage   yes

appendonly                    yes




redis集群管理工具redis-trib.rb依赖ruby环境,首先需要安装ruby环境:


yum install ruby rubygems


ruby -v    //查看版本


gem install redis   //gem 安装redis ruby接口



















































 


    这里在同一台服务器用不同的端口表示不同的redis服务器,如下:

    主节点:192.168.106.132:7001 192.168.106.132:7002 192.168.106.132:7003

    从节点:192.168.106.132:7004 192.168.106.132:7005 192.168.106.132:7006


在/usr/local下创建redis-cluster目录,其下创建7001、7002。。7006目录,如下:

mkdir /opt/app/redis-cluster

mkdir /opt/app/redis-cluster{7001,7002,7003,7004,7005,7006}



./redis-cli -c -p 7001

cluster info

































https://www.aliyun.com/product/kvstore?spm=5176.8072238.yqblog1.7.0vTinb


Redis集群