1. 일단 2.8 기준으로 설정한다. 


2. conf 파일을 만든다.
6379.conf  6479.conf  6579.conf  6679.conf  6779.conf  6879.conf  6979.conf
이처럼 6개파일을 만든다.
위 컴피그를 수정한다. 
[root@localhost conf]# vi 6379.conf

## Generated by install_server.sh ##
################################## INCLUDES ###################################
# include /path/to/local.conf
# include /path/to/other.conf
################################ GENERAL  #####################################
daemonize yes
pidfile /var/run/redis_6379.pid
port 6379
tcp-backlog 511
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1
# unixsocket /tmp/redis.sock
# unixsocketperm 700
timeout 0
tcp-keepalive 0
loglevel notice
logfile /usr/local/redis/log/redis_6379.log
# syslog-enabled no
# Specify the syslog identity.
# syslog-ident redis
# syslog-facility local0
databases 16

################################ SNAPSHOTTING  ################################
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /usr/local/redis/data/6379

################################# REPLICATION #################################
# slaveof <masterip> <masterport>
# masterauth <master-password>
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
# repl-ping-slave-period 10
# repl-timeout 60
repl-disable-tcp-nodelay no
# repl-backlog-size 1mb
# repl-backlog-ttl 3600
slave-priority 100
# min-slaves-to-write 3
# min-slaves-max-lag 10
################################## SECURITY ###################################
# requirepass 1234
# rename-command CONFIG ""

################################### LIMITS ####################################
# maxclients 10000
# maxmemory <bytes>
# maxmemory-policy noeviction
# maxmemory-samples 5
############################## APPEND ONLY MODE ###############################
appendonly yse
appendfilename "appendonly.aof"
# appendfsync always
appendfsync everysec
# appendfsync no
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes

################################ LUA SCRIPTING  ###############################
lua-time-limit 5000

################################ REDIS CLUSTER  ###############################
cluster-enabled yes
cluster-config-file nodes-6379.conf
cluster-node-timeout 15000
# cluster-slave-validity-factor 10
# cluster-migration-barrier 1
# cluster-require-full-coverage yes

################################## SLOW LOG ###################################
slowlog-log-slower-than 10000
slowlog-max-len 128

################################ LATENCY MONITOR ##############################
latency-monitor-threshold 0

############################# EVENT NOTIFICATION ##############################
notify-keyspace-events ""

3. 위설정한 디렉토리는 전부 있어야한다.

4. 만든 컨피그로 모든 레디스 실행한다 
/usr/local/redis/redis-cluster-test/6379/redis-server /usr/local/redis/redis-cluster-test/6379/6379.conf
/usr/local/redis/redis-cluster-test/6479/redis-server /usr/local/redis/redis-cluster-test/6479/6479.conf
/usr/local/redis/redis-cluster-test/6579/redis-server /usr/local/redis/redis-cluster-test/6579/6579.conf
/usr/local/redis/redis-cluster-test/6679/redis-server /usr/local/redis/redis-cluster-test/6679/6679.conf
/usr/local/redis/redis-cluster-test/6779/redis-server /usr/local/redis/redis-cluster-test/6779/6779.conf
/usr/local/redis/redis-cluster-test/6879/redis-server /usr/local/redis/redis-cluster-test/6879/6879.conf



5. 클러스터 설정 자동으로 클라스터 설정을 잡는다. 노드 범위도 자동으로 분활해준다. 만약 노드 범위를 바꾸려면 옵션으로 변경가능하다.

./redis-trib.rb create --replicas 1 175.207.8.169:6379 175.207.8.169:6479 \175.207.8.169:6579 175.207.8.169:6679 175.207.8.169:6779 175.207.8.169:6879



6. 에러 발생 

$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
$ \curl -sSL https://get.rvm.io | bash -s stable
이동 
$ cd /usr/localrvm/bin
$ rvm install 2.2.0+
gem 설치 
# yum install rubygems
gem redis
#gem install redis


7. 참고사항 
위 클러스터 설정은 기존에 있던 sentinel + sharding 기능을 한다고 보면된다.




참고 싸이트 
http://redis.io/topics/cluster-tutorial -- 클러스터 튜토리얼 공식
http://the-earth.tistory.com/182 --번역본 
http://ddakker.tistory.com/327 --4번 설정시 에러 날때 해결법 ruby 설정


/usr/local/redis/src/redis-cli -p 6379 shutdown
/usr/local/redis/src/redis-cli -p 6479 shutdown 
/usr/local/redis/src/redis-cli -p 6579 shutdown 
/usr/local/redis/src/redis-cli -p 6679 shutdown 
/usr/local/redis/src/redis-cli -p 6779 shutdown 
/usr/local/redis/src/redis-cli -p 6879 shutdown  


rm -f  /usr/local/redis/data/6379/*
rm -f  /usr/local/redis/data/6479/* 
rm -f  /usr/local/redis/data/6579/* 
rm -f  /usr/local/redis/data/6679/* 
rm -f  /usr/local/redis/data/6779/* 
rm -f  /usr/local/redis/data/6879/* 





1. 데이터 입력중 마스터 DB가 중지댈때 데이터 보장되는 지 확인 


1.1 소스코드 

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.data.redis.RedisConnectionFailureException;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisSentinelPool;
import redis.clients.jedis.exceptions.JedisConnectionException;

/**
* @Auth Hong Seungkyun
* @Description
* <pre></pre>
*/
public class RedisTest {

     public static void main(String[] args) throws Exception {

          Set<String> sentinelIps = new HashSet<>();
          sentinelIps.add("175.207.8.166:26379");
          sentinelIps.add("175.207.8.167:26379");
          sentinelIps.add("175.207.8.168:26379");

          GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();

          JedisSentinelPool jedisSentinelPool = new JedisSentinelPool("mymaster", sentinelIps, poolConfig, 5000, "1020");
          Jedis jedis1 = jedisSentinelPool.getResource();
          String[] keys = new String[100];
         
         
         
          //삭제처리
          StringBuffer delkey = new StringBuffer();
          for (int i = 0; i < 100; i++) {    
               keys[i] ="Test_"+i;
          }    
          jedis1.del(keys);
              

          for (int i = 0; i < 100; i++) {              
               try {
                    RedisTest.setData(jedisSentinelPool, "Test_"+i, "value_"+i);
                    System.out.println("input > key : Test_"+i+" , value :  value_"+i);
               } catch (Exception e) {
                    System.out.println(e.getMessage());
                    System.out.println("에러 발생");
               }         
              
               Thread.sleep(500);
          }
         
          for (int i = 0; i < 100; i++) {
               Jedis jedis = jedisSentinelPool.getResource();
               try {
                    String value = jedis.get("Test_" + i);
                    System.out.println("output > key : Test_"+i+" , value :"+value);
               } catch (RedisConnectionFailureException e) {
                    e.printStackTrace();
                    jedisSentinelPool.returnBrokenResource(jedis);
               } finally {

                    try {

                         jedisSentinelPool.returnResource(jedis);

                    } catch (JedisConnectionException e) {

                         System.out.println(e);

                    }
               }
          }

          /*
          * JedisPool jedisPool = new JedisPool(new JedisPoolConfig(), "175.207.8.166",6379,0,"1020");
          * Jedis jedis = jedisPool.getResource();
          * try {
          * jedis.set("foo", "client_test");
          * } catch (Exception e) {
          * System.out.println(e.getMessage());
          * }
          * System.out.println(">>>>> : "+jedis.get("foo"));
          */

     }
     public  static void  setData(JedisSentinelPool jedisSentinelPool, String key , String value ){
          Jedis jedis =null;
          try {              
               jedis = jedisSentinelPool.getResource();
               jedis.set(key, value);
          } catch (RedisConnectionFailureException e) {
               System.out.println(e);
               System.out.println("헐헐2!!");
               jedisSentinelPool.returnBrokenResource(jedis);
          } finally {
               try {
                    jedisSentinelPool.returnResource(jedis);
               } catch (JedisConnectionException e) {                   
                    System.out.println(e);
                    System.out.println("헐헐3!!");
               }
          }
         
     }

}
1.2 서버 콘솔 
입력 도중 
# redis-cli -a 1020 shutdown 명령 입력 

1.3 데이터 처리 로그 

1월 27, 2015 11:16:22 오전 redis.clients.jedis.JedisSentinelPool initSentinels
정보: Trying to find master from available Sentinels...
1월 27, 2015 11:16:23 오전 redis.clients.jedis.JedisSentinelPool initSentinels
정보: Redis master running at 175.207.8.167:6379, starting Sentinel listeners...
1월 27, 2015 11:16:23 오전 redis.clients.jedis.JedisSentinelPool initPool
정보: Created JedisPool to master at 175.207.8.167:6379
input > key : Test_0 , value :  value_0
.......
input > key : Test_16 , value :  value_16
input > key : Test_17 , value :  value_17 ==>> 에러 최초 발생 
Unexpected end of stream.
에러 발생
redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: Software caused connection abort: socket write error
헐헐3!!
java.net.SocketException: Software caused connection abort: socket write error
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
1월 27, 2015 11:17:03 오전 redis.clients.jedis.JedisSentinelPool initPool
정보: Created JedisPool to master at 175.207.8.168:6379
Could not get a resource from the pool
에러 발생

input > key : Test_41 , value :  value_41 ==> 마스터 체이진 정상 입력
input > key : Test_42 , value :  value_42
........
input > key : Test_99 , value :  value_99

//데이터 읽기
output > key : Test_0 , value :value_0
output > key : Test_1 , value :value_1
output > key : Test_2 , value :value_2
........
output > key : Test_17 , value :value_17
output > key : Test_18 , value :null
output > key : Test_19 , value :null
output > key : Test_20 , value :null
......
output > key : Test_36 , value :null
output > key : Test_37 , value :null
output > key : Test_38 , value :null
output > key : Test_39 , value :null
output > key : Test_40 , value :null

output > key : Test_41 , value :value_41
output > key : Test_42 , value :value_42
........
output > key : Test_95 , value :value_95
output > key : Test_96 , value :value_96
output > key : Test_97 , value :value_97
output > key : Test_98 , value :value_98
output > key : Test_99 , value :value_99

결론 
강제 셧다운시 10초  이후에 시스템이 정상 운영됨 
1. 10 초 사이데이터 처리 방안이 필요함 ( 서버 체크 시간 8초로 설정해서 11초후에 정상 처리  시스템  설정 시간보다 다소 시간이 지연됨.)


참고 싸이트 

 


 

 

1. 설치 위치 : http://www.redis.io/download

2. 설치 하기 


$ wget http://download.redis.io/releases/redis-2.8.15.tar.gz
$ tar xzf redis-2.8.15.tar.gz
$ cd redis-2.8.15
$ make
$ make install


2. 인스톨 하기 
$ cd utils
$ ./install_server.sh

3. 실행/종료 

$ /etc/init.d/redis_6379 start
$ /etc/init.d/redis_6379 stop


4. 테스트 

$ src/redis-cli
redis> set foo bar
OK
redis> get foo
"bar"


5. 비밀번호 설정  

$ vi etc/redis/6379.conf 

requirepass 비밀번호

파일 저장 

$ /etc/init.d/redis_6379 stop
$ /etc/init.d/redis_6379 start


6. 접속 테스트 
src/redis-cli
auth 비밀번호 
ok
사용 하면 끝



7. 포트 열기 기본 레디스 + 센티널 포트 열기


# iptables -I INPUT 1 -p tcp --dport 6379 -j ACCEPT 
# iptables -I OUTPUT 1 -p tcp --dport 6979 -j ACCEPT  
# iptables -I INPUT 1 -p tcp --dport 26379 -j ACCEPT 
iptables -I OUTPUT 1 -p tcp --dport 26379 -j ACCEPT 


# service iptables save
# service iptables restart





8. Master/ slave 설정
Master 의 경우
      SECURITY 섹션에서 requirepass 를 설정하기만 하면 된다.
   # requirepass foobared
      이 부분을 주석 제거하고, 원하는 비밀번호로 설정.. 센티널 설정할려면 이부분 설정한다.

Slave 의 경우    
   # slaveof <masterip> <masterport>
      주석 제거하고, 마스터의 아이피와 포트를 적는다. 기본 포트를 사용한다면 6379

    REPLICATION 섹션에서 설정을 변경한다.
   # masterauth <master-password>
      주석 제거하고, requirepass에서 설정한 비밀번호를 적는다.
   # repl-ping-slave-period 10
      주석 제거하고, 기본값 10으로 사용
   # repl-timeout 60
      주석 제거하고, 기본값 60으로 사용
      repl-ping-slave-period 값보다 큰 값을 사용하라는 코멘트가 있다.

  


9. 기타 사항 
1. 마스터 서버 종료하기 
./redis-cli - a 비밀번호
> SHUTDOWN





참고 싸이트 

1. http://trend21c.tistory.com/1645 에러 관련 정리  잘되어있슴
2. http://lovedev.tistory.com/?page=3 설치 관련 정보

문제 해결 

$yum -y install gcc

$ make distclean
$ make
$ make test

$ yum -y install tcl
$ make test



10. sentinel 설정
11. 준비 과정 
          --> master/slave 설정을 완료하고 레디스를 실행한다.
          --> sentinel.conf 설정을 해당 서버 환경에 맞게 설정한다.
          --> 실행시에는 redis-sentinel /usr/local/reids/conf/sentinel.conf(프로퍼티 파일으 내가만든파일 위치)     

12. 센티널 설정 
sentinel.conf 설정 (설정파일은 redis 설치한 디렉토리에 보면 샘플 파일이 있다 이것을 복사해서 써도대고 새로 만들어도 된다)
## 마스터/ 슬레이브 설정
sentinel monitor mymaster 175.207.8.168 6379 2
sentinel down-after-milliseconds mymaster 30000
sentinel auth-pass mymaster 1020
sentinel failover-timeout mymaster 80000
sentinel parallel-syncs mymaster 1
 

 --> 마스터만 설정을 전부 다하고 
 --> 슬레이브는 마스터만 등록하면된다.

13. 설정참고 URL

14. 개발 운영 참고
15. 개잘 참고 사이트 
http://yakolla.tistory.com/47 -- 자바 관련 설명되어있다.

16. shiding