Skip to content

Commit 834197a

Browse files
committed
Merge branch 'master' of github.com:mosuke5/terraform_for_alibabacloud_examples
2 parents b39b90e + 7cab505 commit 834197a

File tree

11 files changed

+181
-195
lines changed

11 files changed

+181
-195
lines changed

mongo_cluster_sample/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
# マルチゾーンをわたるMongoDBクラスタを構築サンプル
1+
# MongoDB cluster example
2+
This is the repository to build multi-az MongoDb cluster.
3+
24
![mongo](/image/architecture_mongo_cluster.png)
35

4-
このサンプルを実行するためには、各ゾーンのサブネット (vswitch作成)CIDRの設定とmongoインスタンススペックの設定
5-
が必要です。そして、システムを管理するために、`mongoadmin`ユーザーが作成されます。`mongoadmin`ユーザーへログイン
6-
するためには、各プロビジョンスクリプト (`provision_mongo.sh`及び`provision_snat.sh`)に、`mongoadmin`ユーザーの
7-
公開鍵と秘密鍵を設定する必要があります。
6+
You need to configure subnet(vswitch) and CIDR, mongodb instance spec.
7+
Provisioning scripts(`provision_mongo.sh` and `provision_snat.sh`) will provision `mongoadmin` user. In order to manage MongoDB, you can login as `mongodadmin` user. So, you need to configure your publickey and privatekey to `terraform.tfvars`.
88

9+
Following is example of `terraform.tfvars`.
910
```
1011
secret_key = ""
1112
access_key = ""
@@ -19,4 +20,4 @@ natgw_cidr = "10.0.128.0/20"
1920
mongo_primary_cidr = "10.0.0.0/19"
2021
mongo_secondary0_cidr = "10.0.32.0/19"
2122
mongo_secondary1_cidr = "10.0.64.0/19"
22-
```
23+
```

wordpress_advanced_sample/README.md

Lines changed: 54 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,76 @@
1-
# Advanced WordPress構築サンプル
2-
## 概要
3-
実践的なWordPress環境のサンプル
4-
![wordpress](/image/architecture_wordpress_advanced_sample.png)
1+
# Advanced WordPress Example
2+
This is the example of building high available wordpress with SLB and ECS, RDS and so on. Architecture overview is [here](https://docs.google.com/presentation/d/1pqtbiJRGc3uUm8ulhMBf4SWm2WPCCrhgUInjm9DMYdc/edit?ts=5b1df94f#slide=id.g3bf33c5b60_0_77).
53

6-
- SLBの構築
7-
- リスナーの設定
8-
- バックエンドサーバの設定
9-
- ECS(WordPress用)の構築
10-
- ECS(踏み台用)の構築
11-
- NATサーバとしての設定
12-
- VRouterのルーティングテーブルへの追加
13-
- RDSの構築
14-
- VPCの構築
4+
1. Create VPC
5+
1. Create Vswitch
6+
1. Create Security Group and set some rules
7+
1. Create two ECS instances for wordpress application in Vswitch
8+
1. Create one ECS instance for bastion server in Vswitch
9+
1. Create EIP and bind it to bastion ECS instance
10+
1. Create NAT Gateway and add it to route table of VRouter
11+
1. Create a RDS instance in Vswitch and create database, db user
12+
1. Set ECS private ip address to RDS white list
13+
14+
## How to use
15+
You can build wordpress by following process. But if you want to operate wordpress in production environment, you need to configure more.
1516

16-
## 利用方法
17-
基本的に下記の方法で実行可能です。
1817
```
19-
// 事前準備
20-
$ cd wordpress_advanced_sample // 実行したいサンプルへ移動
2118
$ cp terraform.tfvars.sample terraform.tfvars
2219
$ vim terraform.tfvars
23-
-> API KEYや公開鍵など必要情報更新
24-
25-
// Dry-Run
26-
$ terraform plan -var-file="terraform.tfvars"
20+
=> Edit variables with your favorite editor.
2721
28-
// クラウドへ反映
29-
$ terraform apply -var-file="terraform.tfvars"
30-
(略)
31-
Apply complete! Resources: x added, 0 changed, 0 destroyed.
22+
// Deploy to Alibaba Cloud
23+
$ terraform apply
24+
...
25+
Apply complete! Resources: 26 added, 0 changed, 0 destroyed.
3226
33-
// 出力にRDSへの接続アドレスや踏み台のEIPのアドレスなどが表示されます
3427
Outputs:
35-
ecs_private_ip = 192.168.1.xx,192.168.1.xx
36-
fumidai_eip = xx.xx.xx.xx
37-
slb_ip = yy.yy.yy.yy
38-
rds_connection_string = xxxxxxxxx.rds.aliyuncs.com
3928
40-
// 踏み台ECSへ接続
41-
$ ssh ecs-user@xx.xx.xx.xx
29+
bastion_eip = <bastion_ip>
30+
ecs_private_ip = <wordpress_private_ip_1>,<wordpress_private_ip_2>
31+
rds_connection_string = <rds_connection_address>
32+
slb_ip = <slb_ip>
33+
```
4234

43-
// WordPress ECSへ接続
44-
$ ssh root@192.168.1.xx
35+
```
36+
// Connect to bastion ECS instance
37+
$ ssh ecs-user@<bastion_ip>
4538
46-
// WordPress ECSの設定
47-
$ wget https://raw.githubusercontent.com/mosuke5/terraform_for_alibabacloud_examples/master/wordpress_advanced_sample/provisioning_wordpress.sh
48-
$ sh provisioning_wordpress.sh
49-
/* このスクリプトで下記を行います
50-
- ecs-userの作成(パスワードはデフォルトではTest1234)
51-
- php, apacheのインストール
52-
- wordpressの配置
53-
- sshの設定(rootログイン禁止)
54-
*/
39+
// Then connect to wordpress ECS instance
40+
// You need to do this process two times, because you have two wordpress servers.
41+
$ ssh ecs-user@<wordpress_private_ip_1/2>
42+
-> Default ecs-user password is "Test1234"
5543
56-
// WordPressの設定
44+
// Configure wordpress
5745
$ cd /var/www/html/wordpress
5846
$ sudo cp wp-config-sample.php wp-config.php
5947
$ sudo vim wp-config.php
60-
/** WordPress のためのデータベース名 */
6148
define('DB_NAME', 'database_name_here');
62-
63-
/** MySQL データベースのユーザー名 */
6449
define('DB_USER', 'username_here');
65-
66-
/** MySQL データベースのパスワード */
6750
define('DB_PASSWORD', 'password_here');
68-
69-
/** MySQL のホスト名 */
7051
define('DB_HOST', 'localhost');
52+
```
7153

54+
After deploy and configuration to `wp-config.php`, let's access to your slb ip address.
55+
You will find wordpress installation screen.
7256

73-
define('AUTH_KEY', 'put your unique phrase here');
74-
define('SECURE_AUTH_KEY', 'put your unique phrase here');
75-
define('LOGGED_IN_KEY', 'put your unique phrase here');
76-
define('NONCE_KEY', 'put your unique phrase here');
77-
define('AUTH_SALT', 'put your unique phrase here');
78-
define('SECURE_AUTH_SALT', 'put your unique phrase here');
79-
define('LOGGED_IN_SALT', 'put your unique phrase here');
80-
define('NONCE_SALT', 'put your unique phrase here');
81-
```
57+
`http://<your slb ip address>/wordpress`
58+
59+
## Provisioning to ECS for wordpress
60+
Wordpress ECS will be provisioned to following settings by Ansible.
61+
62+
- Install Apache
63+
- Install PHP
64+
- Deploy WordPress source code
65+
- Create `ecs-user`
66+
- Add `ecs-user` to sudoers
67+
- Add your public key to `/home/ecs-user/.ssh/authorized_keys`
68+
- Disable root account login
69+
70+
## Provisioning to ECS for bastion
71+
Bastion ECS will be provisioned to following settings by Ansible.
8272

83-
## 利用開始
84-
設定が完了したらブラウザから接続してみよう。
85-
`http://<your slb address>/wordpress`
73+
- Create `ecs-user`
74+
- Add `ecs-user` to sudoers
75+
- Add your public key to `/home/ecs-user/.ssh/authorized_keys`
76+
- Disable password authentication and root account login

wordpress_advanced_sample/outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ output "slb_ip" {
22
value = "${alicloud_slb.slb.address}"
33
}
44

5-
output "fumidai_eip" {
5+
output "bastion_eip" {
66
value = "${alicloud_eip.eip.ip_address}"
77
}
88

@@ -11,5 +11,5 @@ output "ecs_private_ip" {
1111
}
1212

1313
output "rds_connection_string" {
14-
value = "${alicloud_db_instance.rds.connections.0.connection_string}"
14+
value = "${alicloud_db_instance.db.connection_string}"
1515
}

wordpress_advanced_sample/playbook.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
- hosts: 127.0.0.1
33
connection: local
44
vars:
5-
wordpress_url: "https://ja.wordpress.org/wordpress-4.8-ja.tar.gz"
5+
wordpress_url: "https://wordpress.org/wordpress-4.9.6.tar.gz"
66
user_name: "ecs-user"
77
tasks:
88
- name: be sure httpd is installed

wordpress_advanced_sample/playbook_fumidai.yml renamed to wordpress_advanced_sample/playbook_bastion.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
- hosts: 127.0.0.1
33
connection: local
44
vars:
5-
wordpress_url: "https://ja.wordpress.org/wordpress-4.8-ja.tar.gz"
65
user_name: "ecs-user"
76
tasks:
87
- name: create general user
@@ -35,9 +34,4 @@
3534
line='PasswordAuthentication no'
3635
3736
- name: restart sshd
38-
service: name=sshd state=restarted
39-
40-
- name: be sure iptables is installed
41-
yum: name="{{ item }}" state=latest
42-
with_items:
43-
- iptables
37+
service: name=sshd state=restarted
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
yum install -y wget epel
2+
yum install -y ansible
3+
cd /root
4+
wget https://raw.githubusercontent.com/mosuke5/terraform_examples_for_alibabacloud/master/wordpress_advanced_sample/playbook_bastion.yml -O playbook.yml
5+
ansible-playbook playbook.yml

wordpress_advanced_sample/provisioning_fumidai.sh

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)