Redis集群安装文档

安装java环境

rpm -ivh jdk-8u112-linux-x64.rpm

配置环境变量

JAVA_HOME=/usr/java/jdk1.8.0_112
JRE_HOME=/usr/java/jdk1.8.0_112/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME

安装redis

下载redis并解压

cd /data/cluster/redis/
mkdir download
cd download/
wget http://download.redis.io/releases/redis-3.2.5.tar.gz
tar -xzvf redis-3.2.5.tar.gz

创建redis所需的目录

mkdir redis_cluster
mkdir redis_cluster/data
mkdir redis_cluster/log
mkdir redis_cluster/conf

编译源码

cd /data/cluster/redis/download/redis-3.2.5
make
make install PREFIX=/data/cluster/redis/redis_cluster/redis-3.2.5

mkdir /data/cluster/redis/redis_cluster/data/6379
mkdir /data/cluster/redis/redis_cluster/data/6380

添加conf文件

注意:配置文档中涉及IP的地方,不能改成机器名

6379 如下示例

vim /data/cluster/redis/redis_cluster/data/6379/redis-6379.conf

port 6379
bind 10.1.36.241
cluster-enabled yes
cluster-config-file nodes-6379.conf
cluster-node-timeout 5000
appendonly yes
daemonize yes
pidfile /var/run/redis-6379.pid
dir /data/cluster/redis/redis_cluster/data/6379
dbfilename dump-6379.rdb
appendfilename appendonly-6379.aof
logfile /data/cluster/redis/redis_cluster/log/redis-6379.log

6380 如下示例

vim /data/cluster/redis/redis_cluster/data/6380/redis-6380.conf

port 6380
bind 10.1.36.241
cluster-enabled yes
cluster-config-file nodes-6380.conf
cluster-node-timeout 5000
appendonly yes
daemonize yes
pidfile /var/run/redis-6380.pid
dir /data/cluster/redis/redis_cluster/data/6380
dbfilename dump-6380.rdb
appendfilename appendonly-6380.aof
logfile /data/cluster/redis/redis_cluster/log/redis-6380.log

安装集群环境

sudo yum -y install ruby ruby-devel rubygems rpm-build
sudo gem install redis

cp /data/cluster/redis/download/redis-3.2.5/src/redis-trib.rb /data/cluster/redis/redis_cluster/redis-3.2.5/bin/

启动redis

cd /data/cluster/redis/redis_cluster
./redis-3.2.5/bin/redis-server conf/redis-6379.conf
./redis-3.2.5/bin/redis-server conf/redis-6380.conf

创建redis cluster

cd /data/cluster/redis/redis_cluster
./redis-3.2.5/bin/redis-trib.rb create –replicas 1 10.1.36.241:6379 10.1.36.242:6381 10.1.36.243:6383 10.1.36.241:6380 10.1.36.242:6382 10.1.36.243:6384

出现错误 Connection timed out

/usr/lib/ruby/gems/1.8/gems/redis-3.3.2/lib/redis/connection/ruby.rb:111:in `_write_to_socket’: Connection timed out (Redis::TimeoutError)

原因防火墙问题,需要彻底关闭防火墙iptables -F
/etc/init.d/iptables stop
chkconfig iptables off
iptables-save

重装gem到低版本

gem list
sudo gem uninstall redis –version 3.3.2
sudo gem install redis –version 3.0.0

启动redis集群

bi-server-01cd /data/cluster/redis/redis_cluster
./redis-3.2.5/bin/redis-server conf/redis-6379.conf
./redis-3.2.5/bin/redis-server conf/redis-6380.conf
ps -ef|grep redis

bi-server-02cd /data/cluster/redis/redis_cluster
./redis-3.2.5/bin/redis-server conf/redis-6381.conf
./redis-3.2.5/bin/redis-server conf/redis-6382.conf
ps -ef|grep redis

bi-server-03cd /data/cluster/redis/redis_cluster
./redis-3.2.5/bin/redis-server conf/redis-6383.conf
./redis-3.2.5/bin/redis-server conf/redis-6384.conf
ps -ef|grep redis

./redis-3.2.5/bin/redis-trib.rb create –replicas 1 10.1.36.241:6379 10.1.36.242:6381 10.1.36.243:6383 10.1.36.241:6380 10.1.36.242:6382 10.1.36.243:6384

常用操作

查看哪些端口的节点是master,哪些端口的节点是slave

cd /data/cluster/redis/redis_cluster
./redis-3.2.5/bin/redis-trib.rb check 10.1.36.243:6384

启动client

cd /data/cluster/redis/redis_cluster
./redis-3.2.5/bin/redis-cli -c -h 10.1.36.241 -p 6379

使用info 或者 info replication查看本redis的信息

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据