海运的博客

PVE/Linux安装nut管理apc BK650M2-CH ups自动关机

发布时间:December 9, 2021 // 分类: // 9 Comments

先查看usb是否识别ups:

lsusb
Bus 001 Device 054: ID 051d:0002 American Power Conversion Uninterruptible Power Supply

安装:

apt install nut-server nut-client

配置nut运行为服务器模式,可控制多台电脑。

/etc/nut/nut.conf 
MODE=netserver

设置nut和ups连接方式,修改此配置后需重新启动upsdrvctl start生效。

/etc/nut/ups.conf
[myups]
       driver = usbhid-ups
       port = auto
       desc = "APC UPS"
       #忽略低电量和低运行时间,有的断电后会马上关机
       ignorelb
       #重写ups返回的低电量和低运行时间值,可用于控制停电时关机时间,满足一个关机,-1为禁用此项
       override.battery.charge.low = 99
       override.battery.runtime.low = -1
       #可以都设置为-1禁用ups低电量自动关机,使用下面的脚本自定义关机

连接ups,nut-server启动时自动加载,usb拔出后需手工启动。

upsdrvctl start

设置nut server监听ip和端口:

/etc/nut/upsd.conf 
LISTEN 0.0.0.0 3493

设置客户端连接验证密码:

/etc/nut/upsd.users
#管理员可set更改ups内变量参数,master可设置FSD关机标签,slave收到通知后关机
[admin]
    password = 123456
    actions = SET FSD
    instcmds = ALL
    upsmon master
[user1]
    password = 123456
    actions = FSD
    #instcmds = ALL
    upsmon master
#别的电脑连接使用此用户
[user2]
    password = 123456
    #actions = SET
    #instcmds = ALL
    upsmon slave

设置upsmon客户端连接nut server监控ups状态,当断电后执行关机等操作:

/etc/nut/upsmon.conf 
MONITOR myups@localhost 1 user1 123456 master

upsmon默认监控断电且ups电量过低时执行关机,可自定义关机:

upsmon.conf 
NOTIFYCMD /sbin/upssched
#当使用电池来电时syslog并执行上面的命令
NOTIFYFLAG ONBATT SYSLOG+EXEC
NOTIFYFLAG ONLINE SYSLOG+EXEC

upssched自定义操作:

/etc/nut/upssched.conf 
CMDSCRIPT /usr/local/bin/upssched
#此目录nut要可写
PIPEFN /run/nut/upssched.pipe
LOCKFN /run/nut/upssched.lock
#断电10秒后执行上面脚本并发送power-off参数
AT ONBATT * START-TIMER power-off 10
#来电后取消上面定时
AT ONLINE * CANCEL-TIMER power-off

关机脚本,要添加可执行权限:

/usr/local/bin/upssched
#! /bin/sh

case $1 in
  power-off)
    /sbin/upsmon -c fsd
    ;;
  *)
    logger -t upssched "Unrecognized command: $1"
    ;;
esac

启动并查看ups信息:

systemctl restart nut-server.service 
systemctl restart nut-client.service 
upsc myups

配置nut-cgi web管理界面:

apt install nut-cgi --no-install-recommends fcgiwrap nginx

nut-cgi连接nut-server配置:

/etc/nut/hosts.conf
MONITOR myups@localhost 1 user1 123456 master

nginx配置文件:

server {
  listen     89;
  charset utf-8;
 
  location /{
    alias /usr/share/nut/www/;
    try_files $uri $uri/ /index.html;
  }
 
  location /cgi-bin/nut/ {
    gzip off;
    alias /usr/lib/cgi-bin/nut/;
    include /etc/nginx/fastcgi_params;
    fastcgi_param SCRIPT_FILENAME /usr/lib/$fastcgi_script_name;
    fastcgi_pass  unix:/var/run/fcgiwrap.socket;
  }
  access_log off;
}

nut web界面效果:
2021-12-10_080005.jpg

参考:
https://loganmarchione.com/2017/02/raspberry-pi-ups-monitor-with-nginx-web-monitoring/
https://srackham.wordpress.com/2013/02/27/configuring-nut-for-the-eaton-3s-ups-on-ubuntu-linux/
https://alainlam.cn/?p=56
https://untitled.pw/hardware-iot/2767.html
https://www.wangchucheng.com/zh/posts/setting-up-ups-with-nut-on-linux/
https://forums.contribs.org/index.php?topic=44443.0

PVE/KVM安装windows遇到的问题

发布时间:December 8, 2021 // 分类: // No Comments

由于windows不包含VirtIO驱动,PVE默认使用ide硬盘很卡,在新建虚拟机时将硬盘ide调整为scsi,额外新建一个cd驱动器挂载virtio-win iso,然后在windows安装界面加载挂载的驱动,windows7最新可用版本为virtio-win-0.1.173
2021-12-07_170730.jpg
windows7安装完成后设备管理器有一未识别设备,下载windows6.x-hypervintegrationservices-x64管理员运行powershell安装。

Dism /online /Add-Package /PackagePath:C:\windows6.x-hypervintegrationservices-x64.cab

参考:
https://forum.proxmox.com/threads/unknown-device-in-win7-vm.49698/
https://forum.proxmox.com/threads/windows-7-and-virtio-drivers-no-signed-drivers-found-for-0-1-185-and-0-1-190-or-bsod-with-0-1-189.79708/
https://pve.proxmox.com/wiki/Paravirtualized_Block_Drivers_for_Windows
https://pve.proxmox.com/wiki/Windows_7_guest_best_practices
https://pve.proxmox.com/wiki/Windows_VirtIO_Drivers

Proxmox LXC挂载目录及权限设置

发布时间:November 26, 2021 // 分类: // No Comments

PVE LXC挂载目录服务器目录到容器内:

cat /etc/pve/lxc/100.conf 
mp0: /data/e,mp=/data/e
mp1: /data/f,mp=/data/f

LXC为了安全默认为无特权容器,容器内程序以root的子用户运行,容器内要写挂载的文件要在服务器内为指定的子用户设置相应权限。
查看root的默认从属用户起始id为100000,数量65536个。

grep root /etc/subgid /etc/subuid
/etc/subgid:root:100000:65536
/etc/subuid:root:100000:65536

配置映射从属用户到lxc容器,默认lxc容器内root(id=0)映射为服务器id 100000,递增65536个,即容器内用户id 0-65535对应服务器100000-165535。

cat /etc/pve/lxc/100.conf 
lxc.idmap: u 0 100000 65536
lxc.idmap: g 0 100000 65536

注意容器内nobody id为65534,没映射到会连接不上ssh,提示错误:

fatal: setgroups: Invalid argument [preauth]

如果将挂载目录让容器内root可读写的话在服务器内将所有者更改为id 100000。

chown -R 100000:100000 /data/e
#也可使用用户名
useradd -u 100000 -M -s -s /usr/sbin/nologin lxc-root 
groupmod -g 100000 lxc-root
chown -R lxc-root:lxc-root /data/e

为方便管理可将服务器实体用户映射为容器内指定用户,需先将服务器内的实体用户id添加为root的子用户(其它用户不行),如添加id为1005的用户。

grep root /etc/subuid /etc/subgid
/etc/subgid:root:100000:65536
/etc/subgid:root:1005:1
/etc/subuid:root:100000:65536
/etc/subuid:root:1005:1

配置lxc将服务器id 1005映射为容器内id 1005,其它为root虚拟子用户。

#lxc内id 0到1005映射为服务器id 100000到101005
lxc.idmap: u 0 100000 1005
lxc.idmap: g 0 100000 1005
#将lxc内id 1005映射为服务器id 1005实体用户
lxc.idmap: u 1005 1005 1
lxc.idmap: g 1005 1005 1
#lxc剩下的id 1006到65535映射为服务器id 101006到165535
lxc.idmap: u 1006 101006 64530
lxc.idmap: g 1006 101006 64530

参考:
https://pve.proxmox.com/wiki/Unprivileged_LXC_containers
https://forum.proxmox.com/threads/newuidmap-uid-range-1100-1101-1100-1101-not-allowed.73414/

Proxmox7.1显示CPU/主板/硬盘温度

发布时间:November 24, 2021 // 分类: // No Comments

安装获取温度软件:

apt install lm-sensors
apt install hddtemp
chmod +s /usr/sbin/hddtemp

修改/usr/share/perl5/PVE/API2/Nodes.pm:

PVE::pvecfg::version_text();
#以下为添加
$res->{thermal} = `sensors -j`;  
$res->{thermal_hdd} = `hddtemp /dev/sd?`;
#结束
my $dinfo = df('/', 1);     # output is bytes

修改/usr/share/pve-manager/js/pvemanagerlib.js:

{
        itemId: 'version',
                colspan: 2,
                printBar: false,
                title: gettext('PVE Manager Version'),
                textField: 'pveversion',
                value: '',
},
#以下为添加内容
        {
                itemId: 'thermal',
                colspan: 2,
                printBar: false,
                title: gettext('CPU/主板温度'),
                textField: 'thermal',
                renderer: function(value) {
                        //value = JSON.parse(value.replaceAll('Â', ''));
                        value = JSON.parse(value);
                        const cpu0 = value['coretemp-isa-0000']['Package id 0']['temp1_input'].toFixed(1);
                        const cpu1 = value['coretemp-isa-0000']['Core 0']['temp2_input'].toFixed(1);
                        const cpu2 = value['coretemp-isa-0000']['Core 1']['temp3_input'].toFixed(1);
                        const cpu3 = value['coretemp-isa-0000']['Core 2']['temp4_input'].toFixed(1);
                        const cpu4 = value['coretemp-isa-0000']['Core 3']['temp5_input'].toFixed(1);
                        const board = value['acpitz-acpi-0']['temp1']['temp1_input'].toFixed(1);
                        return `Package: ${cpu0}°C | Core: ${cpu1}° C | ${cpu2}° C | ${cpu3}° C | Board: ${board}°C`; 
                }
        },
        {
                itemId: 'thermal-hdd',
                colspan: 2,
                printBar: false,
                title: gettext('硬盘温度'),
                textField: 'thermal_hdd',
                renderer: function(value) {
                        value = value.replaceAll('Â', '');
                        return value.replaceAll('\n', '<br>');
                }
        },
#结束
],

修改显示区域高度:

Ext.define('PVE.node.StatusView', {
    extend: 'Proxmox.panel.StatusView',
    alias: 'widget.pveNodeStatus',
    #height: 300,
    height: 450,
    bodyPadding: '15 5 15 5',

    layout: {

效果如下:
2021-11-24_154258.jpg

参考:
https://64g.cc/index.php/2021/07/18/proxmox-7-0-%E6%B7%BB%E5%8A%A0cpu-nvme-hdd%E6%B8%A9%E5%BA%A6%E7%9B%91%E6%8E%A7/
https://zry.io/archives/285

Proxmox网桥通过SLAAC配置公网ipv6地址

发布时间:November 19, 2021 // 分类: // 2 Comments

Proxmox安装后默认没有通过SLAAC配置公网ipv6地址,使用debian/ubuntu的方法配置ipv6提示错误不支持的方法auto。

iface vmbr0 inet6 auto

原来Proxmox使用的是ifupdown2,非debian/ubuntu使用ifupdown。

查看内核也已经开启ipv6自动配置:

cat /proc/sys/net/ipv6/conf/vmbr0/accept_ra
1
cat /proc/sys/net/ipv6/conf/vmbr0/autoconf 
1

查看已开启ipv6转发:

cat /proc/sys/net/ipv6/conf/vmbr0/forwarding 
1

需要将accept_ra值改成2才能自动配置SLAAC ipv6地址:

/etc/sysctl.conf
net.ipv6.conf.all.accept_ra=2
net.ipv6.conf.default.accept_ra=2
net.ipv6.conf.vmbr0.accept_ra=2
net.ipv6.conf.all.autoconf=1
net.ipv6.conf.default.autoconf=1
net.ipv6.conf.vmbr0.autoconf=1

参考:
https://github.com/CumulusNetworks/ifupdown2/issues/178#issuecomment-725558706
https://www.starduster.me/2020/02/19/talk-about-slaac-on-linux-principle-configuration-and-behavior/

分类
最新文章
最近回复
  • 海运: 恩山有很多。
  • swsend: 大佬可以分享一下固件吗,谢谢。
  • Jimmy: 方法一 nghtp3步骤需要改成如下才能编译成功: git clone https://git...
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...
  • 孤狼: ups_status_set: seems that UPS [BK650M2-CH] is ...
  • 孤狼: 擦。。。。apcupsd会失联 nut在冲到到100的时候会ONBATT进入关机状态,我想想办...
  • 海运: 网络,找到相应的url编辑重发请求,firefox有此功能,其它未知。
  • knetxp: 用浏览器F12网络拦截或监听后编辑重发请求,修改url中的set为set_super,将POS...
  • Albert: 啊啊啊啊啊啊啊啊啊 我太激动了,终于好了英文区搜索了半天,翻遍了 pve 论坛没找到好方法,博...