본문 바로가기

Software Engineering/Redis

[Redis] Ubuntu 환경에서 source code로 설치한 redis 삭제하기

사진: Unsplash 의 Pascal Debrunner

 

지난 글에서는 폐쇠망 환경에서 redis를 설치하기 위해 소스 코드를 다운로드 받아서 redis를 설치하는 방법을 알아보았습니다. 이 경우에는 패키지 관리자가 redis 삭제를 지원하지 않기 때문에 수동으로 redis를 삭제해야 합니다. 진행하는 순서는 삭제 해야 할 서비스와 파일을 확인, 서비스 삭제, 파일 삭제 순서로 진행합니다.

실행 환경

  • Ubuntu 20.04
  • Redis 6.2.7 (소스 코드 빌드, systemd로 서비스 등록)

Redis 서비스 및 삭제 대상 파일 확인

먼저 삭제 할 redis 서비스명을 확인합니다. 서비스명을 알고 있다면 건너뛰어도 좋습니다.

# redis로 등록된 서비스 목록 확인
$ systemctl list-units --type=service --all | grep redis
  redis_6379.service    loaded    inactive dead    Redis In-Memory Data Store    # redis_6379 이름으로 서비스 등록됨

 

이제 redis_6379로 등록된 서비스 설정 파일을 확인하여, 실행 파일, config 파일 위치를 찾습니다.

# 서비스 파일 확인
$ cat /etc/systemd/system/redis_6379.service 
[Unit]
Description=Redis In-Memory Data Store
After=network.target

[Service]
ExecStart=/usr/local/bin/redis-server /etc/redis/6379.conf    # config 파일 위치
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always
User=redis
Group=redis

[Install]
WantedBy=multi-user.target

 

실행 파일은 /usr/local/bin 디렉토리에, config 파일은 /etc/redis/6379.conf 를 사용하는 것을 확인하였습니다. config 파일의 내용을 확인하여 redis 데이터 파일과 로그 파일이 저장되는 위치를 확인합니다.

# dir + 공백으로 검색
$ cat /etc/redis/6379.conf | grep "dir "
dir /var/redis/6379/

# logfile + 공백으로 검색
$ cat /etc/redis/6379.conf | grep "logfile "
logfile "/var/redis/6379/redis.log"

 

이제 확인한 redis_6379 서비스, /etc/redis/6379.conf 파일, /var/redis/6379의 데이터, 로그 파일을 삭제하도록 하겠습니다.

Redis 서비스 삭제

서비스를 삭제하기 위해 서비스를 해제(disable) 합니다. 서비스를 해제하지 않고 정지 후 삭제하면 systemctl 서비스 목록에 심볼릭 링크가 지워지지 않은 상태로 유지됩니다. 깨끗한 삭제를 위해 먼저 서비스를 해제합니다.

# 서비스 해제
$ sudo systemctl disable redis_6379
Removed /etc/systemd/system/multi-user.target.wants/redis_6379.service.

# 서비스 중지
$ sudo systemctl stop redis_6379

# 서비스 상태 확인
$ sudo systemctl status redis_6379
● redis_6379.service - Redis In-Memory Data Store
     Loaded: loaded (/etc/systemd/system/redis_6379.service; disabled; vendor preset: enabled)    # disalbed 확인
     Active: inactive (dead)    # inactive 확인

 

서비스 파일을 삭제하고 서비스 리스트에서 제거 된 것을 확인 합니다.

# 서비스 파일 삭제
$ sudo rm /etc/systemd/system/redis_6379.service 

# 삭제 여부 확인
$ cat /etc/systemd/system/redis_6379.service 
cat: /etc/systemd/system/redis_6379.service: No such file or directory

# 서비스 리스트 확인 (출력 결과 없음)
$ systemctl list-units --type=service --all | grep redis

 

서비스 파일을 모두 삭제하였습니다. 이제 redis 관련 파일을 삭제하겠습니다.

Redis 파일 삭제

삭제해야 할 파일은 위에서 확인한 redis 실행 파일(/usr/local/bin/redis*), 설정 파일(/etc/redis/6379.conf), 데이터 파일(/var/redis/6379/dump.rdb), 로그 파일(/var/redis/6379/redis.log) 4가지 항목 입니다. 이 파일은 설치 방법에 따라 다를 수 있으니,위에서 진행한 순서대로 대상 파일을 확인합니다. 각 파일을 순서대로 삭제합니다.

 

실행 파일을 삭제합니다.

# 실행 파일 확인
$ ls /usr/local/bin/redis* -aul
-rwxr-xr-x 1 root root  7266408 Dec 26 10:47 /usr/local/bin/redis-benchmark
lrwxrwxrwx 1 root root       12 Dec 28 06:15 /usr/local/bin/redis-check-aof -> redis-server
lrwxrwxrwx 1 root root       12 Dec 28 06:15 /usr/local/bin/redis-check-rdb -> redis-server
-rwxr-xr-x 1 root root  7184232 Dec 28 03:11 /usr/local/bin/redis-cli
lrwxrwxrwx 1 root root       12 Dec 28 06:15 /usr/local/bin/redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 12809680 Dec 27 13:11 /usr/local/bin/redis-server

# 파일 삭제
$ sudo rm /usr/local/bin/redis*

# 삭제 확인
$ ls /usr/local/bin/redis* -aul
ls: cannot access '/usr/local/bin/redis*': No such file or directory

 

config 파일을 삭제합니다.

# config 파일 확인
$ ls /etc/redis//6379.conf -aul
-rw-r--r-- 1 redis redis 93872 Dec 27 10:50 /etc/redis/6379.conf

# config 파일 삭제
$ sudo rm /etc/redis/6379.conf 

# 삭제 확인
$ ls /etc/redis/6379.conf -aul
ls: cannot access '/etc/redis/6379.conf': No such file or directory

 

데이터 파일, 로그 파일을 삭제합니다.

# 데이터, 로그 파일 확인
$ ls /var/redis/6379/ -aul
total 1960
drwxr-xr-x 2 redis redis    4096 Dec 28 06:11 .
drwxr-xr-x 3 root  root     4096 Dec 27 09:56 ..
-rw-r--r-- 1 redis redis     118 Dec 28 03:11 dump.rdb
-rw-r--r-- 1 redis redis 1989542 Dec 27 11:53 redis.log

# 파일 삭제
$ sudo rm /var/redis/6379/*

# 삭제 확인
$ ls /var/redis/6379/ -aul
total 8
drwxr-xr-x 2 redis redis 4096 Dec 28 06:20 .
drwxr-xr-x 3 root  root  4096 Dec 27 09:56 ..

 

디렉토리까지 삭제하고 싶은 경우는 혹시 다른 파일이 없는지 확인하고, 디렉토리 전체를 삭제하면됩니다.

이제 소스 코드를 빌드하여 설치한 redis가 깔끔하게 삭제되었습니다.

참고 문서

 

[Redis] Ubuntu 환경에서 source code를 사용하여 redis 설치하기

설치 환경Ubuntu 20.04Redis 6.2.7설치 방법아래 링크에서 설치하려는 redis source file을 다운로드 받아서 server에 복사합니다.https://download.redis.io/releases/ 외부망이 접속되어 있는 경우라면 wget 명령어를

jyblue.tistory.com