单节点redis集群部署
部署redis 6.2.7版本
没资源,就用一台机子部
解压安装包
tar zxf redis-6.2.7.tar.gzcd redis-6.2.7
编译安装
mkdir -p /var/local/redis-6.2.7/{data,conf,logs,pid}data:数据目录
conf:配置文件目录
logs:日志目录
pid:redis进程文件目录
makemake install PREFIX=/var/local/redis-6.2.7
拷贝配置
cp redis.conf /var/local/redis-6.2.7/conf/redis_7001.conf
cd /var/local/redis-6.2.7
修改配置
logfile可以不加,这样日志会输出到/dev/null,不用怕文件过大有写入错误
bind 0.0.0.0
port 7001 # 修改默认端口,只要不占用就可以
daemonize yes # 后台运行程序
pidfile /var/local/redis-6.2.7/pid/redis_7001.pid # 以端口命名pid文件名
loglevel notice
logfile "/var/local/redis-6.2.7/logs/redis_7001.log" # 以端口命名log文件名
dbfilename dump_7001.rdb
dir /var/local/redis-6.2.7/data
repl-disable-tcp-nodelay yes
requirepass xxxwoaixuexi.. # 这是密码
maxclients 10000
maxmemory 524288000 # 500M
maxmemory-policy allkeys-lru
appendonly yes
appendfilename "appendonly_7001.aof"
no-appendfsync-on-rewrite yes
auto-aof-rewrite-percentage 100
cluster-enabled yes
cluster-config-file nodes_7001.conf
cluster-node-timeout 15000
cluster-migration-barrier 1
拷贝五份配置(至少要六个节点组集群)
cp conf/redis_7001.conf conf/redis_7002.confcp conf/redis_7001.conf conf/redis_7003.confcp conf/redis_7001.conf conf/redis_7004.confcp conf/redis_7001.conf conf/redis_7005.confcp conf/redis_7001.conf conf/redis_7006.conf
替换端口
sed -i 's/7001/7002/g' conf/redis_7002.confsed -i 's/7001/7003/g' conf/redis_7003.confsed -i 's/7001/7004/g' conf/redis_7004.confsed -i 's/7001/7005/g' conf/redis_7005.confsed -i 's/7001/7006/g' conf/redis_7006.conf
启动脚本 start_redis.sh
REDIS_HOME=/var/local/redis-6.2.7
$REDIS_HOME/bin/redis-server $REDIS_HOME/conf/redis_7001.conf &
sleep 1s
$REDIS_HOME/bin/redis-server $REDIS_HOME/conf/redis_7002.conf &
sleep 1s
$REDIS_HOME/bin/redis-server $REDIS_HOME/conf/redis_7003.conf &
sleep 1s
$REDIS_HOME/bin/redis-server $REDIS_HOME/conf/redis_7004.conf &
sleep 1s
$REDIS_HOME/bin/redis-server $REDIS_HOME/conf/redis_7005.conf &
sleep 1s
$REDIS_HOME/bin/redis-server $REDIS_HOME/conf/redis_7006.conf &
配置集群
bin/redis-cli -a xxxwoaixuexi.. --cluster create --cluster-replicas 1 10.65.132.113:7001 10.65.132.113:7002 10.65.132.113:7003 10.65.132.113:7004 10.65.132.113:7005 10.65.132.113:7006