1.解压redis
tar -xvf redis-3.2.11.tar.gz
cd redis-3.2.11
make
“如果make有报错,则执行,没有报错就不需要 make MALLOC=libc ”
配置redis主从
主:0.0.0.0:6379
从:0.0.0.0:6380
从:0.0.0.0:6381
主Redis配置
cp -r redis-3.2.11 /usr/local/redis-1
修改redis.conf文件
Cd /usr/local/redis-1
Vim redis.conf
redis.conf
#下面是redis.conf的主 要配置参数的意义:
#daemonize:是否以后台daemon方式运行
#pidfile:pid文件位置
#port:监听的端口号
#timeout:请求超时时间
#loglevel:log信息级别
#logfile:log文件位置
#databases:开启数据库的数量
#save * *:保存快照的频率,第一个*表示多长时间,第三个*表示执行多少次写操作。在一定时间内执行一定数量的写操作时,自动保存快照。可设置多个条件。
#rdbcompression:是否使用压缩
#dbfilename:数据快照文件名(只是文件名,不包括目录)
#dir:数据快照的保存目录(这个是目录)
#appendonly:是否开启appendonlylog,开启的话每次写操作会记一条log,这会提高数据抗风险能力,但影响效率。
#appendfsync:appendonlylog如何同步到磁盘(三个选项,分别是每次写都强制调用fsync、每秒启用一次fsync、不调用fsyn
c等待系统自己同步)
daemonize yes
bind 0.0.0.0
pidfile "/var/run/redis_1.pid"
port 6379
maxclients 10000
tcp-backlog 511
timeout 300
tcp-keepalive 0
loglevel warning
maxmemory 80gb
logfile "/var/log/redis-01.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/redis1/dir"
slave-serve-stale-data yes
slave-read-only yes
repl-disable-tcp-nodelay no
slave-priority 100
appendonly no
#appendfilename "appendonly.aof"
appendfsync no
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
lua-time-limit 5000
slowlog-log-slower-than 5000
slowlog-max-len 128
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 64mb60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
# Generated by CONFIG REWRITE
从Redis配置
cp -r redis2 /usr/local/redis-2
修改redis.conf文件
Cd /usr/local/redis-2
Vim redis.conf
daemonize yes
bind 0.0.0.0
pidfile "/var/run/redis2.pid"
port 6380
maxclients 10000
tcp-backlog 511
timeout 300
tcp-keepalive 0
loglevel warning
maxmemory 80gb
logfile "/var/log/redis-02.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-2/dir"
slave-serve-stale-data yes
slave-read-only yes
repl-disable-tcp-nodelay no
slave-priority 100
appendonly no
#appendfilename "appendonly.aof"
appendfsync no
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
lua-time-limit 5000
slowlog-log-slower-than 5000
slowlog-max-len 128
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 64mb60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
# Generated by CONFIG REWRITE
slaveof 127.0.0.1 6379
从Redis配置
cp -r redis-3.2.11 /usr/local/redis-3
修改redis.conf文件
Cd /usr/local/redis-3
Vim redis.conf
daemonize yes
bind 0.0.0.0
pidfile "/var/run/redis3.pid"
port 6381
maxclients 10000
tcp-backlog 511
timeout 300
tcp-keepalive 0
loglevel warning
maxmemory 80gb
logfile "/var/log/redis-03.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-3/dir"
slave-serve-stale-data yes
slave-read-only yes
repl-disable-tcp-nodelay no
slave-priority 100
appendonly no
#appendfilename "appendonly.aof"
appendfsync no
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
lua-time-limit 5000
slowlog-log-slower-than 5000
slowlog-max-len 128
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 64mb60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
# Generated by CONFIG REWRITE
slaveof 127.0.0.1 6379
启动redis
/usr/local/redis-1/src/redis-server/usr/local/redis-1/redis.conf
/usr/local/redis-2/src/redis-server/usr/local/redis-2/redis.conf
/usr/local/redis-3/src/redis-server/usr/local/redis-3/redis.conf
登入redis
主
/usr/local/redis-1/src/redis-cli-h 127.0.0.1 –p 6379
从
/usr/local/redis-2/src/redis-cli-h 127.0.0.1 –p 6380
从
/usr/local/redis-3/src/redis-cli-h 127.0.0.1 –p 6381
测试数据
在主redis执行
set name person
get name
在从redis执行
get name
在从redis执行
get name