LoginSignup
3
4

More than 5 years have passed since last update.

SoftLayerの無料ベアメタルでOpenStackの学習をする(7) - 第6章「シンプルな3階層構造アプリケーションのデプロイ」

Last updated at Posted at 2015-03-24

前回はこちら - 次回はこちら


これはなに

「OpenStackクラウドインテグレーション オープンソースクラウドによるサービス構築入門」の実習をSoftLayerの無料ベアメタルで行う記録である。
OpenStackクラウドインテグレーション オープンソースクラウドによるサービス構築入門

第6章 シンプルな3階層構造アプリケーションのデプロイ

この章ではgitに用意されている3層のSNSアプリをOpenStackにデプロイする。

第5章から第10章までの支援ファイルはこちら。まとめてgitでダウンロードできる。
https://github.com/josug-book1-materials/chapter05-10

第6章の支援ファイルはこちらである。
https://github.com/josug-book1-materials/chapter05-10/tree/master/06

前回と同様に第6章のすべてのステップをまとめて行うスクリプトも用意されている。
https://github.com/josug-book1-materials/chapter05-10/blob/master/06/build_chap06.sh

さすがに勉強にならないので、今回もステップ・バイ・ステップで確認しながら進める。

6.1 作業前の注意

今回の作業は踏み台サーバーで行うので、踏み台にログインして「source ooenrc」で環境変数をセットして、支援ファイルをgitしておくように、という注意である。


[root@step-server ~]# cd
[root@step-server ~]# source openrc
[root@step-server ~]# git clone https://github.com/josug-book1-materials/chapter05-10.git

6.2 セキュリティグループとキーペアの作成

(6)の5.4 作業用ネットワークと踏み台サーバーの準備では踏み台サーバーにSSHログインするセキュリティグループとキーペアを作成した。
ここでは、下記を下記を作成する。

  1. 各サーバー間の通信を許可するセキュリティグループ
  2. 踏み台サーバーから各インスタンスへの接続を許可するセキュリティグループ
  3. 踏み台サーバーから各インスタンスへssh接続するキーペア

6.2.1 セキュリティグループの作成

書籍ではセキュリティグループの作成をまとめて行ってセキュリティグループルールを作成しているが、セキュリティグループの作成毎にセキュリティグループルールを作成する。

外部ネットからWebサーバーに適用されるsg-web-from-internetの作成。0.0.0.0/0からhttp(80)/https(443)の接続を許可する。


[root@step-server ~]# neutron security-group-create sg-web-from-internet
Created a new security_group:
+----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field                | Value                                                                                                                                                                                                                                                                                                                         |
+----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| description          |                                                                                                                                                                                                                                                                                                                               |
| id                   | f9bbc1ca-2b47-46e0-a9b7-6f42bc0d57f6                                                                                                                                                                                                                                                                                          |
| name                 | sg-web-from-internet                                                                                                                                                                                                                                                                                                          |
| security_group_rules | {"remote_group_id": null, "direction": "egress", "remote_ip_prefix": null, "protocol": null, "tenant_id": "106e169743964758bcad1f06cc69c472", "port_range_max": null, "security_group_id": "f9bbc1ca-2b47-46e0-a9b7-6f42bc0d57f6", "port_range_min": null, "ethertype": "IPv4", "id": "09d6443a-1c45-4355-bbf3-7aa375850509"} |
|                      | {"remote_group_id": null, "direction": "egress", "remote_ip_prefix": null, "protocol": null, "tenant_id": "106e169743964758bcad1f06cc69c472", "port_range_max": null, "security_group_id": "f9bbc1ca-2b47-46e0-a9b7-6f42bc0d57f6", "port_range_min": null, "ethertype": "IPv6", "id": "cc608154-3187-442f-9179-0c5fa373b7c3"} |
| tenant_id            | 106e169743964758bcad1f06cc69c472                                                                                                                                                                                                                                                                                              |
+----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

[root@step-server ~]# neutron security-group-rule-create --ethertype IPv4 --protocol tcp \
> --port-range-min 80 --port-range-max 80 \
> --remote-ip-prefix 0.0.0.0/0 sg-web-from-internet
+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| direction         | ingress                              |
| ethertype         | IPv4                                 |
| id                | 59d404e5-ea71-4c19-9ac8-826e65b67689 |
| port_range_max    | 80                                   |
| port_range_min    | 80                                   |
| protocol          | tcp                                  |
| remote_group_id   |                                      |
| remote_ip_prefix  | 0.0.0.0/0                            |
| security_group_id | f9bbc1ca-2b47-46e0-a9b7-6f42bc0d57f6 |
| tenant_id         | 106e169743964758bcad1f06cc69c472     |
+-------------------+--------------------------------------+
[root@step-server ~]# neutron security-group-rule-create --ethertype IPv4 --protocol tcp \
> --port-range-min 443 --port-range-max 443 \
> --remote-ip-prefix 0.0.0.0/0 sg-web-from-internet
Created a new security_group_rule:
+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| direction         | ingress                              |
| ethertype         | IPv4                                 |
| id                | af37ddd2-311e-4e36-8e83-dfd2752793d3 |
| port_range_max    | 443                                  |
| port_range_min    | 443                                  |
| protocol          | tcp                                  |
| remote_group_id   |                                      |
| remote_ip_prefix  | 0.0.0.0/0                            |
| security_group_id | f9bbc1ca-2b47-46e0-a9b7-6f42bc0d57f6 |
| tenant_id         | 106e169743964758bcad1f06cc69c472     |
+-------------------+--------------------------------------+

Webサーバー-Appサーバーに適用されるsg-all-from-app-netの作成。172.16.10.0/24からの接続であれば、すべてのポートの接続とicmp(ping)の接続を許可する。

[root@step-server ~]# neutron security-group-create sg-all-from-app-net
Created a new security_group:
+----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field                | Value                                                                                                                                                                                                                                                                                                                         |
+----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| description          |                                                                                                                                                                                                                                                                                                                               |
| id                   | ddb0a170-99b3-4409-bd4c-1dab987f0fc9                                                                                                                                                                                                                                                                                          |
| name                 | sg-all-from-app-net                                                                                                                                                                                                                                                                                                           |
| security_group_rules | {"remote_group_id": null, "direction": "egress", "remote_ip_prefix": null, "protocol": null, "tenant_id": "106e169743964758bcad1f06cc69c472", "port_range_max": null, "security_group_id": "ddb0a170-99b3-4409-bd4c-1dab987f0fc9", "port_range_min": null, "ethertype": "IPv4", "id": "eb46aec3-df4e-438a-bd43-6e3b5da6fc02"} |
|                      | {"remote_group_id": null, "direction": "egress", "remote_ip_prefix": null, "protocol": null, "tenant_id": "106e169743964758bcad1f06cc69c472", "port_range_max": null, "security_group_id": "ddb0a170-99b3-4409-bd4c-1dab987f0fc9", "port_range_min": null, "ethertype": "IPv6", "id": "bc112a1b-56f1-4241-b54b-edbcb9dfab12"} |
| tenant_id            | 106e169743964758bcad1f06cc69c472                                                                                                                                                                                                                                                                                              |
+----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

[root@step-server ~]# neutron security-group-rule-create --ethertype IPv4 --protocol tcp \
> --port-range-min 1 --port-range-max 65535 \
> --remote-ip-prefix 172.16.10.0/24 sg-all-from-app-net
Created a new security_group_rule:
+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| direction         | ingress                              |
| ethertype         | IPv4                                 |
| id                | b12167aa-dc78-4edf-ae63-4f5314bb8c00 |
| port_range_max    | 65535                                |
| port_range_min    | 1                                    |
| protocol          | tcp                                  |
| remote_group_id   |                                      |
| remote_ip_prefix  | 172.16.10.0/24                       |
| security_group_id | ddb0a170-99b3-4409-bd4c-1dab987f0fc9 |
| tenant_id         | 106e169743964758bcad1f06cc69c472     |
+-------------------+--------------------------------------+

[root@step-server ~]# neutron security-group-rule-create --ethertype IPv4 --protocol icmp \
> --remote-ip-prefix 172.16.10.0/24 sg-all-from-app-net
Created a new security_group_rule:
+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| direction         | ingress                              |
| ethertype         | IPv4                                 |
| id                | 15c86252-2b68-4ead-a010-63b795cffe9f |
| port_range_max    |                                      |
| port_range_min    |                                      |
| protocol          | icmp                                 |
| remote_group_id   |                                      |
| remote_ip_prefix  | 172.16.10.0/24                       |
| security_group_id | ddb0a170-99b3-4409-bd4c-1dab987f0fc9 |
| tenant_id         | 106e169743964758bcad1f06cc69c472     |
+-------------------+--------------------------------------+

Appサーバー-DBサーバーに適用されるsg-all-from-dbs-netの作成。172.16.20.0/24からの接続であれば、すべてのポートの接続とicmp(ping)の接続を許可する。


[root@step-server ~]# neutron security-group-create sg-all-from-dbs-net
Created a new security_group:
+----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field                | Value                                                                                                                                                                                                                                                                                                                         |
+----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| description          |                                                                                                                                                                                                                                                                                                                               |
| id                   | 686e2f26-9e3e-4217-b305-3c184a20d227                                                                                                                                                                                                                                                                                          |
| name                 | sg-all-from-dbs-net                                                                                                                                                                                                                                                                                                           |
| security_group_rules | {"remote_group_id": null, "direction": "egress", "remote_ip_prefix": null, "protocol": null, "tenant_id": "106e169743964758bcad1f06cc69c472", "port_range_max": null, "security_group_id": "686e2f26-9e3e-4217-b305-3c184a20d227", "port_range_min": null, "ethertype": "IPv4", "id": "efefcdb1-2879-41a0-83dd-b8ee11a91ba0"} |
|                      | {"remote_group_id": null, "direction": "egress", "remote_ip_prefix": null, "protocol": null, "tenant_id": "106e169743964758bcad1f06cc69c472", "port_range_max": null, "security_group_id": "686e2f26-9e3e-4217-b305-3c184a20d227", "port_range_min": null, "ethertype": "IPv6", "id": "9efd3a4c-bc13-4b3f-b518-8fc4717087ed"} |
| tenant_id            | 106e169743964758bcad1f06cc69c472                                                                                                                                                                                                                                                                                              |
+----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

[root@step-server ~]# neutron security-group-rule-create --ethertype IPv4 --protocol tcp \
> --port-range-min 1 --port-range-max 65535 \
> --remote-ip-prefix 172.16.20.0/24 sg-all-from-dbs-net
Created a new security_group_rule:
+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| direction         | ingress                              |
| ethertype         | IPv4                                 |
| id                | d942bab9-4ee4-42d4-8a05-c11ce8728797 |
| port_range_max    | 65535                                |
| port_range_min    | 1                                    |
| protocol          | tcp                                  |
| remote_group_id   |                                      |
| remote_ip_prefix  | 172.16.20.0/24                       |
| security_group_id | 686e2f26-9e3e-4217-b305-3c184a20d227 |
| tenant_id         | 106e169743964758bcad1f06cc69c472     |
+-------------------+--------------------------------------+

[root@step-server ~]# neutron security-group-rule-create --ethertype IPv4 --protocol icmp \
> --remote-ip-prefix 172.16.20.0/24 sg-all-from-dbs-net
Created a new security_group_rule:
+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| direction         | ingress                              |
| ethertype         | IPv4                                 |
| id                | b004df8f-6b46-4347-9eac-910f91929e17 |
| port_range_max    |                                      |
| port_range_min    |                                      |
| protocol          | icmp                                 |
| remote_group_id   |                                      |
| remote_ip_prefix  | 172.16.20.0/24                       |
| security_group_id | 686e2f26-9e3e-4217-b305-3c184a20d227 |
| tenant_id         | 106e169743964758bcad1f06cc69c472     |
+-------------------+--------------------------------------+

踏み台サーバーから、Web、App、DBサーバーへの接続へ適用されるsg-all-from-consoleの作成。10.0.0.0/24からの接続であれば、すべてのポートの接続とicmp(ping)の接続を許可する。


[root@step-server ~]# neutron security-group-create sg-all-from-console
Created a new security_group:
+----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field                | Value                                                                                                                                                                                                                                                                                                                         |
+----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| description          |                                                                                                                                                                                                                                                                                                                               |
| id                   | 95618f13-e85e-4634-828c-540d756f9523                                                                                                                                                                                                                                                                                          |
| name                 | sg-all-from-console                                                                                                                                                                                                                                                                                                           |
| security_group_rules | {"remote_group_id": null, "direction": "egress", "remote_ip_prefix": null, "protocol": null, "tenant_id": "106e169743964758bcad1f06cc69c472", "port_range_max": null, "security_group_id": "95618f13-e85e-4634-828c-540d756f9523", "port_range_min": null, "ethertype": "IPv4", "id": "c4f73837-afca-47b5-8311-86546985c97e"} |
|                      | {"remote_group_id": null, "direction": "egress", "remote_ip_prefix": null, "protocol": null, "tenant_id": "106e169743964758bcad1f06cc69c472", "port_range_max": null, "security_group_id": "95618f13-e85e-4634-828c-540d756f9523", "port_range_min": null, "ethertype": "IPv6", "id": "b2b5490d-84bd-41cd-8d71-4d418bd1f19f"} |
| tenant_id            | 106e169743964758bcad1f06cc69c472                                                                                                                                                                                                                                                                                              |
+----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+


[root@step-server ~]# neutron security-group-rule-create --ethertype IPv4 --protocol tcp \
> --port-range-min 1 --port-range-max 65535 \
> --remote-ip-prefix 10.0.0.0/24 sg-all-from-console
Created a new security_group_rule:
+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| direction         | ingress                              |
| ethertype         | IPv4                                 |
| id                | 10f4c1c0-cccb-4a14-8dbd-f649462a6486 |
| port_range_max    | 65535                                |
| port_range_min    | 1                                    |
| protocol          | tcp                                  |
| remote_group_id   |                                      |
| remote_ip_prefix  | 10.0.0.0/24                          |
| security_group_id | 95618f13-e85e-4634-828c-540d756f9523 |
| tenant_id         | 106e169743964758bcad1f06cc69c472     |
+-------------------+--------------------------------------+

[root@step-server ~]# neutron security-group-rule-create --ethertype IPv4 --protocol icmp \
> --remote-ip-prefix 10.0.0.0/24 sg-all-from-console
Created a new security_group_rule:
+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| direction         | ingress                              |
| ethertype         | IPv4                                 |
| id                | 484fa4ec-21ca-47ef-91a0-016df7551f76 |
| port_range_max    |                                      |
| port_range_min    |                                      |
| protocol          | icmp                                 |
| remote_group_id   |                                      |
| remote_ip_prefix  | 10.0.0.0/24                          |
| security_group_id | 95618f13-e85e-4634-828c-540d756f9523 |
| tenant_id         | 106e169743964758bcad1f06cc69c472     |
+-------------------+--------------------------------------+

6.2.2 キーペアの作成

踏み台サーバーから、アプリケーション用のインタンスに接続するSSH作成し権限の変更をする。


[root@step-server ~]# nova keypair-add key-for-internal | tee key-for-internal.pem
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAoC5dt0ryTvxlmVOODSuTLoR5JgehXBRtjUA6Smt4rHwlBRxp
YPReargPgN52SJY4gGD2BE39DSuX+sky9IB9BF9bc7aVvVD/MUYKDJUijbRwFS7j
~~~~~~~~~~
sUketT8yXb6sYbxsAtaRnIjEjdZWECYNrHsEXJCrE7Mdu4fjlsLL73jD48Dz7oIe
P1P8GWWEKT2NhCCEz1dH2wNAbCw25lMfotNwmCjKCmkLaU7vjhhnpg==
-----END RSA PRIVATE KEY-----

[root@step-server ~]# chmod 600 key-for-internal.pem

作成した秘密キーをホスト区画にもコピーしておく。この作業はホスト区画から行う。


user01@test:~$ scp -i key-for-step-server.pem root@192.168.100.131:~/key-for-internal.pem ~/
key-for-internal.pem                                          100% 1680     1.6KB/s   00:00

6.3 仮想マシンインスタンスの起動とアプリケーションのデプロイ

6.3.1 userdataファイルの作成

仮想マシンのuserdataを用意する。各々の内容はこちら・gitからアプリをcloneして各々の役割用のセットアップスクリプトを実行する・

6.3.2 環境変数の設定

ネットワークのUUIDを名前から取得して環境変数に保管する。


[root@step-server ~]# function get_uuid () { cat - | grep " id " | awk '{print $4}'; }
[root@step-server ~]# export MY_DMZ_NET=neutron net-show dmz-net | get_uuid
[root@step-server ~]# export MY_APP_NET=neutron net-show app-net | get_uuid
[root@step-server ~]# export MY_DBS_NET=neutron net-show dbs-net | get_uuid
[root@step-server ~]# env |grep MY_
MY_DBS_NET=ec886dac-29bf-404a-8464-736c948e7c2a
MY_APP_NET=7d3828af-2da1-4e10-a904-f9e03b28e181
MY_DMZ_NET=35e4baac-7230-4232-9644-856874dfe8af

6.3.3 仮想マシンインスタンスの起動

作成済みのuserdataで仮想マシンインスタンスを起動する。

まずwebサーバー。


user01@test:~/chapter05-10/06$ nova boot --flavor standard.xsmall --image "centos-base" \
> --key-name key-for-internal --user-data userdata_web.txt \
> --security-groups sg-all-from-console,sg-web-from-internet,sg-all-from-app-net \
> --availability-zone az1 \
> --nic net-id=${MY_DMZ_NET} --nic net-id=${MY_APP_NET} \
> web01
+--------------------------------------+----------------------------------------------------------------+
| Property                             | Value                                                          |
+--------------------------------------+----------------------------------------------------------------+
| OS-DCF:diskConfig                    | MANUAL                                                         |
| OS-EXT-AZ:availability_zone          | nova                                                           |
| OS-EXT-STS:power_state               | 0                                                              |
| OS-EXT-STS:task_state                | scheduling                                                     |
| OS-EXT-STS:vm_state                  | building                                                       |
| OS-SRV-USG:launched_at               | -                                                              |
| OS-SRV-USG:terminated_at             | -                                                              |
| accessIPv4                           |                                                                |
| accessIPv6                           |                                                                |
| adminPass                            | J3byEEVYosrf                                                   |
| config_drive                         |                                                                |
| created                              | 2015-03-24T02:32:10Z                                           |
| flavor                               | standard.xsmall (100)                                          |
| hostId                               |                                                                |
| id                                   | ca755522-3eb2-475a-8e37-7fe23398b1d9                           |
| image                                | centos-base (098f948e-e80b-4b1a-8a46-f8d2dd57e149)             |
| key_name                             | key-for-internal                                               |
| metadata                             | {}                                                             |
| name                                 | web01                                                          |
| os-extended-volumes:volumes_attached | []                                                             |
| progress                             | 0                                                              |
| security_groups                      | sg-all-from-console, sg-web-from-internet, sg-all-from-app-net |
| status                               | BUILD                                                          |
| tenant_id                            | 106e169743964758bcad1f06cc69c472                               |
| updated                              | 2015-03-24T02:32:10Z                                           |
| user_id                              | 98dd78b670884b64b879568215777c53                               |
+--------------------------------------+----------------------------------------------------------------+

次にappサーバー。


user01@test:~/chapter05-10/06$ nova boot --flavor standard.xsmall --image "centos-base" \
> --key-name key-for-internal --user-data userdata_app.txt \
> --security-groups sg-all-from-console,sg-all-from-app-net,sg-all-from-dbs-net \
> --availability-zone az1 \
> --nic net-id=${MY_DMZ_NET} --nic net-id=${MY_APP_NET} --nic net-id=${MY_DBS_NET} \
> app01
+--------------------------------------+---------------------------------------------------------------+
| Property                             | Value                                                         |
+--------------------------------------+---------------------------------------------------------------+
| OS-DCF:diskConfig                    | MANUAL                                                        |
| OS-EXT-AZ:availability_zone          | nova                                                          |
| OS-EXT-STS:power_state               | 0                                                             |
| OS-EXT-STS:task_state                | scheduling                                                    |
| OS-EXT-STS:vm_state                  | building                                                      |
| OS-SRV-USG:launched_at               | -                                                             |
| OS-SRV-USG:terminated_at             | -                                                             |
| accessIPv4                           |                                                               |
| accessIPv6                           |                                                               |
| adminPass                            | vR5Usr6SiieH                                                  |
| config_drive                         |                                                               |
| created                              | 2015-03-24T02:33:34Z                                          |
| flavor                               | standard.xsmall (100)                                         |
| hostId                               |                                                               |
| id                                   | 35d338e5-6e8a-4cee-9be1-9a37b431bf38                          |
| image                                | centos-base (098f948e-e80b-4b1a-8a46-f8d2dd57e149)            |
| key_name                             | key-for-internal                                              |
| metadata                             | {}                                                            |
| name                                 | app01                                                         |
| os-extended-volumes:volumes_attached | []                                                            |
| progress                             | 0                                                             |
| security_groups                      | sg-all-from-console, sg-all-from-app-net, sg-all-from-dbs-net |
| status                               | BUILD                                                         |
| tenant_id                            | 106e169743964758bcad1f06cc69c472                              |
| updated                              | 2015-03-24T02:33:34Z                                          |
| user_id                              | 98dd78b670884b64b879568215777c53                              |
+--------------------------------------+---------------------------------------------------------------+

最後dbにサーバー。


user01@test:~/chapter05-10/06$ nova boot --flavor standard.xsmall --image "centos-base" \
> --key-name key-for-internal --user-data userdata_dbs.txt \
> --security-groups sg-all-from-console,sg-all-from-dbs-net \
> --availability-zone az1 \
> --nic net-id=${MY_DMZ_NET} --nic net-id=${MY_DBS_NET} \
> dbs01
+--------------------------------------+----------------------------------------------------+
| Property                             | Value                                              |
+--------------------------------------+----------------------------------------------------+
| OS-DCF:diskConfig                    | MANUAL                                             |
| OS-EXT-AZ:availability_zone          | nova                                               |
| OS-EXT-STS:power_state               | 0                                                  |
| OS-EXT-STS:task_state                | scheduling                                         |
| OS-EXT-STS:vm_state                  | building                                           |
| OS-SRV-USG:launched_at               | -                                                  |
| OS-SRV-USG:terminated_at             | -                                                  |
| accessIPv4                           |                                                    |
| accessIPv6                           |                                                    |
| adminPass                            | CKvxdXLA6d8a                                       |
| config_drive                         |                                                    |
| created                              | 2015-03-24T02:37:15Z                               |
| flavor                               | standard.xsmall (100)                              |
| hostId                               |                                                    |
| id                                   | edf1b599-de4f-4b2c-be90-17ab1252728f               |
| image                                | centos-base (098f948e-e80b-4b1a-8a46-f8d2dd57e149) |
| key_name                             | key-for-internal                                   |
| metadata                             | {}                                                 |
| name                                 | dbs01                                              |
| os-extended-volumes:volumes_attached | []                                                 |
| progress                             | 0                                                  |
| security_groups                      | sg-all-from-console, sg-all-from-dbs-net           |
| status                               | BUILD                                              |
| tenant_id                            | 106e169743964758bcad1f06cc69c472                   |
| updated                              | 2015-03-24T02:37:15Z                               |
| user_id                              | 98dd78b670884b64b879568215777c53                   |
+--------------------------------------+----------------------------------------------------+

こんな感じで起動してきた。


user01@test:~/chapter05-10/06$ nova list
+--------------------------------------+-------------+--------+------------+-------------+---------------------------------------------------------------+
| ID                                   | Name        | Status | Task State | Power State | Networks                                                      |
+--------------------------------------+-------------+--------+------------+-------------+---------------------------------------------------------------+
| 35d338e5-6e8a-4cee-9be1-9a37b431bf38 | app01       | ACTIVE | -          | Running     | dmz-net=192.168.0.3; app-net=172.16.10.3; dbs-net=172.16.20.1 |
| edf1b599-de4f-4b2c-be90-17ab1252728f | dbs01       | ACTIVE | -          | Running     | dmz-net=192.168.0.4; dbs-net=172.16.20.3                      |
| 65d3400d-3467-4563-9ff5-9c0e30c7157e | step-server | ACTIVE | -          | Running     | work-net=10.0.0.1, 192.168.100.131                            |
| ca755522-3eb2-475a-8e37-7fe23398b1d9 | web01       | ACTIVE | -          | Running     | dmz-net=192.168.0.1; app-net=172.16.10.1                      |
+--------------------------------------+-------------+--------+------------+-------------+---------------------------------------------------------------+

ダッシュボードからの確認も書籍と同様。問題が無いようだ。

ネットワークトポロジー

6.4 アプリケーションの設定

設定方法はこちらで確認できる。
具体的には、WebサーバーとAppサーバーのendpoint.confに指定されているIPを今回の環境のものに変更する。

6.4.1 APPサーバーの設定

appサーバーに接続する。
app01には「dmz-net=192.168.0.3」が割り振られたので、下記でログオンする。


[root@step-server ~]# ssh -i key-for-internal.pem root@192.168.0.3
[root@app01 ~]#

App→DBの参照が出来るようにdb_hostのアドレスを設定する。dbs01には「dbs-net=172.16.20.3」が割り振られている。


[root@app01 ~]# cat /root/sample-app/endpoint.conf
[rest-server]
rest_host = 127.0.0.1
rest_endpoint = http://%(rest_host)s:5555/bbs

[db-server]
db_host = 172.16.20.3
db_endpoint = mysql://user:password@%(db_host)s/sample_bbs?charset=utf8

アプリケーションを起動して接続を確認したらログアウトする。


[root@app01 ~]# sh /root/sample-app/server-setup/rest.init.sh start
Starting rest.py                                           [  OK  ]
[root@app01 ~]# curl http://127.0.0.1:5555/bbs
{}
[root@app01 ~]# exit
logout
Connection to 192.168.0.3 closed.

6.4.2 WEBサーバー

webサーバーに接続する。
web01には「dmz-net=192.168.0.1」が割り振られたので、下記でログオンする。


[root@step-server ~]# ssh -i key-for-internal.pem root@192.168.0.1
[root@web01 ~]#

Web→Appの参照が出来るようにrest_hostのアドレスを設定する。app01には「app-net=172.16.10.3」が割り振られている。


[root@web01 ~]# cat /root/sample-app/endpoint.conf
[rest-server]
rest_host = 172.16.10.3
rest_endpoint = http://%(rest_host)s:5555/bbs

[db-server]
db_host = localhost
db_endpoint = mysql://user:password@%(db_host)s/sample_bbs?charset=utf8

アプリケーションを起動して接続を確認したらログアウトする。

[root@web01 ~]# sh /root/sample-app/server-setup/web.init.sh start
Starting web.py                                            [  OK  ]
[root@web01 ~]# curl http://127.0.0.1/
<!doctype html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title></title>
  </head>
  <body>
    <form method="POST" action="/">
      <label for="text">Please write something and hit enter</label> <input id="text" name="text" type="text" value="">
    </form>
    <br/>
  </body>
</html>
[root@web01 ~]# exit
logout
Connection to 192.168.0.1 closed.

6.5 アプリケーションのリリース

外部を見立てたExt-NetからFloting IPを取得し、web01にアサインする。


[root@step-server ~]# nova floating-ip-create Ext-Net
+-----------------+-----------+----------+---------+
| Ip              | Server Id | Fixed Ip | Pool    |
+-----------------+-----------+----------+---------+
| 192.168.100.133 |           | -        | Ext-Net |
+-----------------+-----------+----------+---------+
[root@step-server ~]# nova floating-ip-associate web01 192.168.100.133

ホスト区画に戻りnginxのReverse Proxyの設定をする。

/etc/nginx/conf.dに今回はweb01.confという名前で下記を作成する。ポート1080にアクセスするとweb01に転送される。Basic認証の設定はダッシュボード用に作ったものをそのまま利用する。

server {
  listen 1080;
  server_name [Public IP];
  location /  {
    auth_basic "Input ID/PASS";
    auth_basic_user_file /etc/nginx/.htpasswd;
    proxy_pass http://192.168.100.133/;
  }
}

nginxを再起動する。

user01@test:/etc/nginx/conf.d$ sudo service nginx restart
 * Restarting nginx nginx                                                                    [ OK ]

指定したポート1080にアクセスする。Basic認証の後に、アプリケーションの稼動が確認できた。

アプリケーションの確認


第6章が完了した。


前回はこちら - 次回はこちら

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4