Ossian Story
article thumbnail
Published 2017. 11. 6. 16:52
[DB] Redis 설치 [DB]/Redis

[DB] Redis 설치


Redis 란?


Redis(RMote DIctionary Server)는 디스크가 아닌 메모리 기반의 데이터 저장소입니다. 

Memory 위에서 동작하는 Key / Value 저장소인 Redis는 NoSQL DBMS로 분류됩니다.


Memory 위에서 동작하기 때문에 처리 속도가 일반 디스크에서 작동하는 것보다 훨씬 빠릅니다.

또한 데이터가 Memory + Disk에 저장되기 때문에 Server Shutdown이 발생하더라도 Data의 복구가 가능합니다.


String / Set / Sorted Set / Hash / List등의 다양한 Data Type을 지원합니다.



Redis 설치 준비


본 설치는 GCP(Google Cloud Platform)의CentOS 7을 기준으로 설치를 진행합니다.

Yum을 통해 설치하는 방법과 Redis를 직접 다운로드 받아 설치하는 방법이 있으며, 본 포스팅은 Redis를 직접 다운로드 받은 후 설치하는 것을 기준으로 합니다.


  1. Redis Compile 시 필요한 gcc-c++ 설치

    sudo yum -y install gcc-c++




  2. Memory 설정
    - 메모리 사용이 허용량을 넘어가게 될 경우에 대한 처리 입니다.

    $> sudo sysctl vm.overcommit_memory=1
    $> sudo echo "vm.overcommit_memory=1" >> /etc/sysctl.conf



    아래의 명령어로 잘 적용이 되었는지 확인합니다.

    $> suco sysctl -| grep vm.overcommit_memory






  3. TCP Backlog 설정
    - 아래의 설정을 하지 않고 Redis 구동 시 TCP Backlog 경고가 발생합니다.
    - Accept limit 설정이 511로 되어있지만 Linux의 기본값은 128로 되어있기 때문에 강제로 128로 적용된다는 경고입니다.
    - 아래의 명령어로 Accept limit을 변경합니다.

    $> sudo sysctl -w net.core.somaxconn=65535
    $> sudo echo "net.core.somaxconn=65535" >> /etc/sysctl.conf



    아래의 명령어로 잘 적용이 되었는지 확인합니다.

    $> sudo sysctl -|grep net.core.somaxconn=65535




  4. THP 설정
    - "[CentOS] THP(Transparent Huge Pages) 란?" 포스팅을 참조하여 THP 설정을 진행합니다.

  5. Redis Download

    $> wget http://download.redis.io/releases/redis-4.0.2.tar.gz




Redis 설치


다운로드 받은 Redis의 압축을 해제 합니다.

$> sudo tar -zxvf redis-4.0.2.tar.gz



압축을 해제한 Redis의 폴더로 이동합니다.

$> cd redis-4.0.2



Make 명령어로 컴파일 합니다.      

$> sudo make



Make에서 에러가 없다면 "make install"을 입력합니다.
 - 아래와 같이 에러사항이 없으면 성공입니다.

$> sudo make install
cd src && make install
make[1]: Entering directory `/home/ossian/redis-4.0.2/src'
    CC Makefile.dep
make[1]: Leaving directory `/home/ossian/redis-4.0.2/src'
make[1]: Entering directory `/home/ossian/redis-4.0.2/src'
Hint: It's a good idea to run 'make test' ;)
 
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
make[1]: Leaving directory `/home/ossian/redis-4.0.2/src'



make install까지 완료되었으면 redis 디렉토리의 utils 경로로 이동합니다.

$> cd utils
$> pwd
/home/ossian/redis-4.0.2/utils



utils 디렉토리 안에 있는 "install_server.sh"를 실행합니다.

$> sudo ./install_server.sh



Welcome to the redis service installer
This script will help you easily set up a running redis server
 
Please select the redis port for this instance: [6379]   # Redis를 실행할 Port 번호를 입력합니다.
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] # Redis의 Config.conf 저장 위치를 지정합니다.
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] # Redis의 Log 저장 위치를 지정합니다.
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379# Redis의 Data directory 위치를 지정합니다.
Selected default - /var/lib/redis/6379
Please select the redis executable path [] /usr/local/bin/redis-server # Redis의 실행 위치를 지정합니다.
Selected config:
Port           : 6379
Config file    : /etc/redis/6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
[ossian@redis-master utils]$ 



아래의 명령어로 Redis가 잘 실행되었는지 확인합니다.

$> ps -ef |grep redis
root      4467     1  0 15:25 ?        00:00:00 /usr/local/bin/redis-server 127.0.0.1:6379
ossian    4522   946  0 15:33 pts/0    00:00:00 grep --color=auto redis



아래의 명령어로 Redis의 Log를 확인합니다. 로그에 에러로그가 없다면 정상적으로 설치된 것입니다.

$> tail -16 /var/log/redis_6379.log
4467:M 07 Nov 15:25:27.940 # Server initialized
4467:M 07 Nov 15:25:27.941 * Ready to accept connections




Redis 실행 테스트


아래와 같이 Redis Client를 사용하여 간단한 Redis 실행 테스트를 해봅니다. "ping"이라고 입력 시 "pong"라는 문구가 출력되면 정상적으로 작동하는 것 입니다.

$> redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379>



아래와 같이 키=값 구조로 데이터를 입력 후 출력 시 정상적으로 출력이 된다면 Redis가 정상적으로 작동하는 것 입니다.

127.0.0.1:6379> set myKey myValue
OK
127.0.0.1:6379> get myKey
"myValue"
127.0.0.1:6379> 





참고 사이트

 + Redis에 대해 자세히 알게 해주셔서 너무나 감사합니다.

'[DB] > Redis' 카테고리의 다른 글

[DB] Redis Persistance - 데이터 저장  (0) 2017.11.13
[DB] Redis + HAProxy를 활용한 FailOver 구성  (0) 2017.11.09
[DB] Redis Sentinel 구성  (5) 2017.11.08
[DB] Redis Replication 구성  (0) 2017.11.07
profile

Ossian Story

@ossians