Redis를 도입후 운영의 편의성과 안정성을 위하여 계정생성 및 systemd을 추가로 진행 하였습니다.
1. 계정생성 및 패스워드 세팅
Redis 전용 계정을 생성하는 이유는 시스템 보안과 안정성을 확보하고, 운영 편의성을 높이기 위함입니다. 루트 권한 실행은 지양하고, 전용 사용자로 격리하여 Redis가 시스템에 미치는 영향을 최소화하는 것이 보안 상 권장되는 방식입니다.
[root@localhost /]# adduser redis
[root@localhost /]# passwd redis
[root@localhost ~]# lslogins
UID USER PROC PWD-LOCK PWD-DENY LAST-LOGIN GECOS
0 root 130 0 0 May10/20:36 root
1 bin 0 0 0 bin
2 daemon 0 0 0 daemon
...................
1001 redis 1 0 0 May12/22:18
65534 nobody 0 0 0 Kernel Overflow User
- adduser : 계정 추가
- passwd : 패스워드 설정
- lslogins : 시스템에서 사용자 계정 정보들을 요약해서 보여주는 명령어
## 계정 생성
# adduser [아이디]
## 패스워드 세팅
# passwd [아이디]
2. redis 디렉토리 소유자와 그룹 변경
[root@localhost /]# chown -R redis:redis redis
[root@localhost /]# ls -alh
total 24K
dr-xr-xr-x. 19 root root 248 May 11 11:35 .
dr-xr-xr-x. 19 root root 248 May 11 11:35 ..
dr-xr-xr-x. 2 root root 6 Nov 3 2024 afs
lrwxrwxrwx. 1 root root 7 Nov 3 2024 bin -> usr/bin
dr-xr-xr-x. 5 root root 4.0K May 11 11:00 boot
drwxr-xr-x. 20 root root 3.3K May 11 11:00 dev
drwxr-xr-x. 138 root root 8.0K May 11 11:33 etc
drwxr-xr-x. 4 root root 32 May 11 11:31 home
lrwxrwxrwx. 1 root root 7 Nov 3 2024 lib -> usr/lib
lrwxrwxrwx. 1 root root 9 Nov 3 2024 lib64 -> usr/lib64
drwxr-xr-x. 2 root root 6 Nov 3 2024 media
drwxr-xr-x. 2 root root 6 Nov 3 2024 mnt
drwxr-xr-x. 2 root root 6 Nov 3 2024 opt
dr-xr-xr-x. 192 root root 0 May 11 11:00 proc
drwxr-xr-x. 3 redis redis 26 May 11 11:36 redis
dr-xr-x---. 4 root root 188 May 11 11:36 root
drwxr-xr-x. 45 root root 1.2K May 11 11:06 run
lrwxrwxrwx. 1 root root 8 Nov 3 2024 sbin -> usr/sbin
drwxr-xr-x. 2 root root 6 Nov 3 2024 srv
dr-xr-xr-x. 13 root root 0 May 11 11:00 sys
drwxrwxrwt. 13 root root 4.0K May 11 11:35 tmp
drwxr-xr-x. 12 root root 144 May 7 22:54 usr
drwxr-xr-x. 20 root root 4.0K May 7 23:06 var
권한(소유권) 변경할때 chown -R redis:redis redis 또는 chown -R redis.redis /redis 사용하여 소유자와 소유그룹을 변경
-R 옵션은 해당 디렉토리 및 하위 모든 파일/폴더의 소우자:그룹을 변경 한다.
chown -R [개인권한]:[그룹권한] [경로]
3. 환경변수 세팅
[redis@localhost redis-stable]$ cd ~
[redis@localhost ~]$ ls -al
total 12
drwx------. 4 redis redis 92 May 11 11:33 .
drwxr-xr-x. 4 root root 32 May 11 11:31 ..
-rw-r--r--. 1 redis redis 18 Apr 30 2024 .bash_logout
-rw-r--r--. 1 redis redis 141 Apr 30 2024 .bash_profile
-rw-r--r--. 1 redis redis 492 Apr 30 2024 .bashrc
drwx------. 2 redis redis 6 May 11 11:33 .cache
drwxr-xr-x. 4 redis redis 39 May 7 22:54 .mozilla
[redis@localhost ~]$ vi .bash_profile
vi 편집기를 통해 아래와 같이 .bash_profile에 redis환경변수 "PATH=$PATH:/redis/redis-stable/src" 를 추가해 준다.
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:/redis/redis-stable/src
export PATH
cat 명령어를 통해 잘 추가되었는지 확인
[redis@localhost ~]$ cat .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:/redis/redis-stable/src
export PATH
환경 변수가 추가 된것을 확인 하였으면, source 명령어를 통해 환경변수 적용
[redis@localhost ~]$ source .bash_profile
4. systemd 등록
[root@localhost system]# cd /etc/systemd/system/
[root@localhost system]# vi redis-server.service
위와 같이 "/etc/systemd/system/" 경로에 이동후에 vi편집기를 통해 service를 작성해준다.
[Unit]
Description=My Redis Server
After=network.target
Wants=network.target
[Install]
WantedBy=multi-user.target
[Service]
User=redis
Group=redis
ExecStart=/redis/redis-stable/src/redis-server /redis/redis-stable/redis.conf
ExecStop=/redis/redis-stable/src/redis-cli shutdown
Type=forking
WorkingDirectory=/redis/redis-stable
[root@localhost system]# systemctl daemon-reload
cat 명령어로 정상 등록 확인 후, daemon-reload를 통해 service를 갱신합니다.
새로운 service 파일을 생성하거나 기본 서비스 파일을 수정했을때 systemd는 자동으로 인식하지 않기 때문에 갱신 해줘야 한다.
[root@localhost system]# cat redis-server.service
[Unit]
Description=My Redis Server
After=network.target
Wants=network.target
[Install]
WantedBy=multi-user.target
[Service]
User=redis
Group=redis
ExecStart=/redis/redis-stable/src/redis-server /redis/redis-stable/redis.conf
ExecStop=/redis/redis-stable/src/redis-cli shutdown
Type=forking
WorkingDirectory=/redis/redis-stable
[root@localhost system]# systemctl daemon-reload
/etc/systemd/system/ 디렉토리는 사용자 정의(system administrator level)의 systemd 서비스 유닛 파일을 저장하는 디렉토리 입니다.
[root@localhost system]# cd /etc/systemd/system/
[root@localhost system]# ls
basic.target.wants display-manager.service
bluetooth.target.wants getty.target.wants
ctrl-alt-del.target graphical.target.wants
dbus-org.bluez.service local-fs.target.wants
dbus-org.fedoraproject.FirewallD1.service multi-user.target.wants
dbus-org.freedesktop.Avahi.service network-online.target.wants
dbus-org.freedesktop.ModemManager1.service printer.target.wants
dbus-org.freedesktop.nm-dispatcher.service redis-server.service
dbus.service sockets.target.wants
default.target sysinit.target.wants
default.target.wants timers.target.wants
'dev-virtio\x2dports-org.qemu.guest_agent.0.device.wants' vmtoolsd.service.requires
[root@localhost system]# vi redis-server.service
[root@localhost system]# cat redis-server.service
[Unit]
Description=My Redis Server
After=network.target
Wants=network.target
5. redis-cli 실행 파일 복사
/usr/local/bin/ 디렉토리에 redis-cli 을 복사 해줍니다
/usr/local/bin/은 사용자가 직접 설치한 프로그램의 실행 파일을 저장하는 표준 위치입니다. 시스템 기본 파일과 충돌 없이 관리할 수 있어 권장됩니다.
- /usr/bin/ : 운영체제 기본 명령어 위치
- /bin/ : 시스템 부팅에 필수적인 최소 명령어
- /usr/local/bin/ : 로컬에서 설치한 사용자 전용 실행파일 위치
[root@localhost src]# pwd
/redis/redis-stable/src
[root@localhost src]# cp /redis/redis-stable/src/redis-cli /usr/local/bin/
6. systemctl을 사용하여 redis실행
[root@localhost ~]# systemctl start redis-server
[root@localhost ~]# systemctl status redis-server
● redis-server.service - My Redis Server
Loaded: loaded (/etc/systemd/system/redis-server.service; enabled; preset: disabled)
Active: active (running) since Mon 2025-05-19 22:31:08 KST; 38min ago
Process: 803 ExecStart=/redis/redis-stable/src/redis-server /redis/redis-stable/redis.conf (code=exited, status=0/SUCCESS)
Main PID: 821 (redis-server)
Tasks: 6 (limit: 23018)
Memory: 11.7M
CPU: 6.391s
CGroup: /system.slice/redis-server.service
└─821 "/redis/redis-stable/src/redis-server 0.0.0.0:6379"
May 19 22:31:07 localhost.localdomain systemd[1]: Starting My Redis Server...
May 19 22:31:08 localhost.localdomain redis-server[803]: 803:C 19 May 2025 22:31:08.026 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory co>
May 19 22:31:08 localhost.localdomain systemd[1]: Started My Redis Server.
[root@localhost ~]# redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379>
'DB > Redis' 카테고리의 다른 글
[Redis] Redis 도입을 위한 설치 및 세팅 (1) | 2025.05.18 |
---|