読者です 読者をやめる 読者になる 読者になる

akiyoko blog

akiyoko の IT技術系ブログです

網元AMI を使ってハイパフォーマンス WordPress環境を構築

以前の記事「Ansible で CentOS 6.5 に WordPress + Nginx + PHP-FPM 環境をさくっと構築(Vagrantバージョン & さくらのVPSバージョン)」を書いたときに、プロダクション向けにさくっと WordPress 使うんだったら、網元AMI が一番楽じゃね?と思ったので、実際に触ってみることにしました。

使い方

網元AMIを起動します。

http://ja.megumi-cloud.com
から、「MARKET PLACE」をクリックします。
f:id:akiyoko:20140607111700p:plain

ここでは何もせず、「Continue」をクリックします。

f:id:akiyoko:20140607111712p:plain

AWS にログインしていなければ、ここでログインします。

f:id:akiyoko:20140607111720p:plain

1-Click Launch で以下を選択して、「Launch with 1-Click」ボタンをクリックします。
(EC2の料金は、$18.72 になるようです。)

Version 1.2(そのまま)
Region Asia Pacific (Tokyo)
EC2 Instance Type Standard Micro (t1.micro)
VPC Settings Will launch into EC2 Classic (no VPC)(デフォルト)
Security Group WordPress powered by AMIMOTO-1-2-AutogenByAWSMP-(ベンダー推奨のもの)
Key Pair 先に作っておいたものを指定

f:id:akiyoko:20140607111732p:plain
f:id:akiyoko:20140607111742p:plain

「Manage in AWS Console」ボタンをクリックして、EC2 のコンソール画面に移動します。

f:id:akiyoko:20140607111749p:plain
f:id:akiyoko:20140607111814p:plain


停止しても IPアドレスが変わらないように、Elastic IP を付けます。
「Elastic IP」から、「Allocate IP」ボタンをクリックします。

f:id:akiyoko:20140607111831p:plain

「Yes, Allocate」をクリック。

f:id:akiyoko:20140607111841p:plain

Elastic IP が作成できました。

f:id:akiyoko:20140607111853p:plain
f:id:akiyoko:20140607111902p:plain

作成した Elastic IP を右クリック -> 「Associate Address」を選択します。

f:id:akiyoko:20140607111920p:plain

網元AMI で立ち上げた EC2インスタンスインスタンス名を指定して、「Associate」をクリック。

f:id:akiyoko:20140607111932p:plain

Elastic IP が割り当てられました。

f:id:akiyoko:20140607111948p:plain


参考


 

スペック

網元AMI のスペックについては、公式ページでは以下のように公表されています。
http://ja.megumi-cloud.com/performance/

Root Device Type: ebs (Volume Capacity: 10GiB)
OS: Amazon Linux AMI release 2013.03
Web: Nginx 1.4
PHP: PHP 5.4 with APC
MySQL: Percona 5.5


実際にスペックを見てみました。

$ ssh -i ~/.ssh/aws_akiyoko.pem ec2-user@ec2-54-248-225-171.ap-northeast-1.compute.amazonaws.com
The authenticity of host 'ec2-54-248-225-171.ap-northeast-1.compute.amazonaws.com (54.248.225.171)' can't be established.
RSA key fingerprint is 2b:2d:dc:f3:9e:2d:fd:b2:c3:fa:fa:7f:c2:37:b2:df.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'ec2-54-248-225-171.ap-northeast-1.compute.amazonaws.com,54.248.225.171' (RSA) to the list of known hosts.
Last login: Thu Apr 10 11:56:46 2014 from 202.241.189.52.ap.gmobb-fix.jp
      ___         _            __
     / _ | __ _  (_)_ _  ___  / /____
    / __ |/  ' \/ /  ' \/ _ \/ __/ _ \
   /_/ |_/_/_/_/_/_/_/_/\___/\__/\___/


Amazon Linux AMI release 2014.03
    Nginx 1.4 + PHP 5.4 + Percona 5.5

  amimoto     http://ja.megumi-cloud.com/
  digitalcube http://www.digitalcube.jp/


$ cat /etc/system-release
Amazon Linux AMI release 2014.03
$ php -v
PHP 5.4.28 (cli) (built: May 20 2014 22:27:05)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
$ yum list installed | grep apc
php54-pecl-apc.x86_64                3.1.15-0.3.svn329913.14.amzn1 @amzn-main
$ mysql --version
mysql  Ver 14.14 Distrib 5.5.37-35.1, for Linux (x86_64) using readline 5.1
$ yum list installed | grep percona
Percona-Server-client-55.x86_64      5.5.37-rel35.1.el6            @percona
Percona-Server-server-55.x86_64      5.5.37-rel35.1.el6            @percona
Percona-Server-shared-55.x86_64      5.5.36-rel34.2.el6            @percona
Percona-Server-shared-compat.x86_64  5.5.33-rel31.1.566.rhel6      @percona
percona-release.x86_64               0.0-1                         installed
$ nginx -v
nginx version: nginx/1.4.7
$ httpd -v
Server version: Apache/2.4.9 (Amazon)
Server built:   Apr  1 2014 05:31:18

$ yum list installed | grep php
php-pear.noarch                      1:1.9.4-20.15.amzn1           @amzn-main
php54.x86_64                         5.4.28-1.54.amzn1             @amzn-updates
php54-cli.x86_64                     5.4.28-1.54.amzn1             @amzn-updates
php54-common.x86_64                  5.4.28-1.54.amzn1             @amzn-updates
php54-devel.x86_64                   5.4.28-1.54.amzn1             @amzn-updates
php54-fpm.x86_64                     5.4.28-1.54.amzn1             @amzn-updates
php54-gd.x86_64                      5.4.28-1.54.amzn1             @amzn-updates
php54-mbstring.x86_64                5.4.28-1.54.amzn1             @amzn-updates
php54-mcrypt.x86_64                  5.4.28-1.54.amzn1             @amzn-updates
php54-mysqlnd.x86_64                 5.4.28-1.54.amzn1             @amzn-updates
php54-pdo.x86_64                     5.4.28-1.54.amzn1             @amzn-updates
php54-pecl-apc.x86_64                3.1.15-0.3.svn329913.14.amzn1 @amzn-main
php54-pecl-memcache.x86_64           3.0.8-1.11.amzn1              @amzn-main
php54-process.x86_64                 5.4.28-1.54.amzn1             @amzn-updates
php54-xml.x86_64                     5.4.28-1.54.amzn1             @amzn-updates
$ yum list installed | grep mysql
php54-mysqlnd.x86_64                 5.4.28-1.54.amzn1             @amzn-updates
$ yum list installed | grep nginx
nginx.x86_64                         1:1.4.7-1.17.amzn1            @amzn-main
$ yum list installed | grep httpd
httpd24.x86_64                       2.4.9-1.55.amzn1              @amzn-updates
httpd24-tools.x86_64                 2.4.9-1.55.amzn1              @amzn-updates

 

PHP

/etc/php.ini

[PHP]
engine = On
short_open_tag = On
asp_tags = Off
precision = 14
y2k_compliance = On
output_buffering = 4096
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func =
serialize_precision = 100
allow_call_time_pass_reference = Off
safe_mode = Off
safe_mode_gid = Off
safe_mode_include_dir =
safe_mode_exec_dir =
safe_mode_allowed_env_vars = PHP_
safe_mode_protected_env_vars = LD_LIBRARY_PATH
disable_functions =
disable_classes =
zend.enable_gc = On
expose_php = Off
max_execution_time = 90
max_input_time = 60
memory_limit = 128M
error_reporting = E_ALL & ~E_DEPRECATED
display_errors = Off
display_startup_errors = Off
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
track_errors = Off
html_errors = Off
variables_order = "GPCS"
request_order = "GP"
register_globals = Off
register_long_arrays = Off
register_argc_argv = Off
auto_globals_jit = On
post_max_size = 8M
magic_quotes_gpc = Off
magic_quotes_runtime = Off
magic_quotes_sybase = Off
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
doc_root =
user_dir =
enable_dl = Off
file_uploads = On
upload_max_filesize = 4M
max_file_uploads = 20
allow_url_fopen = On
allow_url_include = Off
default_socket_timeout = 60

[Date]
date.timezone = "Asia/Tokyo"

[filter]

[iconv]

[intl]

[sqlite]

[sqlite3]

[Pcre]

[Pdo]

[Phar]

[Syslog]
define_syslog_variables  = Off

[mail function]
SMTP = localhost
smtp_port = 25
sendmail_path = /usr/sbin/sendmail -t -i
mail.add_x_header = On

[SQL]
sql.safe_mode = Off

[ODBC]
odbc.allow_persistent = On
odbc.check_persistent = On
odbc.max_persistent = -1
odbc.max_links = -1
odbc.defaultlrl = 4096
odbc.defaultbinmode = 1

[MySQL]
mysql.allow_persistent = On
mysql.max_persistent = -1
mysql.max_links = -1
mysql.default_port =
mysql.default_socket =
mysql.default_host =
mysql.default_user =
mysql.default_password =
mysql.connect_timeout = 60
mysql.trace_mode = Off

[MySQLi]
mysqli.max_links = -1
mysqli.default_port = 3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect = Off

[OCI8]

[PostgresSQL]
pgsql.allow_persistent = On
pgsql.auto_reset_persistent = Off
pgsql.max_persistent = -1
pgsql.max_links = -1
pgsql.ignore_notice = 0
pgsql.log_notice = 0

[Sybase-CT]
sybct.allow_persistent = On
sybct.max_persistent = -1
sybct.max_links = -1
sybct.min_server_severity = 10
sybct.min_client_severity = 10

[bcmath]
bcmath.scale = 0

[browscap]

[Session]
session.save_handler = files
session.save_path = "/var/tmp/php/session"
session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.bug_compat_42 = Off
session.bug_compat_warn = Off
session.referer_check =
session.entropy_length = 0
session.entropy_file =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_character = 5
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"

[MSSQL]
mssql.allow_persistent = On
mssql.max_persistent = -1
mssql.max_links = -1
mssql.min_error_severity = 10
mssql.min_message_severity = 10
mssql.compatability_mode = Off
mssql.secure_connection = Off

[Assertion]

[COM]

[mbstring]

[gd]

[exif]

[Tidy]
tidy.clean_output = Off

[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400

[sysvshm]


/etc/php.d/apc.ini

[APC]
extension = apc.so

apc.enabled=1
apc.shm_segments=1
apc.shm_size=64M
apc.num_files_hint=128
apc.user_entries_hint=8192
apc.ttl=0
apc.use_request_time=1
apc.user_ttl=7200
apc.gc_ttl=3600
apc.cache_by_default=1
apc.filters=.*\.phar
apc.mmap_file_mask=/dev/zero
apc.file_update_protection=2
apc.enable_cli=0
apc.max_file_size=1M
apc.stat=1
apc.stat_ctime=0
apc.canonicalize=0
apc.write_lock=1
apc.report_autofilter=0
apc.rfc1867=0
apc.rfc1867_prefix =upload_
apc.rfc1867_name=APC_UPLOAD_PROGRESS
apc.rfc1867_freq=0
apc.rfc1867_ttl=3600
apc.include_once_override=0
apc.lazy_classes=0
apc.lazy_functions=0
apc.coredump_unmap=0
apc.file_md5=0
apc.preload_path


 

nginx

$ nginx -V
nginx version: nginx/1.4.7
built by gcc 4.8.2 20131212 (Red Hat 4.8.2-7) (GCC)
TLS SNI support enabled
configure arguments:
 --prefix=/usr/share/nginx
 --sbin-path=/usr/sbin/nginx
 --conf-path=/etc/nginx/nginx.conf
 --error-log-path=/var/log/nginx/error.log
 --http-log-path=/var/log/nginx/access.log
 --http-client-body-temp-path=/var/lib/nginx/tmp/client_body
 --http-proxy-temp-path=/var/lib/nginx/tmp/proxy
 --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi
 --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi
 --http-scgi-temp-path=/var/lib/nginx/tmp/scgi
 --pid-path=/var/run/nginx.pid
 --lock-path=/var/lock/subsys/nginx
 --user=nginx
 --group=nginx
 --with-file-aio
 --with-ipv6
 --with-http_ssl_module
 --with-http_spdy_module
 --with-http_realip_module
 --with-http_addition_module
 --with-http_xslt_module
 --with-http_image_filter_module
 --with-http_geoip_module
 --with-http_sub_module
 --with-http_dav_module
 --with-http_flv_module
 --with-http_mp4_module
 --with-http_gunzip_module
 --with-http_gzip_static_module
 --with-http_random_index_module
 --with-http_secure_link_module
 --with-http_degradation_module
 --with-http_stub_status_module
 --with-http_perl_module
 --with-mail
 --with-mail_ssl_module
 --with-pcre
 --with-google_perftools_module
 --with-debug
 --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'
 --with-ld-opt=' -Wl,-E'


/etc/nginx/nginx.conf

user              nginx nginx;
worker_processes  2;
worker_rlimit_nofile 10240;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  8192;
    use epoll;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format main    '$remote_addr - $remote_user [$time_local] "$request" '
                       '$status $body_bytes_sent "$http_referer" '
                       '"$http_user_agent" "$http_x_forwarded_for"';
    log_format backend '$http_x_forwarded_for - $remote_user [$time_local] "$request" '
                       '$status $body_bytes_sent "$http_referer" '
                       '"$http_user_agent"';

    access_log  /var/log/nginx/access.log  main;

    server_name_in_redirect off;
    server_tokens      off;

    sendfile           on;
    tcp_nopush         off;

    keepalive_timeout  5;

    client_max_body_size    4M;
    client_body_buffer_size 256k;

    if_modified_since before;

    gzip              on;
    gzip_http_version 1.0;
    gzip_vary         on;
    gzip_comp_level   6;
    gzip_types        text/plain
                      text/xml
                      text/css
                      text/javascript
                      application/xhtml+xml
                      application/xml
                      application/rss+xml
                      application/atom_xml
                      application/javascript
                      application/x-javascript
                      application/x-httpd-php;
    gzip_disable      "MSIE [1-6]\.";

    # proxy cache
    proxy_cache_path  /var/cache/nginx/proxy_cache levels=1:2
                      keys_zone=czone:32m max_size=256m inactive=1440m;
    proxy_temp_path   /var/cache/nginx/proxy_temp;
    proxy_cache_key   "$scheme://$host$request_uri";
    proxy_set_header  Host               $host;
    proxy_set_header  X-Real-IP          $remote_addr;
    proxy_set_header  Remote-Addr        $remote_addr;
    proxy_set_header  X-Forwarded-Host   $host;
    proxy_set_header  X-Forwarded-Server $host;
    proxy_set_header  X-Forwarded-For    $proxy_add_x_forwarded_for;
    proxy_set_header  X-Forwarded-Proto  $scheme;
    proxy_set_header  X-UA-Detect        $mobile;
    proxy_set_header  Accept-Encoding    "";
    proxy_hide_header X-Pingback;
    proxy_hide_header Link;
    proxy_hide_header ETag;
    proxy_connect_timeout 5;
    proxy_send_timeout 10;
    proxy_read_timeout 90;
    proxy_cache_use_stale timeout invalid_header http_500 http_502 http_503 http_504;
    proxy_cache_lock on;
    proxy_cache_lock_timeout 5s;

    # fastcgi cache
    #fastcgi_cache_path /var/cache/nginx/fastcgi_cache levels=1:2
    #                   keys_zone=fastcgizone:32m inactive=60m;
    #fastcgi_cache_key "$scheme$request_method$host$request_uri";
    #fastcgi_cache_use_stale error timeout invalid_header http_500;

    #limit_req_zone $request_method zone=method:1m rate=250r/s;

    upstream backend {
        server unix:/var/run/nginx-backend.sock;
    }

    upstream phpfpm {
        server unix:/var/run/php-fpm.sock;
    }

    include /etc/nginx/conf.d/*.conf;
}

 

Percona MySQL

/etc/my.cnf

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
pid-file=/var/run/mysqld/mysqld.pid
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
character-set-server = utf8
skip-name-resolve
default-storage-engine=InnoDB

innodb_strict_mode
innodb_file_per_table
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size=64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 16
innodb_log_file_size=16M
innodb_flush_log_at_trx_commit = 2
innodb_flush_method=O_DIRECT
innodb_fast_shutdown = 0

query_cache_size=64M
query_cache_limit=2M
query_cache_min_res_unit=4k
query_cache_type=1

tmp_table_size=64M
max_heap_table_size=64M

table_open_cache=1024
max_allowed_packet=1M
sort_buffer=512K
read_buffer_size=256K
read_rnd_buffer_size=256K
join_buffer_size=256K
key_buffer_size=16M

max_connections=128
thread_cache=128

slow_query_log
slow_query_log_file=/var/log/mysqld-slow.log
long_query_time=1

log-error=/var/log/mysqld.log

wait_timeout=60

[mysqld_safe]
log-error=/var/log/mysqld.log

 

WordPress インストール

WordPress のインストールをしていきます。
ブラウザから割り当てた Elastic IP にアクセスして、サイトの設定をしていきます。

f:id:akiyoko:20140607112304p:plain

f:id:akiyoko:20140607112320p:plain

f:id:akiyoko:20140607112337p:plain

無事に完了。

ダッシュボードを見てみると、WordPress のバージョンは 3.9.1 でした。


インストール後、Percona MySQL を見てみます。
EC2インスタンス名で、データベースとユーザが作成されているようです。
rootユーザでも接続できますね。

$ mysql -u root

mysql> select Host, User from mysql.user;
+-------------------+------------------+
| Host              | User             |
+-------------------+------------------+
| 127.0.0.1         | root             |
| ::1               | root             |
| ip-10-133-144-179 |                  |
| ip-10-133-144-179 | root             |
| localhost         |                  |
| localhost         | root             |
| localhost         | wp_4501d71352007 |
| localhost         | wp_a67c6d8235aa7 |
| localhost         | wp_a984f1b1b2f3c |
| localhost         | wp_f4445d94eb14b |
| localhost         | wp_fea47db4ba3a4 |
+-------------------+------------------+
11 rows in set (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| i_f2df8af4         |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.02 sec)

mysql> connect i_f2df8af4;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Connection id:    14
Current database: i_f2df8af4

mysql> show tables;
+-----------------------+
| Tables_in_i_f2df8af4  |
+-----------------------+
| wp_commentmeta        |
| wp_comments           |
| wp_links              |
| wp_options            |
| wp_postmeta           |
| wp_posts              |
| wp_term_relationships |
| wp_term_taxonomy      |
| wp_terms              |
| wp_usermeta           |
| wp_users              |
+-----------------------+
11 rows in set (0.00 sec)


最初から入っているプラグインはこんな感じでした。
有効化はされていないので、用途に合わせて有効化しましょう。

f:id:akiyoko:20140608123922p:plain



ちなみに、(stop→startしたりして)EC2インスタンスIPアドレスが変わってしまった場合には、wp_optionsテーブルの値を書き換えてあげれば接続できるようになると思います(たぶん)。まあ、その手間がないように Elastic IP を付けた方がいいとは思いますが。

mysql> select * from wp_options where option_value like '%54.248.225.171%';
+-----------+-------------+-----------------------+----------+
| option_id | option_name | option_value          | autoload |
+-----------+-------------+-----------------------+----------+
|         1 | siteurl     | http://54.248.225.171 | yes      |
|        33 | home        | http://54.248.225.171 | yes      |
+-----------+-------------+-----------------------+----------+
2 rows in set (0.00 sec)



 

WordPress

WordPressの本体は、
/var/www/vhosts/i-f2df8af4/
にあるようです。
こちらも、EC2インスタンス名でディレクトリが切られています。

$ ls -al /var/www/vhosts/i-f2df8af4/
合計 200
drwxr-xr-x  5 nginx nginx  4096  6月  7 09:12 .
drwxr-xr-x  3 nginx nginx  4096  6月  7 09:09 ..
-rw-r--r--  1 nginx nginx   418  9月 25  2013 index.php
-rw-r--r--  1 nginx nginx 19930  4月 10 08:50 license.txt
-rw-r--r--  1 nginx nginx  3293  5月  9 10:31 readme-ja.html
-rw-r--r--  1 nginx nginx 10165  5月  9 10:31 readme.html
-rw-r--r--  1 nginx nginx  4896 12月 25 03:57 wp-activate.php
drwxr-xr-x  9 nginx nginx  4096  5月  9 10:31 wp-admin
-rw-r--r--  1 nginx nginx   271  1月  9  2012 wp-blog-header.php
-rw-r--r--  1 nginx nginx  4818  2月 19 06:45 wp-comments-post.php
-rw-r--r--  1 nginx nginx  4255  5月  9 10:31 wp-config-sample.php
-rw-r--r--  1 nginx nginx  4881  6月  7 09:11 wp-config.php
drwxr-xr-x  6 nginx nginx  4096  6月  7 09:12 wp-content
-rw-r--r--  1 nginx nginx  2932  9月 25  2013 wp-cron.php
drwxr-xr-x 12 nginx nginx  4096  5月  9 10:31 wp-includes
-rw-r--r--  1 nginx nginx  2380 10月 25  2013 wp-links-opml.php
-rw-r--r--  1 nginx nginx  2359 10月 25  2013 wp-load.php
-rw-r--r--  1 nginx nginx 32671  4月 14 01:06 wp-login.php
-rw-r--r--  1 nginx nginx  8235 11月 13  2013 wp-mail.php
-rw-r--r--  1 nginx nginx 11070  4月  8 05:15 wp-settings.php
-rw-r--r--  1 nginx nginx 25665 11月 13  2013 wp-signup.php
-rw-r--r--  1 nginx nginx  4026 10月 25  2013 wp-trackback.php
-rw-r--r--  1 nginx nginx  3032  2月 10 05:39 xmlrpc.php

 

まとめ

網元AMI を使うと、超簡単に WordPress環境が構築できます。
これでハイパフォーマンスが保証されているとなると、安心してプロダクション利用ができますね。

料金は、一番安い ti.micro を使ったとして、いろいろ含めて一ヶ月で 2,000〜2,500円くらいでしょうか。レンタルサーバだと500円くらいで借りれるところもあるので、これを高いとみるか安いとみるかは、あなた次第です。