2014年5月10日 星期六

[Linux] 使用 Nagios 監控 AWS EC2、RDS 服務狀況 @ Ubuntu 12.04

雖然 AWS 已經有不錯的服務監控系統,但原先已經用 Nagios 監控服務,就順手研究一下對於 EC2、RDS 的監控吧。

由於資安角度,預設都不給 PING 的,此外 RDS (此例是 MySQL port 3306) 則只開放特定 TCP Port 而已,對 Nagios 而言,就可以改測試 TCP Port (HTTP,HTTPS,SSH) 等用法,如此一來就可以解決 Host is Down 囉。

define host {
        host_name aws-rdb
        alias aws-rdb-dns
        address aws-rdb-dns
        use rdb-host
        contact_groups db-services
}

define host {
        host_name aws-dev
        alias aws-dev-dns
        address aws-dev-dns
        hostgroups ssh-servers,http-servers
        use ec2-host
        contact_groups pc-services
}

define command {
        command_name check-rds-host-alive
        command_line /usr/lib/nagios/plugins/check_tcp -H $HOSTADDRESS$ -p 3306
}

define command {
        command_name check-ec2-host-alive
        command_line /usr/lib/nagios/plugins/check_tcp -H $HOSTADDRESS$ -p 80
}

define host{
        name                            rdb-host    ; The name of this host template
        notifications_enabled           1       ; Host notifications are enabled
        event_handler_enabled           1       ; Host event handler is enabled
        flap_detection_enabled          1       ; Flap detection is enabled
        failure_prediction_enabled      1       ; Failure prediction is enabled
        process_perf_data               1       ; Process performance data
        retain_status_information       1       ; Retain status information across program restarts
        retain_nonstatus_information    1       ; Retain non-status information across program restarts
                check_command                   check-rds-host-alive
                max_check_attempts              10
                notification_interval           0
                notification_period             24x7
                notification_options            d,u,r
                contact_groups                  admins
        register                        0       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
        }

define host{
        name                            ec2-host    ; The name of this host template
        notifications_enabled           1       ; Host notifications are enabled
        event_handler_enabled           1       ; Host event handler is enabled
        flap_detection_enabled          1       ; Flap detection is enabled
        failure_prediction_enabled      1       ; Failure prediction is enabled
        process_perf_data               1       ; Process performance data
        retain_status_information       1       ; Retain status information across program restarts
        retain_nonstatus_information    1       ; Retain non-status information across program restarts
                check_command                   check-ec2-host-alive
                max_check_attempts              10
                notification_interval           0
                notification_period             24x7
                notification_options            d,u,r
                contact_groups                  admins
        register                        0       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
        }

[Linux] AWS RDS + PHPMyAdmin + HTTPS + HTTP Basic authentication @ Ubuntu 14.04

為了配合 AWS RDS 而開始用 mysql-server-5.6 ,就試著用 EC2 + Ubuntu 14.04,安裝 PHPMyAdmin 時,採用的 DB 不是在本機的,而是 RDS 上。雖然我也不常用 PHPMyAdmin ,但為了提供其他人使用,所以就來架設一下 XD

$ sudo apt-get install mysql-client-5.6 php5 apache2 apache2-utils git php5-mysql
$ sudo a2ensite default-ssl.conf
$ sudo php5enmod mcrypt
$ sudo service apache2 restart

$ sudo vim /etc/phpmyadmin/config-db.php
// 在底部新增:
$dbuser='rds_account';
$dbpass='rds_password';
$dbserver='rds_location';

$ sudo vim /etc/phpmyadmin/config.inc.php

// 採用 HTTP Basic authentication
//$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['auth_type'] = 'http';

// ...
// 最底層加上強制 HTTPS
$cfg['ForceSSL'] = true;


如此一來,使用 http://hostname/phpmyadmin 時,就會強制轉成 https://hostname/phpmyadmin,並且會採用 HTTP Basic authentication 機制。

註:不知為何,採用 HTTP Basic authentication 機制時,logout 後再進行 login 時,url後面會帶有 old_usr 資訊時,無法正常登入,所以後來就放棄了 XD

2014年5月7日 星期三

AWS 筆記 - 使用 Amazon EC2 進行 Deploying Web services

稍微把玩 AWS Elastic Load Balancing 跟 Auto Scaling 後,大概有一點粗淺的心得:
  • 開一台機器,如 micro 等級,並設定這台機器關機也不下線,可專門用於製作 AMI
  • EC2 micro 採用 EBS 管理,每一次製作 AMI 會產生新的 EBS snapshot,記得定時去清理
  • 程式碼若是透過 git 管理,可以在 /etc/rc.local 上設定開機自動更新方式,至少 AMI 不是最新程式碼時也還能堪用(但 git server 掛了就...)
  • 如果想要透過 web cgi 更新,記得把 source tree 的 owner 或 group (搭配775方式) 設定 www-data,可以用 sudo -u www-data /tmp/update.sh 進行測試
AWS Elastic Load Balancing:
  • 使用 AWS ELB 時,可以讓多台機器綁定在固定的 DNS Name,記得需要處理一下多台機器進行切換其 Session/Cookie 問題,例如單純的使用情境,可以透過設定 Stickiness: LBCookieStickinessPolicy, expirationPeriod='600' 等方式來應付等
  • 對於有使用 HTTP Authentication 的 web server 而言,因為帳密是一直隨 browser 傳給 web server 的(就像 cookie一樣),所以 ELB 再切換機器時,不會因機器不同台而再次詢問帳密
AWS Auto Scaling:
  • 對 Auto Scaling 而言,預設機器都是關機後就下線,除非改掉預設方式,不然更新系統時 reboot 的結果就是開一台新機器,此外,把 Auto Scaling Group 刪掉等同把機器都下線
  • 透過製作新的 AMI 來取代系統更新時,而原先設定好的 Auto Scaling Launch Config 不能更新採用的 AMI,但可透過新增新的 Launch Config 後,更新 Auto Scaling 設定後,再刪掉舊的 Launch config 等

2014年5月6日 星期二

[Linux] 從 Ubuntu 12.04 / MySQL 5.5 升級到 Ubuntu 14.04 / MySQL 5.6 過程 @ Ubuntu 12.04

由於某台機器接近閒置,原本單純想把 MySQL 5.5 升級到 MySQL 5.6 的,後來看一下 Ubuntu 14.04 裡頭有 MySQL 5.6 可以用,就把它升了。

連續過程:

$ sudo do-release-upgrade -d

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04 LTS
Release:        14.04

Codename:       trusty

$ service mysql stop

$ sudo apt-get remove mysql-common mysql-server-5.5 mysql-server-core-5.5 mysql-client-5.5 mysql-client-core-5.5
$ sudo apt-get autoremove

$ sudo apt-get install mysql-server-5.6
$ mysql_upgrade -u root -p


更正規的 MySQL 更新方式是要先把 /var/lib/mysql 跟 /etc/mysql 備份起來才行動的,此處因為機器上的服務已經遷移(在其他處有備份),所以就這樣升了。

2014年5月2日 星期五

iOS 開發筆記 - 使用 AdMob 與 IDFA 的處理



查詢 Admob 的 iOS release notes 可知 Admob 6.5.0 (2013/07/16) 時已經有用到 IDFA 了。但很妙地,上回上傳時沒碰到,但這次更新時又會碰到?這次就試著勾選處理了。

如果在一開始上傳 binary 前選 Dose this app use the Advertising Identifier (No) 時,上傳 binary 時,驗證過程會看到類似的訊息:
Improper Advertising Identifier IDFA Usage. Your app contains the Advertising Identifier IDFA API ...
解法在此刻只能遞交一份空專案,接著在 Reject by developer 後,才能再重新填這張單子。

簡言之,在 Admob 而言,就是勾選三項:
  • Does this app use the Advertising Identifier (Yes)
  • Serve advertisements within the app (checked)
  • Limit Ad Tracking setting in iOS (checked)
不過,話說那最後一條真的是背書啊 Orz 亂用第三方 libraries 挺抖的。