Container/Docker

[Docker] 도커파일 Apache-Tomcat 망분리 구축 및 Zabbix-Agent 설치 간단 예제 (Apache Dockerfile, Tomcat Dockerfile, Zabbix-agent Dockerfile)

Nirsa 2020. 5. 29. 16:57
반응형

 

  • 도커 Apache-Tomcat 망분리 구축 및 Zabbix-Agent 설치 코드 (Apache Dockerfile, Tomcat Dockerfile, Zabbix-agent Dockerfile)

기존에 올렸던 포스팅(https://nirsa.tistory.com/132?category=876464)을 도커파일로 변환시켜서 사용하는 예제 입니다. 셋팅자체는 위의 포스팅과 거의 똑같고 서버 IP 등의 정보는 변경해서 사용하시면 됩니다.

기본적으로 연결하기 위한 간단한 설정만 적용된 apache, zabbix-agent 두가지 Dockerfile을 만든 후 docker-compose를 사용하여 실행 했습니다. 간단히 작성된것이므로 볼륨등을 추가적으로 설정 후 사용하시는게 좋습니다. 만약, 소스코드를 따로 설정해야할 경우 COPY 또는 VOLUMES 등을 이용하면 됩니다.

 

  • Apache Server
# Dockerfile-web-v1.1
FROM centos:7

RUN yum install -y httpd httpd-devel gcc gcc-c++ wget perl make &&  mkdir /worker
WORKDIR /worker/
wget http://apache.mirror.cdnetworks.com/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.48-src.tar.gz && tar zxvf tomcat-connectors-1.2.48-src.tar.gzWORKDIR /worker/tomcat-connectors-1.2.48-src/native/
RUN ./configure --with-apxs=/bin/apxs \
	&& make && make install \
	&& sed -i 's/\#ServerName www.example.com:80/ServerName localhost/g' /etc/httpd/conf/httpd.conf \
	&& touch /etc/httpd/conf/workers.properties \
	&& echo -e "worker.list=loadbalancer\nworker.loadbalancer.type=lb\nworker.loadbalancer.balanced_workers=worker1,worker2\nworker.loadbalancer.sticky_session=1\n\nworker.worker1.type=ajp13\nworker.worker1.host=10.178.0.7\nworker.worker1.port=8010\nworker.worker1.lbfactor=1\n\nworker.worker2.type=ajp13\nworker.worker2.host=10.178.0.8\nworker.worker2.port=9010\nworker.worker2.lbfactor=1\n" > /etc/httpd/conf/workers.properties \
	&& perl -p -i -e '$.==57 and print "LoadModule jk_module /usr/lib64/httpd/modules/mod_jk.so\n<IfModule jk_module>\n   JkWorkersFile /etc/httpd/conf/workers.properties\n   JkLogFile /var/log/httpd/mod_jk.log\n   JkLogLevel info\n   JkLogStampFormat \"[%a %b %d %H:%M:%S %Y]\"\n   JkMount /*.jsp loadbalancer\n</IfModule>"' /etc/httpd/conf/httpd.conf 

CMD ["/usr/sbin/httpd", "-D", "FOREGROUND"]
EXPOSE 80
# Dockerfile-zabbix-v1.2
FROM centos:7

RUN rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm \
        && yum -y install zabbix-agent \
        && sed -i 's/Server=127.0.0.1/Server=10.178.0.4/g' /etc/zabbix/zabbix_agentd.conf \
        && sed -i 's/ServerActive=127.0.0.1/ServerActive=10.178.0.4/g' /etc/zabbix/zabbix_agentd.conf

EXPOSE 10050/TCP
CMD ["/usr/sbin/zabbix_agentd", "--foreground", "-c", "/etc/zabbix/zabbix_agentd.conf"]
# docker-compose.yaml
version: "3"
services:
  apache:
    image: apache:v1.1
    build:
      context: .
      dockerfile: Dockerfile-web-v1.1
    ports:
      - "80:80"

  zabbix:
    image: zabbix:v1.2
    build:
      context: .
      dockerfile: Dockerfile-zabbix-v1.2
    ports:
      - "10050:10050"

 

  • Tomcat
# Dockerfile-was1-v1.1
FROM centos:7

RUN yum -y update && yum install -y java-1.8.0-openjdk-devel.x86_64 wget perl
ENV JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64
ENV export JAVA_HOME
ENV PATH=$PATH:$JAVA_HOME/bin
ENV export PATH

RUN wget http://mirror.navercorp.com/apache/tomcat/tomcat-9/v9.0.36/bin/apache-tomcat-9.0.36.tar.gz \
	&& tar zxvf apache-tomcat-9.0.36.tar.gz \
	&& mv apache-tomcat-9.0.36 /usr/local/tomcat9 \
	&& perl -p -i -e '$.==114 and print "    <Connector protocol=\"AJP/1.3\" secretRequired=\"false\" address=\"0.0.0.0\" port=\"8010\" redirectPort=\"8443\" />\n"' /usr/local/tomcat9/conf/server.xml \
	&& echo "hi worker1" > /usr/local/tomcat9/webapps/ROOT/index.jsp
    
ENTRYPOINT ["/usr/local/tomcat9/bin/catalina.sh", "run"]
EXPOSE 8010
# Dockerfile-zabbix-v1.2
FROM centos:7

RUN rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm \
        && yum -y install zabbix-agent \
        && sed -i 's/Server=127.0.0.1/Server=10.178.0.4/g' /etc/zabbix/zabbix_agentd.conf \
        && sed -i 's/ServerActive=127.0.0.1/ServerActive=10.178.0.4/g' /etc/zabbix/zabbix_agentd.conf

EXPOSE 10050/TCP
CMD ["/usr/sbin/zabbix_agentd", "--foreground", "-c", "/etc/zabbix/zabbix_agentd.conf"]
# docker-compose.yaml
version: "3"
services:
  apache:
    image: tomcat:v1.1
    build:
      context: .
      dockerfile: Dockerfile-was1-v1.1
    ports:
      - "8010:8010"

  zabbix:
    image: zabbix:v1.2
    build:
      context: .
      dockerfile: Dockerfile-zabbix-v1.2
    ports:
      - "10050:10050"

 

반응형