개발자/리눅스

[CentOS] Redis 설치

푸루닉 2024. 3. 27. 16:30

CentOS 마지막 포스팅은 Redis 설치이다.

 

1. EPEL Repository 설치

yum install epel-release

 

2. yum 업데이트

yum update

 

3. 특정 버전 설치(지정하지 않을 시 가장 최신 redis 받게됨)

yum install redis-3.2.12

 

4.redis 시작 및 자동시작 설정

systemctl start redis

systemctl enable redis

 

5. 설치 확인

# pong이 반환되면 성공
redis-cli ping
pong

6. 방화벽 추가 후 재시작

firewall-cmd --zone=public --add-service=redis --permanent

firewall-cmd --reload

 

7. 외부접속 허용

vi /etc/redis.conf

쭉 내리다보면 bind 127.0.0.1이 있을텐데 주석 처리 후

bind 0.0.0.0 으로 수정

(모든 외부접속 허용)

# 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 127.0.0.1
bind 0.0.0.0

# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.
#
# When protected mode is on and if:

 

8. 외부접속 확인

netstat -nlpt|grep 6379
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      6489/redis-server 0

9. redis 암호 설정

 

vi /etc/redis.conf

겁나 많은 위치 찾는법 : /찾고싶은 단어 (n 누르면 다음으로)

 

requirepass f~~ 이부분 주석 지우고 비밀번호 지정하면 됩니다.

################################## SECURITY ###################################

# Require clients to issue AUTH <PASSWORD> before processing any other
# commands.  This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
requirepass 님들이 원하는 비밀번호

# Command renaming.
#
# It is possible to change the name of dangerous commands in a shared
# environment. For instance the CONFIG command may be renamed into something
# hard to guess so that it will still be available for internal-use tools
# but not available for general clients.
#
# Example:
#
# rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
#
# It is also possible to completely kill a command by renaming it into
# an empty string:
#
# rename-command CONFIG ""
#
# Please note that changing the name of commands that are logged into the
# AOF file or transmitted to slaves may cause problems.

10. 암호 접속 확인

(순서대로 쳐서 아래와같이 나오면 됩니다. 비밀번호 설정이 됐다면.)

./redis-cli
OK
auth 님들이 설정한 비밀번호
OK
ping
PONG

redis란?

Redis는 "Remote Dictionary Server"의 약자로, 인터넷 상에서 데이터를 저장하고 관리하기 위한 프로그램입니다. 매우 빠른 속도로 데이터를 처리할 수 있어, 웹사이트나 애플리케이션에서 실시간으로 정보를 처리해야 할 때 자주 사용됩니다. 

 

Redis를 사용하는 이유

예를 들어, 온라인 쇼핑몰을 운영한다고 가정해보겠습니다. 고객들이 상품을 보고, 장바구니에 담고, 결제하는 모든 과정에서 정보를 빠르게 처리해야 합니다. 특히, 많은 사람들이 동시에 쇼핑몰을 이용할 때, 서버는 수많은 요청을 신속하게 처리할 수 있어야 하죠. 이런 상황에서 Redis가 유용하게 사용됩니다.

 

Redis의 특징

빠른 속도: Redis는 메모리 내에 데이터를 저장하기 때문에, 하드 디스크보다 훨씬 빠르게 데이터에 접근할 수 있습니다. 이로 인해, 데이터를 저장하고, 읽어오는 작업이 매우 빠릅니다.

키-값 저장소: Redis는 데이터를 '키(Key)'와 '값(Value)'의 형태로 저장합니다. 예를 들어, '사용자ID'를 키로 하고, 그 사용자의 정보를 값으로 저장할 수 있습니다. 이런 방식으로 데이터를 관리하기 때문에, 특정 데이터를 찾을 때 매우 효율적입니다.

다양한 데이터 구조 지원: Redis는 단순한 키-값 저장 외에도 리스트, 집합, 해시 등 다양한 형태의 데이터 구조를 지원합니다. 이를 통해 개발자는 필요에 따라 유연하게 데이터를 저장하고 관리할 수 있습니다.

지속성: 메모리 내에 데이터를 저장하더라도, 설정에 따라 이 데이터를 디스크에 저장할 수 있습니다. 이로 인해 시스템이 재시작되더라도 데이터를 유실하지 않고 보존할 수 있습니다.

다양한 사용 사례: 세션 관리, 메시징 시스템, 실시간 분석, 캐싱 등 다양한 분야에서 Redis를 활용할 수 있습니다.