跳到主要內容

Google Cloud DNS使用記錄


DNS是網際網路服務上不可或缺的一項服務,Google Cloud Platform上當壖也不能缺少這個服務... 果然在今年度問世了... 這邊介紹整個操作與設定的過程...

Zone的管理

建立DNS Zone


peixindeMacBook-Pro in ~/Downloads
○ → gcloud dns managed-zone create --dns_name="gcp.arecord.us." --description="A zone" "gcp-arecord-us"
Creating {'dnsName': 'gcp.arecord.us.', 'name': 'gcp-arecord-us',
'description': 'A zone'} in easelifes-gcp-project

Do you want to continue (Y/n)?  Y

{
   "creationTime": "2014-04-24T11:32:03.853Z",
   "description": "A zone",
   "dnsName": "gcp.arecord.us.",
   "id": "1595320562141013743",
   "kind": "dns#managedZone",
   "name": "gcp-arecord-us",
   "nameServers": [
   ]
}

檢視Zone是否建立完成


peixindeMacBook-Pro in ~/Downloads
○ → gcloud dns managed-zone list
[
   {
       "creationTime": "2014-04-24T11:32:03.853Z",
       "description": "A zone",
       "dnsName": "gcp.arecord.us.",
       "id": "1595320562141013743",
       "kind": "dns#managedZone",
       "name": "gcp-arecord-us",
       "nameServers": [
           "ns-cloud-d1.googledomains.com.",
           "ns-cloud-d2.googledomains.com.",
           "ns-cloud-d3.googledomains.com.",
           "ns-cloud-d4.googledomains.com."
       ]
   }
]

檢視某個特定Zone下的記錄


peixindeMacBook-Pro in ~/Downloads
○ → gcloud dns managed-zone get gcp-arecord-us
{
   "creationTime": "2014-04-24T11:32:03.853Z",
   "description": "A zone",
   "dnsName": "gcp.arecord.us.",
   "id": "1595320562141013743",
   "kind": "dns#managedZone",
   "name": "gcp-arecord-us",
   "nameServers": [
   ]
}

Record管理

檢視DNS Zone下的記錄(record)


peixindeMacBook-Pro in ~/Downloads
○ → gcloud dns records --zone="gcp-arecord-us" list
[
   {
       "kind": "dns#resourceRecordSet",
       "name": "gcp.arecord.us.",
       "rrdatas": [
           "ns-cloud-d1.googledomains.com.",
           "ns-cloud-d2.googledomains.com.",
           "ns-cloud-d3.googledomains.com.",
           "ns-cloud-d4.googledomains.com."
       ],
       "ttl": 21600,
       "type": "NS"
   },
   {
       "kind": "dns#resourceRecordSet",
       "name": "gcp.arecord.us.",
       "rrdatas": [
           "ns-cloud-d1.googledomains.com. dns-admin.google.com. 0 21600 3600 1209600 300"
       ],
       "ttl": 21600,
       "type": "SOA"
   }
]


編輯DNS記錄


peixindeMacBook-Pro in ~/Downloads
○ → gcloud dns records --zone="gcp-arecord-us" edit
/bin/sh: /usr/bin/mate: No such file or directory
Traceback (most recent call last):
 File "/Users/simonsu/opt/google-cloud-sdk/bin/.././lib/googlecloudsdk/gcloud/gcloud.py", line 105, in <module>
   main()
 File "/Users/simonsu/opt/google-cloud-sdk/bin/.././lib/googlecloudsdk/gcloud/gcloud.py", line 101, in main
   _loader.Execute()
 File "/Users/simonsu/opt/google-cloud-sdk/bin/.././lib/googlecloudsdk/calliope/__init__.py", line 1460, in Execute
   post_run_hooks=self.__post_run_hooks, kwargs=kwargs)
 File "/Users/simonsu/opt/google-cloud-sdk/bin/.././lib/googlecloudsdk/calliope/__init__.py", line 1084, in _Execute
   pre_run_hooks=pre_run_hooks, post_run_hooks=post_run_hooks)
 File "/Users/simonsu/opt/google-cloud-sdk/bin/.././lib/googlecloudsdk/calliope/__init__.py", line 816, in Run
   result = command_instance.Run(args)
 File "/Users/simonsu/opt/google-cloud-sdk/lib/googlecloudsdk/dns/dnstools/records/edit.py", line 48, in Run
   new_change = edit.OnlineEdit(util.PrettyPrintString(changes))
 File "/Users/simonsu/opt/google-cloud-sdk/bin/.././lib/googlecloudsdk/core/util/edit.py", line 58, in OnlineEdit
   shell=True)
 File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 542, in check_call
   raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '/usr/bin/mate -w /var/folders/2v/c5mwdhks52z70sl0sk6t0zgc0000gn/T/tmpVacNiX.txt' returned non-zero exit status 127

插曲 - 安裝textmate並且設定至路徑




Mac的用戶,可以下載TextMate:http://macromates.com/,並安裝至Application folder,然後透過下面指令將mate link到/usr/bin/mate

$ sudo ln -s /Applications/TextMate.app/Contents/SharedSupport/Support/bin/mate /usr/bin/mate

其中,mate需要安裝1.5.11版本,才可以在路徑中找到mate德執行檔... 安裝完之後,再執行一次上面指令,就可以正常編輯DNS記錄檔案...



編輯好後,儲存並關閉,則console會跳轉到執行結束畫面,執行結束會列表目前的record設定狀況,因此在這邊就可以看到剛剛所增加的設定值。

peixindeMacBook-Pro in ~
○ → gcloud dns records --zone="gcp-arecord-us" edit  (After save and close….)
{
   "additions": [
       {
           "kind": "dns#resourceRecordSet",
           "name": "www.gcp.arecord.us.",
           "rrdatas": [
               "192.168.2.10"
           ],
           "ttl": 86400,
           "type": "A"
       },
       {
           "kind": "dns#resourceRecordSet",
           "name": "gcp.arecord.us.",
           "rrdatas": [
               "ns-cloud-d1.googledomains.com. dns-admin.google.com. 1 21600 3600 1209600 300"
           ],
           "ttl": 21600,
           "type": "SOA"
       }
   ],
   "deletions": [
       {
           "kind": "dns#resourceRecordSet",
           "name": "gcp.arecord.us.",
           "rrdatas": [
               "ns-cloud-d1.googledomains.com. dns-admin.google.com. 0 21600 3600 1209600 300"
           ],
           "ttl": 21600,
           "type": "SOA"
       }
   ],
   "id": "1",
   "kind": "dns#change",
   "startTime": "2014-04-24T13:41:59.125Z",
   "status": "pending"
}

測試記錄是否寫入


要確認record是否正常寫入,可以透過gcloud dns records list的方式列表...

peixindeMacBook-Pro in ~
○ → gcloud dns records --zone="gcp-arecord-us" list
[
   {
       "kind": "dns#resourceRecordSet",
       "name": "gcp.arecord.us.",
       "rrdatas": [
           "ns-cloud-d1.googledomains.com.",
           "ns-cloud-d2.googledomains.com.",
           "ns-cloud-d3.googledomains.com.",
           "ns-cloud-d4.googledomains.com."
       ],
       "ttl": 21600,
       "type": "NS"
   },
   {
       "kind": "dns#resourceRecordSet",
       "name": "gcp.arecord.us.",
       "rrdatas": [
           "ns-cloud-d1.googledomains.com. dns-admin.google.com. 1 21600 3600 1209600 300"
       ],
       "ttl": 21600,
       "type": "SOA"
   },
   {
       "kind": "dns#resourceRecordSet",
       "name": "www.gcp.arecord.us.",
       "rrdatas": [
           "192.168.2.10"
       ],
       "ttl": 86400,
       "type": "A"
   }
]

檢視DNS是否設定完成


確認好令表正確之後,接下來可以確認一下記錄是否已經生效...

peixindeMacBook-Pro in ~
Address: 216.239.32.109#53

Address: 192.168.2.10

後續


到這邊為止,記錄雖然已經生效,但是還無法讓網際網路上的大眾找到您的記錄,所剩的臨門一腳是~將DNS記錄指向到適當的DNS server位置,如果需要找DNS server位置,可以透過下面指令:

peixindeMacBook-Pro in ~
○ → gcloud dns managed-zone get gcp-arecord-us
{
   "creationTime": "2014-04-24T11:32:03.853Z",
   "description": "A zone",
   "dnsName": "gcp.arecord.us.",
   "id": "1595320562141013743",
   "kind": "dns#managedZone",
   "name": "gcp-arecord-us",
   "nameServers": [
   ]
}

其中nameServers的位置,設定到網域提供商所指定的DNS name server位置即可,而如果您設定的是subdomain,則透過指定NS record即可完成設定,下面是godaddy subdomain的記錄設定範例:


設定完成後,等待一段時間,重新確認DNS記錄:

peixindeMacBook-Pro in ~
○ → nslookup www.gcp.arecord.us
Server: 168.95.1.1
Address: 168.95.1.1#53

Non-authoritative answer:
Address: 192.168.2.10

參考

留言

這個網誌中的熱門文章

Share a chrome plugin for manage google cloud platform

好玩意兒報報.... 同事的新作,把Google Project List在Chrome Plugin中! 對一次管理多個專案的人來說,真得超方便的拉! 下載: https://chrome.google.com/webstore/detail/gdclauncher/bicgkglnnilldakpenngnblekooejnpg 使用說明: 1. Use browser url bar to quick search: Type "gdcl" in browser Press "TAB" to start search Type the project id key word then select the search result... 2. Using quick launch bar... You can search by keyword or click project name to go to the project or gae link to go to gae or go to billing page....

透過Google Apps Script結合Google Form做即時郵件通知

體驗過Google Apps Script的功能後,也發現他結合GmailApps的模組 GmailApps的應用可以用在表單填寫完成後,做發信的通知 例如您開立了一個訂購的表單,為了要在第一時間通知商家有訂單進入 就可以直接呼叫Gmail做發信的通知,讓手持Smart Phone的我們可以很快的知道生意上門了! 下面規劃三個function,其中: onCommit():為form commit時候觸發的function,需要掛載於form commit trigger上 jsonArrToTable():目的將json array解析成為一個Table getLastRowTable():目的將整個table的回傳過濾為剩下第一筆(表頭,含有Form的欄位說明)與最後一筆(原則上就是剛剛送出的那一筆表單) 完整程式碼如下: function onCommit(){   var sheet = SpreadsheetApp.getActiveSheet();   var rows = sheet.getDataRange();   var numRows = rows.getNumRows();   var values = rows.getValues();   var content = getLastRowTable(values);   var htmlBody = "Hi Admin: <br/><br/>有訂單拉,檢查一下吧! <br/><br/>" + content + '<br/><br/>Send by Google Apps';   GmailApp.sendEmail(     " your-email-address@gmail.com ",      "Order Confirm Notice",      htmlBody,      {from: ' from-email-...

Cloud Monitor嚐鮮

GCP上,我們非常想要的一個功能,終於問世.... Cloud Monitor來了!