管理サーバからwebサーバのhttpd.confを一括更新するコマンドを作った。

Webサーバのhttpd.confを一括更新するプログラム ファイルを特定の場所にrsyncし、その後diffコマンドで正常にアップロードできたかを確認してくれるようなものです。
https://github.com/kurimon/awstool_updatehttpdconf/blob/master/README.md

AWSでリージョン一覧をフォーマット指定して取得するコマンドを作った。

結果サンプル

$ ./regionlist 
name:eu-west-1  Endpoint:ec2.eu-west-1.amazonaws.com
name:sa-east-1  Endpoint:ec2.sa-east-1.amazonaws.com
name:us-east-1  Endpoint:ec2.us-east-1.amazonaws.com
name:ap-northeast-1 Endpoint:ec2.ap-northeast-1.amazonaws.com
name:us-west-2  Endpoint:ec2.us-west-2.amazonaws.com
name:us-west-1  Endpoint:ec2.us-west-1.amazonaws.com
name:ap-southeast-1 Endpoint:ec2.ap-southeast-1.amazonaws.com
name:ap-southeast-2 Endpoint:ec2.ap-southeast-2.amazonaws.com

フォーマット指定もできます。

$ ./regionlist -f="%RegionName,%Endpoint"
eu-west-1,ec2.eu-west-1.amazonaws.com
sa-east-1,ec2.sa-east-1.amazonaws.com
us-east-1,ec2.us-east-1.amazonaws.com
ap-northeast-1,ec2.ap-northeast-1.amazonaws.com
us-west-2,ec2.us-west-2.amazonaws.com
us-west-1,ec2.us-west-1.amazonaws.com
ap-southeast-1,ec2.ap-southeast-1.amazonaws.com

Usage

 使用方法:                                                         
    regionlist [オプション]                                        
                                                                   
 オプション:                                                       
    -h                                                             
        この画面を表示する                                         
                                                                   
    -f="フォーマット"                                            
        フォーマット中で使用可能な変数                             
            %RegionName                                            
            %Endpoint 

FluentdとRedisとnode.jsを使った準リアルタイムログビューア(Logbear)

FluentdとRedisとnode.jsを使って準リアルタイムログビューアを作った

ログをブラウザでtailするのに良い感じのソリューションが見つからなかったので作りました。

使い方

fluentd.confをこんな感じに設定すると

<source>
  type forward
  port 8888
</source>

<match タグ名>
  type redis
  host localhost
  port 6379
  flush_interval 1s
</match>

こんな感じに表示されます

AWSでインスタンス一覧をフォーマット指定して取得するコマンドを作った。

結果サンプル

$ ./serverlist
id:i-xxxxx  TagName:web001  StateName:running   Private_IP:10.0.1.1 Public_IP:null
id:i-xxxxx  TagName:web002  StateName:running   Private_IP:10.0.1.2 Public_IP:null
id:i-xxxxx  TagName:dns001  StateName:running   Private_IP:10.0.2.1 Public_IP:XX.XX.XX.XX
id:i-xxxxx  TagName:nat001  StateName:running   Private_IP:10.0.3.1 Public_IP:XX.XX.XX.XX

フォーマット指定もできます。

$ ./serverlist -f="%InstanceId,%InstanceStateName"
i-xxxxx,running
i-xxxxx,running
i-xxxxx,running
i-xxxxx,running

Usage

使用方法:                                                         
   serverlist [オプション,オプション,オプション....]              

オプション:                                                       
   -h                                                             
       この画面を表示する                                         

   -f="フォーマット"                                            
       フォーマット中で使用可能な変数                             
           %InstanceId                                              
           %InstanceStateName                                       
           %InstanceStateCode                                       
           %PrivateIpAddress                                        
           %PublicIpAddress                                         
           %LaunchTime                                              
           %T{Tag Name} 

httpdのダウンロード→ビルド→インストール

事前準備:/root/tmpディレクトリを作っておく。

#!/bin/bash

# 作業ディレクトリへ移動
cd /root/tmp

# tarballのダウンロード(httpd-2.2.20.tar.gz)
wget http://ftp.kddilabs.jp/infosystems/apache//httpd/httpd-2.2.20.tar.gz

# openssl-develのインストール(httpdのビルドに必要)
yum -y install openssl-devel

# 解凍
# オプション:x eXtract アーカイブの抽出
# オプション:z gZip 圧縮・解凍に gzip を使う
# オプション:v Verbose 作成・抽出時にファイルのリストを画面出力する
# オプション:f File 作成・抽出するファイルを指定する(tar は本来テープメディアのためのコマンド (Tape ARchive) のため、これを指定しないとデフォルトで /dev/rmt0 になってしまう)
tar xzvf httpd-2.2.20.tar.gz

# 解凍したディレクトリに移動
cd httpd-2.2.20

# apacheのビルド
./buildconf

# --prefix=ディレクトリ:インストール先ディレクトリを指定
# --with-kayout=ファイル:ファイルから取得したインストールパスレイアウトIDを使用する
# --enable-module=モジュール名:モジュールを有効にする
./configure --prefix=/usr/local/apache --with-layout=Apache --enable-modules=most --enable-mods-shared=all --with-mpm=prefork

make

make install

iptables設定用スクリプト

#!/bin/bash

# iptablesのチェインの初期化
iptables -F

# デフォルトルールの設定
# すべての受信を拒否
# --policyはチェーン内でどのルールにもマッチしなかった場合に適応される
iptables --policy INPUT DROP
iptables --policy FORWARD DROP

# すべての送信を許可
iptables --policy OUTPUT ACCEPT

# 自分自身に対するすべてのアクセスを許可(lo = ループバックインターフェース)
# --append は指定したチェインにルールを追加する
# --in-    はパケットを受信するLANインターフェースを(eth0やloなどで)指定する
# --out-   はパケットを受信するLANインターフェースを(eth0やloなどで)指定する
iptables --append INPUT  --in- lo --jump ACCEPT

# 全ホスト(ブロードキャストアドレス、マルチキャストアドレス)宛パケットはログを記録せずに破棄
# ※不要ログ記録防止
iptables --append INPUT --destination 255.255.255.255 -jump DROP
iptables --append INPUT --destination 224.0.0.1 -jump DROP

########################################################################
######### ----ここから各種サービス(必要なサービスのみ追加)---- #########

# 外部からのTCP22番ポート(SSH)へのアクセスを許可
# --dportはポート番号を指定する(--protocolにtcpとudpのプロトコルを指定した場合に拡張されるオプション)
iptables --append INPUT --protocol tcp --dport 22 --jump ACCEPT

# 外部からのTCP80番ポート(HTTP)へのアクセスを許可
iptables --append INPUT --protocol tcp --dport 80 --jump ACCEPT

# 外部からのTCP443番ポート(HTTPS)へのアクセスを許可
iptables --append INPUT --protocol tcp --dport 443 --jump ACCEPT

######### ----ここまで各種サービス(必要なサービスのみ追加)---- #########
########################################################################

# セッションを確立した後のパケット疎通(アクセス)は許可
# -mは外部モジュールのロード{書式:-m <module-name>}
# --stateオプションにはパケットの接続状態を指定する。つまり下記の場合は接続状態が「ESTABLISHED(確立),RELATED」の時にアクセスを許可する
iptables --append INPUT  -m state --state ESTABLISHED,RELATED --jump ACCEPT

# 設定内容の保存
/etc/rc.d/init.d/iptables save

# ファイアウォール起動
/etc/rc.d/init.d/iptables restart

facebookのインフラを使いすぎるとアカウントを停止される

facebookからのメール

Facebook To 自分
詳細を表示 19:21 (46分前)
Hi,

Great experiences on Platform allow users to build out their identity and share engaging, relevant content with friends. To ensure users continue to have a positive experience using apps and sites on Facebook, we run automated screens that monitor user feedback and disable apps receiving negative user feedback (including, but not limited to, feed story hides, app uninstalls, and reports).

Your app administrator (ID #233032973381917) has been disabled because our automated systems detected that your app is receiving negative user feedback. To help prevent this from happening in the future, we suggest you actively monitor user reports, volume of content published per user, and any spikes in share or install activity (real-time analytics available on Insights: http://www.facebook.com/insights/ ). You may also be in violation of our Facebook Principles and Policies: http://developers.facebook.com/policy/ .

If you think we have removed your app erroneously, please read about our appeals process and complete the form to appeal at http://www.facebook.com/help?faq=17553. We will work quickly to evaluate your case.

Thank you,
The Facebook Platform Team