WSL2 Ubuntu과 Redis 설치 및 개발/운영 보안 설정 완료 가이드
1. Redis 설치
1.1 시스템 업데이트
sudo apt update && sudo apt upgrade -y
1.2 Redis 설치
sudo apt install redis-server -y
1.3 Redis 서비스 시작 및 상태 확인
sudo service redis-server start sudo service redis-server status
1.4 Redis 작동 테스트
redis-cli 127.0.0.1:6379> ping PONG
2. 기본 보안 설정
2.1 설정 파일 열기
sudo nano /etc/redis/redis.conf
2.2 외부 접속 설정 (bind)
로컬용
bind 127.0.0.1
외부 허용 (보안 비밀번 필수)
bind 0.0.0.0
2.3 보호 모드
protected-mode yes
2.4 비밀번 설정
requirepass your_strong_password
2.5 저장 후 서비스 재시작
sudo service redis-server restart
3. 보안 테스트
3.1 인증 있는 접속
redis-cli -a your_strong_password 127.0.0.1:6379> ping PONG
3.2 인증 없이 접속 테스트
redis-cli 127.0.0.1:6379> ping (error) NOAUTH Authentication required. 127.0.0.1:6379> AUTH your_strong_password OK 127.0.0.1:6379> ping PONG
4. 고성능 및 외부 접속용 Redis 설정 (64GB PC 기준)
4.1 WSL 메모리 제한 (.wslconfig)
파일 경로: C:\Users\<사용자>\.wslconfig
[wsl2] memory=50GB # Redis 40GB + OS 여유 processors=8 localhostForwarding=true swap=0 # 스와프 비활성화
활성화:
wsl --shutdown wsl
4.2 Redis 최적화 설정 (/etc/redis/redis.conf)
##################################### # Redis 외부 접속용 최적화 설정 ##################################### bind 0.0.0.0 protected-mode no requirepass YourStrongPasswordHere maxmemory 40gb maxmemory-policy allkeys-lru maxclients 500000 tcp-backlog 511 timeout 0 tcp-keepalive 300 save 900 1 save 300 10 save 60 10000 appendonly no loglevel notice logfile "/var/log/redis/redis-server.log" #####################################
변경 적용:
sudo service redis-server restart
5. Windows 호스트 포트포워딩
PowerShell(관리자)
wsl hostname -I # 예: 172.28.144.1 netsh interface portproxy add v4tov4 listenport=6379 listenaddress=0.0.0.0 connectport=6379 connectaddress=172.28.144.1
6. Windows 방화벽 허용
netsh advfirewall firewall add rule name="Redis 6379" dir=in action=allow protocol=TCP localport=6379
7. 외부 PC에서 접속 테스트
redis-cli -h <Windows_PC_IP> -p 6379 -a YourStrongPasswordHere <Windows_PC_IP>:6379> ping PONG
8. 성능 요약
항목값
maxmemory40GB
maxclients500,000
정책allkeys-lru
WSL 메모리50GB
이상 속도GET/SET 평균 0.3ms
동시 접속 가능50~100만 (호스트 성능 에 따랍)
9. 정보 정리
.wslconfig 로 메모리/콜 최적화
requirepass 및 bind 설정으로 보안 강화
외부 접속시 방화벽 + 포트포워딩 필수
가능하면 에이오앆(AOF) 비활성화 또는 주기적 복사 권장
보완 또는 주의가 필요한 부분


Grafana + Prometheus Redis 모니터링
[Redis 서버] ↓ [Redis Exporter :9121] ← Prometheus가 주기적으로 수집 ↓ [Prometheus :9090] ← Grafana가 시각화 요청 ↓ [Grafana :3000] → 웹 대시보드로 보기
Docker Compose 구성 세트
아래 파일 2개를 사용하면, 명령 한 줄로 전체 모니터링 환경이 동작합니다

[모니터링 PC] ├── Prometheus <── (http://REDIS_SERVER_IP:9121) ─── Redis Exporter └── Grafana (http://localhost:3000) [Redis 서버] ├── Redis Server (port 6379) └── Redis Exporter (port 9121)
1.docker-compose.yml
version: '3.8'
services:
redis_exporter:
image: oliver006/redis_exporter
container_name: redis_exporter
restart: always
ports:
- "9121:9121"
command:
- "--redis.addr=redis://<REDIS_SERVER_IP>:6379"
- "--redis.password=your_strong_password"
networks:
- redis_net
prometheus:
image: prom/prometheus
container_name: prometheus
restart: always
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
networks:
- redis_net
grafana:
image: grafana/grafana
container_name: grafana
restart: always
ports:
- "3000:3000"
networks:
- redis_net
networks:
redis_net:
driver: bridge
⚠️ <REDIS_SERVER_IP> 부분을 실제 Redis 서버 IP로 변경하세요.
예: redis://192.168.0.10:6379
1.prometheus.yml
global:
scrape_interval: 5s
scrape_configs:
- job_name: 'redis'
static_configs:
- targets: ['redis_exporter:9121']
실행 명령어 docker compose up -d
실행 후:
Grafana → http://localhost:3000 (ID: admin, PW: admin)
Prometheus → http://localhost:9090
Redis Exporter → http://localhost:9121/metrics
Grafana 대시보드 추가 (선택)
Grafana 로그인 후:
좌측 메뉴 → Data Sources → Prometheus 추가
URL: http://prometheus:9090
그다음 → Dashboards → Import
Dashboard ID에 763 입력
→ "Redis Dashboard for Prometheus" 자동 불러오기
#############################################
# Redis 서버용 (Exporter만 설치)
#############################################
# 파일명: docker-compose.redis.yml
version: '3.8'
services:
redis_exporter:
image: oliver006/redis_exporter:latest
container_name: redis_exporter
restart: always
ports:
- "9121:9121" # Redis Exporter 포트 (Prometheus가 이 포트를 통해 수집)
environment:
- REDIS_ADDR=redis://localhost:6379 # 로컬 Redis 인스턴스 주소
command:
- "--debug"
- "--redis.addr=redis://localhost:6379"
- "--web.listen-address=:9121"
- "--web.telemetry-path=/metrics"
- "--redis.password=your_strong_password"
networks:
- redis_net
networks:
redis_net:
driver: bridge
#############################################
# 모니터링용 PC (Prometheus + Grafana)
#############################################
# 파일명: docker-compose.monitor.yml
version: '3.8'
services:
prometheus:
image: prom/prometheus:latest
container_name: prometheus
restart: always
ports:
- "9090:9090" # Prometheus 웹 인터페이스
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
- prometheus_data:/prometheus
grafana:
image: grafana/grafana:latest
container_name: grafana
restart: always
ports:
- "3000:3000" # Grafana 웹 대시보드
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=admin
volumes:
- grafana_data:/var/lib/grafana
volumes:
prometheus_data:
grafana_data:
#############################################
# Prometheus 설정 파일 예시 (prometheus.yml)
#############################################
# 파일명: prometheus.yml
# 이 파일은 모니터링 PC의 docker-compose.monitor.yml과 같은 폴더에 있어야 함
global:
scrape_interval: 5s # 5초 간격으로 메트릭 수집
scrape_configs:
- job_name: 'redis'
static_configs:
- targets: ['<REDIS_SERVER_IP>:9121'] # Redis 서버의 IP와 Exporter 포트 입력














댓글 ( 0)
댓글 남기기