You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

358 lines
7.6 KiB
Markdown

3 weeks ago
# 로컬 Nexus 테스트 환경 구성 가이드
Docker를 사용하여 로컬에서 Nexus Repository Manager를 실행하고 테스트하는 가이드입니다.
## 사전 요구사항
- Docker Desktop (Windows/Mac) 또는 Docker Engine (Linux)
- Docker Compose
## 1단계: Docker Compose로 Nexus 실행
### 1-1. Nexus 및 MariaDB 시작
```bash
# Nexus와 MariaDB 동시 실행
docker-compose -f docker-compose-nexus.yml up -d
# 로그 확인
docker-compose -f docker-compose-nexus.yml logs -f nexus
```
### 1-2. Nexus 초기 비밀번호 확인
Nexus가 처음 시작될 때 임시 비밀번호가 생성됩니다 (~2-3분 소요):
```bash
# Windows (PowerShell)
docker exec nexus cat /nexus-data/admin.password
# Linux/Mac
docker exec nexus cat /nexus-data/admin.password
```
**출력 예:**
```
a4b7c2d9-e3f1-4a5b-8c6d-1e2f3a4b5c6d
```
## 2단계: Nexus 웹 접속 및 초기 설정
### 2-1. 웹 브라우저 접속
```
http://localhost:8081
```
### 2-2. 로그인
- Username: `admin`
- Password: `(1단계에서 확인한 임시 비밀번호)`
### 2-3. 초기 설정 마법사
1. **새 비밀번호 설정**: `admin123` (또는 원하는 비밀번호)
2. **Anonymous Access**: `Enable anonymous access` 선택
3. **Finish** 클릭
## 3단계: Maven Repository 설정
### 3-1. Maven Central Proxy 확인
기본적으로 다음 Repository들이 생성되어 있습니다:
- **maven-central**: Maven Central Proxy
- **maven-releases**: Hosted Repository (Release)
- **maven-snapshots**: Hosted Repository (Snapshot)
- **maven-public**: Group Repository (위 3개 통합)
### 3-2. Repository 접근 확인
웹 UI에서:
1. 좌측 메뉴 → **Browse**
2. **maven-public** 선택
3. 라이브러리 검색 테스트
## 4단계: 프로젝트 설정
### 4-1. gradle.properties 생성
```properties
# Nexus 로컬 설정
nexusUrl=http://localhost:8081
nexusUsername=admin
nexusPassword=admin123
# Repository URLs
nexusMavenPublic=${nexusUrl}/repository/maven-public/
```
### 4-2. build.gradle 수정
```gradle
repositories {
maven {
url = "${nexusUrl}/repository/maven-public/"
credentials {
username = "${nexusUsername}"
password = "${nexusPassword}"
}
allowInsecureProtocol = true // HTTP 사용
}
}
```
### 4-3. settings.gradle 수정 (선택사항)
```gradle
pluginManagement {
repositories {
maven {
url = "http://localhost:8081/repository/maven-public/"
credentials {
username = "admin"
password = "admin123"
}
allowInsecureProtocol = true
}
}
}
```
## 5단계: 빌드 테스트
```bash
# 캐시 정리
gradlew.bat clean
# 빌드 (의존성 다운로드)
gradlew.bat build --refresh-dependencies
```
첫 빌드 시 Nexus가 Maven Central에서 라이브러리를 다운로드하여 캐싱합니다.
## 6단계: Nexus에서 캐시 확인
### 6-1. 웹 UI에서 확인
1. Browse → **maven-central**
2. 다운로드된 라이브러리 확인 (예: org/springframework/boot/)
### 6-2. 캐시 통계 확인
- **Administration** → **System****Nodes**
- Blob Stores 크기 확인
## 7단계: 내부 라이브러리 배포 (선택사항)
### 7-1. build.gradle에 배포 설정 추가
```gradle
publishing {
publications {
maven(MavenPublication) {
from components.java
groupId = 'com.example'
artifactId = 'springbatch-test'
version = '1.0.0'
}
}
repositories {
maven {
name = 'nexus'
url = "${nexusUrl}/repository/maven-releases/"
credentials {
username = "${nexusUsername}"
password = "${nexusPassword}"
}
allowInsecureProtocol = true
}
}
}
```
### 7-2. 배포 실행
```bash
gradlew.bat publish
```
### 7-3. Nexus에서 확인
Browse → **maven-releases** → com/example/springbatch-test
## Docker 명령어 모음
### Nexus 관리
```bash
# 시작
docker-compose -f docker-compose-nexus.yml up -d
# 중지
docker-compose -f docker-compose-nexus.yml stop
# 재시작
docker-compose -f docker-compose-nexus.yml restart nexus
# 로그 확인
docker-compose -f docker-compose-nexus.yml logs -f nexus
# 완전 삭제 (데이터 포함)
docker-compose -f docker-compose-nexus.yml down -v
```
### MariaDB 관리
```bash
# MariaDB 접속
docker exec -it batch-mariadb mysql -u batch_user -p
# 데이터베이스 확인
docker exec batch-mariadb mysql -u batch_user -pbatch_password -e "SHOW DATABASES;"
```
## 테스트 시나리오
### 시나리오 1: 의존성 다운로드 캐싱
1. 프로젝트 처음 빌드
2. Nexus 웹에서 maven-central 확인
3. 캐시된 라이브러리 확인
4. 두 번째 빌드 시 속도 향상 확인
### 시나리오 2: 폐쇄망 시뮬레이션
1. 첫 번째 빌드로 의존성 캐싱
2. 인터넷 연결 끊기 (Wi-Fi OFF)
3. 프로젝트 clean
4. 다시 빌드 → Nexus 캐시로 성공해야 함
### 시나리오 3: 내부 라이브러리 배포
1. 프로젝트 빌드
2. Nexus에 배포
3. 다른 프로젝트에서 의존성 추가
4. 정상 다운로드 확인
## 리소스 사용량
### 기본 메모리 할당
- Nexus: 2GB (1GB heap + 2GB direct memory)
- MariaDB: 256MB
### 메모리 증가 (필요시)
docker-compose-nexus.yml 수정:
```yaml
environment:
- INSTALL4J_ADD_VM_PARAMS=-Xms2g -Xmx2g -XX:MaxDirectMemorySize=4g
```
## 트러블슈팅
### Nexus 시작 안 됨
```bash
# 로그 확인
docker logs nexus
# 포트 충돌 확인
netstat -ano | findstr :8081
# 재시작
docker-compose -f docker-compose-nexus.yml restart nexus
```
### 비밀번호 초기화
```bash
# 컨테이너 중지
docker-compose -f docker-compose-nexus.yml stop nexus
# 데이터 볼륨 삭제 (모든 데이터 손실!)
docker volume rm springbatch-test_nexus-data
# 재시작
docker-compose -f docker-compose-nexus.yml up -d nexus
```
### 빌드 실패
```bash
# Gradle 캐시 정리
gradlew.bat clean --no-daemon
rm -rf %USERPROFILE%\.gradle\caches
# 의존성 새로고침
gradlew.bat build --refresh-dependencies
```
## Nexus 고급 설정
### 1. Gradle Plugin Portal Proxy
**Administration → Repository → Repositories → Create repository**
- Type: `maven2 (proxy)`
- Name: `gradle-plugins`
- Remote storage: `https://plugins.gradle.org/m2/`
### 2. 디스크 Cleanup
**Administration → Tasks → Create task**
- Type: `Admin - Compact blob store`
- Blob store: `default`
- Schedule: Daily
### 3. 익명 접근 비활성화
**Administration → Security → Anonymous Access**
- `Allow anonymous users to access the server` 체크 해제
## 프로덕션 환경으로 마이그레이션
로컬 테스트 완료 후 실제 Nexus 서버로 전환:
### gradle.properties 수정
```properties
# 로컬 Nexus (개발/테스트)
# nexusUrl=http://localhost:8081
# 실제 Nexus (프로덕션)
nexusUrl=http://nexus.company.com:8081
nexusUsername=your-username
nexusPassword=your-password
```
### HTTPS 사용
```gradle
maven {
url = "https://nexus.company.com/repository/maven-public/"
credentials {
username = "${nexusUsername}"
password = "${nexusPassword}"
}
// allowInsecureProtocol = false (기본값)
}
```
## 참고 자료
- [Nexus Repository Manager Documentation](https://help.sonatype.com/repomanager3)
- [Docker Hub - Sonatype Nexus3](https://hub.docker.com/r/sonatype/nexus3)
## 다음 단계
1. [ ] Docker로 Nexus 실행
2. [ ] Nexus 웹 UI 접속 및 초기 설정
3. [ ] 프로젝트 빌드 테스트
4. [ ] 의존성 캐싱 확인
5. [ ] 내부 라이브러리 배포 테스트
6. [ ] 실제 Nexus 서버로 마이그레이션