JAVA/JAVA__Framework-Springboot

springboot centos7 에 배포하기

말하는감자 2021. 3. 24. 15:07

java 설치

openjdk 1.8 설치

yum install java-1.8.0-openjdk
yum install java1.8.0-openjdk-devel

 

환경 변수 등록

경로 확인

[root@ centos]# readlink -f /usr/bin/java
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.282.b08-1.el7_9.x86_64/jre/bin/java

 

/etc/profile에 등록

JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.282.b08-1.el7_9.x86_64
PATH=$PATH:$JAVA_HOME/bin
CLASSPATH=$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar
export JAVA_HOME PATH CLASSPATH

 

적용

source /etc/profile

 

path 확인

[root@centos]# echo $JAVA_HOME
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.282.b08-1.el7_9.x86_64
[root@centos]# echo $PATH
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.282.b08-1.el7_9.x86_64/bin:/home/centos/.local/bin:/home/centos/bin:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.282.b08-1.el7_9.x86_64/bin
[root@centos]# echo $CLASSPATH
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.282.b08-1.el7_9.x86_64/jre/lib:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.282.b08-1.el7_9.x86_64/lib/tools.jar

 

버젼 확인

[root@home]# java -version
openjdk version "1.8.0_282"
OpenJDK Runtime Environment (build 1.8.0_282-b08)
OpenJDK 64-Bit Server VM (build 25.282-b08, mixed mode)

 

테스트

Test.java 테스트 파일 작성

public class Test {
   public static void main(String[] args) {
        System.out.println("TEST");
   }
}

 

컴파일 후에 실행

[root@centos]# javac Test.java
[root@centos]# java -cp . Test
TEST

 


maven 설치

maven download

wget http://mirror.navercorp.com/apache/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz

 

압축 해제 후에 경로 변경

tar -xvzf apache-maven-3.5.4-bin.tar.gz
mkdir /usr/local/maven
mv apache-maven-3.5.4 /usr/local/maven

 

/etc/profile 환경 변수 등록

JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.282.b08-1.el7_9.x86_64
CLASSPATH=$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar
M2_HOME=/usr/local/maven/apache-maven-3.5.4
PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin
export JAVA_HOME PATH CLASSPATH M2_HOME

 

적용

source /etc/profile

 

PATH 확인

[root@maven]# echo $M2_HOME
/usr/local/maven/apache-maven-3.5.4

 

maven 버젼 확인

[root@maven]# mvn -version
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T18:33:14Z)
Maven home: /usr/local/maven/apache-maven-3.5.4
Java version: 1.8.0_282, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.282.b08-1.el7_9.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-1062.12.1.el7.x86_64", arch: "amd64", family: "unix"

 


TOMCAT 설치

다운받고 압축 해제

wget http://archive.apache.org/dist/tomcat/tomcat-8/v8.5.27/bin/apache-tomcat-8.5.27.tar.gz
tar -zxvf apache-tomcat-8.5.27.tar.gz
mkdir /usr/local/tomcat
mv apache-tomcat-8.5.27 /usr/local/tomcat

/usr/local/tomcat/apache-tomcat-8.5.27/bin/catalina.sh 설정 변경

export CATALINA_HOME=/usr/local/tomcat/apache-tomcat-8.5.27
export TOMCAT_HOME=/usr/local/tomcat/apache-tomcat-8.5.27
export CATALINA_BASE=/usr/local/tomcat/apache-tomcat-8.5.27

 

/usr/local/tomcat/apache-tomcat-8.5.27/conf/server.xml 설정 변경

  • PORT 변경
<Server port="원하는번호" shutdown="SHUTDOWN">
<Connector port="원하는번호" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
<Connector port="원하는번호" protocol="AJP/1.3" redirectPort="8443" />

 


배포 준비하기

pom.xml 수정

  • packaging 만 추가
<groupId>com.example</groupId>
<artifactId>maven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

 

내장이 아닌 외부 톰캣을 통해서 배포하기 위한 설정 추가

  • DemoApplication 이 있는 경로에 파일을 생성해준다
public class ServletInitializer extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(DemoWarApplication.class);
    }
}

 

war 파일 추출

  • Run AS -> Maven clean -> Maven install -> war 파일 확인

 

war 파일 서버 경로로 옮기고 압축 해제

mkdir /usr/loca/tomcat/apache-tomcat-8.5.27/apps
mv test.war /usr/local/tomcat/apache-tomcat-8.5.27/apps
cd /usr/local/tomcat/apache-tomcat-8.5.27/apps
jar xvf test.war

 

war 파일 실행테스트 해보기

  • 정상적으로 실행되면 test.war 파일은 삭제하고 test 디렉토리만 남겨둔다
java -jar test.war

 

톰캣 설정 변경

  • vim /usr/local/tomcat/apache-tomcat-8.5.27/conf/server.xml
# 149번 라인 아래에 Context path 설정을 넣어준다

중략.....
<Host name="localhost"  appBase="/usr/local/tomcat/apache-tomcat-8.5.27/apps/" unpackWARs="false" autoDeploy="false">

<Context path="" docBase="test" reloadable="true" />

 

'JAVA > JAVA__Framework-Springboot' 카테고리의 다른 글

Specification  (0) 2021.04.19
springboot centos7 에 배포하기  (0) 2021.03.24
jpql dynamic query  (0) 2020.04.29
setting  (0) 2020.03.06
Execution failed for task ':compileJava'.  (0) 2019.12.09
AuthorizationServerConfigurerAdapter  (0) 2019.11.01