三台linux服务器
比如:
主:X.X.X.81
从:X.X.X.82
从:X.X.X.83
1)安装redis之前先要安装gcc-c++和tcl
yum install gcc-c++
yum install tcl
2)新建用户redis
groupadd redis
useradd –g redis
passwd redis (输入密码)
3)新建文件夹u01
mkdir /u01
cd /u01
4)上传redis压缩包到服务器
授权给用户redis
chown redis:redis redis-4.0.1.tar.gz
chmod 777 –R /u01
su – redis
tar -zxvf redis-4.0.1.tar.gz
在redis目录下新建temp,run,logs目录
编译redis
make
make test
进入到reids目录
vi reids.conf
找到bind 127.0.0.1将其注解掉
已上步骤三个redis服务器都是一样的操作
下面开始配置redis
主服务器(81):
进入到redis目录
分别新建redis_6379.conf和6379_sentinel.conf文件
redis_6379.conf配置
include /u01/redis-4.0.1/redis.conf
###################################################
# HAND Properties
###################################################
##### Security #####
protected-mode no
masterauth password #这里设置密码
requirepass password #这里设置密码 和上面一样
##### Basic #####
port 6379
daemonize yes
pidfile "/u01/redis-4.0.1/run/redis_6379.pid"
loglevel notice
logfile "/u01/redis-4.0.1/logs/redis.log"
maxclients 4096
maxmemory-policy noeviction
tcp-backlog 511
##### Persistence #####
save ""
dbfilename dump.rdb
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
auto-aof-rewrite-percentage 0
auto-aof-rewrite-min-size 0
dir "/u01/redis-4.0.1/temp"
##### Replication #####
slave-priority 10
min-slaves-to-write 1
min-slaves-max-lag 3
6379_sentinel.conf配置
protected-mode no
port 26379
dir "/tmp"
logfile " /u01/redis-4.0.1/logs /sentinel.log"
sentinel monitor mymaster X.X.X.81 6379 2
sentinel auth-pass mymaster password
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 60000
从服务器(82和83):
分别新建redis_6379.conf和sentinel_26379.conf文件
redis_6379.conf配置(redis.conf 中bind 127.0.0.1要注解掉)
include /u01/redis-4.0.1/redis.conf
###################################################
# HAND Properties
###################################################
##### Security #####
protected-mode no
masterauth password
requirepass password
##### Basic #####
port 6379
daemonize yes
pidfile "/u01/redis-4.0.1/run/redis_6379.pid"
loglevel notice
logfile "/u01/redis-4.0.1/logs/redis.log"
maxclients 4096
maxmemory-policy noeviction
tcp-backlog 511
##### Persistence #####
save ""
dbfilename dump.rdb
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
auto-aof-rewrite-percentage 0
auto-aof-rewrite-min-size 0
dir "/u01/redis-4.0.1/temp"
##### Replication #####
slave-priority 10
min-slaves-to-write 1
min-slaves-max-lag 3
slaveof 10.10.17.81 6379
sentinel_26379.conf配置
protected-mode no
port 26379
dir "/tmp"
logfile " /u01/redis-4.0.1/logs /sentinel.log"
sentinel monitor mymaster X.X.X.81 6379 2
sentinel auth-pass mymaster password
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 60000
开启防护墙
root用户登录三个主从服务器
vi /etc/sysconfig/iptables添加下面两句话开启6379和26379端口
-A INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 26379 -j ACCEPT
重启防护墙
service iptables restart
启动redis,注意redis启动顺序是很重要的,先主后从
主服务器:
cd /u01/redis-4.0.1
src/redis-server ./redis_6379.conf
src/redis-sentinel ./6379_sentinel.conf
从服务器
cd /u01/redis-4.0.1
src/redis-server ./redis_6379.conf
src/redis-sentinel ./sentinel_26379.conf