Files
Obsidian-Main/00. Inbox/樹莓派.canvas

16 lines
7.2 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{
"nodes":[
{"id":"2379c5036a2ef1af","type":"text","text":"# 設定\n## 更新與安裝\n1. `sudo apt update`\n2. `sudo apt upgrade -y`\n3. `sudo apt install dnsutils`\n\n## `raspi-config`\n1. 打開ssh與vnc\n2. 開機進入console\n\n## `~/.bashrc`\n```bash\nalias ll='ls -al'\nalias pwoff='sudo shutdown -h now'\n```","x":-60,"y":-135,"width":371,"height":315},
{"id":"e5bba63eeea5211f","type":"text","text":"# 安裝\n1. 到[官網](https://www.raspberrypi.com/software/)下載`imager`\n2. 記得在`imager`裡面設定ssh public key","x":-440,"y":-47,"width":340,"height":140},
{"id":"3a39140e3c8408cf","type":"text","text":"## 設定 static IP\n**用router來固定ip以下方法沒用**\n\n1. `sudo vim /etc/dhcpcd.conf`\n2. 填入\n```\ninterface wlan0\nstatic ip_address=192.168.1.21/24\nstatic routers=192.168.1.1\nstatic domain_name_servers=168.95.192.1\n```\n3. reboot","x":-60,"y":200,"width":371,"height":280},
{"id":"6184baf71c6585ff","type":"text","text":"## crontab\n### 加入\n使用`crontab -e`,然後加入這一行:\n`*/1 * * * * /home/awin/script/ddns.sh`\n\n### 說明\n![[Pasted image 20240111231507.png]]\n依序是 **分鐘,   小時,   日期,   月份,    星期,   command**\n參數為 0-59,   0-23,   1-31,  1-21,   0-6,   需要執行的command\n**※ 星期參數為 0 代表星期日**\n\n- 【*】:星號,代表任何時刻都接受的意思\n- 【,】逗號代表分隔時段。例如30 9,17 * * * command代表早上 9 點半和下午五點半都執行 command。\n- 【-】減號代表一段時間範圍。例如15 9-12 * * * command代表從 9 點到 12 點的每個 15 分都執行 command。\n- 【/n】斜線n 代表數字,表示每個 n 單位間隔。例如:*/5 * * * * command代表每隔 5 分鐘執行一次 command。\n\n■ 還有一些人性化的參數,一次取代全部五個數字參數\n- 【@reboot】 僅在開機的時候執行一次。\n- 【@yearly】 一年執行一次和0 0 1 1 * command效果一樣。\n- 【@annually】和@yearly一樣\n- 【@monthly】一個月執行一次和0 0 1 * * command效果一樣。\n- 【@weekly】一個星期執行一次和0 0 * * 0 command效果一樣。\n- 【@daily】每天執行和0 0 * * * command效果一樣。\n- 【@midnight】和@daily一樣\n- 【@hourly】 每小時執行和0 * * * * command效果一樣。\n\n### 範例\n- 每 5 分鐘執行一次:\n - `*/5 * * * *  root    /usr/libexec/atrun`\n- 每 5 小時執行一次\n - `* */5 * * * root    /usr/libexec/atrun`\n- 每天 AM 5:00 執行指令(星號與星號之間要有空隔)\n - `00 05   * * *  username /bin/bash /路徑/command`\n- 1 至 20 號每天執行一次\n - `0 1 1-20  * * root    /usr/libexec/atrun`\n- 當分針移到第 5 分時,執行此 cron\n - `5 * * * * root    /usr/libexec/atrun`\n- 當時針移到 1 點 1 分時,執行此 cron\n - `1 1 * * * root    /usr/libexec/atrun`\n- 每週一的 1 點 1 分,執行\n - `1 1 * * 1 root    /usr/libexec/atrun`\n- 2 月 29 日時針到 1 點 1 分,執行\n - `1 1 29 2 * root    /usr/libexec/atrun`\n- 8 點到 16 點每 5 分鐘執行一次 cron\n - `/5 8-16 * * *   root    /usr/libexec/atrun`\n\n### crontab 命令\n#### 啟動\n`sudo service cron start`\n\n#### 重新啟動\n`/etc/init.d/cron restart`\n\n#### 查詢service狀態\n`sudo /etc/init.d/cron status`\n\n#### 編輯 crontab\n`crontab -e`\n\n\n","x":-731,"y":620,"width":631,"height":430},
{"id":"6ad2c15172b3b925","type":"text","text":"## 設定 DDNS of Cloudflare\n1. 準備`/home/awin/script/ddns.sh`\n2. 把script加入craontab\n\n","x":-60,"y":624,"width":371,"height":136},
{"id":"89db003eaa4162c9","type":"text","text":"## `/home/awin/script/ddns.sh`\n```bash\n#!/bin/bash\nCF_ACCESS_TOKEN=033xQP4_ZpTq3sSkeftz5J6BWw_R9eoDNTba7zfH\nCF_ZONE_ID=1d6a623d1780c31544fc86f718dac16e\nURLS=('awin.one'\n 'blog.awin.one'\n 'ftp.awin.one'\n 'git.awin.one',\n 'storj.awin.one')\nCF_RECORD_IDS=('d67b2a1b3d7cd520b8e8dad2cb522460'\n '69dcc0bd619b1a3d4a71458faff2aa50'\n 'bd397d9779d42c0b92c9c9c47b765769'\n '4eccb48e85f2daa8fefeb92c8cb4b4ee'\n '216d631bc860c6a11b62e3a1003f3e3e')\n\nINTERNET_IP=`curl -s http://ipv4.icanhazip.com`\nINTERFACE_IP=`ip address show ppp0 | grep ppp0 | grep global | awk '{print$2}'`\nDNS_RECORD_IP=`dig +short \"${URLS[0]}\" | grep -Eo '([0-9]{1,3}\\.){3}[0-9]{1,3}' | awk 'NR==1{print}'`\nNOW_TIME=`date`\n\nif [ \"$INTERNET_IP\" != \"$DNS_RECORD_IP\" ]\nthen\n echo \"Renew IP: ${DNS_RECORD_IP} to ${INTERNET_IP}\"\n echo \"${NOW_TIME}: Renew IP: ${DNS_RECORD_IP} to ${INTERNET_IP}\" > /home/awin/log/ddns.log\n for ((i = 0; i < ${#URLS[@]}; i++)); do\n curl -X PUT \"https://api.cloudflare.com/client/v4/zones/${CF_ZONE_ID}/dns_records/${CF_RECORD_IDS[$i]}\" \\\n -H \"Authorization: Bearer ${CF_ACCESS_TOKEN}\" \\\n -H \"Content-Type: application/json\" \\\n --data '{\"type\":\"A\",\"name\":\"'${URLS[$i]}'\",\"content\":\"'${INTERNET_IP}'\",\"ttl\":120,\"proxied\":false}'\n done\nelse\n echo \"No change: ${INTERNET_IP}\"\n echo \"${NOW_TIME}: No change: ${INTERNET_IP}\" > /home/awin/log/ddns.log\nfi\n```\n\n### 參考\n- [5 分鐘整合 Cloudflare API 實做 Cloudflare DDNS 動態 IP 對應網址](https://blog.toright.com/posts/7333/cloudflare-ddns)\n- [自架 DDNS 教學:用 Cloudflare API 達成多域名同步更新! | by Rex | Medium](https://blog.rexyuan.com/%E7%94%A8-cloudflare-dns-api-%E4%BE%86%E9%81%94%E6%88%90-ddns-adaee3c5a84d)","x":-1660,"y":350,"width":886,"height":700},
{"id":"84c3e0d9a25b9cfd","x":-1448,"y":1160,"width":928,"height":640,"type":"text","text":"## 看log\nRaspberry Pi 4沒有`/var/log/syslog`,要使用`journalctl`。\n```bash\njournalctl\n```\nOr \n```bash\njournalctl | grep SOMETHING\n```\n\n### 看系統訊息\n```bash\njournalctl -p 0\n```\n\n#### Error code意思\n```\n0: 紧急情况\n1: 警报\n2: 危急\n3: 错误\n4: 警告\n5: 通知\n6: 信息\n7调试\n```\n\n### 看開機log\n```bash\njournalctl --list-boots\n```\n\n- 第一個數字顯示的是journald 的唯一的啟動追蹤號碼,你可以在下一個命令中使用它來分析該特定的啟動。\n- 第二個數字是啟動ID你也可以在指令中指定。\n- 接下來的兩個日期、時間組合是儲存在對應文件中的日誌的時間。如果你想找出某個特定日期、時間的日誌或錯誤,這就非常方便了。\n\n例如\n```bash\njournalctl -b -45\n```\nOr\n```bash\njournalctl -b 8bab42c7e82440f886a3f041a7c95b98\n```\n\n也可以使用 `-x` 選項在顯示器上加入systemd 錯誤訊息的解釋。在某些情況下,這是個救命稻草。例:\n```bash\njournalctl -xb -p 3\n```"}
],
"edges":[
{"id":"f01be3b2d50be1dd","fromNode":"2379c5036a2ef1af","fromSide":"bottom","toNode":"3a39140e3c8408cf","toSide":"top"},
{"id":"7ee9a7ffb58d8dd7","fromNode":"e5bba63eeea5211f","fromSide":"right","toNode":"2379c5036a2ef1af","toSide":"left"},
{"id":"25b55a6eadd7d434","fromNode":"3a39140e3c8408cf","fromSide":"bottom","toNode":"6ad2c15172b3b925","toSide":"top"}
]
}