星期日, 8月 16, 2020

GCP 平臺建立 Managed instance groups 與 Load balancing 小記

GCP 平臺建立 Managed instance groups 與 Load balancing 小記


今天來整理 GCP 上面使用 Managed instance group 與 Load balancing 的一些操作與想法


情境如下



使用者透過 Load balancer IP 來進行存取, 後端連接 Managed instance group 來提供服務


==== 準備服務主機 ====


先使用 gcloud 指令建立 openSUSE Leap GCE

使用 Portal 上面的 SSH 登入主機

  • 使用 zypper 指令安裝 apache2, 啟用並設定開機啟動 

    • # zypper  install apache2

    • # systemctl start  apache2

    • # systemctl enable apache2


參考網路上網頁顯示主機名稱或是 URL 的方式


將相關網頁存成 /srv/www/htdocs/index.html

網頁呈現如下



  • 這個方法目前沒有很好, 因為在後續 LB 測試的時候只會顯示 LB 的 IP, 後面再找其他的方式來顯示後端主機的 hostname or IP


將主機關機, 等等建立為映像檔


==== 建立主機映像檔 ====


點選 Compute Engine -- > Images -- > CREATE IMAGE



輸入名稱 / 選取 Source disk / 選取 Location ( 我這邊選 Taiwan )

點選 Create 建立



觀察資訊



==== 建立 Instance templates  ====


點選 Compute Engine -- > 點選 Instance templates

點選 Create Instance template



輸入 名稱 / 選取機器的規格



點選 Boot disk 的 change



點選 Custom images

點選 剛剛建立的 image

點選 Select



可以觀察到剛剛的 image 已經被選取

是專案狀況看看要不要調整 networking 或是 security

點選 Create



  • 這邊要注意, 如果 firewall 是採取 tag 的方式, 記得按照需求加上 network tag

  • 也要注意 VPC 的選定是否正確


觀察資訊



==== 建立 Health check  ====


點選 Compute Engine -- > 點選 Health checks

點選 CREATE A HEALTH CHECK



輸入 名稱 -- > 選取 Scope / Protocol 與 port

輸入 檢查區間

點選 CREATE



  • Check Interval 按照實際需求來調整, 但是最好是超過 10 秒以上, 不然後面建立 Instance group 也會被警告

  • Unhealthy threshod 最好也是超過 3 次, 不然也會被警告


觀察相關資訊



==== 建立 Managed instance Group 與設定 Auto scaling  ====


點選 Compute Engine -- > 點選 Instance groups

點選 Create instance group



點選 New managed instance group

輸入 名稱 -- > 選取 Location

選取 剛剛建立的 Instance template


這邊按照需求選取 Auto scaling 的條件, 預設是 CPU 使用率超過 60%

設定 最少最大的 instance 數量

選取 Health check 方式 (使用剛剛建立的 Health check )

點選 Create


觀察相關資訊

Instance groups:


VM instances:



如果有遇到 Health check 沒過的問題


  • 官方文件有提到要針對 130.211.0.0/22 與 35.191.0.0/16 要設定防火牆規則允許通過

    • https://cloud.google.com/load-balancing/docs/https/ext-http-lb-simple

    • 我是設定 Target 針對所有 instance, 然後 130.211.0.0/22 與 35.191.0.0/16 的 TCP port 80 allow, 比較嚴謹的方式當然也可以下 tag 來處理, 但是還要個別打上 tag, 然後 130.211.0.0/22 與 35.191.0.0/16 又是 google 宣告的網段, 所以就先這樣處理


Firewall 的規劃可能考量

  • 參考 https://cloud.google.com/load-balancing/docs/https

  • Load Balancer + Instance Group內的GCE 都允許 port 80 存取

    • 設定 130.211.0.0/22 與 35.191.0.0/16 可以存取 tcp port 80

    • 使用 tag 方式, 設定 0.0.0.0/0 可以存取 tcp port 80, 在 instance group template 內加入該 tag

    • 效果

      • 存取 LB IP -- > Pass

      • 存取 後端 Instance Group 產生的 GCE IP -- > Pass

  • 只允許 Load Balancer 轉發 port 80 到 Instance Group 內的 GCE 

    • 設定 130.211.0.0/22 與 35.191.0.0/16 可以存取 tcp port 80

    • 效果: 不希望使用者直接打後端的 node, 避免程式寫死存取某一個 node IP, 只允許存取 Load Balancer 的 IP

      • 存取 LB IP -- > Pass

      • 存取 後端 Instance Group 產生的 GCE IP -- > ERR_CONNECTION_TIMED_OUT


對於 Source IP 說明的截圖 


==== 建立 Load balancing ====


點選 Network services 點選 Load balancing

點選 Create load balancer



點選 HTTP(S) Load Balancing 的 Start configuration

  • 這邊就以實際的狀況來選取



選取外部還是內部的 Load Balancer

點選 Continue


輸入名稱

點選 Backend configuration

下拉選單, 點選 Backend services -- > 點選 Create a backend service



輸入 名稱

New Backend:

選取 剛剛建立 Instance Group

輸入要連接的 port

設定 Balancing mode

點選 Done


  • Backend service 有個 Named port 就是從外部接入的 port 是那一個, 然後 instance group 可以設定 Named port 連接進來後, 要到 instance group 內的機器的對應 port


會觀察到剛剛建立的 Backend 顯示到資訊內

選取 剛剛建立的 Health Check

點選 Create 




點選 Fronted configuration

輸入名稱 / Protocol / Port

點選 Done



觀察資訊

確認 Frontend 已經被建立

點選 Create



觀察資訊



點選剛剛建立的 Load balancer

觀察 LB 的 IP



觀察是否可以存取



最後來聊聊 Load balancing 的組成

這個也是剛接觸最讓我迷惑的部分 :p


Load balancing 組成分為 4 個部分

  • Forwarding rule

    • 如果是透過 portal 設定, 是在 Frontend configuration 被設定, 但是沒有在界面提到這個關鍵字

  • Target HTTP proxy

    • 如果是透過 portal 設定, 是在 Frontend configuration 被設定, 但是沒有在界面提到這個關鍵字

  • URL map

    • 如果是透過 portal 設定, 大部分在建立 Backend Service 的時候就被設定預設,但是沒有在界面提到這個關鍵字

  • Backend Service

    • 非常清楚


如果不是使用 gcloud 指令建立 Load balancer 而是使用 portal 建立的話

會看到 Load balancing 介面預設顯示爲

  • Load balancers

    • 這邊想法上會認為是主體, 這個部分不會有問題

  • Backends

    • 這邊是後端服務, 這個部分不會有問題

  • Frontends

    • 這邊比較會產生困惑, 因為可以看到上面顯示的是 Forwarding rule name



點選 Load balancing 的 advanced menu, 觀察界面

  • Forwarding rules

  • Target proxies

  • Backend services

  • Backend buckets

  • Certificates

  • Target pools



  • Advanced menu 可以觀察 Forwarding rules 與 Target proxies ( Frontend ), Backend 被拆分成 Backend services 與 Backend buckets

  • 可以從剛剛建立的 test20200815-front 觀察

    • Forwarding rule: test20200815-front 有 IP address, 然後指向 test20200815-lb-target-proxy

    • Target Proxy 會對應到 URL map ( 某一個 LB 主體內的 Host and Path )

    • URL map ( LB 主體內的 Host and Path ) 會指定 Backend

    • 指定的 Backend 會對應到後端的服務


如果是透過 gcloud 指令建立, 就比較清楚, 分別爲

  • # gcloud compute health-check create

  • # gcloud compute backend-services create

  • # gcloud compute backend-service add-backend

  • # gcloud compute url-maps create

  • # gcloud compute target-proxies create

  • # gcloud compute forwarding-rule create


今天也算是好好整理之前想整理的部分了


~ enjoy it



Reference:


星期三, 8月 12, 2020

openSUSE Leap 15.2 安裝小記

openSUSE Leap 15.2 安裝小記


openSUSE Leap 15.1 Lifetime 到 2020/11 


三個月前才認命的動手安裝 openSUSE Leap 15.2


安裝前處理

  • 使用 imagewriter 建立 openSUSE 安裝USB

  • 整理 /home/sakana 目錄

    • 使用 du -h --max-depth=1 /home/sakana 檢查

    • 清掉不要的檔案, 特別是 ~/.cache , ~/.config 內兩大瀏覽器內有站很大空間的 cache

    • 因為有很多相關的 config 在個人家目錄內, 所以先把舊的 openSUSE Leap 15.1 的 /home 目錄, 使用# tar    cvf   home.tar  /home 進行打包到隨身碟 ( 不要使用 .gz 方式, 會比較快速 )

    • 新機器再使用 tar 指令還原回來


這次也是使用 USB 來進行安裝,  


== 安裝過程小記==


這次建立的時候我還是選擇 GNOME 桌面


磁碟區分割的部分, 使用引導的方式安裝, 因為一直出線開機分割區的警告, 所以我就用引導式

  • 刪除所有分割區

  • 建立獨立分割區 XFS

  • 根目錄取消 Btrfs 快照


===============


Network Manager:


openSUSE Leap 15.2 預設為 Network Manager



Google Chrome:84.0

https://www.google.com/intl/zh-TW/chrome/browser/ 


還是會有驗證性問題, 但是功能沒有差異

為了進行google 登入,先使用 Google 驗證App,  後面來處理yubikey


home 資料回覆:


因為有很多相關的 config 在個人家目錄內, 所以先把舊的 openSUSE Leap 15.0 的 /home 目錄, 使用# tar    cvf   home.tar  /home 進行打包到隨身碟 ( 不要使用 .gz 方式, 會比較快速 )

新機器再使用 tar 指令還原回來


Notes

  • Ifconfig 預設沒有安裝, 要使用 ip  address show


關閉GNOME裡面的搜尋功能預設關閉 (點選右上角的設定按鈕), 因為我覺得用不到



中文輸入法問題:


在系統內新增中文輸入法, 目前使用 ibus

  • system_key( windows ) + 空白鍵 切換輸入法



取消 USB 為安裝來源

# yast2  repositories 



Freemind:

使用one click install 安裝 http://software.opensuse.org/package/freemind 

我是使用 editors 那個來源的 ymp 檔案安裝


.mm 的檔案指定用 freemind  開啟



新增 Packman 套件庫:


使用 #yast2  repositories 加入社群版本的Packman 


#yast2  repositories


Firefox Sync:

登入 Firefox Sync, 會處理之前有下載的 Plugin

例如 https://addons.mozilla.org/zh-TW/firefox/addon/video-downloadhelper/ 



flash-player:

# zypper   install   flash-player


Telegram desktop:



播放器:


# zypper  install   vlc vlc-codecs


  • Mp4 codec 應該是要安裝 vlc-codecs,  需要 Packman  套件庫

  • 過程會安裝 ffmpeg-3


並將 .rmvb 以及 .mp4 預設播放器設定為  VLC


安裝  ffmpeg ( 會把提供者從 openSUSE 換成 Packman )

# zypper  install   ffmpeg-3


這樣的好處是使用 youtube-dl  可以轉換  mp3 格式


參考之前的文章 http://sakananote2.blogspot.tw/2014/06/opensuse-131.html 


透過 youtube-dl  -F 來觀察可以下載的格式


# zypper  install youtube-dl


> youtube-dl  -F  http://www.youtube.com/watch?v=13eLHrDcb1k

[youtube] Setting language

[youtube] 13eLHrDcb1k: Downloading video webpage

[youtube] 13eLHrDcb1k: Downloading video info webpage

[youtube] 13eLHrDcb1k: Extracting video information

Available formats:

22 : mp4 [720x1280]

18 : mp4 [360x640]

43 : webm [360x640]

5 : flv [240x400]

17 : mp4 [144x176]


指定要下載的格式進行下載 (請注意 -f 是小寫)


> youtube-dl  -f  22  http://www.youtube.com/watch?v=13eLHrDcb1k


下載為 mp3

首先要安裝 ffmpeg 套件


>youtube-dl    http://www.youtube.com/watch?v=13eLHrDcb1k --extract-audio --audio-format mp3



Skype:

目前的版本是 8.51.0.72 的版本


https://www.skype.com/zh-Hant/download-skype/skype-for-linux/downloading/?type=weblinux-rpm


下載 RPM 版本用軟體安裝就裝好了 :)


使用 #yast2 sound 調整音效



GNOME Extension:


參考調校小記


主要是裝 chrome 內的 GNOME Shell integration


然後到 https://extensions.gnome.org/

選想裝的 Extension, 調爲 on 就好

裝了

  • TopIcons Plus 

  • NetSpeed


可以用下列指令觀察

> gnome-tweak-tool


不過我覺得從  https://extensions.gnome.org/ 最快


.7z 支援:

# zypper  install  p7zip


imagewriter:

# zypper  install  imagewriter

用來製作開機 USB


rdesktop 安裝與測試:

#zypper  install  freerdp


執行方式

#xfreerdp  -g  1280x1024  -u administrator  HOST_IP


修改 LS_OPTIONS 變數

# vi   /etc/profile.d/ls.bash

把 root 的 LS_OPTIONS 的 -A 移除


修改 HISTSIZE 變數

# vi   /etc/profile

修改 HISTSIZE 的筆數



Yubico Key:

如果 linux 沒有抓到 Yubico 的 U2F Key可以使用以下步驟

讓 linux 支援 Yubico , 我是參考 https://www.yubico.com/faq/enable-u2f-linux/  

作法

https://raw.githubusercontent.com/Yubico/libu2f-host/master/70-u2f.rules  另存新檔

存到 /etc/udev/rules.d/70-u2f.rules

將 linux 重開機, 接下來就可以使用了 :-)


ansible 安裝:


目前版本 2.9.6

#zypper  install  ansible


Docker 安裝:


目前版本 19.03.11

#zypper  install  docker


將使用者 sakana  加入 docker  群組 

# usermod -a -G docker sakana

#systemctl  start  docker

#systemctl  enable   docker


Dropbox 103.4.383版 :


openSUSE Leap 15.2 預設不支援 dropbox

參考官方網站上面斷頭的安裝方式來安裝


> cd  ~  && wget -O - "https://www.dropbox.com/download?plat=lnx.x86_64" | tar xzf -


接下來,請從新建立的 .dropbox-dist 資料夾執行 Dropbox 精靈。


> ~/.dropbox-dist/dropboxd


順便安裝 Nautilus 相關套件

# zypper  install  nautilus-extension-dropbox



變更主機名稱:


#yast2 lan



Filezilla 安裝:


#zypper  install  filezilla



smartgit 安裝:

參考 http://sakananote2.blogspot.tw/2016/01/opensuse-leap421-smartgit.html


下載 smartgit-linux-20_1_4.tar.gz

http://www.syntevo.com/smartgit/download 


解壓縮到 /opt

# tar  zxvf   smartgit-linux-*.tar.gz  -C   /opt/


建立 link 讓一般使用者也能使用

# ln  -s   /opt/smartgit/bin/smartgit.sh   /usr/local/bin/smartgit


安裝 git

# zypper  install  git


建立 個人的 ssh key ( 這次沒有作, 因為將舊的 /home 還原回來 )

> ssh-keygen  -t  dsa


將 ssh 的公鑰 id_dsa.pub 新增到 Github 的 Settings -- >  SSH and GPG Keys  ( 這次沒有作, 因為將舊的 /home 還原回來 )


接下來就是以一般使用者的身份執行 smartgit 指令

> smartgit


這次沒有發生 一般使用者發生找不到 jre 路徑


解法, 目前是在 ~/.smartgit/smartgit.vmoptions 檔案內

將 jre 指向 /opt/smartgit/jre


> cat   ~/.smartgit/smartgit.vmoptions 

jre=/opt/smartgit/jre


按照上面的參考設定


# zypper  install  alacarte

設定 smart git icon 使用 alacarte


> alacarte

在設定好之後如果發現無法直接開啟資料夾 ( 資料夾上面按右鍵 -- > Open )

Edit -- > Preferences --> 點選  Tools -- > 點選 Re-Add Defaults 得到解決

2016-11-24 15-48-28 的螢幕擷圖.png




Azure-cli 安裝:


版本: 2.10.1

參考 http://sakananote2.blogspot.com/2018/07/kubernetes-in-azure-with-opensuse-leap.html


匯入 rpm key

# rpm --import   https://packages.microsoft.com/keys/microsoft.asc


新增 Azure CLI 的 repo

# zypper  addrepo --name 'Azure CLI' --check https://packages.microsoft.com/yumrepos/azure-cli azure-cli


安裝 azure-cli 套件

# zypper  install --from azure-cli  -y  azure-cli


使用互動的方式登入 azure ( 現在已經不需要輸入機器碼, 直接驗證帳號就可以  )

> az  login


AWS Cli 安裝:


版本: 2.0.39



# curl  "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip"  -o  "awscliv2.zip"


# unzip  awscliv2.zip


# ./aws/install


# aws --version


aws-cli/2.0.39 Python/3.7.3 Linux/5.3.18-lp152.19-default exe/x86_64.opensuse-leap.15


將補齊的指令 寫到或是修改到個人家目錄的 .bashrc 內

  • echo "complete -C '/usr/local/bin/aws_completer' aws" >> /root/.bashrc



Google Cloud SDK ( gcloud )安裝:


參考 http://sakananote2.blogspot.com/2019/04/gsutil-google-cloud-storage-in-opensuse.html

安裝 gcloud

  • 但是目前實務上是使用容器的方式來執行


使用一般使用者安裝

> wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-305.0.0-linux-x86_64.tar.gz 


> tar  zxvf  google-cloud-sdk-305.0.0-linux-x86_64.tar.gz


> ./google-cloud-sdk/install.sh



Visual Studio Core 相關 :


參考 http://sakananote2.blogspot.com/2019/01/visual-studio-code-with-opensuse-leap-15.html


安裝 vscode


# rpm  --import   https://packages.microsoft.com/keys/microsoft.asc


# sh  -c  ' echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ntype=rpm-md\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc"  >  /etc/zypp/repos.d/vscode.repo '


# zypper  refresh


# zypper  install  code


安裝 vscode extension ( 這次沒有作, 因為將舊的 /home 還原回來 )

  • AWS Toolkit for Visual Studio Code

  • Bracket Pair Colorizer

  • Code Time

  • Git Graph

  • GitHub Pull Requests

  • GitLens

  • Kubernetes

  • Python

  • REST Client

  • GitHub Pull Requests and Issues



PPSSPP 安裝:


#zypper  install ppsspp




這個版本沒有安裝的, 以後要安裝就看之前的筆記



這樣又可以再戰一年 :p


~ enjoy it


參考