この記事は約92分32秒で読むことができます。

apacheとtomcatをdockerコンテナで作って,ajp連携できるようにした話。

参考文献

なんとなくわかる。なんかのアイディアにつかえそう。

Dockerfileを並列に結ぶコマンドを作りたい(作った?)  

Docker ARGコマンドすげぇつかえそう

Dockerfile ARG入門  
Docker Compose - docker-compose.yml リファレンス  
DockerでTomcatとNginxの構築をやってみた  
Proxy Support HOW-TO  
Apache モジュール mod_proxy  
よく見るHTTPステータスコード一覧とその意味を理解する  
Apache のリバースプロキシの設定方法  
Apache httpd と Tomcat を連携させる方法  
Apache 2.4 で リバースプロキシの設定  

ディレクトリ構成

コード表示

[oracle@centos tmp]$ tree
.
├── app
│   ├── ap
│   │   ├── Dockerfile
│   │   ├── kick.sh
│   │   └── mig
│   │       ├── cfg
│   │       │   ├── env.sh
│   │       │   └── inst.sh
│   │       ├── exe
│   │       │   └── pre.sh
│   │       └── src
│   │           └── index.html
│   ├── db
│   └── web
│       ├── Dockerfile
│       ├── kick.sh
│       └── mig
│           ├── cfg
│           │   ├── env.sh
│           │   └── inst.sh
│           ├── exe
│           │   └── pre.sh
│           └── src
│               └── index.html
└── docker-compose.yml

12 directories, 13 files

Dockerfile

ap側

コード表示

[oracle@centos tmp]$ cat $(find ./app/ap -name "D*")
FROM centos:latest

ENV TZ='Asia/Tokyo'

ENV MNT_DIR=/mnt
ENV MIG_DIR=./mig
ENV CFG_DIR=${MNT_DIR}/cfg
ENV EXE_DIR=${MNT_DIR}/exe
ENV TAR_DIR=/mnt

COPY ${MIG_DIR}/ ${MNT_DIR}/

RUN source ${CFG_DIR}/*.sh

RUN find ${TAR_DIR} -name "*.sh"
RUN chmod u+x ${CFG_DIR}/*.sh && find ${CFG_DIR} -name "*.sh" | while read line;do bash -c ${line};done
RUN chmod u+x ${EXE_DIR}/*.sh && find ${EXE_DIR} -name "*.sh" | while read line;do bash -c ${line};done

RUN sed -i -e 's/.*<role rolename="admin-gui"\/>.*/<role rolename="admin-gui"\/>/' /usr/share/tomcat/conf/tomcat-users.xml
RUN sed -i -e 's/.*<role rolename="manager-gui"\/>.*/<role rolename="manager-gui"\/>/' /usr/share/tomcat/conf/tomcat-users.xml
RUN sed -i -e 's/.*<user name="admin".*/<user name="admin" password="tomcat" roles="admin-gui,manager-gui"\/>/' /usr/share/tomcat/conf/tomcat-users.xml

EXPOSE 8080
CMD ["/sbin/init"]

web側

コード表示

[oracle@centos tmp]$ cat $(find ./app/web -name "D*")
FROM centos:latest

ENV TZ='Asia/Tokyo'

ENV MNT_DIR=/mnt
ENV MIG_DIR=./mig
ENV CFG_DIR=${MNT_DIR}/cfg
ENV EXE_DIR=${MNT_DIR}/exe
ENV WEB_SRC_DIR=${MIG_DIR}/src
ENV AP_SRC_DIR=${MNT_DIR}/src/ap
ENV TAR_DIR=/mnt

COPY ${MIG_DIR}/ ${MNT_DIR}/

RUN source ${CFG_DIR}/*.sh

COPY ${WEB_SRC_DIR}/*.html ${WEB_TAR_DIR}/
 
RUN find ${TAR_DIR} -name "*.sh"

RUN chmod u+x ${CFG_DIR}/*.sh && find ${CFG_DIR} -name "*.sh" | while read line;do bash -c ${line};done
RUN chmod u+x ${EXE_DIR}/*.sh && find ${EXE_DIR} -name "*.sh" | while read line;do bash -c ${line};done

EXPOSE 80
CMD ["/sbin/init"]

kick.sh

apとwebで差はない。コレ一つにまとめるスクリプトつくれそうだけど、、まだできていない。

コード表示

[oracle@centos tmp]$ diff $(echo $(find ./app/ -name "kic*"))
[oracle@centos tmp]$ cat $(find ./app/web -name "kic*")
WK_PATH=$0
EXE_PATH=$(pwd)${WK_PATH#.}
IMAGE_NAME=$1

if [ -z "${IMAGE_NAME}" ]; then
cat <<EOF
_________________________________________________________________________________
please enter build image name.

EOF
  exit 1
fi

echo "Building image '${IMAGE_NAME}' ..."

BUILD_START=$(date '+%s')
( cd ${EXE_PATH%/*};docker build --force-rm=true --no-cache=true -t ${IMAGE_NAME} -f Dockerfile . || {
  echo 'there was an error building the image.'
  exit 1
} )
BUILD_END=$(date '+%s')
BUILD_ELAPSED=$((${BUILD_END}-${BUILD_START}))

echo ''

if [ $? -eq 0 ]; then
cat <<EOF
_________________________________________________________________________________

-->${IMAGE_NAME} was built

Build completed in ${BUILD_ELAPSED} seconds.

EOF

else
  echo 'docker image was NOT successfully created'
fi

env.sh

空っぽ。ちなみに試したけど、外部ファイルの環境変数ENVコマンド以外で指定できないぽいから、除外対象ファイルとか除外文言とか定義したりして活用する見込み。

コード表示

[oracle@centos tmp]$ diff $(echo $(find ./app/ -name "env*"))
[oracle@centos tmp]$ cat $(find ./app/web -name "env*")
#!/bin/bash

inst.sh

ap側

コード表示

[oracle@centos tmp]$ cat $(find ./app/ap -name "inst*")
#!/bin/bash
yum install -y tar \ 
yum install -y curl \ 
yum install -y iputils \
yum install -y net-tools \
yum install -y iproute \
yum install -y vim \
yum install -y tree \
yum install -y lsof \
yum install -y tomcat \
yum install -y tomcat-webapps \
yum install -y tomcat-admin-webapps \
yum install -y tomcat-docs-webapp

web側

コード表示

[oracle@centos tmp]$ cat $(find ./app/web -name "inst*")
#!/bin/bash
yum install -y httpd \ 
yum install -y iputils \
yum install -y net-tools \
yum install -y iproute \
yum install -y vim \
yum install -y tree \
yum install -y lsof

pre.sh

このスクリプトいいよな。サブシェルでディレクトリ変えずに、マッチしないやつは消していく発想。ハンドリングも綺麗。

コード表示

[oracle@centos tmp]$ diff $(echo $(find ./app/ -name "pre*"))
[oracle@centos tmp]$ cat $(find ./app/ap -name "pre*")
#!/bin/bash
(cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;\
yum update -y;yum clean all;

index.html

コード表示

[oracle@centos tmp]$ diff $(echo $(find ./app/ -name "inde*"))
[oracle@centos tmp]$ cat $(find ./app/ap -name "inde*")
<html>
    <head>
        <title>Test Page</title>
    </head>
    <body>
        <p>This is a test.</p>
    </body>
</html>

docker-compose.yml

bashかけるんだったら、うまいことやってやろうとしたけど。そう簡単に甘くない。上書きされたりされなかったりがめんどくさいんだよな。8009ポートは外部からアクセスする必要ないので、portsではなく、expose。

コード表示

[oracle@centos tmp]$ cat $(find ./ -name "*com*")
version: '3'
services:
  apache:
    image: apache
    container_name: apa
    #command: bash -c "echo hoge"
    privileged: true
    ports:
      - '8080:80'
  tomcat:
    image: tomcat
    container_name: tom
    #command: bash -c "echo hoge"
    privileged: true
    ports:
      - '8081:8080'
    expose:
      - '8009'

dockerイメージ作成

コード表示

[oracle@centos tmp]$ bash $(find ./app/ap -name "kic*") tomcat
[oracle@centos tmp]$ bash $(find ./app/web -name "kic*") apache
[oracle@centos tmp]$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
apache              latest              31ede815a512        2 minutes ago       503MB
tomcat              latest              6f8507eb4e71        4 minutes ago       681MB
centos              latest              9f38484d220f        6 weeks ago         202MB

コンテナ起動前、ブリッジ接続ルータ確認

コード表示

[oracle@centos tmp]$ brctl show
bridge name	bridge id		STP enabled	interfaces
docker0		8000.0242bccfb016	no		
virbr0		8000.5254006a2171	yes		virbr0-nic

コンテナ起動前、ip確認

コード表示

[oracle@centos tmp]$ ip a show
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0:  mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:d8:61:2c:f1:5b brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.109/24 brd 192.168.1.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::ccc0:20d4:3aed:ca75/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: virbr0:  mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:6a:21:71 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic:  mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:6a:21:71 brd ff:ff:ff:ff:ff:ff
5: docker0:  mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:bc:cf:b0:16 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:bcff:fecf:b016/64 scope link 
       valid_lft forever preferred_lft forever

コンテナ起動前、ipマスカレ確認

POSTROUTING確認。一部抜粋。

コード表示

[oracle@centos tmp]$ sudo iptables -t nat -L -n
[sudo] oracle のパスワード:
Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         
MASQUERADE  all  --  172.17.0.0/16        0.0.0.0/0           
RETURN     all  --  192.168.122.0/24     224.0.0.0/24        
RETURN     all  --  192.168.122.0/24     255.255.255.255     
MASQUERADE  tcp  --  192.168.122.0/24    !192.168.122.0/24     masq ports: 1024-65535
MASQUERADE  udp  --  192.168.122.0/24    !192.168.122.0/24     masq ports: 1024-65535
MASQUERADE  all  --  192.168.122.0/24    !192.168.122.0/24    
POSTROUTING_direct  all  --  0.0.0.0/0            0.0.0.0/0           
POSTROUTING_ZONES_SOURCE  all  --  0.0.0.0/0            0.0.0.0/0           
POSTROUTING_ZONES  all  --  0.0.0.0/0            0.0.0.0/0           

dockerコンテナ起動

コード表示

[oracle@centos tmp]$ docker-compose down
Stopping tom ... done
Stopping apa ... done
Removing tom ... done
Removing apa ... done
Removing network tmp_default
[oracle@centos tmp]$ docker-compose up -d
Creating network "tmp_default" with the default driver
Creating apa ... done
Creating tom ... done
[oracle@centos tmp]$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                              NAMES
c2b460acbc07        tomcat              "/sbin/init"        54 seconds ago      Up 53 seconds       8009/tcp, 0.0.0.0:8081->8080/tcp   tom
61eff46d2318        apache              "/sbin/init"        54 seconds ago      Up 53 seconds       0.0.0.0:8080->80/tcp               apa

コンテナ起動後、ブリッジ確認

コード表示

[oracle@centos tmp]$ brctl show
bridge name	bridge id		STP enabled	interfaces
br-e1cb1ad75561		8000.02424a058b14	no		veth027f014
							veth2c1ba96
docker0		8000.0242bccfb016	no		
virbr0		8000.5254006a2171	yes		virbr0-nic

コンテナ起動後、ip確認

docker-composeだとデフォルトでbridge接続のルータできるんだな。出来たルータにコンテナのケーブルが刺さっている。

コード表示

[oracle@centos tmp]$ ip a show
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0:  mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:d8:61:2c:f1:5b brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.109/24 brd 192.168.1.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::ccc0:20d4:3aed:ca75/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: virbr0:  mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:6a:21:71 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic:  mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:6a:21:71 brd ff:ff:ff:ff:ff:ff
5: docker0:  mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:bc:cf:b0:16 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:bcff:fecf:b016/64 scope link 
       valid_lft forever preferred_lft forever
556: br-e1cb1ad75561:  mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:4a:05:8b:14 brd ff:ff:ff:ff:ff:ff
    inet 172.28.0.1/16 brd 172.28.255.255 scope global br-e1cb1ad75561
       valid_lft forever preferred_lft forever
    inet6 fe80::42:4aff:fe05:8b14/64 scope link 
       valid_lft forever preferred_lft forever
558: veth2c1ba96@if557:  mtu 1500 qdisc noqueue master br-e1cb1ad75561 state UP group default 
    link/ether fa:07:e3:4e:8e:3a brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet6 fe80::f807:e3ff:fe4e:8e3a/64 scope link 
       valid_lft forever preferred_lft forever
560: veth027f014@if559:  mtu 1500 qdisc noqueue master br-e1cb1ad75561 state UP group default 
    link/ether d6:cf:3d:b9:7e:73 brd ff:ff:ff:ff:ff:ff link-netnsid 1
    inet6 fe80::d4cf:3dff:feb9:7e73/64 scope link 
       valid_lft forever preferred_lft forever

docker network確認

tmp_default以外はデフぉである。composeでできたということ。

コード表示

[oracle@centos tmp]$ docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
73a8404b71c6        bridge              bridge              local
ad2f99e1e398        host                host                local
4d1d8a2fc9da        none                null                local
e1cb1ad75561        tmp_default         bridge              local

コンテナに割り当てられたip確認

コード表示

[oracle@centos tmp]$ docker network inspect $(docker network ls -q) | grep -E "Subnet|Name|IPv4|G"
        "Name": "bridge",
                    "Subnet": "172.17.0.0/16",
                    "Gateway": "172.17.0.1"
        "Name": "host",
        "Name": "none",
        "Name": "tmp_default",
                    "Subnet": "172.28.0.0/16",
                    "Gateway": "172.28.0.1"
                "Name": "apa",
                "IPv4Address": "172.28.0.2/16",
                "Name": "tom",
                "IPv4Address": "172.28.0.3/16",

コンテナ起動後、ipマスカレ確認

一部抜粋。POSTROUTINGにブリッジルータの奴が登録されている。

コード表示

[oracle@centos tmp]$ sudo iptables -t nat -L -n
[sudo] oracle のパスワード:
Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         
MASQUERADE  all  --  172.28.0.0/16        0.0.0.0/0           
MASQUERADE  all  --  172.17.0.0/16        0.0.0.0/0           
RETURN     all  --  192.168.122.0/24     224.0.0.0/24        
RETURN     all  --  192.168.122.0/24     255.255.255.255     
MASQUERADE  tcp  --  192.168.122.0/24    !192.168.122.0/24     masq ports: 1024-65535
MASQUERADE  udp  --  192.168.122.0/24    !192.168.122.0/24     masq ports: 1024-65535
MASQUERADE  all  --  192.168.122.0/24    !192.168.122.0/24    
POSTROUTING_direct  all  --  0.0.0.0/0            0.0.0.0/0           
POSTROUTING_ZONES_SOURCE  all  --  0.0.0.0/0            0.0.0.0/0           
POSTROUTING_ZONES  all  --  0.0.0.0/0            0.0.0.0/0           
MASQUERADE  tcp  --  172.28.0.2           172.28.0.2           tcp dpt:80
MASQUERADE  tcp  --  172.28.0.3           172.28.0.3           tcp dpt:8080

tomcatコンテナに潜る

server.xmlのポート確認。未使用ポートになりうる、8080はクローズしておく本来は。今回は開けっぱで。

コード表示

[root@c2b460acbc07 /]# cp /etc/tomcat/{,org_}server.xml
cp: overwrite '/etc/tomcat/org_server.xml'? y
[root@c2b460acbc07 /]# diff /etc/tomcat/{,org_}server.xml
[root@c2b460acbc07 /]# cat ./etc/tomcat/server.xml | grep -A 10 "Connector port="
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
    <!-- Define a SSL HTTP/1.1 Connector on port 8443
--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
               maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" />
    -->

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />


    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">

webappsでググる。ここらのフォルダは削除してあらたに作っていってもいいんだよな。そっちの方がすっきりする。参考程度のコンテナきってもいいし。何かモノ作る時には削除しよう。web.xmlも大事だ。

コード表示

[root@c2b460acbc07 /]# find . -name "*webapps*"
./usr/share/tomcat/webapps
./var/lib/yum/yumdb/t/6343923fac93857eecb0cd7fd4ff8015ec401c66-tomcat-admin-webapps-7.0.76-9.el7_6-noarch
./var/lib/yum/yumdb/t/47c2512fc616bb948c785d40da7093e19239019d-tomcat-webapps-7.0.76-9.el7_6-noarch
./var/lib/tomcat/webapps
[root@c2b460acbc07 /]# diff -r /usr/share/tomcat/webapps /var/lib/tomcat/webapps
[root@c2b460acbc07 /]# ll /usr/share/tomcat/webapps
lrwxrwxrwx. 1 root tomcat 23 Apr 30 22:17 /usr/share/tomcat/webapps -> /var/lib/tomcat/webapps
[root@c2b460acbc07 /]# ll /var/lib/tomcat/webapps
total 24
drwxr-xr-x.  3 tomcat tomcat 4096 Apr 30 22:17 ROOT
drwxr-xr-x. 14 root   root   4096 Apr 30 22:17 docs
drwxr-xr-x.  8 tomcat tomcat 4096 Apr 30 22:17 examples
drwxr-xr-x.  5 root   tomcat 4096 Apr 30 22:17 host-manager
drwxr-xr-x.  5 root   tomcat 4096 Apr 30 22:17 manager
drwxr-xr-x.  5 tomcat tomcat 4096 Apr 30 22:17 sample
[root@c2b460acbc07 /]# find . -name "*web.xml*"
./usr/share/mime/application/vnd.oasis.opendocument.text-web.xml
./var/lib/tomcat/webapps/ROOT/WEB-INF/web.xml
./var/lib/tomcat/webapps/sample/WEB-INF/web.xml
./var/lib/tomcat/webapps/host-manager/WEB-INF/web.xml
./var/lib/tomcat/webapps/manager/WEB-INF/web.xml
./var/lib/tomcat/webapps/examples/WEB-INF/web.xml
./var/lib/tomcat/webapps/docs/appdev/web.xml.txt
./var/lib/tomcat/webapps/docs/appdev/sample/web/WEB-INF/web.xml
./var/lib/tomcat/webapps/docs/WEB-INF/web.xml
./etc/tomcat/web.xml

サービス起動

コード表示

[root@c2b460acbc07 /]# systemctl status tomcat
● tomcat.service - Apache Tomcat Web Application Container
   Loaded: loaded (/usr/lib/systemd/system/tomcat.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
[root@c2b460acbc07 /]# systemctl start tomcat
[root@c2b460acbc07 /]# systemctl status tomcat
● tomcat.service - Apache Tomcat Web Application Container
   Loaded: loaded (/usr/lib/systemd/system/tomcat.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2019-05-01 15:16:50 JST; 1s ago
 Main PID: 5725 (java)
   CGroup: /docker/c2b460acbc0728e00a4443375d97e70d4caebdb487aa3a54538f78fc06f4932f/system.slice/tomcat.service
           └─5725 /usr/lib/jvm/jre/bin/java -classpath /usr/share/tomcat/bin/bootstrap.jar:/usr/share/tomcat/bin/tomcat-juli.jar:/usr/share/java/commons-daemon.jar -Dcatalina.base=/usr/share/tomcat -Dcatalina...
           ‣ 5725 /usr/lib/jvm/jre/bin/java -classpath /usr/share/tomcat/bin/bootstrap.jar:/usr/share/tomcat/bin/tomcat-juli.jar:/usr/share/java/commons-daemon.jar -Dcatalina.base=/usr/share/tomcat -Dcatalina...

May 01 15:16:51 c2b460acbc07 server[5725]: May 01, 2019 6:16:51 AM org.apache.catalina.startup.TldConfig execute
May 01 15:16:51 c2b460acbc07 server[5725]: INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned b...pilation time.
May 01 15:16:51 c2b460acbc07 server[5725]: May 01, 2019 6:16:51 AM org.apache.catalina.startup.HostConfig deployDirectory
May 01 15:16:51 c2b460acbc07 server[5725]: INFO: Deployment of web application directory /var/lib/tomcat/webapps/docs has finished in 114 ms
May 01 15:16:51 c2b460acbc07 server[5725]: May 01, 2019 6:16:51 AM org.apache.coyote.AbstractProtocol start
May 01 15:16:51 c2b460acbc07 server[5725]: INFO: Starting ProtocolHandler ["http-bio-8080"]
May 01 15:16:51 c2b460acbc07 server[5725]: May 01, 2019 6:16:51 AM org.apache.coyote.AbstractProtocol start
May 01 15:16:51 c2b460acbc07 server[5725]: INFO: Starting ProtocolHandler ["ajp-bio-8009"]
May 01 15:16:51 c2b460acbc07 server[5725]: May 01, 2019 6:16:51 AM org.apache.catalina.startup.Catalina start
May 01 15:16:51 c2b460acbc07 server[5725]: INFO: Server startup in 955 ms
Hint: Some lines were ellipsized, use -l to show in full.
[root@c2b460acbc07 /]# lsof -i:8009 -i:8080 -P
COMMAND  PID   USER   FD   TYPE    DEVICE SIZE/OFF NODE NAME
java    5725 tomcat   49u  IPv4 670144588      0t0  TCP *:8080 (LISTEN)
java    5725 tomcat   50u  IPv4 670144589      0t0  TCP *:8009 (LISTEN)

apacheにもぐる

noindexでぐぐると、デフぉ頁のふぁいるでてくる。ちなみに/var/www/htmlにファイル置いているとtomcatのデフォルトページがでないんだね。

コード表示

[oracle@centos ~]$ docker exec -it apa /bin/bash
[root@61eff46d2318 /]# find / -name "*noindex*"
/usr/share/httpd/noindex
[root@61eff46d2318 /]# cd /usr/share/httpd/noindex
[root@61eff46d2318 noindex]# ll
total 16
drwxr-xr-x. 3 root root 4096 Apr 30 22:19 css
drwxr-xr-x. 2 root root 4096 Apr 30 22:19 images
-rw-r--r--. 1 root root 4897 Oct 16  2014 index.html
[root@61eff46d2318 noindex]# cd ..
[root@61eff46d2318 httpd]# ll
total 12
drwxr-xr-x. 3 root root 4096 Apr 30 22:19 error
drwxr-xr-x. 3 root root 4096 Apr 30 22:19 icons
drwxr-xr-x. 4 root root 4096 Apr 30 22:19 noindex

asobu。起動したりすれば、staticなページをcurlで標準出力したりできる。

コード表示

[root@61eff46d2318 httpd]# cd /var/www/html
[root@61eff46d2318 html]# ll 
total 0
[oracle@centos ~]$ docker exec -it apa /bin/bash
[root@61eff46d2318 /]# cd /var/www/html
[root@61eff46d2318 html]# cat <<ROD >index.html
> <html>
>     <head>
>         <title>Test Page</title>
>     </head>
>     <body>
>         <p>ainekurainenahatomujiku</p>
>     </body>
> </html>
> ROD
[root@61eff46d2318 html]# cat ind*
<html>
    <head>
        <title>Test Page</title>
    </head>
    <body>
        <p>ainekurainenahatomujiku</p>
    </body>
</html>
[root@61eff46d2318 html]# ll
total 4
-rw-r--r--. 1 root root 133 May  1 15:21 index.html
[root@61eff46d2318 html]# mkdir -p {aine,kuraine,nahato,mujiku}
[root@61eff46d2318 html]# tree
.
|-- aine
|-- index.html
|-- kuraine
|-- mujiku
`-- nahato

4 directories, 1 file
[root@61eff46d2318 html]# printf '%s\n' {aine,kuraine,nahato,mujiku} | xargs -I@ bash -c 'echo cp index.html @'
cp index.html aine
cp index.html kuraine
cp index.html nahato
cp index.html mujiku
[root@61eff46d2318 html]# printf '%s\n' {aine,kuraine,nahato,mujiku} | xargs -I@ bash -c 'cp index.html @'
[root@61eff46d2318 html]# tree
.
|-- aine
|   `-- index.html
|-- index.html
|-- kuraine
|   `-- index.html
|-- mujiku
|   `-- index.html
`-- nahato
    `-- index.html

4 directories, 5 files
[root@61eff46d2318 html]# ll
total 36
drwxr-xr-x. 2 root root 4096 May  1 15:22 aine
-rw-r--r--. 1 root root  133 May  1 15:21 index.html
drwxr-xr-x. 2 root root 4096 May  1 15:22 kuraine
drwxr-xr-x. 2 root root 4096 May  1 15:22 mujiku
drwxr-xr-x. 2 root root 4096 May  1 15:22 nahato
[root@61eff46d2318 html]# printf '%s\n' 'http://192.168.1.109:8080/'{aine,kuraine,nahato,mujiku}'/index.html'
http://192.168.1.109:8080/aine/index.html
http://192.168.1.109:8080/kuraine/index.html
http://192.168.1.109:8080/nahato/index.html
http://192.168.1.109:8080/mujiku/index.html
[root@61eff46d2318 html]# printf '%s\n' 'curl -v http://192.168.1.109:8080/'{aine,kuraine,nahato,mujiku}'/index.html' | xargs -I@ bash -c '@'
* About to connect() to 192.168.1.109 port 8080 (#0)
*   Trying 192.168.1.109...
* No route to host
* Failed connect to 192.168.1.109:8080; No route to host
* Closing connection 0
curl: (7) Failed connect to 192.168.1.109:8080; No route to host
* About to connect() to 192.168.1.109 port 8080 (#0)
*   Trying 192.168.1.109...
* No route to host
* Failed connect to 192.168.1.109:8080; No route to host
* Closing connection 0
curl: (7) Failed connect to 192.168.1.109:8080; No route to host
* About to connect() to 192.168.1.109 port 8080 (#0)
*   Trying 192.168.1.109...
* No route to host
* Failed connect to 192.168.1.109:8080; No route to host
* Closing connection 0
curl: (7) Failed connect to 192.168.1.109:8080; No route to host
* About to connect() to 192.168.1.109 port 8080 (#0)
*   Trying 192.168.1.109...
* No route to host
* Failed connect to 192.168.1.109:8080; No route to host
* Closing connection 0
curl: (7) Failed connect to 192.168.1.109:8080; No route to host

httpd.confに追加

脱線したけど、これが大切。ipはdockerコンテナのapaにallocateされているip。

コード表示

[root@61eff46d2318 /]# cp /etc/httpd/conf/{,org_}httpd.conf
[root@61eff46d2318 /]# diff /etc/httpd/conf/{,org_}httpd.conf
[root@61eff46d2318 /]# vi /etc/httpd/conf/httpd.conf
[root@61eff46d2318 /]# diff /etc/httpd/conf/{,org_}httpd.conf
354,356d353
< ProxyRequests Off
< ProxyPass / ajp://172.28.0.3/
< ProxyPassReverse / ajp://172.28.0.3/

httpdサービス起動

コード表示

[root@61eff46d2318 /]# systemctl status httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:httpd(8)
           man:apachectl(8)
[root@61eff46d2318 /]# systemctl start httpd.service
[root@61eff46d2318 /]# systemctl status httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2019-05-01 15:30:03 JST; 1s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 5954 (httpd)
   Status: "Processing requests..."
   CGroup: /docker/61eff46d23187594f7efef2c6d7dee336011a869d9c014c8144a8b2d35290783/system.slice/httpd.service
           ├─5954 /usr/sbin/httpd -DFOREGROUND
           ├─5955 /usr/sbin/httpd -DFOREGROUND
           ├─5956 /usr/sbin/httpd -DFOREGROUND
           ├─5957 /usr/sbin/httpd -DFOREGROUND
           ├─5958 /usr/sbin/httpd -DFOREGROUND
           └─5959 /usr/sbin/httpd -DFOREGROUND
           ‣ 5954 /usr/sbin/httpd -DFOREGROUND

May 01 15:30:03 61eff46d2318 systemd[1]: Starting The Apache HTTP Server...
May 01 15:30:03 61eff46d2318 httpd[5954]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.28.0.2. Set the 'ServerName' directive globally to suppress this message
May 01 15:30:03 61eff46d2318 systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.

ブラウザから確認。それぞれ同じ画面が出ていればOK。

tomcatのほう。managerはユーザー名とパスワードはtomcat/adminかな

コード表示

http://192.168.1.109:8081/docs
http://192.168.1.109:8081/sample
http://192.168.1.109:8081/example
http://192.168.1.109:8081/manager/html

apacheのほう

コード表示

http://192.168.1.109:8080/docs
http://192.168.1.109:8080/sample
http://192.168.1.109:8080/example
http://192.168.1.109:8080/manager/html

ログ確認。apacheにもtomcatにも同じログでているね。

tomcat側

コード表示

[root@c2b460acbc07 /]# find /var -name "*log*"
/var/lib/systemd/catalog
/var/lib/yum/yumdb/a/0be125f712efee4727af884ffa4a21b3d366a71e-avalon-logkit-2.1-14.el7-noarch
/var/lib/yum/yumdb/a/e6cbbc5407023b2bee22d34231a4266b69d0ea4c-apache-commons-logging-1.1.2-7.el7-noarch
/var/lib/yum/yumdb/l/fcb0a245a2d3b4e92b76136762f22caf2e7fe5f7-log4j-1.2.17-16.el7_4-noarch
/var/lib/tomcat/webapps/ROOT/asf-logo-wide.svg
/var/lib/tomcat/webapps/host-manager/images/asf-logo.svg
/var/lib/tomcat/webapps/manager/images/asf-logo.svg
/var/lib/tomcat/webapps/examples/jsp/security/protected/login.jsp
/var/lib/tomcat/webapps/examples/jsp/security/protected/login.jsp.html
/var/lib/tomcat/webapps/examples/jsp/cal/login.html
/var/lib/tomcat/webapps/examples/servlets/chat/login.jsp
/var/lib/tomcat/webapps/examples/servlets/chat/login.jsp.html
/var/lib/tomcat/webapps/docs/images/asf-logo.svg
/var/lib/tomcat/webapps/docs/logging.html
/var/lib/tomcat/webapps/docs/changelog.html
/var/log
/var/log/yum.log
/var/log/lastlog
/var/log/tallylog
/var/log/tomcat/catalina.2019-05-01.log
/var/log/tomcat/localhost.2019-05-01.log
/var/log/tomcat/localhost_access_log.2019-05-01.txt
/var/log/tomcat/manager.2019-05-01.log
/var/log/tomcat/host-manager.2019-05-01.log
[root@c2b460acbc07 /]# tail -f /var/log/tomcat/localhost_access_log.2019-05-01.txt
192.168.1.109 - - [01/May/2019:06:34:19 +0000] "GET / HTTP/1.1" 200 11217
192.168.1.109 - - [01/May/2019:06:37:33 +0000] "GET /docs HTTP/1.1" 302 -
192.168.1.109 - - [01/May/2019:06:37:33 +0000] "GET /docs/ HTTP/1.1" 304 -
192.168.1.109 - - [01/May/2019:06:46:18 +0000] "GET / HTTP/1.1" 200 11197
192.168.1.109 - - [01/May/2019:06:46:32 +0000] "GET /docs HTTP/1.1" 302 -
192.168.1.109 - - [01/May/2019:06:46:39 +0000] "GET /docs/introduction.html HTTP/1.1" 200 15227
192.168.1.109 - - [01/May/2019:06:46:42 +0000] "GET /docs/jndi-resources-howto.html HTTP/1.1" 200 58181
192.168.1.109 - - [01/May/2019:06:46:43 +0000] "GET /docs/manager-howto.html HTTP/1.1" 200 80158
192.168.1.109 - - [01/May/2019:06:46:43 +0000] "GET /docs/jasper-howto.html HTTP/1.1" 200 26829
192.168.1.109 - - [01/May/2019:06:46:44 +0000] "GET /docs/mbeans-descriptors-howto.html HTTP/1.1" 200 10795

apache側

コード表示

[root@61eff46d2318 /]# find /var -name "*log*"
/var/lib/systemd/catalog
/var/lib/yum/yumdb/c/b3f16e3c1bff41f2602b03b90e2f37b26e59400b-centos-logos-70.0.6-3.el7.centos-noarch
/var/log
/var/log/yum.log
/var/log/lastlog
/var/log/tallylog
/var/log/httpd/access_log
/var/log/httpd/error_log
[root@61eff46d2318 /]# tail -f /var/log/httpd/access_log
192.168.1.109 - - [01/May/2019:06:34:18 +0000] "-" 408 - "-" "-"
192.168.1.109 - - [01/May/2019:06:34:19 +0000] "-" 408 - "-" "-"
192.168.1.109 - - [01/May/2019:06:34:34 +0000] "GET /docs HTTP/1.1" 503 299 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"
192.168.1.109 - - [01/May/2019:06:35:07 +0000] "GET /docs HTTP/1.1" 503 299 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"
192.168.1.109 - - [01/May/2019:06:35:08 +0000] "GET /docs HTTP/1.1" 503 299 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"
192.168.1.109 - - [01/May/2019:06:35:09 +0000] "GET /docs HTTP/1.1" 503 299 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"
192.168.1.109 - - [01/May/2019:06:36:00 +0000] "-" 408 - "-" "-"
192.168.1.109 - - [01/May/2019:06:37:33 +0000] "GET /docs HTTP/1.1" 302 - "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"
192.168.1.109 - - [01/May/2019:06:37:33 +0000] "GET /docs/ HTTP/1.1" 304 - "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"
192.168.1.109 - - [01/May/2019:06:38:24 +0000] "-" 408 - "-" "-"
192.168.1.109 - - [01/May/2019:06:46:18 +0000] "GET / HTTP/1.1" 200 11197 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"
192.168.1.109 - - [01/May/2019:06:46:32 +0000] "GET /docs HTTP/1.1" 302 - "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"
192.168.1.109 - - [01/May/2019:06:46:39 +0000] "GET /docs/introduction.html HTTP/1.1" 200 15227 "http://192.168.1.109:8080/docs/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"
192.168.1.109 - - [01/May/2019:06:46:42 +0000] "GET /docs/jndi-resources-howto.html HTTP/1.1" 200 58181 "http://192.168.1.109:8080/docs/introduction.html" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"
192.168.1.109 - - [01/May/2019:06:46:43 +0000] "GET /docs/manager-howto.html HTTP/1.1" 200 80158 "http://192.168.1.109:8080/docs/jndi-resources-howto.html" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"
192.168.1.109 - - [01/May/2019:06:46:43 +0000] "GET /docs/jasper-howto.html HTTP/1.1" 200 26829 "http://192.168.1.109:8080/docs/manager-howto.html" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"
192.168.1.109 - - [01/May/2019:06:46:44 +0000] "GET /docs/mbeans-descriptors-howto.html HTTP/1.1" 200 10795 "http://192.168.1.109:8080/docs/jasper-howto.html" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"
192.168.1.109 - - [01/May/2019:06:47:30 +0000] "-" 408 - "-" "-"

Leave a Reply

Your email address will not be published. Required fields are marked *