DB/Redis

Redis local 설치하기

_sparrow 2020. 12. 25. 00:25
반응형

redis.io/topics/quickstart

 

Redis Quick Start – Redis

*Redis Quick Start This is a quick start document that targets people without prior experience with Redis. Reading this document will help you: Download and compile Redis to start hacking. Use redis-cli to access the server. Use Redis from your application

redis.io

wget http://download.redis.io/redis-stable.tar.gz

tar xvzf redis-stable.tar.gz

cd make

make 작동안되면 오류에 뜨는 라이브러리 설치

 

실행테스트

$ redis-server 구동시 다른 터미널에서 $redis-cli ping 입력시 pong 반납확인

 

레디스 지속운영을 위한 환경설정 

 

압축해제시 생성된 redis.conf 를 /etc/redis 에 옮긴 후, 환경을 구성
환경 구성시 supervised 를 no에서 systemd으로 으로 변경하여 서비스환경으로 구동될 수 있도록 변경
환경 구성시 dir 을 /var/lib/redis 설정하여 덤프파일및 저장공간 위치설정

$sudo mkdir /etc/redis

$sudo cp /redis-stable/redis.conf /etc/redis

 

$sudo vi /etc/redis/redis.conf

# If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
#   supervised no      - no supervision interaction
#   supervised upstart - signal upstart by putting Redis into SIGSTOP mode
#   supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
#   supervised auto    - detect upstart or systemd method based on
#                        UPSTART_JOB or NOTIFY_SOCKET environment variables
# Note: these supervision methods only signal "process is ready."
#       They do not enable continuous liveness pings back to your supervisor.
supervised systemd < 수정


# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir /var/lib/redis < 수정

 

sudo vi /etc/systemd/system/redis.service 입력

[Unit]
Description=Redis In-Memory Data Store
After=network.target

[Service]
User=redisuser
Group=redisuser
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always

[Install]
WantedBy=multi-user.target

 

6. redis를 구동할 사용자 생성

redis를 구동할 사용자를 생성한다. 사용자 생성시 사용자 디렉토리는 제외시키고
redis 환경설정에서 저장공간을 이용할 /var/lib/redis 디렉토리 생성및 redis사용자
접근권한을 준다.

 

$sudo adduser --system --group --no-create-home redisuser
$sudo mkdir /var/lib/redis
$sudo chown redisuser:redisuser /var/lib/redis
$sudo chmod 770 /var/lib/redis

7. 시스템 부팅시 실행되도록 구성

시스템 부팅시 redis가 자동실행 되도록 서비스에 등록 한다.

$sudo systemctl enable redis

 

실행결과

Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /etc/systemd/system/redis.service.

8. redis구동 및 상태확인

redis를 서비스명령으로 구동및 상태를 확인한다.

서비스 시작및 상태확인

 

$sudo systemctl start redis
$sudo systemctl status redis

 

# 결과

● redis.service - Redis In-Memory Data Store
   Loaded: loaded (/etc/systemd/system/redis.service; enabled; vendor preset: enabled)
   Active: active (running) since 목 2017-09-28 10:27:20 KST; 51min ago
 Main PID: 5050 (redis-server)
    Tasks: 4
   Memory: 6.3M
      CPU: 1.576s
   CGroup: /system.slice/redis.service
           └─5050 /usr/local/bin/redis-server 127.0.0.1:6379   

 

서비스 재시작

$sudo systemctl restart redis

 

원격접속 허가 /etc/redis/redis.conf

 

기본적으로 서비스는 로컬에서만 접속할 수가 있다 이를 원격으로 접속할 수 있도록 변경한다.
/etc/redis로 이동후 redis.conf 를 변경한다.
환경 구성시 bind 항목을 기존 127.0.0.1 을 0.0.0.0 으로 변경후
서비스를 재시작한다.

환경설정 bind /etc/redis/redis.conf

################################## NETWORK #####################################
# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 lookback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 0.0.0.0 < 127.0.0.1 에서 수정
 
반응형