php 运行 ipmi 命令滞后卡顿解决方案

	public function IPMIcommand($ip, $user, $password, $cmd)
	{
		if (!(ereg('^[[:alnum:] ]+', $cmd))) {
			throw new Exception('Invalid characters in command');
		}
		if (ereg('^bootdev ', $cmd)) {
			$cmd = 'chassis ' . $cmd;
		}

		$output = array();
		exec('/usr/bin/ipmitool -H ' . escapeshellarg($ip) . ' -U ' . escapeshellarg($user) . ' -P ' . escapeshellarg($password) . '' . ' ' . $cmd . ' 2>&1', $output);
		return implode("\n", $output);
	}

 看别人写代码, 解决了 10 年为啥php 命令跑起来会卡顿的疑惑

debootstrap部署打包系统debian 和 ubuntu

目前为止好像还不支持 ubuntu24

具体支持的版本查看/usr/share/debootstrap/scripts/目录

#!/bin/bash
# 设置变量
NAME="jammy"
DISK="/dev/vdb"

BOOT_PART="${DISK}1"
SWAP_PART="${DISK}2"
ROOT_PART="${DISK}3"

apt update -y
apt install -y debootstrap  arch-install-scripts parted dosfstools
parted ${DISK} --script -- mklabel msdos
parted ${DISK} --script -- mkpart primary ext4 1MiB 2GiB
parted ${DISK} --script -- mkpart primary linux-swap 2GiB 3GiB
parted ${DISK} --script -- mkpart primary ext4 3GiB 100%

# 格式化分区
#mkfs.vfat -F32 $BOOT_PART
mkfs.ext4 -F $BOOT_PART
mkfs.ext4 -F $ROOT_PART
mkswap $SWAP_PART
swapon $SWAP_PART  

mount $ROOT_PART /mnt/
mkdir -p /mnt/boot
mount $BOOT_PART /mnt/boot

# 使用 debootstrap 安装基本系统
debootstrap --arch amd64 $NAME  /mnt/ http://archive.ubuntu.com/ubuntu/

mount --bind /proc /mnt/proc
mount --bind /dev /mnt/dev
mount --bind /sys /mnt/sys
mount -t devpts devpts /mnt/dev/pts

#更新设置系统内核和配置
chroot /mnt /bin/bash -c "echo 'root:your_password' | chpasswd"
chroot /mnt/ apt -y update
chroot /mnt/ apt -y upgrade
chroot /mnt/ locale-gen en_US.UTF-8
chroot /mnt/ update-locale LANG=en_US.UTF-8
for I in linux-image-generic linux-firmware initramfs-tools efibootmgr grub2-common grub-efi-amd64 grub-pc;
do chroot /mnt/ apt -y install --no-install-recommends $I ; done 
chroot /mnt/ sed -i 's#GRUB_CMDLINE_LINUX=""#GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"#g' /etc/default/grub  
chroot /mnt/ echo GRUB_DISABLE_OS_PROBER=true >/etc/default/grub 
chroot /mnt/ grub-install $DISK
chroot /mnt/ grub-mkconfig -o /boot/grub/grub.cfg
chroot /mnt/ update-grub
#chroot /mnt/ grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu --recheck
chroot /mnt/ apt -y install  --no-install-recommends  openssh-server 
chroot /mnt/  sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
chroot /mnt/ systemctl enable systemd-networkd
chroot /mnt/ systemctl enable  ssh

cat>/mnt/etc/apt/sources.list<<EOF
deb http://archive.ubuntu.com/ubuntu ${NAME} main 
deb http://archive.ubuntu.com/ubuntu ${NAME} ${NAME}-security  main
deb http://archive.ubuntu.com/ubuntu ${NAME} ${NAME}-updates   main
EOF

cat>/mnt/etc/systemd/network/10-eth0.network<<EOF
[Match]
Name=eth0

[Network]
DHCP=yes
EOF

# 配置网络、主机名、fstab等(可根据需要添加)
cat>/mnt/etc/fstab<<EOF
/dev/vda1  /boot  ext4  defaults        1 1
/dev/vda2  swap   swap  defaults        0 0
/dev/vda3  /      ext4   defaults       1 2
EOF

echo "ubuntu" > /mnt/etc/hostname
cat <<EOL > /mnt/etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp
EOL

swapoff $SWAP_PART
for i in /dev/pts /dev /proc /sys /boot /; do umount /mnt$i; done  ## 卸载挂载
echo "Ubuntu installation setup completed on $DISK"

brew 安装 php 报错备忘录

Error: Invalid formula: /usr/local/Homebrew/Library/Taps/shivammathur/homebrew-php/Formula/[email protected]
[email protected]: undefined method `service' for #<Class:0x00007f968a9d5f80>
Error: Invalid formula: /usr/local/Homebrew/Library/Taps/shivammathur/homebrew-php/Formula/[email protected]
[email protected]: undefined method `service' for #<Class:0x00007f968aa0c828>
Error: Invalid formula: /usr/local/Homebrew/Library/Taps/shivammathur/homebrew-php/Formula/php-debug.rb
php-debug: undefined method `service' for #<Class:0x00007f968aa3c0c8>
Error: Invalid formula: /usr/local/Homebrew/Library/Taps/shivammathur/homebrew-php/Formula/[email protected]
[email protected]: undefined method `service' for #<Class:0x00007f968aa7f210>
Error: Invalid formula: /usr/local/Homebrew/Library/Taps/shivammathur/homebrew-php/Formula/[email protected]
[email protected]: undefined method `service' for #<Class:0x00007f968aaa5cd0>
Error: Invalid formula: /usr/local/Homebrew/Library/Taps/shivammathur/homebrew-php/Formula/[email protected]
[email protected]: undefined method `service' for #<Class:0x00007f968a947230>
Error: Invalid formula: /usr/local/Homebrew/Library/Taps/shivammathur/homebrew-php/Formula/[email protected]
[email protected]: undefined method `service' for #<Class:0x00007f96a009c700>
Error: Invalid formula: /usr/local/Homebrew/Library/Taps/shivammathur/homebrew-php/Formula/[email protected]
[email protected]: undefined method `service' for #<Class:0x00007f968a9e4210>
Error: Invalid formula: /usr/local/Homebrew/Library/Taps/shivammathur/homebrew-php/Formula/[email protected]
[email protected]: undefined method `service' for #<Class:0x00007f968aa77b28>
Error: Invalid formula: /usr/local/Homebrew/Library/Taps/shivammathur/homebrew-php/Formula/[email protected]
[email protected]: undefined method `service' for #<Class:0x00007f967811a628>
Error: Invalid formula: /usr/local/Homebrew/Library/Taps/shivammathur/homebrew-php/Formula/[email protected]
[email protected]: undefined method `service' for #<Class:0x00007f96a00a6570>
Error: Cannot tap shivammathur/php: invalid syntax in tap!

解决方法

brew untap exolnet/deprecated
brew tap --repair
brew update
brew tap shivammathur/php
brew install shivammathur/php/[email protected]
brew link --overwrite --force shivammathur/php/[email protected]

原文出处https://github.com/shivammathur/homebrew-php/discussions/743

massgrave的kms 激活

PowerShell 脚本

irm https://get.activated.win | iex

 

附各种 iso 和软件下载地址https://massgrave.dev/genuine-installation-media

dnf将repo仓库同步到本地

将metadata 里面所有的包下载下来

 dnf reposync  -p ./ --download-metadata --repoid=epel

同步最新版本和清理本地旧版本

dnf reposync  -p ./ -n --delete --download-metadata --repoid=epel

一是有些小的 repo 需要本地保存一份自建镜像,防止失联。 二是看一下有哪些安装包和结构

WHMCS调取账单付款链接数据

<?php
include("init.php");
$invoiceid = (int) $whmcs->get_req_var("id");
$invoice = new WHMCS\Invoice($invoiceid);
$params = $invoice->getGatewayInvoiceParams();
$params  = json_decode(json_encode($params), true);
print_r($invoice->getData("status"));
print_r($invoice->getData("balance"));
print_r($invoice->getPaymentLink());

$params 就支付网关XXXX_link传进去的原始数据,有了这个数据就可以方便在不需要登录的情况下直接显示出支付的信息。

通过查看 whmcs 官方版本解密源码可以看到 

https://github.com/puarudz/WHMCS-7.8.0-decoded/blob/e7446479de49a28c8801d4c0c95f4cae22dcff33/modules/gateways/callback/skrill.php

 

附带whmcs生成二维码方案, 由于默认没自带qrcode.js 又不想另外去引入文件, vendor自带有bacon-qr-code  /google-authenticator totp  tcpdf  几个可以直接拿来用。

function XXXX_qrcode($qrlink) {
                $qrcode = new TCPDF2DBarcode( $qrlink , 'QRCODE,L');
               // $Data = $qrcode->getBarcodePngData( 3 , 3);
                $Data = $barcode->getBarcodeSVG(6, 6); 
               $base64Image = base64_encode($Data);
               return 'data:image/svg+xml;base64,' . $svgEncoded;

             //  return 'data:image/png;base64,'.$base64Image;
}

Cento9 upgrade to Centos10

CentOS Stream 9 在 2027年5月31号 EOL停止更新,这里提前做一下准备。

前期准备

更新stream-release和epel-release 需要去镜像网站上查看rpm 版本号,确保路径正确。

由于目前系统上线不久,很多源的release 没有追加更新 ,需要确认是否已经对 10 支持, 否则需要移除才能升级,

例如当前升级时候就只能先卸载remi-release才能执行升级,升级前务必备份重要数据,如果安装的rpm 比较多需要确认新系统兼容。

VERSION=10.0-0.20
dnf install -y https://mirror.stream.centos.org/10-stream/BaseOS/x86_64/os/Packages/centos-{stream-release,stream-repos,gpg-keys}-${VERSION}.el10.noarch.rpm   --allowerasing

#dnf install -y https://dl.fedoraproject.org/pub/epel/epel-{next-release,release}-latest-10.noarch.rpm   #epel官方暂时还没有出

dnf install -y https://dl.fedoraproject.org/pub/epel/10/Everything/x86_64/Packages/e/epel-release-10-1.el10_0.noarch.rpm   #临时用这个

sed -e 's|^#baseurl=https://download.example/|baseurl=https://dl.fedoraproject.org/|' -e 's|^metalink=|#metalink=|' -e 's|^gpgkey=.*|gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-$releasever|'   -i.bak /etc/yum.repos.d/epel.repo       # 更新epel.repo设置,官方暂时还没更新 metalink 和 GPG key 的地址 

执行升级

dnf -y --releasever=10 --allowerasing --setopt=deltarpm=false distro-sync

收尾

rpm -qa | grep '\.el9' | xargs xargs rpm -e    #强制卸载el9的残留rpm
grub2-mkconfig -o /boot/grub2/grub.cfg     #重新生成 grub引导
grubby --default-kernel           # 查看确认默认启动内核

dnf upgrade -y     #最后再更新一下

kexec 切换新版内核 

kernel=$(grubby --default-kernel | sed 's|/boot/vmlinuz-||')
parameter=$(sed 's|.*vmlinuz-[^ ]* ||' /proc/cmdline)
kexec -l /boot/vmlinuz-$kernel --initrd=/boot/initramfs-$kernel.img  --append=\"$parameter\"
kexec -e

kexec是在当前运行的系统和内核下切换内核, 重启是让主板重新走grub引导内核。

切换内核和重启风险都很大,需要谨慎,提前做好准备。

检查grub和kernel 后有条件的可以安排时间进行尝试重启系统。

 

升级完成后查看内核和发新版本信息

# cat /etc/redhat-release
CentOS Stream release 10 (Coughlan)

# rpm -qa|grep kernel |grep el10
kernel-headers-6.11.0-25.el10.x86_64
kernel-tools-libs-6.11.0-25.el10.x86_64
kernel-modules-core-6.11.0-25.el10.x86_64
kernel-core-6.11.0-25.el10.x86_64
kernel-modules-6.11.0-25.el10.x86_64
kernel-6.11.0-25.el10.x86_64
kernel-tools-6.11.0-25.el10.x86_64

# uname -a
Linux XXXXXXX 6.11.0-25.el10.x86_64 #1 SMP PREEMPT_DYNAMIC Mon Sep 16 20:35:26 UTC 2024 x86_64 GNU/Linux

善后

升级完 rpm -qa 查询出错

error: Verifying a signature using certificate 99DB70FAE1D7CE227FB6488205B555B38483C65D (CentOS (CentOS Official Signing Key) <[email protected]>):
  1. Certificate 05B555B38483C65D invalid: policy violation
      because: No binding signature at time 2024-09-03T17:32:14Z
      because: Policy rejected non-revocation signature (PositiveCertification) requiring second pre-image resistance
      because: SHA1 is not considered secure
  2. Certificate 05B555B38483C65D invalid: policy violation
      because: No binding signature at time 2024-10-04T09:48:41Z
      because: Policy rejected non-revocation signature (PositiveCertification) requiring second pre-image resistance
      because: SHA1 is not considered secure

 

解决办法卸载 epel9 的 pubkey, 如果 rpm -qa报错, 可以将查询文本保存到文件查看

rpm -q gpg-pubkey --qf '%{NAME}-%{VERSION}-%{RELEASE}\t%{SUMMARY}\n'    #查看所有gpg key

rpm -e  gpg-pubkey-3228467c-613798eb   #移除epel9的SHA1 pubkey

运行 dnf提示dnf modules 报错, 可能是之前的升级不支持的遗留,再确定后对/etc/dnf/modules.d/*目录进行清理即可

 rm -rf  /etc/dnf/modules.d/*

 

 

LSI 2208阵列卡刷 IT 直通模式, 附带 sas2flash for Linux

BIOS 模式启动 DOS 系统

megarec -adplist   #查看阵列卡编号
megarec -m0flash 0 2208_16.rom    #写入2208的RAID卡ROM ,如果卡是正常的这一步跳过。
megarec -writesbr 0 sbrempty.bin
megarec -cleanflash 0

重启设置UEFI 模式启动进入 EFI  Shell

fs0:
sas2flash -o -f 9207-8.bin -b mptsas2.rom    # 刷入IT 直通固件
sas2flash -o -sasadd 50030480195exxxx     #xxxx替换成任意 4 个数字
sas2flash -list  #检查SAS Address地址和上面写入的是否一样

由于lsi2208fixer_changed.iso只有mptsas2.rom没有 bios 和 uefi 的 rom, 刷完系统只能直通硬盘没有 boot 引导。

阅读剩余部分...

私有 IPv6 随机生成

IPv4 还能记住那几个保留的内网段 IP, IPv6太多完全没法玩, 配置设备的时候又不知道该咋写 IP段方便。

随机生成方案就简单了

https://simpledns.plus/private-ipv6

 

 

 

guestmount直接挂载虚拟硬盘

guestmount --add  /tmp/linux-centos-stream_8-x86_64-gen2-v1.qcow2  --mount /dev/sda1  /mnt/

最早 kvm 虚拟机上线的时候就玩过, 当时嫌弃在这玩意挂载后大规模读写 IO 性能差, 就多数时候在用kpartx 命令。

 

Centos9 stream 横跳almalinux 9

dnf -y install --allowerasing https://mirror.rackspace.com/almalinux/almalinux-{release,gpg-keys,repos}-latest-9.x86_64.rpm
dnf -y --releasever=9 --allowerasing --setopt=deltarpm=false distro-sync

按道理说横跳Rocky Linux应该也没问题, 最好 Centos 的版本旧一点好, 所以横跳前不建议 dnf update.

nmcli 一键设置网桥为 br0 脚本

#!/bin/bash

BRIDGE="br0"
# ip -o route get to 8.8.8.8|awk  '{ print "gateway:" $3 " netname:" $5"  IP:" $7}'  
NET_IFACE=$(ip -o route get to 8.8.8.8|awk '{ print $5}')  #根据外网 ip 来判断网卡方法
#NET_IFACE=$(nmcli -t -f DEVICE,STATE device | grep ':connected' | head -n 1 | cut -d: -f1)   #从第一个网卡的方式获取网卡名 

#mv  /etc/sysconfig/network-scripts/ifcfg-$NET_IFACE  /etc/sysconfig/network-scripts/ifcfg-$NET_IFACE.bak
IP4_ADDRESS=$(nmcli device show "$NET_IFACE" |grep "IP4.ADDRESS\[1\]" | awk '{ print $2}')
IP4_GATEWAY=$(nmcli -g IP4.GATEWAY device show "$NET_IFACE")
IP6_ADDRESS=$(nmcli device show "$NET_IFACE" |grep "IP6.ADDRESS\[1\]" | awk '{ print $2}')
IP6_GATEWAY=$(nmcli -g IP6.GATEWAY device show "$NET_IFACE"|sed 's/\\//g')

nmcli conn add type bridge con-name "$BRIDGE" ifname "$BRIDGE"

if [ $IP4_ADDRESS ]  ; then
nmcli conn mod "$BRIDGE" ipv4.addresses $IP4_ADDRESS
nmcli conn mod "$BRIDGE" ipv4.gateway $IP4_GATEWAY
nmcli conn mod "$BRIDGE" ipv4.dns '8.8.8.8,1.1.1.1,1.2.4.8'
nmcli conn mod "$BRIDGE" ipv4.method manual
else
nmcli conn mod "$BRIDGE" ipv4.method auto
fi
if [ $IP6_ADDRESS ]  ; then
nmcli conn mod "$BRIDGE" ipv6.addresses $IP6_ADDRESS
nmcli conn mod "$BRIDGE" ipv6.gateway $IP6_GATEWAY
nmcli conn mod "$BRIDGE" ipv6.method manual
else
nmcli conn mod "$BRIDGE" ipv6.method auto
fi
nmcli connection modify "$BRIDGE" stp no
nmcli connection delete $NET_IFACE
nmcli conn add type ethernet slave-type bridge con-name "$NET_IFACE"-to-"$BRIDGE" ifname "$NET_IFACE" master "$BRIDGE"
systemctl restart NetworkManager

 

设置完成后网桥为 br0

原本的网卡名会变成类似eth0-to-br0

最好开着 ipmi 玩, 掉线了会比较蛋疼

qemu-img 转虚拟硬盘格式

mage forma Argument to qemu-img
QCOW2 (KVM, Xen) qcow2
QED (KVM) qed
raw raw
VDI (VirtualBox) vdi
VHD (Hyper-V) vpc
VMDK (VMware) vmdk

raw image.img 转 qcow2

qemu-img convert -f raw -O qcow2 image.img image.qcow2 

vmdk 转 raw

qemu-img convert -f vmdk -O raw image.vmdk image.img

vmdk 转 qcow2

qemu-img convert -f vmdk -O qcow2 image.vmdk image.qcow2

SolusVM Node server centos7 升级 centos9 善后工作

dnf install  solusvm-release -y
mv /etc/yum.repos.d/libguestfs-plesk.repo  /etc/yum.repos.d/libguestfs-plesk.repo.bak
bash /usr/local/solusvm/tmp/update/php8_updater.sh
service svmstack-fpm8 restart
dnf -y install  libguestfs-tools-c libguestfs* dhcp-server
ln -s  /etc/dhcpd.conf   /etc/dhcp/dhcpd.conf

从 centos7 升级到 8 再升级到 9, 无需重启系统也不用 kexec 切换内核。

就是中间过程比较曲折,尤其是在升级 8 的过程中的问题。

主要需要注意的地方是,UEFI 启动需要 shim-x64 和重新生成 grub.conf, 确定内核和IP 配置正确。

 

curl -k -i https://10.10.10.10:6767/command.php 

最后确认 api 接口 php 输出不是 500 错误就成功了。

Centos8升级 Centos9

注意:Centos9 是用 UEFI 启动方式, 升级前请先确认,以免重启无法引导

由于 Centos9 是滚动更新所以VER=9.0-26参数需要查看http://mirror.stream.centos.org/9-stream/BaseOS/x86_64/os/Packages/的 rpm

dnf upgrade --refresh -y
dnf remove -y $(dnf repoquery --unneeded)
dnf remove -y $(dnf repoquery --extras)
dnf autoremove -y

VER="9.0-26"
dnf install -y http://mirror.stream.centos.org/9-stream/BaseOS/x86_64/os/Packages/centos-{stream-release,stream-repos,gpg-keys}-${VER}.el9.noarch.rpm  --allowerasing
dnf install -y https://dl.fedoraproject.org/pub/epel/{epel-release-latest-9.noarch.rpm,epel-next-release-latest-9.noarch.rpm}
dnf -y remove rxvt-unicode-terminfo
dnf -y --releasever=9 --allowerasing --setopt=deltarpm=false distro-sync
rpmdb --rebuilddb
dnf -y remove -y subscription-manager
dnf upgrade --refresh -y
dnf -y groupupdate "Core" "Minimal Install"
dnf -y install kernel*  yum 
rpm -qa | grep '\.el8' | xargs xargs rpm -e # 卸载

#grubby --default-kernel
grubby --set-default 0

dnf -y install grub2 grub2-efi* shim-x64   #centos9的 baseos 包里面是shim-x64-15-15.el8_2.x86_64.rpm
dnf -y reinstall grub2 grub2-efi-x64  shim-x64
grub2-mkconfig -o /boot/grub2/grub.cfg
#grub2-install /dev/sda  #不适用于 uefi

 [ -d /sys/firmware/efi ] && echo UEFI || echo BIOS    #判断是 BIOS 还是 EFI

如果有dnf module @modulefailsafe 报错可以禁用或者不管

rm -rf /etc/dnf/modules.d/*  /var/lib/dnf/modulefailsafe/*   #  删掉即可

 

升级完成前确认网络配置以及系统内核引导全部正常后才能重启, 否则后续处理起来比较麻烦, 要挂救援系统操作。

阅读剩余部分...