NoSQL/Redis

Redis > 설치 > 기본

Krevis 2023. 11. 15. 07:15

설치 방법

  • 패키징 파일 설치
    • 빠르고 간편하다.
    • 파일이 여러 군데 흩어져 저장되어 관리가 어려울 수 있다.
    • 인터넷 연결이 필요하다.
  • 소스 파일을 다운로드해 직접 빌드
    • 번거롭다.
    • 한 서버에 여러 개의 레디스 인스턴스를 띄우고자 할 때에 편할 수 있다.

소스 파일로 설치

https://redis.io/download/

 

다운로드

wget https://github.com/redis/redis/archive/7.2.4.tar.gz

 

압축 풀기

tar -zxvf 7.2.4.tar.gz

 

빌드

cd redis-7.2.4

make

빌드를 위해서 gcc 4.6 버전 이상이 필요하다.

 

기본 디렉터리 내의 bin 디렉터리에 실행 파일 복사하기 위해 make install 수행

make PREFIX=경로 install

 

지정한 경로에 bin 디렉터리 생성 및 파일이 생성된다.

 

실행

bin/redis-server redis.conf

Foreground 모드로 실행된다.

19598:C 02 Feb 2024 07:01:37.485 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
19598:C 02 Feb 2024 07:01:37.485 * Redis version=7.2.4, bits=64, commit=00000000, modified=0, pid=19598, just started
19598:C 02 Feb 2024 07:01:37.485 * Configuration loaded
19598:M 02 Feb 2024 07:01:37.486 * Increased maximum number of open files to 10032 (it was originally set to 256).
19598:M 02 Feb 2024 07:01:37.486 * monotonic clock: POSIX clock_gettime
19598:M 02 Feb 2024 07:01:37.491 # Failed to write PID file: Permission denied
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 7.2.4 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 19598
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           https://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

19598:M 02 Feb 2024 07:01:37.491 # WARNING: The TCP backlog setting of 511 cannot be enforced because kern.ipc.somaxconn is set to the lower value of 128.
19598:M 02 Feb 2024 07:01:37.491 * Server initialized
19598:M 02 Feb 2024 07:01:37.491 * Ready to accept connections tcp

 

중지

Ctrl + c

19598:signal-handler (1706825141) Received SIGINT scheduling shutdown...
19598:M 02 Feb 2024 07:05:41.194 * User requested shutdown...
19598:M 02 Feb 2024 07:05:41.194 * Saving the final RDB snapshot before exiting.
19598:M 02 Feb 2024 07:05:41.215 * DB saved on disk
19598:M 02 Feb 2024 07:05:41.215 * Removing the pid file.
19598:M 02 Feb 2024 07:05:41.216 # Redis is now ready to exit, bye bye...

 

백그라운드 프로세스 종료

bin/redis-cli shutdown

Docker 기반 설치

이미지 다운로드

https://hub.docker.com/_/redis

Version: Stable 7.2.1

docker pull redis:7.2.1

브릿지 네트워크 생성

여러 Docker Container를 하나의 네트워크로 연결하려면 별도의 브릿지 네트워크를 생성해야 한다.

docker network ls

docker network create redis-bridge

docker network inspect redis-bridge

Redis 서버 실행

docker run --name some-redis -p 6379:6379 --network redis-bridge -d redis:7.2.1 redis-server --save 60 1 --loglevel warning

 

- 최소 1개의 쓰기 작업이 수행되었다면 매 60초 마다 DB 스냅샷을 1회 생성하는 영속성 저장소와 함께 실행
- 호스트에 6379포트로 바인딩
- /data 볼륨에 저장된다

 

별도 redis.conf 설정 시

docker run --name some-redis -p 6379:6379 -v /경로/redis/conf:/usr/local/etc/redis --network redis-network -d redis:7.2.1 redis-server --save 60 1 --loglevel warning

 

Redis CLI로 Redis 서버에 접속

docker run -it --network redis-bridge --rm redis:7.2.1 redis-cli -h some-redis

redis.conf 설정하여 이미지 만들기

$ vi Dockerfile

FROM redis:7.2.1
COPY redis.conf /usr/local/etc/redis/redis.conf
CMD [ "redis-server", "/usr/local/etc/redis/redis.conf" ]

 

$ docker build -t some-redis .

직접 만든 이미지로 컨테이너 실행

$ docker run --name some-redis --network redis-bridge some-redis

'NoSQL > Redis' 카테고리의 다른 글

Redis > 설치 > Docker Compose 기반 Replication, Sentinel, Cluster  (0) 2024.04.03
Redis > 접속 및 명령  (0) 2024.02.02
Redis > 환경설정  (2) 2024.02.02