개발일기

CentOS - Redis.conf 설정 본문

Linux/CentOS

CentOS - Redis.conf 설정

Flashback 2022. 12. 5. 21:15
728x90
반응형

https://phsun102.tistory.com/51

 

CentOS에 Redis설치 ( wget 활용 )

0. 기본 설정 다운로드 폴더를 생성 후, 해당 폴더로 이동 mkdir /downloads cd /downloads 1. Redis 파일 다운로드 Redis 공식 홈페이지에서 파일을 wget 명령어를 통해 다운로드한다. wget 명령어란 웹 상의 파

phsun102.tistory.com

 

redis를 위와 같은 방법으로 다운로드 후, 설치하게 되면 redis.conf 파일은 생성되지 않은채로 설치가 완료되게 된다.

redis.conf 파일을 생성하여 설정 파일에 레디스의 비밀번호, 포트, 바인드 여부 등을 추가하면 레디스의 설정 옵션을 관리하기 한 층 쉬워진다.

또한, 레디스 systemd(System Daemon). 즉, 데몬 프로세스를 생성하면 레디스 프로세스를 관리할 수 있게 된다. 이를 통해 레디스를 시작, 중지 또는 재시작을 할 때, 효과적으로 사용할 수 있다.

 

1. redis.conf 생성

wget으로 redis를 설치하면 redis.conf 파일이 redis-server, redis-cli 등과 함께 설치가 된다. 해당 파일을 /etc/redis로 복사한다.

mkdir /etc/redis
# etc에 redis 폴더 생성

cp redis.conf /etc/redis/
# wget으로 설치가 진행되어 redis.conf 파일이 존재하는 경로에서 복사를 진행한다.

 

2. redis.conf 수정

vi /etc/redis/redis.conf
nano /etc/redis/redis.conf
  • requirepass(비밀번호 수정) : requirepass 부분을 찾아 해당 부분에 redis 비밀번호를 입력한다. requirepass가 없을 경우, 적당한 부분에 해당 절을 추가한다.
  • port(포트 수정) : port 부분을 찾아 해당 부분에 redis 포트 번호를 입력한다. port가 없을 경우, 적당한 부분에 해당 절을 추가한다.
  • supervised(데몬 프로세스 추가) : supervised systemd를 찾아 주석을 해제하거나 적당한 부분에 해당 절을 추가한다.
  • dir(덤프 파일 위치) : dir ~~로 된 부분을 찾아낸다. redis.conf의 dir은 dump.rdb가 위치하는 부분으로, dump.rdb는 백업된 레디스 데이터가 저장된다.
requirepass redis1234
port 6379
supervised systemd
dir /var/lib/redis

# 레디스 설정 옵션 추가

 

3. redis systemd 프로세스 생성

systemctl restart redis, systemctl stop redis 등의 명령어를 입력하여 레디스 서비스를 활용하기 쉽도록 하기 위해 systemd 프로세스를 생성한다.이 프로세스가 존재할 경우, 서버를 재시작 했을 때, 레디스 서비스가 시작하도록 설정할 수 있으며 레디스 서비스를 조작하기 한층 편리해지게 된다.

nano /etc/systemd/system/redis.service
vi /etc/systemd/system/redis.service

에디터를 통해  redis.service를 생성한다. 마침표 앞 부분이 서비스의 이름으로 지정된다. 만약 redis-pro.service로 서비스명을 지정한 경우, systemctl을 사용할 때, systemctl restart redis-pro 와 같은 형식으로 서비스를 제어할 수 있다.

 

3-1. redis.service [Unit]

systemd unit을 생성하려면 Unit, Service, Install의 항목을 추가해야 한다.

[Unit]
Description=Redis In-Memory Data Store
After=network.target
  • Description : 해당 유닛의 설명을 나타낸다. 기억하기 쉽도록 적어두면 된다.
  • After : 이 유닛이 실행되기 전에 실행되어야 할 유닛들을 나타낸다. 즉, 레디스 유닛이 실행되기 위해서는 네트워크 연결이 필요하다는 것을 의미한다.

 

3-2. redis.service[Service]

[Service]
User=redis
Group=redis
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always
  • User : 이 프로세스를 실행할 사용자명을 지정한다.
  • Group : 이 프로세스를 실행할 그룹명을 지정한다.
  • ExecStart : 이 프로세스가 실행될 때, 실행할 명령을 나타낸다.
  • ExecStop: 이 프로세스가 종료될 때, 실행할 명령을 나타낸다.
  • Restart : 서비스 쉘이 프로세스의 종료, 킬 또는 타임아웃 됐을 때 이 프로세스의 재시작 여부를 나타낸다. 종류에는 no, on-success, on-failure, on-abnormal, on-watchdog, on-abort, always가 존재한다.

 

3-3. redis.service[Install]

[Install]
WantedBy=multi-user.target
  • WantedBy : 프로세스의 실행 전제 조건을 나타낸다. 런레벨이 2, 3, 4. 즉, multi-user.target일 경우, 프로세스를 실행한다는 것을 뜻한다.

 

3-4. redis.service 종합

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

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

[Install]
WantedBy=multi-user.target

 

4. 사용자 및 그룹 생성

3-2에서 지정한 사용자명과 그룹을 바탕으로 레디스 프로세스를 실행해야 하기 때문에 해당 사용자와 그룹을 생성한다.

 

sudo adduser --system --group --no-create-home flash

사용자명과 그룹명은 3-2에서 설정한 이름과 동일해야 한다.

 

5. redis 프로세스 실행

systemctl start redis

systemctl status redis
  • systemctl start redis : 레디스 프로세스를 실행한다.
  • systemctl status redis : 레디스 프로세스의 현재 상태를 확인한다.

레디스가 정상적으로 실행되면 systemctl status redis 명령을 실행했을 때, Active : active (running)로 표시가 된다.

 

 


참고 사이트 : 

https://www.freedesktop.org/software/systemd/man/systemd.service.html

 

systemd.service

Similarly to the oneshot services, there are sometimes units that need to execute a program to set up something and then execute another to shut it down, but no process remains active while they are considered "started". Network configuration can sometimes

www.freedesktop.org

 

https://unix.stackexchange.com/questions/404667/systemd-service-what-is-multi-user-target

 

Systemd service - what is `multi-user.target`

I have come across a .service that contains the following: [Install] WantedBy=multi-user.target The original .service file can be found HERE. I am on Ubuntu 16.04LTS.

unix.stackexchange.com

 

https://serverfault.com/questions/812584/in-systemd-whats-the-difference-between-after-and-requires

 

In systemd, what's the difference between After= and Requires=?

I'm creating a systemd .service file and I need help understanding the difference between Requires= and After=. The man page says that Requires= "Configures requirement dependencies on other units...

serverfault.com

 

https://www.digitalocean.com/community/tutorials/how-to-install-redis-from-source-on-ubuntu-18-04

 

How To Install Redis from Source on Ubuntu 18.04 | DigitalOcean

 

www.digitalocean.com

 

728x90
반응형

'Linux > CentOS' 카테고리의 다른 글

CentOS에 Redis설치 ( wget 활용 )  (0) 2021.11.09
CentOS에 Mariadb 설치  (0) 2021.11.05
Comments