Linux

Redisインストールから冗長化構成, Redis Sentinelによるフェイルオーバー CentOS6

 

 

# yum update


EPEL
# yum install epel-release

Installed:
  epel-release.noarch 0:6-8

Remi
# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

Retrieving http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
warning: /var/tmp/rpm-tmp.yrv4ED: Header V4 DSA/SHA1 Signature, key ID 00f97f56: NOKEY
Preparing...                ########################################### [100%]
   1:remi-release           ########################################### [100%]



 

# yum groupinstall "Development Tools" "Base"

# yum install wget unzip gcc gcc-c++ pcre-devel zlib-devel make wget openssl-devel libxml2 libxml2-devel libxslt-devel libxslt libxslt-devel gd-devel perl-ExtUtils-Embed GeoIP-devel gperftools-devel flex

重要
# yum install jemalloc

重要
# yum install --enablerepo=epel gperftools

Installed:
  gperftools.x86_64 0:2.0-11.el6.3

Dependency Installed:
  Xaw3d.x86_64 0:1.5E-15.1.el6       ghostscript.x86_64 0:8.70-21.el6_8.1         ghostscript-fonts.noarch 0:5.50-23.2.el6      graphviz.x86_64 0:2.26.0-10.el6      gv.x86_64 0:3.7.1-1.el6
  libXaw.x86_64 0:1.0.11-2.el6       libXfont.x86_64 0:1.5.1-2.el6                libXmu.x86_64 0:1.1.1-2.el6                   libfontenc.x86_64 0:1.1.2-3.el6      pprof.noarch 0:2.0-11.el6.3
  urw-fonts.noarch 0:2.4-11.el6      xorg-x11-font-utils.x86_64 1:7.2-11.el6

Complete!

 

 

# cd /usr/local/src

安定最新版ダウンロード ※@see https://redis.io/download
# wget http://download.redis.io/releases/redis-3.2.8.tar.gz

解凍します。
# tar xvzf redis-*.tar.gz

# cd redis-*

redis-3.2.8]# make && make install


Hint: It's a good idea to run 'make test' ;)

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
make[1]: Leaving directory `/usr/local/src/redis-3.2.8/src'

 

 

# mkdir /etc/redis

# mkdir -p /var/redis/6379

# cp utils/redis_init_script /etc/init.d/redis_6379

# cp redis.conf /etc/redis/6379.conf

 

 

# vi /etc/redis/6379.conf


daemonize no

↓変更

#daemonize no
daemonize yes


pidfile /var/run/redis_6379.pid



logfile ""

↓変更

#logfile ""
logfile /var/log/redis/redis_6379.log



dir ./

↓変更

#dir ./
dir /var/redis/6379

 

ログディレクトリ作成

# mkdir /var/log/redis

 

 

# vi /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.

※2行を追加する

# chkconfig: - 58 74
# description: redis_6379 is the redis daemon



好みでrestart機能もつけています。
# 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: - 58 74
# description: redis_6379 is the redis daemon.

REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"

start(){
    if [ -f $PIDFILE ]
    then
            echo "$PIDFILE exists, process is already running or crashed"
    else
            echo "Starting Redis server..."
            $EXEC $CONF
    fi
}
stop(){
    if [ ! -f $PIDFILE ]
    then
            echo "$PIDFILE does not exist, process is not running"
    else
            PID=$(cat $PIDFILE)
            echo "Stopping ..."
            $CLIEXEC -p $REDISPORT shutdown
            while [ -x /proc/${PID} ]
            do
                echo "Waiting for Redis to shutdown ..."
                sleep 1
            done
            echo "Redis stopped"
    fi
}

case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis server..."
                $EXEC $CONF
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $CLIEXEC -p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    restart)
        stop
        start
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac

 

 

# chkconfig --add redis_6379

# chkconfig redis_6379 on

# /etc/init.d/redis_6379 start

Starting Redis server...

 

# netstat -an | grep 6379
tcp        0      0 127.0.0.1:6379              0.0.0.0:*                   LISTEN

 

# redis-cli ping
PONG

 

バージョン確認

# redis-cli info | grep redis_version
redis_version:3.2.8

 

 

カーネルチューニング

 

# vi /etc/sysctl.conf



※下記を追記

#Redis用設定
vm.overcommit_memory = 1
net.core.somaxconn = 1024

 

# sysctl -p

net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
vm.overcommit_memory = 1 ←確認
net.core.somaxconn = 1024 ←確認

 

Transparent Huge Pages (THP) の無効化

# vi /etc/rc.local

# that this script will be executed during boot.

・
・
touch /var/lock/subsys/local


※以下を追記

#Redis用設定
echo never > /sys/kernel/mm/transparent_hugepage/enabled

 

# cat /etc/rc.local

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

#Redis用設定
echo never > /sys/kernel/mm/transparent_hugepage/enabled

 

実行権限付与

# chmod +x /etc/rc.d/rc.local

 

再起動

# reboot now

 

# tail -n 25 /var/log/redis/redis_6379.log

6037:M 13 Feb 19:08:55.807 * DB saved on disk
6037:M 13 Feb 19:08:55.807 * Removing the pid file.
6037:M 13 Feb 19:08:55.807 # Redis is now ready to exit, bye bye...
1483:M 13 Feb 19:14:22.924 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 3.2.8 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 1483
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

1483:M 13 Feb 19:14:22.927 # Server started, Redis version 3.2.8
1483:M 13 Feb 19:14:22.927 * DB loaded from disk: 0.001 seconds
1483:M 13 Feb 19:14:22.928 * The server is now ready to accept connections on port 6379

 

 

 

Redis冗長化

 

6379ポートを利用しているRedisをテンプレートに6381, 6382, 6383を作成します。

cp /etc/redis/6379.conf /etc/redis/6381.conf
cp /etc/redis/6379.conf /etc/redis/6382.conf
cp /etc/redis/6379.conf /etc/redis/6383.conf


sed -i -e "s/6379/6381/g" /etc/redis/6381.conf
sed -i -e "s/6379/6382/g" /etc/redis/6382.conf
sed -i -e "s/6379/6383/g" /etc/redis/6383.conf


mkdir -p /var/redis/6381
mkdir -p /var/redis/6382
mkdir -p /var/redis/6383


cp /etc/init.d/redis_6379 /etc/init.d/redis_6381
cp /etc/init.d/redis_6379 /etc/init.d/redis_6382
cp /etc/init.d/redis_6379 /etc/init.d/redis_6383


sed -i -e "s/6379/6381/g" /etc/init.d/redis_6381
sed -i -e "s/6379/6382/g" /etc/init.d/redis_6382
sed -i -e "s/6379/6383/g" /etc/init.d/redis_6383


chkconfig --add redis_6381
chkconfig --add redis_6382
chkconfig --add redis_6383

chkconfig redis_6380 on
chkconfig redis_6381 on
chkconfig redis_6382 on
chkconfig redis_6383 on


/etc/init.d/redis_6381 start
/etc/init.d/redis_6382 start
/etc/init.d/redis_6383 start

 

 

 

redis_6379をマスター。redis_6381, redis_6382, redis_6383をスレーブにします。

# redis-cli -p 6381 slaveof 127.0.0.1 6379
OK

# redis-cli -p 6382 slaveof 127.0.0.1 6379
OK

# redis-cli -p 6383 slaveof 127.0.0.1 6379
OK

 

# redis-cli -p 6379 info | grep role
role:master

# redis-cli -p 6381 info | grep role
role:slave

# redis-cli -p 6382 info | grep role
role:slave

# redis-cli -p 6383 info | grep role
role:slave

 

値の追加

# redis-cli -p 6379 set open-sesame Hello
OK

# redis-cli -p 6381 get open-sesame
"Hello"

レプリケート確認
# redis-cli -p 6382 get open-sesame
"Hello"

# redis-cli -p 6383 get open-sesame
"Hello"

 

値の削除

# redis-cli -p 6379 del open-sesame
(integer) 1

# redis-cli -p 6381 get open-sesame
(nil)

# redis-cli -p 6382 get open-sesame
(nil)

# redis-cli -p 6383 get open-sesame
(nil)

 

レプリケーション状態確認

# redis-cli -p 6379 info replication

# Replication
role:master
connected_slaves:1
slave0:ip=127.0.0.1,port=6381,state=online,offset=335,lag=0
master_repl_offset:335
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:334

 

 

# redis-cli -p 6381 info replication

# Replication
role:slave
master_host:127.0.0.1
master_port:6379
master_link_status:up
master_last_io_seconds_ago:5
master_sync_in_progress:0
slave_repl_offset:363
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:36548
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:36547

 

 

# redis-cli -p 6382 info replication

# Replication
role:slave
master_host:127.0.0.1
master_port:6379
master_link_status:up
master_last_io_seconds_ago:5
master_sync_in_progress:0
slave_repl_offset:762
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:22371
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:22370

 

 

# redis-cli -p 6383 info replication

# Replication
role:slave
master_host:127.0.0.1
master_port:6379
master_link_status:up
master_last_io_seconds_ago:6
master_sync_in_progress:0
slave_repl_offset:790
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0

 

 

 

Redis Sentinel フェイルオーバー機能付加

 

 

# /etc/init.d/redis_6379 stop
Stopping ...
Redis stopped

# chkconfig redis_6379 --list

# chkconfig redis_6379 --list
redis_6379      0:off   1:off   2:off   3:off   4:off   5:off   6:off

 

redis_6381をマスター。redis_6382, redis_6383をスレーブにします。

# redis-cli -p 6382 slaveof 127.0.0.1 6381
OK

# redis-cli -p 6383 slaveof 127.0.0.1 6381
OK

 

確認します。

# redis-cli -p 6381 info replication


# Replication
role:master
connected_slaves:2
slave0:ip=127.0.0.1,port=6382,state=online,offset=74721,lag=0
slave1:ip=127.0.0.1,port=6383,state=online,offset=74721,lag=0
master_repl_offset:74721
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:4856
repl_backlog_histlen:69866

 

# redis-cli -p 6382 info replication

# Replication
role:slave
master_host:127.0.0.1
master_port:6381
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_repl_offset:74987
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:40480

 

# redis-cli -p 6383 info replication


# Replication
role:slave
master_host:127.0.0.1
master_port:6381
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_repl_offset:75400
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0

 

 

# mkdir /var/run/redis

# cp /usr/local/src/redis-*/sentinel.conf /etc/redis/sentinel_1.conf

 

# vi /etc/redis/26381.conf

daemonize yes
port 26381
pidfile sentinel_26381.pid
dir /var/run/redis
logfile /var/log/redis/26381.log
sentinel monitor mymaster 127.0.0.1 6381 2
sentinel down-after-milliseconds mymaster 5000
sentinel auth-pass mymaster syncPass

 

# vi /etc/redis/26382.conf

daemonize yes
port 26382
pidfile sentinel_26382.pid
dir /var/run/redis
logfile /var/log/redis/26382.log
sentinel monitor mymaster 127.0.0.1 6381 2
sentinel down-after-milliseconds mymaster 5000
sentinel auth-pass mymaster syncPass

 

# vi /etc/redis/26383.conf

daemonize yes
port 26383
pidfile sentinel_26383.pid
dir /var/run/redis
logfile /var/log/redis/26383.log
sentinel monitor mymaster 127.0.0.1 6381 2
sentinel down-after-milliseconds mymaster 5000
sentinel auth-pass mymaster syncPass

 

# groupadd redis

# useradd -s /sbin/nologin -M -g redis redis

# chmod 644 /etc/redis/2638*.conf

# chown redis:redis /etc/redis/2638*.conf

 

# cp -p /etc/init.d/redis_6381 /etc/init.d/redis-sentinel_1

 

# vi /etc/init.d/redis-sentinel_1


#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

# chkconfig: - 58 74
# description: redis_6379 is the redis daemon.

#REDISPORT=6379
REDISPORT=6381
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"

(略)


↓変更


#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

# chkconfig: 345 75 15
REDISPORT=26381
EXEC=/usr/local/bin/redis-sentinel
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis/sentinel_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"

(略)

 

好みでrestartをつけています。

# cat /etc/init.d/redis-sentinel_1

#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

# chkconfig: 345 75 15
REDISPORT=26381
CLIEXEC=/usr/local/bin/redis-cli
EXEC=/usr/local/bin/redis-sentinel
PIDFILE=/var/run/redis/sentinel_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"

start(){
    if [ -f $PIDFILE ]
    then
            echo "$PIDFILE exists, process is already running or crashed"
    else
            echo "Starting Redis server..."
            $EXEC $CONF
    fi
}
stop(){
    if [ ! -f $PIDFILE ]
    then
            echo "$PIDFILE does not exist, process is not running"
    else
            PID=$(cat $PIDFILE)
            echo "Stopping ..."
            $CLIEXEC -p $REDISPORT shutdown
            while [ -x /proc/${PID} ]
            do
                echo "Waiting for Redis to shutdown ..."
                sleep 1
            done
            echo "Redis stopped"
    fi
}

case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis server..."
                $EXEC $CONF
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $CLIEXEC -p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    restart)
        stop
        start
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac

 

 

# cp -p /etc/init.d/redis-sentinel_1 /etc/init.d/redis-sentinel_2

# cp -p /etc/init.d/redis-sentinel_1 /etc/init.d/redis-sentinel_3

 

 

# vi /etc/init.d/redis-sentinel_2

#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

# chkconfig: 345 75 15
REDISPORT=26382 ←変更
EXEC=/usr/local/bin/redis-sentinel
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis/sentinel_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"

(略)

 

 

# cat /etc/init.d/redis-sentinel_2

#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

# chkconfig: 345 75 15
REDISPORT=26382
CLIEXEC=/usr/local/bin/redis-cli
EXEC=/usr/local/bin/redis-sentinel
PIDFILE=/var/run/redis/sentinel_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"

start(){
    if [ -f $PIDFILE ]
    then
            echo "$PIDFILE exists, process is already running or crashed"
    else
            echo "Starting Redis server..."
            $EXEC $CONF
    fi
}
stop(){
    if [ ! -f $PIDFILE ]
    then
            echo "$PIDFILE does not exist, process is not running"
    else
            PID=$(cat $PIDFILE)
            echo "Stopping ..."
            $CLIEXEC -p $REDISPORT shutdown
            while [ -x /proc/${PID} ]
            do
                echo "Waiting for Redis to shutdown ..."
                sleep 1
            done
            echo "Redis stopped"
    fi
}

case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis server..."
                $EXEC $CONF
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $CLIEXEC -p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    restart)
        stop
        start
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac

 

 

# vi /etc/init.d/redis-sentinel_3

#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

# chkconfig: 345 75 15
REDISPORT=26383
EXEC=/usr/local/bin/redis-sentinel
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis/sentinel_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"

(略)

 

 

# cat /etc/init.d/redis-sentinel_3

#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

# chkconfig: 345 75 15
REDISPORT=26383
CLIEXEC=/usr/local/bin/redis-cli
EXEC=/usr/local/bin/redis-sentinel
PIDFILE=/var/run/redis/sentinel_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"

start(){
    if [ -f $PIDFILE ]
    then
            echo "$PIDFILE exists, process is already running or crashed"
    else
            echo "Starting Redis server..."
            $EXEC $CONF
    fi
}
stop(){
    if [ ! -f $PIDFILE ]
    then
            echo "$PIDFILE does not exist, process is not running"
    else
            PID=$(cat $PIDFILE)
            echo "Stopping ..."
            $CLIEXEC -p $REDISPORT shutdown
            while [ -x /proc/${PID} ]
            do
                echo "Waiting for Redis to shutdown ..."
                sleep 1
            done
            echo "Redis stopped"
    fi
}

case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis server..."
                $EXEC $CONF
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $CLIEXEC -p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    restart)
        stop
        start
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac

 

 

# /etc/init.d/redis-sentinel_1 start
Starting Redis server...


# /etc/init.d/redis-sentinel_2 start
Starting Redis server...


# /etc/init.d/redis-sentinel_3 start
Starting Redis server...

 

 

# chkconfig redis-sentinel_1 on
# chkconfig redis-sentinel_2 on
# chkconfig redis-sentinel_3 on

 

 

# redis-cli -p 6381 -a syncPass info | grep role
role:master

# redis-cli -p 6382 -a syncPass info | grep role
role:slave

# redis-cli -p 6383 -a syncPass info | grep role
role:slave

 

マスターを落とす

# redis-cli -p 6381 -a syncPass shutdown

----------------------------------------
#  /etc/init.d/redis_6381 stop
Stopping ...
Redis stopped
----------------------------------------

 

 

# redis-cli -p 6381 -a syncPass info | grep role
Could not connect to Redis at 127.0.0.1:6381: Connection refused

# redis-cli -p 6382 -a syncPass info | grep role
role:slave

# redis-cli -p 6383 -a syncPass info | grep role
role:master

 

# service redis_6381 start
Starting Redis server...


# redis-cli -p 6381 -a syncPass info | grep role
role:slave

# redis-cli -p 6382 -a syncPass info | grep role
role:slave

# redis-cli -p 6383 -a syncPass info | grep role
role:master

 

 

【iptablesの設定】

# vi /etc/sysconfig/iptables

※以下を追記する。
//91がWEBサーバ、101~103はredisサーバと想定した設定

-A INPUT -p tcp -m tcp -s 192.168.11.91  -dport 6379 -j ACCEPT
-A INPUT -p tcp -m tcp -s 192.168.11.101 -dport 6379 -j ACCEPT
-A INPUT -p tcp -m tcp -s 192.168.11.102 -dport 6379 -j ACCEPT
-A INPUT -p tcp -m tcp -s 192.168.11.103 -dport 6379 -j ACCEPT
-A INPUT -p tcp -m tcp -s 192.168.11.91  -dport 6381 -j ACCEPT
-A INPUT -p tcp -m tcp -s 192.168.11.101 -dport 6381 -j ACCEPT
-A INPUT -p tcp -m tcp -s 192.168.11.102 -dport 6381 -j ACCEPT
-A INPUT -p tcp -m tcp -s 192.168.11.103 -dport 6381 -j ACCEPT
-A INPUT -p tcp -m tcp -s 192.168.11.91  -dport 6382 -j ACCEPT
-A INPUT -p tcp -m tcp -s 192.168.11.101 -dport 6382 -j ACCEPT
-A INPUT -p tcp -m tcp -s 192.168.11.102 -dport 6382 -j ACCEPT
-A INPUT -p tcp -m tcp -s 192.168.11.103 -dport 6382 -j ACCEPT
-A INPUT -p tcp -m tcp -s 192.168.11.91  -dport 6383 -j ACCEPT
-A INPUT -p tcp -m tcp -s 192.168.11.101 -dport 6383 -j ACCEPT
-A INPUT -p tcp -m tcp -s 192.168.11.102 -dport 6383 -j ACCEPT
-A INPUT -p tcp -m tcp -s 192.168.11.103 -dport 6383 -j ACCEPT

 

# service iptables restart

 

 

【データをディスクにセーブする】

マスターに接続する
# redis-cli -p 6381 -a hoge


フォアグラウンドでディスクにセーブする
> save
OK


バックグラウンドでディスクにセーブする
> bgsave
Background saving started

 

 

【sentinelでマスター情報確認】

 

# redis-cli -p 26381

127.0.0.1:26381> sentinel get-master-addr-by-name mymaster
1) "127.0.0.1"
2) "6381"

 

マスターノード詳細

127.0.0.1:26381> sentinel master mymaster

 1) "name"
 2) "mymaster"
 3) "ip"
 4) "127.0.0.1"
 5) "port"
 6) "6381"
 7) "runid"
 8) "0e71dff9af133341e7ec6fa4c326ff4701f88d5d"
 9) "flags"
10) "master"
11) "link-pending-commands"
12) "0"
13) "link-refcount"
14) "1"
15) "last-ping-sent"
16) "0"
17) "last-ok-ping-reply"
18) "306"
19) "last-ping-reply"
20) "306"
21) "down-after-milliseconds"
22) "5000"
23) "info-refresh"
24) "5970"
25) "role-reported"
26) "master"
27) "role-reported-time"
28) "2882428"
29) "config-epoch"
30) "2"
31) "num-slaves"
32) "2"
33) "num-other-sentinels"
34) "2"
35) "quorum"
36) "2"
37) "failover-timeout"
38) "180000"
39) "parallel-syncs"
40) "1"

 

 

127.0.0.1:26381> sentinel slaves mymaster

1)  1) "name"
    2) "127.0.0.1:6383"
    3) "ip"
    4) "127.0.0.1"
    5) "port"
    6) "6383"
    7) "runid"
    8) "dca2b64e2dbe634baa12d9f91d719e6ebfd193fc"
    9) "flags"
   10) "slave"
   11) "link-pending-commands"
   12) "0"
   13) "link-refcount"
   14) "1"
   15) "last-ping-sent"
   16) "0"
   17) "last-ok-ping-reply"
   18) "751"
   19) "last-ping-reply"
   20) "751"
   21) "down-after-milliseconds"
   22) "5000"
   23) "info-refresh"
   24) "6972"
   25) "role-reported"
   26) "slave"
   27) "role-reported-time"
   28) "2919579"
   29) "master-link-down-time"
   30) "0"
   31) "master-link-status"
   32) "ok"
   33) "master-host"
   34) "127.0.0.1"
   35) "master-port"
   36) "6381"
   37) "slave-priority"
   38) "100"
   39) "slave-repl-offset"
   40) "568706"
2)  1) "name"
    2) "127.0.0.1:6382"
    3) "ip"
    4) "127.0.0.1"
    5) "port"
    6) "6382"
    7) "runid"
    8) "d20ada93e27db7b843ffb57d1b72563d422b63b6"
    9) "flags"
   10) "slave"
   11) "link-pending-commands"
   12) "0"
   13) "link-refcount"
   14) "1"
   15) "last-ping-sent"
   16) "0"
   17) "last-ok-ping-reply"
   18) "446"
   19) "last-ping-reply"
   20) "446"
   21) "down-after-milliseconds"
   22) "5000"
   23) "info-refresh"
   24) "8400"
   25) "role-reported"
   26) "slave"
   27) "role-reported-time"
   28) "2919579"
   29) "master-link-down-time"
   30) "0"
   31) "master-link-status"
   32) "ok"
   33) "master-host"
   34) "127.0.0.1"
   35) "master-port"
   36) "6381"
   37) "slave-priority"
   38) "100"
   39) "slave-repl-offset"
   40) "568440

 

 

【ベンチマーク】

 

# redis-benchmark -h 127.0.0.1 -p 6381


====== PING_INLINE ======
  100000 requests completed in 1.13 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

99.89% <= 1 milliseconds
99.90% <= 2 milliseconds
99.95% <= 4 milliseconds
100.00% <= 4 milliseconds
88573.96 requests per second

====== PING_BULK ======
  100000 requests completed in 1.17 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

99.76% <= 1 milliseconds
99.97% <= 3 milliseconds
100.00% <= 4 milliseconds
100.00% <= 4 milliseconds
85543.20 requests per second

====== SET ======
  100000 requests completed in 1.50 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

99.72% <= 1 milliseconds
99.94% <= 2 milliseconds
99.95% <= 3 milliseconds
100.00% <= 3 milliseconds
66711.14 requests per second

====== GET ======
  100000 requests completed in 1.12 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

99.95% <= 1 milliseconds
99.95% <= 2 milliseconds
99.97% <= 3 milliseconds
99.97% <= 5 milliseconds
100.00% <= 5 milliseconds
89285.71 requests per second

====== INCR ======
  100000 requests completed in 1.40 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

99.93% <= 1 milliseconds
100.00% <= 1 milliseconds
71174.38 requests per second

====== LPUSH ======
  100000 requests completed in 1.60 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

91.51% <= 1 milliseconds
99.75% <= 2 milliseconds
99.81% <= 3 milliseconds
99.94% <= 4 milliseconds
100.00% <= 4 milliseconds
62460.96 requests per second

====== RPUSH ======
  100000 requests completed in 1.47 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

99.88% <= 1 milliseconds
99.95% <= 2 milliseconds
100.00% <= 2 milliseconds
68027.21 requests per second

====== LPOP ======
  100000 requests completed in 1.49 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

96.39% <= 1 milliseconds
99.74% <= 2 milliseconds
99.84% <= 3 milliseconds
100.00% <= 4 milliseconds
100.00% <= 4 milliseconds
67069.08 requests per second

====== RPOP ======
  100000 requests completed in 1.43 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

99.88% <= 1 milliseconds
100.00% <= 2 milliseconds
100.00% <= 2 milliseconds
70028.02 requests per second

====== SADD ======
  100000 requests completed in 1.12 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

99.48% <= 1 milliseconds
99.82% <= 2 milliseconds
99.88% <= 3 milliseconds
99.96% <= 5 milliseconds
100.00% <= 5 milliseconds
89365.51 requests per second

====== SPOP ======
  100000 requests completed in 1.10 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

99.95% <= 1 milliseconds
100.00% <= 1 milliseconds
90991.81 requests per second

====== LPUSH (needed to benchmark LRANGE) ======
  100000 requests completed in 1.59 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

91.65% <= 1 milliseconds
99.91% <= 2 milliseconds
99.93% <= 3 milliseconds
99.95% <= 4 milliseconds
99.96% <= 5 milliseconds
100.00% <= 5 milliseconds
62735.26 requests per second

====== LRANGE_100 (first 100 elements) ======
  100000 requests completed in 2.91 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

80.06% <= 1 milliseconds
99.97% <= 2 milliseconds
99.99% <= 3 milliseconds
100.00% <= 3 milliseconds
34352.46 requests per second

====== LRANGE_300 (first 300 elements) ======
  100000 requests completed in 7.38 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

0.00% <= 1 milliseconds
98.22% <= 2 milliseconds
99.71% <= 3 milliseconds
99.72% <= 4 milliseconds
99.86% <= 5 milliseconds
99.94% <= 6 milliseconds
99.96% <= 7 milliseconds
100.00% <= 7 milliseconds
13546.46 requests per second

====== LRANGE_500 (first 450 elements) ======
  100000 requests completed in 10.41 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

0.00% <= 1 milliseconds
0.05% <= 2 milliseconds
99.06% <= 3 milliseconds
99.53% <= 4 milliseconds
99.62% <= 5 milliseconds
99.86% <= 6 milliseconds
99.89% <= 7 milliseconds
99.94% <= 8 milliseconds
100.00% <= 8 milliseconds
9603.38 requests per second

====== LRANGE_600 (first 600 elements) ======
  100000 requests completed in 13.69 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

0.00% <= 2 milliseconds
0.05% <= 3 milliseconds
98.62% <= 4 milliseconds
99.07% <= 5 milliseconds
99.32% <= 6 milliseconds
99.76% <= 7 milliseconds
99.85% <= 8 milliseconds
99.96% <= 9 milliseconds
99.99% <= 10 milliseconds
100.00% <= 12 milliseconds
7306.20 requests per second

====== MSET (10 keys) ======
  100000 requests completed in 3.99 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

0.03% <= 1 milliseconds
70.55% <= 2 milliseconds
98.77% <= 3 milliseconds
99.80% <= 4 milliseconds
99.85% <= 5 milliseconds
99.90% <= 6 milliseconds
99.95% <= 7 milliseconds
100.00% <= 7 milliseconds
25068.94 requests per second

 

Amazonおすすめ

iPad 9世代 2021年最新作

iPad 9世代出たから買い替え。安いぞ!🐱 初めてならiPad。Kindleを外で見るならiPad mini。ほとんどの人には通常のiPadをおすすめします><

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)