티스토리 뷰

728x90
반응형

본 포스팅에서는 Redis 5.x 설치 및 활용 가이드입니다.


지난 시간에 이어서 Redis OpenSource Software를 설치하고 활용할 만한 팁을 공유하는 시간을 갖도록 하겠습니다.

 

1) Redis 5.x 설치


설치 방법은 정말 간단합니다. 총 3 Step으로 나뉘어져 있으며, 설치하기 위해서는 gcc가 설치되어 있어야 하고, 인터넷이 되는 CentOS 환경에서 진행하였습니다.

 

Step 1) 바이너리 다운로드 (wget http://download.redis.io/releases/redis-5.0.5.tar.gz)


[root@localhost ~]# wget http://download.redis.io/releases/redis-5.0.5.tar.gz
--2019-05-30 23:20:04--  http://download.redis.io/releases/redis-5.0.5.tar.gz
Resolving download.redis.io (download.redis.io)... 109.74.203.151
Connecting to download.redis.io (download.redis.io)|109.74.203.151|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1975750 (1.9M) [application/x-gzip]
Saving to: 'redis-5.0.5.tar.gz'

100%[============================================================>] 1,975,750   2.05MB/s   in 0.9s   

2019-05-30 23:20:06 (2.05 MB/s) - 'redis-5.0.5.tar.gz' saved [1975750/1975750]

[root@localhost ~]# 


Step 2) 압축해제 및 디렉토리 이동


[root@localhost ~]# tar xzf redis-5.0.5.tar.gz
[root@localhost ~]# cd redis-5.0.5/
[root@localhost redis-5.0.5]#


Step 3) 컴파일


[root@localhost redis-5.0.5]# make
cd src && make all
make[1]: Entering directory `/root/redis-5.0.5/src'
    CC Makefile.dep
make[1]: Leaving directory `/root/redis-5.0.5/src'
make[1]: Entering directory `/root/redis-5.0.5/src'
rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-rdb redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html Makefile.dep dict-benchmark
(cd ../deps && make distclean)
make[2]: Entering directory `/root/redis-5.0.5/deps'
(cd hiredis && make clean) > /dev/null || true
(cd linenoise && make clean) > /dev/null || true
(cd lua && make clean) > /dev/null || true
(cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true
(rm -f .make-*)
make[2]: Leaving directory `/root/redis-5.0.5/deps'
(rm -f .make-*)
echo STD=-std=c99 -pedantic -DREDIS_STATIC='' >> .make-settings
echo WARN=-Wall -W -Wno-missing-field-initializers >> .make-settings
echo OPT=-O2 >> .make-settings
echo MALLOC=jemalloc >> .make-settings
echo CFLAGS= >> .make-settings
echo LDFLAGS= >> .make-settings
echo REDIS_CFLAGS= >> .make-settings
echo REDIS_LDFLAGS= >> .make-settings
echo PREV_FINAL_CFLAGS=-std=c99 -pedantic -DREDIS_STATIC='' -Wall -W -Wno-missing-field-initializers -O2 -g -ggdb   -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src -DUSE_JEMALLOC -I../deps/jemalloc/include >> .make-settings
echo PREV_FINAL_LDFLAGS=  -g -ggdb -rdynamic >> .make-settings
(cd ../deps && make hiredis linenoise lua jemalloc)
make[2]: Entering directory `/root/redis-5.0.5/deps'
(cd hiredis && make clean) > /dev/null || true
(cd linenoise && make clean) > /dev/null || true
(cd lua && make clean) > /dev/null || true
(cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true
(rm -f .make-*)
(echo "" > .make-cflags)
(echo "" > .make-ldflags)
MAKE hiredis

...

...


# 설치 중 다음과 같은 error 발생 시 아래와 같이 dept 디렉토리로 이동하여 make를 실행한다. (make hiredis jemalloc linenoise lua)


[root@ip-192-168-106-237 redis-5.0.5]# make
cd src && make all
make[1]: Entering directory `/root/redis-5.0.5/src'
    CC Makefile.dep
make[1]: Leaving directory `/root/redis-5.0.5/src'
make[1]: Entering directory `/root/redis-5.0.5/src'
    CC adlist.o
In file included from adlist.c:34:0:
zmalloc.h:50:10: fatal error: jemalloc/jemalloc.h: No such file or directory
 #include <jemalloc/jemalloc.h>
          ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/root/redis-5.0.5/src'
make: *** [all] Error 2
[root@ip-192-168-106-237 redis-5.0.5]#

==>

[root@ip-192-168-106-237 redis-5.0.5]# cd deps/
[root@ip-192-168-106-237 deps]# make hiredis jemalloc linenoise lua
MAKE hiredis
cd hiredis && make static
make[1]: Entering directory `/root/redis-5.0.5/deps/hiredis'
cc -std=c99 -pedantic -c -O3 -fPIC  -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb  net.c
cc -std=c99 -pedantic -c -O3 -fPIC  -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb  hiredis.c
cc -std=c99 -pedantic -c -O3 -fPIC  -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb  sds.c
cc -std=c99 -pedantic -c -O3 -fPIC  -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb  async.c
cc -std=c99 -pedantic -c -O3 -fPIC  -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb  read.c
ar rcs libhiredis.a net.o hiredis.o sds.o async.o read.o
make[1]: Leaving directory `/root/redis-5.0.5/deps/hiredis'
MAKE jemalloc
cd jemalloc && ./configure --with-version=5.1.0-0-g0 --with-lg-quantum=3 --with-jemalloc-prefix=je_ --enable-cc-silence CFLAGS="-std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops " LDFLAGS=""
configure: WARNING: unrecognized options: --enable-cc-silence
checking for xsltproc... false
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out

...

[root@ip-192-168-106-237 deps]# cd ..

[root@ip-192-168-106-237 redis-5.0.5]# make install
cd src && make install
make[1]: Entering directory `/root/redis-5.0.5/src'
    CC adlist.o
    CC quicklist.o
    CC ae.o
    CC anet.o
    CC dict.o
    CC server.o

...


2) Redis 기동


[root@localhost redis-5.0.5]# src/redis-server
13879:C 30 May 2019 23:44:11.641 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
13879:C 30 May 2019 23:44:11.641 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=13879, just started
13879:C 30 May 2019 23:44:11.641 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf
13879:M 30 May 2019 23:44:11.641 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 5.0.5 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 13879
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

13879:M 30 May 2019 23:44:11.642 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
13879:M 30 May 2019 23:44:11.642 # Server initialized
13879:M 30 May 2019 23:44:11.643 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
13879:M 30 May 2019 23:44:11.643 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
13879:M 30 May 2019 23:44:11.643 * Ready to accept connections


기동이 완료되면 redis-cli에 접속해 보겠습니다.


[root@localhost redis-5.0.5]# src/redis-cli
127.0.0.1:6379> set for bar
OK
127.0.0.1:6379> get for
"bar"
127.0.0.1:6379> 


위와 같이 사용가능한 Command 목록은 아래에서 확인할 수 있습니다.

 

 

https://redis.io/topics/rediscli

 

redis-cli, the Redis command line interface – Redis

*redis-cli, the Redis command line interface redis-cli is the Redis command line interface, a simple program that allows to send commands to Redis, and read the replies sent by the server, directly from the terminal. It has two main modes: an interactive m

redis.io

Redis를 활용하면 다음과 같은 상황에서 이점을 획득할 수 있습니다.

예를 들어 ELK Stack을 활용하여 Log를 수집하여 분석하는 시스템을 구축하고자 합니다. 이때 로그를 수집하기 위해 LogStash는 로그를 전송하게 되는데 전송되는데 사용되는 네트워크 및 I/O 비용이 어마무시하게 됩니다.

이때 Redis를 인스턴스와 로그 저장소 사이에 두어 로그를 빠르게 전송하면서도 일정 수치를 넘어서지 않도록 안정성 역시 확보할 수 있게 됩니다.

비슷하게 생각해 보자면, WAS에서 DB로 데이터를 조회해 오는데 Result Set이 어마무시하게 많은 데이터를 조회할 경우 OOM이나 Bottleneck 등의 현상을 유발하게 되는데, Redis를 두어 안정성을 확보하는 방안을 생각해 볼 수 있습니다.

이와 같은 구조는 다음 시간에 차차 구성 실습 및 설계 방안에 대해 논의해 보겠습니다.

728x90
반응형