2016年4月19日 星期二

2016年4月18日 星期一

[Nginx] - Virtual Host + Gzip

無法查看此摘要。請 按這裡查看文章。

[VPS] - 當 Demo & Backup & 翻牆 Shadowsock ... etc Server

最近購買了一個小型的 VPS  https://my.frantech.ca/cart.php
LV BuyVM-128MB  , 兩年才 30 塊美金 , 很划算
機房在 Las Vegas美西 , 對於台灣的回應時間平均 17xms,
尚可接受 ><" , 不然日本或新加坡機房對台灣的 latency 比較友善

64 bytes from vps.raptornode.com (209.xx.xx.71): icmp_seq=1 ttl=54 time=172 ms
64 bytes from vps.raptornode.com (209.xx.xx.71): icmp_seq=2 ttl=54 time=174 ms
64 bytes from vps.raptornode.com (209.xx.xx.71): icmp_seq=3 ttl=54 time=173 ms

啟用Ubuntu 14.x

ssh 進去後 , 
沒有SWAP 檔 , 自己加上去 ,  
因為要Run Nginx + php + MariaDB + Others

# free -m
                   total       used       free     shared    buffers     cached
Mem:           128        113         14         66          0        105

# 新增 260M
# dd if=/dev/zero of=/var/swapfile bs=1024 count=261440
261440+0 records in
261440+0 records out
267714560 bytes (268 MB) copied, 1.34082 s, 200 MB/s

# /sbin/mkswap /var/swapfile
# /sbin/swapon  /var/swapfile


# Reboot 開機自動啟用
1. 加到 /etc/fstab
2. /etc/rc.local 也可

2016年4月11日 星期一

[Ubuntu] - 切換作業環境語系 zh_TW.UTF-8 & 台北時間

因為使用購買了國外的 VPS , 預設裝起 Ubuntu 14.x 
locale 都是英文 , 時間也是UTC 
整各要切換回自己熟悉的工作環境 zh_TW.UTF-8 

0. 調整時間 Asia/Taipei
# sudo dpkg-reconfigure tzdata

1. 新增語系定義

# sudo vim /var/lib/locales/supported.d/local
zh_TW.UTF-8 UTF-8
zh_TW BIG5


2. 產生語系檔案 
# sudo locale-gen


3. 預設顯示語系 /etc/default/locale
# sudo vim /etc/default/locale

LANG="zh_TW.UTF-8"
LANGUAGE="zh_TW.UTF-8"
LC_NUMERIC="zh_TW.UTF-8"
LC_TIME="zh_TW.UTF-8"
LC_MONETARY="zh_TW.UTF-8"
LC_PAPER="zh_TW.UTF-8"
LC_NAME="zh_TW.UTF-8"
LC_ADDRESS="zh_TW.UTF-8"
LC_TELEPHONE="zh_TW.UTF-8"
LC_MEASUREMENT="zh_TW.UTF-8"
LC_IDENTIFICATION="zh_TW.UTF-8"

4. Logout --> Login ....

Done ~

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