Download - Cloud Foundry: Open Platform as a Service
Cloud Foundry:Open Platform as a Service
日本Cloud Foundryグループ車谷駿介
内容は個人的見解を示したもので,所属先等との関係は一切ありません.
whoami
• 日本Cloud Foundryグループ• 普段は研究開発に従事
– Cloud FoundryひいてはPaaS– (勝手に)分散処理する技術– スマートフォン向けのシンクライアント技術
2
Agenda
• Platform as a Serviceの嬉しさ• Open PaaS• 実際にWeb AppをPaaSで動かす
3
Platform as a Service?
• より汎用的なSaaS
SaaS PaaS IaaS ネットワーク,ストレージ,等
仮想化技術
サーバOS
データ ランタイム,フレームワーク
アプリケーション
4
SaaS
Why not SaaS?
• 制約なくアプリケーションを開発したい
PaaS ネットワーク,ストレージ,等
仮想化技術
サーバOS
データ ランタイム,フレームワーク
アプリケーション
5
Why not IaaS?
• “動作環境”はお任せしたい
PaaS IaaS ネットワーク,ストレージ,等
仮想化技術
サーバOS
データ ランタイム,フレームワーク
アプリケーション
6
Proprietary PaaS
• Force.com• GAE• Azure• AWS Elastic Beanstalk• DotCloud• MOGOK• etc.
7
Open PaaS!
• Cloud Foundry– https://github.com/cloudfoundry
• OpenShift– https://github.com/openshift
• Cloudify– https://github.com/CloudifySource
• Nodester– https://github.com/nodester
8
Why choose “Open” PaaS?
• “動作環境”を縛られたくない
PaaS ネットワーク,ストレージ,等
仮想化技術
サーバOS
データ ランタイム,フレームワーク
アプリケーション
9
Open PaaSの言語対応状況Cloud Foundry OpenShift Cloudify
Erlang(rebar) ○Java 1.6 ○ (Tomcat6) ○ (JBoss 7.1) ○(multiple).NET ○Node.js 0.4.x ○ △Node.js 0.6.x ○ ○ △Perl 5 ○ (mod_perl) △PHP 5 ○ (mod_php) ○ (mod_php) ○(mod_php)Python(WSGI) ○ ○ △Ruby 1.8.x ○ ○ △Ruby 1.9.x ○ △Scala(Lift,Play) ○ △ (自力でlib読込) △任意言語追加 ○ (DIY) ○
10
Open PaaSのRDBMS対応状況
11
Cloud Foundry OpenShift CloudifyHSQLDB ○MySQL ○ ○ ○PostgreSQL ○ ○ ○VoltDB ○
Open PaaSのNoSQL対応状況
12
Cloud Foundry OpenShift CloudifyKVS
Cassandra ○Memcached ○
ドキュメント指向CouchDB ○MongoDB ○ ○ ○Redis ○ ○
グラフNeo4J ○
Open PaaSのその他対応状況
13
Cloud Foundry OpenShift CloudifyMQ
ActiveMQ ○RabbitMQ ○
大規模処理Hadoop ○
全文検索Elasticsearch ○Solr ○
その他Worker ○ (standalone) ○ (worker)任意の拡張 ○
Cloud Foundry based PaaS
• Stackato (ActiveState)– http://www.activestate.com/stackato
• Iron Foundry (Tier 3)– http://www.ironfoundry.org
• AppFog– http://www.appfog.com
• PaaS.io– http://paas.io
14
必要なもの
• Cloud Foundryの動作環境– どこかのサービスにアカウントを用意– あるいは自前
• 弄り回すためのちょっとした知識– ランタイムやフレームワーク,DB類– APIs– 癖
15
動作環境を自前で用意• Micro Cloud Foundry
– 環境構築済みのVMイメージ• vcap/dev_setup
– https://github.com/cloudfoundry/vcap/tree/master/dev_setup
– 依存ツールの状況次第で異常終了する場合も• うまく行かなかったらCoffee break!
• BOSH等によって管理しつつデプロイ– https://github.com/cloudfoundry/bosh
16
CUI
• VMC: The VMware Cloud CLI– https://github.com/cloudfoundry/vmc– `gem install vmc [--pre]` or
`apt-get install cloudfoundry-client̀– `vmc help [command]`
$ vmc target http://api.cloudfoundry.comSuccessfully targeted to [http://api.cloudfoundry.com]
$ vmc login Attempting login to [http://api.cloudfoundry.com]Email: [email protected]: ********Successfully logged into [http://api.cloudfoundry.com] 17
適当なアプリケーションを用意$ git clone git://github.com/cloudfoundry/vcap-test-assets.git$ cd vcap-test-asset/java_web/java_tiny_app$ vi ...
↓
protected void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException {
res.setContentType("text/plain");res.setStatus(200);PrintWriter out = res.getWriter();out.println(
System.getenv("VCAP_APP_HOST") +":" + System.getenv("VCAP_APP_PORT"));
out.close(); }
18
デプロイ↓
$ cd YOUR_APPS_DIR$ mvn package$ cd target # Java Webの場合,*.warのあるディレクトリ$ vmc pushWould you like to deploy from the current directory? [Yn]: Application Name: javawebmeetscfDetected a Java Web Application, is this correct? [Yn]: Application Deployed URL [javawebmeetscf.cloudfoundry.com]: Memory reservation (128M, 256M, 512M, 1G, 2G) [512M]: How many instances? [1]: Bind existing services to 'javawebmeetscf'? [yN]: Create services to bind to 'javawebmeetscf'? [yN]: Would you like to save this configuration? [yN]:
↓
19
起動完了↓
Creating Application: OK
Uploading Application:Checking for available resources: OKPacking application: OKUploading (5K): OK
Push Status: OKStaging Application 'javawebmeetscf': OK Starting Application 'javawebmeetscf': OK
$ vmc apps
+----------------+----+---------+---------------------------------+----------+| Application | # | Health | URLS | Services |+----------------+----+---------+---------------------------------+----------+| javawebmeetscf | 1 | RUNNING | javawebmeetscf.cloudfoundry.com | |+----------------+----+---------+---------------------------------+----------+
20
インスタンスを増やす$ vmc instances javawebmeetscf 2Scaling Application instances up to 2: OK
$ vmc apps +----------------+----+---------+---------------------------------+----------+| Application | # | Health | URLS | Services |+----------------+----+---------+---------------------------------+----------+| javawebmeetscf | 2 | RUNNING | javawebmeetscf.cloudfoundry.com | |+----------------+----+---------+---------------------------------+----------+
21
環境変数: VCAP_SERVICES{"mongodb-1.8": [{
"name": "ivanmongo", "label": "mongodb-1.8","plan": "free","tags": ["mongodb", "mongodb-1.8", "nosql"], "credentials": {"hostname": "172.30.48.61", "host": "172.30.48.61","port": 25067,"username": "何らかのUUID", "password": "何らかのUUID","name": "何らかのUUID","db": "db" }}]}
22
環境変数: VCAP_APPLICATION
{"instance_id": "16進値", "instance_index": 0,"name": "showenvs","uris": ["showenvs.cloudfoundry.com"],"users": [“[email protected]"],"version": "bc5c7351500267c234e659b0f978b530bc6fdf28-1","start": "2012-05-24 06:45:19 +0000","runtime": "ruby18","state_timestamp": 1337841919,"port": 6539,"limits": {"fds": 256, "mem": 134217728, "disk": 2147483648},"host": "172.30.50.22"}
23
GUI (Eclipse Extension)
• [Help]>[Eclipse Marketplace...]– 但し,対応プロジェクトは
Java Web (Servlet Spec 2.5),Spring, Grails, Liftのみ
24
接続先の設定 (1)
1. [Window]>[Show View]>[Servers]2. “new server wizard”
↑ホストはlocalhostのまま
25
接続先の設定(2)
↑必要に応じて変更
↓Finish
26
設定完了
27
概要設定
28
アプリケーション設定
29
アプリケーションの管理
30
サービスの追加
31
Remote System View
• ファイルはインスタンス毎に独立
32
Cloud Foundry Explorer
33
アカウントの追加
34
画面構成は概ね同じ
35
まず知っておくべき”癖”
• ローカルのファイルシステムは非永続的• DB等の接続先は環境変数で与えられる
– 環境変数を直接読むように書き換え– Javaは少々事情が異なる(特にSpring/Play!)
• Tunnelによるデータベースの直接操作– 例: dump済みの既存データの流し込み
• サーバでビルドが必要な物は要注意– gemやnpmのパッケージ”は”よしなに取得
36
cloudfoundry-runtime
• https://github.com/cloudfoundry/vcap-java/tree/master/cloudfoundry-runtime– プロパティ設定用クラスを提供するライブラリ
• たとえばpom.xmlに:
37
<dependency><groupId>org.cloudfoundry</groupId><artifactId>cloudfoundry-runtime</artifactId><version>0.8.1</version>
</dependency>
Springの自動設定
• 同じタイプのサービスは1つに限定される– MySQL, Postgres:
javax.sql.DataSource
– MongoDB:org.springframework.data.document.mongodb.MongoDbFactory
– Redis:org.springframework.data.redis.connection.RedisConnectionFactory
– RabbitMQ:org.springframework.amqp.rabbit.connection.ConnectionFactory
38
Play!の自動設定
• 単一のRDBと接続• db.*.driverをよしなに置換
– production||prodで名前が終わる,バインドされた唯一のサービス
– 唯一バインドされたサービス
39
Java系フレームワーク向けCloud Foundryプラグイン
• Cloud Foundry Maven Plugin– `mvn cf:push`
• Grails Cloud Foundry Plugin– `grails install-plugin cloud-foundry`– `grails cf-*`– grails-app/conf/Config.groovyで設定
40
サービス一覧を表示$ vmc services
============== System Services ==============
+------------+---------+---------------------------------------+| Service | Version | Description |+------------+---------+---------------------------------------+| mongodb | 1.8 | MongoDB NoSQL store || mysql | 5.1 | MySQL database service || postgresql | 9.0 | PostgreSQL database service (vFabric) || rabbitmq | 2.4 | RabbitMQ message queue || redis | 2.2 | Redis key-value store service |+------------+---------+---------------------------------------+
=========== Provisioned Services ============
+----------------+---------+| Name | Service |+----------------+---------+| mysql-e8ccf | mysql || tekito-service | mongodb |+----------------+---------+
41
サービスとの接続$ gem install caldecott # ない場合$ vmc tunnel1: mongodb-794fd2: postgresql-454d3: postgresql-611ee4: redis-47609Which service to tunnel to?: 1Deploying tunnel application 'caldecott'. # 初回だけ(snip.)Getting tunnel connection info: OK
Service connection info: username : 3be0e520-11ed-4af1-b005-c078bcec2da2password : 4de480b9-75e9-4105-9784-6fb50391cd5bname : db
↓
42
mongodump↓
Starting tunnel to tekito-service on port 10001.1: none2: mongodump3: mongo4: mongorestoreWhich client would you like to start?: 2Launching 'mongodump --host localhost --port 10001 -u 20f75687-7917-4c3b-b2a7-54d3443342f4 -p 96bdd18e-e125-4f9c-b74a-64130ab65d24 --db db'
connected to: localhost:10001DATABASE: db to dump/db
db.system.users to dump/db/system.users.bson3 objects
db.system.indexes to dump/db/system.indexes.bson1 objects
krmtn@kcf-workspace:~$ lssystem.indexes.bson system.users.bson 43
mongorestoreStarting tunnel to tekito-service on port 10001.1: none2: mongorestore3: mongodump4: mongoWhich client would you like to start?: 2Directory or filename to restore from: dump/dbLaunching 'mongorestore --host localhost --port 10001 -u 20f75687-7917-4c3b-b2a7-54d3443342f4 -p 96bdd18e-e125-4f9c-b74a-64130ab65d24 --db db dump/db'
connected to: localhost:10001Thu May 24 21:11:14 dump/db/system.users.bsonThu May 24 21:11:14 going into namespace [db.system.users]3 objects foundThu May 24 21:11:14 dump/db/system.indexes.bsonThu May 24 21:11:14 going into namespace [db.system.indexes]Thu May 24 21:11:14 { name: "_id_", ns: "db.system.users", key: { _id: 1 } }1 objects found
44
mongoStarting tunnel to tekito-service on port 10001.1: none2: mongorestore3: mongo4: mongodumpWhich client would you like to start?: 3Launching 'mongo --host localhost --port 10001 -u 20f75687-7917-4c3b-b2a7-54d3443342f4 -p 96bdd18e-e125-4f9c-b74a-64130ab65d24 db'
MongoDB shell version: 2.0.4connecting to: localhost:10001/db>
45
None (SSH接続)Starting tunnel to tekito-service on port 10001.1: none2: mongorestore3: mongodump4: mongoWhich client would you like to start?: 1Open another shell to run command-line clients oruse a UI tool to connect using the displayed information.Press Ctrl-C to exit...
46
まとめ
• PaaSで実行環境やDB周りの構築から開放• Open PaaSが続々• CUI嫌いでも大丈夫?
47