DNS TTL 選擇時間長短 ,差別在哪
在設定 DNS 時,選完類型 (A、CNAME、MX…)、主機名稱 (@、subdomainname、service..)、指向(@、IP或網域)
接下來就會看到 TTL 包含了 1/2小時、1小時、12小時、1天、1周…
接下來會說明 TTL 是甚麼? 以及DNS TTL 選擇時間長短 ,差別在哪
TTL ( Time to Live, 存留時間) 是用來記錄 DNS 有效時間的參數值
Continue Reading在設定 DNS 時,選完類型 (A、CNAME、MX…)、主機名稱 (@、subdomainname、service..)、指向(@、IP或網域)
接下來就會看到 TTL 包含了 1/2小時、1小時、12小時、1天、1周…
接下來會說明 TTL 是甚麼? 以及DNS TTL 選擇時間長短 ,差別在哪
TTL ( Time to Live, 存留時間) 是用來記錄 DNS 有效時間的參數值
Continue ReadingHeroku 的 Add on 擴充功能,提供了資料庫的項目
在 MySQL 會選擇 “ClearDB MySQL :: Database” 這個 AddOn
這項服務是免費的,但是必須要先填寫信用卡資料,才能完成啟用
啟用後,就能在 local cli 登入 heroku
接著執行
heroku config | grep CLEARDB_DATABASE_URL
或者
Continue Reading在swoole 官方介紹到運作原理時,就有針對 swoole 運作方式與 PHP-FPM 的差異進行比較
傳統 PHP-FPM 是基於 PHP Server 來解析
而 Swoole 則是用 C 所編譯的 PHP 擴充,可以直接透過 CLI mode 與 server 溝通
這一點差異就讓 swoole 能做到傳統 php model 無法達成的事情
讓 PHP 開發者可寫出高效能、可拓展的程式
並且可以直接設計 no-blocking I/O 程式,以及與底層 linux kernel 溝通
其中包括幾點:
…
Continue Reading在 Linux 建構服務時,通常遇到問題除了查詢log 之外,大多數還會確認連線是否正常,port是否有打通之類
Linux 命令列的 netstat 可以查詢到各種網路相關訊息
當我們要檢測 socket、TCP、UDP、IP、ethernet等各種連線,都可以用它來查詢
支援一般權限,以及 IPv4, IPv6
這裡筆記方式記錄一些用法
watch -d -n0 "netstat | grep ESTABLISHED"
以下可能是 CentOS的環境使用:
列出完整的 URL 位址
netstat -tup -W
這個指令可以將所有連線的 IP 位址列出來,並依照每個 IP 位址的連線數排序
netstat -an | grep ESTABLISHED | awk '/^tcp/ {print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr
用 awk 分析連線 這個指令可以分析 Apache 的連線,列出每個 IP 位址的連線數
sudo netstat -anpt | grep http | grep ESTABLISHED | awk -F "[ :]*" '{print $4}' | uniq -c
這個指令可以將所有連線的 IP 位址列出來,並依照每個 IP 位址的連線數排序.
Continue Reading透過設定 Deploy keys (SSH Key) 可以避免掉每次 push 都要輸入帳密的流程
設定的步驟如下:
MAC系統會自帶 apache, 在這裡要先將它關閉
暫停apache
sudo apachectl -k stop
關閉開機啟動
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
shift+command+p > Package Control:Install Package > sftp
File>SFTP/FTP/Setup Server
這時會開啟一個json格式的設定檔案
首先,先查看vagant ssh-config
$ vagrant ssh-config
Host homestead-7
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/liaoxiangru/Homestead/.vagrant/machines/homestead-7/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
ForwardAgent yes
設定 Sftp config 檔案,填寫對應資訊
例如:
{
// The tab key will cycle through the settings when first created
// Visit http://wbond.net/sublime_packages/sftp/settings for help
// sftp, ftp or ftps
"type": "sftp",
"sync_down_on_open": true,
"sync_same_age": true,
"host": "127.0.0.1",
"user": "vagrant",
//"password": "password",
"port": "2222",
"remote_path": "/home/vagrant/code",
//"file_permissions": "664",
//"dir_permissions": "775",
//"extra_list_connections": 0,
"connect_timeout": 30,
//"keepalive": 120,
//"ftp_passive_mode": true,
//"ftp_obey_passive_host": false,
"ssh_key_file": "~/.ssh/id_rsa",
//"sftp_flags": ["-F", "/path/to/ssh_config"],
//"preserve_modification_times": false,
//"remote_time_offset_in_hours": 0,
"remote_encoding": "utf-8",
//"remote_locale": "C",
//"allow_config_upload": false,
}
接著存擋為 sftp-config.json
Continue ReadingLaravel 為了讓PHP開發整體體驗都能完善,在local開發的環境設定也提供了相關解決方案
也就是這裡要介紹的 Homestead
Laravel Homestead 是官方所維護的 Vagrant box pre-package
讓你可以直接透過這個環境開發,而不必再獨立安裝PHP、Web server…等軟體
並且不必擔心忘記系統設定,因為 Vagrant boxes 是一次性設定安裝完畢,
如果在安裝流程有發現錯誤,隨時都可以重新安裝環境,並且只需要幾分鐘的時間就能完成
Continue Reading這裡記錄 Services 實作流程
在之前,要先透過 part2 建立了 image gordon/get-started:part2
在這裡,建立 docker-compose.yml ,透過 image 來產生五個重複的 container
version: "3"
services:
web:
# replace username/repo:tag with your name and image details
image: gordon/get-started:part2
deploy:
replicas: 5
resources:
limits:
cpus: "0.1"
memory: 50M
restart_policy:
condition: on-failure
ports:
- "4000:80"
networks:
- webnet
networks:
webnet:
接著先執行 swarm 初始化(這部分會在 part 4 介紹)
docker swarm init
接著,執行建立 service app 名稱為 getstartedlab
Continue Reading這裡記錄 Containers 實作流程
在這裡按照下方流程就能快速建立出一個 python demo web
預計將專案放置在 docker_project/get_started/
建立檔案: Dockerfile
# Use an official Python runtime as a parent image
FROM python:2.7-slim
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
# Make port 80 available to the world outside this container
EXPOSE 80
# Define environment variable
ENV NAME World
# Run app.py when the container launches
CMD ["python", "app.py"]
requirements.txt
Continue ReadingDocker 基本操作常用的指令:
docker build -t friendlyhello . # Create image using this directory's Dockerfile
docker run -p 4000:80 friendlyhello # Run "friendlyname" mapping port 4000 to 80
docker run -d -p 4000:80 friendlyhello # Same thing, but in detached mode
docker container ls # List all running containers
docker container ls -a # List all containers, even those not running
docker container stop <hash> # Gracefully stop the specified container
docker container kill <hash> # Force shutdown of the specified container
docker container rm <hash> # Remove specified container from this machine
docker container rm $(docker container ls -a -q) # Remove all containers
docker image ls -a # List all images on this machine
docker image rm <image id> # Remove specified image from this machine
docker image rm $(docker image ls -a -q) # Remove all images from this machine
docker login # Log in this CLI session using your Docker credentials
docker tag <image> username/repository:tag # Tag <image> for upload to registry
docker push username/repository:tag # Upload tagged image to registry
docker run username/repository:tag # Run image from a registry
Docker Mount 下圖清楚了說明Docker host的 Volume with bind mounts 以及tmpfs mount 機制
這裡針對 tmpfs 部分進行介紹:
tmpfs mounts 只會儲存於host system的記憶體,不會寫入 host system的 filesystem。
因此,tmpfs mount 資料不會保存在硬碟、Docker host或 container 裡,只會存在container 執行的期間
通常會把 tmpfs mount 應用在非敏感或不必持續保留的狀態資料,舉例來說,swarm service 就是使用 tmpfs mount 去 mount secrets 到 service的 container。
在 Docker 17.06 以上版本,建議使用 –mount flag 來進行 bind mounts, volumes, 或者 tmpfs mount。
tmpfs mounts 最適合使用於不必持續保留的資料,或者當你的應用程式需要寫入大量的非持續保留的資料時。在 host machine 或者 container,適當的採用 tmpfs mount 幾可以讓container執行效能提升。
Continue ReadingDocker Mount 下圖清楚了說明Docker host的 Volume with bind mounts 以及tmpfs mount 機制
這裡針對 Bind Mounts 部分進行介紹:
Bind mounts 在早期 Docker 版本就已經存在,相對於 volumes ,使用 Bind mounts 有一些功能限制:
當 container 在host machine 中的檔案或目錄使用 bind mount
host machine 是以完整的路徑來參照這些檔案或目錄
因此,在Docker host 中不需要存在這些檔案或目錄
若參照的目錄或檔案不存在,則會自動建立。
透過 Bind Mounts 的方式是非常有效率的方式,但使用 bind mounts 需要 host machine 有特定的 filesystem 結構才能運作
如果你正開發一個新的 Docker 應用程式,考慮改用 Volumes 時,就不能直接透過Docker CLI 來管理 bind mounts。
使用 bind mounts 其中一個特點就是,
Continue Reading下圖清楚了說明Docker host的 Volume with bind mounts 以及tmpfs mount 機制
這裡針對 Volumes 部分進行介紹:
Continue Reading在 Docker 管理資料
在 container 所建立的檔案,預設都會存放在可容器寫入層(writable container layer)
這表示:
當你建立一個新的 container,會同時在最上層建立一個新的可寫入層(writable layer),也稱為 container layer。
在 container內所有的改變都會在這裡面,例如: 建立新檔案,編輯檔案,刪除檔案,都會寫入這個容器可寫入層。
Continue Readingcomposer require --dev "xethron/migrations-generator"
php artisan --version
Continue Reading
Docker-Compose 是一個可以用來定義且執行多個 Container 應用程式的工具
可以很簡單的透過 Compose 的 yaml 來設定你的container應用程式
並且透過一個指令,就可以建立及啟動所有yaml設定的應用程式
Compose 可以在產品、階段產品、開發或測試項目使用
在使用上大致可以區分為三個過程:
Continue ReadingMySQL 是一個廣泛被使用,開源的關聯式資料庫管理系統( relational database management system, RDBMS)
目前的MySQL執行效能不斷提升,可靠且易於使用,
因此經常被作為網路應用程式開發資料庫的首選.
其中包括 Facebook, Twitter, YouTube, Yahoo 等公司都有使用。
詳細說明可參考官網: www.mysql.com.
這裡將說明如何在 Docker 安裝即執行 MySQL 環境
Continue Reading-d 表示在背景( Detached )執行,Docker 預設前景( foreground )執行
-p 表示將本機 8080 port 的來源轉發到 container 的 80 port
–name 表示為 container 的名稱
–rm 表示當 exit container 時,會移除 container( incompatible with -d )
docker run -d -p 80:80 --name mywebserver nginx
//if need custom port (ex 3000) can do like this
docker run -d -p 3000:80 --name mywebserver nginx
由於 local 還沒有 nginx 的 image,因此Docker 會先執行檢查及下載 nginx image
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
...下載安裝
Status: Downloaded newer image for nginx:latest
安裝完畢之後,就會直接對 nginx image 進行 instance 為 nginx container,並執行
Continue Reading