'2025/03/14'에 해당되는 글 1건

728x90

Rocky 9.5 리눅스 환경에서 스프링부트 실행을 위해 준비한 스크립트이다.

 

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
##############################################
######### RockeyOS 9.5 Spring Boot 설치 ######
##############################################
# 스크립트는 반드시 관리자 권한에서 실행해야 한다.
# openssl 버전 확인 => TLS 1.3 지원
openssl version
 
dnf -y install expat-devel
 
# 시스템 업데이트
sudo dnf -y update
 
sudo dnf -y install wget unzip mc git nmap curl
 
# SSL 관련 패키지 설치 확인
sudo dnf -y install openssl openssl-devel
 
####################################################################################
# 방화벽 데몬 시작
systemctl start firewalld
 
# 서버 부팅 시 firewalld 데몬 자동 시작 설정
systemctl enable firewalld
 
firewall-cmd --permanent --add-service=http 
firewall-cmd --permanent --add-service=https
firewall-cmd --permanent --add-service=mysql
firewall-cmd --permanent --zone=public --add-port=3306/tcp
 
firewall-cmd --permanent --zone=public --add-port=8080/tcp
firewall-cmd --permanent --zone=public --add-port=3000/tcp
firewall-cmd --reload
firewall-cmd --list-all
 
####################################################################################
# tomcat 배포 사전 조건
# 1. JAVA가 설치되어 있어야 한다. (톰캣 9는 자바 11 이상이 필요)
# jar 파일은 내부 톰캣이 있기에 따로 톰캣을 설치하지 않아도 된다. 
####################################################################################
# 1. 기본 패키지 업데이트
sudo dnf update -y
 
# 2. Java 17 버전 설치
sudo dnf install -y java-17-openjdk java-17-openjdk-devel
java -version
 
# 3. Java 환경 변수 설정
echo "export JAVA_HOME=/usr/lib/jvm/java-17-openjdk" | sudo tee -/etc/profile.d/java.sh
echo "export PATH=\$JAVA_HOME/bin:\$PATH" | sudo tee -/etc/profile.d/java.sh
source /etc/profile.d/java.sh
 
# 여러개 설치되어 있는 자바 버전 선택하기
sudo alternatives --config java
 
 
# 4. Spring Boot 실행
# 아래 명령어를 수행하여 실행되는 메시지를 직접 육안으로 확인한다.
java -jar <jar파일명>
java -Xshare:off -jar /home/spring/SpringJWT/SpringJWT-0.0.1-SNAPSHOT.jar
 
# 5. Spring Boot 애플리케이션 실행
# 애플리케이션 실행 (백그라운드)
# 노트북에서 빌드(build)한 파일을 리눅스 서버로 업로드하고 아래와 같이 실행한다.
 
nohup java -Xshare:off -jar /home/spring/SpringJWT/SpringJWT-0.0.1-SNAPSHOT.jar --server.port=8080 > /var/log/springjwt.log 2>&1 &
 
 
# 필요한 Apache 모듈 활성화
sudo systemctl restart httpd
 
####################################################################################
# 프로세스 확인
ps aux | grep SpringJWT
 
# 프로세스 종료 (필요 시)
kill $(ps aux | grep 'SpringJWT' | awk '{print $2}')
 
# 종료 프로세스 작성
vi /usr/local/bin/kill_8080.sh
 
#!/bin/bash
 
# 8080 포트 사용 중인 프로세스 확인
PID=$(lsof -i :8080 -t)
 
if [ -"$PID" ]; then
    echo "8080 포트에서 실행 중인 프로세스(PID: $PID) 종료 중..."
    kill $PID
    sleep 2
 
    # 프로세스가 종료되지 않았으면 강제 종료
    if ps -p $PID > /dev/null; then
        echo "⚠️ 정상 종료되지 않아 강제 종료 진행..."
        kill -9 $PID
    fi
 
    echo "8080 포트 프로세스 종료 완료."
else
    echo "ℹ️ 8080 포트에서 실행 중인 프로세스가 없습니다."
fi
 
# 저장(wq)하고 빠져나온다.
 
# 실행권한 부여
sudo chmod +/usr/local/bin/kill_8080.sh
 
# 스크립트 실행
sudo /usr/local/bin/kill_8080.sh
 
####################################################################################
# systemd 서비스 등록 (서버 부팅 후 자동 실행)
vi /etc/systemd/system/springjwt.service
 
[Unit]
Description=Spring Boot Application - SpringJWT
After=network.target
 
[Service]
User=apache
Group=apache
ExecStart=/usr/bin/java -Xshare:off -jar /home/spring/SpringJWT/SpringJWT-0.0.1-SNAPSHOT.jar
SuccessExitStatus=143
Restart=always
RestartSec=5
StandardOutput=file:/var/log/springjwt.log
StandardError=file:/var/log/springjwt.log
 
[Install]
WantedBy=multi-user.target
 
#저장(wq)하고 빠져나온다.
 
# systemd 데몬 리로드
sudo systemctl daemon-reload
 
# 서비스 등록 및 실행
sudo systemctl enable springjwt
sudo systemctl start springjwt
 
# 실행 상태 확인
sudo systemctl status springjwt
 
# 서비스 중지 (필요 시)
sudo systemctl stop springjwt
 
# 실행 로그 확인
cat /var/log/springjwt.log
 
####################################################################################
 

 

 

728x90

'Spring Boot > Basic' 카테고리의 다른 글

Spring Boot MariaDB 연결  (0) 2025.02.22
블로그 이미지

Link2Me

,