iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 22
0
Everything on Azure

玩轉 Azure 於指尖隨心所欲系列 第 22

讓 WebApps 更安全走 Private Network 與 MySQL 串聯

WebApps是一個非常便利的服務,只要租用就可以直接對外連線,但試想如果你的網站開始複雜了,想要有個資料庫讓網站可以存取更新會員資料難道...也是走Internet嗎?能不能藏在內部網路之中呢?這次我們就是來實作怎麼來走Private連線並串接資料庫...這次用MySQL作為範例.

一樣新增資源找到資料庫選擇MySQL(PaaS)
https://ithelp.ithome.com.tw/upload/images/20181022/20025481dKHTvEfFJG.png

建立過程如果你是有已經備份檔可以透過此來建立,而裡面的資料都會保留你之前的狀態,我們沒有所以選空白
https://ithelp.ithome.com.tw/upload/images/20181022/20025481AlDrVx1ebJ.png

規格等級第四與第五代價格一樣....當然第五代喽!個人需求自訂
https://ithelp.ithome.com.tw/upload/images/20181022/20025481UXsoUZ8tP7.png

設定好登入MySQL帳密與版本5.7 / 5.6,我選最新
https://ithelp.ithome.com.tw/upload/images/20181022/20025481Xdi297RVd4.png

MySQL建立中
https://ithelp.ithome.com.tw/upload/images/20181022/20025481IFvoCOWbeV.png

建立完成,右上角連線登入資訊可以另外保存成文字檔方便後續設定用
https://ithelp.ithome.com.tw/upload/images/20181022/200254811MpxAWMOLT.png

剛剛是後端DB已經Ready,現在來處理WebApp,我們來點選一下網路

  • 第一項等等會借助P2S VPN讓WebApp從原本只能走公用網路連線改走私有網路
  • 第二項是讓你直接以最小微型VPN概念穿牆到你內部指定服務主機(也只能是網站-->資料庫)
  • 第三項就是把你的網站作快取加速,全域跨境的商業應用最適合
  • 最後就是對你的網站能否存取的黑名單設定....預設是全通都能連
    https://ithelp.ithome.com.tw/upload/images/20181022/20025481bE3qfHT2Dy.png

點進去看到都是反白沒法設定,因為你沒有作點對站的VPN設置
https://ithelp.ithome.com.tw/upload/images/20181022/200254817EVoIC2vIx.png

再回到新增資源選擇虛擬網路閘道(VPN)
https://ithelp.ithome.com.tw/upload/images/20181022/20025481cJB3YHqPOO.png

測試選擇基本就好...如果正式環境請以VPNGW1起跳(選擇動態路由比較單純,另外虛擬網路我用東亞,視個人環境決定)
https://ithelp.ithome.com.tw/upload/images/20181022/20025481O1uZ0NfIxM.png

新增Public IP另外地區就是東南亞,完成就建立
https://ithelp.ithome.com.tw/upload/images/20181022/20025481gN6u6TQmbE.png

建立進行中......
https://ithelp.ithome.com.tw/upload/images/20181022/20025481GA3dFs3JTl.png

從VPN總覽可以看到更新中就還在建立(約30-45分鐘)所以如果是已知的任務可以提早作
https://ithelp.ithome.com.tw/upload/images/20181022/20025481itHJBt5Ja6.png

OK,VPN建立完成了
https://ithelp.ithome.com.tw/upload/images/20181022/20025481AMFjL3Ca1o.png

VPN內選擇到點對站
https://ithelp.ithome.com.tw/upload/images/20181022/20025481iFCz2TOFmF.png

我們要確認一下目前此虛擬網路下各個子網路不能衝突到
https://ithelp.ithome.com.tw/upload/images/20181022/20025481YhY1ql6C8e.png

好!!在設定VPN給予的範圍出錯.....因為本身虛擬網路的範圍涵蓋太廣/16,導致衝突
https://ithelp.ithome.com.tw/upload/images/20181022/20025481PUgNLOObTf.png

把虛擬網路位置空間從/16縮小為/20
https://ithelp.ithome.com.tw/upload/images/20181022/20025481p7lmLJqhoe.png

這樣就可以設定點對站所指派的網路區段了
https://ithelp.ithome.com.tw/upload/images/20181022/20025481Oy0CtItyST.png

正常不用太久..因為更新到整個虛擬網路所以又要五到十分鐘的時間
https://ithelp.ithome.com.tw/upload/images/20181022/20025481BExN06gnPK.png

再回到WebApps的網路是不是已經有個東亞的虛擬網路可以設定了
https://ithelp.ithome.com.tw/upload/images/20181022/20025481wL2i2JKBCZ.png

已經讓WebApps與虛擬網路綁定中間的點對站位置就是被指配的網路IP位置範圍
https://ithelp.ithome.com.tw/upload/images/20181022/20025481snAXdkMasv.png

我們回到VPN檢視一下點對站下面的裝置是不是就多了一組被指派的IP(補充一下P2S除此之外還可以產生憑證綁在上面讓地端的電腦透過安裝此配發的憑證作信任來作私有網路連接)
https://ithelp.ithome.com.tw/upload/images/20181022/20025481kMSupmDfcy.png

接下來我們要把WebApp串上MySQL了..來看看連線字串到最下面就是給WebApps的
Database={your_database}; Data Source=garymysql.mysql.database.azure.com; User Id=gary@garymysql; Password={your_password}
https://ithelp.ithome.com.tw/upload/images/20181022/200254812keENon7eF.png

問題來了!!我MySQL根本都還沒有DB哪來的名稱阿...沒錯就是用Azure方便的CLI...來個錯誤示範怎麼無法連
,DB沒有指定來源是不能隨便來訪問的..
https://ithelp.ithome.com.tw/upload/images/20181022/20025481i8uYEH1iUi.png

把此Azure CLI的IP設置上去....這也是一台Linux在背景運作有外部IP的
https://ithelp.ithome.com.tw/upload/images/20181022/20025481uosSzTiIcL.png

我們再登入一次沒有問題了,並確認DB狀態無誤
https://ithelp.ithome.com.tw/upload/images/20181022/20025481xQ6yqKpLEh.png

建立空白資料庫完成
https://ithelp.ithome.com.tw/upload/images/20181022/20025481t37nqV9xkT.png

我們就可以把剛剛的連線字串加上MySQL DB / MySQL連線伺服器名稱 / MySQL登入帳密就可以了
https://ithelp.ithome.com.tw/upload/images/20181022/200254811brCUy5mO0.png

測試ping一下內部VM是否能通
https://ithelp.ithome.com.tw/upload/images/20181022/20025481NfHnr0FFfm.png

用WebApps上內建的進階工具Kudo來ping開機的這台東亞VM OK(原本圖中是.1因為中間WebApps有把網路中斷連線再接入...IP會依序下去....你就知道我拔了幾次了@@)
https://ithelp.ithome.com.tw/upload/images/20181022/20025481OOFlGbOODO.png

試試ping MySQL:3306也沒有問題....
https://ithelp.ithome.com.tw/upload/images/20181022/20025481LXZXYColk4.png

好啦!今天串接示範就到這裡...後續想用的大大們再試試喽!


上一篇
Azure WebApps 玩轉技巧-線上編修語法 & 一鍵切換 Production
下一篇
Azure VPN 走 BGP 最佳路由實記
系列文
玩轉 Azure 於指尖隨心所欲32
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言