【Linux】【redis】Linux下多机器redis集群
1、软件下载
redis:http://download.redis.io/releases/redis-3.2.1.tar.gz
ruby包:https://rubygems.org/downloads/redis-3.2.1.gem
2、上传到Linux上,也可以直接在Linux上下载wget -c URL(-c表示断点续传)
检查8000和8001端口是否被占用,没有没占用就可以使用ps -ef|grep 8000
创建文件夹
mkdir /opt/software/redis
mkdir /opt/software/redis/redis8000
mkdir /opt/software/redis/redis8001
解压redis
tar -zxvf /opt/tool/redis-3.2.1.tar.gz
查看是否安装gcc
gcc -v
如果没有安装gcc
sudo apt install gcc
编译redis
cd /opt/tool/redis-3.2.1
make
如果提示要安装make就安装
sudo apt install make
创建文件夹
mkdir /opt/software/redis/bin
复制文件到刚创建的文件夹
cp /opt/tool/redis-3.2.1/src/redis-cli /opt/software/redis/bin/
cp /opt/tool/redis-3.2.1/src/redis-server /opt/software/redis/bin/
cp /opt/tool/redis-3.2.1/src/redis-sentinel /opt/software/redis/bin/
cp /opt/tool/redis-3.2.1/src/redis-benchmark /opt/software/redis/bin/
创建文件夹
mkdir /opt/software/redis/etc
复制配置文件
cp /opt/tool/redis-3.2.1/redis.conf /opt/software/redis/etc/
创建文件夹和文件
mkdir /opt/software/redis/logs
touch /opt/software/redis/logs/redis.out
复制文件夹到8000和8001文件夹下
cp -r /opt/software/redis/bin/ /opt/software/redis/redis8000
cp -r /opt/software/redis/bin/ /opt/software/redis/redis8001
cp -r /opt/software/redis/logs/ /opt/software/redis/redis8000
cp -r /opt/software/redis/logs/ /opt/software/redis/redis8001
cp -r /opt/software/redis/etc/ /opt/software/redis/redis8000
cp -r /opt/software/redis/etc/ /opt/software/redis/redis8001
编辑配置文件
vi /opt/software/redis/redis8000/etc/redis.conf
vi /opt/software/redis/redis8001/etc/redis.conf
启动redis
nohup /opt/software/redis/redis8000/bin/redis-server /opt/software/redis/redis8000/etc/redis.conf >>/opt/software/redis/redis8000/logs/redis.out 2>&1 & nohup /opt/software/redis/redis8001/bin/redis-server /opt/software/redis/redis8001/etc/redis.conf >>/opt/software/redis/redis8001/logs/redis.out 2>&1 &
查看redis启动情况
ps -ef|grep redis
其他两台机器一样
3、安装ruby工具
sudo apt-get install ruby
运行gem
sudo gem install /opt/tool/redis-3.2.1.gem
复制redis的src下文件redis-trib.rb
cp /opt/tool/redis-3.2.1/src/redis-trib.rb /opt/software/redis/
启动集群(只要一台机器启动就可以了)
/opt/software/redis/redis-trib.rb create --replicas 1 192.168.3.25:8000 192.168.3.25:8001 192.168.3.26:8000 192.168.3.26:8001 192.168.3.27:8000 192.168.3.27:8001
如果有问题:创建redis集群报错:ERR Slot 0 is already busy (Redis::CommandError)
4、测试
连接
/usr/local/redis/bin/redis-cli -p 8000 -h 192.168.3.25 -c
查看节点连接状态
cluster nodes
查看集群信息
cluster info
设值
获取值
扩展资料(手动搭建集群):https://xlui.me/t/redis-cluster/