[K8s] Kubernetes – 容器管理工具指南

Intro Kubernetes – Wikipedia Kubernetes Documentation (Reference: ByteByteGoHq/system-design-101) 生態系 (Ecosystem) Minikube – 本地端工具 適合開發測試使用的本地端 K8S 集群工具,透過單一 Cluster 方便在本地端上演練各種指令操作 Hello Minikube – Kubernetes minikube start TBC References [AWS EKS] 從零打造一個可運行 Fargate workload 的 EKS cluster [Kubernetes] Pod 的設計 & 相關運作機制

[Web] 應用程式部署方法論 – Web Application Deployment

Intro Web application 部署方式整理 Methodologies 部署策略 Rolling Update 滾動升級 Performing a Rolling Update – Kubernetes 通常用於已 Container 化環境,配合如 Load Balancer 來逐步轉導流量到新的版本。 主要利用逐步引入新版本的 instance 方式 ,替換舊的 instance 並在完成後關閉。 Blue-Green 藍綠部署 部署前準備好一組新版本的環境,等於同時有兩個不同版本的相同環境。配合 Load Balancer 將所有流量一次轉導到新的環境,有問題時只需要 rollback 即可,缺點為維護期間需要兩組環境的成本。 Blue-green deployment Canary Deployment 金絲雀部署 […]

[DNS] CAA – Certification Authority Authorization 指南

Intro DNS CAA (DNS憑證頒發機構授權) – Wikipedia RFC 6844 通過域名持有人指定其域名的白名單憑證頒發機構來實現的安全機制。 該政策透過一個新的域名系統資源記錄(Record)「CAA」來實現,Record範例如下: example.com. CAA 0 issue “ca.example.net” 設定 首先 DNS records 要能夠支援 CAA record 再來針對憑證機構產生及設定 CAA record 即可,以下範例以 Letss Encrypt 機構為例: example.com. CAA 0 issue “letsencrypt.org” CAA Record Helper – CAA資源記錄產生器 References […]

[HTTPS] Two-way SSL – SSL雙向驗證 on Nginx

Intro Two-way SSL即Server端也要求Client端提供certificate做驗證,handshake流程上是Client端先驗證Server端後才換Server端驗證Client端。 圖片來源:web-service-principles – HTTP Client端憑證 Client端提供終端憑證並設定使用該憑證對應的Private Key; Server端設定Client端的CA憑證,以用於驗證Client端提供的終端憑證。 [Server] TLS/SSL憑證(Certificate)常用指令 – 製作CSR Nginx設定 Nginx可以在Server block上啟用驗證Client端certificate: server { listen 443 ssl; ssl_certificate /etc/nginx/ssl/public.crt; ssl_certificate_key /etc/nginx/ssl/private.rsa; # Client certificate verification ssl_client_certificate /etc/nginx/ssl/client_ca.pem; ssl_verify_client on; server_name api.my_domain.com; location / { # […]

[Apache] PHP + Apache 環境指南 (libapache-mod-php) on Ubuntu

Intro 雖然Nginx已經…如要架設Apache,可以使用Apache mod PHP去介接PHP(目前Apache不使用PHP-FPM)。 安裝 快速LAMP安裝檔 安裝Apache: $ sudo apt-get install apache2 安裝Apache mod PHP $ sudo apt-get install libapache2-mod-php PHP版本切換 Ubuntu Manpage: a2enmod, a2dismod Ubuntu系列使用Aapche指令工具a2dismod與a2enmod切換,省去修改零散設定檔。基本上版本支援已裝的libapache2-mod-php各版本: $ sudo a2dismod php7.0 $ sudo a2enmod php5.6 Apache MOD PHP 設定要至/etc/php/apache2/ Server執行使用者 Apache […]

[HTTP] Content-Disposition 中文解碼支援所有瀏覽器

Intro 非英文語系檔名下載要支援多瀏覽器需要特別處理一下。 目標是達到Google Chrome, FireFox, Edge, IE以及更多的瀏覽器皆能支援。 Content-Disposition – HTTP | MDN 解決方法 使用filename*並遵循RFC 5987編碼標準即可,格式範例: Content-Disposition: attachment; filename=%E4%B8%AD%E6%96%87.txt; filename*=UTF-8”%E4%B8%AD%E6%96%87.txt; PHP sample code: $filename = rawurlencode(‘中文檔名File測試’); header(“Content-Disposition: attachment; filename={$filename}{$extension}; filename*=UTF-8”{$filename}{$extension};”);

[Web] Nginx limit_req 指南 – ngx_http_limit_req_module

Intro Nginx限制訪問速率模組:Nginx http_limit_req 原理 使用leaky bucket原理(可以稱漏桶原理),桶的概念如下: 桶中存放request (令牌的概念) 桶上方由Nginx照設定速率計算補充request 桶下方提供提取request,即一個Request會消耗掉桶中存放的一個request Nginx對於桶的特性如下: 單一IP對應使用一個桶 limit_req_zone中rate是以request數量回推時間做補充的,依照兩次領取的時差補充相應的量 limit_req中burst即定義桶的request最大存放量,在每個新IP(不在Zone中)進入時會拿到全滿request(burst量)的桶 重啟Nginx會清空Zone,意即所有桶的剩餘Quota記憶清除,重新以全滿計算 比照實際設定,limit_req_zone $binary_remote_addr zone=one:10m rate=6r/m;即每間隔10秒可以得到一個request補充量。以rate=100r/s速率來說明,即每0.01秒得一個request補充量,間距0.1秒計算得10個request補充量; 而limit_req zone=one burst=5 nodelay;則表示每個IP桶最大預存的request量為5,有用掉則需等待補充。 Nginx實際上實作leaky bucket補充的方式可能為Trigger回填間隔補充量方式,本篇僅為概念說明,不代表實際Nginx演算法 Reference Nginx下limit_req模块burst参数超详细解析

[Network] Fail2ban 指南 – 搭配 SSH/Nginx (DDoS、Request Limit)

Outline SSH 設定方針 Nginx 防禦設定方針 Access log Error log by llimit_req_zone 進階 Fail2ban 設定 Email Notifications * Intro Fail2ban – Manuals 架構 Fail2ban 是依照設定檔執行過濾,原始設定檔路徑: /etc/fail2ban/jail.conf 如要修改新增可以複製建立成local的設定檔名稱,如有此檔會以此檔優先: /etc/fail2ban/jail.local /etc/fail2ban/jail.d/* Ubuntu Fail2ban 0.9 版本中可以找到預設的/etc/fail2ban/jail.d/defaults-debian.conf,內容是對[sshd]做enabled = true。 所以安裝好後預設即會開啟SSH保護(預設port為22) [過濾器名稱]會對應到/etc/fail2ban/filter.d/過濾器名稱.conf。 參數解析 官方文件 – Options […]

[Web] 後端程式語言指南 – Back-End Application Languages

Intro Programming languages used in most popular websites Web Server進程模型 同步單進程服務器 – QPS=1/每個請求秒數 同步多進程服務器 – QPS=進程數/每個請求秒數 同步單進程多線程服務器 – QPS=線程數/每個請求秒數 同步多進程多線程服務器 – QPS=進程數*每個線程數/每個請求秒數 (Ex. Apache) 同步單進程單線程事件驅動線程池服務器 – QPS依設計決定 (Ex. NodeJS) Difference between Multiprocessing and Multithreading PHP nginx使用php-fpm介接、或Apcahe使用mod_php Python nginx使用WSGI(多家套件可選)介接、或Apcahe使用mod_python Python 3 […]