2016年2月26日 星期五

[AWS] - 手動 Clone EC2 Instance

主要是透過後台 Instance --> image --> Create image



然後自訂成 AMI , 也可以修訂此 EBS 的 容量 或 多 volume



然後再去 Lanch Instance  --> My AMIs --> 選擇剛剛自己定義的 AMIs




PS 如果成本考量 , 要記得去刪除 AMI images > <" ~


2016年2月25日 星期四

[SSL] - Ubuntu 14.x Let's Encrypt's + Nginx

使用  Let's Encrypt's 來驗證




# sudo apt-get update


# sudo apt-get install git apt-get update

# apt-get install git bc

# service nginx stop

# git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt

# cd /opt/letsencrypt

# ./letsencrypt-auto certonly --standalone








IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at
   /etc/letsencrypt/live/xlinux.website/fullchain.pem. Your cert will
   expire on 2016-05-24. To obtain a new version of the certificate in
   the future, simply run Let's Encrypt again.
 - If you like Let's Encrypt, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate

   Donating to EFF:                    https://eff.org/donate-le


# vim  /etc/nginx/sites-available/default

# 把 80 port 都倒入到 https 443 port
HTTP 狀態 301/302 說明
301: 要求的網頁已經永久改變網址。此狀態要求用戶端未來在連結此網址時應該導向至指定的 URI。
# 302: 物件已移動,並告知移動過去的網址。針對表單架構驗證,這通常表示為「物件已移動」。
# 要求的資源暫時存於不同的 URI 底下。由於重新導向可能偶而改變,
# 用戶端應繼續使用要求 URI 來執行未來的要求。 
# 除非以 Cache-Control 或 Expires 標頭欄位表示,
# 此回應才能夠快取。

server {
    listen 80;
    server_name xlinux.website;
    return 301 https://$host$request_uri;
    #  rewrite ^ https://xlinux.webiste$request_uri? permanent;
    
}

# 把前面兩行註解掉
server {
        #listen 80 default_server;
        #listen [::]:80 default_server ipv6only=on;

        listen 443 ssl;

        server_name xlinux.website www.xlinux.website;

        ssl_certificate /etc/letsencrypt/live/xlinux.website/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/xlinux.website/privkey.pem;

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';bc

改好後檢查一下設定檔是否 OK

# nginx -c /etc/nginx/nginx.conf -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

# 啟動 Nginx
# server nginx start






















Let's Encrypt's 效期有 90 天  , 但官方網站說 建議60 天就更新

# vim /etc/nginx/sites-enabled/default

新增 location ~ /.well-known { allow all; }

# cd /opt/letsencrypt/

 # ./letsencrypt-auto certonly -a webroot --agree-tos --renew-by-default --webroot-path=/var/www/html -d linux.xxxx -d www.xlinux.xxx Checking for new version... Requesting root privileges to run letsencrypt... /home/ubuntu/.local/share/letsencrypt/bin/letsencrypt --no-self-upgrade certonly -a webroot --agree-twww/html -d www.xlinux.xxxx -d www.xlinux.xxxx IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/www.xlinux.website/fullchain.pem. Your cert will expire on 2016-05-26. To obtain a new version of the certificate in the future, simply run Let's Encrypt again. - If you like Let's Encrypt, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le 

service nginx reload


bulid script

# cp /opt/letsencrypt/examples/cli.ini  /etc/letsencrypt/live/renew.ini

# vim /etc/letsencrypt/live/renew.ini

rsa-key-size = 4096 email = fifixxxxxx@gmail.com domains = xlinux.xxxx, www.xlinux.xxxx webroot-path = /var/www/html


# /opt/letsencrypt/letsencrypt-auto certonly -a webroot --renew-by-default --config /etc/letsencrypt/live/renew.ini


# 撰寫 Cront 自動更新
30 2 * * 1 /xxxxxxxxx >> /var/log/renewal.log


到 Qualys SSL 驗證  https://www.ssllabs.com/

This server supports weak Diffie-Hellman (DH) key exchange parameters. Grade capped to B.





 Weak Diffie-Hellman 問題,Diffie-Hellman 預設長度不夠
使用 openssl 產生 4096 bit tell nginx to use it for DHE key-exchange:

# cd /etc/ssl/certs
# openssl dhparam -out dhparam.pem 4096    ( 這個會跑很久 , 在 AWS haw SSD 上跑要十五分鐘 ...... )
# vim /etc/nginx/sites-enabled/default

server {
        #listen 80 default_server;
        #listen [::]:80 default_server ipv6only=on;

        listen 443 ssl;

        server_name xlinux.website www.xlinux.xxxx;
        ssl_session_cache    shared:SSL:10m;
        ssl_session_timeout 5m;
        ssl_certificate /etc/letsencrypt/live/xlinux.xxxx/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/xlinux.xxxx/privkey.pem;

        ssl_dhparam /etc/ssl/certs/dhparam.pem;
        ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        #ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH'; 
         ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
        add_header Strict-Transport-Security max-age=31536000;






2016年2月24日 星期三

[AWS] - Support Center

忘記大概何時啟用 Usage Free Tier  , 後台也查不到時間
只好寫信去詢問 Supoort Center , ( 鼎新也有類似的 eService 可以使用 , 跟主題無關 > <" )





AWS Support 還有分等級回覆 , 好的服務當然要收費 ~



  • PS 突然想到註冊的時候都會有發信件到註冊 Email , 但 ~~ 就順便測試一下 AWS Support 的威力 :D




檢察了信件 , 於 2016/02/25 PM 11:06回信

回信速度大概九個小時左右

2016年2月23日 星期二

[AWS] - Windows Instance Build


  • AWS 後台建立一個新的 Instances ,
  • 選擇 AWS Markplace 的 AMI 來建立 ( 官方版的比較不會亂來 > <" )

       Type 要選 HVM  ( 透過 CPU VT技術資源 )  比較好的樣子
                 PS  (  PVM的是用軟體模擬 ex. Xen )











建立後使用 Elastic IPs Allocate New Address

  • Security Gruops 新增 RDP  
  • 選擇所做的 key pairs *.pem , 來 decode 出密碼



























  • 打開 Windows RDP Clinet  輸入 Public IP  & 解譯後密碼





















進去Windows 後 再修改 Administrator 的密碼即可
PS ( Windows 版權好像包含在 AMI 建立後的 Instance 有收費依據
http://aws.amazon.com/tw/ec2/faqs/#When_I_import_a_VM_of_Windows_Server_2003_or_2008,_who_is_responsible_for_supplying_the_operating_system_license
)















  • Billing 那邊也會有顯示使用的報表



[AWS] - Billing

昨天把 Instance 關掉 , 今天帳單上面多了

  • Elastic IPs 沒有綁到 Instance 也會扣款 > <"   8hr / $0.04 US















  • 使用 Route53 代管一筆 Domain ,1 HostedZone $0.50 US   ,  70Queries 目前 $0.01 US










  • EC2 目前這個月的  free tier t2.micro ( 750 ) 用了 484 剩下 266
所以開兩台來做測試 ( HA ) ~ 到月底前 (2/28) 一天關閉各一台 ....
是 OK的 > <" (  24  x 6天 ) x 2 台 =  288



     





















   需要 $ 85.14 US / monthly > <"   1美元 = 33.2811928 台幣
     = 2833.4592 TWD  



查了資料 , 有些信用卡刷國外的會有N%的手續費這個也要考量參考 http://echooservice.blogspot.tw/2014/10/aws.html


2016年2月22日 星期一

[AWS] - EC2 + RDS




  • 1. 選擇要用的資料庫
   A. MYSQL 已經可以使用 5.7 的版本,
   B. Amazon 自己的極光 Aurora
      High performance MySQL-compatible, enterprise-class database at 1/10th the cost of
      commercial databases
   C .先選擇使用 MariaDB 來做測試驗證














  • 2. 選定要開發用的 Dev  而不是產品要用的 , 



  •  3. 選定所需要的硬體資源資訊 , Multi-AZ 要選NO , 除非後續公司有必要使用 


  • 4. 從 EC2 instance 測試驗證連接

root@ip-172-31-20-24:/var/www/html/pma# mysql -u root -p -h 172.xx.xx.xx
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 10.0.17-MariaDB-log MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> quit
Bye

  • 5. 好像可以直接 Replication 不知道有沒有類似 node 的概念來做  MMM
         ex.   mariadb galera cluster


  • 6. 還可以選 Destination Region  , 台灣的話就選 東京 或 新加坡




2016年2月21日 星期日

[AWS] - Route53 + EC2 LEMP ( Ubuntu14 + Nginx + PHP5 + MariaDB )

去 Godaddy 逛逛看到了一組 39 元 TWD 網域註冊後 ,
當測試來驗證一下 AWS 的 EC2 + Route53

1. 登入Godaddy 後台 ~到設定




















2. 設定域名伺服器 , 指定到 AWS route53 

NS-298.AWSDNS-37.COM
NS-1931.AWSDNS-49.CO.UK
NS-1226.AWSDNS-25.ORG

NS-992.AWSDNS-60.NET 





















3. 到 AWS Route53 設定一組 IPV4 的 A 紀錄
Ex.   fifi.xlinux.website  xxxxxxxxxxxx
PS ( 大概等了 1個小時以內就生效 )














4. AMI(Amazon Machine Image) 打開  AMI 建立一個  Instance  , 選擇 Ubuntu14











SSD 選擇 General purpose 就好 , 因為不用算 IOPS ( input/output per second ) 費用,

Provision IOP   這種會算費用












5. 到 Elastic IP (EIP) 綁定固定 IP , 不然 Instance Reboot 都會換 IP















6.  設定 SSH 連線
  A. 先建立一組 Key Pairs  xxx.pem
       使用 pietty or putty or xshell   ..etc 來連線
       匯入 xxx.pem 或透過 Linux console   
       ssh -i 'xx.pem'  ubuntu@fifi.xlinux.website

  B. 若要取消 key Pairs  , 編輯 sshd config 

   # vim  /etc/ssh/sshd_config
   PasswordAuthentication YES

   C. 重新啟動 sshd 
    # service sshd restart



7. 到 Security Group 設定防火牆存取 
   打開 icmp 跟 web 的 port
   

     
8. 安裝 LEMP

   A. 安裝 MariaDB 
        # apt-get install mariadb-server
  B. 安裝 Web Nginx 
        # apt-get install nginx
  C. 安裝 PHP FPM
       # apt-get install php5-fpm php5-mysql
       
  D.  設定 PHP FPM  9000 port 啟動
       # vim /etc/php5/fpm/pool.d/www.conf    

       ; listen = /var/run/php5-fpm.sock

       listen = 127.0.0.1:9000

      # service php5-fpm restart


   E. 設定 Nginx 透過 php fpm 運作 script 
       # vim /etc/nginx/sites-enabled/default
              root /var/www/html;
             index index.php index.html index.htm;
         
        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        #
        #       # With php5-cgi alone:
                fastcgi_pass 127.0.0.1:9000;
        #       # With php5-fpm:
                # fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }
         # service nginx restart
      

.... Orz ..  設定了一筆 A 紀錄後 ,
已經被收了 $ 0.01  US 




     




2016年2月18日 星期四

[AWS] - Amazon Cloud Drive

備份檔案很麻煩家裡有 N 顆硬碟 ~ 250G / 320G / 500G / 1T / 2T ...
使用 DropBox 來備份私人檔案 - 每年的費用有點小貴



看到了 ACD 服務 https://www.amazon.com/clouddrive/home,  一年 60美金 ,
Securely store all of your photos, videos, files and documents for just $59.99 per year





目前用起來速度好像還好

但 Windows AP 好陽春 , 還要自己點上 / 下傳 ,
Dropbox 是只要有變動就會偵測

來研究一下使用 Ubuntu 來 Mount 下來看看