| | 1 | = Mac 設定 = |
| | 2 | == 開發環境設定 == |
| | 3 | {{{ |
| | 4 | #install xcode command tool |
| | 5 | xcode-select --install |
| | 6 | # check |
| | 7 | xcode-select -p |
| | 8 | # install home-brew |
| | 9 | ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" |
| | 10 | # check brew |
| | 11 | brew doctor |
| | 12 | brew update |
| | 13 | # install develop environment |
| | 14 | brew install ansible |
| | 15 | brew install gradle |
| | 16 | brew cask install java |
| | 17 | brew cask install intellij-idea-ce ## community edition |
| | 18 | # install JSON toolkits |
| | 19 | brew install jq |
| | 20 | brew install npm |
| | 21 | npm install json2csv -g |
| | 22 | # install azure-cli |
| | 23 | npm install azure-cli -g |
| | 24 | }}} |
| | 25 | |
| | 26 | == 辦公環境設定 == |
| | 27 | {{{ |
| | 28 | # install firefox |
| | 29 | brew cask install firefox-zh-tw |
| | 30 | # 編輯器 |
| | 31 | brew cask install sublime-text |
| | 32 | # Markdown 筆記用: |
| | 33 | brew cask install macdown |
| | 34 | # Markdown 寫文件用: |
| | 35 | brew cask install gitbook-editor |
| | 36 | brew cask install pandoc |
| | 37 | # 群組溝通用:slack |
| | 38 | brew cask install slack |
| | 39 | # 資料分析用 |
| | 40 | brew cask install tableau-public ## 拿來分析一些 CSV 用 |
| | 41 | # MS Office 日常文書用 |
| | 42 | brew cask install microsoft-office |
| | 43 | }}} |
| | 44 | |
| | 45 | == 網路環境設定 == |
| | 46 | |
| | 47 | * Mac 無線網路設定 |
| | 48 | [[File:Funp_wifi.png|480px]] |
| | 49 | * Android 手機無線網路設定 |
| | 50 | [[File:Android_WiFi.png|240px]] |
| | 51 | |
| | 52 | == 鍵盤快速鍵 == |
| | 53 | |
| | 54 | * 首先,認識一下選單上的鍵盤符號對應: |
| | 55 | [[File:hotkeys.png|400px]] |
| | 56 | |
| | 57 | == 終端機設定 == |
| | 58 | |
| | 59 | * 一開始覺得很奇怪,為何用 `screen` 有顏色,不用就沒有顏色。 |
| | 60 | * 原因是預設的 `TERM` 不支援,需改為 `xterm-256color` 才行。 |
| | 61 | * [[File:mac_terminal_xterm.png|600px]] |
| | 62 | * 修改後,查詢 `$TERM` 環境變數應該會看到: |
| | 63 | {{{ |
| | 64 | ~$ echo $TERM |
| | 65 | xterm-256color |
| | 66 | }}} |
| | 67 | |
| | 68 | = Azure = |
| | 69 | |
| | 70 | * 若要使用命令列建立與管理 Azure 資源,您必須具備以下條件: |
| | 71 | ** 有 Azure 帳戶 (免費試用版) - 註冊 Azure - https://azure.microsoft.com/zh-tw/ |
| | 72 | ** 安裝 Azure CLI - https://azure.microsoft.com/zh-tw/documentation/articles/xplat-cli-install/ |
| | 73 | ** 登入使用您帳戶的相關 Azure 資源 - https://azure.microsoft.com/zh-tw/documentation/articles/xplat-cli-connect/ |
| | 74 | |
| | 75 | == Azure CLI 安裝 == |
| | 76 | === Mac OS X === |
| | 77 | |
| | 78 | {{{ |
| | 79 | brew install npm |
| | 80 | npm install azure-cli -g |
| | 81 | }}} |
| | 82 | |
| | 83 | * 雖然 homebrew 裡也有 `azure-cli`,但版本比較舊,建議用 npm 的版本。 |
| | 84 | {{{ |
| | 85 | ~$ brew info azure-cli |
| | 86 | azure-cli: stable 0.10.6 (bottled), HEAD |
| | 87 | }}} |
| | 88 | |
| | 89 | === Docker === |
| | 90 | |
| | 91 | * Docker Hub - https://hub.docker.com/r/microsoft/azure-cli/ |
| | 92 | * azure-cli 的 github - https://github.com/azure/azure-xplat-cli |
| | 93 | * 在 Docker主機中,執行: |
| | 94 | |
| | 95 | {{{ |
| | 96 | docker run -it microsoft/azure-cli |
| | 97 | }}} |
| | 98 | |
| | 99 | === 小技巧 === |
| | 100 | |
| | 101 | * 在 Docker 主機中,有 `azure.completion.sh` 可以讓 Azure CLI 提供指令的建議。若有需要,請在 Mac OS 的家目錄建立 .bashrc 與 .bash_profile 檔案,並 `source 路徑/azure.completion.sh` |
| | 102 | * 如果懶得從 docker image 裡面取得 azure.completion.sh 可至以下 gist 路徑取得: |
| | 103 | ** https://gist.githubusercontent.com/jazzwang/4397a4a13507fef8d94010a49337d120/raw/b7dc8b8086198d01c92f52cb5bd363d3811e0b40/azure.completion.sh |
| | 104 | * 以下是我的設定,供參考: |
| | 105 | ** `.bash_profile` |
| | 106 | {{{ |
| | 107 | # ~/.profile: executed by the command interpreter for login shells. |
| | 108 | # This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login |
| | 109 | # exists. |
| | 110 | # see /usr/share/doc/bash/examples/startup-files for examples. |
| | 111 | # the files are located in the bash-doc package. |
| | 112 | |
| | 113 | # the default umask is set in /etc/profile; for setting the umask |
| | 114 | # for ssh logins, install and configure the libpam-umask package. |
| | 115 | #umask 022 |
| | 116 | |
| | 117 | # if running bash |
| | 118 | if [ -n "$BASH_VERSION" ]; then |
| | 119 | # include .bashrc if it exists |
| | 120 | if [ -f "$HOME/.bashrc" ]; then |
| | 121 | . "$HOME/.bashrc" |
| | 122 | fi |
| | 123 | fi |
| | 124 | |
| | 125 | # set PATH so it includes user's private bin if it exists |
| | 126 | if [ -d "$HOME/bin" ] ; then |
| | 127 | PATH="$HOME/bin:$PATH" |
| | 128 | fi |
| | 129 | }}} |
| | 130 | ** `.bashrc` |
| | 131 | {{{ |
| | 132 | ## for Intellij IDEA |
| | 133 | export JAVA_HOME="$(/usr/libexec/java_home)" |
| | 134 | ## for terminal |
| | 135 | export CLICOLOR=1 |
| | 136 | export LSCOLORS="Gxfxcxdxbxegedabagacad" |
| | 137 | alias ls='ls -GFh' |
| | 138 | source /usr/local/etc/bash_completion.d/git-completion.bash |
| | 139 | source /usr/local/etc/bash_completion.d/azure.completion.sh |
| | 140 | source /usr/local/etc/bash_completion.d/docker |
| | 141 | source /usr/local/etc/bash_completion.d/brew |
| | 142 | source /usr/local/etc/bash_completion.d/brew-cask |
| | 143 | source /usr/local/etc/bash_completion.d/gradle |
| | 144 | }}} |
| | 145 | |
| | 146 | == Azure 術語與觀念 == |
| | 147 | |
| | 148 | * Azure 建立和處理資源的部署模型有二種: 資源管理員和傳統 |
| | 149 | * 傳統的文件入口:https://azure.microsoft.com/zh-tw/documentation/articles/virtual-machines-command-line-tools/ |
| | 150 | * Microsoft 建議大部分的新部署使用 Resource Manager model。(常看到的 ARM 縮寫,指的就是 Azure Resource Manager) |
| | 151 | * 資源管理員文件入口:https://azure.microsoft.com/zh-tw/documentation/articles/xplat-cli-azure-resource-manager/ |
| | 152 | |
| | 153 | {| class="wikitable sortable" |
| | 154 | |- |
| | 155 | ! 縮寫 !! 全文 !! 說明 |
| | 156 | |- |
| | 157 | | ASM || || |
| | 158 | |- |
| | 159 | | ARM || Azure Resource Manager || Azure 資源管理員 |
| | 160 | |- |
| | 161 | | || Resource Group || |
| | 162 | |} |
| | 163 | |
| | 164 | == Azure CLI 操作與管理 == |
| | 165 | |
| | 166 | * 安裝好 Azure CLI 之後,您就能從命令列使用者介面 (Bash、終端機及命令提示字元等) 中執行 azure 命令。例如,若要執行 [說明] 命令,請輸入下列命令: |
| | 167 | |
| | 168 | {{{ |
| | 169 | azure help |
| | 170 | }}} |
| | 171 | |
| | 172 | * 若要查看您所安裝的 Azure CLI 版本,請輸入下列命令: |
| | 173 | |
| | 174 | {{{ |
| | 175 | azure --version |
| | 176 | }}} |
| | 177 | |
| | 178 | * 參考 https://azure.microsoft.com/zh-tw/documentation/articles/xplat-cli-connect/ 完成帳號綁定 |
| | 179 | * 因為使用的是 0.9.10 以後的版本,所以直接使用 `azure login` |
| | 180 | |
| | 181 | === azure login === |
| | 182 | |
| | 183 | {{{ |
| | 184 | ~# azure --version |
| | 185 | 0.9.19 (node: 4.2.4) |
| | 186 | root@azure:~# azure login |
| | 187 | info: Executing command login |
| | 188 | -info: To sign in, use a web browser to open the page https://aka.ms/devicelogin. Enter the code G*K*N*D*L to authenticate. |
| | 189 | /info: Added subscription Free Trial |
| | 190 | info: Setting subscription "Free Trial" as default |
| | 191 | + |
| | 192 | info: login command OK |
| | 193 | }}} |
| | 194 | |
| | 195 | === azure account === |
| | 196 | |
| | 197 | * 檢查 account 狀態 |
| | 198 | |
| | 199 | {{{ |
| | 200 | ~# azure account list |
| | 201 | info: Executing command account list |
| | 202 | data: Name Id Current State |
| | 203 | data: ---------- ------------------------------------ ------- ------- |
| | 204 | data: Free Trial #################################### true Enabled |
| | 205 | info: account list command OK |
| | 206 | }}} |
| | 207 | |
| | 208 | === azure config === |
| | 209 | |
| | 210 | * 由於預設是 ASM 模式,可以透過 `azure config mode arm` 改成 ARM 模式。 |
| | 211 | {{{ |
| | 212 | azure config mode arm |
| | 213 | }}} |
| | 214 | |
| | 215 | === azure location === |
| | 216 | |
| | 217 | * 查詢目前 Azure 的機房位置 |
| | 218 | {{{ |
| | 219 | ~$ azure location list |
| | 220 | info: Executing command location list |
| | 221 | warn: The "location list" commands is changed to list subscription's locations. For old information, use "provider list or show" commands. |
| | 222 | info: Getting locations... |
| | 223 | data: Name Display Name Latitude Longitude |
| | 224 | data: ------------------ ------------------- -------- --------- |
| | 225 | data: eastasia East Asia 22.267 114.188 |
| | 226 | data: southeastasia Southeast Asia 1.283 103.833 |
| | 227 | data: centralus Central US 41.5908 -93.6208 |
| | 228 | data: eastus East US 37.3719 -79.8164 |
| | 229 | data: eastus2 East US 2 36.6681 -78.3889 |
| | 230 | data: westus West US 37.783 -122.417 |
| | 231 | data: northcentralus North Central US 41.8819 -87.6278 |
| | 232 | data: southcentralus South Central US 29.4167 -98.5 |
| | 233 | data: northeurope North Europe 53.3478 -6.2597 |
| | 234 | data: westeurope West Europe 52.3667 4.9 |
| | 235 | data: japanwest Japan West 34.6939 135.5022 |
| | 236 | data: japaneast Japan East 35.68 139.77 |
| | 237 | data: brazilsouth Brazil South -23.55 -46.633 |
| | 238 | data: australiaeast Australia East -33.86 151.2094 |
| | 239 | data: australiasoutheast Australia Southeast -37.8136 144.9631 |
| | 240 | data: southindia South India 12.9822 80.1636 |
| | 241 | data: centralindia Central India 18.5822 73.9197 |
| | 242 | data: westindia West India 19.088 72.868 |
| | 243 | data: canadacentral Canada Central 43.653 -79.383 |
| | 244 | data: canadaeast Canada East 46.817 -71.217 |
| | 245 | info: location list command OK |
| | 246 | }}} |
| | 247 | |
| | 248 | === azure vm === |
| | 249 | |
| | 250 | ==== azure vm list ==== |
| | 251 | |
| | 252 | * 檢查 vm 狀態 |
| | 253 | |
| | 254 | {{{ |
| | 255 | ~$ azure vm list |
| | 256 | info: Executing command vm list |
| | 257 | + Getting virtual machines |
| | 258 | data: ResourceGroupName Name ProvisioningState PowerState Location Size |
| | 259 | data: ------------------- ---------------------- ----------------- -------------- ------------- -------------- |
| | 260 | info: vm list command OK |
| | 261 | }}} |
| | 262 | |
| | 263 | ==== azure vm image list ==== |
| | 264 | |
| | 265 | * 查詢作業系統範本 Image |
| | 266 | {{{ |
| | 267 | ~$ azure vm image list |
| | 268 | info: Executing command vm image list |
| | 269 | Location: southeastasia |
| | 270 | Publisher: OpenLogic |
| | 271 | + Getting virtual machine image offers (Publisher: "OpenLogic" Location:"southeastasia") |
| | 272 | data: Publisher Offer Sku OS Version Location Urn |
| | 273 | data: --------- ---------- --- ----- ------------ ------------- ------------------------------------- |
| | 274 | data: OpenLogic CentOS 6.5 Linux 6.5.201501 southeastasia OpenLogic:CentOS:6.5:6.5.201501 |
| | 275 | data: OpenLogic CentOS 6.5 Linux 6.5.201503 southeastasia OpenLogic:CentOS:6.5:6.5.201503 |
| | 276 | data: OpenLogic CentOS 6.5 Linux 6.5.201506 southeastasia OpenLogic:CentOS:6.5:6.5.201506 |
| | 277 | data: OpenLogic CentOS 6.5 Linux 6.5.20150904 southeastasia OpenLogic:CentOS:6.5:6.5.20150904 |
| | 278 | data: OpenLogic CentOS 6.5 Linux 6.5.20160309 southeastasia OpenLogic:CentOS:6.5:6.5.20160309 |
| | 279 | data: OpenLogic CentOS 6.6 Linux 6.6.201501 southeastasia OpenLogic:CentOS:6.6:6.6.201501 |
| | 280 | data: OpenLogic CentOS 6.6 Linux 6.6.201503 southeastasia OpenLogic:CentOS:6.6:6.6.201503 |
| | 281 | data: OpenLogic CentOS 6.6 Linux 6.6.201506 southeastasia OpenLogic:CentOS:6.6:6.6.201506 |
| | 282 | data: OpenLogic CentOS 6.6 Linux 6.6.20150706 southeastasia OpenLogic:CentOS:6.6:6.6.20150706 |
| | 283 | data: OpenLogic CentOS 6.6 Linux 6.6.20150731 southeastasia OpenLogic:CentOS:6.6:6.6.20150731 |
| | 284 | data: OpenLogic CentOS 6.6 Linux 6.6.20160309 southeastasia OpenLogic:CentOS:6.6:6.6.20160309 |
| | 285 | data: OpenLogic CentOS 6.7 Linux 6.7.20150815 southeastasia OpenLogic:CentOS:6.7:6.7.20150815 |
| | 286 | data: OpenLogic CentOS 6.7 Linux 6.7.20160303 southeastasia OpenLogic:CentOS:6.7:6.7.20160303 |
| | 287 | data: OpenLogic CentOS 6.7 Linux 6.7.20160310 southeastasia OpenLogic:CentOS:6.7:6.7.20160310 |
| | 288 | data: OpenLogic CentOS 6.8 Linux 6.8.20160620 southeastasia OpenLogic:CentOS:6.8:6.8.20160620 |
| | 289 | data: OpenLogic CentOS 7.0 Linux 7.0.20150128 southeastasia OpenLogic:CentOS:7.0:7.0.20150128 |
| | 290 | data: OpenLogic CentOS 7.0 Linux 7.0.20150325 southeastasia OpenLogic:CentOS:7.0:7.0.20150325 |
| | 291 | data: OpenLogic CentOS 7.0 Linux 7.0.20150605 southeastasia OpenLogic:CentOS:7.0:7.0.20150605 |
| | 292 | data: OpenLogic CentOS 7.0 Linux 7.0.20150904 southeastasia OpenLogic:CentOS:7.0:7.0.20150904 |
| | 293 | data: OpenLogic CentOS 7.0 Linux 7.0.20160309 southeastasia OpenLogic:CentOS:7.0:7.0.20160309 |
| | 294 | data: OpenLogic CentOS 7.1 Linux 7.1.20150410 southeastasia OpenLogic:CentOS:7.1:7.1.20150410 |
| | 295 | data: OpenLogic CentOS 7.1 Linux 7.1.20150605 southeastasia OpenLogic:CentOS:7.1:7.1.20150605 |
| | 296 | data: OpenLogic CentOS 7.1 Linux 7.1.20150731 southeastasia OpenLogic:CentOS:7.1:7.1.20150731 |
| | 297 | data: OpenLogic CentOS 7.1 Linux 7.1.20160308 southeastasia OpenLogic:CentOS:7.1:7.1.20160308 |
| | 298 | data: OpenLogic CentOS 7.2 Linux 7.2.20160303 southeastasia OpenLogic:CentOS:7.2:7.2.20160303 |
| | 299 | data: OpenLogic CentOS 7.2 Linux 7.2.20160308 southeastasia OpenLogic:CentOS:7.2:7.2.20160308 |
| | 300 | data: OpenLogic CentOS 7.2 Linux 7.2.20160620 southeastasia OpenLogic:CentOS:7.2:7.2.20160620 |
| | 301 | data: OpenLogic CentOS-HPC 6.5 Linux 6.5.20160408 southeastasia OpenLogic:CentOS-HPC:6.5:6.5.20160408 |
| | 302 | data: OpenLogic CentOS-HPC 7.1 Linux 7.1.20160408 southeastasia OpenLogic:CentOS-HPC:7.1:7.1.20160408 |
| | 303 | info: vm image list command OK |
| | 304 | }}} |
| | 305 | |
| | 306 | ==== azure vm sizes ==== |
| | 307 | |
| | 308 | * 查詢 VM 大小種類 |
| | 309 | ** 所需參數:`--location` 或 `--vm-name` |
| | 310 | {{{ |
| | 311 | ~$ azure vm sizes --location southeastasia |
| | 312 | }}} |
| | 313 | |
| | 314 | ==== azure vm quick-create ==== |
| | 315 | |
| | 316 | * 快速建立新的 VM |
| | 317 | {{{ |
| | 318 | Usage: vm quick-create [options] <resource-group> <name> <location> <os-type> <image-urn> <admin-username> <admin-password> |
| | 319 | }}} |
| | 320 | {| class="wikitable" |
| | 321 | |- |
| | 322 | ! 變數 !! 可用選項 |
| | 323 | |- |
| | 324 | | location || 詳見 `azure location list` |
| | 325 | |- |
| | 326 | | os-type || <ul><li>Windows</li><li>Linux</li></ul> |
| | 327 | |- |
| | 328 | | image-urn || 詳見 `azure vm image list` |
| | 329 | |} |
| | 330 | * 範例: |
| | 331 | {{{ |
| | 332 | ~$ azure vm quick-create cassandra cassandra12v2 southeastasia Linux OpenLogic:CentOS:7.2:latest jazz TenM@x1234 |
| | 333 | }}} |
| | 334 | |
| | 335 | ==== azure vm create ==== |
| | 336 | |
| | 337 | * 手動建立 VM |
| | 338 | {{{ |
| | 339 | Usage: vm create [options] <resource-group> <name> <location> <os-type> |
| | 340 | }}} |
| | 341 | * 範例:使用現成 OS 碟,附掛到新的 VM |
| | 342 | {{{ |
| | 343 | -f, --nic-name <nic-name> ## 可使用相同 resource group 的現有 NIC (必須先 detach) |
| | 344 | }}} |
| | 345 | {{{ |
| | 346 | ~$ azure vm create -g cassandra -n test -l southeastasia -y Linux \ |
| | 347 | --vm-size Standard_DS3_v2 \ |
| | 348 | --os-disk-vhd https://cli17432911802090392708.blob.core.windows.net/vhds/cli7ee1f2e662a40b58-os-1467009098723.vhd \ |
| | 349 | -f testnic}}} |
| | 350 | |
| | 351 | === azure storage === |
| | 352 | * 官方文件:[https://azure.microsoft.com/zh-tw/documentation/articles/storage-azure-cli/ 使用 Azure CLI 搭配 Azure 儲存體] |
| | 353 | * `azure storage account list` 可以查詢目前建立的 storage account |
| | 354 | {{{ |
| | 355 | ~$ azure storage account list |
| | 356 | info: Executing command storage account list |
| | 357 | + Getting storage accounts |
| | 358 | data: Name Type Location Resource Group |
| | 359 | data: ------------------------ ------------ ------------- ------------------- |
| | 360 | data: tenmaxsglog Standard_LRS southeastasia tenmax-sg-data |
| | 361 | info: storage account list command OK |
| | 362 | }}} |
| | 363 | * `azure storage account keys list <name>` 可以查詢 storage account key |
| | 364 | {{{ |
| | 365 | ~$ azure storage account keys list tenmaxsglog |
| | 366 | info: Executing command storage account keys list |
| | 367 | Resource group name: tenmax-sg-data |
| | 368 | + Getting storage account keys |
| | 369 | data: Primary: *********** |
| | 370 | data: Secondary: *********** |
| | 371 | info: storage account keys list command OK |
| | 372 | }}} |
| | 373 | |
| | 374 | == AzureKit 安裝與使用 == |
| | 375 | |
| | 376 | * pop 寫的 command line 工具 |
| | 377 | ** 原始碼: http://github.com/tenmax/azurekit |
| | 378 | * Mac OS X 安裝 |
| | 379 | {{{ |
| | 380 | ~$ brew tap tenmax/azure |
| | 381 | ~$ brew install azurekit |
| | 382 | }}} |
| | 383 | |
| | 384 | === 設定檔 === |
| | 385 | |
| | 386 | * azurekit 包含 `azurecat`, `azuresink`, `azuresas` 三個小工具 |
| | 387 | * 設定檔放在 `${HOME}/.azure/storagekeys`, 內容包括: |
| | 388 | {{{ |
| | 389 | DefaultEndpointsProtocol=https; |
| | 390 | AccountName=.........; |
| | 391 | AccountKey=....... |
| | 392 | }}} |
| | 393 | |
| | 394 | === azurecat === |
| | 395 | |
| | 396 | * A CLI tool to cat microsoft azure blob storage |
| | 397 | * 直接 cat 遠端 Azure Blob Storage 的檔案 |
| | 398 | |
| | 399 | === azuresink === |
| | 400 | |
| | 401 | * A CLI tool to pipe standard in to microsoft azure blob storage |
| | 402 | * 將本機檔案上傳到 Azure Blob Storage |
| | 403 | |
| | 404 | === azuresas === |
| | 405 | |
| | 406 | * 取得 Azure Blob Storage 的 sharing URL |
| | 407 | |
| | 408 | == GUI 界面 == |
| | 409 | |
| | 410 | === Microsoft Azure Storage Explorer === |
| | 411 | |
| | 412 | * http://storageexplorer.com/ |
| | 413 | * 注意:需打開 MAC 安全性設定,才能進行安裝。 |
| | 414 | * [[File:Mac_Security_Setting.png|400px]] |
| | 415 | |
| | 416 | === Cyberduck === |
| | 417 | |
| | 418 | * Mac OS X 安裝 |
| | 419 | {{{ |
| | 420 | brew install Caskroom/cask/cyberduck |
| | 421 | }}} |
| | 422 | |
| | 423 | == 其他 CLI 工具 == |
| | 424 | |
| | 425 | * https://www.npmjs.com/package/azure-storage-cmd |
| | 426 | * https://github.com/bfaludi/azrcmd |
| | 427 | |
| | 428 | = Cassandra = |
| | 429 | == 內部文件 == |
| | 430 | == 自學教材 == |
| | 431 | |
| | 432 | * [https://www.safaribooksonline.com/library/view/cassandra-administration/9781782164203/ Cassandra Administration] |
| | 433 | ** by C Y Kan |
| | 434 | ** Publisher: Packt Publishing |
| | 435 | ** Release Date: November 2013 |
| | 436 | ** ISBN: 9781782164203 |
| | 437 | ** Running time: 2:51:40 |
| | 438 | |
| | 439 | == 維運技巧 == |
| | 440 | |
| | 441 | === 加機器 === |
| | 442 | |
| | 443 | === 跨資料中心 === |
| | 444 | |
| | 445 | * 跨資料中心時,Cassandra Driver 最好加上 Compression 的設定 |
| | 446 | * [參考] https://datastax.github.io/java-driver/2.1.7/features/compression/ |
| | 447 | [[File:after_compression.png|400px]] |
| | 448 | |
| | 449 | = Ansible = |
| | 450 | == Ansible 快速入門 == |
| | 451 | * sysadmincasts 三小時入門 |
| | 452 | ** [https://sysadmincasts.com/episodes/43-19-minutes-with-ansible-part-1-4 Episode #43 - 19 Minutes With Ansible (Part 1/4)] |
| | 453 | ** [https://sysadmincasts.com/episodes/45-learning-ansible-with-vagrant-part-2-4 Episode #45 - Learning Ansible with Vagrant (Part 2/4)] |
| | 454 | ** [https://sysadmincasts.com/episodes/46-configuration-management-with-ansible-part-3-4 Episode #46 - Configuration Management with Ansible (Part 3/4)] |
| | 455 | ** [https://sysadmincasts.com/episodes/47-zero-downtime-deployments-with-ansible-part-4-4 Episode #47 - Zero-downtime Deployments with Ansible (Part 4/4)] |
| | 456 | |
| | 457 | = Gradle = |
| | 458 | |
| | 459 | == 參考書目 == |
| | 460 | |
| | 461 | * [http://storage.pardot.com/68052/1700/Building_and_Testing_with_Gradle.pdf 免費電子書(1) Building and Testing with Gradle] |
| | 462 | * [http://storage.pardot.com/68052/1448/Gradle_Beyond_the_Basics.pdf 免費電子書(2) Gradle Beyond the Basics] |
| | 463 | |
| | 464 | == 安裝 gradle == |
| | 465 | |
| | 466 | * Mac 安裝 |
| | 467 | {{{brew install gradle}}} |
| | 468 | * Debian / Ubuntu 安裝 |
| | 469 | {{{apt-get -y install gradle}}} |
| | 470 | * 習慣 bash completion 的可以額外下載 gradle 的自動命令補完,並加入對應的 `.bashrc` 設定 |
| | 471 | {{{ |
| | 472 | curl -L -s https://gist.github.com/nolanlawson/8694399/raw/gradle-tab-completion.bash -o /usr/local/etc/bash_completion.d/gradle |
| | 473 | }}} |
| | 474 | |
| | 475 | == gradle init == |
| | 476 | |
| | 477 | * 使用 `gradle init` 產生 gradle 專案目錄的範本 |
| | 478 | {{{ |
| | 479 | ~$ mkdir -p gradle-sample |
| | 480 | ~$ cd gradle-sample |
| | 481 | ~/gradle-sample$ gradle init |
| | 482 | :wrapper |
| | 483 | :init |
| | 484 | |
| | 485 | BUILD SUCCESSFUL |
| | 486 | |
| | 487 | Total time: 2.419 secs |
| | 488 | |
| | 489 | This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.12/userguide/gradle_daemon.html |
| | 490 | }}} |
| | 491 | * `gradle init` 產生的目錄結構如下: |
| | 492 | {{{ |
| | 493 | . |
| | 494 | ├── build.gradle |
| | 495 | ├── gradle |
| | 496 | │ └── wrapper |
| | 497 | │ ├── gradle-wrapper.jar |
| | 498 | │ └── gradle-wrapper.properties |
| | 499 | ├── gradlew |
| | 500 | ├── gradlew.bat |
| | 501 | └── settings.gradle |
| | 502 | |
| | 503 | 2 directories, 6 files |
| | 504 | }}} |
| | 505 | * `gradle init` 支援產生不同的範本,包括: |
| | 506 | ** `gradle init --type basic` |
| | 507 | ** `gradle init --type groovy-library` |
| | 508 | ** `gradle init --type java-library` |
| | 509 | ** `gradle init --type pom` |
| | 510 | ** `gradle init --type scala-library` |
| | 511 | |
| | 512 | == gradle tasks == |
| | 513 | |
| | 514 | * 可以用 `gradle tasks` 了解目前定義了哪些 task |
| | 515 | {{{ |
| | 516 | :tasks |
| | 517 | |
| | 518 | ------------------------------------------------------------ |
| | 519 | All tasks runnable from root project |
| | 520 | ------------------------------------------------------------ |
| | 521 | |
| | 522 | Build Setup tasks |
| | 523 | ----------------- |
| | 524 | init - Initializes a new Gradle build. [incubating] |
| | 525 | wrapper - Generates Gradle wrapper files. [incubating] |
| | 526 | |
| | 527 | Help tasks |
| | 528 | ---------- |
| | 529 | buildEnvironment - Displays all buildscript dependencies declared in root project 'gradle-sample'. |
| | 530 | components - Displays the components produced by root project 'gradle-sample'. [incubating] |
| | 531 | dependencies - Displays all dependencies declared in root project 'gradle-sample'. |
| | 532 | dependencyInsight - Displays the insight into a specific dependency in root project 'gradle-sample'. |
| | 533 | help - Displays a help message. |
| | 534 | model - Displays the configuration model of root project 'gradle-sample'. [incubating] |
| | 535 | projects - Displays the sub-projects of root project 'gradle-sample'. |
| | 536 | properties - Displays the properties of root project 'gradle-sample'. |
| | 537 | tasks - Displays the tasks runnable from root project 'gradle-sample'. |
| | 538 | |
| | 539 | BUILD SUCCESSFUL |
| | 540 | |
| | 541 | Total time: 1.994 secs |
| | 542 | |
| | 543 | This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.12/userguide/gradle_daemon.html |
| | 544 | }}} |
| | 545 | |
| | 546 | == gradle build == |
| | 547 | |
| | 548 | * 編譯並產生 distribution |
| | 549 | {{{gradle build}}} |
| | 550 | |
| | 551 | == gradle clean == |
| | 552 | |
| | 553 | * 清除編譯好的 build |
| | 554 | {{{gradle clean}}} |
| | 555 | |
| | 556 | == plugin: 'application' == |
| | 557 | === gradle distZip === |
| | 558 | |
| | 559 | * 產生 Release 用的 Zip 檔 |
| | 560 | {{{ |
| | 561 | ~/git/tenmax-log-toolkit$ gradle distZip |
| | 562 | :compileJava |
| | 563 | Note: Some input files use or override a deprecated API. |
| | 564 | Note: Recompile with -Xlint:deprecation for details. |
| | 565 | Note: Some input files use unchecked or unsafe operations. |
| | 566 | Note: Recompile with -Xlint:unchecked for details. |
| | 567 | :processResources UP-TO-DATE |
| | 568 | :classes |
| | 569 | :jar |
| | 570 | :elandbidStartScript |
| | 571 | :elandproductStartScript |
| | 572 | :elandreqStartScript |
| | 573 | :elandreqoldStartScript |
| | 574 | :imaxaggreStartScript |
| | 575 | :pmaxaggreStartScript |
| | 576 | :pmaxexportStartScript |
| | 577 | :startScripts |
| | 578 | :distZip |
| | 579 | |
| | 580 | BUILD SUCCESSFUL |
| | 581 | |
| | 582 | Total time: 7.461 secs |
| | 583 | |
| | 584 | This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.12/userguide/gradle_daemon.html |
| | 585 | jazz@jazzbook ~/git/tenmax-log-toolkit$ ls build/distributions/tenmax-log-toolkit.zip |
| | 586 | build/distributions/tenmax-log-toolkit.zip |
| | 587 | }}} |
| | 588 | |
| | 589 | == plugin: 'spring-boot' == |
| | 590 | |
| | 591 | === gradle bootRun === |
| | 592 | |
| | 593 | {{{ |
| | 594 | Application tasks |
| | 595 | ----------------- |
| | 596 | bootRun - Run the project with support for auto-detecting main class and reloading static resources |
| | 597 | }}} |
| | 598 | |
| | 599 | == 學習資源 == |
| | 600 | |
| | 601 | * http://projects.spring.io/spring-boot/ |
| | 602 | |
| | 603 | = Others = |
| | 604 | |
| | 605 | == brew == |
| | 606 | |
| | 607 | {| class="wikitable" |
| | 608 | |- |
| | 609 | ! 指令 !! 描述 !! 範例 |
| | 610 | |- |
| | 611 | | `brew doctor` || 檢查 brew 系統是否有潛在問題 || {{{~$ brew doctor |
| | 612 | Please note that these warnings are just used to help the Homebrew maintainers |
| | 613 | with debugging if you file an issue. If everything you use Homebrew for is |
| | 614 | working fine: please don't worry and just ignore them. Thanks! |
| | 615 | |
| | 616 | Warning: Your Homebrew is outdated. |
| | 617 | You haven't updated for at least 24 hours. This is a long time in brewland! |
| | 618 | To update Homebrew, run `brew update`.}}} |
| | 619 | |- |
| | 620 | | `brew desc` || 顯示套件的簡單描述 || {{{~$ brew desc mysql |
| | 621 | mysql: Open source relational database management system}}} |
| | 622 | |- |
| | 623 | | `brew info` || 顯示套件的詳細描述 || {{{~$ brew info mysql |
| | 624 | mysql: stable 5.7.12 (bottled) |
| | 625 | Open source relational database management system |
| | 626 | https://dev.mysql.com/doc/refman/5.7/en/ |
| | 627 | Conflicts with: mariadb, mariadb-connector-c, mysql-cluster, mysql-connector-c, percona-server |
| | 628 | Not installed |
| | 629 | From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/mysql.rb |
| | 630 | ==> Dependencies |
| | 631 | Build: cmake ✘ |
| | 632 | Required: openssl ✔ |
| | 633 | ==> Options |
| | 634 | --with-archive-storage-engine |
| | 635 | Compile with the ARCHIVE storage engine enabled |
| | 636 | --with-blackhole-storage-engine |
| | 637 | Compile with the BLACKHOLE storage engine enabled |
| | 638 | --with-debug |
| | 639 | Build with debug support |
| | 640 | --with-embedded |
| | 641 | Build the embedded server |
| | 642 | --with-local-infile |
| | 643 | Build with local infile loading support |
| | 644 | --with-test |
| | 645 | Build with unit tests |
| | 646 | ==> Caveats |
| | 647 | We've installed your MySQL database without a root password. To secure it run: |
| | 648 | mysql_secure_installation |
| | 649 | |
| | 650 | To connect run: |
| | 651 | mysql -uroot |
| | 652 | |
| | 653 | To have launchd start mysql now and restart at login: |
| | 654 | brew services start mysql |
| | 655 | Or, if you don't want/need a background service you can just run: |
| | 656 | mysql.server start}}} |
| | 657 | |} |
| | 658 | |
| | 659 | === 建立自己的 Cask === |
| | 660 | |
| | 661 | * 參考文件:https://github.com/caskroom/homebrew-cask/blob/master/doc/development/adding_a_cask.md |
| | 662 | * STEP 1: |
| | 663 | {{{ |
| | 664 | ~$ brew cask create microsoft-azure-storage-explorer |
| | 665 | }}} |
| | 666 | * STEP 2: 照著修改內容 - 可以先看一下[https://github.com/caskroom/homebrew-cask/pulls 別人的 Pull Request 常被檢討什麼] |
| | 667 | {{{ |
| | 668 | cask 'microsoft-azure-storage-explorer' do |
| | 669 | version :latest |
| | 670 | sha256 :no_check |
| | 671 | |
| | 672 | url 'https://go.microsoft.com/fwlink/?LinkId=708342' |
| | 673 | name 'Microsoft Azure Storage Explorer' |
| | 674 | homepage 'http://storageexplorer.com/' |
| | 675 | license :gratis |
| | 676 | |
| | 677 | app 'Microsoft Azure Storage Explorer.app' |
| | 678 | end |
| | 679 | }}} |
| | 680 | * STEP 3: 檢驗是否可以正常下載 |
| | 681 | {{{ |
| | 682 | ~$ brew cask audit --download microsoft-azure-storage-explorer |
| | 683 | }}} |
| | 684 | * STEP 4: 檢驗語法是否正確 |
| | 685 | {{{ |
| | 686 | ~$ cd "$(brew --repository)"/Library/Taps/caskroom/homebrew-cask |
| | 687 | homebrew-cask$ brew cask style --fix Casks/microsoft-azure-storage-explorer.rb |
| | 688 | }}} |
| | 689 | * STEP 5: 檢查安裝與反安裝是否正確 |
| | 690 | {{{ |
| | 691 | homebrew-cask$ brew cask install microsoft-azure-storage-explorer |
| | 692 | homebrew-cask$ brew cask uninstall microsoft-azure-storage-explorer |
| | 693 | }}} |
| | 694 | * STEP 6: 建立新的 branch 分支 |
| | 695 | {{{ |
| | 696 | homebrew-cask$ git checkout -b microsoft-azure-storage-explorer |
| | 697 | }}} |
| | 698 | * STEP 7: 加入新的 Cask Formulae |
| | 699 | {{{ |
| | 700 | homebrew-cask$ git add Casks/microsoft-azure-storage-explorer.rb |
| | 701 | homebrew-cask$ git diff --cached |
| | 702 | homebrew-cask$ git commit -v |
| | 703 | }}} |
| | 704 | * STEP 8: 送上自己的 gitlab 用來提交 Pull Request ( PS. 必須先 fork homebrew-cask 到自己的 github 帳號下 ) |
| | 705 | {{{ |
| | 706 | homebrew-cask$ git push https://github.com/jazzwang/homebrew-cask microsoft-azure-storage-explorer |
| | 707 | }}} |
| | 708 | * STEP 9: 等 homebrew-cask 的 Travis CI 通過,若有錯誤,就還要反覆修改並重新提交內容。 |
| | 709 | |
| | 710 | === 更新自己的 Cask === |
| | 711 | |
| | 712 | * 參考: https://github.com/caskroom/homebrew-cask/blob/master/CONTRIBUTING.md#updating-a-cask |
| | 713 | * STEP 1: 安裝 `cask-repair` |
| | 714 | {{{ |
| | 715 | # install and setup script - only needed once |
| | 716 | brew install vitorgalvao/tiny-scripts/cask-repair |
| | 717 | cask-repair --help |
| | 718 | |
| | 719 | # fork homebrew-cask to your account - only needed once |
| | 720 | cd "$(brew --repository)/Library/Taps/caskroom/homebrew-cask/Casks" |
| | 721 | hub fork |
| | 722 | cask-repair --pull origin --push jazzwang microsoft-azure-storage-explorer |
| | 723 | }}} |
| | 724 | 或 |
| | 725 | {{{ |
| | 726 | cask-repair microsoft-azure-storage-explorer |
| | 727 | }}} |
| | 728 | * STEP 2: 照著問題回答,例如修改版號、修改下載網址等 |
| | 729 | {{{ |
| | 730 | Type the new version (or leave blank to use the current one) |
| | 731 | > 0.8.0 |
| | 732 | Paste the new URL (or leave blank to use the current one) |
| | 733 | > http://go.microsoft.com/fwlink/?LinkId=708342 |
| | 734 | }}} |
| | 735 | |
| | 736 | === Homebrew Tap === |
| | 737 | |
| | 738 | * 舉凡官方不收或是有 license 疑慮的 formula 變可透過 Homebrew Tap 的方式來自已管理。 |
| | 739 | * [參考] https://blog.gasol.tw/make-your-own-homebrew/ |
| | 740 | |
| | 741 | == Tableau == |
| | 742 | |
| | 743 | * 為了看 DSP 與 DMP 的 Daily Report,可以使用 Tableau 來觀察 CSV 檔的內容。 |
| | 744 | * Mac 安裝 |
| | 745 | {{{ |
| | 746 | brew install Caskroom/cask/tableau-public |
| | 747 | }}} |
| | 748 | |
| | 749 | == Hadoop == |
| | 750 | |
| | 751 | * 在 Mac 上安裝單機版(local mode)的 Hadoop 還蠻簡單的,只需要透過 `brew` 就可以裝好。 |
| | 752 | * Mac 安裝 |
| | 753 | {{{ |
| | 754 | brew install hadoop |
| | 755 | }}} |
| | 756 | |
| | 757 | == Hive == |
| | 758 | |
| | 759 | * 在 Mac 上安裝單機版(local mode)的 Hive 還蠻簡單的,只需要透過 `brew` 就可以裝好。 |
| | 760 | * Mac 安裝 |
| | 761 | {{{ |
| | 762 | brew install hive |
| | 763 | }}} |
| | 764 | |
| | 765 | == Spark == |
| | 766 | |
| | 767 | * 在 Mac 上安裝單機版(local mode)的 Apache Spark 還蠻簡單的,只需要透過 `brew` 就可以裝好。 |
| | 768 | * Mac 安裝 |
| | 769 | {{{ |
| | 770 | brew install apache-spark |
| | 771 | }}} |
| | 772 | |
| | 773 | == Gist == |
| | 774 | |
| | 775 | * http://defunkt.io/gist/ |
| | 776 | * https://github.com/defunkt/gist |
| | 777 | * RubyGems 安裝: |
| | 778 | {{{ |
| | 779 | gem install gist |
| | 780 | }}} |
| | 781 | * Mac 安裝 |
| | 782 | {{{ |
| | 783 | brew install gist |
| | 784 | }}} |
| | 785 | * Debian / Ubuntu 安裝 |
| | 786 | {{{ |
| | 787 | apt-get -y install gist |
| | 788 | }}} |
| | 789 | * 使用 |
| | 790 | ** 登入 - `gist --login` |
| | 791 | ** 上傳單一檔案 - `gist file1` |
| | 792 | ** 上傳多個檔案 - `gist file1 file2` |
| | 793 | ** 上傳 STDIN 到指定檔名 - `指令 | gist -f "檔名"` |
| | 794 | ** 複製 gist URL 到剪貼簿 - `指令 | gist -c` |
| | 795 | |
| | 796 | == Bash == |
| | 797 | |
| | 798 | * 偶爾會用到一些 Bash 的色塊 COLOR |
| | 799 | * 參考文件: |
| | 800 | ** http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html |
| | 801 | ** https://wiki.archlinux.org/index.php/Bash/Prompt_customization |
| | 802 | * TLDP 的測試腳本可以在 gist 取得 |
| | 803 | ** https://gist.github.com/jazzwang/55203a9f33386e0e567328fb86ebf7db |
| | 804 | |
| | 805 | == Spring Boot == |
| | 806 | |
| | 807 | * 假設 project 名稱是 tenmax-audience-library ,主程式的 package 是 io.tenmax |
| | 808 | * 要切換 Spring Profile 可以在環境變數中,設定 `SPRING_PROFILES_ACTIVE` 為特定的 profile 名稱 |
| | 809 | ** [參考] http://stackoverflow.com/questions/23367507/how-to-pass-system-property-to-gradle-task |
| | 810 | {{{ |
| | 811 | export SPRING_PROFILES_ACTIVE=dev |
| | 812 | }}} |
| | 813 | * 若要切換 log4j 的 level 一般要在 `application.yml` 先改好 |
| | 814 | ** [參考] http://stackoverflow.com/questions/20485059/spring-boot-how-can-i-set-the-logging-level-with-application-properties |
| | 815 | ** 因為有使用 gradle 的 `application` plugin,參考產生出來的 `bin/tenmax-audience-library` start script,發現可以在環境變數中,設定 `TENMAX_AUDIENCE_LIBRARY_OPTS` |
| | 816 | {{{ |
| | 817 | export TENMAX_AUDIENCE_LIBRARY_OPTS="-Dlogging.level.io.tenmax=DEBUG" |
| | 818 | }}} |
| | 819 | |
| | 820 | == Intellij IDEA CE == |
| | 821 | |
| | 822 | * MAC OS X 安裝 |
| | 823 | {{{ |
| | 824 | brew cask install intellij-idea-ce |
| | 825 | }}} |
| | 826 | * 設定用 command line 指令 `idea` 就可以啟動 IDEA |
| | 827 | [[File:Idea command line launcher.png|400px]] |
| | 828 | |
| | 829 | == gitbook == |
| | 830 | |
| | 831 | * MAC OS X 安裝 |
| | 832 | * 編輯器 |
| | 833 | {{{ |
| | 834 | brew cask install gitbook-editor |
| | 835 | }}} |
| | 836 | * 用戶端程式 |
| | 837 | {{{ |
| | 838 | npm -g install gitbook-cli |
| | 839 | }}} |
| | 840 | |
| | 841 | == mailx == |
| | 842 | |
| | 843 | * CentOS 安裝 |
| | 844 | {{{ |
| | 845 | sudo yum -y install mailx postfix |
| | 846 | }}} |
| | 847 | * 複製 Mac OS 家目錄下 `Library/Application\ Support/Firefox/Profiles/*.default` 的 `cert*.db` 與 `key*.db` 放到 Linux 家目錄的 `.cert` 底下 |
| | 848 | * 設定帳號資訊於 `.mailrc` |
| | 849 | {{{ |
| | 850 | [jazz@tenmax-sg-spark1 ~]$ cat .mailrc |
| | 851 | set smtp-use-starttls |
| | 852 | set nss-config-dir=/home/jazz/.cert |
| | 853 | set ssl-verify=ignore |
| | 854 | set smtp=smtp://outlook-apaccentral.office365.com:587 |
| | 855 | set smtp-auth=login |
| | 856 | set smtp-auth-user=jazz@funp.com |
| | 857 | set smtp-auth-password=$PASSWORD |
| | 858 | set from="jazz@tenmax.io(Jazz Wang)" |
| | 859 | }}} |
| | 860 | * 使用 `mail -s "信件標題" 收件者信箱 < 信件內容 ` 即可用命令列寄信 |
| | 861 | * [參考] http://www.systutorials.com/1411/sending-email-from-mailx-command-in-linux-using-gmails-smtp/ |
| | 862 | * [參考] http://www.binarytides.com/linux-mailx-command/ |
| | 863 | |
| | 864 | == jq == |
| | 865 | |
| | 866 | {{{ |
| | 867 | azurecat -b 4096 -z $URL |
| | 868 | | jq -c '. | select( .bidRequest.domain=="setn.com") |
| | 869 | | { underbid: .bidResponse.campUnderIds, winCampaign: .bidResponse.campaignId , |
| | 870 | space: .bidRequest.spaceId , time: .dateTime }' |
| | 871 | }}} |