Word press on conoha このべん #3
-
Upload
wataru-okamoto -
Category
Technology
-
view
2.247 -
download
1
description
Transcript of Word press on conoha このべん #3
Nginx, Percona, PHP, WordPress
WordPress on ConoHa
14年4月15日火曜日
OKAMOTOWataru
@wokamoto14年4月15日火曜日
14年4月15日火曜日
WordPress Template
14年4月15日火曜日
* WordPress について* Nginx とは?* Nginx Reverse Proxy Cache の紹介* MySQL チューニングの勘所* monit によるプロセス監視* WordPress Template の紹介* wp-cli の紹介* VM Image 作成に使用しているツール
Menu for Today
14年4月15日火曜日
WordPress
WordPress について
14年4月15日火曜日
WordPress ?
* OSS のブログ/CMSプラットフォーム
* トラフィック量上位100万サイトでのシェア60%
14年4月15日火曜日
WordPress ?
14年4月15日火曜日
WordPress ?
14年4月15日火曜日
Nginx
Nginx とは?
14年4月15日火曜日
Nginx ?
* OSS の軽量 HTTP サーバ
* スレッドモデルでは無く、イベントループモデルを採用
* トラフィック量上位100万サイトでのシェア20%
14年4月15日火曜日
Nginx ?
14年4月15日火曜日
Nginx ?
14年4月15日火曜日
WordPres.com でも採用$ wget -‐S -‐-‐spider http://wordpress.comwordpress.com|66.155.11.243|:80 に接続しています... 接続しました。HTTP による接続要求を送信しました、応答を待っています... HTTP/1.1 200 OK Server: nginx Date: Tue, 15 Apr 2014 05:58:07 GMT Content-‐Type: text/html; charset=utf-‐8 Connection: keep-‐alive Vary: Accept-‐Encoding X-‐Frame-‐Options: SAMEORIGIN Vary: Cookie Set-‐Cookie: wordpress_homepage=existing; expires=Wed, 30-‐Apr-‐2014 05:58:07 GMT
Nginx ?
14年4月15日火曜日
PHP は fast-CGI でApache の mod_php のように Web サーバと同一プロセスで php を動作させることはできません。
php-fpm などを使って別プロセスで動作させる必要があります。
Nginx ?
14年4月15日火曜日
Nginx + php-fpm
14年4月15日火曜日
nginx.conf の例server { listen 80 default; server_name _; root /path/to/app; index index.php index.html index.htm; charset utf-‐8;
location ~ \.php$ { fastcgi_pass unix:/var/run/php-‐fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }}
Nginx + php-fpm
14年4月15日火曜日
php-fpm.conf の例[www]listen = /var/run/php-‐fpm.socklisten.owner = nginxlisten.group = nginxlisten.mode = 0666
user = nginxgroup = nginx
pm = dynamicpm.max_children = 15pm.start_servers = 5pm.min_spare_servers = 5pm.max_spare_servers = 7
Nginx + php-fpm
14年4月15日火曜日
NginxPerformance
Nginx Reverse Proxy Cache の紹介
14年4月15日火曜日
Nginx PerformanceApache, mod_php, WordPress
14年4月15日火曜日
ab -n 100 -c 10 (WordPress トップページ)
* Requests per second: 4.26 [#/sec]
* Time per request: 2346.174 [ms]
* Connection Times Total: 2309 [ms]
Nginx PerformanceApache, mod_php, WordPress
14年4月15日火曜日
Nginx PerformanceNginx, php-fpm, WordPress
14年4月15日火曜日
ab -n 100 -c 10 (WordPress トップページ)
* Requests per second: 5.79 [#/sec]
* Time per request: 1726.535 [ms]
* Connection Times Total: 1617 [ms]
Nginx PerformanceNginx, php-fpm, WordPress
14年4月15日火曜日
Nginx PerformanceReverse Proxy Cache
14年4月15日火曜日
ab -n 100 -c 10 (WordPress トップページ)
* Requests per second: 141.24 [#/sec]
* Time per request: 708.007 [ms]
* Connection Times Total: 636 [ms]
Nginx PerformanceNginx Reverse Proxy Cache, WordPress
14年4月15日火曜日
NginxReverse Proxy Cache
14年4月15日火曜日
nginx.conf の例http { : 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 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;
upstream backend { server unix:/var/run/nginx-‐backend.sock; } :}
Reverse Proxy Cache
14年4月15日火曜日
server { listen 80 default; server_name _; root /path/to/app; index index.php index.html index.htm;
location ~* \.(js|css|html?|xml|jpe?g|gif|png|swf|wmv|flv|ico)$ { expires 365d; }
location / { set $do_not_cache 0; if ($request_method = POST) { set $do_not_cache 1; } proxy_no_cache $do_not_cache; proxy_cache_bypass $do_not_cache; proxy_redirect off; proxy_cache czone; proxy_cache_key "$scheme://$host$request_uri"; proxy_cache_valid 200 0m; proxy_pass http://backend; }}
14年4月15日火曜日
server { listen unix:/var/run/nginx-‐backend.sock; server_name _; root /path/to/app; index index.php index.html index.htm; charset utf-‐8;
gzip off; gzip_vary off;
location ~ \.php$ { fastcgi_pass unix:/var/run/php-‐fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; fastcgi_pass_header "X-‐Accel-‐Redirect"; fastcgi_pass_header "X-‐Accel-‐Buffering"; fastcgi_pass_header "X-‐Accel-‐Charset"; fastcgi_pass_header "X-‐Accel-‐Expires"; fastcgi_pass_header "X-‐Accel-‐Limit-‐Rate"; }}
14年4月15日火曜日
cache 時間を php で制御
<?phpheader('X-‐Accel-‐Expires: '. 60 * 60 * 24);?>
Reverse Proxy Cache
14年4月15日火曜日
WP Plugin“Nginx Cache Controller”
Reverse Proxy Cache
14年4月15日火曜日
WP Plugin“Nginx Mobile Theme”
Reverse Proxy Cache
14年4月15日火曜日
MySQL Tuning
MySQL チューニングの勘所
14年4月15日火曜日
MySQL Tuning# curl -‐L mysqltuner.pl | perl % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed100 44790 100 44790 0 0 26346 0 0:00:01 0:00:01 -‐-‐:-‐-‐:-‐-‐ 26346
>> MySQLTuner 1.3.0 -‐ Major Hayden <[email protected]> >> Bug reports, feature requests, and downloads at http://mysqltuner.com/ >> Run with '-‐-‐help' for additional options and output filtering[!!] Successfully authenticated with no password -‐ SECURITY RISK![OK] Currently running supported MySQL version 5.5.35-‐33.0[OK] Operating on 64-‐bit architecture
-‐-‐-‐-‐-‐-‐-‐-‐ Storage Engine Statistics -‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐[-‐-‐] Status: +ARCHIVE +BLACKHOLE +CSV -‐FEDERATED +InnoDB +MRG_MYISAM [-‐-‐] Data in InnoDB tables: 496K (Tables: 12)[-‐-‐] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 17)[OK] Total fragmented tables: 0
-‐-‐-‐-‐-‐-‐-‐-‐ Security Recommendations -‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐[!!] User '@localhost' has no password set.[!!] User '@v210-‐172-‐187-‐188.z0d1.static.cnode.jp' has no password set.[!!] User '[email protected]' has no password set.[!!] User 'root@::1' has no password set.[!!] User 'root@localhost' has no password set.[!!] User 'root@v210-‐172-‐187-‐188.z0d1.static.cnode.jp' has no password set.
-‐-‐-‐-‐-‐-‐-‐-‐ Performance Metrics -‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐[-‐-‐] Up for: 5h 5m 4s (111 q [0.006 qps], 8 conn, TX: 102K, RX: 11K)[-‐-‐] Reads / Writes: 96% / 4%[-‐-‐] Total buffers: 232.0M global + 1.5M per thread (128 max threads)[OK] Maximum possible memory usage: 424.0M (2% of installed RAM)[OK] Slow queries: 0% (0/111)[OK] Highest usage of available connections: 0% (1/128)[OK] Key buffer size / total MyISAM indexes: 16.0M/97.0K[OK] Query cache efficiency: 41.3% (38 cached / 92 selects)[OK] Query cache prunes per day: 0[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 8 sorts)[!!] Temporary tables created on disk: 28% (2 on disk / 7 total)[OK] Thread cache hit rate: 87% (1 created / 8 connections)[OK] Table cache hit rate: 83% (36 open / 43 opened)[OK] Open file limit used: 0% (18/2K)[OK] Table locks acquired immediately: 100% (98 immediate / 98 locks)[OK] InnoDB buffer pool / data size: 64.0M/496.0K[OK] InnoDB log waits: 0-‐-‐-‐-‐-‐-‐-‐-‐ Recommendations -‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐General recommendations: MySQL started within last 24 hours -‐ recommendations may be inaccurate Enable the slow query log to troubleshoot bad queries When making adjustments, make tmp_table_size/max_heap_table_size equal Reduce your SELECT DISTINCT queries without LIMIT clausesVariables to adjust: tmp_table_size (> 64M) max_heap_table_size (> 64M)
mysqltuner.pl
14年4月15日火曜日
MySQL Tuning
-‐-‐-‐-‐-‐-‐-‐-‐ Storage Engine Statistics -‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐[-‐-‐] Status: +ARCHIVE +BLACKHOLE +CSV -‐FEDERATED +InnoDB +MRG_MYISAM [-‐-‐] Data in InnoDB tables: 496K (Tables: 12)[-‐-‐] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 17)[OK] Total fragmented tables: 0
Storage Engine Statistics
14年4月15日火曜日
MySQL Tuning
-‐-‐-‐-‐-‐-‐-‐-‐ Security Recommendations -‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐[!!] User '@localhost' has no password set.[!!] User '@v210-‐172-‐187-‐188.z0d1.static.cnode.jp' has no password set.[!!] User '[email protected]' has no password set.[!!] User 'root@::1' has no password set.[!!] User 'root@localhost' has no password set.[!!] User 'root@v210-‐172-‐187-‐188.z0d1.static.cnode.jp' has no password set.
Security Recommendations
14年4月15日火曜日
MySQL Tuning
-‐-‐-‐-‐-‐-‐-‐-‐ Performance Metrics -‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐[-‐-‐] Up for: 5h 5m 4s (111 q [0.006 qps], 8 conn, TX: 102K, RX: 11K)[-‐-‐] Reads / Writes: 96% / 4%[-‐-‐] Total buffers: 232.0M global + 1.5M per thread (128 max threads)[OK] Maximum possible memory usage: 424.0M (2% of installed RAM)[OK] Slow queries: 0% (0/111)[OK] Highest usage of available connections: 0% (1/128)[OK] Key buffer size / total MyISAM indexes: 16.0M/97.0K[OK] Query cache efficiency: 41.3% (38 cached / 92 selects)[OK] Query cache prunes per day: 0[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 8 sorts)[!!] Temporary tables created on disk: 28% (2 on disk / 7 total)[OK] Thread cache hit rate: 87% (1 created / 8 connections)[OK] Table cache hit rate: 83% (36 open / 43 opened)[OK] Open file limit used: 0% (18/2K)[OK] Table locks acquired immediately: 100% (98 immediate / 98 locks)[OK] InnoDB buffer pool / data size: 64.0M/496.0K[OK] InnoDB log waits: 0
Performance Metrics
14年4月15日火曜日
MySQL Tuning-‐-‐-‐-‐-‐-‐-‐-‐ Recommendations -‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐General recommendations: MySQL started within last 24 hours -‐ recommendations may be inaccurate Enable the slow query log to troubleshoot bad queries When making adjustments, make tmp_table_size/max_heap_table_size equal Reduce your SELECT DISTINCT queries without LIMIT clausesVariables to adjust: tmp_table_size (> 64M) max_heap_table_size (> 64M)
Performance Metrics
14年4月15日火曜日
Monit
monit によるプロセス監視
14年4月15日火曜日
Monit
14年4月15日火曜日
Monit# monit の監視間隔set daemon 30 with start delay 5 # web ステータスチェックset httpd port 2812 and use address localhost allow localhost # アラートメールの送信先set alert root@localhostset alert [email protected] # 設定ファイルのインクルードinclude /etc/monit.d/*
/etc/monit.conf の例
14年4月15日火曜日
Monitcheck process mysqld with pidfile /var/run/mysqld/mysqld.pid start program = "/sbin/service mysqld start" stop program = "/sbin/service mysqld stop"
/etc/monit.d/mysqld の例
14年4月15日火曜日
Monitcheck process php-‐fpm with pidfile /var/run/php-‐fpm/php-‐fpm.pid start program = "/sbin/service php-‐fpm start" stop program = "/sbin/service php-‐fpm stop"
check directory php_tmp with path "/var/tmp/php" if failed uid nginx then exec "/bin/chown -‐R nginx:nginx /var/tmp/php"
check directory php_session with path "/var/tmp/php/session" if failed uid nginx then exec "/bin/chown -‐R nginx:nginx /var/tmp/php/session"
check directory php_log with path "/var/log/php-‐fpm" if failed uid nginx then exec "/bin/chown -‐R nginx:nginx /var/log/php-‐fpm"
/etc/monit.d/php-fpm の例
14年4月15日火曜日
ConoHaWordPress Template
WordPress テンプレートの紹介
14年4月15日火曜日
* OS: CentOS 6.5
* Web: Nginx ver.1.4.4
* PHP: php-fpm ver.5.4.23 with APC
* DB: Percona MySQL ver. 5.5.35
* System Monitoring: Monit ver.5.5
WordPress template
14年4月15日火曜日
WordPress templateHeartbleed?# rpm -‐q opensslopenssl-‐1.0.1e-‐el6_5.7.x86_64
上記のパッケージ番号であれば対応済み上記のパッケージ番号以外の場合は yum でアップデート後、VPS を再起動してください。
# yum update openssl# reboot
14年4月15日火曜日
WordPress template
14年4月15日火曜日
WP-CLI
wp-cli の紹介
14年4月15日火曜日
WP-CLI
14年4月15日火曜日
* WP-CLI InstallWP-CLI$ curl -‐L https://raw.github.com/wp-‐cli/builds/gh-‐pages/phar/wp-‐cli.phar > wp
$ chmod +x wp
14年4月15日火曜日
WP-CLI$ cd /path/to/wordpress$ wp core download -‐-‐locale=ja
$ wp core config -‐-‐dbname=wp \ -‐-‐dbuser=wp_user -‐-‐dbpass=password \ -‐-‐dbhost=localhost -‐-‐locale=ja
$ wp core install -‐-‐url=http://example.com \ -‐-‐title=test -‐-‐admin_name=admin \ -‐-‐[email protected] \ -‐-‐admin_password=test
* WordPress Install
14年4月15日火曜日
WP-CLI$ wp plugin install hotfix
$ wp plugin activate hotfix
$ wp plugin status
4 installed plugins: I akismet 2.5.9 I hello 1.6 A hotfix 1.0 A wp-‐multibyte-‐patch 1.7 Legend: I = Inactive, A = Active
* WordPress Plugins Install
14年4月15日火曜日
WP-CLI$ cd /path/to/wordpress
$ wp core update
$ wp core update-‐db
$ wp core version -‐-‐extraWordPress version: 3.7.1Database revision: 25824TinyMCE version: 3.59 (359-‐20131026)
* WordPress Core Update
14年4月15日火曜日
WP-CLI$ wp plugin status3 installed plugins: I akismet 2.5.9 UA nginx-‐champuru 1.6.0 I wp-‐multibyte-‐patch 1.7
Legend: A = Active, I = Inactive, U = Update
$ wp plugin update nginx-‐champuru
$ wp plugin update-‐all
* WordPress Plugins Update
14年4月15日火曜日
WP-CLI$ wp export
$ wp export -‐-‐post_type=post
$ wp export -‐-‐post_status=publish
$ wp import export.xml
$ wp import export.xml -‐-‐skip=attachment
* WordPress Export & Import
14年4月15日火曜日
WP-CLI$ wp nginx flush
$ wp nginx listarray(3291) { [0]=> object(stdClass)#126 (3) { ["cache_id"]=> string(1) "0" ["cache_url"]=> :
* Nginx Cache Controlle
14年4月15日火曜日
Chef
VM Image 作成に使用しているツール
14年4月15日火曜日
Chef
14年4月15日火曜日
Chef×14年4月15日火曜日
ChefInfrastructure as Code
14年4月15日火曜日
ChefInfrastructure as Code
14年4月15日火曜日
$ curl -‐L https://www.opscode.com/chef/install.sh | sudo bash
Chef* Chef Solo Install
14年4月15日火曜日
* Recipepackage "nginx" do! action :installend
service "nginx" do! action [ :enable , :start ]end
Chef
14年4月15日火曜日
* Chef 活用ガイドChefhttp://www.amazon.co.jp/dp/4048919857
14年4月15日火曜日
Thanks !
14年4月15日火曜日