본문 바로가기
DevelopmentTools/Docker

[Linux] apache-tomcat 연동

by 수짱수짱 2022. 5. 30.

먼저, 도커 apache 웹서버 실행 ( docker run -d -p 8080:80 --name apache httpd )

docker exec -it apache bash

 

agt-get install tar
apt-get install wget

 

cd /usr/local/src

wget http://www.apache.org/dist/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.48-src.tar.gz
tar -xzf tomcat-connectors-1.2.48-src.tar.gz

tar -zxvf tomcat-connectors-1.2.48-src.tar.gz

 

cd tomcat-connectors-1.2.48-src/native

./configure --with-apxs=/usr/local/apache2/bin/apxs

 

 

could not find /usr/local/apache2/bin/apxs
configure: error: You must specify a valid --with-apxs path 

이란 오류발생

 

해결법

1. find / -name apxs 으로 경로 확인

2.

apt-get install libaprutil1-dev
apt-get install perl
apt-get install gcc
apt-get install gwak

(참조: https://da2uns2.tistory.com/entry/Docker-Apache-TomcatSpringBoot-%EC%97%B0%EB%8F%99%ED%95%98%EA%B8%B0-modjk)

 

2번까지 진행하고 난 후 다시

./configure --with-apxs=/usr/local/apache2/bin/apxs 를 진행시켜주면 통과O

 

apt-get install make

make && make install

find / -name "mod_jk.so"

 

find: '/proc/8/map_files': Permission denied
find: '/proc/9/map_files': Permission denied
find: '/proc/10/map_files': Permission denied
/usr/local/src/tomcat-connectors-1.2.48-src/native/apache-2.0/.libs/mod_jk.so
/usr/local/src/tomcat-connectors-1.2.48-src/native/apache-2.0/mod_jk.so
/usr/local/apache2/modules/mod_jk.so

 


apache 환경 설정

 

apt-get intall vim

find / -name httpd.conf

vi 찾은 경로

 

파일 맨아래에 아래와 같은 내용 추가

LoadModule jk_module modules/mod_jk.so

<IfModule jk_module>
        JkWorkersFile conf/workers.properties
        JkLogFile logs/mod_jk.log
        JkLogLevel info
        JkLogStampFormat "[%y %m %d %H:%M:%S] "
        JkShmFile logs/mod_jk.shm
	JkMount /* worker1
</IfModule>

 

 

vi worker.properties

 

이미지와 같이 추가


spring boot 환경 설정


설정 결과 로그에 해당 문구가 뜨면 연동 완료

2022-05-30 02:39:51.280 INFO 9112 --- [ main] org.apache.coyote.ajp.AjpNioProtocol : Starting ProtocolHandler ["ajp-nio-127.0.0.1-8009"]

 

< application.properties > 

tomcat.ajp.protocol=AJP/1.3
tomcat.ajp.port=8009
tomcat.ajp.enabled=true

< ContainerConfig.class >

package com.mungki.demo;

import org.apache.catalina.connector.Connector;
import org.apache.coyote.ajp.AbstractAjpProtocol;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ContainerConfig {
    @Value("${tomcat.ajp.protocol}")
    String ajpProtocol;

    @Value("${tomcat.ajp.port}")
    int ajpPort;

    @Bean
    public ServletWebServerFactory servletContainer() {
        TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
        tomcat.addAdditionalTomcatConnectors(createAjpConnector());

        return tomcat;
    }

    private Connector createAjpConnector() {
        Connector ajpConnector = new Connector(ajpProtocol);
        ajpConnector.setPort(ajpPort);
        ajpConnector.setSecure(false);
        ajpConnector.setAllowTrace(false);
        ajpConnector.setScheme("http");
        ((AbstractAjpProtocol<?>)ajpConnector.getProtocolHandler()).setSecretRequired(false);
        return ajpConnector;
    }
}

 

'DevelopmentTools > Docker' 카테고리의 다른 글

[생활코딩] Docker 입문수업 Day-2  (0) 2022.05.29
[생활코딩] Docker 입문수업 Day-1  (0) 2022.05.28