47
Windows Azure で LL ででで Web でででででででででで ででで でで でで stanaka @ hatena.ne.jp http://d.hatena.ne.jp/stanaka/ http://twitter.com/stanaka/

Using Windows Azure

Embed Size (px)

DESCRIPTION

Putting PHP Application, MySQL, Mediawiki on Windows Azure

Citation preview

Page 1: Using Windows Azure

Windows Azure でLL 言語系 Web アプリケーション開発

はてな 田中 慎司stanaka @ hatena.ne.jp

http://d.hatena.ne.jp/stanaka/http://twitter.com/stanaka/

Page 2: Using Windows Azure

アジェンダ

Azure とは GAE/AWS と比較

試してみた Hello World 級 PHP on Azure PHP & MySQL on Azure Mediawiki on Azure

Page 3: Using Windows Azure

スペック 基本的に Linux 系

いわゆる LAMP スタック Linux, Apache, MySQL, Perl IDE は使わない

Windows との接点 メインのノート PC は Windows VB, C# は知っている COM コンポーネントは一度書いたことがある

VisualStudio

Page 4: Using Windows Azure

今日のテーマ LL 系言語エンジニアからの視点

クラウドサービスでの Azure の位置付け Azure – AWS – GAE

Azure の勘所 とりあえず動かしてみる

Page 5: Using Windows Azure

Azure とは

Microsoft によるクラウドサービス アプリケーションの動作サービス (Windows Azure) ネットワークサービス (.NET Services) クラウドの RDB(SQL Azure)

Page 6: Using Windows Azure

Windows Azure

Windows Azure Compute Web Role Worker Role

Windows Azure Storage BLOB Table Queue Drive

Page 7: Using Windows Azure

Role

Web Role ウェブアプリケーション向け IIS .NET Framework

Worker Role バッチ処理向け

普通の TCP 通信もできる .NET Framework

Page 8: Using Windows Azure

Storage

BLOB メディアイメージ HTTP REST でアクセス

Table BigTable 的 DB

Queue メッセージキュー

Drive( 未リリース ?) NTFS ドライブ

Page 9: Using Windows Azure

Amazon Web Services EC2

IA サーバ環境を提供 時間貸しレンタルサーバ

ストレージ S3 CloudFront

サービス Elastic Block Storage Relational Database Service SimpleDB Simple Queue Service

Page 10: Using Windows Azure

Google Application Engine 自動的にスケールする 柔軟なデータストア (BigTable) サービス

URL フェッチ メール Memcache 画像操作 cron XMPP 通信

Page 11: Using Windows Azure

Google Application Engine の制約 言語の制約

Python/Java のみ 処理機能の制約

サーブレットによる 30 秒以上を要するリクエスト処理

サーブレットによるレスポンス送出時のデータストリーミング

ファイルシステムへの書き込み 外部サーバーへのソケット接続

VM 機能の制約 スレッド生成 ガベージコレクション実行やシステム停止 カスタムクラス・ローダの利用

Page 12: Using Windows Azure

Windows Azure の特性 EC2 と GAE の中間

インスタンスは意識する ただし各インスタンスの直接制御はできない

.NET が基本だが、ネイティブアプリも動作 C/C++ のコードも動く

言語処理系を上げてしまえば、なんでも動く !! MySQL/memcached も動く

Page 13: Using Windows Azure

開発環境 VisualStudio

Microsoft Visual Web Developer 2008 Express Edition

Eclipse Azure SDK

Page 14: Using Windows Azure

Azure Platform Interoperability

Windows Azure Tools for Eclipse PHP / Java などとの Interoperability に

も注力 http://www.microsoft.com/windowsazure/

interop/

Page 15: Using Windows Azure

Azure の開発フロー Visual Studio / Eclipse で開発

ビルドも ローカルテスト環境にデプロイ Azure にデプロイ

Staging で確認 Prodution に展開

Page 16: Using Windows Azure

LL 言語系 Web 屋から観点 .NET の世界

C# という言語がある IIS ってなんだ

Internet Information Services IDE に抵抗がある

統合開発環境 Eclipse / Visual Studio

Page 17: Using Windows Azure

Azure への期待 クラウドプレイヤーの増加

AWS vs GAE vs Azure 競争促進

ロックインの排除 アプリレイヤーとクラウドレイヤーの疎結合

化 Azure は、 GAE ほど極端ではない

Page 18: Using Windows Azure

Azure の開発フロー (LL 言語向け )

Emacs / vi で開発 コマンドラインでビルド

IDE だとよく分からない

Page 19: Using Windows Azure

簡単な Azure アプリ

/ProjectRoot/ WebRole/ index.html simple.csdef .. クラウド・サービス定義ファイル simple.cscfg .. クラウド・サービス構成ファイル

Page 20: Using Windows Azure

簡単な Azure アプリ simple.csdef クラウド・サービス定義

ファイル<?xml version="1.0" encoding="utf-8"?><ServiceDefinition name="Simple" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition"> <WebRole name="WebRole"> <ConfigurationSettings> </ConfigurationSettings> <InputEndpoints> <!-- Must use port 80 for http and port 443 for https when running in the cloud --> <InputEndpoint name="HttpIn" protocol="http" port="80" /> </InputEndpoints> </WebRole></ServiceDefinition>

Page 21: Using Windows Azure

簡単な Azure アプリ simple.cscfg クラウド・サービス構成

ファイル

<?xml version="1.0"?><ServiceConfiguration serviceName="Simple" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration"> <Role name="WebRole"> <Instances count="1"/> <ConfigurationSettings> </ConfigurationSettings> </Role></ServiceConfiguration>

Page 22: Using Windows Azure

簡単な Azure アプリ index.html

<html> <head><title>Quick Sample</title></head> <body> This a quick sample. <br /> <img alt="Sample Photo" src="photo.jpg" /> </body></html>

Page 23: Using Windows Azure

簡単な Azure アプリ ビルド

デプロイ

>cspack simple.csdef /copyonlyWindows(R) Azure(TM) Packaging Tool version 1.0.0.0for Microsoft(R) .NET Framework 3.5Copyright (c) Microsoft Corporation. All rights reserved.

>csrun simple.csx simple.cscfgWindows(R) Azure(TM) Desktop Execution Tool version 1.0.0.0for Microsoft(R) .NET Framework 3.5Copyright (c) Microsoft Corporation. All rights reserved.Using session id 1Created deployment(34)Started deployment(34)Deployment input endpoint HttpIn of role WebRole at http://127.0.0.1:82/

Page 24: Using Windows Azure

簡単な Azure アプリ 開発環境にデプロイ

Page 25: Using Windows Azure

簡単な Azure アプリ 動作 !

Page 26: Using Windows Azure

簡単な Azure アプリ 本番

Page 27: Using Windows Azure

PHP on Azure

PHP の言語処理系 (php.exe) を Azure 上に送りこむ ネイティブコードサポート !

Page 28: Using Windows Azure

PHP on Azure

/ProjectRoot/ WebRole/ index.php web.config simple.csdef .. クラウド・サービス定義ファイル simple.cscfg .. クラウド・サービス構成ファイル

Page 29: Using Windows Azure

PHP on Azure

phpsimple.csdef クラウド・サービス定義ファイル

<?xml version="1.0" encoding="utf-8"?><ServiceDefinition name="phpsimple" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition"> <WebRole name="WebRole" enableNativeCodeExecution="true“> <ConfigurationSettings> </ConfigurationSettings> <InputEndpoints> <!-- Must use port 80 for http and port 443 for https when running in the cloud --> <InputEndpoint name="HttpIn" protocol="http" port="80" /> </InputEndpoints> </WebRole></ServiceDefinition>

Page 30: Using Windows Azure

PHP on Azure

phpsimple.cscfg クラウド・サービス構成ファイル

<?xml version="1.0"?><ServiceConfiguration serviceName="phpsimple" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration"> <Role name="WebRole"> <Instances count="1"/> <ConfigurationSettings> </ConfigurationSettings> </Role></ServiceConfiguration>

Page 31: Using Windows Azure

PHP on Azure

index.php

<html><head><title>Hello World PHP</title></head><body><?phpecho 'Today is '. date('Y-m-d') ."\n";?> </body></html>

Page 32: Using Windows Azure

PHP on Azure

web.config<?xml version="1.0"?><configuration> <system.webServer> <handlers> <add name="FastCGIHandler" verb="*" path="*.php" scriptProcessor="%RoleRoot%\approot\PHP\php-cgi.exe" modules="FastCgiModule" resourceType="Unspecified" /> </handlers> <defaultDocument> <files> <add value="index.php"/> </files> </defaultDocument> </system.webServer></configuration>

Page 33: Using Windows Azure

PHP on Azure

web.roleconfig

<?xml version="1.0" encoding="utf-8" ?><configuration> <system.webServer> <fastCgi> <application fullPath="%RoleRoot%\approot\PHP\php-cgi.exe" /> </fastCgi> </system.webServer></configuration>

Page 34: Using Windows Azure

PHP on Azure

ビルド

デプロイ

>cspack phpsimple.csdef /copyonlyWindows(R) Azure(TM) Packaging Tool version 1.0.0.0for Microsoft(R) .NET Framework 3.5Copyright (c) Microsoft Corporation. All rights reserved.

>csrun phpsimple.csx phpsimple.cscfgWindows(R) Azure(TM) Desktop Execution Tool version 1.0.0.0for Microsoft(R) .NET Framework 3.5Copyright (c) Microsoft Corporation. All rights reserved.Using session id 1Created deployment(32)Started deployment(32)Deployment input endpoint HttpIn of role WebRole at http://127.0.0.1:82/

Page 35: Using Windows Azure

PHP on Azure

開発環境にデプロイ

Page 36: Using Windows Azure

PHP on Azure

動作 !

Page 37: Using Windows Azure

PHP & MySQL on Azure

Windows Azure MySQL PHP Solution Accelerator http://code.msdn.microsoft.com/

winazuremysqlphp

MySQL php.exe に加え、 mysql.exe も送りこむ Worker Role で mysql のインスタンスを起動

させる

Page 38: Using Windows Azure

PHP & MySQL on Azure

Windows Azure MySQL PHP Solution Accelerator をダウンロード・展開

PHP, MySQL, PHPMyAdmin などを詰め込む

ディレクトリ構成

Page 39: Using Windows Azure

MySQL を WorkerRole で動かす LocalStorage を定義

(ServiceDefinition.csdef)

<LocalResources> <LocalStorage name="InstMgrLocalStorage" sizeInMB="75" cleanOnRoleRecycle="false" /> <LocalStorage name="MySQL" sizeInMB="75" cleanOnRoleRecycle="false" /> <LocalStorage name="MySQLDatastore" sizeInMB="122880" cleanOnRoleRecycle="false" /> <LocalStorage name="BlobBackup" sizeInMB="2" cleanOnRoleRecycle="false" /></LocalResources>

Page 40: Using Windows Azure

MySQL を WorkerRole で動かす Wrapper で指定 (MySQLAccess.cs)

public bool Start(int id){ try { string baseDir = RoleEnvironment.GetLocalResource("MySQL").RootPath.Replace('\\', '/'); string dataDir = RoleEnvironment.GetLocalResource("MySQLDatastore").RootPath.Replace('\\', '/'); string blobDir = RoleEnvironment.GetLocalResource("BlobBackup").RootPath.Replace('\\', '/');

File.Copy("my.ini", iniFile, true); //update teh my.ini file with mysql server details UpdateMyIni(iniFile, baseDir, dataDir, port, id.ToString());

Page 41: Using Windows Azure

PHP & MySQL on Azure

Page 42: Using Windows Azure

PHP & MySQL on Azure

Page 43: Using Windows Azure

Mediawiki on Azure

Windows Azure Mediawiki MySQL Solution Accelerator http://code.msdn.microsoft.com/

winazuremediawiki 基本的には、 Windows Azure MySQL PHP

Solution Accelerator と同等

Page 44: Using Windows Azure

Mediawiki on Azure

memcached を動かす MySQL と 同 様 に Worker Role + C# の

Wrapperprotected void RunMemcached() { IPEndPoint endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["memcached"].IPEndpoint; string cacheSize = RoleEnvironment.GetConfigurationSettingValue("CacheSizeInMB"); string arguments = "-m " + cacheSize + " -l " + endpoint.Address + " -p " + endpoint.Port; ProcessStartInfo startInfo = new ProcessStartInfo();… try { using (Process exeProcess = Process.Start(startInfo)) { exeProcess.WaitForExit();

Page 45: Using Windows Azure

Mediawiki on Azure

Page 46: Using Windows Azure

その他 Ruby on Rails on Azure

FastCGI 対応のものは動かせる Ruby on Rails も http://rubyonrails.cloudapp.net

Page 47: Using Windows Azure

まとめ Azure を試してみた

LL 系言語アプリも十分動かせる Amazon EC2 の対抗として十分なポテン

シャルがありそう

ただし、もうすこし UNIX-like な開発環境があると親和性が高くなる OSX な開発者もいるので ..