redis 集群 (Linux环境)

安装redis步骤这里略过

这里集群我这边就使用一台机器 , 如果使用多台机器修改相应的IP和端口即可 

注:redis安装目录  /usr/local/redis/  集群端口 6379-6384

cd /usr/local/redis/
mkdir cluster
cd cluster
mkdir 6379
mkdir 6380
mkdir 6381
mkdir 6382
mkdir 6383
mkdir 6384
mkdir 6379/data
mkdir 6380/data
mkdir 6381/data
mkdir 6382/data
mkdir 6383/data
mkdir 6384/data
cd ..
cp ./etc/redis.conf ./cluster/6379/redis.conf
cp ./etc/redis.conf ./cluster/6380/redis.conf
cp ./etc/redis.conf ./cluster/6381/redis.conf
cp ./etc/redis.conf ./cluster/6382/redis.conf
cp ./etc/redis.conf ./cluster/6383/redis.conf
cp ./etc/redis.conf ./cluster/6384/redis.conf

修改各个规格复制的redis.conf

下面为需要修改的配置项以及说明 (红色字体部分根据实际情况修改)

port 6380           # 客户端连接端口
bind 127.0.0.1      # 实例绑定的IP地址,不限制请求端IP的话可以改成 0.0.0.0
dir /usr/local/redis/cluster/6380/data # redis实例数据配置存储位置
daemonize yes                          # 是否以后台进程的方式启动redis实例
pidfile /var/run/redis_6380.pid        # 指定该进程pidfile
cluster-enabled yes # 开启集群模式
cluster-config-file # 集群中该实例的配置文件,该文件会在data目录下生成
appendonly yes      # 开启aop日志
protected-mode no   # 关闭保护模式
requirepass cyclone # master开启密码保护
masterauth cyclone  # replica同master交互密码

启动redis

/usr/local/redis/bin/redis-server /usr/local/redis/cluster/6379/redis.conf
/usr/local/redis/bin/redis-server /usr/local/redis/cluster/6380/redis.conf
/usr/local/redis/bin/redis-server /usr/local/redis/cluster/6381/redis.conf
/usr/local/redis/bin/redis-server /usr/local/redis/cluster/6382/redis.conf
/usr/local/redis/bin/redis-server /usr/local/redis/cluster/6383/redis.conf
/usr/local/redis/bin/redis-server /usr/local/redis/cluster/6384/redis.conf

查看启动状态

 

 将各个redis关联起来

/usr/local/redis/bin/redis-cli -a 123456 --cluster create --cluster-replicas 1 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384

 

 集群完成


附:

停止redis节点命令

/usr/local/redis/bin/redis-cli -a 123456 -c -h 127.0.0.1 -p 6379 shutdown
/usr/local/redis/bin/redis-cli -a 123456 -c -h 127.0.0.1 -p 6380 shutdown
/usr/local/redis/bin/redis-cli -a 123456 -c -h 127.0.0.1 -p 6381 shutdown
/usr/local/redis/bin/redis-cli -a 123456 -c -h 127.0.0.1 -p 6382 shutdown
/usr/local/redis/bin/redis-cli -a 123456 -c -h 127.0.0.1 -p 6383 shutdown
/usr/local/redis/bin/redis-cli -a 123456 -c -h 127.0.0.1 -p 6384 shutdown
rm -rf /usr/local/redis/cluster/6379/data/*
rm -rf /usr/local/redis/cluster/6380/data/*
rm -rf /usr/local/redis/cluster/6381/data/*
rm -rf /usr/local/redis/cluster/6382/data/*
rm -rf /usr/local/redis/cluster/6383/data/*
rm -rf /usr/local/redis/cluster/6384/data/*

打开redis命令

打开客户端
cd /usr/local/redis/bin/
./redis-cli -a 123456 -c -p 6379 

参考:

https://www.cnblogs.com/grimm/p/12533455.html

https://www.jianshu.com/p/813a79ddf932

 很不错的两篇文章,强烈推荐

posted on 2020-09-09 18:38  hi-gdl  阅读(171)  评论(0编辑  收藏  举报

导航