구성도
THP 비활성화
/etc/rc.local 에 아래 내용 추가
echo never > /sys/kernel/mm/transparent_hugepage/enabled
Redis 다운로드 및 설치
Redis 다운로드
cd /usr/local
wget http://download.redis.io/releases/redis-4.0.14.tar.gz
tar xzf redis-4.0.14.tar.gz
mv redis-4.0.14 redis
cd /usr/local/redis/src
make
디렉토리 생성
cd /usr/local/redis/
mkdir -p /usr/local/redis/cluster/7000
mkdir -p /usr/local/redis/cluster/conf
touch /usr/local/redis/cluster/redis_start.sh
chmod 700 /usr/local/redis/cluster/redis_start.sh
실행파일 생성
vi /usr/local/redis/cluster/redis_start.sh
#!/bin/sh
/usr/local/redis/src/redis-server /usr/local/redis/cluster/conf/redis.7000.conf
conf 파일 생성
conf 파일 생성
vi /usr/local/redis/cluster/conf/redis.7000.conf
masterauth , requirepass에는 패스워드 입력
################################## NETWORK #####################################
#bind에는 접속 가능한 서버의 IP주소를 입력합니다.
bind 11.1.1.1 127.0.0.1
protected-mode yes
port 7000
tcp-backlog 511
timeout 0
tcp-keepalive 300
################################# GENERAL #####################################
dir /usr/local/redis/cluster/7000
daemonize yes
supervised no
pidfile redis.pid
loglevel notice
logfile redis.log
always-show-logo yes
################################ SNAPSHOTTING ################################
save ""
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.cluster.rdb
################################# REPLICATION #################################
masterauth ***********
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync yes
repl-diskless-sync-delay 5
repl-timeout 60
repl-disable-tcp-nodelay no
slave-priority 100
################################## SECURITY ###################################
requirepass *********
############################# LAZY FREEING ####################################
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
############################## APPEND ONLY MODE ###############################
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble no
################################ LUA SCRIPTING ###############################
lua-time-limit 5000
################################ REDIS CLUSTER ###############################
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
################################## SLOW LOG ###################################
slowlog-log-slower-than 10000
slowlog-max-len 128
################################ LATENCY MONITOR ##############################
latency-monitor-threshold 0
############################# EVENT NOTIFICATION ##############################
notify-keyspace-events ""
############################### ADVANCED CONFIG ###############################
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
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 사용자 및 그룹 생성
groupadd redis
useradd -g redis redis
chown -R redis:redis /usr/local/redis
redis 기동 확인
redis 시작
su - redis
/usr/local/redis/cluster/redis_start.sh
기동 확인
ps -ef | grep redis
redis cluster 구성
cluster 구성은 전체 서버가 아닌 한대만 설치해도 된다
cluster 구성용 redis-trib-pass 파일 다운로드
cd /usr/local/redis/src
wget https://raw.githubusercontent.com/seekasia/redis/master/src/redis-trib-pass.rb
redis-trib-pass.rb 첫번째 행 ruby2.1 => ruby 수정
vi redis-trib-pass.rb
chmod 700 redis-trib-pass.rb
ruby를 다운로드
cd /usr/local/src
wget https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.1.tar.gz
tar xvf ruby-2.5.1.tar.gz
ruby 컴파일
yum install -y bzip2 gcc openssl-devel readline-devel zlib-devel
cd ruby-2.5.1/
./configure
make
make install
ruby --version
gem install redis
마스터 서버 cluster 설정
*redis cluster 구성시 host name 이 아닌 Ip Address를 이용한다.
/usr/local/redis/src/redis-trib-pass.rb create --auth password 1.1.1.1:7000 1.1.1.2:7000 1.1.1.3:7000
cluster 확인 (마스터 ID 확인)
/usr/local/redis/src/redis-cli -p 7000 -a password cluster nodes
d6c9d17ba96137d13d0217a7e62ea7e7250a090e 1.1.1.1:7000@17000 myself,master - 0 0 1 connected 0-5460
5ac01a2c3936ef788fe63f8e9467156734b07aae 1.1.1.2:7000@17000 master - 0 1563850868038 2 connected 5461-10922
64908665fb8d8f966c5b0b3c82b60c7858db6d6e 1.1.1.3:7000@17000 master - 0 1563850868037 3 connected 10923-16383
* 첫번째 키가 마스터 키
slave 추가
#/usr/local/redis/src/redis-trib.rb add-node --slave --master-id <마스터ID> --auth 비밀번호 <슬레이브IP:port> <현재실행서버IP:port>
예:
Cluster 1 master slave 설정
/usr/local/redis/src/redis-trib-pass.rb add-node --slave --master-id d6c9d17ba96137d13d0217a7e62ea7e7250a090e --auth password 1.1.1.2:7000 1.1.1.1:7000
/usr/local/redis/src/redis-trib-pass.rb add-node --slave --master-id d6c9d17ba96137d13d0217a7e62ea7e7250a090e --auth password 1.1.1.3:7000 1.1.1.1:7000
Cluster 2 master slave 설정
/usr/local/redis/src/redis-trib-pass.rb add-node --slave --master-id 5ac01a2c3936ef788fe63f8e9467156734b07aae --auth password 1.1.1.4:7000 1.1.1.1:7000
/usr/local/redis/src/redis-trib-pass.rb add-node --slave --master-id 5ac01a2c3936ef788fe63f8e9467156734b07aae --auth password 1.1.1.5:7000 1.1.1.1:7000
Cluster 3 master slave 설정
/usr/local/redis/src/redis-trib-pass.rb add-node --slave --master-id 64908665fb8d8f966c5b0b3c82b60c7858db6d6e --auth password 1.1.1.6:7000 1.1.1.1:7000
/usr/local/redis/src/redis-trib-pass.rb add-node --slave --master-id 64908665fb8d8f966c5b0b3c82b60c7858db6d6e --auth password 1.1.1.7:7000 1.1.1.1:7000