树莓派4B入门

安装系统

需要一张SD卡来烧录系统。
现在在官方工具的支持下,已经很简单了,甚至不需要自己提前下载系统iso文件。
Install Raspberry Pi OS using Raspberry Pi Imager选择对应系统进行安装。
然后打开软件,choose OS ->choose storage然后点击write等待烧录完成。
我的建议是新手选择安装带图形化界面的版本。树莓派4B选择64位的系统,之前的选择32位。

我的基础设置

以下这一小节不具备通用性。建议参考其他博客或者教程。

然后第一次使用,有有显示屏和无显示屏连接两种方式。由于我这次是想挂到校园网下,无显示屏折腾了半天死活找不到IP地址,所以借了同学的显示屏和键盘来配置基础设置。

后面设置静态IP或者一直在线即可通过IP SSH连接使用。

apt 换源

我替换为了清华源。
注意换源需要注意自己的系统版本。
首先在终端输入cat /etc/os-release查看输出,我的输出如下:

lucas@pi:~ $ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

VERSION那一行是bullseye,所以下面我是bullseye。不同版本不同。

然后直接去清华Raspbian 镜像使用帮助复制粘贴即可。

首先打开/etc/apt/sources.list文件,替换为如下内容。

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
deb [arch=armhf] https://mirrors.aliyun.com/docker-ce/linux/raspbian bullseye stable
# deb-src [arch=armhf] https://mirrors.aliyun.com/docker-ce/linux/raspbian bullseye stable

然后打开/etc/apt/sources.list.d/raspi.list,替换为如下内容:

deb https://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ bullseye main

安装Docker

参考链接:Docker - 从入门到实践

已经写得很详细了。

安装Hexo,Nginx部署博客

hexo需要通过npm安装,所以首先需要安装node.js。

官网选择Linux Binaries (ARM)对应ARMv7或者v8(分别对应32位和64位)下载:node.js 下载

换源

npm需要首先换源。我换了淘宝源。

npm config set registry=http://registry.npm.taobao.org

不推荐通过cnpm 使用,会出现各种莫名的问题。

安装 Hexo

npm install -g hexo-cli

项目初始化

进入hexo项目根目录,npm i安装依赖。
然后就可以使用

hexo clean
hexo g
hexo s

然后访问本地的4000端口查看博客了。

Nginx 部署静态网页

安装 Nginx

sudo apt-get install nginx即可。

自启动

sudo systemctl enable nginx
sudo systemctl start nginx

配置访问博客资源

修改/etc/nginx/sites-available/default文件。
修改监听的端口以及把root路径指向Hexo项目的public目录即可。

然后就可以通过你的ip:port访问网页了。

除此之外,Nginx还可以用来做nginx静态文件服务。网上教程很多。

安装 Pi Dashboard

也很简单,Docker 拉取一个镜像就解决了。

sudo docker run -d --name docker-pi-dashboard -e 'LISTEN=1024' --net=host ecat/docker-pi-dashboard

在浏览器中输入 <你的IP地址>:1024即可访问到 pi dashboard

安装qbittorrent下载BT种子文件

添加软件源:sudo add-apt-repository ppa:qbittorrent-team/qbittorrent-stable

apt安装:sudo apt-get install qbittorrent-nox

然后输入: qbittorrent-nox即可启动服务。

默认启动端口为 8080,默认账户密码为:admin/adminadmin

然后就可以访问网页进行各种设置了。

自启动

需要自己写systemd启动文件,很简单。

sudo vim /etc/systemd/system/qbittorrent-nox.service添加如下内容:

[Unit]
Description=qBittorrent-nox
After=network.target
[Service]
User=root
Type=forking
RemainAfterExit=yes
ExecStart=/usr/bin/qbittorrent-nox -d
[Install]
WantedBy=multi-user.target

然后就能通过systemctl管理了。

nps内网穿透

内网穿透后就能从公网访问到校园网下的树莓派了。

需要你有一个具有公网IP的云主机,我的是阿里云。

Github项目地址:nps

其中,中文文档有教安装和配置。nps和npc安装和使用

我觉得这个文档写得不太行,有一点点门槛。可以结合一些优秀的博客和教程一起食用。

安装ufw防火墙

安装:apt-get update && apt-get install ufw
然后看一下两篇文章就应该可以很顺畅的使用了:

The End

折腾东西,也不是说越是人烟稀少的地方我越要往里钻。

很多时候,选择通用的方案可以节省很多精力和时间去做更有意义的事。

不然,你配置个环境就这里出错那里不对劲,很容易半途而废,或者在歧路上越走越远。

HARD v.s. COMPLEX

猜你喜欢

转载自blog.csdn.net/DaydreamHippo/article/details/128179202