redis主从搭建测试

8 篇文章 1 订阅
3 篇文章 0 订阅

redis安装和主从搭建都非常简单,记录一下测试搭建过程。

一、 准备工作

1. 创建相关目录

mkdir -p /data/redis/{base,home,tools}
mkdir -p /data/redis/rd6380/{conf,datafile,log}
mkdir -p /data/redis/tools/{bin,etc}

2. 下载redis软件

Download | Redis

3. 安装依赖包

yum -y install gcc gcc-c++ libstdc++-devel tcl

必须要先装,否则make编译会遇到类似以下报错

[root@redis01 redis-4.0.10]# make PREFIX=/root/redis-4.0.10
cd src && make all
make[1]: Entering directory `/root/redis-4.0.10/src'
    CC Makefile.dep
make[1]: Leaving directory `/root/redis-4.0.10/src'
make[1]: Entering directory `/root/redis-4.0.10/src'
    CC adlist.o
/bin/sh: cc: command not found
make[1]: *** [adlist.o] Error 127
make[1]: Leaving directory `/root/redis-4.0.10/src'
make: *** [all] Error 2

另外如果是报了上面的错之后才安装依赖包,需要先清理上次编译残留文件,然后再重新编译

make distclean

如果没清理直接编译可能会遇到以下报错

fatal error: jemalloc/jemalloc.h: No such file or directory

二、 redis安装

1. 解压软件

tar -zxvf redis-4.0.12.tar.gz

2. 进行编译

cd redis-4.0.12
make PREFIX=/解压目录/redis-4.0.12

cd src
make install

3. 复制命令到规范目录

cp /解压目录/src/redis* /data/redis/tools/bin/

三、 编辑主库参数文件

cd /data/redis/rd6380/conf
vi redis.conf

需改参数:端口号、密码、从库ip(没有则忽略)、内存大小

daemonize yes
pidfile /var/run/redis.6380.pid
port 6380
timeout 300
tcp-keepalive 60
loglevel notice
logfile  /data/redis/rd6380/log/redis.log
# syslog-enabled no
# syslog-ident redis
# syslog-facility local0
databases 16
# save ""
 save 900 1
 save 300 10
 save 60 10000
stop-writes-on-bgsave-error no
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /data/redis/rd6380/datafile/
#slaveof ip 6380
#masterauth 密码
slave-serve-stale-data yes
slave-read-only yes
# repl-ping-slave-period 10
repl-timeout 600
repl-disable-tcp-nodelay no
repl-backlog-size 64mb
# repl-backlog-ttl 3600
slave-priority 100
# min-slaves-to-write 3
# min-slaves-max-lag 10
requirepass 密码
# rename-command CONFIG ""
maxclients 10000
maxmemory 4000000000
maxmemory-policy noeviction
# maxmemory-samples 3
appendonly yes
# appendfsync always
appendfsync everysec
# 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 20000
protected-mode no
slowlog-max-len 128
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth  0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 8192mb 4096mb 600
client-output-buffer-limit pubsub 32mb 8mb 60
lazyfree-lazy-server-del yes
aof-rewrite-incremental-fsync yes

四、 启动redis

redis-server /data/redis/rd6380/conf/redis.conf

五、 从库搭建

一二步同主库

1. 编辑从库参数文件

daemonize yes
pidfile /var/run/redis.6380.pid
port 6380
timeout 300
tcp-keepalive 60
loglevel notice
logfile  /data/redis/rd6380/log/redis.log
# syslog-enabled no
# syslog-ident redis
# syslog-facility local0
databases 16
# save ""
 save 900 1
 save 300 10
 save 60 10000
stop-writes-on-bgsave-error no
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /data/redis/rd6380/datafile
slaveof 主库ip 主库端口
masterauth 密码
slave-serve-stale-data yes
slave-read-only yes
# repl-ping-slave-period 10
repl-timeout 600
repl-disable-tcp-nodelay no
repl-backlog-size 64mb
# repl-backlog-ttl 3600
slave-priority 100
# min-slaves-to-write 3
# min-slaves-max-lag 10
requirepass 密码
# rename-command CONFIG ""
maxclients 10000
maxmemory 4000000000
maxmemory-policy noeviction
# maxmemory-samples 3
appendonly yes
# appendfsync always
appendfsync everysec
# 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 20000
protected-mode no
slowlog-max-len 128
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth  0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 8192mb 4096mb 600
client-output-buffer-limit pubsub 32mb 8mb 60
lazyfree-lazy-server-del yes
aof-rewrite-incremental-fsync yes

2. 启动redis

redis-server /data/redis/rd6380/conf/redis.conf

3. 主从同步检测

主库插入数据

[root@db03 redis]# redis-cli -p 6380
127.0.0.1:6380> AUTH 密码
OK
127.0.0.1:6380> set a 666
OK
127.0.0.1:6380> get a
"666"

从库检测

[root@db04 conf]# redis-cli -p 6380
127.0.0.1:6380> auth 密码
OK
127.0.0.1:6380> get a
"666"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Hehuyi_In

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值