2018/10/10
解決升級 Ubuntu 18.04 (bionic) 後 256MB RAM 的機器開不了機
Ubuntu 18.04 出來也半個月了
一直想嘗試看看, 雖然說我都用 server 版本 基本上沒什麼差
趁著國慶假期 手癢升級了手邊的一台只有 256MB RAM 的 VM
升級前當然先把套件都升到最新
```
sudo apt update
sudo apt upgrade
sudo autoremove
```
然後就是重頭戲了 -- 開始升級
```
sudo do-release-upgrade
```
過程中會問你四次左右的 y/n 都是選 y 就對了
升級完開機之後 出現了悲劇
```
kernel panic not syncing out of memory and no killable processes
```
嘗試著加大 RAM 到 384MB 是可以開機的
於似乎開始找解決辦法
試過把舊版 linux-kernel 都移除, grub 重裝都不太行
最後找到了這篇
https://askubuntu.com/questions/956737/end-kernel-panic-not-syncing-out-of-memory-and-no-killable-processes/956742
```
cd /lib/modules/4.15.0-36-generic
sudo find . -name *.ko -exec strip --strip-unneeded {} +
sudo update-initramfs -c -k 4.15.0-36-generic
```
重新調整 RAM 為 256MB
登登登 正常開機進去了
不過目前 pppoeconf 設定開機自動撥 pppoe 的功能似乎是失效的 要再想辦法解決了
2018/09/29
macOS 如何清除 dns cache
在 windows 系統中可以透過 `ipconfig /flushdns` 來清除 dns cache
那麼在 macOS 中要怎麼清除呢?
很簡單
```
sudo killall -HUP mDNSResponder
```
2018/09/27
分離 git repository 中某個資料夾並獨立為一個 repository
由於歷史因素, 公司以前只開一個 repository, 用資料夾分不同的 applications
然後現在要導入自動化, 總不能每次都下載那一大包 source code 吧
所以想辦法看有沒有可以把某個資料夾獨立成一個 repository 並且 commit log 都可以保留的辦法
當然, 我可以把該資料夾手動複製然後創立新的 repository 並且 commit 上去
但是這樣就會遺失過往的 commit log
於似乎找了一下有沒有其他方法
git 這麼神, 當然有
1. 先建立好要獨立的 repository, 以 bitbucket 為例 git@bitbucket.org:user/sub-folder-project1
2. 下載原先大 repository, 並切換到要分離的資料夾的上層目錄
```shell
$ git clone git@bitbucket.org:user/huge-project
$ cd huge-project/path/to/sub-folder-project1
$ cd ..
```
3. 開始執行 git 指令分開 sub-folder-project1
```shell
# git filter-branch --prune-empty --subdirectory-filter FOLDER-NAME BRANCH-NAME
$ git filter-branch --prune-empty --subdirectory-filter sub-folder-project1 develop
```
4. 將分離出來的 sub-folder-project1 加上遠端資訊並且 push
```shell
$ git remote add subproject1 git@bitbucket.org:user/sub-folder-project1
$ git push -u origin develop
```
這樣就大功告成了啊~~
不過原本的 huge-project 的 develop 就會因此而亂掉, 若還需要繼續使用的話, 建議砍掉重新 clone 一份
參考: [https://help.github.com/articles/splitting-a-subfolder-out-into-a-new-repository/](https://help.github.com/articles/splitting-a-subfolder-out-into-a-new-repository/)
2018/09/04
深入了解 ansible 中 tags 使用方式
我們先新增一個 role
包含了四個檔案 main.yml, all.yml, deploy.yml, other.yml
每個 task 檔 都會執行 3 個 task 分別是 無 tag(all tag) deploy tag, other tag
並且 main.yml 會用 include 的方式載入剩餘三個 task 檔
為了方便說明我用 ABC DEF GHI JKL 取名 task
main.yml
```yaml
---
- name: A
debug:
msg: 'all tag in main.yml'
- name: B
debug:
msg: 'deploy tag in main.yml'
tags:
- deploy
- name: C
debug:
msg: 'other tag in main.yml'
tags:
- other
- name: X
include: all.yml
- name: Y
include: deploy.yml
tags:
- deploy
- name: Z
include: other.yml
tags:
- other
```
all.yml
```yaml
---
- name: D
debug:
msg: 'all in all.yml'
- name: E
debug:
msg: 'deploy in all.yml'
tags:
- deploy
- name: F
debug:
msg: 'other in all.yml'
tags:
- other
```
deploy.yml
```yaml
---
- name: G
debug:
msg: 'all in deploy.yml'
- name: H
debug:
msg: 'deploy in deploy.yml'
tags:
- deploy
- name: I
debug:
msg: 'other in deploy.yml'
tags:
- other
```
other.yml
```yaml
---
- name: J
debug:
msg: 'all in other.yml'
- name: K
debug:
msg: 'deploy in other.yml'
tags:
- deploy
- name: L
debug:
msg: 'other in other.yml'
tags:
- other
```
playbook則是用不同方式上 tags
```yaml
#!/usr/bin/env ansible-playbook
---
- hosts: localhost
gather_facts: no
roles:
- { role: role-tags }
- hosts: localhost
gather_facts: no
tags:
- deploy
roles:
- { role: role-tags }
- hosts: localhost
gather_facts: no
roles:
- { role: role-tags, tags: [ "deploy" ] }
```
執行 playbook 時也加入 tags 參數看看結果如何
1. playbook 完全不加 tags
```bash
ansible-playbook site.tags.yml # 結果:ABCDEFGHIJKL全部執行
ansible-playbook site.tags.yml --tags=deploy # 結果:BEGHIK
ansible-playbook site.tags.yml --tags=other # 結果:CFIJKL
ansible-playbook site.tags.yml --tags=gg # 結果:全部不會執行
```
2. 在 playbook 加 deploy tag
```bash
ansible-playbook site.tags.yml # 結果:ABCDEFGHIJKL全部執行
ansible-playbook site.tags.yml --tags=deploy # 結果:ABCDEFGHIJKL全部執行
ansible-playbook site.tags.yml --tags=other # 結果:CFIJKL
ansible-playbook site.tags.yml --tags=gg # 結果:全部不會執行
```
3. 在 playbook 的 role 上加 deploy tag
```bash
ansible-playbook site.tags.yml # 結果:ABCDEFGHIJKL全部執行
ansible-playbook site.tags.yml --tags=deploy # 結果:ABCDEFGHIJKL全部執行
ansible-playbook site.tags.yml --tags=other # 結果:CFIJKL
ansible-playbook site.tags.yml --tags=gg # 結果:全部不會執行
```
23的 --tags=deploy 結果跟我預想的不太一樣
我原本以為加在 playbook 上的 tag 是用來過濾我要執行哪些 roles/tasks
很顯然的他也是上 tag 而且是對以下所有 roles/tasks 標記
如此一來, 就可以了解如果你真的要過濾的話 在執行 playbook 加上 --tags 才會是過濾, 其他加在檔案的都為了之後過濾用的標記
補充:
可以在執行 playbook 時加上 --list-tasks 去看哪些 task 被加了什麼標記例如
```shell
$ ansible-playbook site.tags.yml --list-tasks
playbook: site.tags.yml
play #1 (localhost): localhost TAGS: []
tasks:
role-tags : A TAGS: [deploy]
role-tags : B TAGS: [deploy]
role-tags : C TAGS: [deploy, other]
role-tags : D TAGS: [deploy]
role-tags : E TAGS: [deploy]
role-tags : F TAGS: [deploy, other]
role-tags : G TAGS: [deploy]
role-tags : H TAGS: [deploy]
role-tags : I TAGS: [deploy, other]
role-tags : J TAGS: [deploy, other]
role-tags : K TAGS: [deploy, other]
role-tags : L TAGS: [deploy, other]
```
2018/08/10
如何將 elasticsearch 資料設定 TTL
一開始在研究 elasticsearch 時 沒想太多就直接拿來用
隨著時間過去, 資料累積愈來愈多, 開始有了需要將資料 TTL 的功能
於是開始研究有沒有這樣的功能
首先我們需要了解的技能有:
1. reindex
2. index template
3. date math index name with index alias
4. rollover index
第一步驟: 將原先的 index 重新命名
由於為了讓其他 get api 在設定 TTL 後還可以正常運作, 在這邊需要做這樣的動作, 原因是 index A 之後會變成 alias A
```
// reindex
POST _reindex
{
"source": {
"index": "game"
},
"dest": {
"index": "game_old"
}
}
// 刪除原 index
DELETE game
```
第二步驟: 建立 index template
讓之後建立的 index 自動設定一些內部參數
```
PUT _template/game-template
{
"index_patterns": ["game-*"],
"settings": {
"number_of_shards": 5,
"number_of_replicas": 1
},
"aliases" : {
"game-query" : {},
"game" : {}
},
"mappings" : {
}
}
```
第三步驟: 建立日期格式的 index 名稱
依據現在的時間建立 index 並且給予 write 的 alias,讓之後寫資料可以利用這個 alias 去寫
```
// <game-{now/d}-000001>
PUT /%3Cgame-%7Bnow%2Fd%7D-000001%3E
{
"aliases": {
"game-write": {}
}
}
```
第四步驟: 定期跑 rollover index
定期建立新的 index, 並將過時的 index 刪除
```
// 每天跑一次
POST /game-write/_rollover
{
"conditions": {
"max_age": "1d"
}
}
// 每天刪除舊資料
DELETE /game-YYYY.MM.dd-*
```
隱藏步驟: 如果要搬移舊資料, 則這時候再利用 reindex 功能建立
```
// reindex
POST _reindex
{
"source": {
"index": "game_old",
"query": {
"range": {
"createdDate": {
"gte": particularDate.getTime(),
"lt": particularDate.getTime() + 86400000
}
}
}
},
"dest": {
"index": "game-YYYY.MM.dd-000001"
}
}
// 全部搬移完後就可以刪除 game_old 了
DELETE /game_old
```
2018/05/19
在nginx啟動時不需要輸入密碼
我們在產生 https 的憑證 private key 大部分都會輸入密碼再多一層保護
在 nginx 1.7.3 之前 每次重啟 nginx 就會跳出要輸入 pem 密碼
如果是多個 sites 共用一把 key 的話就要輸入 n 次....
幸好在 1.7.3 之後支援了這個 directive
```
ssl_password_file
```
這樣在啟動 nginx 時就不用輸入密碼了
2018/05/15
了解 /etc/group
markdown
```sh
$ cat /etc/group
admin:x:100:admin
--1-- 2 -3- --4--
```
1. 群組名稱
2. 密碼
3. 群組id (gid)
4. 成員清單
```sh
$ cat /etc/group
admin:x:100:admin
--1-- 2 -3- --4--
```
1. 群組名稱
2. 密碼
3. 群組id (gid)
4. 成員清單
訂閱:
文章 (Atom)