顯示具有 AWS 標籤的文章。 顯示所有文章
顯示具有 AWS 標籤的文章。 顯示所有文章

2016年4月4日 星期一

[AWS] - S3 Buket 開放對外存取權限

之前使用 EC2 透過 S3 fuse 來 Mount Buket , 但這樣還是透過  EC2 的前端流量 + 內部流量 , 目前把 S3 Buket Mount 到前端的應用層  , 前端的圖層 Url 直接透過 S3 的 Web Hosting 來做使用讀取 Ex. https://xxxbuketname.s3.amazonaws.com/xxfilename.jpg

後台介面目前只能針對一各檔案去開放存取 , 如果要大量 , 需使用 Policy 政策來使用

官方文件有說明 :  https://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html

{
  "Version":"2012-10-17",
  "Statement":[
    {
      "Sid":"AddPerm",
      "Effect":"Allow",
      "Principal": "*",
      "Action":["s3:GetObject"],
      "Resource":["arn:aws:s3:::examplebucket/*"]
    }
  ]
}

2016年3月9日 星期三

[SMTP] - EDM Email Service 架設

最近有個需求是透過 AWS EC2 的一個 instance 來建照一台可以讓同各 subnet 的機器 ,
發 EDM 的 Email Server
採用 Ubuntu + Postfix 來處理

由於網域 xxx.com.tw 是讓 Godaddy 來管理 , 所以要先去 Godadday
新增一筆 MX

; For further information, please consult the BIND documentation
; located on the following website:
;
; http://www.isc.org/
;
; And RFC 1035:
;
; http://www.ietf.org/rfc/rfc1035.txt
;
; Please note that we do NOT offer technical support for any use
; of this zone data, the BIND name server, or any other third-
; party DNS software.
;
; Use at your own risk.

; SOA Record
xxx.com.tw. 600 IN SOA ns15.domaincontrol.com. dns.jomax.net (
2016030802
28800
7200
604800
600
)

; A Records
s1 600 IN A x.x.x.x
s2 600 IN A x.x.x.x
@ 600 IN A x.x.x.x

; CNAME Records
ftp 3600 IN CNAME @
www 3600 IN CNAME @
email 3600 IN CNAME @

; MX Records
@ 3600 IN MX 10 email.xxx.com.tw

; NS Records
@ 3600 IN NS ns16.domaincontrol.com
@ 3600 IN NS ns15.domaincontrol.com

#  apt-get install postfix

# vim /etc/postfix/main.cf

myhostname = ip-172-31-30-43
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = email.xxx.com.tw, xxx.com.tw , localhost  # 遇到任事的可以收
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 172.xx.xx.xx/20  # 准許本機 跟 172的網段可以寄信 , 後續也可以透過  iptables 或 Ec2 的 Security Group 來做
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all
home_mailbox = Maildir/     # 採用一封信件一個檔案

驗證

# telnet  xxx.com.tw 25
Trying 52.x.x.0...
telnet: connect to address 52.xx.xx.0: Connection timed out

要去打開 Ec2 的 Security Group 25 Port



Again

# telnet xxx.com.tw 25
Trying 52.xxx.xxx.0...
Connected to xxx.com.tw.
Escape character is '^]'.
220 ip-172-31-30-43 ESMTP Postfix (Ubuntu)
ehlo localhost
250-ip-172-31-30-43
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
quit
221 2.0.0 Bye
Connection closed by foreign host.

或安裝 mail client tools

# apt-get install mailutils

echo "Message Body" | mail -s "2Message Subject" fifi@xxx.com.tw

透過外部信件 ex. Gmail 寄給  fifi@xxx.com.tw
確認可以收 跟 送信

PS ( 如果寄到 gmail or Yahoo or other mail Server , 有時候要注意反解析網域寄信
不然會檔 , 自己用nslookup 來檢查 或 去跟 ISP 申請  )

收到信件的話會再帳號的 home下多一個 Maildir的目錄
裡面會有寄過來的信件 list

/home/xxx/Maildir
Maildir/
├── cur
├── new
│   ├── 1457580107.Vca01I6193bM206156.ip-172xxxx0-43
│   ├── 1457590218.Vca01I6194eM276640.ip-172xxxxs-43
│   └── 1457591864.Vca01I6194cM347714.ip-172xxxx-43
└── tmp

或看 mail log
# tail -f /var/log/mail.log

Mar 10 07:10:50 ip-172-31-30-43 postfix/smtpd[4088]: disconnect from mail-pf0-f174.google.com[209.85.192.174]
Mar 10 07:10:50 ip-172-31-30-43 postfix/smtp[4060]: F21726193B: to=<txxx@gmail.com>, orig_to=<xxx@xxx.com.tw>, relay=gmail-smtp-in.l.google.com[64.233.187.27]:25, delay=0.91, delays=0.01/0/0.35/0.55, dsn=2.0.0, status=sent (250 2.0.0 OK 1457593837 g24si4022733pfj.91 - gsmtp)
Mar 10 07:10:50 ip-172-31-30-43 postfix/qmgr[1515]: F21726193B: removed



@ Alias 新群組信件帳號 , 驗證

# vim /etc/aliases

# See man 5 aliases for format
postmaster:    root
cs: xxx1@gmail.com,xxx2@gmail.com

# newaliases

echo "Message Body" | mail -s "2Message Subject" cs@xxx.com.tw


2016年3月7日 星期一

[Ubuntu] - 移掉 Web Server Apache2 / Web Script PHP 相關資訊



@Before


root@ip-172-31-30-43:/etc/apache2# curl -LIv https://xxxx.com.tw
HTTP/1.1 200 OK
Date: Mon, 07 Mar 2016 08:02:12 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: PHP/5.5.9-1ubuntu4.14
Content-Type: text/html



# vim /etc/apache2/conf-available/security.conf
ServerSignature Off
ServerTokens Prod

# vim /etc/php5/apache2/php.ini
expose_php = Off

# service apache2 restart

@ After

# curl -LI https://xxxx.com.tw
HTTP/1.1 200 OK
Date: Mon, 07 Mar 2016 08:05:29 GMT
Server: Apache
Content-Type: text/htm





2016年3月1日 星期二

[AWS] - Technical Essentials

90 % > <"


[AWS] - EC2 + S3

@ 到S3後台建立一個 Toky 的 Buket g1101























# sudo -s ( 小心使用 ><" )
# cd /root/
# apt-get install build-essential git libfuse-dev libcurl4-openssl-dev libxml2-dev mime-support automake libtool
# apt-get install pkg-config libssl-dev
# git clone https://github.com/s3fs-fuse/s3fs-fuse
# cd s3fs-fuse/
# ./autogen.sh
# ./configure --prefix=/usr --with-openssl
# make
# make install

# vim /etc/passwd-s3fs
#<AWS Access Key ID>:<AWS Secret Access Key>
AxxxxxxxxxxxxxxUA:vxxxxxxxxxxxxxxx+1






# chmod 640 /etc/passwd-s3fs
# mkdir /tmp/cache
# chmod 777 /tmp/cache
# mkdir /mnt/s3
# s3fs -o use_cache=/tmp/cache g1101 /mnt/s3

@ 查看 >< 有 256T
# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            492M   12K  492M   1% /dev
tmpfs           100M  348K   99M   1% /run
/dev/xvda1      7.8G  1.6G  5.9G  21% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none            5.0M     0  5.0M   0% /run/lock
none            497M     0  497M   0% /run/shm
none            100M     0  100M   0% /run/user
s3fs            256T     0  256T   0% /mnt/s3


@ 如果要讓這個目錄可以讓 web User ( apache or www-data  )  存取到
要加上 allow_other

# s3fs -o allow_other,use_cache=/tmp/cache g1101 /mnt/s3

@ 自動開機 mount 加到 fstab or 寫到 /etc/rc.local

# vim /etc/fstab
s3fs#mybucket /mnt/s3 fuse allow_other,use_cache=/tmp/cache 0 0

@ Umount S3 Drive

# fusermount -u /mnt/s3

2016年2月26日 星期五

[AWS] - 手動 Clone EC2 Instance

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



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



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




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


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 下來看看