佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > Centos7 Redis主從搭建配置的實(shí)現(xiàn)

Centos7 Redis主從搭建配置的實(shí)現(xiàn)

熱門標(biāo)簽:呼叫中心市場(chǎng)需求 Linux服務(wù)器 百度競(jìng)價(jià)排名 AI電銷 服務(wù)外包 鐵路電話系統(tǒng) 網(wǎng)站排名優(yōu)化 地方門戶網(wǎng)站

一、環(huán)境介紹

Redis—master   172.18.8.19
Redis—slave   172.18.8.20

二、redis主的配置

#創(chuàng)建redis數(shù)據(jù)目錄
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從配置

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   -----從庫(kù)比主庫(kù)多這2行配置參數(shù)
masterauth Allwelltokok   -----從庫(kù)比主庫(kù)多這2行配置參數(shù)
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啟動(dòng)腳本

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

五、啟動(dòng)服務(wù)

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

查看日志

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  

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • 一篇文章讓你明白R(shí)edis主從同步
  • redis的主從配置方法詳解
  • Redis的主從同步解析
  • PHP實(shí)現(xiàn)的redis主從數(shù)據(jù)庫(kù)狀態(tài)檢測(cè)功能示例
  • Redis主從實(shí)現(xiàn)讀寫(xiě)分離
  • Redis教程(九):主從復(fù)制配置實(shí)例
  • Redis主從復(fù)制問(wèn)題和擴(kuò)容問(wèn)題的解決思路
  • WINDOWS中REDIS主從配置實(shí)現(xiàn)代碼解析

標(biāo)簽:黃山 湖南 衡水 湘潭 銅川 仙桃 蘭州 崇左

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Centos7 Redis主從搭建配置的實(shí)現(xiàn)》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    海淀区| 西城区| 阿合奇县| 界首市| 左贡县| 武鸣县| 旬邑县| 南昌市| 万荣县| 邢台市| 和林格尔县| 琼海市| 张家口市| 普兰店市| 阳新县| 和田县| 普定县| 莱芜市| 巴林左旗| 云霄县| 新绛县| 昂仁县| 资中县| 桐柏县| 界首市| 金溪县| 星座| 青田县| 光泽县| 吉隆县| 永康市| 宿迁市| 奎屯市| 百色市| 当雄县| 湄潭县| 周至县| 思南县| 潮安县| 山东| 林州市|