雖然vps也便宜,但還是想買4b
樹莓派4b顯示器接線為 hdmini,買時沒有附贈
是以以下均為mac系統下通過ssh操作
文章來自:http://blog.csdn.net/intbird 轉載請說明出處
rasberrypi 4b
-
-
- 0. 服務面闆
- 1.燒錄系統
-
- 1.官方工具
- 2. 從U盤或者SSD啟動
-
- 1.幫助文檔
- 2.U盤啟動操作
- 3.SD Card Copier
- 4.将Ubuntu寫入SSD
- 5.挂載蘋果系統分區
- 3. Ubuntu Store 和 Snap store
-
- 1.Snap和Snap-store
- 2.Snap網絡設定
- 3. snap-store安裝軟體
- 4.Ubuntu(樹莓派armv7) 開啟螢幕共享
- 5.Ubuntu(VPS amd64)打開螢幕共享
- 6.服務和桌面版切換
- 2.ssh啟用
-
- 1. 沒有hdmini線
- 2. 有線和無線網絡
-
- 1.使用網線連接配接
- 3.指令行連接配接無線網
- 4.文本編輯管理無線網
- 5.DHCP和靜态位址
- 3.ssh登入
-
- 預設user: pi
- 預設密碼: raspberry
- 4.root使用者
-
- 1. 修改root
- 2. 切換root
- 3. root登入
- 5.遠端登入
-
- 1.遠端登入(推薦zerotier)
-
- 1. 路由器支援配置 DDNS + DMZ
- 2.手動添加用戶端軟體支援
- 2.frp(需要公網ip)
-
- 1.frp檢視
- 1.frp配置
- 3. zerotier
- 4.TeamViewer 和 VncView 等
- 5.ngrok
- 6.gost
- 6.軟路由和網絡設定
-
- 1. SwitchOMG
- 2. GOST
- 3. 軟路由
- 7. Docker
-
- 1. docker 安裝
- 2. docker 管理工具:
-
- 1.portainer如圖:
- 2.portainer安裝
- 3.portainer密碼: 123456
- 3. dockerHub registry2搭建:
-
- 1.registry2 添加
- 2.registry2 安裝
- 3.registry2 解釋
- 4.registry2 登入
- 4. docker遷移:
-
- 1.将運作中的容器打包并上傳
- 2.或者使用potainer管理工具上傳
- 3.另一台機器拉取運作鏡像
- 4.Dockerfile
- 5.部分問題跟進
- 8. 遠端管理
-
- 1. webmin安裝系統監控
-
- 1.安裝會自動提示依賴庫
- 2.管理頁面位址端口
- 3.配置一下https
- 4.mac遠端管理樹莓派
- 2. postfix郵件伺服器
- 9.遠端同步和備份
-
- 1. rsync
- 2. rclone
- 3.備份工具
-
- Amanda ,Rsync&Rclone, timeshift ,rsnapshot
- 4 雲盤同步
-
- 4.1 百度盤同步
- 4.2 阿裡盤同步
- 4.3 OneDrive盤
- 4.4 Mount WebDav
- 10.硬體
-
- netstat
- temp cpu溫度
- iftop 網絡監控
-
0. 服務面闆
https://pi.intbird.net/
搭建的部分服務可能會忘,html源碼可以友善配置
公開的服務需要加個登入密碼
沒有密碼權限的就不要放公網
map的key作為區分
- key包含https,value為空,則用key跳轉
- value包含https,則使用value跳轉
- key和value都不包含連結,則作為分割線
加個背景好看一點
https://pi.intbird.net/
https://pi.intbird.net/
1.燒錄系統
1.官方工具
https://www.raspberrypi.org/software/
可以線上選擇要安裝的系統和直接燒錄sd卡
sd卡需要8g以上
,否則失敗
2. 從U盤或者SSD啟動
1.幫助文檔
https://www.raspberrypi.org/documentation/hardware/raspberrypi/bootmodes/msd.md
https://www.tomshardware.com/how-to/boot-raspberry-pi-4-usb
https://peyanski.com/official-raspberry-pi-4-usb-boot/
2.U盤啟動操作
su root
apt update
apt-get upgrade -y
apt full-upgrade
rpi-update
reboot
su root
sudo rpi-eeprom-update -d -a
reboot
su root
raspi-config
Advanced Options > Boot Order > B1 USB Boot
進入進階設定
選擇 boot order
選擇boot-loader version
3.SD Card Copier
如果ssd不是sdcard等,無法用官方 pi-imager 寫入
則可以通過sdcardcpier複制到ssd内
這個東西非常好
這個東西非常好
這個東西非常好
見: [ 4. 将Ubuntu寫入SSD ]
4.将Ubuntu寫入SSD
1.安裝如圖
樹莓派從SSD啟動Ubuntu的話
我還沒看到直接燒錄ubuntu系統的
是以:
簡單和上手快的話就用 兩個USB裝置 + 一塊SSD
大意說明:
-
準備兩個USB裝置(讀卡器,U盤等) + 一個SSD硬碟`準備
-
燒錄
一個USB燒錄樹莓派官方系統
一個USB燒錄ubuntu官方系統
-
啟動
啟動一個USB的ubuntu系統,完成ubuntu初始化設定
啟動一個USB的樹莓派系統,打開Copier SDCard工具
-
複制
利用Copier SDCard工具
将剛才完成初始化的Ubuntu系統卡複制到SSD裡
-
拔掉所有USB,從SSD啟動Ubuntu即可重新開機
問題:
ubuntu系統裝置發熱明顯
CPU負載較高
但是有很多桌面版互動較好
自由取舍吧
5.挂載蘋果系統分區
挂載一個apfs硬碟到樹莓派
- 自動挂載
// 安裝挂載工具
apt-get install libfsapfs-utils
> libfsapfs-utils 已經是最新版 (20190210-1)
// 得到外設标示
fdisk -l
> /dev/sda1 2048 616447 614400 300M EFI System
> /dev/sda2 616448 878591 262144 128M Microsoft reserved
> /dev/sda3 878592 234441607 233563016 111.4G unknown
// 挂載硬碟
mkdir -p /mnt/intbird-sandisk
fsapfsmount -f 1 /dev/sda3 /mnt/intbird-sandisk
> fsapfsmount 20190210
> [email protected]:/home/pi# ls /mnt/intbird-sandisk
> Applications cores home Library mnt opt private sw System Users usr Volumes
-
手動挂載
https://github.com/sgan81/apfs-fuse
看他的最新說明文檔
3. Ubuntu Store 和 Snap store
1.Snap和Snap-store
更新到最新版,Snap商店應用會越來越多的
2.Snap網絡設定
- snap速度極其慢,是以設定一下網絡
snap set system proxy.http="http://127.0.0.1:1083"
snap set system proxy.https="http://127.0.0.1:1083"
- 檢視網絡
snap get system proxy
[email protected]:~# snap get system proxy
Key Value
proxy.http http://127.0.0.1:1083
proxy.https http://127.0.0.1:1083
[email protected]:~#
- 删除網絡
snap unset system proxy.http
snap unset system proxy.https
- 安裝軟體
snap install nextcloud
[email protected]:~# snap install nextcloud
nextcloud 20.0.4snap2 from Nextcloud✓ installed
3. snap-store安裝軟體
snap run snap-store
搜尋要安裝的軟體安裝即可
chrome
4.Ubuntu(樹莓派armv7) 開啟螢幕共享
ubuntu20.10 vnc 自帶螢幕共享,官方文檔
是以
- ubuntu在設定裡允許螢幕共享
- mac打開螢幕共享app,連接配接到如圖位址即可
ubuntu打開共享
mac: finder -> 連接配接伺服器 -> vnc://respberrypi.local
5.Ubuntu(VPS amd64)打開螢幕共享
Ubuntu自帶vino,因為沒有圖形界面
是以通過指令行打開它即可
效果如圖
系統資訊
切換使用者
x86的snap商店比樹莓派的arm snap商店東西多太多
//更新,桌面也有--no-recomends版的,自行查找
sudo apt update
sudo apt install tasksel
tasksel --list-tasks
tasksel install ubuntu-desktop
reboot
systemctl set-default graphical.target
reboot
//手動開啟ubuntu桌面,待我研究他咋開機啟動
//也可以開啟其他桌面,當然其他桌面需要開啟對應的VNC服務
startx &
//指令行配置vino,connections讓本地和外網都能通路
gsettings set org.gnome.Vino require-encryption false
gsettings set org.gnome.settings-daemon.plugins.sharing active true
gsettings set org.gnome.Vino prompt-enabled false
gsettings set org.gnome.Vino authentication-methods "['vnc']"
gsettings set org.gnome.Vino vnc-password $(echo -n '$passwd'|base64)
dconf write /org/gnome/settings-daemon/plugins/sharing/vino-server/enabled-connections "['']"
export DISPLAY=:0 && /usr/lib/vino/vino-server &
6.服務和桌面版切換
開啟桌面占用1G+記憶體,so…
// 服務模式
systemctl set-default multi-user.target
//桌面模式
systemctl set-default graphical.target
2.ssh啟用
1. 沒有hdmini線
1.無法遠端連接配接:
拔掉sd卡, 直接在
sd卡的根目錄下 添加一個名為 ssh 的空檔案
重新開機即可
2.可以遠端連接配接:
修改pi密碼通過遠端連接配接在root下建立一個ssh檔案
3.如果有顯示器:
$sudo su
$raspi-config
$enable ssh
4.如果有遠端桌面:
2. 有線和無線網絡
1.使用網線連接配接
記錄樹莓派ip(如: 192.168.3.107)
3.指令行連接配接無線網
su root raspi-config
System Options > Wireless Lan > ssid & passwd
4.文本編輯管理無線網
https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md
nano /etc/wpa_supplicant/wpa_supplicant.conf
5.DHCP和靜态位址
cat /etc/dhcpcd.conf
eth0: 有線網絡
wlan0: 無線網絡
3.ssh登入
預設user: pi
預設密碼: raspberry
本地ip: 192.168.3.107
連接配接軟體: termius , mac終端
ssh指令:
内網登入:
ssh [email protected] -p 22
外網登入:
ssh [email protected] -p 8002
(外網登入見下面)
工具登入: 如圖 termius 的mac版
4.root使用者
1. 修改root
使用pi登入後,修改root使用者密碼:
sudo passwd root
2. 切換root
已添加root使用者,切換root使用者:
su root
or
sudo su
3. root登入
root賬戶被禁用登陸(直接使用root使用者遠端登入會失敗)
cat /etc/ssh/sshd_config
搜尋 PermitRootLogin
修改:
#PermitRootLogin prohibit-password
變為:
PermitRootLogin yes
vi 後儲存退出重新開機
5.遠端登入
樹莓派在家運作,不可能一直内網通路,可以開啟遠端登入
1.遠端登入(推薦zerotier)
1. 路由器支援配置 DDNS + DMZ
已有公網ip (
移動現在很少給家庭使用者公網ip了, 基本上是廢了
)
通過ddns方式直接通路到樹莓派的内網位址
- ddns: 使用 no-ip 或者 花生殼等( pi.ddns.net -> &public ip )
- 路由器靜态位址配置設定 (固定樹莓派ip)
- 在路由器端設定dmz主機ip( pi.ddns.net:8080 -> respi host)
2.手動添加用戶端軟體支援
ddns的方式: (如: noip)
linux client: [https://my.noip.com/#!/dynamic-dns/duc](https://my.noip.com/#!/dynamic-dns/duc)
![在這裡插入圖檔描述](https://img-blog.csdnimg.cn/20201124181402418.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2ludGJpcmQ=,size_16,color_FFFFFF,t_70#pic_center)
2.frp(需要公網ip)
1.frp檢視
沒有有公網ip:
frp, ngrok等内網穿透
- 通過公網ip伺服器轉發樹莓派 和 連接配接端的流量
- 通過xtcp 對點連接配接到樹莓派
詳細連接配接可以檢視frp官網
frp多個用戶端連接配接如圖:
1.frp配置
- 樹莓派端(armv7l):
./frpc -c ./frpc.ini
- 公網ip服務端:
./frps -c ./frps.ini
公網ip遠端連接配接如圖: 可以在遠端連接配接中 再次進行 遠端連接配接
frpc.ini
[common]
authentication_method = token
section = xxx
server_addr = intbird.net
server_port = 8001
admin_addr = 127.0.0.1
admin_port = 7400
admin_user = intbird
admin_pwd = xxx
[web]
type = http
local_port = 80
custom_domains = intbird.net
[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 8002
use_encryption = true
frps.ini
[common]
authentication_method = token
section = xxx
dashboard_port = 8000
dashboard_user = intbird
dashboard_pwd = xxx
bind_port = 8001
bind_udp_port = 8002
vhost_http_port = 8003
subdomain_host = intbird.net
enable_prometheus = false
3. zerotier
過于強大和簡單, 自行百度, 我最愛它
4.TeamViewer 和 VncView 等
TeamViewer
VNC
5.ngrok
沒有付費,一次隻能連接配接一個用戶端且停止後位址會随機改變
https://dashboard.ngrok.com/get-started/setup
./ngork authtoken $youToken
./ngork tcp 22
6.gost
在公司通路家庭内網示例,在前面的步驟完成後即可
開啟sks5或https( gost)
chomd u+x ./gost
./gost -L socks5+tls:/user:[email protected]:1080
6.軟路由和網絡設定
1. SwitchOMG
圖示如圖:
Chrome插件SwitchyOmega: https://github.com/FelisCatus/SwitchyOmega/releases
2. GOST
GOST轉發本地指定端口,這樣會靈活一點
1080端口 用于從家通路公司内網
1090端口 用于從公司通路家裡内網
./gost-linux-armv7-2.11.1 -L=socks5://:1080 -F=socks5+tls://intbird:[email protected]$HOST:1080
3. 軟路由
-
樹莓派的打開的端口 區域網路電腦可以直接連接配接
是以再不使用fly-core進行tproxy的情況下:
将iphone的wifi服務連接配接到樹莓派ip
iphone可以通過樹莓派上網
1080端口 用于從家通路公司内網
1090端口 用于從公司通路家裡内網
- oepnwrt或者fly-code說了就發不出去了…
7. Docker
Docker官網
1. docker 安裝
- ubuntu
apt-get install -y docker.io
- centos
yum install -y docker
- macos
2. docker 管理工具:
docker有自己的管理工具和api,哪個工具都行:
docker本地api
,
tls遠端api
kitematic
,
docker-app
k8s node 也算一個吧
我這裡用portainer-ce
1.portainer如圖:
2.portainer安裝
ocker run -d -p 9000:9000 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /root/intbird/docker/portainer:/data \
--restart always \
portainer/portainer-ce \
--admin-password='$2a$10$752FJIPGCGYal52wccmoj.LY00lGmTnDxSmjeI48a.K6abTL.Zbj6'
3.portainer密碼: 123456
進去以後改個密碼
3. dockerHub registry2搭建:
1.registry2 添加
2.registry2 安裝
docker run -d \
-p 5000:5000 \
--restart=always \
--name registry2 \
-v /root/intbird/docker/registry2/auth:/auth \
-v /root/intbird/docker/registry2/certs:/certs \
-v /root/intbird/docker/registry2/data:/var/lib/registry \
-e "REGISTRY_AUTH=htpasswd" \
-e "REGISTRY_AUTH_HTPASSWD_REALM=intbird" \
-e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd.config \
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/registry.pem \
-e REGISTRY_HTTP_TLS_KEY=/certs/registry.key \
registry:2
3.registry2 解釋
/auth: 授權檔案所在目錄
/certs: registry2 https的證書位置
/var/lib/registry : registry2倉庫位置
注意: 1.REALM 為 intbird
即: 登入的使用者名
注意: 2. htpasswd
htpasswd: 認證類型
可以使用docker工具(xmartlabs/htpasswd)生成
docker run --rm -ti xmartlabs/htpasswd intbird [email protected] > htpasswd.config
4.registry2 登入
就用預設的5000端口, 443端口留作他用
docker login dockerhub.intbird.ml:5000
所需檔案如圖:
4. docker遷移:
兩種push方法都是一樣的,選一個用即可
1.将運作中的容器打包并上傳
docker commit -p intbird-nodejs intbird-nodejs-snapshot
docker tag intbird-nodejs-snapshot dockerhub.intbird.ml:5000/intbird-nodejs-snapshot
docker push dockerhub.intbird.ml:5000/intbird-nodejs-snapshot
2.或者使用potainer管理工具上傳
- 打包上傳
- 密碼正确則上傳成功
- 檢查倉庫檔案
3.另一台機器拉取運作鏡像
docker login
intbird/$passwd
docker pull dockerhub.intbird.ml:5000/intbird-nodejs-snapshot:latest
4.Dockerfile
關于build産物優化體積
仁者見仁,智者見智
FROM node:14.15.0-alpine
WORKDIR /data/
COPY package*.json ./
COPY ./node .
RUN npm install
EXPOSE 8081
CMD [ "node", "node/node-dev.js" ]
# docker build -t intbird.net/nodejs .
# docker run -p 8081:8081 -d intbird.net/nodejs
docker build -t intbird/intbird-nodejs .
docker run -p 8081:8081 -d intbird/intbird-nodejs
5.部分問題跟進
- 兩個常見的參數
: 相當于守護程序--restart always
: 允許别名通路同一網絡--net-alias=intbird-nodejs
-
提示磁盤空間占滿等
嘗試了部分方法,效果我覺得不太理想
更多多待後續跟進嘗試後繼續…
8. 遠端管理
1. webmin安裝系統監控
1.安裝會自動提示依賴庫
https://www.webmin.com/deb.html
2.管理頁面位址端口
https://raspberrypi:10000
3.配置一下https
1.自建的CA憑證
2.用自建的CA憑證生成raspberrypi證書
3.浏覽器設定信任自建的CA憑證即可
4.mac遠端管理樹莓派
配置一下 /etc/hosts 加入 $ip raspberry
證書信任一下
後續遠端連接配接有些安全保障
2. postfix郵件伺服器
postfix + dovecot + spark等郵件用戶端(待補充…)
9.遠端同步和備份
樹莓派組建或者挂載磁盤陣列後,
備份伺服器或者遠端檔案到磁盤
或者将磁盤檔案備份到遠端伺服器(百度雲,阿裡雲,onedrive等)
1. rsync
https://wordpress.intbird.net/2021/02/08/syncthing/
# rsync -ahivzPL \
# --delete \
# --include-from="/root/intbird/intbird/rsync-include" \
# --exclude-from="/root/intbird/intbird/rsync-exclude" \
# --progress \
# -e "ssh -i /root/.ssh/id_rsa_c" \
# [email protected]:/root/ /root/clouds/server-c/
1.grsync
2. rclone
https://wordpress.intbird.net/2021/02/08/syncthing/
rclone 過于強大,示例為本人使用的
備份伺服器指定檔案夾 到 Onedrive雲盤
以保證伺服器可以随時恢複
當然也可以使用這兩個sync工具,直接同步到樹莓派
rclone sync \
--copy-links \
--delete-during \
--progress \
localhost:/ OneDrive:/OS-Backup/intbird.net/ \
--filter-from filter-list.txt \
-vv > /rclone/log.log 2>&1 &
3.備份工具
如何使用詳見文章(https://wordpress.intbird.net):
https://wordpress.intbird.net/2021/08/06/debian-system-backup/
Amanda ,Rsync&Rclone, timeshift ,rsnapshot
4 雲盤同步
使用rclone工具或者webdav或者盤對應的linux版本
4.1 百度盤同步
bypy
bypy info // 擷取授權碼
<< 填入web頁面的授權碼
bypy syncup // bypy -h for more help
4.2 阿裡盤同步
aliyundriver
java -jar webdav.jar --aliyundrive.refresh-token="Token"
4.3 OneDrive盤
rclone
rclone config
如果伺服器沒有浏覽器不好授權
可以在本地授權後,将rclone.conf檔案scp到伺服器上去
服務直接使用授權過的配置可以直接登入
4.4 Mount WebDav
apt-get install davfs2
mount -t davfs http://127.0.0.1:8025 /media/pi/aliDrive/
10.硬體
netstat
netstat -tunlp
temp cpu溫度
[email protected]:~ $
/opt/vc/bin/vcgencmd measure_temp
temp=28.0’C
使用kibana做一個溫度監控
echo "'$(vcgencmd measure_temp)'"
curl --location --request PUT 'http://localhost:9200/rasberrypi/_temp/' -H 'Content-Type: application/json' -d '{
"temp": 0,
"temp_text": "'$(vcgencmd measure_temp)'"
}'
iftop 網絡監控
剛使用兩天, 後續繼續補充
個人網站: https://intbird.net
文章來自: http://blog.csdn.net/intbird 轉載請說明出處