관리 메뉴

nalaolla

Redis – install 본문

SPRING/Redis

Redis – install

날아올라↗↗ 2020. 2. 18. 14:05
728x90

Redis는 데이터베이스, 캐시 및 메시지 브로커로 사용되는 오픈 소스 in-memory 데이터 구조 저장소입니다. string, hashes, lists, sets, sorted sets 데이터 구조를 지원하며. pub/sub를 통한 메시지 브로커 기능도 지원합니다. 또한 Redis Sentinel, Redis Cluster를 통해 고 가용성 및 자동 파티셔닝을 제공합니다.

다운로드 및 설치

CentOS 환경 하에서 설치하는 법을 설명합니다. Redis의 최신 버전은 https://redis.io/download 에서 확인 할 수 있습니다. 서버의 적당한 위치에 다운로드합니다.

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

컴파일 시 gcc는 필수이므로 설치가 안되어 있을 경우 설치합니다.

$ sudo yum install gcc

다운받은 파일을 압축 해제합니다.

$ tar -xvf redis-5.0.4.tar.gz

Redis 설치 시 필요한 dependencies를 설치합니다.

$ cd redis-5.0.4

$ cd deps

$ make hiredis lua jemalloc linenoise

Redis를 설치합니다.

$ cd ..

$ make

$ sudo make install

cd src && make install

make[1]: Entering directory `/home/ec2-user/apps/redis-5.0.4/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/ec2-user/apps/redis-5.0.4/src'

$ cd /usr/local/bin

$ ls

redis-benchmark  redis-check-rdb  redis-sentinel

redis-check-aof  redis-cli        redis-server

install script로 Redis 인스턴스 환경 셋업

install_server.sh로 생성할 Redis 인스턴스의 환경을 설정합니다.
여러 개의 Redis설정이 필요하면 아래 스크립트 수행을 반복하면 됩니다.
Please select the redis executable path []는 입력이 필요한데 executable path인
/usr/local/bin/redis-server를 입력하면 됩니다.

$ cd utils

$ 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] 6300

Please select the redis config file name [/etc/redis/6300.conf]

Selected default - /etc/redis/6300.conf

Please select the redis log file name [/var/log/redis_6300.log]

Selected default - /var/log/redis_6300.log

Please select the data directory for this instance [/var/lib/redis/6300]

Selected default - /var/lib/redis/6300

Please select the redis executable path [] /usr/local/bin/redis-server

Selected config:

Port           : 6300

Config file    : /etc/redis/6300.conf

Log file       : /var/log/redis_6300.log

Data dir       : /var/lib/redis/6300

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/6300.conf => /etc/init.d/redis_6300

Installing service...

Successfully added to chkconfig!

Successfully added to runlevels 345!

Starting Redis server...

Installation successful!

Redis start / stop / restart

$ sudo service redis_6300 {start / stop / restart}

Redis 인스턴스 확인 및 테스트

$ ps -ef | grep redis

root     12969     1  0 14:51 ?        00:00:00 /usr/local/bin/redis-server 127.0.0.1:6300

$ redis-cli -p 6300

127.0.0.1:6300> set a b

OK

127.0.0.1:6300> get a

"b"

Redis Log 확인

$ cd /var/log

$ vi -R redis_6300.log

12968:C 24 Apr 2019 14:51:24.235 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo

12968:C 24 Apr 2019 14:51:24.235 # Redis version=5.0.4, bits=64, commit=00000000, modified=0, pid=12968, just started

12968:C 24 Apr 2019 14:51:24.235 # Configuration loaded

12969:M 24 Apr 2019 14:51:24.238 * Increased maximum number of open files to 10032 (it was originally set to 1024).

                _._

           _.-``__ ''-._

      _.-``    `.  `_.  ''-._           Redis 5.0.4 (00000000/0) 64 bit

  .-`` .-```.  ```\/    _.,_ ''-._

 (    '      ,       .-`  | `,    )     Running in standalone mode

 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6300

 |    `-._   `._    /     _.-'    |     PID: 12969

  `-._    `-._  `-./  _.-'    _.-'

 |`-._`-._    `-.__.-'    _.-'_.-'|

 |    `-._`-._        _.-'_.-'    |           http://redis.io

  `-._    `-._`-.__.-'_.-'    _.-'

 |`-._`-._    `-.__.-'    _.-'_.-'|

 |    `-._`-._        _.-'_.-'    |

  `-._    `-._`-.__.-'_.-'    _.-'

      `-._    `-.__.-'    _.-'

          `-._        _.-'

              `-.__.-'

 

12969:M 24 Apr 2019 14:51:24.238 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

12969:M 24 Apr 2019 14:51:24.238 # Server initialized

12969:M 24 Apr 2019 14:51:24.238 # 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.

12969:M 24 Apr 2019 14:51:24.238 # 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.

12969:M 24 Apr 2019 14:51:24.238 * Ready to accept connections

12969:M 24 Apr 2019 15:06:25.099 * 1 changes in 900 seconds. Saving...

12969:M 24 Apr 2019 15:06:25.099 * Background saving started by pid 13425

13425:C 24 Apr 2019 15:06:25.100 * DB saved on disk

13425:C 24 Apr 2019 15:06:25.101 * RDB: 0 MB of memory used by copy-on-write

12969:M 24 Apr 2019 15:06:25.199 * Background saving terminated with success

Trobleshooting

maximum open files 설정

WARNING Increased maximum number of open files to 10032 (it was originally set to 1024). 발생할경우

현재 값 확인

$ ulimit -n

값이 작으면(<65535) 아래 파일을 수정합니다.

$ sudo vi /etc/security/limits.conf

root soft nofile 168724

root hard nofile 168724

overcommit_memory 설정

WARNING overcommit_memory is set to 0! 발생할 경우

현재 값 확인

$ /sbin/sysctl -a | grep vm.overcommit_memory

1이 아닌경우 1로 세팅합니다.

$ sudo /sbin/sysctl -w vm.overcommit_memory=1

리부팅 시에도 적용되도록 /etc/sysctl.conf에 추가합니다.

$ vi /etc/sysctl.conf

vm.overcommit_memory=1

Transparent Huge Pages (THP) support enabled 설정

WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. 발생할 경우

현재 값 확인

$ cat /sys/kernel/mm/transparent_hugepage/enabled

always [madvise] never

never가 선택 안되어 있을 경우

$ sudo su

$ echo never > /sys/kernel/mm/transparent_hugepage/enabled

리부팅 시에도 적용되도록 rc.local에 추가

$ sudo vi /etc/rc.local

echo never > /sys/kernel/mm/transparent_hugepage/enabled

CentOS 7에서는 부팅 시 rc.local이 자동 실행되지 않으므로 아래와 같이 설정합니다.

$ sudo chmod u+x /etc/rc.d/rc.local

$ sudo systemctl start rc-local

TCP backlog 설정

WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. 발생할 경우

현재값 확인

$ cat /proc/sys/net/core/somaxconn

128

1024 이상으로 수정합니다.

$ sudo su

$ sysctl -w net.core.somaxconn=1024

리부팅 시에도 적용을 위해 다음 내용을 추가합니다.

$ sudo vi /etc/sysctl.conf

net.core.somaxconn=1024

위의 내용을 모두 적용하고 서버를 리부팅한 후에 Redis를 시작하면 WARNING메시지가 모두 사라진 것을 확인 가능합니다.

3408:C 24 Apr 2019 16:09:35.485 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo

3408:C 24 Apr 2019 16:09:35.485 # Redis version=5.0.4, bits=64, commit=00000000, modified=0, pid=3408, just started

3408:C 24 Apr 2019 16:09:35.485 # Configuration loaded

                _._

           _.-``__ ''-._

      _.-``    `.  `_.  ''-._           Redis 5.0.4 (00000000/0) 64 bit

  .-`` .-```.  ```\/    _.,_ ''-._

 (    '      ,       .-`  | `,    )     Running in standalone mode

 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6300

 |    `-._   `._    /     _.-'    |     PID: 3409

  `-._    `-._  `-./  _.-'    _.-'

 |`-._`-._    `-.__.-'    _.-'_.-'|

 |    `-._`-._        _.-'_.-'    |           http://redis.io

  `-._    `-._`-.__.-'_.-'    _.-'

 |`-._`-._    `-.__.-'    _.-'_.-'|

 |    `-._`-._        _.-'_.-'    |

  `-._    `-._`-.__.-'_.-'    _.-'

      `-._    `-.__.-'    _.-'

          `-._        _.-'

              `-.__.-'

 

3409:M 24 Apr 2019 16:09:35.488 # Server initialized

3409:M 24 Apr 2019 16:09:35.488 * DB loaded from disk: 0.000 seconds

3409:M 24 Apr 2019 16:09:35.488 * Ready to accept connections

 

 

[출처] https://daddyprogrammer.org/post/1229/redis-single-instance/

728x90