Hero Image
一次搞懂密碼學中的三兄弟 — Encode、Encrypt 跟 Hash

一次搞懂密碼學中的三兄弟 — Encode、Encrypt 跟 Hash 編碼(Encoding) 不會修改資料、也沒有任何加密的效果,單純就是 換個方式來表達資料 而已,其中最有名的例子就是摩斯密碼 JavaScript 中有兩個很實用的 function 分別是 encodeURI 跟 decodeURI 把網址中的特殊字元(空白、標點符號等等)編碼成符合 URL 的格式 Base64 是一種可以把二進位的資料編碼成 ASCII 字元的方法 霍夫曼編碼(Huffman Coding) 一種用來進行 無失真壓縮 的編碼演算法,說穿了他的概念就是把常用的字記成縮寫,從而降低資料量、達到壓縮的效果 加密(Encrypt) 加密跟解密必須要有金鑰(Key)才能進行。以最簡單的 凱薩加密法 來說,他加密的方式就是把每個英文字母加上一個 偏移量,這個偏移量就是用來執行加解密的 Key AES (Advanced Encryption Standard) 是一種對稱加密演算法,所謂的對稱就是說加密解密 都是用同一個 key,這點跟上面說到的凱薩加密法一樣,但 AES 不像凱薩的 key 只有 0-25 這麼少種,而是可以有超過 10³⁸ 種 RSA 這類非對稱加密法有個很特別的地方,就是他會產生一組兩個 Key 分別叫公鑰(Public Key)跟私鑰(Private Key),而且 用公鑰加密的內容只能用私鑰解 雜湊(Hashing) 各個 欄位/字元 丟進去某個公式計算的方式就叫做雜湊(Hash),而這個計算公式就稱為 雜湊函數(Hash function),過程可能會做各種加減乘除,最後算出一個值或字串,因為不可能由雜湊後的結果回推,所以雜湊的過程是 不可逆的

Hero Image
Nginx 出現 500 Error 修復 (too many open file, connection)

Nginx 出現 500 Error 修復 (too many open file, connection) Nginx 出現 500 Error, 錯誤訊息只能從 Log 查到, 有遇到下述兩種狀況: socket() failed (24: Too many open files) while connecting to upstream $ sudo su - www-data $ ulimit -n # 看目前系統設定的限制 (ulimit -a # 可查看全部參數) 1024 # vim /etc/security/limits.conf # 由此檔案設定 nofile (nofile - max number of open files) 的大小 # 增加/修改 下述兩行 * soft nofile 655360 * hard nofile 655360 ulimit -n # 登出後, 在登入, 執行就會出現此值 655360 # 若 ulimit -n 沒出現 655360 的話, 可使用 ulimit -n 655360 # 強制設定 # 再用 ulimit -n 或 ulimit -Sn (驗證軟式設定)、ulimit -Hn (驗證硬式設定) 檢查看看(或 ulimit -a). # 從系統面另外計算 + 設定 lsof | wc -l # 計算開啟檔案數量 sudo vim /etc/sysctl.conf fs.file-max = 3268890 sudo sysctl -p 512 worker_connections are not enough while connecting to upstream # /etc/nginx/nginx.conf worker_connections 10240; # 參考 Nginx CoreModule # worker_processes 2; # worker_rlimit_nofile 10240; # events { # # worker_connections 10240; # } # Nginx 的 connection 增加後, 整體速度會變慢很多, 主要原因是 php-cgi 不夠用, 所以要作以下調整. # php-cgi was started with phpfcgid_children="10" and phpfcgid_requests="500" # ab was run on another server, connect via a switch using GBit ethernet # http://till.klampaeckel.de/blog/archives/30-PHP-performance-III-Running-nginx.html # vim /etc/nginx/nginx.conf worker_connections 10240; worker_rlimit_nofile # vim /etc/init.d/php-fcgi PHP_FCGI_CHILDREN=15 PHP_FCGI_MAX_REQUESTS=1000 改成 PHP_FCGI_CHILDREN=512 # 或 150 慢慢加, 注意 MySQL connection 是否夠用 PHP_FCGI_MAX_REQUESTS=10240 # 上述文章的 phpfcgid_stop(), 寫得還不錯, 有需要可以用看看. # phpfcgid_stop() { # echo "Stopping $name." # pids=`pgrep php-cgi` # pkill php-cgi # wait_for_pids $pids # }

Hero Image
Gitlab-CI Introduction

Gitlab CI Concept Gitlab DevOps GitOps Workflow code push -> pipeline -> stage -> job Design plan -> code -> build -> test -> release -> deploy -> operate -> monitor -> plan Runner Executors Shell VirtualBox Docker Docker Machine Kubernetes Else… References Gitlab CI/CD Gitlab Runner .gitlab-ci.yaml Runner Register gitlab-runner register After register concurrent = 1 check_interval = 0 [session_server] session_timeout = 1800 [[runners]] name = "public-shell" url = "https://gitlab.go2cloudten.com/" token = "-mdH9OAOzG5yPsf_AVnW" executor = "shell" [[runners]] name = "public-docker" url = "https://gitlab.go2cloudten.com/" token = "AcEGPPKTS1uuQ_A_qpWy" executor = "docker" [runners.docker] dns = ["192.168.185.5", "192.168.185.6"] tls_verify = false image = "registry.go2cloudten.com/it/office_sop/node:12.13.0" privileged = true disable_entrypoint_overwrite = false oom_kill_disable = false disable_cache = false shm_size = 0 pull_policy = "if-not-present" volumes = ["/cache"] Repository .gitlab-ci.yaml stages: - domain check-icp: stage: domain image: registry.go2cloudten.com/it/office_sop/icp tags: - docker script: - domains=$(awk -F '|' '{if($6 ~ "Y" && ($7 ~ "West" || $7 ~ "Yuqu")) print $3}' domains-info.md | sed 's/ //g' | sort | uniq) - if [[ "${domains}" == "" ]]; then telegram.sh 'There is no domain in list' ; else telegram.sh 'Start checking ICP.' ; fi - for i in ${domains}; do result=$(checkicp ${i}); if [[ "${result}" == "未备案" ]];then telegram.sh "${i} 未备案"; sleep 1 ;fi;done - telegram.sh 'ICP check completed.' only: - schedules