LoginSignup
15
14

More than 5 years have passed since last update.

0円で、ゼロから始めるIBMクラウド生活。

Last updated at Posted at 2018-11-03

お題 : IBM Cloudは、0円開発環境の有力な選択肢なのか?

クラウド後発組の代名詞(?)のIBM Cloud。

前身のBluemix時代から比べると、日本語情報も充実してきた。そして、なんといってもクレカを用意することなくずっと利用できる無料インスタンスがついてくる。

ibm.PNG
 
AWS無料枠のように課金に怯えて生きる(?)必要はないというわけ。
ということで、個人の無料開発環境として、これまでは(AWSの一部となった)Cloud9を使ってきた私が、IBM Cloudをお試ししていく。今の会社での引き継ぎで、AWSのサーバー群の中に混じってなぜだかIBM Cloudベースのサーバーが1台あったためとも言う。

なお、クラウドビジネスの主力化に苦戦中のIBMは、IBM Cloudをなんとか普及させようと、以下のようなコンテンツも用意してくださっている。

itpro.PNG
元記事 : https://special.nikkeibp.co.jp/atclh/ITP/17/ibm1027/

...パット見をキャッチーにしようとしすぎたのか、やたら読みにくいので、上の記事でIBM cloud入門は困難と思われる。...もちろん、IBMなりに頑張っているのは分かるけれど(WatsonやSparkを使えるという意味で、革新的アプリが作れるかもしれないし)。Redhat買収後は会社の株価が下がって大変だ。応援の意味でIBM株を買ってみたら、さらに下がって僕も大変だよ。。株価が下がっても、IBM Cloud無償版は継続してね

IBM cloudにお試しサービス立ててみての感想

....IBMを軽くdisってしまったので、はじめに、3時間ほどいじくってのポジティブな感想を:

そこそこのググり力がある人にとっては、無償環境として、IBM cloud良いかも。固有のコマンドやサービスに深入りしなければIBM cloud、割と便利で普通に使えそうだ。
以下、興味を持った人向けのググり時間を節約するためのメモ:

[1] IBM Cloudライト・アカウントの登録

クレカを用意しなくても良いため、登録時に特に注意するところはないため、略。
それでも流れが気になる人は、以下の記事あたりをちら見しておこう。
https://qiita.com/no13/items/f45909666da48d55bc37

[2] クライアント環境の選択

 AWSなどと比べマイナーなIBM Cloudゆえに、クライアント環境はMacまたはLinuxを選ぶことにする。ここではWindows 10上のWindows Subsystem for Linux(WSL)のubuntu/debianでいく(WSLについては、末尾におまけをつけた。)。

[3] IBM cloudクライアントの導入

他のクラウドと同じくクライアントの導入は簡単だ。
本家の解説(以下)に従うと良い。
https://console.bluemix.net/docs/cli/index.html#getting-started

すなわち、以下のようにして、インストーラーを走らせるだけで良い。

curl -sL https://ibm.biz/idt-installer | bash

私の場合、約3分で導入が終わった。導入後はLinuxにどのようなパッケージが導入されたのか、確認しておいたほうが良いだろう。

確認コマンド例:

sudo dpkg -l > ibm_cloud

以下が結果(の一部)。docker-ceが導入されたことがわかる。

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                          Version                        Architecture Description
+++-=============================-==============================-============-===============================================================================
ii  adduser                       3.115                          all          add and remove users and groups
ii  apt                           1.4.8                          amd64        commandline package manager
ii  apt-transport-https           1.4.8                          amd64        https download transport for APT
ii  apt-utils                     1.4.8                          amd64        package management related utility programs
ii  base-files                    9.9+deb9u5                     amd64        Debian base system miscellaneous files
ii  base-passwd                   3.5.43                         amd64        Debian base system master password and group files
ii  bash                          4.4-5                          amd64        GNU Bourne Again SHell
ii  binutils                      2.28-5                         amd64        GNU assembler, linker and binary utilities
ii  bsdmainutils                  9.0.12+nmu1                    amd64        collection of more utilities from FreeBSD
ii  bsdutils                      1:2.29.2-1+deb9u1              amd64        basic utilities from 4.4BSD-Lite
ii  build-essential               12.3                           amd64        Informational list of build-essential packages
ii  bzip2                         1.0.6-8.1                      amd64        high-quality block-sorting file compressor - utilities
ii  ca-certificates               20161130+nmu1+deb9u1           all          Common CA certificates
ii  coreutils                     8.26-3                         amd64        GNU core utilities
ii  cpio                          2.11+dfsg-6                    amd64        GNU cpio -- a program to manage archives of files
ii  cpp                           4:6.3.0-4                      amd64        GNU C preprocessor (cpp)
ii  cpp-6                         6.3.0-18+deb9u1                amd64        GNU C preprocessor
ii  cron                          3.0pl1-128+deb9u1              amd64        process scheduling daemon
ii  curl                          7.52.1-5+deb9u8                amd64        command line tool for transferring data with URL syntax
ii  dash                          0.5.8-2.4                      amd64        POSIX-compliant shell
ii  debconf                       1.5.61                         all          Debian configuration management system
ii  debconf-i18n                  1.5.61                         all          full internationalization support for debconf
ii  debian-archive-keyring        2017.5                         all          GnuPG archive keys of the Debian archive
ii  debianutils                   4.8.1.1                        amd64        Miscellaneous utilities specific to Debian
ii  diffutils                     1:3.5-3                        amd64        File comparison utilities
ii  dmidecode                     3.0-4                          amd64        SMBIOS/DMI table decoder
ii  dmsetup                       2:1.02.137-2                   amd64        Linux Kernel Device Mapper userspace library
ii  docker-ce                     18.06.1~ce~3-0~debian          amd64        Docker: the open-source application container engine
ii  dpkg                          1.18.25                        amd64        Debian package management system

(以下、略)

動作確認としてヘルプを表示。

ibmcloud dev help

NAME:
   ibmcloud dev - A CLI plugin to create, manage, and run applications on IBM Cloud

USAGE:
   ibmcloud dev command [arguments...] [command options]

VERSION:
   2.1.7

COMMANDS:
   build             Build the application in a local container
   code              Download the code from an application
   console           Opens the IBM Cloud console for an application
   create            Creates a new application and gives you the option to add services
   diag              This command displays version information about installed dependencies
   debug             Debug your application in a local container
   delete            Deletes an application from your space
   deploy            Deploy an application to IBM Cloud
   edit              Add or remove services for your application
   enable            Add IBM Cloud files to an existing application.
   get-credentials   Gets credentials required by the application to enable use of connected services.
   list              List all IBM Cloud applications in a space
   run               Run your application in a local container
   shell             Open a shell into a local container
   status            Check the status of the containers used by the CLI
   stop              Stop a container
   test              Test your application in a local container
   view              View the URL of your application
   help              Show help
(以下、略)

IBM cloudの操作で詰まったときには、これらのコマンドを起点にしてググれば良さそう。

[4] サーバー・インスタンスの作成(node.js)

さて、いよいよサーバーを立てる。
IBM cloudライトアカウントの場合、以下のように、ライトlabelが付いたサービスを選択する方式の模様。

らいと.PNG

今風のクラウドらしく、IoT,AI,そして,scalaに力の入っているIBMらしくsparkやakkaベースのFaaS(AWSでいうlambda)などもメニューに存在する。

まずは、ライトアカウントについての以下の制限を確認しておこう。

10日間 開発なしでアプリを自動停止
30日間 活動なしでサービスの自動削除
「組織の作成」画面では、地域に「米国南部」を選択を行う必要があります。
過去にIBM Cloud 30日フリートライアルに登録したメールアドレスは、ライト・アカウントへの登録は行えません。別のメールアドレスにてご登録ください。

30日立つと消えちゃうということだけれど、逆に言えば、お試しサーバーは気に入るまで何回でも作り直して良いということ。

ひとまず、クライアント側を作る際には必要となることが多いnode.js用インスタンスを選択することした。
必要情報入力後、以下のような表示が現れれば、(node.jsの)サーバーが立ち上がったこととなる。
akka.PNG

「アプリURLにアクセス」をクリックすると、(私の場合)『 https://akka2om.mybluemix.net/ 』というURLに遷移し、hello world画面が表示される:

js.PNG

[5] サーバー・インスタンスにログイン

サーバーに入るのは簡単だ。
親切なことに、サーバー管理コンソールの下に以下のような解説記事がついている。
cf.PNG

クラウド慣れしていない人向け : 記事のタイトルがCloud Foundryだったり、使うコマンドがbluemixだったりするのに混乱しないように、IBMのクラウドサービスの名前は、「Cloud Foundry -> (買収)-> bluemix ->IBM cloud」と変遷してきたことを知っておこう。かつてのCloud Foundryは、Javaやってる人ならば、割合と知っていたであろうクラウドサービス。

先ほどのibmcloudクライアントが正しく入っていれば、以下のコマンドで自分のIBM cloudサーバにログインする準備が整う。

ibmcloud api https://api.ng.bluemix.net

Setting api endpoint to https://api.ng.bluemix.net...
OK

API endpoint: https://api.ng.bluemix.net
Not logged in. Use 'bluemix login' to log in.

この後は、ibmcloud(bluemix) loginコマンドで自身のID/パスワードを入れる。
軽くググるに、以下のようなコマンドでログインするようだった。

ibmcloud login -u (登録したメールアドレス) -o (登録したメールアドレス) -s dev

レスポンスの例:

API endpoint: https://api.ng.bluemix.net

Password>(ここでパスワードを入れる)
Authenticating...
OK

Targeted account Nimsuruo's Account (e..(略)..7e1)

Targeted resource group Default

Targeted Cloud Foundry (https://api.ng.bluemix.net)

Targeted org (登録したメールアドレス)

Targeted space dev


API endpoint:      https://api.ng.bluemix.net
Region:            us-south
User:              (登録したメールアドレス)
Account:           Nimsuruo's Account (e..(略)..7e1)
Resource group:    Default
CF API endpoint:   https://api.ng.bluemix.net (API version: 2.106.0)
Org:               (登録したメールアドレス)
Space:             dev

[6] アプリのデプロイ

ここから先は、本家の以下の解説がわかりやすかった。

IBM cloud(bluemix)向けのテスト用node.jsアプリケーションが用意されている。

git clone https://github.com/isebm/first-bluemix-application.git

構成は以下のような感じ:

first-bluemix-application/
├── app.js
├── manifest.yml
├── models
│   └── memo.js
├── package.json
├── Procfile
├── reference
│   ├── cloudant
│   │   ├── manifest.yml
│   │   ├── memo.js
│   │   └── package.json
│   └── memory
│       ├── manifest.yml
│       ├── memo.js
│       └── package.json
├── routes
│   └── index.js
└── views
    ├── dialog.ejs
    └── index.ejs

この中で、まずは、「manifest.yml」に自身のサイトのホスト名を書き換えるのがお作法。

manifest.yml
applications:
- name: MemoApp
disk_quota: 1024M
memory: 128M
host: <ホスト名>
domain: mybluemix.net
command: node app.js
path: .
instances: 1

私の場合、ホスト名を「akka2om」として、以下のコマンドでサーバーにpushした。

ibmcloud app push

順調にアップロードは進み、サービス起動が始まるのだが....

Invoking 'cf push'...

Pushing from manifest to org (私のメアド) / space dev as (私のメアド)...
Using manifest file /mnt/d/deb/ibmcld/first-bluemix-application/manifest.yml

Deprecation warning: Specifying app manifest attributes at the top level is deprecated. Found: command, disk_quota, domain, host, instances, memory, path.
Please see http://docs.cloudfoundry.org/devguide/deploy-apps/manifest.html#deprecated for alternatives and other app manifest deprecations. This feature will be removed in the future.

Using manifest file /mnt/d/deb/ibmcld/first-bluemix-application/manifest.yml

Updating app MemoApp in org (私のメアド) / space dev as (私のメアド)...
OK

Using route akka2om.mybluemix.net
Uploading MemoApp...
Uploading app files from: /mnt/d/deb/ibmcld/first-bluemix-application
Uploading 7.4K, 19 files
Done uploading
OK

Starting app MemoApp in org (私のメアド) / space dev as (私のメアド)...

以下のエラーが出た。

FAILED
Error restarting application: Server error, status code: 400, error code: 100005, message: You have exceeded your organization's memory limit: app requested more memory than available

ディフォルトの設定で、メモリ割り当てに失敗してしまう!?
もしや,池〇あ〇かさんのために広告費をかけた分、無償枠のメモリが最近半減(512M->256M)されたためか...と一瞬思ったが、アプリをpushする際には、サービスを停止させておく必要があるのだった。

image.png

再度,pushするとサービスのビルド情報が流れ、サービスがrunningとなった。

...(サービスのビルド情報)...
requested state: started
instances: 1/1
usage: 128M x 1 instances
urls: akka2om.mybluemix.net
last uploaded: Sat Nov 3 06:29:07 UTC 2018
stack: cflinuxfs2
buildpack: SDK for Node.js(TM) (ibm-node.js-6.14.4, buildpack-v3.22-20180904-1913)

     state     since                    cpu    memory        disk            details
#0   running   2018-11-03 03:30:02 PM   4.0%   26M of 128M   66.5M of 521M

再度,akka2om.mybluemix.netにアクセスすると,無事,メモ帳アプリが走っているのがわかる。
image.png

続く。

お次は、SSHやgitでのつなぎ方を学んでJVMを入れ、Akka-Httpでござるの巻きを予定。 

Windows Subsystem for Linux(WSL)についてのおまけ

(おまけ①)WSLがはじめてという方向けの情報

以下を参照されたし!ubuntuベースの初心者向け良記事です。
Windows10でWSLとVSCodeを使ってプログラミング環境を整える

導入後は、aptをマスターしておいた方が良いので、『aptコマンドチートシート』などを学ぶが吉。

(おまけ②)WSL上でdebianを使う方向け情報

こちらはある程度Linuxの知識のある方向けの、debianベースの良記事です。
https://scratchpad.jp/debian-on-windows10-1/
https://scratchpad.jp/debian-on-windows10-2/

伝統的に、最小限のパッケージしか入っていないdebian。文字通り、「ゼロから始める」派の人におすすめ。debianでは、はじめに自身が必要とするツールを導入する。今回の目的では、以下くらいで良いだろう。

sudo apt install zip unzip git curl tree

(おまけ③)Windows Subsystem for Linux(WSL)で覚えて起きたいトラブル対策Tips

1) Linuxのパスワードを忘れた。=>Windows側からroot成りする。

以下を参考。
https://linuxfan.info/wsl-password-reset
windowsのコンソールで使える、『(linux名) config --default-user (ユーザー名)』(例、debian config --default-user root)というコマンドは覚えて置いて良いだろう。

2) Linuxの環境が肥大化した/汚れてきた。=>Windows側からリセットしてしまう。

Linuxアプリケーション(ここではDebian)のアイコンを右クリック->『その他』->『アプリの設定』をクリックすると、以下のような設定画面が開く。
でぶ.PNG

ここで、リセットボタンを押すと、Linuxをインストール時に戻せる。

15
14
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
14