728x90
1. Redis 설치
설치할 CentOS 서버에 Redis가 설치되어 있는지 확인한다.
$ redis-server --version
-bash: redis-server: command not found
※ 레디스가 설치되어 있다면 위와같이 command not found 메시지를 나타낼 것이다.
Redis가 설치되어 있지 않다면 아래 명령을 통해 Redis를 설치한다.
$ sudo yum install -y redis
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.kakao.com
* epel: mirror-nrt.yuki.net.uk
* extras: mirror.kakao.com
* updates: mirror.kakao.com
Resolving Dependencies
--> Running transaction check
---> Package redis.x86_64 0:3.2.12-2.el7 will be installed
--> Processing Dependency: libjemalloc.so.1()(64bit) for package: redis-3.2.12-2.el7.x86_64
--> Running transaction check
---> Package jemalloc.x86_64 0:3.6.0-1.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=========================================================================================================================================================================== Package Arch Version Repository Size
===========================================================================================================================================================================Installing:
redis x86_64 3.2.12-2.el7 epel 544 k
Installing for dependencies:
jemalloc x86_64 3.6.0-1.el7 epel 105 k
Transaction Summary
===========================================================================================================================================================================Install 1 Package (+1 Dependent package)
Total download size: 648 k
Installed size: 1.7 M
Downloading packages:
(1/2): jemalloc-3.6.0-1.el7.x86_64.rpm | 105 kB 00:00:00
(2/2): redis-3.2.12-2.el7.x86_64.rpm | 544 kB 00:00:00
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------Total 1.1 MB/s | 648 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Installing : jemalloc-3.6.0-1.el7.x86_64 1/2
Installing : redis-3.2.12-2.el7.x86_64 2/2
Verifying : redis-3.2.12-2.el7.x86_64 1/2
Verifying : jemalloc-3.6.0-1.el7.x86_64 2/2
Installed:
redis.x86_64 0:3.2.12-2.el7
Dependency Installed:
jemalloc.x86_64 0:3.6.0-1.el7
Complete!
설치가 완료되면 Redis 서비스 시작한다.
$ sudo systemctl start redis
이후 CentOS7 재부팅시 Rdis 서비스가 자동 실행되게 설정을 잡아준다.
$ sudo systemctl enable redis
Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /usr/lib/systemd/system/redis.service.
2. Reids 클라이언트 확인
Redis 설치가 완료되면 Redis 클라이언트를 실행하여 정상 작동 유무를 확인한다.
Reids 콘솔 접속
$ redis-cli
127.0.0.1:6379>
Reids 콘솔이 열리면 정상적으로 연결된 것이다.
127.0.0.1:6792> ping
PING
`PING 이라는 응답을 받으면 정상
127.0.0.1:6379> set testkey "Hello, Redis!"
OK
`OK` 라는 응답을 받으면 정상
127.0.0.1:6379> get testkey
"Hello, Redis!"
`Hello, Redis!` 라는 응답을 받으면 정상
Redis 클라이언트 종료
127.0.0.1:6379> exit
3. Redis 외부 연결 허용
CentOS7 서버의 Redis에 대하여 외부 접근을 허용하려면 몇가지 구성이 필요하다.
1) 방화벽 설정에 Redis 서비스 PORT( 6379 ) 예외 처리
방화벽에 Redis 기본 포트인 6379 포트를 추가하여 준다.
$ sudo firewall-cmd --zone=public --add-port=6379/tcp --permanent
success
방화벽 재시작
$ sudo firewall-cmd --reload
success
2) Redis 구성 파일 수정
Redis 구성파일( `/etc/reids.conf` )을 수정하여 외부에서의 연결을 허용한다.
$ sudo vim /etc/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 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:
#
# 1) The server is not binding explicitly to a set of addresses using the
# "bind" directive.
# 2) No password is configured.
#
# The server only accepts connections from clients connecting from the
# IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
# sockets.
#
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
#protected-mode yes
protected-mode no
# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.
port 6379
~~ 이 하 생 략 ~~
################################## 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 foobared
requirepass 사용자지정_비밀번호
~~ 이 하 생 략 ~~
bind | 0.0.0.0 |
protected-mode | no |
requirepass | 사용자지정_비밀번호 |
`bind`를 0.0.0.0으로 설정하면 모둔 IP주소에대하여 연결이 허용되며,
`protected-mode`를 no로 설정하면 외부에서의 접근이 가능하다.
`requirepass` 설정을 통해 비밀번호를 설정할 수 있다.
마지막으로 Reids 서비스 재시작 해준다.
$ sudo systemctl restart redis
728x90
'LINUX > CentOS' 카테고리의 다른 글
[CentOS7] Oracle JDK 1.8 설치 및 환경변수 설정 (0) | 2024.04.11 |
---|---|
[CentOS] Docker 설치하기 (4) | 2024.03.05 |
[LINUX] CentOS7 - MediaWiki 설치 및 사용 (0) | 2023.08.07 |
[CentOS7] 사용자 계정 생성 및 Directory 만들기 (0) | 2023.07.31 |
[Linux] MariaDB 설치 및 세팅 (6) | 2023.02.23 |