redis5.0伪集群配置,按照步骤一步一步来。百分百成功

1. 下载redis5.0.2二进制安装包

wget http://download.redis.io/releases/redis-5.0.2.tar.gz

2. 解压到/opt目录下

tar -xzvf redis-5.0.2.tar.gz -C /opt

3. 编译

cd /opt/redis-5.0.2  && make

4. 指定安装位置

make install PREFIX=/usr/local/redis_cluster/redis7000

5. 拷贝安装目录下配置文件到/usr/local/redis_cluster/redis7000/etc

mkdir /usr/local/redis_cluster/redis7000/etc
cp  /opt/redis-5.0.2/redis.conf  /usr/local/redis_cluster/redis7000/etc/redis7000.conf

6. 修改配置文件 /usr/local/redis_cluster/redis7000/etc/redis7000.conf

vim /usr/local/redis_cluster/redis7000/etc/redis7000.conf
    
# 关闭保护模式
protected-mode no
    
# 以守护进程后台模式运行
daemonize yes
    
# 绑定本机ip
bind 172.16.9.179
    
# 修改端口
port 7000
    
# redis进程文件
pidfile /usr/local/redis_cluster/redis7000/redis_7000.pid
    
# 日志文件
logfile /usr/local/redis_cluster/redis7000/log/redis_7000.log
    
# 快照数据存放目录,一定是目录
dir /usr/local/redis_cluster/redis7000/data/
    
# 启用集群
cluster-enabled yes

7. 在redis7000新建data和log目录

cd /usr/local/redis_cluster/redis7000
mkdir -p data log

8. 安装redis7001

8.1 拷贝安装目录

     

cp -r /usr/local/redis_cluster/redis7000 /usr/local/redis_cluster/redis7001

8.2 重命名配置文件

cd /usr/local/redis_cluster/redis7001/etc
cp redis7000.conf redis7001.conf
rm -rf redis7000.conf

8.3 编辑配置文件

vim  /usr/local/redis_cluster/redis7001/etc/redis7001.conf 
        
# 修改端口
port 7001

# redis进程文件
pidfile /usr/local/redis_cluster/redis7001/redis_7001.pid

# 日志文件
logfile /usr/local/redis_cluster/redis7001/log/redis_7001.log

# 快照数据存放目录,一定是目录
dir /usr/local/redis_cluster/redis7001/data/

9. 仿照步骤8配置安装redis7002,redis7003,redis7004,redis7005

10. 编写启动脚本并赋予执行权限

cd /usr/local/redis_cluster

vim start_redis_cluster.sh


#内容为
/usr/local/redis_cluster/redis7000/bin/redis-server  /usr/local/redis_cluster/redis7000/etc/redis7000.conf
/usr/local/redis_cluster/redis7001/bin/redis-server  /usr/local/redis_cluster/redis7001/etc/redis7001.conf
/usr/local/redis_cluster/redis7002/bin/redis-server  /usr/local/redis_cluster/redis7002/etc/redis7002.conf
/usr/local/redis_cluster/redis7003/bin/redis-server  /usr/local/redis_cluster/redis7003/etc/redis7003.conf
/usr/local/redis_cluster/redis7004/bin/redis-server  /usr/local/redis_cluster/redis7004/etc/redis7004.conf
/usr/local/redis_cluster/redis7005/bin/redis-server  /usr/local/redis_cluster/redis7005/etc/redis7005.conf


## 给文件可执行的权限
chmod u+x start_redis_cluster.sh

11. 编写停止脚本并赋予执行权限

vim stop_redis_cluster.sh

##内容为

/usr/local/redis_cluster/redis7000/bin/redis-cli  -p 7000 shutdown
/usr/local/redis_cluster/redis7001/bin/redis-cli  -p 7001 shutdown
/usr/local/redis_cluster/redis7002/bin/redis-cli  -p 7002 shutdown
/usr/local/redis_cluster/redis7003/bin/redis-cli  -p 7003 shutdown
/usr/local/redis_cluster/redis7004/bin/redis-cli  -p 7004 shutdown
/usr/local/redis_cluster/redis7005/bin/redis-cli  -p 7005 shutdown

##给文件可执行的权限

chmod u+x stop_redis_cluster.sh

12. 启动所有redis节点

./start_redis_cluster.sh

13. 查看是否启动成功

ps aux | grep redis

redis5.0伪集群配置,按照步骤一步一步来。百分百成功_第1张图片

14. 使用5.0新特性redis-cli命令创建集群

/usr/local/redis_cluster/redis7001/bin/redis-cli --cluster create 172.18.203.30:7001 172.18.203.30:7002 172.18.203.30:7003 172.18.203.30:7004 172.18.203.30:7005 172.18.203.30:7006 --cluster-replicas 1

15.    如果报错[ERR] Node 172.16.9.179:7000 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.

15.1 解决办法

a.随便进入一个redis 
    cd /usr/local/redis_cluster/redis7000/bin
    ./redis-cli -h 172.16.9.179 -p 7000

b.执行
    cluster reset
    flushdb

c.退出
    exit

d.重复进入7001 7002 7003 7004 7005 执行②
    ./redis-cli -h 172.16.9.179 -p 7001
    cluster reset
    flushdb
    exit

15.2 再次执行14步骤

/usr/local/redis_cluster/redis7001/bin/redis-cli --cluster create 172.18.203.30:7001 172.18.203.30:7002 172.18.203.30:7003 172.18.203.30:7004 172.18.203.30:7005 172.18.203.30:7006 --cluster-replicas 1

16. 恭喜配置成功,提示如下

redis5.0伪集群配置,按照步骤一步一步来。百分百成功_第2张图片

17.  查看集群的信息

redis5.0伪集群配置,按照步骤一步一步来。百分百成功_第3张图片

18. 测试集群效果

redis5.0伪集群配置,按照步骤一步一步来。百分百成功_第4张图片

 

 

 

 

你可能感兴趣的:(PHP高级,技术文章)