前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >是UPS吖(三)–-树莓派

是UPS吖(三)–-树莓派

作者头像
obaby
发布2023-02-22 15:01:57
3240
发布2023-02-22 15:01:57
举报
文章被收录于专栏:obaby@mars

装ups的另外一个目的就是为了保证树莓派的存储卡不会因为意外断电而出现问题。其实要解决这个问题个人觉得也简单,毕竟也是个linux啊。可以基于nut实现。

The primary goal of the Network UPS Tools (NUT) project is to provide support for Power Devices, such as Uninterruptible Power Supplies, Power Distribution Units, Automatic Transfer Switches, Power Supply Units and Solar Controllers. NUT provides a common protocol and set of tools to monitor and manage such devices, and to consistently name equivalent features and data points, across a vast range of vendor-specific protocols and connection media types. NUT provides many control and monitoring features, with a uniform control and management interface. If you are just getting acquainted with NUT, that page also explains the technical design and some possible set-ups. More than 170 different manufacturers, and several thousands of models are compatible. https://networkupstools.org/index.html

为了要实现树莓派在断电之后还能和venus通讯需要将华为的路由器也切换到ups系统上,只有这样在断电之后树莓派才能直到断电了。晚上重新梳理了一下家的网络拓普(不是专业网络工程师,图例可能用的不太对)

于是又让我想到了联通的工程师来家里换光纤的时候直摇头,哈哈哈。现在组网方式包括5g桥接,光纤,网线,哈哈哈。这个对接种类神奇了。一台企业路由+一台企业交换机+2套光转换+4台无线路由器。好处就是现在家里无线网络无死角覆盖,速度嘛也非常ok。就是太费电,但是我也不想再改了啊,太麻烦了。

都切换到ups供电之后在树莓派上就可以开始配置了:

1.安装nut client

代码语言:javascript
复制
sudo apt install nut

2.修改配置文件:

代码语言:javascript
复制
编辑/etc/nut/nut.conf,MODE设置如下:

MODE=netclient
编辑/etc/nut/upsmon.conf,MONITOR设置如下:

MONITOR ups@192.168.1.12 1 monuser secret slave
说明:

MONITOR <system> <powervalue> <username> <password> ("master"|"slave")
#<system>设置为ups@服务器地址或域名,这里是ups@192.168.1.12
#<powervalue>设置为1
#<username>群晖UPS服务器的默认用户名是monuser
#<password>群晖UPS服务器的默认密码是secret
#("master"|"slave"),客户机设置为slave

3.测试链接,需要修改venus添加允许的ip地址,如果看到下面的内容那就成功啦:

  1. 启动服务:
代码语言:javascript
复制
systemctl start nut-client

5.设置服务开机自启动

代码语言:javascript
复制
systemctl enable nut-client

如果出现下面的错误,可以检查服务器ip白名单,群晖修改白名单之后要点击右下角的应用才会生效。

延伸设置—自定义关机设置:

默认关机逻辑貌似是:nut服务会在UPS发送LOWBATT时通知机器关机,触发时机默认为ups电量剩余20%

如果要自定义关机设置需要进行如下设置(因为群辉提供的ups服务器在ups断电之前就关闭了,不清楚服务器在关机之前是不是会发送lowbatt消息)

1.编辑upsmon.conf,添加以下内容:

代码语言:javascript
复制
vim /etc/nut/upsmon.conf
代码语言:javascript
复制
NOTIFYCMD /sbin/upssched
NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC

通知类型定义:

代码语言:javascript
复制
NOTIFYMSG type message
upsmon comes with a set of stock messages for various events. You can change them if you like.

NOTIFYMSG ONLINE "UPS %s is getting line power"
NOTIFYMSG ONBATT "Someone pulled the plug on %s"
Note that %s is replaced with the identifier of the UPS in question.

The message must be one element in the configuration file, so if it contains spaces, you must wrap it in quotes.

NOTIFYMSG NOCOMM "Someone stole UPS %s"
Possible values for type:

ONLINE
UPS is back online

ONBATT
UPS is on battery

LOWBATT
UPS is on battery and has a low battery (is critical)

FSD
UPS is being shutdown by the primary (FSD = "Forced Shutdown")

COMMOK
Communications established with the UPS

COMMBAD
Communications lost to the UPS

SHUTDOWN
The system is being shutdown

REPLBATT
The UPS battery is bad and needs to be replaced

NOCOMM
A UPS is unavailable (can’t be contacted for monitoring)

NOTIFYFLAG type flag[+flag]…
By default, upsmon sends walls global messages to all logged in users) via /bin/wall and writes to the syslog when things happen. Except for Windows where upsmon only writes to the syslog by default. You can change this.

Examples:

NOTIFYFLAG ONLINE SYSLOG
NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC
Possible values for the flags:

SYSLOG
Write the message to the syslog

WALL
Write the message to all users with /bin/wall

EXEC
Execute NOTIFYCMD (see above) with the message

IGNORE
Don’t do anything

If you use IGNORE, don’t use any other flags on the same line.

2.修改upssched.conf添加以下内容

代码语言:javascript
复制
vim /etc/nut/upssched.conf
代码语言:javascript
复制
CMDSCRIPT /etc/nut/upssched-cmd #编写此脚本设置
# NOTIFYCMD /sbin/upssched
# NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC
PIPEFN /etc/nut/upssched.pipe
LOCKFN /etc/nut/upssched.lock

AT ONBATT * START-TIMER power-off 60
AT ONLINE * CANCEL-TIMER power-off
AT ONLINE * EXECUTE power-on

3.编辑upssched-cmd脚本

代码语言:javascript
复制
vim /etc/nut/upssched-cmd

文件内容:

代码语言:javascript
复制
#!/bin/sh
 case $1 in
       onbatt)
          logger -t upssched-cmd "UPS running on battery"
          # do somethings ,e.g.send email \ wechat
       /usr/sbin/upsmon -c fsd
          ;;
       power-off)
          logger -t upssched-cmd "UPS running on battery power off"
          /usr/sbin/upsmon -c fsd
          ;;
       shutdowncritical)
          logger -t upssched-cmd "UPS on battery critical, forced shutdown"
          /usr/sbin/upsmon -c fsd
          ;;
       upsgone)
          logger -t upssched-cmd "UPS has been gone too long, can't reach"
          ;;
       *)
          logger -t upssched-cmd "Unrecognized command: $1"
          ;;
 esac

修改完成之后重启服务。

参考链接:

https://typecho.leosutopia.cn/index.php/archives/248/#comment-13

https://networkupstools.org/docs/man/index.html#User_man

https://networkupstools.org/docs/man/upssched.conf.html

https://networkupstools.org/docs/man/upsmon.conf.html

https://www.cnblogs.com/LandWind/articles/pve-nut-config.html

https://www.storyxc.com/pages/41ed75/#%E7%BC%96%E5%86%99%E8%84%9A%E6%9C%AC

☆文章版权声明☆

* 网站名称:obaby@mars

* 网址:https://h4ck.org.cn/

* 本文标题: 《是UPS吖(三)–-树莓派》

* 本文链接:https://h4ck.org.cn/2023/02/%e6%98%afups%e5%90%96%ef%bc%88%e4%b8%89%ef%bc%89-%e6%a0%91%e8%8e%93%e6%b4%be/

* 转载文章请标明文章来源,原文标题以及原文链接。请遵从 《署名-非商业性使用-相同方式共享 2.5 中国大陆 (CC BY-NC-SA 2.5 CN) 》许可协议。


分享文章:

相关文章:

  1. 树莓派UPS自定义关机脚本(NUT)
  2. 是UPS吖(一)–开箱
  3. 是UPS吖(二)–-群晖
  4. CentOS 6.2架设VPN和619错误排除
  5. 阿里云蛋疼的pip
  6. Ubuntu Fcitx输入法以及Flash乱码
  7. BroadlinkRM2 Domotizc Plugin插件
  8. IDA Name Chang via idc Script
  9. Ticket #11289, IE bug fix Error
  10. 群晖 NAS Python3 PIP
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023年2月11日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 相关文章:
相关产品与服务
VPN 连接
VPN 连接(VPN Connections)是一种基于网络隧道技术,实现本地数据中心与腾讯云上资源连通的传输服务,它能帮您在 Internet 上快速构建一条安全、可靠的加密通道。VPN 连接具有配置简单,云端配置实时生效、可靠性高等特点,其网关可用性达到 99.95%,保证稳定、持续的业务连接,帮您轻松实现异地容灾、混合云部署等复杂业务场景。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档