linux做redis集群
时间: 2024-01-10 13:19:18 浏览: 100
在Linux上搭建Redis集群的步骤如下:
1.下载Redis源码并解压缩,进入解压后的目录。
2.编译Redis源码,执行以下命令:
```shell
make
```
3.创建6个目录,用于存放6个Redis实例的数据和配置文件,执行以下命令:
```shell
mkdir 7000 7001 7002 7003 7004 7005
```
4.创建6个Redis实例的配置文件,执行以下命令:
```shell
cp redis.conf 7000/
cp redis.conf 7001/
cp redis.conf 7002/
cp redis.conf 7003/
cp redis.conf 7004/
cp redis.conf 7005/
```
5.修改6个Redis实例的配置文件,将以下内容修改为对应的值:
```shell
port 7000
pidfile /var/run/redis_7000.pid
cluster-enabled yes
cluster-config-file nodes_7000.conf
cluster-node-timeout 5000
appendonly yes
```
```shell
port 7001
pidfile /var/run/redis_7001.pid
cluster-enabled yes
cluster-config-file nodes_7001.conf
cluster-node-timeout 5000
appendonly yes
```
```shell
port 7002
pidfile /var/run/redis_7002.pid
cluster-enabled yes
cluster-config-file nodes_7002.conf
cluster-node-timeout 5000
appendonly yes
```
```shell
port 7003
pidfile /var/run/redis_7003.pid
cluster-enabled yes
cluster-config-file nodes_7003.conf
cluster-node-timeout 5000
appendonly yes
```
```shell
port 7004
pidfile /var/run/redis_7004.pid
cluster-enabled yes
cluster-config-file nodes_7004.conf
cluster-node-timeout 5000
appendonly yes
```
```shell
port 7005
pidfile /var/run/redis_7005.pid
cluster-enabled yes
cluster-config-file nodes_7005.conf
cluster-node-timeout 5000
appendonly yes
```
6.启动6个Redis实例,执行以下命令:
```shell
src/redis-server 7000/redis.conf
src/redis-server 7001/redis.conf
src/redis-server 7002/redis.conf
src/redis-server 7003/redis.conf
src/redis-server 7004/redis.conf
src/redis-server 7005/redis.conf
```
7.创建Redis集群,执行以下命令:
```shell
src/redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 --cluster-replicas 1
```
8.查看Redis集群状态,执行以下命令:
```shell
src/redis-cli -c cluster info
src/redis-cli -c cluster nodes
```
阅读全文