😽

🎉何とかできた!CentOS 6の環境でtomcatのApp2Containerによる移行を試してみた

2022/03/25に公開・約14,600字

なんでやったの❓

すでに稼働しているあるシステムにて、AWSへ移設する相談案件があったため。

💻 やってみた

大きくは参考記事の下記にそって対応を実施

App2Containerでtomcat環境をコンテナ化してみた | DevelopersIO

まずはAWS CLIがないので、インストール進める。
aws-cliのインストール(CentOS6 / CentOS7) - Qiita

pyenvのインストールまでは上記でそのままいったが、pyenvでインストールしたバージョン表示にならない事象発生 💦

下記によると、pyenv init がパスまで設定しなくなったとか、、、同じ警告は出なかったけど、解消

pyenv global が効かなくなった(?)話 - サーバーワークスエンジニアブログ

次にdockerインストールする。各種の別ツールは未インストール

# 入ってるのか不明だったので、実行したけど不要でした
$ sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
No Match for argument: docker-client
No Match for argument: docker-client-latest
No Match for argument: docker-common
No Match for argument: docker-latest
No Match for argument: docker-latest-logrotate
No Match for argument: docker-logrotate
No Match for argument: docker-engine
No Packages marked for removal
$ sudo yum install -y yum-utils
$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

# なんかいくつかのリポジトリが動作してなくて、エラー吐くので、disableした
hoge-repo-XXX                   CentOs Linux hoge-repo 6.4 - x86_64                                   enabled:      0
hoge-repo-XXX-noarch            CentOs Linux hoge-repo 6 - noarch                                     enabled:      0
hoge-repo-XXX-src               CentOs Linux hoge-repo 6.4 - x86_64                                   enabled:      0
hoge-repo-test                  CentOs Linux hoge-repo 6.4 - x86_64                                   disabled
hoge-repo-test-src              CentOs Linux hoge-repo 6.4 - x86_64                                   disabled
hoge-repo-vendor                CentOs Linux hoge-repo 6.4 - x86_64

$ sudo yum-config-manager --disable hoge-repo-XXX
$ sudo yum-config-manager --disable hoge-repo-XXX-noarch
$ sudo yum-config-manager --disable hoge-repo-XXX-src

# また、Centos6だともうdockerリポジトリのURL先のファイルがないみたいでエラー履いてたので、dockerリポジトリもdisable
$ sudo yum-config-manager --disable docker-ce-stable

ここで止まりそうでしたが、諦めずに調べてみると・・・👀👀👀
ローカルインストールできるやつひっぱってきてインストール

CentOS6.10 に docker をインストールするまで (2021年版) - Qiita

こっからはrootユーザでやったみたい👀
# curl -o docker-engine-1.7.1-1.el6.x86_64.rpm \
  "https://get.docker.com/rpm/1.7.1/centos-6/RPMS/x86_64/docker-engine-1.7.1-1.el6.x86_64.rpm"

# yum localinstall -y "docker-engine-1.7.1-1.el6.x86_64.rpm"

# sudo service docker start

# sudo service docker status
docker (pid  18800) is running...

動いたー🎉🎉

次はApp2containerをインストール

ここはrootでなくても良さそう

$ curl -o AWSApp2Container-installer-linux.tar.gz https://app2container-release-us-east-1.s3.us-east-1.amazonaws.com/latest/linux/AWSApp2Container-installer-linux.tar.gz
$ sudo tar xvf AWSApp2Container-installer-linux.tar.gz
$ sudo ./install.sh

Setting up bash auto completion for the CLI...
/usr/local/app2container/.AWSApp2Container/v1.13/resources/post-install.sh: line 25: /usr/share/bash-completion/bash_completion: No such file or directory
Auto completion for the CLI setup failed. Silently continuing installation. Ensure "bash_completion" is installed via your preferred package manager for auto-completion features to work. Try either:

sudo yum install bash-completion
sudo apt-get install bash-completion

Or your preferred pkg managers install command. If installing the bash-completion feature, please rerun install.sh to enable completions.

Installation of AWS App2Container completed successfully!
You are currently running version 1.13.
To get started, run 'sudo app2container init'
AWS App2Container was installed under /usr/local/app2container/AWSApp2Container.


$ app2container -v
app2container version 1.13

$ sudo app2container init
Workspace directory path for artifacts[default: /root/app2container]:
AWS Profile (configured using 'aws configure --profile')[default: default]:
Failed

⚠️  AWS prerequisite check failed. Double check your ~/.aws/credentials and ~/.aws/config files to ensure your profile configuration is correct: failed to get account ID: Error getting AWS Account Id: failed to get caller identity: InvalidClientTokenId: The security token included in the request is invalid.
        status code: 403, request id: XXXXXXXXXXXXXX
Error: AWS prerequisite check failed. Double check your ~/.aws/credentials and ~/.aws/config files to ensure your profile configuration is correct: failed to get account ID: Error getting AWS Account Id: failed to get caller identity: InvalidClientTokenId: The security token included in the request is invalid.
        status code: 403, request id: XXXXXXXXXXXXXX

# 403エラーが出るので、aws-cliの認証を確認して各種キーを設定
$ aws config

$ sudo app2container init
Workspace directory path for artifacts[default: /root/app2container]:
AWS Profile (configured using 'aws configure --profile')[default: default]:
Optional S3 bucket for application artifacts:
Report usage metrics to AWS? (Y/N)[default: y]: y ←yesで回答
Automatically upload logs and App2Container generated artifacts on crashes and internal errors? (Y/N)[default: y]: ←yesで回答
Require images to be signed using Docker Content Trust (DCT)? (Y/N)[default: n]: ←yesで回答
Configuration saved
All application artifacts will be created under /root/app2container. Please ensure that the folder permissions are secure.

# ログのフォルダができあがるみたいです
$ ls -ah /root/app2container/
.  ..  log

# 移行元の分析を実行
$ sudo app2container inventory
{
                "java-generic-XXXXXX": {
                                "processId": XXXXXX,
                                "cmdline": "/usr/bin/java ... --conf-file /etc/flume/conf/flume.conf --name agent ",
                                "applicationType": "java-generic",
                                "webApp": ""
                },
                "java-tomcat-XXXXXX": {
                                "processId": XXXXXX,
                                "cmdline": "/usr/bin/java ... -Dcatalina.home=/opt/tomcat -Djava.io.tmpdir=/opt/tomcat/temp org.apache.catalina.startup.Bootstrap start ",
                                "applicationType": "java-tomcat",
                                "webApp": "XXXXXX"
                },
                "java-tomcat-XXXXXX": {
                                "processId": XXXXXX,
                                "cmdline": "/usr/bin/java ... -Dcatalina.home=/opt/tomcat -Djava.io.tmpdir=/opt/tomcat/temp org.apache.catalina.startup.Bootstrap start ",
                                "applicationType": "java-tomcat",
                                "webApp": "XXXXXX"
                },
                "java-tomcat-XXXXXX": {
                                "processId": XXXXXX,
                                "cmdline": "/usr/bin/java ... -Dcatalina.home=/opt/tomcat -Djava.io.tmpdir=/opt/tomcat/temp org.apache.catalina.startup.Bootstrap start ",
                                "applicationType": "java-tomcat",
                                "webApp": "XXXXXX"
                },
                "java-tomcat-XXXXXX": {
                                "processId": XXXXXX,
                                "cmdline": "/usr/bin/java ... -Dcatalina.home=/opt/tomcat -Djava.io.tmpdir=/opt/tomcat/temp org.apache.catalina.startup.Bootstrap start ",
                                "applicationType": "java-tomcat",
                                "webApp": "XXXXXX"
                }
}



$ sudo app2container analyze --application-id java-generic-XXXXXX
✔ Created artifacts folder /root/app2container/binary-generic-XXXXXX
✔ Generated dependency analysis data in /root/app2container/binary-generic-XXXXXX/analysis.json
✔ Created artifacts folder /root/app2container/binary-generic-XXXXXX
✔ Generated dependency analysis data in /root/app2container/binary-generic-XXXXXX/analysis.json
✔ Created artifacts folder /root/app2container/binary-generic-XXXXXX
✔ Generated dependency analysis data in /root/app2container/binary-generic-XXXXXX/analysis.json
✔ Created artifacts folder /root/app2container/binary-generic-XXXXXX
✔ Generated dependency analysis data in /root/app2container/binary-generic-XXXXXX/analysis.json
✔ Created artifacts folder /root/app2container/binary-generic-XXXXXX

â ´ Analyzing application java-generic-XXXXXX 2022/03/07 21:22:17 Unsolicited response received on idle HTTP channel starting with "<h1>404 Not Found</h1>No context found for request"; err=<nil>
✔ Created artifacts folder /root/app2container/java-generic-XXXXXX
✔ Generated analysis data in /root/app2container/java-generic-XXXXXX/analysis.json
👍 Analysis successful for application java-generic-XXXXXX

💡 Next Steps:
1. View the application analysis file at /root/app2container/java-generic-XXXXXX/analysis.json.
2. Edit the application analysis file as needed.
3. Start the containerization process using this command: app2container containerize --application-id java-generic-XXXXXX


java-tomcat-XXXXXX
java-tomcat-XXXXXX
java-tomcat-XXXXXX
java-tomcat-XXXXXX


$ app2container containerize --application-id java-tomcat-XXXXXX
✔ AWS prerequisite check succeeded
Failed Containerizing application java-tomcat-XXXXXX

# ❓❓❓❓❓
⚠️  Error: You must install Docker
Error: Error: You must install Docker

# 😭😭😭😭😭😭😭😭😭 Dockerはインストールして動いてるのに・・・
$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                    PORTS               NAMES
XXXXXX        hello-world         "/hello"            12 hours ago        Exited (0) 12 hours ago                       thirsty_davinci
XXXXXX        hello-world         "/hello"            12 hours ago        Exited (0) 12 hours ago                       happy_yonath


# なんか入っていないものがあるのかも❓と思ってインストールしてみたけど、ダメでした💦
$ sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

# とりあえずdockerの詳細情報取得して問合せしました
$ docker info
Containers: 2
Images: 2
Storage Driver: devicemapper
 Pool Name: docker-252:1-1187448-pool
 Pool Blocksize: 65.54 kB
 Backing Filesystem: extfs
 Data file: /dev/loop0
 Metadata file: /dev/loop1
 Data Space Used: 308.5 MB
 Data Space Total: 107.4 GB
 Data Space Available: 30.52 GB
 Metadata Space Used: 864.3 kB
 Metadata Space Total: 2.147 GB
 Metadata Space Available: 2.147 GB
 Udev Sync Supported: true
 Deferred Removal Enabled: false
 Data loop file: /var/lib/docker/devicemapper/devicemapper/data
 Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
 Library Version: 1.02.117-RHEL6 (2016-08-15)
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 2.6.32-642.6.1.el6.x86_64
Operating System: <unknown>
CPUs: 2
Total Memory: 4.924 GiB
Name: stg-XX-XXX-XXX01
ID: NPY6:DX4P:5LX2:NYR3:D5TF:7YUL:HQ2W:ZHZX:LI47:G74Y:SXLO:UU6V

結論

Dockerのバージョンが古いことが原因らしい。。。。ピエン😭😭😭

[1]【Release notes for AWS App2Container - AWS App2Container】

November 24, 2020	1.1
  ・Added an explicit check to validate use of Docker version 17.07 or above.

🎉あきらめずにCentOS7にアップデートして試してできました❗

その時の参考サイト全部貼る

Discussion

ログインするとコメントできます