基于RPi和LXD的ESP32开发环境

2022-11-22 作者:

对于在板子手动重启时经常把ESP32带进下载模式的问题,LAN8720所需的上/下拉电阻恐怕是最大嫌犯。于是斥巨资近CNY 10元采购了万用板、线仔包和各种直/弯母座,终于搞了MKII —— 重启可靠性问题果然迎刃而解。

过程中,基于lxd的Debian in Debian做了套新环境,顺手也试了试C语言的esp-idf编译,用起来整体感觉很顺手。

RS232 connected with an lxc in raspberry pi 4b (not in pic)

Yes, it actually performs nicely to work on ESP32 development in debian bullseye LXD in Pi OS, no mater you’re working on hardcore C lang based esp-idf or the nice & easy micropython development.

“Hmm… so you need a standard Debian in a derived Debian? “

Well, since I found out that LXD is something very helpful to isolate different needs on different Linux distributions in different containers, while it kinda works pretty much like vm (instead of docker) since it’s easy to config the resources consumption or even usb devices pass-through, and the most important – having its own block storage which can be exported into a single archive.
Then, the only thing I can’t agree with, could be the deep connection with the snapd. Instead of switching to another distribution, such as Arch, I choose to build the LXD of my own (on both Pi OS aarch64 and Ubuntu 22.04 X86_64). Thanks to the good documentation, the stuff (native lxd without the snap crxp) works like a charm.

with Xfce and xrdp, the bullseye lxc can work as an esp dev server quite well

完整阅读本篇»

HAOS集成和风天气

2022-09-27 作者:

室内搞完了,室外就别搞传感器了,直接走api拉数据。

系统默认集成的OpenWeather和AccuWeather都不太靠谱,前者填了api key后报无效,后者是数据离实际差距大+免费api次数不够用,最后还得自己搞国内的天气服务API。

注册了高德、和风两家,后者虽然没有前者的品牌,但毕竟数据种类更齐全,用来练手是不错的。

效果如下:

至于怎么安装,其实什么插件都不用装,直接File Editor插件编写 /config/configuration.yaml ,保存无误后,重启服务即可。

【注】重启服务,只需要“配置”->“系统”->“重新启动”。这个过程很快,30s搞定。不需要重启整个HAOS的vm或者物理机,那个时间要长很多。

要写什么内容呢?

完整阅读本篇»

nginx控制iptables芝麻开门

2022-02-10 作者:

During maintenance of a production server, we use to encounter a problem like this – an internet-access-blocked port, say 3306 (mysql), is about to be open for a little while due to debugging needs, which is not uncommon, right? So how to make this easily operated, mostly secure, and automatically disabled after working – I guess this’s gonna help somehow.

A Linux server with whatever the distribution including iptables (e.g. CentOS, Rocky for now as example), Nginx, fcgiwrap, a simple shell script and a commonly used web browser, let’s say chrome, will be major ingredients on the recipe.

常做运维,总会遇到某些线上服务器,为了便于调试,在符合安全要求的基础上,需要相对便利的对公网短时定向开放某些端口。

昨天想了一招,用nginx操作shell脚本,对特定公网IP开口子,叫一声“芝麻开门”,便捷又安全。举例端口3306(mysql),系统是Rocky Linux 8(原CentOS 8)。

Doors of Durin

Doors of Durin

先查一下现有的防火墙规则,需要的话可以保存一下。换句话说,搞芝麻开门之前,先确定门是隐藏的;也即已经有相应(且持久化)的iptables rule确保到被保护端口的连接是DROP/REJECT状态。

然后就是fcgiwrap的安装,此处就不写nginx安装过程了,默认安装即可。

安装后增加两个systemd服务文件,并测试fcgiwrap服务生效。

【注】那俩服务文件,在Redhat之外的发行版上,fcgiwrap安装包可能自带,请针对所用版本自行检查。

接下来为一个新的nginx server准备个根目录,存放网页和之后控制iptables的脚本。

完整阅读本篇»

树莓派监控SANTAK UPS

2022-01-07 作者:

硬件:SANTAK TG-BOX 600 + RPi 4B (2GB) + Huawei ME909s-821

监控服务:NUT(Network UPS Tools)参考文章挺多,就不详解了;Pi上连了4G模块主要是掉电时可能无法得到Wired Ethernet供应,就发个短信而已,不如直接走wwan靠谱省心。

目前用的是standalone模式,回头有空查下文档试试netserver模式,看config文件介绍,猜测是client可以通过server知道市电挂了,从而在server之前关机?

完整阅读本篇»

OpenWrt测试双WAN和双机高可用

2021-12-03 作者:

So here’s a quick example. OpenWrt shows capability to provide business-level internet access reliabilities – with not only load balancing/failover between 2 or more ISPs, but also VRRP based hardware (dual x86 vm in this experiment) level redundancy.

从以下的例子可以看出,OpenWrt基本满足了提供小型商业级Internet访问可靠性的初步要求。它不仅可以在多个ISP之间实现负载均衡以及故障切换,在此基础上同时提供基于VRRP的硬件冗余(本实验中为双x86虚拟机)。

 

先开仨虚拟机,前两台做OpenWrt,可以先做1台,复制1台。注意要安装mwan3和keepalived。

 

双WAN做好后,断开一路wan做测试。这里的wanb,用的是楼道里的不可靠wifi,通过Raspberry Pi向下路由一层转成有线网,能体现出不稳定的ISP接入状态。

本来是两路负载均衡的策略,wanb断开后,5s之内可以让所有对外请求都稳定落在wan上。

 

下一步,把MASTER的br-lan断开,模拟一个路由器硬件直接宕掉。

 

这个切换时间很短,还没反应过来,BACKUP就接管了VIP地址,对外请求几乎不受什么影响。

完整阅读本篇»

DIY带外管理 · 强悍Pi-KVM

2021-09-27 作者:

Let’s talk about the open source IP-KVM (or KVM over IP) solution based on Raspberry Pi 4B, named Pi-KVM, which has sophisticated feature sets that can provide almost same experience like HP ILO or DELL iDRAC, only except the hardware monitoring and err logging.

  • Hardware screen capture with low latency.
  • OTG Keyboard & mouse; Mass Storage Drive emulation.
  • ATX power control (thru Pi GPIO) with some MOSFET relays.
  • RJ-45 and USB serial console port.
  • IPMI BMC, redfish… all those professional server stuff support.
  • Nice and easy-to-use web UI with virtual keyboard, video quality control, key-combination shortcuts and virtual USB drive control.
  • A fully featured, user-customizable Linux OS.

只要玩过专业带外管理,基本就很难接受只有本地键鼠,以及OS之上的RDP和VNC了吧。

随便放两张Dell iDRAC系统截图吧。

今天要聊到的Pi-KVM,在简单廉价的硬件结构上,实现了除硬件子系统监控和告警之外,专业BMC几乎所有功能。

  • 低延迟的显示器信号捕捉和传输(100ms以内)。
  • OTG 键鼠,U盘模拟;给家用机远程load OS不叫事儿。
  • 通过Pi GPIO外加几个继电器实现的ATX电源控制;不说也懂,控制不了电源还叫BMC么。
  • RJ45和USB串口;既能控制路由/交换,也能控制自己。
  • IPMI BMC,redfish… 专业能玩的,它都能玩。
  • 简洁实用的web控制台,软键盘、组合键、粘贴板、视频质量控制、虚拟USB驱动器控制,全乎+易用。
  • 除了所有以上之外,还是个全功能的Arch Linux ARM版本,灵活性刚刚的,这可把专用BMC打趴了吧。

多吹无益,上图。

【注】请忽略裸线,5V和GND用胶带缠了一下,反正不是高压,胶带不绝缘也没关系,别物理刺穿就行;银色金属箔是屏蔽,说明小米的线做工还是靠谱的哈,该有的都没少。

文档制作基于Ventoy的Win10安装盘,全程不用物理U盘,安装Windows。

如果我没说清楚,就重申一遍。类似Dell和HP的专业BMC,可以直接远程挂载ISO装系统。Pi-KVM更狠,借着自己内置存储,直接把U盘/光盘镜像上传,经过物理USB线,模拟一个驱动器插到被控电脑就搞定了,有点爽。

如上所言,被控电脑经USB线连接仿真U盘,BIOS从Linux file-CD启动,无论装什么OS都能够顺利引导。

完整阅读本篇»