本文共 2958 字,大约阅读时间需要 9 分钟。
## 实验在一台机器上允许,搭建redis一主两从,创建哨兵模式监控## 整个脚本直接执行即可,确认root权限执行## 下载目录mkdir /opt/softcd /opt/soft## 下载软件 wget -O redis-2.8.22.tar.gz https://codeload.github.com/antirez/redis/tar.gz/2.8.22## 解压redistar -xf redis-2.8.22.tar.gzcd redis-2.8.22## 编译安装make PREFIX=/usr/local/redismake install PREFIX=/usr/local/redis## 创建基本的目录,这里做1主两从6379是主,其它两个是从mkdir -p /usr/local/redis/etccd /usr/local/redis/etc/mkdir -p /usr/local/redis/etc/6379 ## ------ 开始创建6379主库cd /usr/local/redis/etc/6379## 6379 配置文件cat > redis.conf << EOF## redis passwordrequirepass pass123## 主密码masterauth pass123## 后台运行daemonize yespidfile /usr/local/redis/etc/6379/redis.pid## 端口port 6379tcp-backlog 511timeout 0tcp-keepalive 0loglevel noticelogfile "/usr/local/redis/etc/6379/redis.log"databases 16save 900 1save 300 10save 60 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump.rdbdir /usr/local/redis/etc/6379/cacheslave-serve-stale-data yes## 从库只读slave-read-only yesrepl-disable-tcp-nodelay noslave-priority 10## 开aofappendonly yesappendfilename "appendonly.aof"appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yeslua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events ""hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-entries 512list-max-ziplist-value 64set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yesEOFcd /usr/local/redis/etc/6379## sentinel配置文件cat > sentinel.conf << EOF# sentinel运行端口port 26379# 监控主机 端口 如果sentinel两次判断失败则转移请求sentinel monitor def_master 127.0.0.1 6379 2# 超时时间 900 秒sentinel failover-timeout def_master 900000# master 密码sentinel auth-pass def_master cF03b7db40E654aEB3sentinel config-epoch def_master 0sentinel leader-epoch def_master 0EOFcd /usr/local/redis/etc## 复制两份修改成从库分别用端口 6380 6381scp /usr/local/redis/etc/6379 /usr/local/redis/etc/6380cd /usr/local/redis/etc/6380sed -i "s#6379#6380#g" redis.confsed -i 's#26379#26380#' sentinel.confecho 'slaveof 127.0.0.1 6379' >> redis.confscp /usr/local/redis/etc/6379 /usr/local/redis/etc/6381cd /usr/local/redis/etc/6381sed -i "s#6379#6381#g" redis.confsed -i 's#26379#26381#' sentinel.confecho 'slaveof 127.0.0.1 6379' >> redis.conf### 到这里基本环境就搭建完成,现在启动环境### 启动master /usr/local/redis/bin/redis-server /usr/local/redis/etc/6379/redis.conf### 启动两个从库 /usr/local/redis/bin/redis-server /usr/local/redis/etc/6380/redis.conf /usr/local/redis/bin/redis-server /usr/local/redis/etc/6381/redis.conf### 启动哨兵 /usr/local/redis/bin/redis-server /usr/local/redis/etc/6379/sentinel.conf#### 到这里安装完成
转载于:https://blog.51cto.com/arlen/1696277