redis集群快速搭建
1 本文以redis6.2.6版本为例,快速搭建一套三主三从的redis集群,已经提前将脚本写好,只需要在节点上面进行执行即可安装
#!/bin/bash install_redis() { # 解压 Redis 源码包 tar -zxvf redis-6.2.6.tar.gz # 创建目录结构 mkdir -p /opt/redis/cluster/{conf,data,log,pid} # 编译并安装 Redis cd redis-6.2.6 && make && make install PREFIX=/opt/redis } generate_redis_config() { local redis_host=$1 local redis_dir="/opt/redis/cluster" for port in 6379 6380; do mkdir -p /opt/redis/cluster/data/${port} config_file="$redis_dir/conf/redis_${port}.conf" cat <<EOF > "$config_file" # Redis 配置文件,端口 ${port} daemonize yes bind $redis_host dir $redis_dir/data/${port}/ pidfile $redis_dir/pid/${port}.pid logfile $redis_dir/log/redis-cluster-${port}.log port ${port} cluster-enabled yes cluster-config-file $redis_dir/conf/redis-cluster-${port}.conf cluster-node-timeout 10000 appendonly yes requirepass Ebupt#202401f masterauth Ebupt#202401f EOF echo "已生成配置文件: $config_file" done } start_redis_node() { for port in 6379 6380; do /opt/redis/bin/redis-server /opt/redis/cluster/conf/redis_${port}.conf echo "已启动配置文件: /opt/redis/cluster/conf/redis_${port}.conf 的节点" done } main() { # 安装 Redis install_redis # 生成 Redis 配置文件 generate_redis_config $1 # 启动 Redis 集群节点 start_redis_node # 生成集群 # yes|/opt/redis/bin/redis-cli --cluster create $1:6379 $1:6380 $1:6381 $1:6382 $1:6383 $1:6384 --cluster-replicas 1 -a
Ebupt#202401f
} main "$@"
2 将该脚本以及redis-6.2.6.tar.gz同时放置到服务器任意目录之后执行即可,这个操作需要在配置的三台上面进行配置
bash install_redis_cluster.sh xx.xx.xx.xx #xx.xx.xx.xx为主机的IP地址
3 安装包
链接:https://pan.baidu.com/s/1GCFILWqIrUMm4HpUFbLV_g
提取码:hpb9
4 组成集群
/opt/redis/bin/redis-cli --cluster create host1:6379 host2:6380 host2:6379 host3:6380 host3:6379 host1:6380 --cluster-replicas 1 -a Ebupt#202401f #host1 #host2 #host3 分别为需要部署的主机123
标签:opt,三主三,redis,cluster,xx,集群,conf,port From: https://www.cnblogs.com/wxm-pythoncoder/p/18182708