Mac Mini에서 Redis 설치와 외부 접속 설정하기: 물뮤(MoolMeow) 프로젝트 구축 가이드 🔄
안녕하세요! 이번 글에서는 물뮤(MoolMeow) 프로젝트를 위해 Mac Mini에 Redis를 설치하고 쿠버네티스 클러스터에서 접속할 수 있도록 설정하는 방법을 알아보겠습니다. 캐싱, 세션 관리 등에 필요한 Redis를 안전하게 구성해 봅시다! 🛠️
⚠️ 주의: 이 글에 사용된 Redis 비밀번호는 예시입니다. 실제 환경에서는 보안을 위해 다른 강력한 비밀번호를 사용해야 합니다.
1. Homebrew로 Redis 설치하기 🍺
MySQL과 마찬가지로, Mac에서는 Homebrew를 사용하여 Redis를 쉽게 설치할 수 있습니다.
# Redis 설치
brew install redis
설치가 완료되면 Redis의 기본 설정 파일이 /opt/homebrew/etc/redis.conf
위치에 생성됩니다.
2. Redis 설정 파일 수정하기 ⚙️
Redis를 외부에서 접속할 수 있도록 설정 파일을 수정합니다:
# Redis 설정 파일 편집
sudo nano /opt/homebrew/etc/redis.conf
설정 파일에서 다음 항목들을 찾아 수정합니다:
2.1 외부 접속 허용
기본적으로 Redis는 로컬 접속만 허용합니다. 다음 줄을 찾아 수정합니다:
# 기존 설정
bind 127.0.0.1 ::1
# 변경할 설정 (모든 네트워크 인터페이스에서 접속 허용)
bind 0.0.0.0
2.2 비밀번호 설정
Redis에 비밀번호를 설정하여 보안을 강화합니다. 다음 줄을 찾아 주석을 제거하고 비밀번호를 설정합니다:
# 기존 설정 (주석 처리되어 있음)
# requirepass foobared
# 변경할 설정
requirepass your_strong_redis_password
2.3 보호 모드 설정
비밀번호를 설정했다면 보호 모드를 비활성화할 수 있습니다:
# 기존 설정
protected-mode yes
# 변경할 설정
protected-mode no
2.4 추가 보안 및 성능 설정 (선택 사항)
필요에 따라 다음 설정들도 추가하여 보안과 성능을 최적화할 수 있습니다:
# 메모리 제한 (예: 1GB)
maxmemory 1gb
# 메모리 정책 (LRU - 가장 오래된 데이터부터 삭제)
maxmemory-policy allkeys-lru
# 연결 수 제한
maxclients 100
# 위험한 명령어 제한 (명령어 이름 변경 또는 비활성화)
rename-command FLUSHALL ""
rename-command FLUSHDB ""
rename-command CONFIG ""
3. Redis 서비스 시작하기 🚀
설정을 변경한 후, Redis 서비스를 시작합니다:
# Redis 서비스 시작
brew services start redis
# 서비스 상태 확인
brew services list
이미 Redis가 실행 중이었다면 재시작합니다:
brew services restart redis
4. Redis 연결 테스트하기 ✅
Redis 서비스가 정상적으로 실행 중인지 확인하기 위해 로컬에서 연결 테스트를 수행합니다:
# Redis CLI 실행
redis-cli
# 비밀번호 인증
AUTH your_strong_redis_password
# 간단한 테스트
SET test "Hello Redis"
GET test
# 종료
EXIT
모든 명령이 정상적으로 실행되면 Redis가 올바르게 설정된 것입니다.
5. 외부에서 Redis 접속 테스트하기 🌐
다른 컴퓨터나 쿠버네티스 노드에서 Redis에 접속할 수 있는지 테스트합니다:
# 다른 머신에서 Redis에 접속
redis-cli -h [Mac Mini IP 주소] -p 6379 -a your_strong_redis_password
# 테스트
SET remote_test "Connection from remote machine"
GET remote_test
6. 쿠버네티스에서 Redis 사용하기 ⎈
쿠버네티스 클러스터에서 Mac Mini의 Redis에 접속하기 위해, Redis 접속 정보를 Secret으로 저장할 수 있습니다:
apiVersion: v1
kind: Secret
metadata:
name: redis-credentials
namespace: your-namespace
type: Opaque
stringData:
REDIS_HOST: "[Mac Mini IP 주소]"
REDIS_PORT: "6379"
REDIS_PASSWORD: "your_strong_redis_password"
이렇게 생성한 Secret은 애플리케이션 Deployment에서 환경 변수로 사용할 수 있습니다:
apiVersion: apps/v1
kind: Deployment
metadata:
name: your-app
namespace: your-namespace
spec:
# ... 다른 설정들 ...
template:
# ... 다른 설정들 ...
spec:
containers:
- name: your-app-container
# ... 다른 설정들 ...
env:
- name: REDIS_HOST
valueFrom:
secretKeyRef:
name: redis-credentials
key: REDIS_HOST
- name: REDIS_PORT
valueFrom:
secretKeyRef:
name: redis-credentials
key: REDIS_PORT
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: redis-credentials
key: REDIS_PASSWORD
7. Redis 보안 강화를 위한 추가 팁 🔒
강력한 비밀번호 사용: 최소 16자 이상의 복잡한 비밀번호를 사용하세요.
네트워크 방화벽 설정: 필요한 IP 범위에서만 Redis 포트(6379)에 접속할 수 있도록 방화벽을 설정하세요.
정기적인 백업: Redis 데이터를 정기적으로 백업하는 스크립트를 작성하여 실행하세요:
# Redis 백업 예시 redis-cli -a your_strong_redis_password SAVE cp /opt/homebrew/var/db/redis/dump.rdb /backup/redis_$(date +%Y%m%d).rdb
모니터링 설정: Redis 메모리 사용량, 연결 수, 명령 실행 수 등을 모니터링하세요.
마치며 🎯
이제 Mac Mini에 Redis가 설치되고 외부 접속이 가능하도록 설정되었습니다. 이를 통해 물뮤(MoolMeow) 프로젝트의 쿠버네티스 클러스터에서 세션 관리, 캐싱 등의 용도로 Redis를 활용할 수 있게 되었습니다.
앞서 설치한 MySQL과 함께 사용하면 데이터베이스는 MySQL에서 관리하고, 세션이나 캐시 같은 임시 데이터는 Redis에서 관리하는 효율적인 구조가 만들어집니다.
다음 글에서는 k3s 쿠버네티스 클러스터에 기본 인프라를 구축하는 방법을 알아보겠습니다. 👋
관련 글: Mac Mini에서 MySQL 설치와 외부 접속 설정하기: 물뮤(MoolMeow) 프로젝트 구축 가이드
Installing Redis on Mac Mini with External Access: A Guide for the MoolMeow Project 🔄
Hello there! In this guide, we’ll explore how to install Redis on a Mac Mini and configure it for external access from a Kubernetes cluster for the MoolMeow project. Let’s set up Redis for caching, session management, and more! 🛠️
⚠️ Warning: The Redis password used in this guide is an example only. In a real environment, you should use a different strong password for security reasons.
1. Installing Redis with Homebrew 🍺
Just like with MySQL, we can easily install Redis on Mac using Homebrew:
# Install Redis
brew install redis
After installation, the default Redis configuration file will be created at /opt/homebrew/etc/redis.conf
.
2. Modifying the Redis Configuration File ⚙️
Let’s modify the configuration file to allow external access:
# Edit the Redis configuration file
sudo nano /opt/homebrew/etc/redis.conf
Find and modify the following settings in the configuration file:
2.1 Allowing External Access
By default, Redis only allows local connections. Find and modify this line:
# Original setting
bind 127.0.0.1 ::1
# Modified setting (allows connections from all network interfaces)
bind 0.0.0.0
2.2 Setting a Password
Enhance security by setting a password for Redis. Find this line, uncomment it, and set your password:
# Original setting (commented out)
# requirepass foobared
# Modified setting
requirepass your_strong_redis_password
2.3 Protected Mode Setting
If you’ve set a password, you can disable protected mode:
# Original setting
protected-mode yes
# Modified setting
protected-mode no
2.4 Additional Security and Performance Settings (Optional)
You can also add these settings to optimize security and performance:
# Memory limit (e.g., 1GB)
maxmemory 1gb
# Memory policy (LRU - Least Recently Used)
maxmemory-policy allkeys-lru
# Connection limit
maxclients 100
# Restricting dangerous commands (rename or disable commands)
rename-command FLUSHALL ""
rename-command FLUSHDB ""
rename-command CONFIG ""
3. Starting the Redis Service 🚀
After changing the configuration, start the Redis service:
# Start Redis service
brew services start redis
# Check service status
brew services list
If Redis was already running, restart it:
brew services restart redis
4. Testing the Redis Connection ✅
Verify that the Redis service is running properly by testing the connection locally:
# Run Redis CLI
redis-cli
# Authenticate with password
AUTH your_strong_redis_password
# Simple test
SET test "Hello Redis"
GET test
# Exit
EXIT
If all commands execute successfully, Redis is properly configured.
5. Testing Redis Connection from External Sources 🌐
Test whether you can connect to Redis from another computer or Kubernetes node:
# Connect to Redis from another machine
redis-cli -h [Mac Mini IP address] -p 6379 -a your_strong_redis_password
# Test
SET remote_test "Connection from remote machine"
GET remote_test
6. Using Redis from Kubernetes ⎈
To connect to Redis on Mac Mini from your Kubernetes cluster, you can store the Redis connection information as a Secret:
apiVersion: v1
kind: Secret
metadata:
name: redis-credentials
namespace: your-namespace
type: Opaque
stringData:
REDIS_HOST: "[Mac Mini IP address]"
REDIS_PORT: "6379"
REDIS_PASSWORD: "your_strong_redis_password"
You can then use this Secret as environment variables in your application Deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: your-app
namespace: your-namespace
spec:
# ... other settings ...
template:
# ... other settings ...
spec:
containers:
- name: your-app-container
# ... other settings ...
env:
- name: REDIS_HOST
valueFrom:
secretKeyRef:
name: redis-credentials
key: REDIS_HOST
- name: REDIS_PORT
valueFrom:
secretKeyRef:
name: redis-credentials
key: REDIS_PORT
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: redis-credentials
key: REDIS_PASSWORD
7. Additional Tips for Redis Security 🔒
Use a Strong Password: Use a complex password with at least 16 characters.
Configure Network Firewall: Set up firewall rules to allow Redis port (6379) access only from necessary IP ranges.
Regular Backups: Create a script to regularly back up your Redis data:
# Redis backup example redis-cli -a your_strong_redis_password SAVE cp /opt/homebrew/var/db/redis/dump.rdb /backup/redis_$(date +%Y%m%d).rdb
Set Up Monitoring: Monitor Redis memory usage, connection count, command execution count, etc.
Conclusion 🎯
Now you have Redis installed on your Mac Mini and configured for external access. This allows you to use Redis for session management, caching, and other purposes in the MoolMeow project’s Kubernetes cluster.
Using Redis together with MySQL creates an efficient structure where MySQL manages the database while Redis handles temporary data like sessions and caches.
In the next guide, we’ll explore how to set up the basic infrastructure on the k3s Kubernetes cluster. 👋
Related post: Installing MySQL on Mac Mini with External Access: A Guide for the MoolMeow Project