redis 主從,基於sentinel 自動切換
#gcc
yum install gcc -y
#授權
chmod -R 777 /usr/local/bin
mkdir redis
cd redis/
wget http://download.redis.io/releases/redis-3.2.1.tar.gz
tar -zxvf redis-3.2.1.tar.gz
cd redis-3.2.1
make MALLOC=libc
make install
cd ..
mkdir redis-cluster
cd redis-cluster/
mkdir 7000 7001 7002
cp ../redis-3.2.1/redis.conf ./7000/
vi ./7000/redis.conf
bind 0.0.0.0
port 7000 //埠7000
daemonize yes //redis後臺執行
pidfile /var/run/redis_7000.pid //pidfile檔案對應7000
appendonly yes
#啟動
/home/xxx/redis/redis-3.2.1/src/redis-server /home/xxx/redis/redis-cluster/7000/redis.conf
#另外兩臺機子,重複上面步驟
/home/xxx/redis/redis-3.2.1/src/redis-server /home/xxx/redis/redis-cluster/7003/redis.conf
/home/xxx/redis/redis-3.2.1/src/redis-server /home/xxx/redis/redis-cluster/7006/redis.conf
#redis 主從
#在從伺服器配置主的地址和埠
slaveof 192.168.1.40 7000
#客戶端連結
/home/xxx/redis/redis-3.2.1/src/redis-cli -p 7000
#服務端資訊
info replication
#哨兵配置
mkdir /home/xxx/redis/sentinel
cd /home/xxx/redis/sentinel
cp /home/xxx/redis/redis-3.2.1/sentinel.conf /home/xxx/redis/sentinel/
#新建檔案,最後的2表示哨兵最低通過票數
vi sentinel.conf
bind 0.0.0.0
sentinel monitor mymaster 192.168.1.40 7000 2
#啟動哨兵
/home/xxx/redis/redis-3.2.1/src/redis-sentinel /home/xxx/redis/sentinel/sentinel.conf