OpenSource

[Redis] 설치 v3.0.7

아르비스 2016. 2. 19. 09:24

IMDG(In-Memory Data Grid)로 자주 사용하고 있는 Redis를 재설치 한다.


기존 2.8.13 버전을 사용하다가, 이번 Container 적용 및 테스트를 위해서..

Redis version up Test



1. Redis Home page 방문 및 Download

   http://redis.io/

   http://redis.io/download/

   [Stable] version은 3.0.7. 

    기존 2.x 버전대비 Cluster, Data sharding, fault tolerance 등의 기능 추가

   [Test] version은 3.2.0

     Geo Indexing 관련 commands가 추가 되었다고 한다. 하지만.. Test 중인 관계로 skip

 -Download URL : http://download.redis.io/releases/redis-3.0.7.tar.gz


2. 빌드 & 설치

  Redis는 서버에서 build 하는 구조임.

  1) 빌드

   #> tar -zxvf redis-3.0.7.tar.gz

   #> cd redis-3.0.7

   #> make && make install

   빌드가 완료되면, ./redis-3.0.7/src 하위에 실행 파일이 생성된다.

  2) 설치

   빌드 된 파일 중, 아래 file 목록 따로 저장하여 실행.

 redis-benchmark

 redis-check-aof

 redis-check-dump

 redis-cli

 redis-sentinel

 redis-server

 위 파일만 있으면 Redis 실행 가능하다.(단 같은 조건의 서버상에서..)


3. 설정

  최소 설정은 아래 서버 실행 command 처럼 최소로도 구성가능하다.

 ./redis-server --port 6380 --slaveof 127.0.0.1 6379

 하지만, Detail한 설정을 위해서 config file을 사용한다.

 config file (redis.conf)는 redis web site에서 제공한다.

 http://redis.io/topics/config

 Download : https://raw.githubusercontent.com/antirez/redis/3.0/redis.conf

 web site에서는 3.0/2.8/2.6/2.4 version용 conf file을 제공한다.

 

 download 받은 redis.conf 파일을 포함한 실행파일은 아래과 같이 임의 저장함.

 ./redis-3.0.8/bin/

 ./redis-3.0.8/conf/

 bin folder에는 위 실행파일을, conf 폴더에는 redis.conf를 저장


 * 상세 설정

 1) redis 설정

  -port : 6379 (default)

 #> vi redis.conf

  아래 내용 만 수정

 

redis_3.0.8.conf

## Run as a deamon. Use 'yes'

daemonize yes


## Redis writes a pid file. multi instance를 위한 pid 구분

pidfile /var/run/redis_6379.pid

port 6379


# output for logging

logfile "./logs/redis_6379.log"


# The working directory.

dir ./data/6379


# Master-Slave replication.  Master-Slave가 있으면.

# slaveof <masterip> <masterport>


# If the master is password protecte. redis에 password 설정

# masterauth <master-password>


  

2) Redis Sentinel 설정


sentinel_3.0.8.conf

http://redis.io/topics/sentinel

 - port : 26379 (default)

 - redis 2.8 이상에서 지원


3) Redis Cluster 설정

http://redis.io/topics/cluster-tutorial

 - port : 16379 (default)

 - redis 3.0 이상버전에서만 지원

- 설정파일은 redis.conf에 있음

   #### REDIS CLUSTER ### 참조

port 7000

cluster-enabled yes

cluster-config-file nodes.conf

cluster-node-timeout 5000

appendonly yes

cluster의 경우 3node 이상에서 동작함.

4) Cluster 생성을 위한 ruby 설치

 cluster 생성을 위한 redis-trib.rb를 실행하기 위해, 설치


# centos 6.x

wget http://rpms.southbridge.ru/rhel6/ruby-1.9.3/x86_64/ruby-1.9.3.p547-1.el6.x86_64.rpm


yum install ruby-1.9.3/x86_64/ruby-1.9.3.p547-1.el6.x86_64.rpm


yum install gcc gcc-g++ make automake autoconf curl-devel openssl-devel zlib-devel httpd-devel apr-devel apr-util-devel sqlite-devel


gem update

gem update --system

gem install redis

gem이 방화벽 문제로 설치가 안될경우, redis.gem을 다운 받아서 설치해 주면 된다.

https://rubygems.org/gems/redis/versions/3.2.2

https://rubygems.org/downloads/redis-3.2.2.gem


설치방법은

gem install redis-3.2.2.gem


확인 방법은 


# gem list


*** LOCAL GEMS ***


bigdecimal (1.1.0)

io-console (0.3)

json (1.5.5)

minitest (2.5.1)

rake (0.9.2.2)

rdoc (3.9.5)

redis (3.2.2)

 


cluster 생성 하기 전에 redis 를 cluster로 묶어주여야 한다.. ㅠㅠ

cassandra나 ES는 cluster name을 자동으로 찾지만,... redis는 아직 드런 기능은 없는듯..


cluster 묶어주기.

최소 3 master node가 있어야 하며, replica를 하려만 최소 6 node가 있어야 한다.

- 3개의 master node 만 묶기


# ./redis-trib.rb create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002


[중요!!]

 같은 서버가 아닌 다른 서버에서 접속할 시 127.0.0.1로 cluster를 구성하면, 다음과 같은 에러가 발생한다..

JedisClusterMaxRedirectionsExceptionToo many Cluster redirections? 


어느 누구도 설명이 없어서.. 한참  삽질했다..ㅠㅠ

이런.. 제길슨.. 역시 tutorial만 믿으면 안된다..ㅎㅎㅎ


>>> Creating cluster

>>> Performing hash slots allocation on 3 nodes...

Using 3 masters:

127.0.0.1:7000

127.0.0.1:7001

127.0.0.1:7002

M: 1f1235521ee5b57b459aa9fe69151a7e4c392d9b 127.0.0.1:7000

   slots:0-5460 (5461 slots) master

M: b0949a0d3082ffde4ae5661a59c0ea538a07760f 127.0.0.1:7001

   slots:5461-10922 (5462 slots) master

M: 2dcfc2ad3373b338f5ec2e3750567d4f503c9496 127.0.0.1:7002

   slots:10923-16383 (5461 slots) master

Can I set the above configuration? (type 'yes' to accept): yes

>>> Nodes configuration updated

>>> Assign a different config epoch to each node

>>> Sending CLUSTER MEET messages to join the cluster

Waiting for the cluster to join..

>>> Performing Cluster Check (using node 127.0.0.1:7000)

M: 1f1235521ee5b57b459aa9fe69151a7e4c392d9b 127.0.0.1:7000

   slots:0-5460 (5461 slots) master

M: b0949a0d3082ffde4ae5661a59c0ea538a07760f 127.0.0.1:7001

   slots:5461-10922 (5462 slots) master

M: 2dcfc2ad3373b338f5ec2e3750567d4f503c9496 127.0.0.1:7002

   slots:10923-16383 (5461 slots) master

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered.

# >


- 6 node (3 master, 3 slave)

./redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005


※ 눈치 채셨겠지만, 중요한 차이는 'replicas' 의 차이..!!


cluster 구성이 완료되면 아래와 같은 문구가 나온다.. !!

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered.

 


log는 각 redis.log 와 node.conf 에 남는다.


vi redis.log

21123:M 25 Feb 13:20:07.055 * The server is now ready to accept connections on port 7000

21123:M 25 Feb 13:26:39.215 # configEpoch set to 1 via CLUSTER SET-CONFIG-EPOCH

21123:M 25 Feb 13:26:39.259 # IP address for this node updated to 127.0.0.1

21123:M 25 Feb 13:26:44.175 # Cluster state changed: ok 


vi node.conf

2dcfc2ad3373b338f5ec2e3750567d4f503c9496 127.0.0.1:7002 master - 0 1456374401867 3 connected 10923-16383

1f1235521ee5b57b459aa9fe69151a7e4c392d9b 127.0.0.1:7000 master - 0 1456374400863 1 connected 0-5460

b0949a0d3082ffde4ae5661a59c0ea538a07760f 127.0.0.1:7001 myself,master - 0 0 2 connected 5461-10922

vars currentEpoch 3 lastVoteEpoch 0




[Script를 이용한 Cluster 생성]

간단하게 생성 할수 있으며, 포트는 기본적으로 30001 번부터 30006까지 master 3 node, slave 3 node가 생성된다. 자세한 설정 부분은 create-cluster를 까보기 바란다..

<Cluster 생성>


To create a cluster, follow this steps:

 

1. Edit create-cluster and change the start / end port, depending on the

number of instances you want to create.

2. Use "./create-cluster start" in order to run the instances.

3. Use "./create-cluster create" in order to execute redis-trib create, so that

an actual Redis cluster will be created.

4. Now you are ready to play with the cluster. AOF files and logs for each instances are created in the current directory.


<cluster 삭제>

In order to stop a cluster:

 

1. Use "./craete-cluster stop" to stop all the instances. After you stopped the instances you can use "./create-cluster start" to restart them if you change ideas.

2. Use "./create-cluster clean" to remove all the AOF / log files to restat with a clean environment.