Skip to content

Instantly share code, notes, and snippets.

@tkuchiki
tkuchiki / install.sh
Last active April 2, 2018 17:14
Ubuntu 16.04 に nginx-build を使って openresty + ngx_small_light + ngx_dynamic_upstream を入れる
#!/bin/bash
apt-get update -y
apt-get install -y libpcre2-dev imagemagick libimlib2-dev libgd-dev libmagickwand-dev libxml2-dev libxslt-dev libgeoip-dev libperl-dev curl git openssl libssl-dev
ln -s /usr/lib/x86_64-linux-gnu/ImageMagick-6.8.9/bin-Q16/Wand-config /usr/bin/
mkdir -p /usr/local/src/nginx/modules
cd /usr/local/src/nginx/modules
git clone https://github.com/cubicdaiya/ngx_dynamic_upstream
git clone https://github.com/cubicdaiya/ngx_small_light
cd ngx_small_light
./setup --with-imlib2 --with-gd
@tkuchiki
tkuchiki / aurora.md
Created September 26, 2016 05:26
terraform で Amazon Aurora の master - slave 構成の DB を起動する
$ cat terraform.tf
resource "aws_rds_cluster" "test_db_cluster" {
    cluster_identifier      = "test-db"
    availability_zones      = ["ap-northeast-1a","ap-northeast-1c"]
    database_name           = "foobar"
    master_username         = "foobar"
    master_password         = "hogehoge"
    backup_retention_period = 35
    preferred_backup_window = "07:00-09:00"
@tkuchiki
tkuchiki / rds.md
Last active September 26, 2016 02:34
aws cli まとめ (rds|aurora)

RDSの最新の自動取得 snapshot を取得する

$ aws rds describe-db-snapshots --snapshot-type automated | jq '.DBSnapshots | sort_by(.SnapshotCreateTime) | reverse | .[0]'
{
  "Engine": "mysql",
  "SnapshotCreateTime": "2016-09-25T18:46:55.366Z",
  "AvailabilityZone": "ap-northeast-1a",
  "PercentProgress": 100,
  "MasterUsername": "root",
@tkuchiki
tkuchiki / stop-instance.md
Created September 23, 2016 01:05
cron で ec2 止める

IAM Role でも aws configure しないと動かないので注意

$ cat /etc/cron.d/stop-instance
30 18 * * * root aws ec2 stop-instances --instance-ids $(curl -s http://169.254.169.254/latest/meta-data/instance-id)
@tkuchiki
tkuchiki / set-localtime.sh
Created September 23, 2016 00:55
localtime の timezone を変更する
#!/bin/bash
echo 'ZONE="Asia/Tokyo"' > /etc/sysconfig/clock
if grep "amazon linux" -iqs /etc/system-release; then
# for Amazon Linux
rm -f /etc/localtime
ln -s /usr/share/zoneinfo/Japan /etc/localtime
else
# for CentOS
/usr/sbin/tzdata-update
@tkuchiki
tkuchiki / gist:c4a9618480b000454b465524557dbbe5
Created July 20, 2016 06:42
Mackerel の AWS Integration でタグによる絞り込みを行うのに必要な権限
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "elasticloadbalancing:DescribeTags",
"Resource": "*"
},
{
"Effect": "Allow",
@tkuchiki
tkuchiki / memo.md
Created June 13, 2016 08:43
CloudFront でエラーページを返す

CloudFront で Origin を S3 にしてエラーページを返す

  • Origin Domain Name
    • S3 の Bucket を指定
  • Restrict Bucket Access
    • yes
  • Origin Access Identity
    • なかったら Create a New Identity
  • Grant Read Permissions on Bucket
  • Yes, Update Bucket Policy
@tkuchiki
tkuchiki / dns_round_robin.md
Last active June 5, 2016 15:55
DNS ラウンドロビンについて
@tkuchiki
tkuchiki / memo.md
Last active March 3, 2017 10:22
Nginx は if の中で使えないディレクティブがあるので、error_page と組み合わせてみる

特定の IP からのアクセスのときだけ認証を通さないで proxy したい

  • Nginx は if の中で使えないディレクティブがある
    • error_page と組み合わせる
      • error_page で実行する location 内で include したり、認証設定を書く

以下の設定は error

if ($geo = 0) {
@tkuchiki
tkuchiki / metadata_endpoint.sh
Last active April 20, 2016 09:05
インスタンスメタデータの URL 一覧を出力
#!/bin/bash
META_DATA="http://169.254.169.254/latest/meta-data"
fetch_uri() {
for md in $(curl -s "${META_DATA}/${1}"); do
if echo "${md}" | grep -qs -E "/$"; then
fetch_uri "${1}${md}"
else
echo "${META_DATA}/${1}${md}"