Skip to content

Commit fb41c35

Browse files
author
mosuke5
authored
update wordpress example (#16)
* update wordpress example
1 parent f75dcdc commit fb41c35

File tree

4 files changed

+64
-75
lines changed

4 files changed

+64
-75
lines changed

wordpress_sample/README.md

Lines changed: 35 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,58 @@
1-
# ベーシックWordPress構築サンプル
2-
## 概要
3-
ECSとRDSを利用したベーシックなWordPress環境のサンプル。
4-
![wordpress](/image/architecture_wordpress_sample.png)
1+
# WordPress example
2+
This is the example of building wordpress with ECS and RDS.
3+
4+
1. Create VPC
5+
1. Create Vswitch
6+
1. Create Security Group and set some rules
7+
1. Create an ECS instance in Vswitch
8+
1. Create EIP and bind it to ECS instance
9+
1. Create a RDS instance in Vswitch and create database, db user
10+
1. Set ECS private ip address to RDS white list
11+
12+
## How to use
13+
You can build wordpress by following process. But if you want to operate wordpress in production, you need to configure more.
514

6-
## 利用方法
7-
基本的に下記の方法で実行可能です。
815
```
9-
// 事前準備
10-
$ cd wordpress_sample // 実行したいサンプルへ移動
1116
$ cp terraform.tfvars.sample terraform.tfvars
1217
$ vim terraform.tfvars
13-
-> API KEYや公開鍵など必要情報更新
14-
15-
// Dry-Run
16-
$ terraform plan -var-file="terraform.tfvars"
18+
=> Edit variables with your favorite editor.
1719
18-
// クラウドへ反映
19-
$ terraform apply -var-file="terraform.tfvars"
20-
(略)
21-
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
20+
// Deploy to Alibaba Cloud
21+
$ terraform apply
22+
...
23+
Apply complete! Resources: 12 added, 0 changed, 0 destroyed.
2224
23-
// 出力にRDSへの接続アドレスとEIPのアドレスが表示されます
2425
Outputs:
2526
rds_connection_string = xxxxxxxxx.rds.aliyuncs.com
2627
wordpress_eip = xx.xx.xx.xx
28+
```
2729

28-
// ECSへ接続
30+
```
31+
// Connect to ECS instance with ssh
2932
$ ssh ecs-user@xx.xx.xx.xx
3033
31-
// WordPressの設定
34+
// Configure wordpress
3235
$ cd /var/www/html/wordpress
3336
$ sudo cp wp-config-sample.php wp-config.php
3437
$ sudo vim wp-config.php
35-
/** WordPress のためのデータベース名 */
3638
define('DB_NAME', 'database_name_here');
37-
38-
/** MySQL データベースのユーザー名 */
3939
define('DB_USER', 'username_here');
40-
41-
/** MySQL データベースのパスワード */
4240
define('DB_PASSWORD', 'password_here');
43-
44-
/** MySQL のホスト名 */
4541
define('DB_HOST', 'localhost');
46-
47-
48-
define('AUTH_KEY', 'put your unique phrase here');
49-
define('SECURE_AUTH_KEY', 'put your unique phrase here');
50-
define('LOGGED_IN_KEY', 'put your unique phrase here');
51-
define('NONCE_KEY', 'put your unique phrase here');
52-
define('AUTH_SALT', 'put your unique phrase here');
53-
define('SECURE_AUTH_SALT', 'put your unique phrase here');
54-
define('LOGGED_IN_SALT', 'put your unique phrase here');
55-
define('NONCE_SALT', 'put your unique phrase here');
5642
```
5743

58-
## 利用開始
59-
設定が完了したらブラウザから接続してみよう。
44+
After deploy and configuration to `wp-config.php`, let's access to your eip address.
45+
You will find wordpress installation screen.
46+
6047
`http://<your eip address>/wordpress`
6148

62-
## ECSへのセットアップ内容
63-
ECSへは下記の設定が行われます。
64-
- Apacheのインストール
65-
- PHPのインストール
66-
- WordPressソースコードの配置
67-
- `ecs-user`の作成
68-
- `ecs-user`のsudoersへの追加
69-
- terraform.tfvarsで指定した公開鍵の配置
70-
- sshdはパスワード認証、rootログインの禁止
49+
## Provisioning to ECS
50+
ECS will be provisioned for following settings by Ansible.
51+
52+
- Install Apache
53+
- Install PHP
54+
- Deploy WordPress source code
55+
- Create `ecs-user`
56+
- Add `ecs-user` to sudoers
57+
- Add your public key to `/home/ecs-user/.ssh/authorized_keys`
58+
- Disable password authentication and root account login

wordpress_sample/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ output "wordpress_eip" {
33
}
44

55
output "rds_connection_string" {
6-
value = "${alicloud_db_instance.rds.connections.0.connection_string}"
6+
value = "${alicloud_db_instance.db.connection_string}"
77
}

wordpress_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.zip"
66
user_name: "ecs-user"
77
tasks:
88
- name: be sure httpd is installed

wordpress_sample/terraform.tf

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,17 @@ variable "database_user_password" {}
88
variable "database_name" {}
99
variable "database_character" {}
1010

11-
# Alicloud Providerの設定
1211
provider "alicloud" {
1312
access_key = "${var.access_key}"
1413
secret_key = "${var.secret_key}"
1514
region = "${var.region}"
1615
}
1716

18-
# セキュリティグループの作成
1917
resource "alicloud_security_group" "sg" {
2018
name = "terraform-sg"
2119
vpc_id = "${alicloud_vpc.vpc.id}"
2220
}
2321

24-
# セキュリティグループのルール設定
2522
resource "alicloud_security_group_rule" "allow_http" {
2623
type = "ingress"
2724
ip_protocol = "tcp"
@@ -44,59 +41,63 @@ resource "alicloud_security_group_rule" "allow_ssh" {
4441
cidr_ip = "0.0.0.0/0"
4542
}
4643

47-
# VPCの作成
4844
resource "alicloud_vpc" "vpc" {
4945
name = "terraform-vpc"
50-
cidr_block = "192.168.0.0/16"
46+
cidr_block = "192.168.1.0/24"
5147
}
5248

53-
# vswitchの作成。VPCの中に作ります。
5449
resource "alicloud_vswitch" "vsw" {
5550
vpc_id = "${alicloud_vpc.vpc.id}"
56-
cidr_block = "192.168.1.0/24"
51+
cidr_block = "192.168.1.0/28"
5752
availability_zone = "${var.zone}"
5853
}
5954

60-
# ECSに紐付けるEIP(グローバルIP)の作成
6155
resource "alicloud_eip" "eip" {
6256
internet_charge_type = "PayByTraffic"
6357
}
6458

65-
# 作成したEIPをECSと紐付けします
6659
resource "alicloud_eip_association" "eip_asso" {
6760
allocation_id = "${alicloud_eip.eip.id}"
6861
instance_id = "${alicloud_instance.web.id}"
6962
}
7063

71-
# ECSの作成
7264
resource "alicloud_instance" "web" {
7365
instance_name = "terraform-ecs"
7466
host_name = "wordpress-ecs"
7567
availability_zone = "${var.zone}"
7668
image_id = "centos_7_3_64_40G_base_20170322.vhd"
7769
instance_type = "ecs.n4.small"
78-
io_optimized = "optimized"
7970
system_disk_category = "cloud_efficiency"
8071
security_groups = ["${alicloud_security_group.sg.id}"]
8172
vswitch_id = "${alicloud_vswitch.vsw.id}"
8273
user_data = "#!/bin/bash\necho \"${var.publickey}\" > /tmp/publickey\n${file("provisioning.sh")}"
8374
}
8475

85-
resource "alicloud_db_instance" "rds" {
86-
engine = "MySQL"
87-
engine_version = "5.6"
88-
db_instance_class = "rds.mysql.t1.small"
89-
db_instance_storage = "10"
90-
db_instance_net_type = "Intranet"
91-
vswitch_id = "${alicloud_vswitch.vsw.id}"
92-
security_ips = ["${alicloud_instance.web.private_ip}"]
76+
resource "alicloud_db_instance" "db" {
77+
engine = "MySQL"
78+
engine_version = "5.6"
79+
instance_name = "terraform-rds"
80+
vswitch_id = "${alicloud_vswitch.vsw.id}"
81+
security_ips = ["${alicloud_instance.web.private_ip}"]
82+
instance_type = "rds.mysql.t1.small"
83+
instance_storage = "50"
84+
}
85+
86+
resource "alicloud_db_account" "default" {
87+
instance_id = "${alicloud_db_instance.db.id}"
88+
name = "${var.database_user_name}"
89+
password = "${var.database_user_password}"
90+
}
9391

94-
master_user_name = "${var.database_user_name}"
95-
master_user_password = "${var.database_user_password}"
92+
resource "alicloud_db_account_privilege" "default" {
93+
instance_id = "${alicloud_db_instance.db.id}"
94+
account_name = "${alicloud_db_account.default.name}"
95+
privilege = "ReadWrite"
96+
db_names = ["${alicloud_db_database.default.name}"]
97+
}
9698

97-
db_mappings = [{
98-
db_name = "${var.database_name}"
99-
character_set_name = "${var.database_character}"
100-
db_description = "terraform wordpress"
101-
}]
99+
resource "alicloud_db_database" "default" {
100+
instance_id = "${alicloud_db_instance.db.id}"
101+
name = "${var.database_name}"
102+
character_set = "${var.database_character}"
102103
}

0 commit comments

Comments
 (0)