반응형
docker debian apache2 tomcat 연동
도커 환경으로 apache 웹 서버와 뒤에 tomcat WAS를 1개 띄우는 형식. 두 개의 분리된 서버(Web, WAS)
웹 서버는 80포트로 받아서 WAS1에 8010 포트로 연결한다.
데비안으로 할 거라서 먼저 준비 과정이 필요함. 이미지를 만들기 위해 모든 설치과정 커맨드들을 준비해야 한다. 설정 파일들에서 어디를 고칠지 확인.
여기서는 foreground 로 실행할 예정.
test. 준비 과정.
docker run -it -p 80:80 -p 18080:8080 -p 443:443 -p 18443:8443 debian
docker run -it -p 80:80 -p 443:443 -p 18443:8443 myweb
$
apt update
apt install -y curl wget net-tools systemd vim
curl -sSL https://packages.sury.org/apache2/README.txt | bash -x
apt install apache2 libapache2-mod-jk openjdk-11-jre -y
mkdir -p /usr/local
cd /usr/local
wget --no-check-certificate https://archive.apache.org/dist/tomcat/tomcat-8/v8.5.51/bin/apache-tomcat-8.5.51.tar.gz
tar xvfz apache-tomcat-8.5.51.tar.gz
mv apache-tomcat-8.5.51 tomcat8
rm apache-tomcat-8.5.51.tar.gz
-----------------------------
# 도커라 systemctl 커맨드가 안됨. service 커맨드는 작동하네.
service apache2 start
service apache2 status
# 이렇게 실행하면 종료되지 않는다.
환경변수 세팅 필요.
source /etc/apache2/envars
apachectl -D FOREGROUND
또는
/usr/sbin/apache2 -D FOREGROUND
바로 foreground로 돌리면 경로 없어서 실패가 발생함.
mkdir -p /var/run/apache2
tomcat docker
http://IP:18080/
apache2
http://IP/
-- 설정 변경 스크립트를 만들기 위해...
cat -n 000-default.conf ; 줄번호가 출력됨. 오호.. 이런 기능이!
설정파일에서 스트링 변경
worker 설정 경로를 따로 만들어 주었다.
sed -i 's/libapache2-mod-jk\/workers.properties/apache2\/workers.properties/g' /etc/apache2/mods-available/jk.conf
13번 라인에 insert 하고 싶은데. 아래 baclash 사이에 내용을 쓴다.
sed -i '줄번호i\내용\' 파일명 ; 줄번호라인 위에 한줄이 삽입됨.
즉, 추가한 줄이 입력한 줄번호가 된다.
sed -i '13i\ JkMount /* myworker\' 000-default.conf
-- workers.properties
# cat workers.properties
#
workers.tomcat_home = /usr/local/tomcat8
workers.java_home = /usr/lib/jvm/java-11-openjdk-amd64
worker.list = myworker
worker.myworker.port = 8009
worker.myworker.host = mywas1c
worker.myworker.type = ajp13
web1 apache2 : myweb1 (HTTP)
root@mobiledeep:/home/psychic/docker/docker_gpms/web# cat Dockerfile
FROM debian
RUN apt update
RUN apt install -y curl wget net-tools systemd vim
RUN curl -sSL https://packages.sury.org/apache2/README.txt | bash -x
RUN apt install apache2 libapache2-mod-jk openjdk-11-jre -y
COPY workers.properties /etc/apache2/workers.properties
RUN sed -i 's/libapache2-mod-jk\/workers.properties/apache2\/workers.properties/g' /etc/apache2/mods-available/jk.conf
RUN sed -i '13i\ JkMount /* myworker\' /etc/apache2/sites-available/000-default.conf
#RUN mkdir -p /usr/local && cd /usr/local && wget --no-check-certificate https://archive.apache.org/dist/tomcat/tomcat-8/v8.5.51/bin/apache-tomcat-8.5.51.tar.gz && tar xvfz apache-tomcat-8.5.51.tar.gz && mv apache-tomcat-8.5.51 tomcat8
#RUN rm /usr/local/apache-tomcat-8.5.51.tar.gz
RUN mkdir -p /var/run/apache2
ENV APACHE_RUN_USER=www-data
ENV APACHE_RUN_GROUP=www-data
ENV APACHE_PID_FILE=/var/run/apache2/apache2.pid
ENV APACHE_RUN_DIR=/var/run/apache2
ENV APACHE_LOCK_DIR=/var/lock/apache2
ENV APACHE_LOG_DIR=/var/log/apache2
ENV export LANG=C
CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"]
#CMD ["/bin/bash"]
EXPOSE 80
EXPOSE 443
구동 스크립트
root@mobiledeep:/home/psychic/docker/docker_gpms/web# cat startup.sh
# docker build -t myweb1 .
docker rm -f myweb1c
docker run --rm --name myweb1c -it -p 80:80 -p 443:443 --link mywas1c:mywas1c myweb1
- link 옵션 때문에 tomcat이 먼저 떠 있어서 작동한다.
tomcat 8.5 ; mywas1
root@mobiledeep:/home/psychic/docker/docker_gpms/was# cat Dockerfile
FROM debian
RUN apt update
RUN apt install -y curl wget net-tools systemd vim
RUN apt install openjdk-11-jre -y
RUN mkdir -p /usr/local && cd /usr/local && wget --no-check-certificate https://archive.apache.org/dist/tomcat/tomcat-8/v8.5.51/bin/apache-tomcat-8.5.51.tar.gz && tar xvfz apache-tomcat-8.5.51.tar.gz && mv apache-tomcat-8.5.51 tomcat8 && perl -p -i -e '$.==114 and print " <Connector protocol=\"AJP/1.3\" secretRequired=\"false\" address=\"0.0.0.0\" port=\"8009\" redirectPort=\"8443\" />\n"' /usr/local/tomcat8/conf/server.xml
ENTRYPOINT ["/usr/local/tomcat8/bin/catalina.sh", "run"]
#COPY server.xml /etc/apache2/qauth.conf
#CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"]
#CMD ["/bin/bash"]
EXPOSE 8080
EXPOSE 8009
EXPOSE 8443
----
빌드
# docker build -t mywas1 .
- 구동 스크립트. foreground.
root@mobiledeep:/home/psychic/docker/docker_gpms/was# cat startup.sh
# docker build -t mywas1 .
docker rm -f mywas1c
docker run --rm --name mywas1c -it -p 8080:8080 -p 8443:8443 -p 8009:8009 mywas1
web2 : SSL 설정 (myweb2)
- SSL 설정은 web 만 하면 된다.
- SSL 인증서는 테스트용으로 self-sign 인증서를 만들면 된다. (openssl 커맨드로 쉽게 만들 수 있음.)
- 필요한 커맨드 조사
기존에서 더 작업해야 할 것들.
sed -i '32,33d' /etc/apache2/sites-available/default-ssl.conf
sed -i '32i\SSLCertificateFile /etc/apache2/servercert.pem\' /etc/apache2/sites-available/default-ssl.conf
sed -i '33i\SSLCertificateKeyFile /etc/apache2/server.key\' /etc/apache2/sites-available/default-ssl.conf
sed -i '34i\JkMount /* myworker\' /etc/apache2/sites-available/default-ssl.conf
a2enmod ssl
cd /etc/apache2/sites-available
a2ensite default-ssl.conf
root@mobiledeep:/home/psychic/storage/docker/docker_gpms/web# cat Dockerfile
FROM debian
RUN apt update
RUN apt install -y curl wget net-tools systemd vim
RUN curl -sSL https://packages.sury.org/apache2/README.txt | bash -x
RUN apt install apache2 libapache2-mod-jk openjdk-11-jre -y
COPY workers.properties /etc/apache2/workers.properties
RUN sed -i 's/libapache2-mod-jk\/workers.properties/apache2\/workers.properties/g' /etc/apache2/mods-available/jk.conf
RUN sed -i '13i\ JkMount /* myworker\' /etc/apache2/sites-available/000-default.conf
# SSL
COPY server.key /etc/apache2/server.key
COPY servercert.pem /etc/apache2/servercert.pem
RUN sed -i '32,33d' /etc/apache2/sites-available/default-ssl.conf
RUN sed -i '32i\SSLCertificateFile /etc/apache2/servercert.pem\' /etc/apache2/sites-available/default-ssl.conf
RUN sed -i '33i\SSLCertificateKeyFile /etc/apache2/server.key\' /etc/apache2/sites-available/default-ssl.conf
RUN sed -i '34i\JkMount /* myworker\' /etc/apache2/sites-available/default-ssl.conf
#RUN mkdir -p /usr/local && cd /usr/local && wget --no-check-certificate https://archive.apache.org/dist/tomcat/tomcat-8/v8.5.51/bin/apache-tomcat-8.5.51.tar.gz && tar xvfz apache-tomcat-8.5.51.tar.gz && mv apache-tomcat-8.5.51 tomcat8
#RUN rm /usr/local/apache-tomcat-8.5.51.tar.gz
RUN mkdir -p /var/run/apache2
ENV APACHE_RUN_USER=www-data
ENV APACHE_RUN_GROUP=www-data
ENV APACHE_PID_FILE=/var/run/apache2/apache2.pid
ENV APACHE_RUN_DIR=/var/run/apache2
ENV APACHE_LOCK_DIR=/var/lock/apache2
ENV APACHE_LOG_DIR=/var/log/apache2
ENV export LANG=C
# SSL
RUN a2enmod ssl && cd /etc/apache2/sites-available && a2ensite default-ssl.conf
CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"]
#CMD ["/bin/bash"]
EXPOSE 80
EXPOSE 443
구동스크립트
root@mobiledeep:/home/psychic/storage/docker/docker_gpms/web# cat startup.sh
docker build -t myweb1 .
docker rm -f myweb1c
docker run --rm --name myweb1c -it -p 80:80 -p 443:443 --link mywas1c:mywas1c myweb1
'Develop > Linux_Unix' 카테고리의 다른 글
[tomcat8] tomcat8 설치, 서비스 스크립트 (0) | 2023.01.04 |
---|---|
[ssl] SSL test 인증서 만들기(https 설정) (0) | 2023.01.04 |
[도커] tomcat mysql mongodb (0) | 2021.10.31 |
[도커] tomcat, mariadb 환경 war hang/slow (0) | 2021.04.28 |
Bash Tip 작업속도를 빠르게 (0) | 2021.03.03 |