服务器之家:专注于服务器技术及软件下载分享
分类导航

Mysql|Sql Server|Oracle|Redis|MongoDB|PostgreSQL|Sqlite|DB2|mariadb|Access|数据库技术|

服务器之家 - 数据库 - Redis - Centos7 Redis主从搭建配置的实现

Centos7 Redis主从搭建配置的实现

2019-11-15 16:18Lancger Redis

这篇文章主要介绍了Centos7 Redis主从搭建配置的实现,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

一、环境介绍

Redis—master   172.18.8.19
Redis—slave   172.18.8.20

二、redis主的配置

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#创建redis数据目录
mkdir -p /data0/redis_trade
 
#redis主配置文件
root># cat redis_6379.conf |grep -Ev "^$|^#"
bind 172.18.8.19
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile "/var/log/redis_6379.log"
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 /data0/redis_trade
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
requirepass Allwelltokok
appendonly yes
appendfilename "appendonly_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
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-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
rename-command FLUSHALL ZYzv6FOBdwflW2nX
rename-command EVAL S9UHPKEpSvUJMM
rename-command FLUSHDB D60FPVDJuip7gy6l
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

三、redis从配置

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
root># cat redis_6379.conf |grep -Ev "^$|^#"
bind 172.18.8.20
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile "/var/log/redis_6379.log"
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 /data0/redis_trade
slaveof 172.18.8.19 6379   -----从库比主库多这2行配置参数
masterauth Allwelltokok   -----从库比主库多这2行配置参数
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
requirepass Allwelltokok
appendonly yes
appendfilename "appendonly_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
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-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
rename-command FLUSHALL ZYzv6FOBdwflW2nX
rename-command EVAL S9UHPKEpSvUJMM
rename-command FLUSHDB D60FPVDJuip7gy6l
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

四、redis启动脚本

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
root># cat /etc/init.d/redis_6379
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
# chkconfig:  2345 90 10
 
source /etc/init.d/functions
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
 
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/usr/local/redis/etc/redis_${REDISPORT}.conf"
AUTH="Allwelltokok"
BIND_IP='172.18.8.19'
 
start(){
   
  if [ -f $PIDFILE ]
  then
    echo "$PIDFILE exists, process is already running or crashed"
  else
    echo "Starting Redis server..."
    $EXEC $CONF
  fi
  if [ "$?"="0" ]
  then
    echo "Redis is running..."
  fi
 
 
}
 
stop(){
 
  if [ ! -f $PIDFILE ]
  then
    echo "$PIDFILE does not exist, process is not running"
  else
    PID=$(cat $PIDFILE)
    echo "Stopping ..."
    $CLIEXEC -h $BIND_IP -a $AUTH -p $REDISPORT SHUTDOWN
    sleep 1
    while [ -x /proc/${PID} ]
    do
      echo "Waiting for Redis to shutdown ..."
      sleep 1
    done
      echo "Redis stopped"
  fi
}
 
restart(){
  stop
  start
 
}
status(){
 
  ps -ef|grep redis-server|grep -v grep >/dev/null 2>&1
 
  if [ $? -eq 0 ];then
 
    echo "redis server is running"
 
  else
    echo "redis server is stopped"
 
  fi
   
 
}
 
 
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
     
  restart)
    restart
    ;;
     
  status)
    status
    ;;  
  *)
   
   echo "Usage: /etc/init.d/redis {start|stop|status|start}" >&2
   exit 1
esac

五、启动服务

?
1
root># /etc/init.d/redis_6379 start 

查看日志

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
root># tail -100f /var/log/redis_6379.log
5563:S 29 Jun 22:14:23.236 * Increased maximum number of open files to 10032 (it was originally set to 1024).
        _._                        
      _.-``__ ''-._                      
   _.-``  `. `_. ''-._      Redis 3.2.12 (00000000/0) 64 bit
 .-`` .-```. ```\/  _.,_ ''-._                 
 '   ,    .-` | `,  )   Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|   Port: 6379
 |  `-._  `._  /   _.-'  |   PID: 5563
 `-._  `-._ `-./ _.-'  _.-'                 
 |`-._`-._  `-.__.-'  _.-'_.-'|                
 |  `-._`-._    _.-'_.-'  |      http://redis.io   
 `-._  `-._`-.__.-'_.-'  _.-'                 
 |`-._`-._  `-.__.-'  _.-'_.-'|                
 |  `-._`-._    _.-'_.-'  |                
 `-._  `-._`-.__.-'_.-'  _.-'                 
   `-._  `-.__.-'  _.-'                   
     `-._    _.-'                     
       `-.__.-'                       
 
5563:S 29 Jun 22:14:23.237 # Server started, Redis version 3.2.12
5563:S 29 Jun 22:14:23.237 * The server is now ready to accept connections on port 6379
5563:S 29 Jun 22:14:23.237 * Connecting to MASTER 172.18.8.19:6379
5563:S 29 Jun 22:14:23.237 * MASTER <-> SLAVE sync started
5563:S 29 Jun 22:14:23.237 * Non blocking connect for SYNC fired the event.
5563:S 29 Jun 22:14:23.238 * Master replied to PING, replication can continue...
5563:S 29 Jun 22:14:23.238 * Partial resynchronization not possible (no cached master)
5563:S 29 Jun 22:14:23.239 * Full resync from master: c9f303069f87253011bf39369366732a2e88b389:1
5563:S 29 Jun 22:14:23.304 * MASTER <-> SLAVE sync: receiving 77 bytes from master
5563:S 29 Jun 22:14:23.305 * MASTER <-> SLAVE sync: Flushing old data
5563:S 29 Jun 22:14:23.305 * MASTER <-> SLAVE sync: Loading DB in memory
5563:S 29 Jun 22:14:23.305 * MASTER <-> SLAVE sync: Finished with success
5563:S 29 Jun 22:14:23.305 * Background append only file rewriting started by pid 5567
5563:S 29 Jun 22:14:23.329 * AOF rewrite child asks to stop sending diffs.
5567:C 29 Jun 22:14:23.329 * Parent agreed to stop sending diffs. Finalizing AOF...
5567:C 29 Jun 22:14:23.329 * Concatenating 0.00 MB of AOF diff received from parent.
5567:C 29 Jun 22:14:23.329 * SYNC append only file rewrite performed
5567:C 29 Jun 22:14:23.330 * AOF rewrite: 0 MB of memory used by copy-on-write
5563:S 29 Jun 22:14:23.337 * Background AOF rewrite terminated with success
5563:S 29 Jun 22:14:23.337 * Residual parent diff successfully flushed to the rewritten AOF (0.00 MB)
5563:S 29 Jun 22:14:23.337 * Background AOF rewrite finished successfully 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://segmentfault.com/a/1190000015432869

延伸 · 阅读

精彩推荐
  • RedisRedis的配置、启动、操作和关闭方法

    Redis的配置、启动、操作和关闭方法

    今天小编就为大家分享一篇Redis的配置、启动、操作和关闭方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧 ...

    大道化简5312019-11-14
  • RedisRedis 事务知识点相关总结

    Redis 事务知识点相关总结

    这篇文章主要介绍了Redis 事务相关总结,帮助大家更好的理解和学习使用Redis,感兴趣的朋友可以了解下...

    AsiaYe8232021-07-28
  • Redisredis实现排行榜功能

    redis实现排行榜功能

    排行榜在很多地方都能使用到,redis的zset可以很方便地用来实现排行榜功能,本文就来简单的介绍一下如何使用,具有一定的参考价值,感兴趣的小伙伴们...

    乘月归5022021-08-05
  • Redis详解Redis复制原理

    详解Redis复制原理

    与大多数db一样,Redis也提供了复制机制,以满足故障恢复和负载均衡等需求。复制也是Redis高可用的基础,哨兵和集群都是建立在复制基础上实现高可用的...

    李留广10222021-08-09
  • RedisRedis全量复制与部分复制示例详解

    Redis全量复制与部分复制示例详解

    这篇文章主要给大家介绍了关于Redis全量复制与部分复制的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用Redis爬虫具有一定的参考学习...

    豆子先生5052019-11-27
  • RedisRedis如何实现数据库读写分离详解

    Redis如何实现数据库读写分离详解

    Redis的主从架构,能帮助我们实现读多,写少的情况,下面这篇文章主要给大家介绍了关于Redis如何实现数据库读写分离的相关资料,文中通过示例代码介绍...

    罗兵漂流记6092019-11-11
  • Redisredis中如何使用lua脚本让你的灵活性提高5个逼格详解

    redis中如何使用lua脚本让你的灵活性提高5个逼格详解

    这篇文章主要给大家介绍了关于redis中如何使用lua脚本让你的灵活性提高5个逼格的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具...

    一线码农5812019-11-18
  • Redisredis 交集、并集、差集的具体使用

    redis 交集、并集、差集的具体使用

    这篇文章主要介绍了redis 交集、并集、差集的具体使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友...

    xiaojin21cen10152021-07-27