[OpenStack] 透過 DevStack 在 AWS EC2 Linux 上安裝 OpenStack

  1. Create a EC2 instance and login
  2. Create a stack user
$ sudo useradd -s /bin/bash -d /opt/stack -m stack
$ echo “stack ALL=(ALL) NOPASSWD: ALL” | sudo tee /etc/sudoers.d/stack
$ sudo su — stack

3. Download DevStack

git clone https://git.openstack.org/openstack-dev/devstack

4. create a local.conf in project

cd devstack
vim local.conf

然後

[[local|localrc]]
ADMIN_PASSWORD=secret
DATABASE_PASSWORD=$ADMIN_PASSWORD
RABBIT_PASSWORD=$ADMIN_PASSWORD
SERVICE_PASSWORD=$ADMIN_PASSWORD

5. start the install: ./stack.sh. This will take a 15–20 mins. Once the installation done, all is done.

=========================
DevStack Component Timing
(times are in seconds)
=========================
run_process 15
test_with_retry 2
apt-get-update 12
pip_install 287
osc 112
wait_for_service 15
git_timed 193
dbsync 23
apt-get 265
— — — — — — — — — — — — -
Unaccounted time 341
=========================
Total runtime 1265
This is your host IP address: 172.31.21.104
This is your host IPv6 address: ::1
Horizon is now available at http://172.31.21.104/dashboard
Keystone is serving at http://172.31.21.104/identity/
The default users are: admin and demo
The password: secret
WARNING: 
Using lib/neutron-legacy is deprecated, and it will be removed in the future
Services are running under systemd unit files.
For more information see:
https://docs.openstack.org/devstack/latest/systemd.html
DevStack Version: queens
Change: 28b4be186105888b72300d27166deb771857df06 Merge “Make stackenv file visible” 2018–01–03 23:19:46 +0000
OS Version: Ubuntu 16.04 xenial
2018–01–08 05:30:33.155 | stack.sh completed in 1265 seconds.

最後完成的訊息就這樣,就算完成安裝了

– DevStack 已經安裝好 keystone, glance, nova, cinder, neutron, 和 horizon,可以試著輸入指令看看
– Floating IPs will be available, guests have access to the external world.
– 可以試著存取 Web Interface horizon (URL 在最後的安裝訊息中)
– `source devstack/openrc 後會多了一個 openstack 指令來管理 DevStack
– You can cd `/opt/stack/tempest` and run tempest tests that have been configured to work with your devstack.
– You can make code changes to OpenStack and validate them.

Note for Using AWS EC2 Ubuntu 16.04

因為 EC2 是在 AWS VPC 中所建立的 VM,所以預設認知到的網卡也是區網內的 private IP,因此上面所匹配的 IP Address 173.x.x.x 是 private IP,只需要替換成這個 instance 的 Public IP 就可以成功連線到 dashboard portal 了



Deploy Ruby on Rails to EB

Creation

從 GitHub 下載 zip 後
直接在建立頁面的 console 去上傳 bundle
並且在創建頁面選擇『配置更多選項』

  1. 設定 RDS 為 postgres
  2. 網路的部分先不用動
    => see Error 2
  3. 安全性那邊要設定 key pair,不然 EC2 建立起來以後你會沒辦法連入

note

  1. 在這邊的 SG 和 Key pair 都無法創建新的,都要先個別創建好(both in EC2 console)以後直接在這邊選擇
  2. 選擇 SG 要順便選擇 subnet,此 SG 必須在該 subnet 中才行

然後就可以按下創建了
通常在 RDS 要建立一段時間 (t2.micro 約 10)

Errors

Error 1

Creating EIP failed Reason: The maximum number of addresses has been reached.

Result
這樣會導致整個環境建立中斷

Reason
By default, all AWS accounts are limited to five (5) Elastic IP addresses per region, because public (IPv4) internet addresses are a scarce public resource.

Solution
檢查一下 VPC 的 console 會發現多了幾個閒置沒在用的 EIP
可能是之前用 CloudFormation 創建的 stack 沒有 release 或怎麼樣造成的
請先 release,因為 EB 會自動配置一個 EIP

不過如果進入到更多配置選項中,將『公共 IP 地址』勾選,應該就不會再另外配置 EIP 了?

Error 2

Stack named 'awseb-e-xiqatjgnt6-stack' aborted operation. Current state: 'CREATE_FAILED' Reason: The following resource(s) failed to create: [AWSEBEIP, AWSEBSecurityGroup, AWSEBRDSDBSubnetGroup].
Stack named 'awseb-e-eakbx7zmm9-stack' aborted operation. Current state: 'CREATE_FAILED' Reason: The following resource(s) failed to create: [AWSEBEIP, AWSEBRDSDBSubnetGroup].

Reason

  • 如果有自行設定數據庫,例如我設定為 postgres,就會出現這個問題
  • 不設定數據庫配置,僅選擇網路設定,就沒有這個錯誤了

Solution
Need to be found…

Error 3

[Instance: i-080a2bf52fef60b22] Command failed on instance. 
Return code: 18 
Output: (TRUNCATED)...` uses the `git` protocol, which transmits data without encryption. 
Disable this warning with `bundle config git.allow_insecure true`, or switch to the `https` protocol to keep your data secure. 
Your Ruby version is 2.4.3, but your Gemfile specified 2.4.1. 
Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/10_bundle_install.sh failed. 
For more detail, check /var/log/eb-activity.log using console or EB CLI.

Result
這樣的結果 environment creation 已經 complete 了,也可以連到 URL
但是會看到 404

Reason

第一段一直到 “…data secure" 那邊是 warning,不影響創建

第二段的部分從 error log 上看起來是在做 bundle install 時出問題,因為像是 “Your Ruby version is 2.4.3, but your Gemfile specified 2.4.1." 我在本地端也有遇過

各語言與平台版本參考

Solution
重新 deploy,但上傳的 source code 中要把 Gemfile 裡的 Ruby version 改一下,就可以了

Error 4

解決了上面四個 error,application 創建起來後,連結到 URL 去卻出現 403 Forbidden

Reason
有一說是因為我把 source code 放在一個資料夾下壓縮,這篇提到的解決方法『To Change document root, go to EBS console>Application>configuration>Software configuration and change the “Document root" under “container options"』我找不到 Document root 這個項目

Solution
嘗試重新部署,但是將檔案直接全部選取後壓縮,而不是放在一個資料夾下再壓縮

  • 改用 CLI create env 建立 application,因為是進到根目錄,所以不會有 Error 4
  • 改用 將檔案直接全部選取後壓縮,而非放在一個資料夾下載壓縮的方法,也不會有 Error 4

Error 5

解決 Error 4 後:

[Instance: i-041a0372896a104fa] Command failed on instance. 
Return code: 11 
Output: (TRUNCATED)...
Git error: command `git clone 'git://github.com/galetahub/ckeditor.git' "/opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/cache/bundler/git/ckeditor-1e597c7ed96f11acd685d7666693f84cdb86ef8c" --bare --no-hardlinks --quiet` in directory /var/app/ondeck has failed. 
Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/10_bundle_install.sh failed. 
For more detail, check /var/log/eb-activity.log using console or EB CLI.

Result
application 一樣有起起來,但是開啟 URL 會出現:502 Bad Gateway

Reason
這看起來是 git 直接去抓 github 上的 CKEditor 套件失敗的問題

ssh 進去主機看 /var/log/eb-activity.log

  Don't run Bundler as root. Bundler can ask for sudo if it is needed, and
  installing your bundle as root will break this application for all non-root
  users on this machine.
  The git source `git://github.com/galetahub/ckeditor.git` uses the `git` protocol, which transmits data without encryption. Disable this warning with `bundle config git.allow_insecure true`, or switch to the `https` protocol to keep your data secure.
  Fetching git://github.com/galetahub/ckeditor.git
  sh: git: command not found

  Retrying `git clone 'git://github.com/galetahub/ckeditor.git' "/opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/cache/bundler/git/ckeditor-1e597c7ed96f11acd685d7666693f84cdb86ef8c" --bare --no-hardlinks --quiet` due to error (2/4): Bundler::Source::Git::GitCommandError Git error: command `git clone 'git://github.com/galetahub/ckeditor.git' "/opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/cache/bundler/git/ckeditor-1e597c7ed96f11acd685d7666693f84cdb86ef8c" --bare --no-hardlinks --quiet` in directory /var/app/ondeck has failed.sh: git: command not found

  Retrying `git clone 'git://github.com/galetahub/ckeditor.git' "/opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/cache/bundler/git/ckeditor-1e597c7ed96f11acd685d7666693f84cdb86ef8c" --bare --no-hardlinks --quiet` due to error (3/4): Bundler::Source::Git::GitCommandError Git error: command `git clone 'git://github.com/galetahub/ckeditor.git' "/opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/cache/bundler/git/ckeditor-1e597c7ed96f11acd685d7666693f84cdb86ef8c" --bare --no-hardlinks --quiet` in directory /var/app/ondeck has failed.sh: git: command not found

  Retrying `git clone 'git://github.com/galetahub/ckeditor.git' "/opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/cache/bundler/git/ckeditor-1e597c7ed96f11acd685d7666693f84cdb86ef8c" --bare --no-hardlinks --quiet` due to error (4/4): Bundler::Source::Git::GitCommandError Git error: command `git clone 'git://github.com/galetahub/ckeditor.git' "/opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/cache/bundler/git/ckeditor-1e597c7ed96f11acd685d7666693f84cdb86ef8c" --bare --no-hardlinks --quiet` in directory /var/app/ondeck has failed.sh: git: command not found

  Git error: command `git clone 'git://github.com/galetahub/ckeditor.git'
  "/opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/cache/bundler/git/ckeditor-1e597c7ed96f11acd685d7666693f84cdb86ef8c"
  --bare --no-hardlinks --quiet` in directory /var/app/ondeck has failed. (Executor::NonZeroExitStatus)


[2018-01-04T03:04:38.118Z] INFO  [2316]  - [Application deployment test3-source@1/StartupStage0/AppDeployPreHook/10_bundle_install.sh] : Activity failed.
[2018-01-04T03:04:38.118Z] INFO  [2316]  - [Application deployment test3-source@1/StartupStage0/AppDeployPreHook] : Activity failed.
[2018-01-04T03:04:38.118Z] INFO  [2316]  - [Application deployment test3-source@1/StartupStage0] : Activity failed.

可以看到問題跟輸出的 error log 差不多,就是 ckeditor 的問題
但在仔細看一下,有一行sh: git: command not found,然後後面幾個下載步驟都出現這個問題
回到 shell 試著下指令 git 發現果然沒有安裝 git
因此問題不是出在 ckeditor 的 repo,而是這個步驟中需要的工具 git 沒有安裝

Solution
參考到這一篇,進入到『Configure/Software Configuration』,新增兩個 ENV Vairables

  • BUNDLE_DISABLE_SHARED_GEMS: 1
  • BUNDLE_PATH: vendor/bundle

儲存以後,EB 會自動更新環境,更新完以後就沒事了,但你去看 error.log 問題其實沒解決

git command not found 那個問題用 work around:

  1. 先 ssh 進去安裝 git
  2. 然後重新打包後上傳部署
    => Console 的不知道出什麼問題,還是會出現 404 且log 中沒有 nginx 和 puma,先放棄
    => CLI 的 log 終於出現 puma

Error 6

(EB Console)解決 Error 5 後連線到 URL:

(EB CLI)解決 Error 5 後連線到 URL:

EB CLI Deployment

Steps

  1. cd <project>
  2. eb init 這個步驟除了創建 EB 環境,也會詢問要不要使用 CodeCommit,如果選擇要,就會順便建立一個 master branch 並推上 CodeCommit
  3. eb create <environment name>
  4. (eb deploy 等到你確定要 deploy 時使用,更新新的修改也要用這個)
  5. eb open

issues

  1. 為什麼用 Console 的沒有辦法使用 puma?
  2. git command not found 的問題怎麼解?
  3. 為什麼用 Console 是 404,用 CLI 是 502?
  4. 為什麼沒辦法在創建時順便建立 RDS? 是因為 production 資料安全問題?

Rails 透過 EB console 上傳的 source code 都會放在 /var/app 底下
最新的版本會是在 /var/app/current 中
後面上傳的會更新在 /var/app/ondeck 中
但不太知道為什麼沒有覆蓋掉 current?

而所有 eb 相關的 log 都放在 /var/log 中

最後的問題似乎是
因為我看 puma.log 竟然還是去讀取 /var/app/current/config/environment
然而這個檔案竟然不存在
因為新上傳的檔案沒有覆蓋掉 current
都放在 ondeck

好像如果是用 CLI
輸入 eb deploy 會自動幫我們做這件事
但不知道為什麼在 Console 的 upload and deploy 那邊沒有

AWS SNS 發送一封最簡單的簡訊

  1. 點選左邊選單的『Text message (SMS)』,點選最下面的『Publish text message』


2. 輸入 (Mobile) Number 和 Message (最多 70 個字),Message type 先預設,Sender ID 先留白


3. 按下『Send text message』後就送出了!


  • 不需要申請一支門號,也不需要預繳費用就可以發送簡訊!
  • 速度超快,送出後半秒鐘就收到了!

Message Type

  • Promotional —不是那麼重要的訊息,例如廣告簡訊,AWS 會最佳化簡訊內容來獲得較好的傳輸效率
  • Transactional —重要的訊息,例如與客戶交易相關的內容(one-time passcodes),AWS 會最佳化簡訊內容來達到較好的可靠度

Sender ID

The sender ID is displayed as the message sender on the receiving device. For example, you can use your business brand to make the message source easier to recognize.

根據說明,這個資料主要是用來顯示簡訊發送者是誰,如此一來收到簡訊就會顯示特定發送者,而非隨機號碼,但並非所有國家的簡訊接收都支援使用 Sender ID。

Support for sender IDs varies by country. For example, messages delivered to U.S. phone numbers will not display the sender ID. For the countries that support sender IDs, see Supported Regions and Countries.

If you do not specify a sender ID, the message will display a long code as the sender ID in supported countries. For countries that require an alphabetic sender ID, the message displays NOTICE as the sender ID.

This message-level sender ID overrides your default sender ID, which you set on the Text messaging preferences page.

SDK

前面是直接在 AWS SNS console 發送簡訊,而這裡展示的是透過 AWS SDK (Node.js) 來發送簡訊

const AWS = require('aws-sdk')
const sns = new AWS.SNS({ region: 'ap-northeast-1' })
var params = {
Message: '這是透過 Node.js AWS SDK 發送的簡訊',
PhoneNumber: '+88691********'
}
sns.publish(params, (err, data) => {
if (err) console.log(err, err.stack)
else         console.log(data)
})

send

$ node test.js
{ ResponseMetadata: { RequestId: '7a7eb765-5beb-582b-8f3f-e5233feb807e' },
MessageId: '4b39898a-9e0f-522f-872b-dbccfa0f3a7a' }


Fee

查詢:https://aws.amazon.com/tw/sns/sms-pricing/

Taiwan



來比較一下 Twilio 和 nexmo

Twilio


nexmo


應該是 AWS SNS 明顯便宜一點,而且 Twilio 需要先購買一支 1 USD/month 的手機門號,nexmo 則是 € 0.0442 /month ( = 1.57210193 NTD/month)

Reference

http://docs.aws.amazon.com/sns/latest/dg/SMSMessages.html
http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#publish-property
http://docs.aws.amazon.com/sns/latest/dg/sms_supported-countries.html