参考官方地址:https://redis.io/topics/cluster-tutorial
假设现有服务器6台 ip分别为
192.168.43.203 192.168.43.204 192.168.43.205
192.168.43.206 192.168.43.207 192.168.43.208
每台机器安装redis服务,都要做如下配置: vi /usr/local/redis/etc/redis.conf
cluster-enabled yes #启用集群模式
cluster-config-file nodes.conf
cluster-node-timeout 5000 #超时时间
appendonly yes
服务器都启动后在任意一台执行如下指令
/usr/local/redis/bin/redis-cli --cluster create --cluster-replicas 1 192.168.43.203:6379 192.168.43.204:6379 192.168.43.205:6379 192.168.43.206:6379 192.168.43.207:6379 192.168.43.208:6379
进入命令行下测试
/usr/local/redis/bin/redis-cli -c
查看集群信息参数
/usr/local/redis/bin/redis-cli CLUSTER INFO 打印集群的信息
/usr/local/redis/bin/redis-cli CLUSTER NODES 列出集群当前已知的所有节点(node),以及这些节点的相关信息。
安装redis扩展,php测试
$obj_cluster = new RedisCluster(NULL, ['192.168.8.113:6379']);
echo $obj_cluster->get('a');