https://go.sawanoboly.net/2019/11/22/wp_redis_disable_metrics/
AMIMOTO で PHP 7.2 を利用する
AMIMOTO で PHP 7.2 を利用するには、以下のコマンドを実行してください。
Chef レシピを最新のものに更新する
$ sudo git -C /opt/local/chef-repo/cookbooks/amimoto/ pull origin 2016.01
remote: Counting objects: 31, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 31 (delta 24), reused 26 (delta 24), pack-reused 4
Unpacking objects: 100% (31/31), done.
From git://github.com/Launch-with-1-Click/lw1-amimoto
* branch 2016.01 -> FETCH_HEAD
3ce41b9..af15013 2016.01 -> origin/2016.01
Updating 3ce41b9..af15013
Fast-forward
attributes/03_php.rb | 17 +++++++++++++++++
attributes/yum_repo.rb | 3 +++
recipes/php.rb | 7 +++++++
recipes/redis.rb | 11 ++++++++---
recipes/repos.rb | 2 +-
templates/amazon/yum/remi.repo.erb | 29 +++++++++++++++++++++++++++++
templates/default/yum/remi.repo.erb | 29 +++++++++++++++++++++++++++++
7 files changed, 94 insertions(+), 4 deletions(-)
Chef レシピに与えるパラメータを保存している /opt/local/amimoto.json を編集する
$ TMP_JSON=$(mktemp)
$ jq -s '.[1] * .[0]' <(echo '{"phpfpm":{"version":"72"}}') <(sudo cat /opt/local/amimoto.json) > ${TMP_JSON}
$ sudo mv -f ${TMP_JSON} /opt/local/amimoto.json
※ 7.2 以外(5.6, 7.0, 7.1)が使用したい場合は、2行目の “version”:”72″ を変更してください。
最後に以下のコマンドを実行します。
$ sudo /opt/local/provision
$ sudo service php-fpm restart
確認
$ php -v
PHP 7.2.1 (cli) (built: Jan 3 2018 09:08:32) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.2.1, Copyright (c) 1999-2017, by Zend Technologies
AMIMOTO で redis object cache を使用する
AMIMOTO で redis object cache を使用するには、以下の3ステップの作業が必要となります。
- redis をインストールする
- WordPress プラグイン Redis Object Cache をインストールして有効化する
- Redis Object Cache に関する不具合を修復するプラグインをインストールする
では、順番にやり方を説明しましょう。
redis をインストールする
これは、それほど難しくありません。
まず、SSH接続してから /opt/local/amimoto.json を編集してください。
以下のコマンドで対応可能です。
$ TMP_JSON=$(mktemp)
$ jq -s '.[1] * .[0]' <(echo '{"redis":true}') <(sudo cat /opt/local/amimoto.json) > ${TMP_JSON}
$ sudo mv -f ${TMP_JSON} /opt/local/amimoto.json
次に以下のコマンドを実行します。
$ sudo /opt/local/provision
Redis が起動しているかどうかは、以下のコマンドで確認できます。
$ sudo service redis status
Redis Object Cache をインストールして有効化する
まず、wp-config.php に以下のコードを追加しておきます。
/** Redis Cache Settings **/
define('WP_REDIS_HOST', '127.0.0.1');
define('WP_REDIS_PORT', 6379);
define('WP_REDIS_MAXTTL', 3600);
define('WP_CACHE_KEY_SALT', DB_NAME);
設定する各定数の意味は、プラグインの説明読んでください。
プラグインのインストールを wp-cli 使ってやるなら、以下の通り
$ wp plugin install --activate redis-cache
$ wp redis enable
$ wp redis sttus
Status: Connected
Client: PECL Extension (v3.1.6)
Redis Object Cache に関する不具合を修復するプラグインをインストールする
ファイル redis-cache-fix.php を取ってきて、wp-content/mu-plugins/ ディレクトリに保存してください。
ターミナルでやるなら以下の通り
$ wget https://gist.githubusercontent.com/wokamoto/5c0c8a19a6dbd08e4121aa05d238543c/raw/464d418bcc7f9686852cdc3c0db6d6316278d6ed/redis-cache-fix.php
$ mkdir /path/to/wordpress/wp-content/mu-plugins
$ mv redis-cache-fix.php /path/to/wordpress/wp-content/mu-plugins/
こんな感じで良いかなと
[AWS] AWS Certificate Manager が Tokyo リージョンにやってきた!
AWS Certificate Manager が Tokyo リージョンでも使えるようになりました。
AWS Certificate Manager now available in more regions
以前、SES を使って ACM の承認メール受信する方法を書いてますので、それ参考にしてくださいねー。
S3 で SES 受信するためのバケットポリシーサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Version": "2008-10-17", | |
"Statement": [ | |
{ | |
"Sid": "GiveSESPermissionToWriteEmail", | |
"Effect": "Allow", | |
"Principal": { | |
"Service": [ | |
"ses.amazonaws.com" | |
] | |
}, | |
"Action": [ | |
"s3:PutObject" | |
], | |
"Resource": "arn:aws:s3:::BUCKET-NAME/*", | |
"Condition": { | |
"StringEquals": { | |
"aws:Referer": "ACCOUNT-ID-WITHOUT-HYPHENS" | |
} | |
} | |
} | |
] | |
} |
[AWS] mailq を監視して CloudWatch のカスタムメトリクスに送信
Web サーバにバックドア仕掛けられて spam 送信の踏み台にされていないかを確認するために mailq の値をカスタムメトリクスに定期的に送信してCloudWatch で検出しておくと、ある日突然 AWS から「Your Amazon EC2 Abuse Report」ってメールが来ることが無くなると思うよ。
#!/bin/sh
# EC2 のインスタンス ID を取得
instanceid=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
# region を取得
az=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone)
_length=$(echo $((${#az} - 1)))
region=$(echo ${az} | cut -c 1-${_length})
namespace="System/Linux"
# mailq
mailq=$(mailq | grep 'Total requests' | awk '{print $3}')
aws cloudwatch put-metric-data \
--region ${region} \
--namespace ${namespace} \
--dimensions InstanceId=${instanceid} \
--unit Count \
--metric-name "MailQueu" \
--value "$mailq"
[WordPress] ひょっとしてコア改竄されてるんでないの?と思ったら
wp-cli で改竄されてないか確認できるよ。
$ cd /path/to/wordpress
$ wp core verify-checksums
[Nginx] nginx: [emerg] could not build the server_names_hash…
Nginx でどんどこバーチャルホストを追加していると、以下の様なエラーが表示されて設定ファイルの再読み込みができなくなることがあります。
nginx: [emerg] could not build the server_names_hash, you should increase server_names_hash_bucket_size: 64
まぁ、言ってるとおりですね。
server_names_hash_bucket が足りなくなってるので増やせよっつってるので、/etc/nginx/nginx.conf に以下を追加しましょう。
網元使ってる場合は /etc/nginx/nginx.conf が再起動時に元に戻ってしまうので /etc/nginx/conf.d/00_server_name_hash_settings.conf という名前で、以下の内容のファイルを作ってやってください。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server_names_hash_bucket_size 128; | |
server_names_hash_max_size 1024; |
[AWS] RDS のパラメータグループに設定されてる値を CSV で取得
jq 使えば csv 化は簡単
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aws rds describe-db-parameters –db-parameter-group-name {PARAMETER-GROUP-NAME-HERE} | |
| jq -r '.Parameters[] | "\(.ParameterName), \(.ParameterValue)"' \ | |
> rds_parameters.csv |
[WordPress][wp-cli] wp-cli でテーブルごとにエクスポートファイルをわける
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
tables=$(wp db query "show tables;" | grep -v "Tables_in") | |
for table in ${tables}; do | |
echo "— ${table}" | |
# エクスポート処理 | |
wp db export ${table}.sql –tables=${table} | |
done |
[WordPress] [CDN] CDN を前面に置いた時にプレビューを正常に表示させるための fix
CDN を前面に置いた時に WordPress ダッシュボードで表示される URL に投稿の更新日付を含ませて、強制的に no cache の状態で表示させるための fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: CloudFront Preview Fix | |
Plugin URI: | |
Description: WPログイン時にパーマリンクに記事変更日付を含み、プレビューが最新になるようにする | |
Version: 0.5 | |
Author: | |
Author URI: | |
*/ | |
add_action( 'init', function(){ | |
$cf_fix = cloudfront_preview_fix::get_instance(); | |
$cf_fix->add_hook(); | |
}); | |
class cloudfront_preview_fix{ | |
private static $instance; | |
private function __construct() {} | |
public static function get_instance() { | |
if ( ! isset( self::$instance ) ) { | |
$c = __CLASS__; | |
self::$instance = new $c(); | |
} | |
return self::$instance; | |
} | |
public function add_hook() { | |
add_action( 'template_redirect', array($this, 'template_redirect') ); | |
add_filter( 'post_link', array($this, 'post_link_fix'), 10, 3 ); | |
add_filter( 'preview_post_link', array($this, 'preview_post_link_fix'), 10, 2 ); | |
add_filter( 'the_guid', array($this,'the_guid') ); | |
add_filter( 'sanitize_file_name', array($this,'sanitizeFileName') ); | |
} | |
public function template_redirect() { | |
if ( is_user_logged_in() ) { | |
nocache_headers(); | |
} | |
} | |
public function post_link_fix( $permalink, $post, $leavename ){ | |
if ( !is_user_logged_in() || !is_admin() || is_feed() ) { | |
return $permalink; | |
} | |
$post = get_post( $post ); | |
$post_time = | |
isset($post->post_modified) | |
? date('YmdHis', strtotime($post->post_modified)) | |
: current_time('YmdHis'); | |
$permalink = add_query_arg( 'post_date', $post_time, $permalink ); | |
return $permalink; | |
} | |
public function preview_post_link_fix( $permalink, $post ){ | |
if ( is_feed() ) { | |
return $permalink; | |
} | |
$post = get_post( $post ); | |
$preview_time = current_time('YmdHis'); | |
$permalink = add_query_arg( 'preview_time', $preview_time, $permalink ); | |
return $permalink; | |
} | |
public function the_guid($guid) { | |
$guid = preg_replace( '#\?post_date=[\d]+#', '', $guid ); | |
return $guid; | |
} | |
public function sanitizeFileName( $filename ){ | |
$info = pathinfo($filename); | |
$ext = empty($info['extension']) ? '' : '.' . $info['extension']; | |
$name = basename($filename, $ext); | |
$finalFileName = $name.'-'.current_time('YmdHis'); | |
return $finalFileName.$ext; | |
} | |
} |