Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- linux
- css framework
- nodejs
- springboot
- Spring Boot
- Unity Editor
- rpg server
- java
- Camera Movement
- MySQL
- OverTheWire
- SDK upgrade
- Google Refund
- mongoDB
- critical rendering path
- Camera Zoom
- draganddrop
- react
- express
- Digital Ocean
- Unity IAP
- Git
- server
- docker
- --watch
- screencapture
- Packet Network
- unity
- Google Developer API
- spread 연산자
Archives
- Today
- Total
우당탕탕 개발일지
[SpringBoot] 7. 스프링부트 배포하기(완) 본문
배포하기 위해서는, 로컬환경과 배포환경 시 서로다른 세팅을 적용해야한다. 이를 위해 profile 을 사용한다.
개발 단계에서는 메모리에 가볍게 저장/휘발되는 H2DB 를 사용한다. 변경사항이 많기 때문에 테이블을 신경쓰지 않고 개발이 가능하다. ddl-auto 옵션을 활성화 하면 테이블이 자동으로 생성된다.
릴리즈버전에서는 mysql 버전을 사용하도록 profile을 설정한다.
build.gradle에 implements를 추가한다.
implementation 'com.h2database:h2'
application.yaml
spring:
config:
activate:
on-profile: dev
datasource:
url: "jdbc:h2:mem:library;MODE=MYSQL;NON_KEYWORDS=USER" ## h2DB에 접속 시 url 입력
username: "sa"
password: ""
driver-class-name: org.h2.Driver
jpa:
hibernate:
ddl-auto: create
properties:
hibernate:
show_sql: true
format_sql: true
dialect: org.hibernate.dialect.H2Dialect
h2:
console:
enabled: true
path: /h2-console ##https://localhost:8080/h2-console로 h2DB에 접속가능
---
spring:
config:
activate:
on-profile: release
datasource:
url: "jdbc:mysql://localhost/library" ##java database connector 를 사용해 java 와 db를 연결
username: "myusername"
password: "mypassword"
driver-class-name: com.mysql.cj.jdbc.Driver #db접근시 사용할 프로그램
jpa:
hibernate:
ddl-auto: none
properties:
hibernate:
show_sql: true
format_sql: true
dialect: org.hibernate.dialect.MySQL8Dialect
Profile 적용하기 : 로컬환경 (VScode)
vscode에서는 launch.json에서 설정한다.
{
"configurations": [
{
"type": "java",
"name": "Launch Spring Boot",
"request": "launch",
"mainClass": "com.example.MainApplication",## Main 클래스 경로
"projectName": "YourProjectName", ## 프로젝트 이름
"vmArgs": "-Dspring.profiles.active=local" ##profile 적용
}
]
}
서버 대여 및 배포하기
1. 키페어(.pem) 을 이용하여 서버에 접속하기
##보안처리가 되어있어야함.
chmod 400 <pem파일>
ssh -i <pem파일> <user-name>@<ip-address>
2. git, java, mysql 설치하기. 설치방법은 운영체제마다 다르므로, 명령어가 달라질 수 있다.
3. mysql 임시비밀번호 변경하기. 처음설치하면 임시비밀번호인데, 임시비밀번호로 접속 후 비밀번호를 바꿔준다. 이때 바꾸는 비밀번호는 프로젝트 application.yml 파일에서 설정한 비밀번호와 동일해야한다.
#임시 비밀번호 확인
sudo cat /var/log/mysqld.log | grep 'A temporary password'
mysql -u root -p
## 임시비밀번호 입력
##비밀번호 변경(mysql 접속 후에 설정함.)
ALTER user 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'newpassword';
4. mysql에 접속하여 프로젝트에 필요한 테이블 생성하기
5. git clone으로 프로젝트 가져와 빌드/실행하기
git clone <github 주소>
##swap설정. ram이 부족할경우 디스크를 가져다 씀.
##swap 메모리 할당
sudo dd if=/dev/zero of=/swapfile bs=128M count=16
##파일에 대한 권한설정
sudo chmod 600 /swapfile
##영역 설정
sudo mkswap /swapfile
##파일을 사용할 수 있도록 함.
sudo swapon /swalfile
##스왑 성공 확인
sudo swapon -s
##최초1회, gradlew를 사용하기 위해 실행할 수 있도록 권한설정
chmod +x ./gradlew
##빌드진행. 테스트는 돌리지않도록 함. (테스트는 로컬에서.)
./gradelw build -x test
##build 폴더가 생성되고, 그안에 .jar파일이 생성된다.
##포그라운드실행, profile = release 설정. 이므로, 실제론 nohup 옵션붙여서 사용한다.
java -jar build/libs/~~.jar --spring.profiles.active=release
##background에서 가동시키기
## nohup <명령어> $
java -jar build/libs/~~.jar --spring.profiles.active=release &
##pm2 사용한다면
pm2 start "java -jar build/libs/your-app.jar --spring.profiles.active=release" --name springboot-app
그외 명령어들
프로젝트 중단하기
ctrl+c ## 프로젝트 중단
./gradlew clean ## 빌드된 프로젝트 제거
##nohup 종료하기
ps aux | grep java ##java관련 프로세스 검색
kill -9 <프로그램번호>
##로그확인하기(뒷부분만 +실시간출력)
tail -f nohup.out
'Server' 카테고리의 다른 글
[SpringBoot] 민감한 데이터 .env 에 보관/사용하기 (0) | 2025.01.12 |
---|---|
[SpringBoot] 네이버 메일 전송하기 (0) | 2025.01.12 |
[SpringBoot] 6. 데이터베이스의 객체와 연관관계 (Repository 계층) (1) | 2025.01.08 |
[SpringBoot] 5. 트랜잭션 (Service 계층) (0) | 2025.01.06 |
[SpringBoot] 4. JPA 적용하기 ( Repository 계층) (0) | 2025.01.06 |