linux版本
CentOs7.3
分别创建三个目录,用于存放源码、单机、集群
1.单机安装
1.1进到redis-src目录下
1.2下载源码
curl -R -O http://download.redis.io/releases/redis-5.0.5.tar.gz
1.3安装依赖包
sudo yum -y install gcc-c++
1.4解压缩
tar -zxf redis-5.0.5.tar.gz
1.5进到redis-5.0.5
PREFIX=/work/redis 指定安装到哪个目录
cd redis-5.0.5
make MALLOC=libc
make install PREFIX=/work/redis
1.6将源码路径下的redis.conf sentinel.conf拷贝到安装路径下
cd /work/redis-src/redis-5.0.5
cp redis.conf sentinel.conf /work/redis/
1.7修改配置文件
cd /work/redis
vi redis.conf
将daemonize no改为daemonize yes
将bind 127.0.0.1改为0.0.0.0
建立软链接
sudo ln -s /work/redis/bin/redis-cli /usr/local/bin/redis-cli
sudo ln -s /work/redis/bin/redis-server /usr/local/bin/redis-server
sudo ln -s /work/redis/bin/redis-sentinel /usr/local/bin/redis-sentinel
sudo ln -s /work/redis/bin/redis-benchmark /usr/local/bin/redis-benchmark
sudo ln -s /work/redis/bin/redis-check-aof /usr/local/bin/redis-check-aof
sudo ln -s /work/redis/bin/redis-check-rdb /usr/local/bin/redis-check-rdb
到此单机版的安装完毕
1.8测试
1.8.1启动redis服务器
cd /work/redis
redis-server /work/redis/redis.conf
1.8.2启动redis客户端
redis-cli -p 6379
1.8.3关闭服务器
shutdown
1.8.4退出客户端
quit
2.集群安装
2.1分别创建redis7001 redis7002 redis7003 redis7004 redis7005 redis7006目录
mkdir redis7001 redis7002 redis7003 redis7004 redis7005 redis7006
2.2将redis-src下的redis.conf文件拷贝到redis7001目录下
cp /work/redis-src/redis-5.0.5/redis.conf /work/redis-cluster/redis7001/
2.3编辑redis.conf
vi /work/redis-cluster/redis7001/redis.conf
修改为以下配置,cluster-enabled yes该行要把注释去掉,其他选项类似
port 7001
daemonize yes
bind 0.0.0.0
protected-mode no
cluster-enabled yes
cluster-config-file nodes-7001.conf
pidfile /var/run/redis_7001.pid
2.4将redis7001文件夹的redis.conf拷贝到其他文件夹
cp /work/redis-cluster/redis7001/redis.conf /work/redis-cluster/redis7002/
cp /work/redis-cluster/redis7001/redis.conf /work/redis-cluster/redis7003/
cp /work/redis-cluster/redis7001/redis.conf /work/redis-cluster/redis7004/
cp /work/redis-cluster/redis7001/redis.conf /work/redis-cluster/redis7005/
cp /work/redis-cluster/redis7001/redis.conf /work/redis-cluster/redis7006/
2.5将其他文件夹的配置文件修改相应的端口
cd /work/redis-cluster
sed -i 's/7001/7002/g' redis7002/redis.conf
sed -i 's/7001/7003/g' redis7003/redis.conf
sed -i 's/7001/7004/g' redis7004/redis.conf
sed -i 's/7001/7005/g' redis7005/redis.conf
sed -i 's/7001/7006/g' redis7006/redis.conf
2.6编写启动、停止脚本
2.6.1新增启动脚本start-cluster.sh
#!/bin/bash
cd /work/redis-cluster/redis7001
redis-server /work/redis-cluster/redis7001/redis.conf
cd /work/redis-cluster/redis7002
redis-server /work/redis-cluster/redis7002/redis.conf
cd /work/redis-cluster/redis7003
redis-server /work/redis-cluster/redis7003/redis.conf
cd /work/redis-cluster/redis7004
redis-server /work/redis-cluster/redis7004/redis.conf
cd /work/redis-cluster/redis7005
redis-server /work/redis-cluster/redis7005/redis.conf
cd /work/redis-cluster/redis7006
redis-server /work/redis-cluster/redis7006/redis.conf
增加执行权限
chmod +x start-cluster.sh
2.6.2新增停止脚本stop-cluster.sh
#!/bin/bash
redis-cli -p 7001 shutdown
redis-cli -p 7002 shutdown
redis-cli -p 7003 shutdown
redis-cli -p 7004 shutdown
redis-cli -p 7005 shutdown
redis-cli -p 7006 shutdown
增加执行权限
chmod +x stop-cluster.sh
2.7启动六个redis实例
./start-cluster.sh
2.8创建集群,5.x版本已经不需要ruby依赖了,直接执行命令即可
redis-cli --cluster create 192.168.56.103:7001 192.168.56.103:7002 192.168.56.103:7003 192.168.56.103:7004 192.168.56.103:7005 192.168.56.103:7006 --cluster-replicas 1
执行过程中,需要确认,输入yes回车即可
至此集群创建成功。
2.9测试
客户端连接进去查看
redis-cli -p 7001 -c