惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

K
Kaspersky official blog
罗磊的独立博客
F
Fortinet All Blogs
人人都是产品经理
人人都是产品经理
量子位
V
Visual Studio Blog
Blog — PlanetScale
Blog — PlanetScale
M
MIT News - Artificial intelligence
B
Blog RSS Feed
腾讯CDC
博客园_首页
aimingoo的专栏
aimingoo的专栏
博客园 - 三生石上(FineUI控件)
博客园 - Franky
S
SegmentFault 最新的问题
N
Netflix TechBlog - Medium
小众软件
小众软件
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
LINUX DO - 热门话题
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Martin Fowler
Martin Fowler
D
Docker
P
Privacy & Cybersecurity Law Blog
S
Securelist
V
V2EX
Jina AI
Jina AI
阮一峰的网络日志
阮一峰的网络日志
T
Tor Project blog
The Hacker News
The Hacker News
Microsoft Azure Blog
Microsoft Azure Blog
AWS News Blog
AWS News Blog
The GitHub Blog
The GitHub Blog
有赞技术团队
有赞技术团队
T
The Exploit Database - CXSecurity.com
Help Net Security
Help Net Security
酷 壳 – CoolShell
酷 壳 – CoolShell
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 叶小钗
Recent Announcements
Recent Announcements
Cloudbric
Cloudbric
Y
Y Combinator Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Latest news
Latest news
MongoDB | Blog
MongoDB | Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Recorded Future
Recorded Future
V2EX - 技术
V2EX - 技术

Jiajun的技术笔记

你好,2026! TiDB 源码阅读(六):TiDB Coprocessor 源码解析 性能优化的核心思想 TiDB 源码阅读(五):索引 TiDB 源码阅读(四):AST、逻辑计划、物理计划 CockroachDB Serverless Architecture podman 无故退出 Cursor Control-L (CTRL-L) Keyboard Shortcuts in Terminal Replace docker with podman Using xmonad with xfce4 A RC script for freebsd frpc 自己动手写一个k8s controller AI 会取代你的(编程)岗位吗? 自建DERP服务器提升Tailscale连接速度(使用Nginx转发) 自动升级Docker容器 再读《程序员修炼之道-从小工到专家》 让浏览器下载文件 再读《软件随想录》/《黑客与画家》/《软技能》 HTTP 压力测试中的 Coordinated Omission 2的补码 编程语言中的 context 是什么? flutter macOS 构建出错 Flatpak 使用小记 Golang CAS 操作是怎么实现的 PostgreSQL 当MQ来使用 Clash 结合 工作VPN 的网络设计 使用 PostgreSQL 搭建 JuiceFS PostgreSQL 配置优化和日志分析 有GitHub Copilot?那就可以搭建你的ChatGPT4服务 窗口函数的使用(以PG为例) 读《为什么学生不喜欢上学》 OpenAI Prompt Engineering 摘录和总结 读《打造真正的新产品》 VueJS 总结 Linux 自动挂载 alist 提供的webdav FreeBSD 使用 vm-bhyve 安装Debian虚拟机 FreeBSD 和 Linux 网卡聚合实现提速 GPT 帮我搞定了时区转换问题 长任务系统如何处理? macOS/Linux 编译 InputLeap 使用开源软KVM - synergy-core 解决 macOS 终端hostname一直变化问题 KVM 共享 Intel 集成显卡 PromQL 备忘 读《格鲁夫给经理人的第一课》 读《打开心智》 为什么要把复杂的联表操作拆成多个单表查询? 红包系统的设计 MySQL Index Condition Pushdown Optimization Go mod 简明教程 OpenWRT 使用 Android/iOS USB 网络 搭建旁路由 Golang gRPC 错误处理 编写可维护的单元测试代码 OAuth 2 详解(六):Authorization Code Flow with PKCE OAuth 2 详解(五):Device Authorization Flow OAuth 2 详解(三):Resource Owner Password Credentials Grant OAuth 2 详解(四):Client Credentials Flow OAuth 2 详解(二):Implict Grant Flow OAuth 2 详解(一):简介及 Authorization Code 模式 ElasticSearch 学习笔记 三种git流程以及发版模型 错误处理实践 权限模型(RBAC/ABAC) OIDC(OpenID Connect) 简介 任务队列简介 PostgreSQL 操作笔记 使用Drone CI构建CI/CD系统 Golang migrate 做数据库变更管理 使用PostgreSQL做搜索引擎 Nginx 源码阅读(三): 连接池、内存池 Nginx 源码阅读(二): 请求处理 Nginx 源码阅读(一): 启动流程 Go 泛型简明教程 KVM 显卡穿透给 Windows 使用 HTTP Router 处理 Telegram Bot 按钮回调 使用反射(reflect)对结构体赋值 GIN 是如何绑定参数的 你好 2022(2021 年终总结) 用Go导入大型CSV到PostgreSQL 使用 OpenWRT 搭建软路由 使用软KVM切换器 barrier 共享键鼠 SQL 防注入及原理 使用 gomock 测试 Go 代码 gevent不是黑魔法(二): gevent 实现 gevent不是黑魔法(一): greenlet 实现 用 entgo 替代 gorm 应用内使用crontab不是那么方便 单测时要不要 mock 数据库? Sentry 自建指南 用selenium完成自动化任务 用闲置的安卓手机做垃圾电话短信过滤 推荐三个时间管理工具 一次事故反思 当JS遇到uint64:JS整数溢出问题 SQLite3 存储以及ACID原理 Redis源码阅读:pub/sub实现 Redis源码阅读:zset实现 Redis源码阅读:bitmap 位图的运算 Redis源码阅读:set是怎么做交并集运算的?
重新捡起你那吃灰的树莓派
2016-04-03 · via Jiajun的技术笔记

重新捡起你那吃灰的树莓派

最近在考驾照,没大块时间看书了,就拿起我那吃灰了1年的树莓派出来耍耍。

操作系统

我安装的是官方的raspberry系统,基于debian。烧录到micro sd卡,启动系统以后:

  • 第一件要做的事情就是执行 raspi-config 选择第一项,把剩余的sd卡空间用起来。

  • 第二件要做的事情就是把软件源换成国内的:

.. code:: bash

# cat /etc/apt/sources.list
deb http://mirrors.aliyun.com/raspbian/raspbian/ jessie main non-free contrib rpi

虽然我买的是 class 10 的 micro sd 卡,但是 sudo apt-get update 以后还是会有点卡。

  • 第三件要做的事情就是把用户切换成root,虽然在生产环境这么做不太好,但是自己的 折腾机器,用root比较方便,例如少打sudo(虽然你也可以在 /etc/sudoers 里设置 不需要密码,但那还不如直接用root呢)。

.. code:: bash

# 首先,切换到root
$ sudo su
# 添加公钥到 ``/root/.ssh/authorized_keys``
cat >> /root/.ssh/authorized_keys
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# 修改sshd_config中的 ``PermitRootLogin`` 选项成 ``without-password``
# cat /etc/ssh/sshd_config  | grep PermitRootLogin
PermitRootLogin without-password

安装aria2

aria2 is a lightweight multi-protocol & multi-source command-line download utility. It supports HTTP/HTTPS, FTP, BitTorrent and Metalink. aria2 can be manipulated via built-in JSON-RPC and XML-RPC interfaces.

.. code:: bash

apt-get install aria2

但实际执行aria2的时候却是用aria2c来执行的。所以之后我们统一所有配置文件等,名字 全用aria2c来命名。aria2c很多可配置选项,学习它的最好方式就是看man。

接下来把下面的配置文件输入到 /etc/aria2c.conf 去::

enable-rpc=true
rpc-allow-origin-all=true
rpc-listen-all=true
rpc-listen-port=6800
max-concurrent-downloads=5
continue=true
max-connection-per-server=5
min-split-size=10M
split=10
max-overall-download-limit=0
max-download-limit=0
max-overall-upload-limit=100
max-upload-limit=100
dir=/data/aria2
bt-enable-lpd=true
bt-require-crypto=true
bt-max-peers=20
disable-ipv6=true
save-session-interval=60
daemon=true

注意其中dir选项是保存下载文件路径。我的树莓派上用了一个有源USB挂了一个1T的硬盘。 下面是我的fstab::

# cat /etc/fstab
proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
# a swapfile is not a swap partition, no line here
#   use  dphys-swapfile swap[on|off]  for that
/dev/disk/by-uuid/56cf232e-f4d9-4b20-a2e4-xxxx /data  ext4  defaults,nofail 0 0

当然,最后一行,仔细看一下,有个nofail选项,man是这么说的::

nofail Do not report errors for this device if it does not exist.

就是说uuid为这个的硬盘,如果开机的时候没有插入,系统也不会等它。而且我实测了一下, 就算是系统已经开启,我再把硬盘插入,系统还是会自动把硬盘挂到 /data 上。

下一步就是使用systemd来让aria2c开机启动了:

.. code:: bash

# cat /etc/systemd/system/aria2c.service
[Unit]
Description=Aria2c download manager
After=network.target

[Service]
User=root
Type=forking
ExecStart=/usr/bin/aria2c --conf-path=/etc/aria2c.conf

[Install]
WantedBy=multi-user.target

接下来::

# systemctl enable aria2c

大功告成~

Web UI

可以用aria2c来下载了,那怎么看下载进度或者其他呢?有人在Github开源了两个web 界面,一个是 yaaw_ 和 webui-aria2_ 。还有人把 yaaw_ 打包成了chrome插件。 接下来我讲一下怎么把 yaaw_ 部署在树莓派上。

.. _yaaw: https://github.com/binux/yaaw .. _webui-aria2: https://github.com/ziahamza/webui-aria2

  • 首先安装nginx和git::

    apt-get install nginx git

  • yaaw_ 拷贝下来,因为我不想让太多数据写入到sd卡上,所以我把web资源都放 /data 上,前提是/data挂载好了,要不然会拿到404哦。

    • 首先拷贝 yaaw_ ::

      git clone https://github.com/binux/yaaw /data/www/yaaw

    • 然后配置 /etc/nginx/sites-enabled/default ::

      server { listen 80 default_server; listen [::]:80 default_server; # SSL configuration # # listen 443 ssl default_server; # listen [::]:443 ssl default_server; # # Self signed certs generated by the ssl-cert package # Don’t use them in a production server! # # include snippets/snakeoil.conf; server_name _; location / { root /data/www/yaaw; index index.html index.htm; } }

    • 重启nginx::

      systemctl restart nginx # 或者 nginx -s reload

    • 测试访问80端口::

      curl localhost

    • 接下来再安装一个chrome插件叫 aria2c-integration_ ,把平时的下载拦截然 后导入到aria2c去,安装完成以后记得配置一下 json-rpchttp://{树莓派ip地址}:6800/jsonrpc

.. _aria2c-integration: https://chrome.google.com/webstore/detail/aria2c-integration/edcakfpjaobkpdfpicldlccdffkhpbfk

配置ftp或Samba

可以下东西,也可以看到下载进度,那怎么用下载好的东西呢?本来是想配置samba的, 但是一看安装那么多依赖,还是改成ftp吧:

  • 首先安装vsftp::

    # apt-get install vsftp
    
  • 然后配置vsftp::

    http://www.g-loaded.eu/2008/12/02/set-up-an-anonymous-ftp-server-with-vsftpd-in-less-than-a-minute/
    

定时报告公网ip

试了一下,我家里的ip地址是分配的公网ip,但是是会变的,比如重启路由器之类的。 如果你们家的ip不是公网ip那还是跳过这一段吧,哈哈哈。 写了一个程序让树莓派邮件报告当前公网ip:

.. code:: python

# coding=utf-8

import requests
import smtplib
from email.mime.text import MIMEText

USER = "[email protected]"
PASSWD = "xxx"
TO = "[email protected]"
TITLE = "raspberry_pi_ip_report"

# get ip

API = "http://www.hahayangqi.cn/a/ip_api.php"
r = requests.get(API)

msg = MIMEText(r.text, "plain", "utf-8")
msg["Subject"] = TITLE
msg["From"] = USER
msg["To"] = TO

s = smtplib.SMTP_SSL("smtp.qq.com", 465)
s.set_debuglevel(1)
s.login(USER, PASSWD)
s.sendmail(USER, TO, msg.as_string())
s.quit()

其中用来查询公网ip的API自己也可以做,比如tornado直接打印 self.request.remote_ip 就得了。

接下来要做的事情就是在路由器里设置端口映射,把路由器的某个端口转发到树莓派上。

设置完之后就可以ssh登陆上去啦!

当然,更简单的一种方式是,检测到ip有变,就去dnspod更新对应的域名绑定,也可以检测到 ip有变才发送邮件,否则不发送邮件。不过考虑到树莓派的sd卡是脆弱的,还是采用最简单粗暴 的方式吧。

最后,别忘了设置crontab定时执行任务。还有别忘了在gmail里加入过滤规则,要不然会被 邮件淹没的。。。

总结

折腾下来,树莓派常用的软件都有,CPU也还过得去,性能瓶颈在于IO。我用的 class 10 的 sd卡,还是会感觉到卡顿。另外CPU也不是特别够用,比如vim装了很多插件以后就特别特别卡, 一方面是IO,一方面是CPU。所以树莓派上的vim用的都是我特别精简版的vimrc。