Merge pull request #438 feature-NEWDWH2021-1699 into release-v4.7.0
This commit is contained in:
commit
6051b77709
62
ec2/README.md
Normal file
62
ec2/README.md
Normal file
@ -0,0 +1,62 @@
|
||||
# EC2インスタンス管理資材
|
||||
|
||||
## NLBゲートウェイ インスタンス 起動スクリプト
|
||||
|
||||
### 目的
|
||||
|
||||
Merck様のDB接続経路としてのNLBから、Auroraデータベースに踏み台アクセスを行うため、ゲートウェイの機能を提供するEC2インスタンスを稼働している。
|
||||
EC2インスタンス内では、NLBからの任意のポートをAuroraデータベースのポートにフォワーディングするために、`socat`プロセスを動かす必要がある。
|
||||
`socat`プロセスを動かすためのコマンドと、EC2インスタンス起動時にプロセスを実行するためのsystemdの設定を配置している。
|
||||
|
||||
### フォルダ構成
|
||||
|
||||
```txt
|
||||
.
|
||||
├── README.md -- 当ファイル
|
||||
└── gateway
|
||||
├── staging -- ステージング環境用設定
|
||||
│ ├── public1-1 -- ap-northeast-1aのインスタンス要設定
|
||||
│ │ ├── socat-dbconnection-1a.service -- systemdにsocatプロセスを登録するためのファイル
|
||||
│ │ └── socat-portforwarding-1a.sh -- socatでAuroraデータベースにポートフォワーディングするためのシェルスクリプト
|
||||
│ └── public2-1 -- ap-northeast-1dのインスタンス要設定
|
||||
│ ├── socat-dbconnection-1d.service
|
||||
│ └── socat-portforwarding-1d.sh
|
||||
│
|
||||
├── product -- 本番環境用設定
|
||||
│ ├── public1-1
|
||||
│ │ ├── socat-dbconnection-1a.service
|
||||
│ │ └── socat-portforwarding-1a.sh
|
||||
│ └── public2-1
|
||||
│ ├── socat-dbconnection-1d.service
|
||||
│ └── socat-portforwarding-1d.sh
|
||||
```
|
||||
|
||||
### ファイル配置方法(両環境共通)
|
||||
|
||||
- 対象のゲートウェイEC2インスタンスにログインする
|
||||
- セッションマネージャーでログインした場合は、`ec2-user`に切り替えること(`sudo su --login ec2-user`)
|
||||
- 以下の操作を実行し、`socat`プロセスを起動するシェルスクリプトを配置する。
|
||||
- **ap-northeast-1aのインスタンス(public-1-1)の場合**
|
||||
- `sudo vi /opt/socat-portforwarding-1a.sh`コマンドを実行する。
|
||||
- `ec2/gateway/<環境名>/public-1-1/socat-portforwarding-1a.sh`の内容をコピペして保存する。
|
||||
- `sudo chmod 774 /opt/socat-portforwarding-1a.sh`コマンドを実行する。
|
||||
- **ap-northeast-1dのインスタンス(public-2-1)の場合**
|
||||
- `sudo vi /opt/socat-portforwarding-1d.sh`コマンドを実行する。
|
||||
- `ec2/gateway/<環境名>/public-2-1/socat-portforwarding-1d.sh`の内容をコピペして保存する。
|
||||
- `sudo chmod 774 /opt/socat-portforwarding-1d.sh`コマンドを実行する。
|
||||
- 以下の操作を実行し、`socat`プロセスを常駐させるためのサービス設定ファイルを配置する。
|
||||
- **ap-northeast-1aのインスタンス(public-1-1)の場合**
|
||||
- `sudo vi /etc/systemd/system/socat-dbconnection-1a.service`コマンドを実行する。
|
||||
- `ec2/gateway/<環境名>/public-1-1/socat-dbconnection-1a.service`の内容をコピペして保存する。
|
||||
- `sudo chmod 774 /etc/systemd/system/socat-dbconnection-1a.service`コマンドを実行する。
|
||||
- **ap-northeast-1dのインスタンス(public-2-1)の場合**
|
||||
- `sudo vi /etc/systemd/system/socat-dbconnection-1d.service`コマンドを実行する。
|
||||
- `ec2/gateway/<環境名>/public-2-1/socat-dbconnection-1d.service`の内容をコピペして保存する。
|
||||
- `sudo chmod 774 /etc/systemd/system/socat-dbconnection-1d.service`コマンドを実行する。
|
||||
- 以下の操作を実行し、`socat`プロセスを起動するスクリプトをsystemdに登録する
|
||||
- **ap-northeast-1aのインスタンス(public-1-1)の場合**
|
||||
- `sudo systemctl enable socat-dbconnection-1a.service`コマンドを実行し、サービスを有効化する。
|
||||
- `sudo systemctl status socat-dbconnection-1a.service`コマンドを実行し、サービスのステータスを確認する。`enabled;`となっていればOK
|
||||
- **ap-northeast-1dのインスタンス(public-2-1)の場合**
|
||||
- `sudo systemctl enable socat-dbconnection-1d.service`コマンドを実行し、サービスを有効化する。
|
||||
- `sudo systemctl status socat-dbconnection-1d.service`コマンドを実行し、サービスのステータスを確認する。`enabled;`となっていればOK
|
||||
10
ec2/gateway/product/public1-1/socat-dbconnection-1a.service
Normal file
10
ec2/gateway/product/public1-1/socat-dbconnection-1a.service
Normal file
@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description = socat-dbconnection-1a
|
||||
|
||||
[Service]
|
||||
ExecStart = /opt/socat-portforwarding-1a.sh
|
||||
Type = oneshot
|
||||
RemainAfterExit = yes
|
||||
|
||||
[Install]
|
||||
WantedBy = default.target
|
||||
3
ec2/gateway/product/public1-1/socat-portforwarding-1a.sh
Normal file
3
ec2/gateway/product/public1-1/socat-portforwarding-1a.sh
Normal file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
socat tcp4-listen:40001,reuseaddr,fork TCP:mbj-newdwh2021-product-dbcluster-instance-1.chs11qsgoyix.ap-northeast-1.rds.amazonaws.com:3306 &
|
||||
socat tcp4-listen:50001,reuseaddr,fork TCP:mbj-newdwh2021-product-dbcluster.cluster-chs11qsgoyix.ap-northeast-1.rds.amazonaws.com:3306 &
|
||||
10
ec2/gateway/product/public2-1/socat-dbconnection-1d.service
Normal file
10
ec2/gateway/product/public2-1/socat-dbconnection-1d.service
Normal file
@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description = socat-dbconnection-1d
|
||||
|
||||
[Service]
|
||||
ExecStart = /opt/socat-portforwarding-1d.sh
|
||||
Type = oneshot
|
||||
RemainAfterExit = yes
|
||||
|
||||
[Install]
|
||||
WantedBy = default.target
|
||||
3
ec2/gateway/product/public2-1/socat-portforwarding-1d.sh
Normal file
3
ec2/gateway/product/public2-1/socat-portforwarding-1d.sh
Normal file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
socat tcp4-listen:40001,reuseaddr,fork TCP:mbj-newdwh2021-product-dbcluster-instance-1-ap-northeast-1d.chs11qsgoyix.ap-northeast-1.rds.amazonaws.com:3306 &
|
||||
socat tcp4-listen:50001,reuseaddr,fork TCP:mbj-newdwh2021-product-dbcluster.cluster-chs11qsgoyix.ap-northeast-1.rds.amazonaws.com:3306 &
|
||||
@ -1,5 +1,5 @@
|
||||
[Unit]
|
||||
Description = socat_dbconnection-1a
|
||||
Description = socat-dbconnection-1a
|
||||
|
||||
[Service]
|
||||
ExecStart = /opt/socat-portforwarding-1a.sh
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
[Unit]
|
||||
Description = socat_dbconnection-1d
|
||||
Description = socat-dbconnection-1d
|
||||
|
||||
[Service]
|
||||
ExecStart = /opt/socat-portforwarding-1d.sh
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user