## 实验在一台机器上允许,搭建redis一主两从,创建哨兵模式监控 ## 整个脚本直接执行即可,确认root权限执行 ## 下载目录 mkdir /opt/soft cd /opt/soft ## 下载软件 wget -O redis-2.8.22.tar.gz https://codeload.github.com/antirez/redis/tar.gz/2.8.22## 解压redis tar -xf redis-2.8.22.tar.gz cd redis-2.8.22 ## 编译安装 make PREFIX=/usr/local/redis make install PREFIX=/usr/local/redis ## 创建基本的目录,这里做1主两从6379是主,其它两个是从 mkdir -p /usr/local/redis/etc cd /usr/local/redis/etc/ mkdir -p /usr/local/redis/etc/6379 ## ------ 开始创建6379主库 cd /usr/local/redis/etc/6379 ## 6379 配置文件 cat > redis.conf << EOF ## redis password requirepass pass123 ## 主密码 masterauth pass123 ## 后台运行 daemonize yes pidfile /usr/local/redis/etc/6379/redis.pid ## 端口 port 6379 tcp-backlog 511 timeout 0 tcp-keepalive 0 loglevel notice logfile "/usr/local/redis/etc/6379/redis.log" databases 16 save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename dump.rdb dir /usr/local/redis/etc/6379/cache slave-serve-stale-data yes ## 从库只读 slave-read-only yes repl-disable-tcp-nodelay no slave-priority 10 ## 开aof appendonly yes appendfilename "appendonly.aof" appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb aof-load-truncated yes lua-time-limit 5000 slowlog-log-slower-than 10000 slowlog-max-len 128 latency-monitor-threshold 0 notify-keyspace-events "" hash-max-ziplist-entries 512 hash-max-ziplist-value 64 list-max-ziplist-entries 512 list-max-ziplist-value 64 set-max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value 64 hll-sparse-max-bytes 3000 activerehashing yes client-output-buffer-limit normal 0 0 0 client-output-buffer-limit slave 256mb 64mb 60 client-output-buffer-limit pubsub 32mb 8mb 60 hz 10 aof-rewrite-incremental-fsync yes EOF cd /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 cF03b7db40E654aEB3 sentinel config-epoch def_master 0 sentinel leader-epoch def_master 0 EOF cd /usr/local/redis/etc ## 复制两份修改成从库分别用端口 6380 6381 scp /usr/local/redis/etc/6379 /usr/local/redis/etc/6380 cd /usr/local/redis/etc/6380 sed -i "s#6379#6380#g" redis.conf sed -i ‘s#26379#26380#‘ sentinel.conf echo ‘slaveof 127.0.0.1 6379‘ >> redis.conf scp /usr/local/redis/etc/6379 /usr/local/redis/etc/6381 cd /usr/local/redis/etc/6381 sed -i "s#6379#6381#g" redis.conf sed -i ‘s#26379#26381#‘ sentinel.conf echo ‘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 #### 到这里安装完成
本文出自 “纳米龙” 博客,请务必保留此出处http://arlen.blog.51cto.com/7175583/1696277
原文地址:http://arlen.blog.51cto.com/7175583/1696277