cat >> /etc/sysctl.conf<
cat >>/etc/security/limits.conf<<EOF
- soft nproc 65535
- hard nproc 65535
- soft nofile 65535
- hard nofile 65535
EOF
sysctl -p
cat /etc/sysctl.conf
cat /etc/security/limits.conf
1、安装redis(3台)
wget http://download.redis.io/releases/redis-4.0.8.tar.gz
cd /usr/local/
tar xzvf /root/redis-4.0.8.tar.gz
cd redis-4.0.8
make
cd src
make install PREFIX=/usr/local/redis
mkdir /data/redis/log -p
mkdir /data/redis/conf -p
mkdir /data/redis/rdb -p
mkdir /data/redis/run -p
mkdir /data/redis/redis_sentinels -p
cd …
cp redis.conf /usr/local/redis
cd src
cp redis-server /usr/local/redis
cp redis-benchmark /usr/local/redis
cp redis-cli /usr/local/redis
cd /usr/local/redis
cd /usr/local/redis/bin/
cp redis-server /bin/
cp redis-cli /bin/
cd /usr/local/redis-4.0.8/src
cp redis-trib.rb /bin/
2.撰写redis配置文件(2台)
vi /data/redis/conf/redis6379.conf
bind 0.0.0.0
daemonize yes
pidfile "/data/redis/run/redis-6379.pid"
port 6379
tcp-backlog 511
timeout 300
tcp-keepalive 0
loglevel notice
logfile "/data/redis/log/redis-6379.log"
maxmemory 10gb #内存的5/8
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename "dump-6379.rdb"
dir "/data/redis/rdb"
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
appendonly yes
appendfilename "redis-6379.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
#cluster-enabled yes
#cluster-config-file nodes-6379.conf
#cluster-node-timeout 15000
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
# Generated by CONFIG REWRITE
masterauth "mypassword"
requirepass "mypassword"
3.撰写sentinel配置文件(2台)
vi /data/redis/conf/redis-sentinel6379.conf
daemonize yes
port 26379
dir "/data/redis/redis_sentinels"
pidfile "/data/redis/run/sentinel6379.pid"
logfile "/data/redis/redis_sentinels/sentinel6379.log"
protected-mode no
sentinel monitor master6379 10.18.30.43 6379 2 #主ip
sentinel client-reconfig-script master6379 /opt/notify_master6379.sh
sentinel auth-pass master6379 mypassword
sentinel config-epoch master6379 1
4.撰写漂移VIP的脚本(2台)
vi /opt/notify_master6379.sh
#!/bin/bash
MASTER_IP=$6
LOCAL_IP='10.18.33.91' #从库修改为10.18.33.92
VIP='10.18.33.247'
NETMASK='24'
INTERFACE='eth0'
if [ ${MASTER_IP} = ${LOCAL_IP} ]; then
/sbin/ip addr add ${VIP}/${NETMASK} dev ${INTERFACE}
/sbin/arping -q -c 3 -A ${VIP} -I ${INTERFACE}
exit 0
else
/sbin/ip addr del ${VIP}/${NETMASK} dev ${INTERFACE}
exit 0
fi
exit 1
chmod +x /opt/notify_master6379.sh
5.开放端口 6379 26379(3台)
6.启动redis服务(2台)
/usr/local/redis/redis-server /data/redis/conf/redis6379.conf
7.初始化主从(从库执行)
/usr/local/redis/redis-cli -p 6379 -a mypassword slaveof 10.18.33.91 6379
8.绑定VIP到主库
/sbin/ip addr add 10.18.33.247/24 dev eth0
9.启动sentinel服务(3台)
/usr/local/redis/redis-server /data/redis/conf/redis-sentinel6379.conf --sentinel
10.检查replication与Sentinel是否配置成功
/usr/local/redis/redis-cli -h 10.18.33.91 -p 6379 -a mypassword info Replication
/usr/local/redis/redis-cli -h 10.18.33.91 -p 26379 -a mypassword info Sentinel
10:验证是否实现了高可用
/usr/local/redis/redis-cli -h 10.18.33.91 -p 6379 -a mypassword shutdown
/usr/local/redis/redis-cli -h 10.18.33.92 -p 6379 -a mypassword info Replication
/usr/local/redis/redis-cli -h 10.18.33.91 -p 26379 -a mypassword info Sentinel