SlideShare ist ein Scribd-Unternehmen logo
1 von 41
AWS Elastic Beanstalk を使って
           みた
         +こねたCDP




         - Hokuriku -
        勉強会 第5回
自己紹介
 中道 健一(nkmc )
 JAWS-UG北陸コアメンバー


 創屋株式会社 所属(石川県白山市)
 ソフトウェア・エンジニア(中間管理職)
 PHP/Python/Ruby/.NET/VC++とか


好きなAWSサービス:Route53
好きなCDP:---
創屋(そうや)株式会社
   2005年創業
   http://www.souya.biz/

   システム開発全般
   AWSを利用したサービス構築
   言語・プラットフォームにとらわれず、
    広い範囲のシステム開発を1社で行える

   開発室:
    石川県白山市日御子町ハ13-6
   東京事務所:
    東京都台東区西浅草3-10-10-201
最近ネタ切れ
 全然目新しいことできてない
 小ネタなら・・・
    ◦ Simple Email Service(SES)でメール送信
    ◦ Elastic MapReduce(EMR)でログ結合
    ◦ EC2上でRuby on Rails使ってみた
ちょっとだけ
     新しいこと
   やってみようか


AWS Elastic Beanstalk
   初めて(!)
AWS Elastic Beanstalkとは
 AWS クラウド内でのアプリケーショ
  ンのデプロイと管理を簡単にするサー
  ビス
 Webアプリケーションをアップロード
  するだけで、アプリケーションの運用
  に必要な環境の作成からデプロイ、
  ロードバランシングなどが自動で行わ
  れる
百聞は一見に如かず




 サンプルアプリを動かしてみよう
サンプルアプリ動かす
 AWS Management Consoleから
  Elastic Beanstalkを選択
 プラットフォームを選んでStart
サンプルアプリ(起動待ち)
 アイコンがグリーンになるまで5分ぐらい待つ
 グリーンになったらブラウザでアクセス
今AWSの中の人が
一生懸命構築してます




    これでワンセット
サンプルアプリ(起動したよ)
   こんな感じの画面がブラウザにでます
プラットフォーム
               言語             コンテナ/              サポートツール
   言語
              バージョン          フレームワーク               提供IDE
Java         5 or 6         Apache + Tomcat6, Eclipse
                            7
PHP          5.3 or 5.4     CAKE PHP
                            Symfony2
Python       2.6            Django
                            Flask
Ruby         1.8.7, 1.9.3   Rails
                            Sinatra
.NET         .NET 2.0以      IIS7.5, 8          Visual Studio2008,
             降                                 2010
Node.js                     Express
                            Geddy
詳細は
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/Welcome.html
参考
この辺り読めばnkmcの話は必要ありません
でした!
 http://aws.amazon.com/jp/elasticbeanstalk/f
  aqs/
 http://www.slideshare.net/AmazonWebServi
  cesJapan/getting-startedwithbeanstalk-
  20130111
 http://www.slideshare.net/dateofrock/net-
  cobol20130222
   書籍
    Amazon Web Services
    プログラミング
VS.NETでWEBアプリをデプロ
イ

  これだけの発表ではアレなので


Visual Studio.NET(2008)
  のデプロイをデモしてみます!
VisualStudio.NETでWEBアプリ
をデプロイ(前準備1)

 Microsoft Visual Studio.NET
  2008/2010を用意(ExpressでもOKか
  不明)
 AWS Toolkit for Microsoft Visual
  Studioをインストール
    ◦ http://aws.amazon.com/jp/visualstudio/
   Web Deployをインストール
    ◦ http://www.iis.net/downloads/microsoft/we
      b-deploy
VS.NETでWEBアプリをデプロ
イ(前準備2)

   VS.NETを起動したら、AWS Toolkitに
    アクセスキーとシークレットキーを設
    定
VS.NETでWEBアプリデプロイ
(1)
   WEBアプリケーション・プロジェク
    トを作成・実装
VS.NETでWEBアプリデプロイ
(2)
   ASP.NET WEBサイトを選択
VS.NETでWEBアプリデプロイ
(3)
   プロジェクトを右クリックして
    Publish to AWS…を選択
VS.NETでWEBアプリデプロイ
(4)
   AWS Elastic Beanstalkを選択
VS.NETでWEBアプリデプロイ
(5)
   アプリケーション名(Name)を入力
VS.NETでWEBアプリデプロイ
(6)
   環境名(Name)を入力
VS.NETでWEBアプリデプロイ
(7)
 コンテナタイプを指定(Container type)
 インスタンスタイプを指定(Instance type)
VS.NETでWEBアプリデプロイ
(8)
   内容を確認してDeployボタン
VS.NETでWEBアプリデプロイ
(9)
   イベントウィンドウが表示されます
   デプロイが完了したら通知ウィンドウが表
    示されます
まとめ
 アプリケーション開発者から使いやす
  い
 ほとんどの言語に対応
 開発、テスト、ステージング、プロダ
  クション環境などを分けて管理できる
 設定ファイルで細かくカスタマイズ可
  能
こねたCDP




Web Storage Archiveパターン
こねたCDP
 ELBの下に複数のEC2をぶら下げた
 WEBサーバのアクセスログどうしよ
  う?
 複数台のサーバを見るのは面倒だか
  ら、S3に集めたいな

    Web Storage Archiveパターンだ!
こねたCDP
Web Storage Archiveパターン




   http://aws.clouddesignpattern.org/index.
   php/CDP:Web_Storage_Archiveパター
   ン
こねたCDP
Web Storage Archiveパターン

   クラウドストレージ(S3)の無限キャパシ
    ティでログなどを貯め続けることができ
    る
   S3の高可用性・耐久性でファイルのバッ
    クアップも不要
   S3の単価が安い
   1箇所にファイルを集めることができる
こねたCDP
 EC2からのログの転送方法は?
 S3syncではなくFluentdを使ってみた。

    ◦ http://fluentd.org/

   この辺りを参考にしてインストール
    ◦ http://blog.suz-lab.com/2012/11/centos6fluentd.html
    ◦ http://dev.classmethod.jp/cloud/amazon-linux-fluentd-
      setup-plugin/
        $ sudo -s
        # cd
        # curl -OL http://toolbelt.treasure-data.com/sh/install-redhat.sh
        # chmod 755 install-redhat.sh
        # ./install-redhat.sh
こねたCDP
転送するファイルのフォルダに権限設定

$ sudo chgrp td-agent /var/log/httpd/
$ sudo chgrp td-agent /var/log/messages
$ sudo chgrp td-agent /var/log/secure
$ sudo chgrp td-agent /var/log/cron

$ sudo chmod g+rx /var/log/httpd/
$ sudo chmod g+rx /var/log/messages
$ sudo chmod g+rx /var/log/secure
$ sudo chmod g+rx /var/log/cron
こねたCDP
  Gemのアップデートとプラグインのインストール

fluent-plugin-s3                   S3にログを書き出すプラグイン
fluent-plugin-forest               タグを動的に扱うプラグイン
                                   プレースホルダを扱えるようにするプラ
fluent-plugin-config-expander      グイン


  $ sudo /usr/lib64/fluent/ruby/bin/fluent-gem update
  $ sudo /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-
  s3 $ sudo /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-
  plugin-forest $ sudo /usr/lib64/fluent/ruby/bin/fluent-gem install
  fluent-plugin-config-expander
こねたCDP
$ sudo vi /etc/td-agent/td-agent.conf
<source>
 type forward                       <match *.**>
 port 24224                          type forest
</source>                            subtype s3


<source>                             <template>
 type config_expander                   aws_key_id AKI******
 <config>                               aws_sec_key **************
  type tail                             s3_bucket log.test.com
  format apache                         s3_endpoint s3-ap-northeast-1.amazonaws.com
  path /var/log/httpd/access_log
  tag ${hostname}/apache.access         path ec2/${tag}/
 </config>                              buffer_path /var/log/td-agent/buffer/${tag}
</source>
                                        time_slice_format %Y/%m/%d/ec2-%Y-%m-%d-%H
<source>                                flush_interval 1m
 type config_expander               #    time_slice_format %Y/%m/%Y-%m-%d
 <config>                           #    time_slice_wait 10m
  type tail                          </template>
  format syslog                     </match>
  path /var/log/messages
  tag ${hostname}/syslog.messages
 </config>
</source>
こねたCDP
これでインストールと設定は完了

$ sudo service td-agent restart


を実行してブラウザからサイトにアク
セス。
しばらくするとS3上にファイルが転送
された!
こねたCDP
暫く放置していたら問題発覚

ファイルの更新間隔が短すぎるのか、
分単位でファイルができてしまう!?

設定間違ってたみたい。
細切れのログファイルが一杯でき
た・・・。
こねたCDP
 AWSの中の人にEMRでファイル結合
  できるって教えてもらった
 コマンドはS3DistCp
    ◦ http://imai-
      factory.s3.amazonaws.com/decks/log_aggregation_with_e
      mr.pdf
    ◦ http://docs.aws.amazon.com/ElasticMapReduce/latest/Dev
      eloperGuide/UsingEMR_s3distcp.html


 EC2のmicroインスタンスを起動し
  て、EMRをキック。
 これでファイルが結合された!
こねたCDP
EC2のマイクロインスタンス起動してすぐ実行する方法

$ cd
$ mkdir elastic-mapreduce-cli
$ cd elastic-mapreduce-cli
$ wget http://elasticmapreduce.s3.amazonaws.com/elastic-mapreduce-ruby.zip
$ unzip elastic-mapreduce-ruby.zip
$ vi credentials.json
{
"access_id": "AKI*****************",
"private_key": "**************************",
"keypair": "keypair_name",
"key-pair-file": "mykeypair.pem",
"log_uri": "s3n://log-merge.test.com/",
"region": "ap-northeast-1"
}

キーを置いとく
$ chmod og-rwx mykeypair.pem

EMRのインスタンスを起動し、jobflow番号を取得する。
$ ./elastic-mapreduce --create --name logmerge --instance-type m1.small --num-instances 1 --alive
Created job flow j-1IFZNUBP3U123

EMRでS3distCp実行
./elastic-mapreduce --jobflow j-1IFZNUBP3U123 
--jar s3://ap-northeast-1.elasticmapreduce/libs/s3distcp/1.latest/s3distcp.jar 
--step-name S3DistCp 
--args '--src,s3://log.test.com/2013/03/,--groupBy,.*([0-9]{4}-[0-9]{2}-[0-9]{2}).*.gz,--outputCodec,gzip,--
dest,s3://log-merge.test.com/merge/'
こねたCDP
と思ったら、更に失敗に気づく

 Fluentdが作るファイルはJSON形式
 フツーはMongoDB(なにそれ)に入れて
  解析したりするらしい
 が・・・今回は単純にWindows用の
  ビュワーでApacheログを見たいだ
  け!
こねたCDP
JSON対応ログビュワーがないよ(´・ω・`)

仕方ないので人力で解決
 FulentdのJSON形式ファイルからApacheロ
  グ形式に変換するツールを自作(VB.NET +
  Json.NET)
 ◦ https://s3-ap-northeast-
   1.amazonaws.com/public.nkmc/tools/JSON2Apa
   che.zip
 ◦ 改変自由で配布します。

最初からS3syncでローテートしたログをアッ
プすればいいだけでした・・・
おしまい

以上、まとまりませんでしたが
おしまい。

Weitere ähnliche Inhalte

Empfohlen

Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Empfohlen (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

JAWS-UG Hokuriku 第5回勉強会 AWS Elastic Beanstalkを使ってみた + こねたCDP