WordPress锚点定位与偏移

最近弄了一个小插件 simpletoc 实现文章目录章节导航,真的挺好的一个小插件。但锚点定位与我这个主题匹配有一点点的小瑕疵。

锚点定位瑕疵现象

没有登录的情况下,由于菜单栏固定显示 position: fixed; 这样导致锚点定位被菜单栏遮挡了

如下图:

登录后的情况下wpadmin-bar 也是固定显示 position: fixed; 这样锚点定位后被完全遮挡了,导致体验非常的糟糕。

实际上我早就发现了这个问题,由于之前很少使用锚点定位,只在bbPress上很小部分内容用了,因为需要手动添加设置锚点连接,比较麻烦所以很少使用锚点定位到指定内容。目前有了这个 simpletoc 插件可以实现自动添加锚点和连接,对于内容比较长的文章,锚点定位到指定内容真心非常实用。

所以必需将这个小瑕疵给解决了。

我现在用的这个主题因为结合了bbPress与BuddyPress深度自定义了各种模板与css样式,所以不能轻易的更换主题,太累。琢磨了几个小时,终于解决了这个小瑕疵。

锚点定位与偏移

偏移就是要偏移的,但要偏移多少?登录与未登录之间相差了一个wpadmin-bar,移动端与PC端的菜单栏和 wpadmin-bar 又有几种模式需要去匹配,别看就这小瑕疵,还是花不少的时间。

目前我用 jQuery 与 CSS 配合解决了此问题,解决问题的过程中发现了CSS居然有函数与变量。

解决 wpadmin-bar 偏移量

jQuery片段我就一起放在页脚footer.php模板上,与返回顶部的jQuery片段在一起。

css样式属性值 --wp-admin-bar-height: 46px; 需要添加到 html 这里,不然 scroll-padding-top 会没有任何效果,其中的复杂关系,暂时没有时间去折腾清楚,先用着吧。

jQuery(function(){
    // 用户登录后就会有wpadminbar
    if ( jQuery('#wpadminbar').length > 0 ) {
        // 屏幕尺寸小于782px
        if ( jQuery(window).width() < 782 ){
            // 在html添加css样式属性值 --wp-admin-bar-height: 46px;
            jQuery('html').css("--wp-admin-bar-height","46px");
        } else { // 屏幕尺寸大于782px
            // 在html添加css样式属性值 --wp-admin-bar-height: 32px;
            jQuery('html').css("--wp-admin-bar-height","32px");
        }
    }
});
jQuery(function(){
    jQuery(window).scroll(function(){	
        if(jQuery(window).scrollTop()>200){
            jQuery('.go-to-top').addClass('go-on');
        } else {
            jQuery('.go-to-top').removeClass('go-on');
        }
    });
    jQuery('#to-top').click(function(){
        jQuery('html, body').animate({scrollTop:0},300);
    });
});

如果不使用jQuery判断 wpadmin-bar ,纯CSS也可以避免被固定的菜单栏与wpadmin-bar遮挡,但还是存在一点点瑕疵,所以暂时还是用了一点jQuery片段来配合一下。

配合CSS样式

我发现 WordPress 的 admin-bar 在不同分辨率下,有3种不同的样式,有点恶心。最主要使用 scroll-padding-top 来实现不同情况下的偏移量,最终完美定位到指定锚点。

/* 搞点颜色 */
:target {
    text-shadow: 6px 0 20px chartreuse;
}

/* 600px 以下样式 */
html {
	font-family: sans-serif;
	font-size: 62.5%;
	line-height: 1.15;
	-ms-text-size-adjust: 100%;
	-webkit-text-size-adjust: 100%;
	-webkit-box-sizing: border-box;
	-moz-box-sizing: border-box;
	box-sizing: border-box;
}

/* 768px以上样式 */
@media screen and (min-width: 48em) {
	html {
		scroll-padding-top: calc(var(--wp-admin-bar-height,1px) + 48px);
	}
}

/* 600px 至 768px 样式*/
@media screen and ( max-width: 48em ) and ( min-width: 37.5em ) {
	html {
		scroll-padding-top: var(--wp-admin-bar-height);
	}
}

上面的CSS的var()函数,其中的变量值--wp-admin-bar-height

上面的CSS的calc()函数,可用于计算哟,不错!

有空再慢慢消化一下这些对于我来说的新东西。

有效禁止WPS自动更新的方法

WPS真棒,因为免费使用,所以很好。但是免费是需要接受他提供的全套豪华套餐的,比如弹广告,各种引导消费的云服务,一直驻留后台运行的都不知道干什么的程序,等等。

好在广告貌似可以在配置工具设置关闭,这个我不太确定能否彻底关闭广告,但起码有这个设置。但他还会添加任务计划程序自动更新软件本身,只要WPS软件更新后,我们的各种设置是不是又被重置了呢?而且我们在任务计划程序这边禁用或删除WPS添加的计划任务,但只要再次使用WPS,这个计划任务又被重新添加激活了!实在令人头疼!

禁止WPS重新添加激活计划任务的方法

打开控制面板管理工具任务计划程序

点击 → 任务计划程序库 → 就能看到WPS相关的计划任务,如下图

管理任务计划程序
管理任务计划程序

双击 → Wps相关的计划任务 → 点击 → 操作

双击 → 启动程序路径

复制 → 程序或脚本 路径

然后将复制的路径粘贴到资源管理器 → 打开目录,如下图

打开WPS计划任务运行的程序目录

我们发现WPS这有两个是与升级相关的程序吧?都把他给禁了!

右键点击 WPS升级程序属性安全编辑

Administrator用户组的用户拒绝所有权限(如果还有:User用户组拒绝所有权限

设置权限限制运行WPS升级程序
设置权限限制运行WPS升级程序

最后应用并确定。

设置好后,可以直接双击运行这两个升级程序,会提示: Windows无法访问指定设备、路径或文件。你可能没有适当的权限访问该项目。

OK,现在计划任务即使能够执行,也无权限运行升级程序了。更何况限制这两个升级程序的权限后,在任务计划程序里禁用WPS的计划任务,就再不会反弹了,不信你可以来打我😂

禁止登录WPS云功能(可选)

免费版的WPS集成了登录体验非常多各种云功能,这些功能肯定消耗不少的电脑资源,对于配置不太好的电脑,简直噩梦。所以,不需要这些花里胡哨的云功能,我们可以直接禁用。(目前暂未发现对本地文档编辑查看等功能有任何影响)

首先禁止 wpscloudsvr.exewpscloudlaunch.exe(禁止的方法同上)

# wpscloudsvr.exe 与 wpscloudlaunch.exe 默认的安装路径如下示例
C:\Users\<用户名>\AppData\Local\Kingsoft\WPS Office\<11.1.0.版本号>\office6\wpscloudsvr.exe
C:\Users\<用户名>\AppData\Local\Kingsoft\WPS Office\<11.1.0.版本号>\office6\wpscloudlaunch.exe

# 还有这个目录也要注意
C:\Program Files (x86)\Kingsoft\office6\wpscloudsvr.exe

# wpscenter.exe 这个我也把它禁止了。
C:\Users\<用户名>\AppData\Local\Kingsoft\WPS Office\<11.1.0.版本号>\office6\wpscenter.exe

然后禁止 yunkit-detect.exe

  • 这个程序是登录异常,引导用户重新下载安装WPS以修复此问题,所以必需禁止。

我们点击未登录的头像,会提示登录异常,接着点击 → 立即修复

WPS访客登录

此时打开任务管理器,即可发现 yunkit-detect.exe 进程

任务管理器 进程

然后右键点击此进程 yunkit-detect.exe打开文件所在的位置,即可快速找到并禁止它了。

设置NextCloud上的OnlyOffice应用需要注意的地方

最近更新了OnlyOffice6.4.2后没有发现有什么异常的地方,网页使用OnlyOffice打开文档表格等文件都一切正常,但是当我们在网页上使用OnlyOffice编辑文档或表格的时候,修改文档或表格的内容竟然无法同步到PC客户端。但是继续在线使用OnlyOffice浏览刚才编辑修改过的文档或表格却可以正常查看到已修改的内容,如果此时使用PC端打开该文档或表格编辑修改内容,那么将会出现非常奇怪的事情:此时使用在线OnlyOffice打开无法看见PC端修改的内容,PC端打开还是无法看见OnlyOffice修改的内容,NextCloud可以识别PC端已修改了该文件并在OnlyOffice打开该文件时创建了一个旧版本。文字实在很难描述清楚这奇怪的混乱。

最后找到问题了!我们需要谨慎的配置NextCloud上的OnlyOffice应用,如下图:

配置NextCloud里的OnlyOffice
配置NextCloud里的OnlyOffice

服务器设置

ONLYOFFICE Docs地址

https://office.sgtfz.top:8866

✓ 关闭证书校验(不安全) 必需勾选!

  • 可能是由于我更换了zeroSSL的原因

更多设置

用于服务器内部的ONLYOFFICE Docs的地址

https://office.sgtfz.top:8866

  • 这里填OnlyOffice服务器地址,不能填IP地址形式,我想应该与上面的ONLYOFFICE Docs地址一致。即使这个地址不填,也能正常使用。

用于ONLYOFFICE Docs内部请求的服务器的地址

http://192.168.33.8

  • 这里填NextCloud服务器地址,可以填IP地址,也可以填域名地址:https://cloud.sgtfz.top:8888/

按照上面正确配置后,在线使用OnlyOffice编辑文档或表格终于正常可以同步到本地了!

一开始我怀疑是OnlyOffice自动保存可能有延时造成的,实际自动保存这个功能挺好的,并不会延时。在线编辑文档完成后,只要关闭网页,自动保存随即生效。

OpenWrt 设备配置遇到的小问题

前几天在设置OpenWrt 21的时候,一不小心复位了br-lan,保存并应用了设置,当时没有发现什么问题。第二天起来发现没法上网了,然后进入PVE发现所有虚拟机都是正常运行的,最后发现是OpenWrt配置出问题了。

OpenWrt21设备配置页
OpenWrt21设备配置页

进入PVE,打开OpenWrt控制台,修改配置文件,但是忘记了配置文件是怎么配置的了,琢磨了一会修改为如下:

root@OpenWrt:~# cat /etc/config/network

config interface 'loopback'
        option device 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'fdd5:7efa:fa6d::/48'

config interface 'lan'
        option device 'eth0'
        option proto 'static'
        option netmask '255.255.255.0'
        option ip6assign '60'
        option ipaddr '192.168.33.1'

config interface 'wan'
        option device 'eth1'
        option proto 'pppoe'
        option username 'q宽带账号d'
        option password 'f宽带密码3'
        option ipv6 'auto'
        option metric '10'

config interface 'wan2'
        option device 'eth2'
        option proto 'pppoe'
        option username 'q宽带账号d'
        option password 'f宽带密码3'
        option ipv6 'auto'
        option metric '11'

网络可以正常了!!

但是少了br-lan这一行配置,最后还是还原了之前备份的OpenWrt,重新复原了之前的配置。如下

root@OpenWrt:~# cat /etc/config/network

config interface 'loopback'
        option device 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'fdd5:7efa:fa6d::/48'

config device
        option name 'br-lan'
        option type 'bridge'
        list ports 'eth0'

config interface 'lan'
        option device 'br-lan'
        option proto 'static'
        option netmask '255.255.255.0'
        option ip6assign '60'
        option ipaddr '192.168.33.1'

config interface 'wan'
        option device 'eth1'
        option proto 'pppoe'
        option username 'q宽带账号d'
        option password 'f宽带密码3'
        option ipv6 'auto'
        option metric '10'

config interface 'wan2'
        option device 'eth2'
        option proto 'pppoe'
        option username 'q宽带账号d'
        option password 'f宽带密码3'
        option ipv6 'auto'
        option metric '11'

暂不明白新版OpenWrt 21关于配置设备这儿,到底能配置什么功能,也没有时间去进一步的了解。但值得注意的是,不能随便复位这儿的配置😂

Proxmox VE 基本配置、操作、报错处理

仅针对我本人管理及使用Proxmox VE 7,经常用到的操作命令汇总,还有使用PVE所遇到的一些问题和解决方法。纯粹的个人兴趣爱好折腾,本人非专业人士,谨慎参考。本篇内容会随着不断的折腾,会持续不断的更新或修改完善,最重要的是整理与总结自己折腾过的东西或事情,让其比较整洁,或不那么容易被时间洗刷掉,方便日后在需要的时候,自己可以看懂就好。

安装好PVE后的最基本配置

仅根据自己的使用习惯对PVE系统最基本的配置,需要配置的地方不多,套用Debian的使用习惯来配置也OK

  • 配置vi编辑器,符合自己的使用习惯 /etc/vim/vimrc.tiny
  • 软件源修改为清华镜像源 /etc/apt/sources.list
  • 禁用PVE企业源 /etc/apt/sources.list.d/pve-enterprise.list
  • 添加PVE清华源 /etc/apt/sources.list.d/pve-no-subscription.list
  • CT模板源改为清华镜像源 /usr/share/perl5/PVE/APLInfo.pm

配置Vi编辑器:

#切换到root身份
su -

#使用nano编辑器修改Vi配置文件vimrc.tiny
nano /etc/vim/vimrc.tiny 
# 需要修改的内容如下
" set compatible
set nocompatible
set backspace=2

软件源修改为清华镜像源:

# 用vi编辑器修改Debian软件源sources.list
vi /etc/apt/sources.list

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free

禁用PVE企业源:

# 禁用PVE企业源
# 注释掉企业源即可。
vi /etc/apt/sources.list.d/pve-enterprise.list
# deb https://enterprise.proxmox.com/debian/pve bullseye pve-enterprise

添加PVE清华源

vi /etc/apt/sources.list.d/pve-no-subscription.list
# PVE清华源内容如下
deb https://mirrors.tuna.tsinghua.edu.cn/proxmox/debian/pve bullseye pve-no-subscription

CT模板源改为清华镜像源:

# CT Templates LXC模板镜像源,修改为清华镜像站
# 将 /usr/share/perl5/PVE/APLInfo.pm 文件中默认的源地址 http://download.proxmox.com
# 替换为 https://mirrors.tuna.tsinghua.edu.cn/proxmox 即可。
# 可以使用如下命令修改:
# 首先备份APLInfo.pm配置文件
cp /usr/share/perl5/PVE/APLInfo.pm /usr/share/perl5/PVE/APLInfo.pm_back

# 修改APLInfo.pm配置文件
sed -i 's|http://download.proxmox.com|https://mirrors.tuna.tsinghua.edu.cn/proxmox|g' /usr/share/perl5/PVE/APLInfo.pm
# 针对 /usr/share/perl5/PVE/APLInfo.pm 文件的修改,重启后生效。

软件源修改为国内的镜像源之后重启 pvedaemon 进程即可生效

systemctl restart pvedaemon.service

配置硬件直通

如果玩PVE不玩硬件直通,那是不是就失去了不少的乐趣呢?所以这个步骤也是不能省略的啦。下面按照步骤顺序操作,硬件直通会非常简单且顺利的完成。

1、主板必须开启vt-d

如果主板无法开启VT-D,真没什么搞头啦。

2、修改grub文件

我这只记录Intel的配置,因为我已经很久没有AMD的配置了,AMD即使性能再好我也不会心动啦。

vi /etc/default/grub
# GRUB_CMDLINE_LINUX_DEFAULT="quiet"做如下修改(intel的CPU)
GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on"

3、更新grub

update-grub

4、加载内核模块modules

vi /etc/modules
# 内容如下
vfio
vfio_iommu_type1
vfio_pci
vfio_virqfd

5、刷新initramfs

update-initramfs -u -k all

6、重启主机

7、验证是否开启iommu

dmesg | grep 'remapping'
# 执行命令后显示如下内容,说明开启成功
DMAR-IR: Enabled IRQ remapping in x2apic mode
# 但我的还多了一行,暂时未作处理。
# root@fzpve:~# dmesg | grep 'remapping'
# [    0.152366] DMAR-IR: Enabled IRQ remapping in xapic mode
# [    0.152367] x2apic: IRQ remapping doesn't support X2APIC mode
#此时输入命令
find /sys/kernel/iommu_groups/ -type l
#出现很多直通组,说明成功了。

8、PCI-E直通要求

完成了前面所有步骤之后,虚拟机 → 机器 → 必需要选 → q35

9、关于显卡直通

目前暂时不考虑直通显卡。

  • 据说新版的PVE7无需做驱动屏蔽,直接开启iommu之后,创建的虚拟机 机器q35,然后添加直通设备即可。
  • 关于直通显卡,在Windows上驱动报错43,尝试下载安装最新版的NVIDIA驱动试试吧!

还有更多直通的玩法,以后有时间再慢慢补全。

PVE存储添加、分区、操作、管理等命令

PVE添加存储涉及挺多东西的,反正我是捉摸不透的。存储类型有:文件级存储、块级存储。文件级存储又分别有许多不同的文件系统,块级存储也是如此。实在令人难以选择到底用哪种存储方案,应该要根据实际环境决定吧。我使用的是文件级存储的目录存储(dir)与块级存储的LVM精简池(lvmthin),因此以下相关命令与操作方法内容仅围绕这两个存储类型的折腾总结。

添加PVE存储步骤顺序:

  • 一、fdisk相关操作命令
  • 二、LVM相关操作命令
  • 三、PVE添加存储命令
  • 四、PVE删除存储命令

一、fdisk相关操作命令

fdisk 功能非常强大,我可是只用很少的一些功能,所以都是些简单的操作命令。

# fdisk -l 查看磁盘容量及分区等信息 ##################################
fdisk -l
# 操作示例:
# root@fzpve:~# fdisk -l
# Disk /dev/sdb: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
# Disk model: CT1000MX500SSD1 
# Units: sectors of 1 * 512 = 512 bytes
# Sector size (logical/physical): 512 bytes / 512 bytes
# I/O size (minimum/optimal): 512 bytes / 512 bytes

# Disk /dev/sda: 119.24 GiB, 128035676160 bytes, 250069680 sectors
# Disk model: SanDisk SDSSDHP1
# Units: sectors of 1 * 512 = 512 bytes
# Sector size (logical/physical): 512 bytes / 512 bytes
# I/O size (minimum/optimal): 512 bytes / 512 bytes
# Disklabel type: gpt
# Disk identifier: A91B586C-3EDC-4722-81A6-525F1F2A13FF

# Device       Start       End   Sectors   Size Type
# /dev/sda1       34      2047      2014  1007K BIOS boot
# /dev/sda2     2048   1050623   1048576   512M EFI System
# /dev/sda3  1050624 250069646 249019023 118.7G Linux LVM

# 使用fdisk进行管理磁盘 #########################################
fdisk /dev/sdc
# 创建GPT分区表
Command (m for help): g
# 确认无误,按w,保存并退出
Command (m for help): w
# 再次fdisk查看磁盘,已经是gpt分区表。
fdisk -l /dev/sdc
# root@fzpve:~# fdisk -l /dev/sdc
# Disk /dev/sdc: 2.73 TiB, 3000592982016 bytes, 5860533168 sectors
# Disk model: ST3000DM001-1ER1
# Units: sectors of 1 * 512 = 512 bytes
# Sector size (logical/physical): 512 bytes / 4096 bytes
# I/O size (minimum/optimal): 4096 bytes / 4096 bytes
# Disklabel type: gpt
# Disk identifier: E45D408D-E74D-7F40-B447-594B45C8ADFA

# 使用fdisk进行管理磁盘
fdisk /dev/sdc
# 按p查看分区参数
Command (m for help): p
# Disk /dev/sdc: 2.73 TiB, 3000592982016 bytes, 5860533168 sectors
# Disk model: ST3000DM001-1ER1
# Units: sectors of 1 * 512 = 512 bytes
# Sector size (logical/physical): 512 bytes / 4096 bytes
# I/O size (minimum/optimal): 4096 bytes / 4096 bytes
# Disklabel type: gpt
# Disk identifier: E45D408D-E74D-7F40-B447-594B45C8ADFA

# 按n进行分区 #####################################################
Command (m for help): n
# 创建第一个分区
Partition number (1-128, default 1): 1
# 第一个分区起始,默认2048
First sector (2048-5860533134, default 2048):
# 第一个分区分配200GB空间
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-5860533134, default 5860533134): +200G

# Created a new partition 1 of type 'Linux filesystem' and of size 200 GiB.

# 按n再次分区
Command (m for help): n
# 第二个分区
Partition number (2-128, default 2):
# 从第一个分区结尾,之后的剩余空间都分配给第二个分区。
First sector (419432448-5860533134, default 419432448):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (419432448-5860533134, default 5860533134):

# Created a new partition 2 of type 'Linux filesystem' and of size 2.5 TiB.

# 按t修改分区类型,分区2修改为lvm #####################################
Command (m for help): t
Partition number (1,2, default 2):
Partition type or alias (type L to list all): lvm

# Changed type of partition 'Linux filesystem' to 'Linux LVM'.

# 按t修改分区类型,分区1也修改为lvm
Command (m for help): t
Partition number (1,2, default 2): 1
Partition type or alias (type L to list all): lvm

# Changed type of partition 'Linux filesystem' to 'Linux LVM'.

# 按w保存并退出
Command (m for help): w
# The partition table has been altered.
# Calling ioctl() to re-read partition table.

使用fdisk分区的目的在于一个磁盘分两个区,一个作为块级存储LVM-thin,另一个作为文件级存储dir。使用fdisk将磁盘分区之后,还需配合LVM创建物理卷、卷组、逻辑卷、格式化等操作哟!

二、LVM相关操作命令

LVM相关的命令太多太复杂,下面相关命令仅针对我使用的两种存储类型:块级存储LVM-thin、文件级存储dir。

创建块级存储LVM-thin

创建块级存储LVM-thin,可以不用对磁盘进行分区,直接创建物理卷、卷组、thin-pool(精简池),即可完成。这样操作的话,貌似没有创建分区表,所以不是GPT分区表。

块级存储LVM-thin貌似有点不同,在创建thin-pool(精简池)的时候,需要留一点点空闲的空间,以便以后灵活操作。具体原因我也了解甚少,请自行查阅更多相关的资料。

# 创建物理卷PV ######################################
pvcreate /dev/sdb
# 操作示例:
# root@fzpve:~# pvcreate /dev/sdb
#   Physical volume "/dev/sdb" successfully created.

# 创建卷组VG ########################################
vgcreate vgssd /dev/sdb
# 操作示例:
# root@fzpve:~# vgcreate vgssd /dev/sdb
#   Volume group "vgssd" successfully created

# 查看物理卷 #############
pvs
# 操作示例:
# root@fzpve:~# pvs
#   PV         VG    Fmt  Attr PSize    PFree  
#   /dev/sda3  pve   lvm2 a--  <118.74g   4.74g
#   /dev/sdb   vgssd lvm2 a--   931.51g 931.51g

# 查看卷组 ###############
vgs

# 查看逻辑卷 #############
lvs  
# 查看指定卷组逻辑卷 ######
# lvs <VGNAME>
lvs vgssd

#或查看tdata,tmeta更多信息
lvs -a 

# 创建 thin-pool (精简池) ################################################
# lvcreate -L 100G -n <poolNAME> <VGNAME>
# lvconvert --type thin-pool <VGNAME>/<poolNAME>
lvcreate -L 920G -n ssdpool vgssd
lvconvert --type thin-pool vgssd/ssdpool
# 操作示例:
# root@fzpve:~# lvcreate -L 920G -n ssdpool vgssd
#   Logical volume "ssdpool" created.
# root@fzpve:~# lvconvert --type thin-pool vgssd/ssdpool
#   Thin pool volume with chunk size 512.00 KiB can address at most 126.50 TiB of data.
#   WARNING: Pool zeroing and 512.00 KiB large chunk size slows down thin provisioning.
#   WARNING: Consider disabling zeroing (-Zn) or using smaller chunk size (<512.00 KiB).
#   WARNING: Converting vgssd/ssdpool to thin pool's data volume with metadata wiping.
#   THIS WILL DESTROY CONTENT OF LOGICAL VOLUME (filesystem etc.)
# Do you really want to convert vgssd/ssdpool? [y/n]: y
#   Converted vgssd/ssdpool to thin pool.

扩容tmeta空间(可选,暂不清楚tmeta空间随着存储数据越来越多,是否会出现不够用的情况)

# 查看可用空间
vgs
# root@fzpve:~# vgs
#   VG    #PV #LV #SN Attr   VSize    VFree  
#   pve     1   3   0 wz--n- <118.74g   4.74g
#   vgssd   1   1   0 wz--n-  931.51g <11.29g

# 查看<poolNAME>_tmeta]空间
lvs -a
# root@fzpve:~# lvs -a
#   LV              VG    Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
#   data            pve   twi-a-tz-- <88.00g             0.00   1.61                            
#   [data_tdata]    pve   Twi-ao---- <88.00g                                                    
#   [data_tmeta]    pve   ewi-ao----   1.00g                                                    
#   [lvol0_pmspare] pve   ewi-------   1.00g                                                    
#   root            pve   -wi-ao----  20.00g                                                    
#   swap            pve   -wi-ao----   4.00g                                                    
#   [lvol0_pmspare] vgssd ewi------- 116.00m                                                    
#   ssdpool         vgssd twi-a-tz-- 920.00g             0.00   10.42                           
#   [ssdpool_tdata] vgssd Twi-ao---- 920.00g                                                    
#   [ssdpool_tmeta] vgssd ewi-ao---- 116.00m

# 扩容[<poolNAME>_tmeta]空间 ##############################################################
# lvextend --poolmetadatasize +900M <VGNAME>/<poolNAME>
lvextend --poolmetadatasize +140M vgssd/ssdpool
# 操作示例:
# root@fzpve:~# lvextend --poolmetadatasize +140M vgssd/ssdpool
#   Size of logical volume vgssd/ssdpool_tmeta changed from 116.00 MiB (29 extents) to 256.00 MiB (64 extents).
#   Logical volume vgssd/ssdpool_tmeta successfully resized.

# 查看<poolNAME>_tmeta]空间
lvs -a
# root@fzpve:~# lvs -a
#   LV              VG    Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
#   data            pve   twi-a-tz-- <88.00g             0.00   1.61                            
#   [data_tdata]    pve   Twi-ao---- <88.00g                                                    
#   [data_tmeta]    pve   ewi-ao----   1.00g                                                    
#   [lvol0_pmspare] pve   ewi-------   1.00g                                                    
#   root            pve   -wi-ao----  20.00g                                                    
#   swap            pve   -wi-ao----   4.00g                                                    
#   [lvol0_pmspare] vgssd ewi------- 256.00m                                                    
#   ssdpool         vgssd twi-a-tz-- 920.00g             0.00   6.45                            
#   [ssdpool_tdata] vgssd Twi-ao---- 920.00g                                                    
#   [ssdpool_tmeta] vgssd ewi-ao---- 256.00m 

创建文件级存储dir

方法与块级存储LVM-thin差不多,稍微有点点区别。在使用fdisk分区的时候已经创建了lvm类型的物理卷,因此下面直接创建卷组、逻辑卷、格式化、挂载。

# 创建卷组
vgcreate vgstdir /dev/sdc1

# 创建逻辑卷
lvcreate -l 100%FREE -n lvstdir vgstdir

# 格式化
mkfs.ext4 /dev/mapper/vgstdir-lvstdir

# 创建挂载目录
mkdir /st200g

# 挂载到目录
mount /dev/mapper/vgstdir-lvstdir /st200g

# 开机自动挂载
echo "/dev/mapper/vgstdir-lvstdir /st200g ext4 defaults 0 0" >> /etc/fstab

有没有发现文件级存储dir需要配置开机自动挂载,而块级存储不需要,是不是由于我添加文件级存储dir的方法不对?这个问题以后再说

重命名LVM逻辑卷

重点是重命名PVE里的虚拟磁盘,我使用的虚拟机磁盘格式为raw格式,有时候虚拟磁盘挂载到不同的虚拟机使用,需要将虚拟磁盘重命名。我发现虚拟磁盘也是LV逻辑卷,重命名虚拟磁盘就变得简单了。

# 重命名虚拟磁盘
# lvrename <VG_Name> <VM_Disk_Name> <New_VM_Disk_Name>
lvrename vgssd vm-101-disk-0 vm-103-disk-0
# 操作示例:
# root@fzpve:~# lvrename vgssd vm-101-disk-0 vm-103-disk-0
#   Renamed "vm-101-disk-0" to "vm-103-disk-0" in volume group "vgssd"

删除LVM逻辑卷、卷组、物理卷

  • 创建LVM顺序是:创建PV,创建VG,创建LV
  • 删除LVM顺序是:删除LV,删除VG,删除PV

thin-pool(精简池) 也是逻辑卷,下面是相关操作命令的例子

# 列出LV逻辑卷
lvdisplay
# 列出指定卷组上的LV逻辑卷
# lvdisplay <VGNAME>
lvdisplay vgssd

# 删除LV逻辑卷
lvremove <VGNAME>/<LV_Name>
# 或
lvremove /dev/<VG_Name>/<LV_Name>

# 列出VG卷组
vgdisplay

# 删除VG卷组
vgremove <VG_Name>

# 列出PV物理卷
pvdisplay

# 删除PV物理卷
# pvremove /dev/<sda,sdb,... 或 sda1,sda2,...>
pvremove /dev/sdc1

三、PVE添加存储

无论是块级存储LVM-thin,还是文件级存储dir,创建好后,都必需将其添加到PVE存储配置,这样PVE才能愉快的使用。

# 添加块级存储LVM-thin
# pvesm add lvmthin <STORAGE_ID> --vgname <VGNAME> --thinpool <poolNAME>
pvesm add lvmthin hdd-backup --vgname vghddst --thinpool hddstpool

# 添加目录存储dir
# pvesm add dir <STORAGE_ID> --path /<PATH>
pvesm add dir st200g-dir --path /st200g

# 查看PVE存储状态
pvesm status

四、PVE删除存储

删除PVE存储并不会删除任何数据,也不会断开连接或卸载任何东西,只是删除了存储配置。

# 简单的一句命令
# pvesm remove <STORAGE_ID>
pvesm remove hdd-backup

LXC容器使用及管理常用命令

目前我主要使用管理LXC的命令不多,也就这些。但不代表就只有这些!

可以打开服务器文档了解更多关于PCT命令

https://服务.器.IP.地址:8006/pve-docs/pct.1.html

# 查看容器的配置
# pct config <vmid> [OPTIONS]
pct config 103

# 进入指定容器
# pct enter <vmid>
pct enter 103

# 退出
exit

# 命令容器开机
# pct start <vmid>
pct start 103

# 命令容器关机
# pct shutdown <vmid>
pct shutdown 103

# 解锁容器
# pct unlock <vmid>
pct unlock 103

# 移除容器挂载点mp0,不是删除数据。移除后该磁盘配置变成未使用磁盘。
# 如果此时再删除未使用磁盘,那么就是删除数据了!谨慎操作!
# pct set <vmid> -delete mp[n]
pct set 103 -delete mp0

# 将虚拟磁盘挂载到指定容器,replicate=0 跳过复制。没有backup参数,默认不备份。
# pct set <vmid> -mp[n] <STORAGE_ID>:<VM-Disk-Name>,mp=/<PATH>,replicate=<0|1>
pct set 103 -mp0 ssd-data:vm-103-disk-0,mp=/site-data,replicate=0

# 建立快照
# pct snapshot <vmid> <snapname> [OPTIONS]
pct snapshot 103 debian11_snap_2021110101

# 查看快照
# pct listsnapshot <vmid>
pct listsnapshot 103

# 删除快照
# pct delsnapshot <vmid> <snapname> [OPTIONS]
pct delsnapshot 103 debian11_snap_2021110101

# 还原快照
# pct rollback <vmid> <snapname>
pct rollback 103 debian11_snap_2021110101

使用PVE遇到的问题与解决方法

第一次使用PVE,讲真的:从安装好使用到目前10多天了,非常稳定,好用,舒服,省心。但毕竟是刚刚与PVE相处,生疏尴尬肯定会有,需要慢慢去熟悉与磨合!

软件无法更新

软件包zfs-initramfszfs-zed无法更新

最近遇到软件无法更新的情况,实际上很早就发现有两个软件包zfs-initramfszfs-zed无法更新的,我一直都没有去理会。

但是,不解决这两个软件包的更新,后续的软件包也都无法更新了!

# 列出更新
apt list --upgradable
# root@fzpve:~# apt list --upgradable
# Listing... Done
# libldb2/stable-security 2:2.2.3-2~deb11u1 amd64 [upgradable from: 2:2.2.0-3.1]
# libsmbclient/stable-security 2:4.13.13+dfsg-1~deb11u2 amd64 [upgradable from: 2:4.13.5+dfsg-2]
# libwbclient0/stable-security 2:4.13.13+dfsg-1~deb11u2 amd64 [upgradable from: 2:4.13.5+dfsg-2]
# python3-ldb/stable-security 2:2.2.3-2~deb11u1 amd64 [upgradable from: 2:2.2.0-3.1]
# samba-common/stable-security 2:4.13.13+dfsg-1~deb11u2 all [upgradable from: 2:4.13.5+dfsg-2]
# samba-libs/stable-security 2:4.13.13+dfsg-1~deb11u2 amd64 [upgradable from: 2:4.13.5+dfsg-2]
# smbclient/stable-security 2:4.13.13+dfsg-1~deb11u2 amd64 [upgradable from: 2:4.13.5+dfsg-2]
# zfs-initramfs/bullseye-backports 2.0.6-1~bpo11+1 all [upgradable from: 2.0.5-pve1]
# zfs-zed/bullseye-backports 2.0.6-1~bpo11+1 amd64 [upgradable from: 2.0.5-pve1]
# 执行更新,失败!
apt upgrade
# root@fzpve:~# apt upgrade
# Reading package lists... Done
# Building dependency tree... Done
# Reading state information... Done
# Calculating upgrade... Done
# Some packages could not be installed. This may mean that you have
# requested an impossible situation or if you are using the unstable
# distribution that some required packages have not yet been created
# or been moved out of Incoming.
# The following information may help to resolve the situation:
# 下面提示缺少zfs-dkms软件包?######################################################################
# The following packages have unmet dependencies:
#  zfsutils-linux : Breaks: zfs-dkms (< 2.0.6-1~bpo11+1) but 2.0.3-9 is to be installed
# E: Broken packages
# ......

解决zfs-initramfszfs-zed无法更新

# 查看zfs-dkms软件包
apt list zfs-dkms
# root@fzpve:~# apt list zfs-dkms
# Listing... Done
# zfs-dkms/stable 2.0.3-9 all

# 安装zfs-dkms软件包
apt install zfs-dkms
# root@fzpve:~# apt install zfs-dkms
# Reading package lists... Done
# Building dependency tree... Done
# Reading state information... Done
# The following additional packages will be installed:
#   dctrl-tools dkms linux-compiler-gcc-10-x86 linux-headers-5.10.0-9-amd64 linux-headers-5.10.0-9-common
#   linux-headers-amd64 linux-kbuild-5.10 python3-distutils python3-lib2to3
# Suggested packages:
#   debtags menu debhelper
# Recommended packages:
#   zfs-zed zfsutils-linux
# The following packages will be REMOVED:
#   zfs-initramfs zfs-zed zfsutils-linux
# The following NEW packages will be installed:
#   dctrl-tools dkms linux-compiler-gcc-10-x86 linux-headers-5.10.0-9-amd64 linux-headers-5.10.0-9-common
#   linux-headers-amd64 linux-kbuild-5.10 python3-distutils python3-lib2to3 zfs-dkms
# 0 upgraded, 10 newly installed, 3 to remove and 7 not upgraded.
# Need to get 13.4 MB of archives.
# After this operation, 77.7 MB of additional disk space will be used.
# Do you want to continue? [Y/n] y
# ......

# 终于可以正常更新了
apt upgrade
# root@fzpve:~# apt upgrade
# Reading package lists... Done
# Building dependency tree... Done
# Reading state information... Done
# Calculating upgrade... Done
# The following packages will be upgraded:
#   libldb2 libsmbclient libwbclient0 python3-ldb samba-common samba-libs smbclient
# 7 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
# Need to get 7,121 kB of archives.
# After this operation, 28.7 kB of additional disk space will be used.
# Do you want to continue? [Y/n] y
# ......

zfs-initramfszfs-zed无法更新的问题处理完毕!实际这个问题一开始是没有的,因为我又不用zfs相关的东西,都怪我在PVE的WebUI管理页面点了更新,之后就发现这两个软件包无法更新!

我发现PVE管理页面WebUI点击更新他使用的命令是

apt-get dist-upgrade

这个命令更新有点危险,我觉得还是慎用。

Syslog日志报错与解决方法

RRD update error pmxcfs 相关报错

如果出现此报错,大部分日志都将会被此报错占领,一大片一大片的出现。

Oct 29 03:00:41 fzpve pmxcfs[1065]: [status] notice: RRD update error /var/lib/rrdcached/db/pve2-storage/fzpve/local-lvm: /var/lib/rrdcached/db/pve2-storage/fzpve/local-lvm: illegal attempt to update using time 1635447641 when last update time is 1635465615 (minimum one second step)
Oct 29 03:00:51 fzpve pmxcfs[1065]: [status] notice: RRD update error /var/lib/rrdcached/db/pve2-node/fzpve: /var/lib/rrdcached/db/pve2-node/fzpve: illegal attempt to update using time 1635447651 when last update time is 1635465615 (minimum one second step)
Oct 29 03:00:51 fzpve pmxcfs[1065]: [status] notice: RRD update error /var/lib/rrdcached/db/pve2-storage/fzpve/local-lvm: /var/lib/rrdcached/db/pve2-storage/fzpve/local-lvm: illegal attempt to update using time 1635447651 when last update time is 1635465615 (minimum one second step)
Oct 29 03:00:51 fzpve pmxcfs[1065]: [status] notice: RRD update error /var/lib/rrdcached/db/pve2-storage/fzpve/local: /var/lib/rrdcached/db/pve2-storage/fzpve/local: illegal attempt to update using time 1635447651 when last update time is 1635465615 (minimum one second step)

RRD update error pmxcfs 相关报错处理方法

# 直接复制执行以下命令,即可解决,具体原因未知。
cd /var/lib/;\
systemctl stop rrdcached;\
mv rrdcached rrdcached.bck;\
systemctl start rrdcached;\
systemctl restart pve-cluster;

postfix/qmgrpostfix/local 相关报错

Nov 01 18:50:08 fzpve postfix/qmgr[1184]: D441EC0E47: from=<root@fzpve.lan>, size=1006, nrcpt=1 (queue active)
Nov 01 18:50:08 fzpve postfix/local[131585]: error: open database /etc/aliases.db: No such file or directory
Nov 01 18:50:08 fzpve postfix/local[131585]: warning: hash:/etc/aliases is unavailable. open database /etc/aliases.db: No such file or directory
Nov 01 18:50:08 fzpve postfix/local[131585]: warning: hash:/etc/aliases: lookup of 'root' failed

postfix/qmgrpostfix/local 报错处理方法

# 打开PVE命令行
# 发现没有该文件 aliases.db
ls /etc/aliases*
# 执行
newaliases
# 再次 ls /etc/aliases*
# 已经生成了 aliases.db 文件,此问题已解决。
# root@fzpve:~# ls /etc/aliases*
# /etc/aliases  /etc/aliases.db

pvestatd 相关报错

Nov 02 21:56:03 fzpve pvestatd[1108]: command '/sbin/vgscan --ignorelockingfailure --mknodes' failed: exit code 5
Nov 02 21:56:13 fzpve pvestatd[1108]: command '/sbin/vgscan --ignorelockingfailure --mknodes' failed: exit code 5

pvestatd 相关报错处理方法

由于拆除了一个已经添加为PVE做存储的磁盘,会出现此报错。

移除已经不存在的PVE存储,解决此报错

# 移除PVE存储
# pvesm remove <storage>
# 移除PVE LVM-thin存储示例:
pvesm remove ssd-data

gpgconf 相关报错

# Nov 05 20:30:01 fzpve systemd[3346]: gpgconf: error running '/usr/lib/gnupg/scdaemon': probably not installed

gpgconf 相关报错处理方法

安装 scdaemon 即可解决此报错 apt install scdaemon

OpenWrt日志EXT4-fs、FAT-fs相关警告处理

安装OpenWrt 21非常的顺利,用着也非常的好用,没有发现有任何的问题,甚至连Bug都没有找到,非常满意,可能是我的使用要求不高的原因吧。

昨晚开启了防火墙的一项功能:

Routing/NAT Offloading
Experimental feature. Not fully compatible with QoS/SQM.
Software flow offloading ✔
Software based offloading for routing/NAT

EXT4-fs、FAT-fs相关的日志警告

所以今天有空就查看日志发现有一些警告,这不是开启Software flow offloading相关功能所造成的警告,而应该是与磁盘分区相关的:

Mon Nov  8 05:58:53 2021 user.notice kernel: [    3.890970] mount_root: mounting /dev/root
Mon Nov  8 05:58:53 2021 kern.warn kernel: [    3.892241] EXT4-fs (sda2): warning: mounting unchecked fs, running e2fsck is recommended
Mon Nov  8 05:58:53 2021 kern.info kernel: [    3.894635] EXT4-fs (sda2): re-mounted. Opts: (null)
Mon Nov  8 05:58:53 2021 kern.warn kernel: [    3.918690] FAT-fs (sda1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
Mon Nov  8 05:58:53 2021 user.warn kernel: [    3.926246] urandom-seed: Seeding with /etc/urandom.seed

首先处理这个问题

  • EXT4-fs (sda2): warning: mounting unchecked fs, running e2fsck is recommended
# 以下两条命令都无法执行!
umount /dev/sda2
e2fsck -a /dev/sda2

# 另一个方案,执行以下命令,重启自动检查磁盘并修复,我们试试
touch /forcefsck
# 重启后,没有任何效果,/forcefsck 这个文件依旧还存在,没用,删掉。

然后处理这个问题

  • FAT-fs (sda1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
# 分别执行以下命令,但是都没用!fsck: not found ,算了,这个问题暂时不处理先!
fsck -V /dev/sda1
fsck -a /dev/sda1

处理失败,没有解决任何问题,暂时先搁置这两个问题先,因为不影响使用,也不影响OpenWrt的启动速度,可以说没有任何影响。
由于OpenWrt运行着,是无法自身处理这两个问题的,应该需要借助其他方法来处理OpenWrt的磁盘。

EXT4-fs、FAT-fs相关的警告已解决

在夜深人静的时候关闭OpenWrt,依然是使用gparted-live-1.0.0-3-amd64.iso启动光盘来启动管理OpenWrt的磁盘。

使用分区软件gparted中文界面我没有找到什么有帮助的选项,有一项检查的功能选项,尝试检查sda1却报错,sda2检查通过。
貌似gparted这个分区软件的检查功能没有什么帮助,于是我发现这个启动盘还有命令行。打开命令行,尝试使用上面的修复方法,却有了意外的收获!

# 首先执行修复sda2,必需使用sudo执行命令
sudo e2fsck -a /dev/sda2
# 由于无法复制修复输出内容,所以我纯手打还原输出内容:
# rootfs: clean, 1822/272896 files, 23449/1337984 blocks

# 然后执行修复sda1
sudo fsck -V /dev/sda1
# fsck from util-linux 2.33.1
# [/usr/sbin/fsck. vfat (1) -- /dev/sda1] fsck. vfat /dev/sda1
# fsck. fat 4.1 (2017-01-24)
# /dev/sda1: 10 files, 2706/8167 clusters

# 最后执行修复sda1,怎么觉得和上面输出内容一样的?不管,反正找到的教程资料就这
sudo fsck -a /dev/sda1
# fsck from util-linux 2.33.1
# fsck. fat 4.1 (2017-01-24)
# /dev/sda1: 10 files, 2706/8167 clusters

执行完上面的命令,关机,删除CD-ROM,开机测试,EXT4-fs与FAT-fs相关的日志警告终于消失了!完美!

从中我们发现,在部署OpenWrt的时候,使用gparted-live-1.0.0-3-amd64.iso启动光盘在扩容OpenWrt磁盘这个环节,不要忘了扩容磁盘之后,需要执行以上3行命令!这样就不会在日志里出现目前这个EXT4-fs与FAT-fs相关的日志警告咯!

从 Hyper-V 迁移到 Proxmox VE 之后…

从 Windows2019 Hyper-V 迁移到 Proxmox VE 我不是将虚拟机通过转换磁盘格式的迁移,因为比较有用的东西所占用的磁盘空间并不多,1TB的容量足够存放。在没有迁移之前,我已经用另一台主机(MSI + E3-1230 V2)安装了Proxmox VE大概了解了2天左右,但如果只是这样大概的了解,始终还是不能解决需要面对的问题,但如果模拟迁移(纯粹的浪费时间),还不如直接迁移!

因此,这次的迁移是使用此主机(MSI + E3-1230 V2)作为中转存储资料备份,迁移的前、后都通过Rsync同步这些资料。

由于我也不懂怎么玩Docker,所以部署NextCloud与OnlyOffice这些都是手动一步一步的配置环境,好在Proxmox VE有LXC容器,真的方便好用不少!之前在Hyper-V虚拟机上的Debian所配置的环境,迁移过程耗时都在配置这些环境上了。(应该可以搞个脚本一键部署这些环境省不少时间,问题是我暂时不会搞)

2021年11月4日 20:00

才完善迁移到Proxmox VE后恢复到之前的所有环境。

对比两个不同平台感受:

Windows server2019 Hyper-V

VS

Proxmox VE

就使用下来的这几天我个人的主观感受

实话说:没有体验出明显的差别!

这也太令人失望的结果了!区别还是有一点点的:

  • PVE平台上整体的内存占用还真是比Windows server2019 Hyper-V平台低了不少!
  • PVE平台上VM里的OpenWrt使用网卡直通比Hyper-V上好点,但我没有测试条件,只是简单的对比 Ping OpenWrt 的延时,这样对比是不是很Low?
  • PVE平台上LXC容器运行Debian部署NextCloud的性能绝对比Hyper-V上的性能更好毋庸置疑的!
  • PVE平台上虚拟Windows我觉得与在Hyper-V上区别并不大!(是不是很意外,B85 + E3 1231V3拔掉显卡运行的哟!)如果插上显卡,是不是PVE优势与可玩性就有了?
  • PVE平台上匹配我那个山寨UPS,那可是差点让我拿锤子把UPS砸了的程度!
  • PVE平台 比 Windows 平台绝对的可玩性更高 → 前提是喜欢折腾!(PVE太多需要使用命令行操作,有时令人焦头烂额。而在Windows平台Hyper-V图形化操作简直舒服太多)

再多的使用对比体验,时间将会慢慢的为我们揭晓!

为什么那么折腾,然鹅体验却仅此而已,还那么费时费力的迁移到PVE平台?

因为Proxmox VE是开源的,可以自由免费的使用!而又不比Windows平台差甚至更好,这就够了。

下面是这几天迁移的收尾工作记录

从 Hyper-V 迁移到 Proxmox VE 收尾工作

2021-10-30 22:10

大头的工作已经基本完成了,剩下的细节工作,还是需要花不少的时间完善的。

  • 山寨UPS电源如何匹配PVE系统,遇到停电的情况,PVE主机正常关闭后UPS才断电。
  • 配置SSL证书同步到主机群。
  • 配置主备份HDD磁盘,完善Lsyncd实时同步,完善HDD磁盘自动保存3天内的快照。
  • 最后再考虑安排VM运行Windows,还有各种新一轮的PVE环境上的各种折腾!

山寨UPS电源如何匹配PVE系统

山克UPS只因你太便宜,159元,且有配套软件控制电脑关机。给我一个不买的理由?正好需要考虑一个UPS电源,好让我服务器上的小姐姐安居乐业。

配套的软件 ViewPower Network Edition

  • 在Windows系统上运行得还可以,只是安装配置的时候有点点坑。
  • 也有在Linux系统上的配套软件,但没有折腾过。

下载Linux系统的配套软件

  • 软件包名称:installViewPowerHTML_Linux_text_x86_64.tar.gz

先看看有没有安装教程!

我去!没有教程,压缩包里只有一个文件:

  • installViewPowerHTML_Linux_text_x64.bin

上传安装包到PVE上

这里有个简单的上传方法,就是直接在PVE的Web UI管理页面

  • 依次点击 local → CT模板 → 上传
  • 浏览选择installViewPowerHTML_Linux_text_x86_64.tar.gz

我们上传的文件在此:

root@fzpve:~# ls /var/lib/vz/template/cache/
debian-11-standard_11.0-1_amd64.tar.gz  installViewPowerHTML_Linux_text_x86_64.tar.gz

安装ViewPower

首先解压缩

# 解压
tar -xvf /var/lib/vz/template/cache/installViewPowerHTML_Linux_text_x86_64.tar.gz

root@fzpve:~# tar -xvf /var/lib/vz/template/cache/installViewPowerHTML_Linux_text_x86_64.tar.gz
# 解压到root目录下了
installViewPowerHTML_Linux_text_x64.bin

然后安装

./installViewPowerHTML_Linux_text_x64.bin
# 下面是安装的过程,一路回车完成
root@fzpve:~# ./installViewPowerHTML_Linux_text_x64.bin
Preparing to install...
Extracting the JRE from the installer archive...
Unpacking the JRE...
Extracting the installation resources from the installer archive...
Configuring the installer for this system's environment...
Launching installer...
Preparing CONSOLE Mode Installation...
......
Respond to each prompt to proceed to the next step in the installation.  If you
want to change something on a previous step, type 'back'.
You may cancel this installation at any time by typing 'quit'.
PRESS <ENTER> TO CONTINUE: 
========================================================================
Choose Install Folder
---------------------
Where would you like to install?
  Default Install Folder: /root/ViewPower
ENTER AN ABSOLUTE PATH, OR PRESS <ENTER> TO ACCEPT THE DEFAULT
      : 
========================================================================
Choose Link Location
--------------------
Where would you like to create links?
  ->1- Default: /root
    2- In your home folder
    3- Choose another location...
    4- Don't create links
ENTER THE NUMBER OF AN OPTION ABOVE, OR PRESS <ENTER> TO ACCEPT THE DEFAULT
      : 
========================================================================
Pre-Installation Summary
------------------------
Please Review the Following Before Continuing:
Product Name:
    ViewPower
Install Folder:
    /root/ViewPower
Link Folder:
    /root
Disk Space Information (for Installation Target): 
    Required:  187,736,834 bytes
    Available: 15,076,519,936 bytes
PRESS <ENTER> TO CONTINUE:
========================================================================
Installing...
-------------
===============================================================================
Installation Complete
---------------------
Congratulations. ViewPower has been successfully installed to:
   /root/ViewPower
PRESS <ENTER> TO EXIT THE INSTALLER:

安装完成,我还没有接UPS的USB线到PVE主机,不知有没有影响,现在去接上吧!

测试访问 http://192.168.33.3:15178/ViewPower

可以正常打开页面咯!

还需要一个步骤,安装runAutoStart.sh

/root/ViewPower/runAutoStart.sh

root@fzpve:~# /root/ViewPower/runAutoStart.sh
/root/ViewPower/runAutoStart.sh: line 39: sudo: command not found
/root/ViewPower/runAutoStart.sh: line 40: sudo: command not found

需要安装sudo

apt install sudo
# 然后再执行
root@fzpve:~# /root/ViewPower/runAutoStart.sh

完成,重启一下PVE主机。

配置与测试ViewPower

不行哟,如果用网页打开PVE管理页面的命令行,还能正常访问

http://192.168.33.3:15178/ViewPower

但如果关掉PVE管理页命令行,直接无法访问。即使正常进入ViewPower网页配置好,测试断电是否正常关机,TMD又害我人为非法断电了一次,又多一次伤害了PVE!

而且,貌似打开ssh会有一行报错提示

netstat: command not found

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sun Oct 31 00:06:06 2021
-bash: netstat: command not found
root@fzpve:~# apt install net-tools
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  net-tools
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 250 kB of archives.
After this operation, 1,015 kB of additional disk space will be used.
Get:1 https://mirrors.tuna.tsinghua.edu.cn/debian bullseye/main amd64 net-tools amd64 1.60+git20181103.0eebece-1 [250 kB]
Fetched 250 kB in 0s (602 kB/s)
Selecting previously unselected package net-tools.
(Reading database ... 42680 files and directories currently installed.)
Preparing to unpack .../net-tools_1.60+git20181103.0eebece-1_amd64.deb ...
Unpacking net-tools (1.60+git20181103.0eebece-1) ...
Setting up net-tools (1.60+git20181103.0eebece-1) ...
Processing triggers for man-db (2.9.4-2) ...
[1]+  Done                    /root/ViewPower/StartMain

好啦!好像不报错啦,但是,一次一次的令人无从配置,且没有希望的那种。

这死垃圾不兼容PVE,不搞了!!!

卸载!!!

时间都浪费在测试,一个晚上其实没多久的,发现这ViewPower垃圾软件非常耗资源,千万不要安装在PVE上!

直通USB给Windows使用UPS

2021-10-31

ViewPower自带的SSH远程关机无法登录服务器执行命令:

ssh_dispatch_run_fatal: Connection from 192.168.33.186 port 50121: DH GEX group out of range [preauth]

实在没法解决上面的报错,时间哗啦啦的浪费。

不得不使用ViewPower的关机前执行档案

C:\stop_pve.bat

但是在编写这个执行档案的批处理文件上,走了许多的弯路,浪费了太多的时间去测试!!谁叫我啥都不懂呢,最后还是在雷迪斯UPS官方网上找到了相关的教程

https://www.yuque.com/ladis/gfg4p3/vdscue

必需要安装配合PuTTy才能ssh连接服务器!批处理命令如下:

% 必须cd到putty的安装目录 %
cd C:\Program Files\PuTTY
% 使用 -i 调用私钥文件。pve-putty-key.ppk使用PuTTygen生成。%
plink -C -no-antispoof -i pve-putty-key.ppk -ssh root@192.168.33.3 "shutdown -h now"

但是必须远程登录Windows系统,这批处理才能起在关机前执行。如果登录系统,然后又注销退出的话,就无法正常执行该批处理命令。这些问题都TMD太折腾人咯,后来终于发现问题了!!

使用计划任务,在用户没有登录的情况下,依旧运行ViewPower程序,解决问题。但是还有一个问题,当我们的设备都在1分钟左右就正常的关闭后,UPS在2分钟后甚至4分钟后都依旧不关闭!

把批处理命令改为如下:解决了UPS不能自动关闭的问题!

% 必须cd到putty的安装目录 %
cd C:\Program Files\PuTTY
% 使用 -i 调用私钥文件。pve-putty-key.ppk使用PuTTygen生成。%
plink -C -no-antispoof -i pve-putty-key.ppk -ssh root@192.168.33.3 "shutdown -h +1"

关于这个山寨的UPS,我不已经不想太详细把折腾过程记录下来,貌似没有意义,有条件不要选择这个品牌的就不会存在这么多的问题。

上面的批处理命令,使用root账户,绝对是不推荐的,风险太高!

今天晚上的首要目标有:

2021-11-2 18:25

远程控制PVE关机的安全性问题:

已在 2021-11-2 20:56 完美解决了此问题!

  • 在PVE上创建普通用户
  • 授权普通用户关机的权限

这样可以解决Windows系统的各种无法预测的风险导致PVE的密钥或密码泄露风险。

# 创建用户
adduser sgtfz

# 编辑权限
visudo

# 仅允许普通用户组sgtfz,免密执行shutdown命令
%sgtfz ALL= NOPASSWD: /usr/sbin/shutdown

# 测试成功免密关机 `sudo /usr/sbin/shutdown -h +1`

# 重新使用PuTTygen生成密钥对,然后在sgtfz用户下新建.ssh免密目录及文件
# 创建目录.ssh
mkdir ~/.ssh
# 创建authorized_keys
vi ~/.ssh/authorized_keys
# 把公钥贴上,保存即可。
ssh-rsa AAAAB3NzaC**********************************************************************/hmaGsHlYQ== rsa-key-20211102

编辑Windows调用的关机命令批处理:

% 必须cd到putty的安装目录 %
cd C:\Program Files\PuTTY
% 使用 -i 调用私钥文件。pve-putty-key.ppk使用PuTTygen生成。%
plink -C -no-antispoof -i putty-key-pve-sgtfz.ppk -ssh sgtfz@192.168.33.3 "sudo /usr/sbin/shutdown -h +1"

TND编辑批处理命令的时候,忘了sudo /usr/sbin/shutdown,还是保留原来的shutdown -h +1
害我又让PVE非法断电了一次,累计测试这家伙都非法断电5次了!!!

终于成功了! 2021-11-2 20:56

至此UPS匹配终于完美完成了!这是很重要的一个环节,因为再好的配置,也经不起突然的停电!所以UPS还是必需得折腾好了,才有下面更多的美好的事情。

接下来?还有很多没有完善的!!!

但我觉得都已经不是问题了,可以慢慢的一步一步的去搞,没有时间就有了时间再搞。这几天已经连续严重熬夜,已经把自己彻底的摧残了!

有空再整理以下过程记录

  • PVE使用fdisk为一块磁盘分两个区:块级存储LVM-thin,目录存储dir
  • 安装与配置OnlyOffice(手动挡)

还有一件事情没有完成的:

  • 命令行实现自动创建指定磁盘快照,并保留3天内的快照。

Windows10 补丁又导致局域网共享打印机无法打印了

今天又遇到局域网共享打印机无法打印的问题!

共享主机是Windows7 x64系统,局域网中所有Windows7系统都能正常使用打印机,唯独Windows10那台电脑无法使用共享的打印机。一开始折腾了很长时间没有找到原因,后来重装系统打印机可以正常使用了,但是由于安装了更新之后发现打印机又不能正常使用了!这才发现是由于Windows10更新补丁造成的问题!

Windows10 LTSC 2019 卸载如下补丁(其他版本的补丁名称暂时未知)

  • 补丁名:KB5006672 (貌似为Windows10月更新补丁)

这问题可能只出现在Windows10使用共享打印机(共享主机为Windows7系统)才会表现出来!

把更新补丁卸载之后,共享打印机终于正常使用了!哎 … !Windows10关于共享以及共享打印机的bug真的太多!这还能让人愉快的办公吗?卸载一个更新有时要等半小时!

以下是关于Windows10共享打印故障的记录:

从 Hyper-V 迁移到 Proxmox VE 过程记录

备份OpenWrt各种配置

  • 已完成各种配置的截图备份

备份 Hyper-V 服务器的各种环境

  • NextCloud与WordPress数据及数据库已备份及同步完成
  • rsync -av --delete /my-data/www/html/ root@192.168.33.131:/data-backup
  • 配置文件目录备份已完成
  • 已备份目录/etc/apache2
  • 已备份目录/etc/mysql
  • 已备份目录/etc/lsyncd
  • 已备份目录/etc/php/7.4
  • 计划任务配置已备份

修改测试主机的IP地址

  • 为主服务器让路,腾出我这个IP地址
  • 修改配置文件 vi /etc/network/interfaces
  • 由原来的192.168.33.3修改为192.168.33.87,并成功完成修改与访问。

400GB多的视频文件在NTFS分区上,该如何处理?

  • 拷贝了一部分存档,剩余的一些不喜欢的就丢弃了。

正式开始了

准时在2021年10月28日21:30左右 开始了

关闭Windows server 2019主机

接着使用路由器替换了OpenWrt,网络继续正常工作

修改B85主板的 PCIe 1x 接口

也就是爆PCIe 1x插槽的菊花,目的是插入PCIe 16x的显卡。

这B85主板配合E3 1231 V3最神奇的地方是: 我可以不插显卡也能够正常开机并进入系统!

我的另一个Z68配合E3 1230 V2不插显卡,死活不能正常开机启动系统!

改造这个PCIe 1x插槽是为了方便以后如果想要玩显卡直通!虽然只有1x的速度,但直通显卡的目的又不是为了游戏。

不玩显卡直通的情况下,我直接拔掉显卡运行,起码也能省一点点的电。

  • 使用小刀爆菊花浪费了不少的时间,由于华硕的PCIe塑料太TM硬了,
  • 只爆了一点点实在搞不定,最后使用电络铁,终于把 PCIe 1x 插槽的菊花完爆了,
  • 顺利插入PCIe 16x显卡,主机正常启动并显示了,完美!

时间已经来到了10:30左右.

开始为Windows server 2019做一个Ghost备份吧,C盘40GB多左右,极限压缩模式真的非常慢

  • 做一个备份吧,万一PVE严重翻车,还能快速恢复到Hyper-V
  • 在Windows server 2019的备份盘暂时不挂载到PVE上,用另一个已同步好资料的磁盘挂载到PVE
  • 在PVE成功完成后,将NextCloud的资料恢复到SSD上之后,再考虑格式化前任备份盘为LVM-thin
  • 在这等待Ghost备份的时间里,又想到了UPS,该如何匹配PVE呢?又是一个头疼的问题

Windows server 2019 系统盘备份完成 时间 23:20

  • 将C盘的Ghost备份25GB拷贝至移动磁盘,30M/S的速度太慢了,这垃圾移动硬盘!
  • 面对之前在Hyper-V上运行的Win7系统,里面下载了不少的电影,丢弃吗?
  • 纠结,从Windows到Linux的迁移,文件系统不同,烦。

下面开始安装PVE

开始安装PVE 23:38

PVE安装完成 2021年10月29日 0:00

开始配置PVE

最基础的配置

  • vi编辑器 /etc/vim/vimrc.tiny
  • 软件源修改为清华镜像源 vi /etc/apt/sources.list
  • 禁用PVE企业源 vi /etc/apt/sources.list.d/pve-enterprise.list
  • CT模板改为清华镜像站/usr/share/perl5/PVE/APLInfo.pm

更新系统

apt update
apt upgrade
reboot

添加SSD硬盘为LVM-thin

  • 由于SSD之前是在Windows上使用的,所以直接在PVE的WebUI管理界面 ⇢ 磁盘 ⇢ 擦除磁盘

为SSD分区

root@fzpve:~# fdisk -l
Disk /dev/sdb: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: CT1000MX500SSD1 
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sda: 119.24 GiB, 128035676160 bytes, 250069680 sectors
Disk model: SanDisk SDSSDHP1
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: A91B586C-3EDC-4722-81A6-525F1F2A13FF

Device       Start       End   Sectors   Size Type
/dev/sda1       34      2047      2014  1007K BIOS boot
/dev/sda2     2048   1050623   1048576   512M EFI System
/dev/sda3  1050624 250069646 249019023 118.7G Linux LVM


Disk /dev/mapper/pve-swap: 4 GiB, 4294967296 bytes, 8388608 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/pve-root: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

# 创建物理卷PV (volume)
pvcreate /dev/sdb

root@fzpve:~# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created.

# 创建卷组VG (group)
vgcreate vgssd /dev/sdb

root@fzpve:~# vgcreate vgssd /dev/sdb
  Volume group "vgssd" successfully created

# 查看SSD可用空间
root@fzpve:~# pvs
  PV         VG    Fmt  Attr PSize    PFree  
  /dev/sda3  pve   lvm2 a--  <118.74g   4.74g
  /dev/sdb   vgssd lvm2 a--   931.51g 931.51g

# 创建 thin-pool (精简池),确定建立920GB,剩余的作为PFree空间
# lvcreate -L 100G -n <poolNAME> <VGNAME>
# lvconvert --type thin-pool <VGNAME>/<poolNAME>
lvcreate -L 920G -n ssdpool vgssd
lvconvert --type thin-pool vgssd/ssdpool

root@fzpve:~# lvcreate -L 920G -n ssdpool vgssd
  Logical volume "ssdpool" created.
root@fzpve:~# lvconvert --type thin-pool vgssd/ssdpool
  Thin pool volume with chunk size 512.00 KiB can address at most 126.50 TiB of data.
  WARNING: Pool zeroing and 512.00 KiB large chunk size slows down thin provisioning.
  WARNING: Consider disabling zeroing (-Zn) or using smaller chunk size (<512.00 KiB).
  WARNING: Converting vgssd/ssdpool to thin pool's data volume with metadata wiping.
  THIS WILL DESTROY CONTENT OF LOGICAL VOLUME (filesystem etc.)
Do you really want to convert vgssd/ssdpool? [y/n]: y
  Converted vgssd/ssdpool to thin pool.

扩容tmeta空间:

# 查看SSD可用空间
root@fzpve:~# vgs
  VG    #PV #LV #SN Attr   VSize    VFree  
  pve     1   3   0 wz--n- <118.74g   4.74g
  vgssd   1   1   0 wz--n-  931.51g <11.29g
# 查看<poolNAME>_tmeta]空间
root@fzpve:~# lvs -a
  LV              VG    Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  data            pve   twi-a-tz-- <88.00g             0.00   1.61                            
  [data_tdata]    pve   Twi-ao---- <88.00g                                                    
  [data_tmeta]    pve   ewi-ao----   1.00g                                                    
  [lvol0_pmspare] pve   ewi-------   1.00g                                                    
  root            pve   -wi-ao----  20.00g                                                    
  swap            pve   -wi-ao----   4.00g                                                    
  [lvol0_pmspare] vgssd ewi------- 116.00m                                                    
  ssdpool         vgssd twi-a-tz-- 920.00g             0.00   10.42                           
  [ssdpool_tdata] vgssd Twi-ao---- 920.00g                                                    
  [ssdpool_tmeta] vgssd ewi-ao---- 116.00m    

# 扩容[<poolNAME>_tmeta]空间
# lvextend --poolmetadatasize +900M <VGNAME>/<poolNAME>
lvextend --poolmetadatasize +140M vgssd/ssdpool

root@fzpve:~# lvextend --poolmetadatasize +140M vgssd/ssdpool
  Size of logical volume vgssd/ssdpool_tmeta changed from 116.00 MiB (29 extents) to 256.00 MiB (64 extents).
  Logical volume vgssd/ssdpool_tmeta successfully resized.
# 查看<poolNAME>_tmeta]空间
root@fzpve:~# lvs -a
  LV              VG    Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  data            pve   twi-a-tz-- <88.00g             0.00   1.61                            
  [data_tdata]    pve   Twi-ao---- <88.00g                                                    
  [data_tmeta]    pve   ewi-ao----   1.00g                                                    
  [lvol0_pmspare] pve   ewi-------   1.00g                                                    
  root            pve   -wi-ao----  20.00g                                                    
  swap            pve   -wi-ao----   4.00g                                                    
  [lvol0_pmspare] vgssd ewi------- 256.00m                                                    
  ssdpool         vgssd twi-a-tz-- 920.00g             0.00   6.45                            
  [ssdpool_tdata] vgssd Twi-ao---- 920.00g                                                    
  [ssdpool_tmeta] vgssd ewi-ao---- 256.00m 

为PVE添加存储:

# 使用刚才创建的 thin-pool (精简池)
# pvesm add lvmthin <STORAGE_ID> --vgname <VGNAME> --thinpool <poolNAME>
pvesm add lvmthin ssd-data --vgname vgssd --thinpool ssdpool

# 检查存储状态
pvesm status

root@fzpve:~# pvesm status
Name             Type     Status           Total            Used       Available        %
local             dir     active        20466256         2617908        16783388   12.79%
local-lvm     lvmthin     active        92270592               0        92270592    0.00%
ssd-data      lvmthin     active       964689920               0       964689920    0.00%

硬件直通配置

时间来到了 00:55

硬件直通需要以下几个步骤的配置

  • 修改grub文件
  • 更新grub
  • 加载内核模块modules
  • 刷新initramfs
  • 然后重启主机
  • 验证是否开启iommu

修改grub文件:

   vi /etc/default/grub
   # GRUB_CMDLINE_LINUX_DEFAULT="quiet"做如下修改(intel的CPU)
   GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on"

更新grub:

update-grub

root@fzpve:~# update-grub
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.11.22-4-pve
Found initrd image: /boot/initrd.img-5.11.22-4-pve
Found memtest86+ image: /boot/memtest86+.bin
Found memtest86+ multiboot image: /boot/memtest86+_multiboot.bin
Adding boot menu entry for EFI firmware configuration
done

加载内核模块modules:

   vi /etc/modules
   # 内容如下
   vfio
   vfio_iommu_type1
   vfio_pci
   vfio_virqfd

刷新initramfs:

update-initramfs -u -k all

root@fzpve:~# update-initramfs -u -k all
update-initramfs: Generating /boot/initrd.img-5.11.22-4-pve
Running hook script 'zz-proxmox-boot'..
Re-executing '/etc/kernel/postinst.d/zz-proxmox-boot' in new private mount namespace..
No /etc/kernel/proxmox-boot-uuids found, skipping ESP sync.

然后重启主机:

reboot

验证是否开启iommu:

dmesg | grep 'remapping'

root@fzpve:~# dmesg | grep 'remapping'
[    0.152366] DMAR-IR: Enabled IRQ remapping in xapic mode
[    0.152367] x2apic: IRQ remapping doesn't support X2APIC mode
  • 执行命令后显示如下内容,说明开启成功 DMAR-IR: Enabled IRQ remapping in x2apic mode
  • 此时输入命令 find /sys/kernel/iommu_groups/ -type l 出现很多直通组,说明成功了
root@fzpve:~# find /sys/kernel/iommu_groups/ -type l
/sys/kernel/iommu_groups/7/devices/0000:00:1c.0
/sys/kernel/iommu_groups/5/devices/0000:00:1a.0
/sys/kernel/iommu_groups/3/devices/0000:00:16.0
/sys/kernel/iommu_groups/11/devices/0000:02:00.0
/sys/kernel/iommu_groups/1/devices/0000:00:01.0
/sys/kernel/iommu_groups/1/devices/0000:01:00.0
/sys/kernel/iommu_groups/1/devices/0000:01:00.1
/sys/kernel/iommu_groups/8/devices/0000:00:1c.1
/sys/kernel/iommu_groups/6/devices/0000:00:1b.0
/sys/kernel/iommu_groups/4/devices/0000:00:19.0
/sys/kernel/iommu_groups/12/devices/0000:03:00.0
/sys/kernel/iommu_groups/12/devices/0000:03:00.1
/sys/kernel/iommu_groups/2/devices/0000:00:14.0
/sys/kernel/iommu_groups/10/devices/0000:00:1f.2
/sys/kernel/iommu_groups/10/devices/0000:00:1f.0
/sys/kernel/iommu_groups/10/devices/0000:00:1f.3
/sys/kernel/iommu_groups/0/devices/0000:00:00.0
/sys/kernel/iommu_groups/9/devices/0000:00:1d.0

配置直通完成 时间来到了 01:09

VM虚拟机部署OpenWrt

首先要建立一个VM虚拟机 硬件配置暂定如下:

  • 内存 512MB
  • 处理器 2核心 [host,flags=+aes]
  • BIOS OVMF(UEFI)
  • 显示 标准VGA(安装配置完成后,最后选择无显示)
  • 机器 q35(最新)
  • SCSI控制器 VirtIO SCSI
  • 硬盘随便添加一个1G的,然后需要使用img镜像导入的磁盘,之后要删除这个硬盘的。
  • 网络设备(net0) 随便添加一个网卡,之后要删除,配置直通网卡的哟。
  • EFI磁盘 这个必须要且不能删除。

然后下载OpenWrt

# 直接在PVE上下载即可
wget https://downloads.openwrt.org/releases/21.02.1/targets/x86/64/openwrt-21.02.1-x86-64-generic-ext4-combined-efi.img.gz

root@fzpve:~# sha256sum openwrt-21.02.1-x86-64-generic-ext4-combined-efi.img.gz > openwrt-21.02.1-x86-64-generic-ext4-combined-efi.img.gz.sha256sum
root@fzpve:~# cat openwrt-21.02.1-x86-64-generic-ext4-combined-efi.img.gz.sha256sum 
005ab565649e10fec4220ee6cc96f2b35a89c01abf2a6d79ccc990b2f39b476a  openwrt-21.02.1-x86-64-generic-ext4-combined-efi.img.gz

# 解压
gzip -d openwrt-21.02.0-x86-64-generic-ext4-combined-efi.img.gz

# 将img磁盘直接导入为VM虚拟磁盘,vmid根据现实灵活修改哟。
# qm importdisk <vmid> <source> <storage> [OPTIONS]
qm importdisk 100 /root/openwrt-21.02.1-x86-64-generic-ext4-combined-efi.img local-lvm

root@fzpve:~# qm importdisk 100 /root/openwrt-21.02.1-x86-64-generic-ext4-combined-efi.img local-lvm
importing disk '/root/openwrt-21.02.1-x86-64-generic-ext4-combined-efi.img' to VM 100 ...
  Rounding up size to full physical extent 124.00 MiB
  Logical volume "vm-100-disk-2" created.
transferred 0.0 B of 120.5 MiB (0.00%)
transferred 2.0 MiB of 120.5 MiB (1.66%)
transferred 4.0 MiB of 120.5 MiB (3.32%)
transferred 6.0 MiB of 120.5 MiB (4.98%)
transferred 50.0 MiB of 120.5 MiB (41.48%)
......
transferred 104.0 MiB of 120.5 MiB (86.29%)
transferred 106.0 MiB of 120.5 MiB (87.94%)
transferred 108.0 MiB of 120.5 MiB (89.60%)
transferred 110.0 MiB of 120.5 MiB (91.26%)
transferred 112.0 MiB of 120.5 MiB (92.92%)
transferred 114.0 MiB of 120.5 MiB (94.58%)
transferred 120.5 MiB of 120.5 MiB (100.00%)
Successfully imported disk as 'unused0:local-lvm:vm-100-disk-2'

最后编辑虚拟机配置

  • 硬件
  • 将之前创建时的网卡删除,添加PCI设备,先添加一个直通网口作为LAN,之后安装好后再添加WAN口
  • 将之前创建虚拟机时的磁盘删除,添加刚才命令导入的虚拟磁盘。
  • 剩下的默认吧,检查配置无误后进入下一环节
  • 选项
  • 开机自动启动 是
  • OS类型 Linux 5.x – 2.6 Kernel
  • 引导顺序 scsi0 (特别注意这必须选导入的OpenWrt磁盘)
  • 剩下的项目默认吧。

82576-0直通作为LAN口

上传gparted-live-1.0.0-3-amd64.iso进行调整OpenWrt分区大小

因为OpenWrt官方镜像默认的根分区只有100MB左右,我们需要将其扩容一下用起来更舒服些。

已完成扩容,关闭虚拟机。

删除 CD-ROM

再到选项选择引导顺序为 scsi0

开启虚拟机测试OpenWRT

我发现双网口的82576网卡直通的时候,不分0或1,都同时直通给OpenWrt的!无法只直通一个口。

这可能是PVE的硬件直通配置还漏了哪个步骤,但已经够用了,所以不纠结这问题先。

时间来到了 2:12

关机,安装硬盘,拷贝数据!!

时间来到了 3:08

发现PVE日志syslog 许多报错

Oct 29 03:00:41 fzpve pmxcfs[1065]: [status] notice: RRD update error /var/lib/rrdcached/db/pve2-storage/fzpve/local-lvm: /var/lib/rrdcached/db/pve2-storage/fzpve/local-lvm: illegal attempt to update using time 1635447641 when last update time is 1635465615 (minimum one second step)
Oct 29 03:00:51 fzpve pmxcfs[1065]: [status] notice: RRD update error /var/lib/rrdcached/db/pve2-node/fzpve: /var/lib/rrdcached/db/pve2-node/fzpve: illegal attempt to update using time 1635447651 when last update time is 1635465615 (minimum one second step)
Oct 29 03:00:51 fzpve pmxcfs[1065]: [status] notice: RRD update error /var/lib/rrdcached/db/pve2-storage/fzpve/local-lvm: /var/lib/rrdcached/db/pve2-storage/fzpve/local-lvm: illegal attempt to update using time 1635447651 when last update time is 1635465615 (minimum one second step)
Oct 29 03:00:51 fzpve pmxcfs[1065]: [status] notice: RRD update error /var/lib/rrdcached/db/pve2-storage/fzpve/local: /var/lib/rrdcached/db/pve2-storage/fzpve/local: illegal attempt to update using time 1635447651 when last update time is 1635465615 (minimum one second step)
Oct 29 03:01:00 fzpve systemd[1]: Starting Proxmox VE replication runner...
Oct 29 03:01:00 fzpve systemd[1]: pvesr.service: Succeeded.
Oct 29 03:01:00 fzpve systemd[1]: Finished Proxmox VE replication runner.
Oct 29 03:01:01 fzpve pmxcfs[1065]: [status] notice: RRD update error /var/lib/rrdcached/db/pve2-node/fzpve: /var/lib/rrdcached/db/pve2-node/fzpve: illegal attempt to update using time 1635447661 when last update time is 1635465615 (minimum one second step)
Oct 29 03:01:02 fzpve pmxcfs[1065]: [status] notice: RRD update error /var/lib/rrdcached/db/pve2-storage/fzpve/local: /var/lib/rrdcached/db/pve2-storage/fzpve/local: illegal attempt to update using time 1635447661 when last update time is 1635465615 (minimum one second step)
Oct 29 03:01:02 fzpve pmxcfs[1065]: [status] notice: RRD update error /var/lib/rrdcached/db/pve2-storage/fzpve/local-lvm: /var/lib/rrdcached/db/pve2-storage/fzpve/local-lvm: illegal attempt to update using time 1635447661 when last update time is 1635465615 (minimum one second step)
Oct 29 03:01:11 fzpve pmxcfs[1065]: [status] notice: RRD update error /var/lib/rrdcached/db/pve2-node/fzpve: /var/lib/rrdcached/db/pve2-node/fzpve: illegal attempt to update using time 1635447671 when last update time is 1635465615 (minimum one second step)
Oct 29 03:01:31 fzpve pmxcfs[1065]: [status] notice: RRD update error /var/lib/rrdcached/db/pve2-storage/fzpve/local: opening '/var/lib/rrdcached/db/pve2-storage/fzpve/local': No such file or directory
Oct 29 03:01:31 fzpve pmxcfs[1065]: [status] notice: RRD create error /var/lib/rrdcached/db/pve2-storage/fzpve/ssd-data: Cannot create temporary file
Oct 29 03:01:31 fzpve pmxcfs[1065]: [status] notice: RRD update error /var/lib/rrdcached/db/pve2-storage/fzpve/ssd-data: opening '/var/lib/rrdcached/db/pve2-storage/fzpve/ssd-data': No such file or directory
Oct 29 03:01:31 fzpve pmxcfs[1065]: [status] notice: RRD create error /var/lib/rrdcached/db/pve2-storage/fzpve/local-lvm: Cannot create temporary file
Oct 29 03:01:31 fzpve pmxcfs[1065]: [status] notice: RRD update error /var/lib/rrdcached/db/pve2-storage/fzpve/local-lvm: opening '/var/lib/rrdcached/db/pve2-storage/fzpve/local-lvm': No such file or directory
Oct 29 03:01:37 fzpve systemd[1]: Starting LSB: start or stop rrdcached...
Oct 29 03:01:37 fzpve rrdcached[7353]: rrdcached started.
Oct 29 03:01:37 fzpve systemd[1]: Started LSB: start or stop rrdcached.
Oct 29 03:01:45 fzpve systemd[1]: Stopping The Proxmox VE cluster filesystem...
Oct 29 03:01:45 fzpve pmxcfs[1065]: [main] notice: teardown filesystem
Oct 29 03:01:46 fzpve systemd[4074]: etc-pve.mount: Succeeded.
Oct 29 03:01:46 fzpve systemd[1]: etc-pve.mount: Succeeded.
Oct 29 03:01:47 fzpve pmxcfs[1065]: [main] notice: exit proxmox configuration filesystem (0)
Oct 29 03:01:47 fzpve systemd[1]: pve-cluster.service: Succeeded.
Oct 29 03:01:47 fzpve systemd[1]: Stopped The Proxmox VE cluster filesystem.
Oct 29 03:01:47 fzpve systemd[1]: pve-cluster.service: Consumed 2.237s CPU time.
Oct 29 03:01:47 fzpve systemd[1]: Starting The Proxmox VE cluster filesystem...
Oct 29 03:01:48 fzpve systemd[1]: Started The Proxmox VE cluster filesystem.
Oct 29 03:01:48 fzpve systemd[1]: Condition check resulted in Corosync Cluster Engine being skipped.
Oct 29 03:02:00 fzpve systemd[1]: Starting Proxmox VE replication runner...
Oct 29 03:02:00 fzpve systemd[1]: pvesr.service: Succeeded.
Oct 29 03:02:00 fzpve systemd[1]: Finished Proxmox VE replication runner.

执行如下命令后终于消停了

# 这是错误的命令路径,这个方法失败
root@fzpve:~# cd /var/lib/rrdcached/
root@fzpve:/var/lib/rrdcached# systemctl stop rrdcached
root@fzpve:/var/lib/rrdcached# mv rrdcached rrdcached.bck
mv: cannot stat 'rrdcached': No such file or directory
# 这才是正确的方法
root@fzpve:/var/lib/rrdcached# cd /var/lib/
root@fzpve:/var/lib# systemctl stop rrdcached
root@fzpve:/var/lib# mv rrdcached rrdcached.bck
root@fzpve:/var/lib# systemctl start rrdcached
root@fzpve:/var/lib# systemctl restart pve-cluster

修改Openwrt软件源为清华镜像站:

# openwrt
#src/gz openwrt_core https://downloads.openwrt.org/releases/21.02.1/targets/x86/64/packages
#src/gz openwrt_base https://downloads.openwrt.org/releases/21.02.1/packages/x86_64/base
#src/gz openwrt_luci https://downloads.openwrt.org/releases/21.02.1/packages/x86_64/luci
#src/gz openwrt_packages https://downloads.openwrt.org/releases/21.02.1/packages/x86_64/packages
#src/gz openwrt_routing https://downloads.openwrt.org/releases/21.02.1/packages/x86_64/routing
#src/gz openwrt_telephony https://downloads.openwrt.org/releases/21.02.1/packages/x86_64/telephony

# tsinghua
src/gz openwrt_core https://mirrors.tuna.tsinghua.edu.cn/openwrt/releases/21.02.1/targets/x86/64/packages
src/gz openwrt_base https://mirrors.tuna.tsinghua.edu.cn/openwrt/releases/21.02.1/packages/x86_64/base
src/gz openwrt_luci https://mirrors.tuna.tsinghua.edu.cn/openwrt/releases/21.02.1/packages/x86_64/luci
src/gz openwrt_packages https://mirrors.tuna.tsinghua.edu.cn/openwrt/releases/21.02.1/packages/x86_64/packages
src/gz openwrt_routing https://mirrors.tuna.tsinghua.edu.cn/openwrt/releases/21.02.1/packages/x86_64/routing
src/gz openwrt_telephony https://mirrors.tuna.tsinghua.edu.cn/openwrt/releases/21.02.1/packages/x86_64/telephony

准备下载CT模板

却发现只有debian10的模板

执行已下命令更新模板

pveam update

即可正常刷出debian11了

CT已经安装好了,基本的配置完成,没有安装AMP环境。

时间已经来到 3:50

好累啊!

关机,然后几分钟后再开,看看PVE日志是否有报错了先吧。

终于正常了,syslog没有报错信息了。

挂载备份磁盘到CT容器 拷贝数据

挂载WD2T磁盘到PVE存储

pvesm add lvmthin wd-backup --vgname vgwd2t --thinpool databackup

在LXC容器添加挂载点

需要修改配置文件进行添加,因为我已经忘记了虚拟磁盘的大小,或是命令有问题吧!

arch: amd64
cores: 4
features: nesting=1
hostname: Debian11-NC
memory: 5120
mp0: wd-backup:vm-100-disk-0,mp=/data-backup,replicate=0,ro=1,size=1000G
net0: name=eth0,bridge=vmbr0,firewall=1,gw=192.168.33.1,hwaddr=0A:FD:83:CE:3B:5A,ip=192.168.33.5/24,type=veth
ostype: debian
rootfs: local-lvm:vm-101-disk-0,size=8G
swap: 2048
unprivileged: 1
# 就是添加这个 unused0: <STORAGE_ID>:<虚拟磁盘>
unused0: local-lvm:vm-101-disk-1 

然后在Web UI管理页面进行操作添加磁盘,即可自动识别虚拟磁盘的容量。

创建的挂载点容量很迷,850G的挂载点,虚拟磁盘显示占用912.68G

SSD pool的容量是920G,那不是正好吗?

时间来到 5:00

安装rsync,默认没有rsync

执行数据同步

rsync -av --delete /data-backup/ /web-data/www/

数据已同步完成

openwrt配置ddns 有点复杂

自定义脚本

aly脚本路径

/usr/lib/ddns/update_aliyun_com.sh

太累了,不玩先吧,现在时间是 7:00

2021年10月29日 17:33

继续研究LXC容器的pct管理命令,目的是使用命令管理LXC,从而实现自动快照。

做快照的时候,我的目的是只为LXC的rootfs与备份的HDD磁盘做快照,SSD不参与做快照
因此快照前必须将SSD挂载点删除,然后再执行快照命令,快照完成后,再将SSD添加回来。

特别注意 千万不能在Web UI管理界面容器资源页删除未使用的磁盘!

此操作将会删除虚拟磁盘!!!

PCT管理命令 我们可以使用帮助命令去了解

# PVE 进入 PCT
# pct enter <vmid>
pct enter 103
# exit 退出pct

# 关于pct的使用帮助
pct help

# 具体到哪个命令
pct help set

我需要使用的pct管理命令

  • 为了能够实现自动快照,目前我需要的操作命令
# 关闭pct容器
pct shutdown <vmid> [OPTIONS]

root@fzpve:~# pct help shutdown
USAGE: pct shutdown <vmid> [OPTIONS]

  Shutdown the container. This will trigger a clean shutdown of the
  container, see lxc-stop(1) for details.

  <vmid>     <integer> (1 - N)

             The (unique) ID of the VM.

  -forceStop <boolean>   (default=0)

             Make sure the Container stops.

  -timeout   <integer> (0 - N)   (default=60)

             Wait maximal timeout seconds.

# 关闭pct容器示例
pct shutdown 101

# 删除pct挂载点mp[0,1,2,...]
pct set <vmid> -delete mp[n]

root@fzpve:~# pct help set
USAGE: pct set <vmid> [OPTIONS]

  Set container options.

  <vmid>     <integer> (1 - N)

             The (unique) ID of the VM.

  ......

  -delete    <string>

             A list of settings you want to delete.

  ......

  -mp[n]     [volume=]<volume> ,mp=<Path> [,acl=<1|0>] [,backup=<1|0>]
             [,mountoptions=<opt[;opt...]>] [,quota=<1|0>]
             [,replicate=<1|0>] [,ro=<1|0>] [,shared=<1|0>]
             [,size=<DiskSize>]

             Use volume as container mount point. Use the special syntax
             STORAGE_ID:SIZE_IN_GiB to allocate a new volume.

  -unused[n] [volume=]<volume>

             Reference to unused volumes. This is used internally, and
             should not be modified manually.


# 删除pct挂载点示例,得记住配置文件挂载点mp0的配置,比如mp=/data-backup,replicate=0,backup=0,以便再次添加
pct set 101 -delete mp0

# 测试关于unused[n]这个命令,测试只有下面的命令成功添加了磁盘
pct set 101 -unused0 wd-backup:vm-100-disk-0 -mp0 wd-backup:vm-100-disk-0,mp=/data-backu
### 但是上面的命令 -unused0 wd-backup:vm-100-disk-0 是多此一举的。

# 我直接使用如下命令即可再次添加删除的挂载点
pct set 101 -mp0 wd-backup:vm-100-disk-0,mp=/data-backup

# 建立pct快照
pct snapshot <vmid> <snapname> [OPTIONS]

root@fzpve:~# pct help snapshot
USAGE: pct snapshot <vmid> <snapname> [OPTIONS]

  Snapshot a container.

  <vmid>     <integer> (1 - N)

             The (unique) ID of the VM.

  <snapname> <string>

             The name of the snapshot.

  -description <string>

             A textual description or comment.

# 建立pct快照示例
pct snapshot 101 debian_snap20211029

# 建立快照之后当然是再次添加刚才已经删除的挂载点啦
# pct set <vmid> -mp[n] <STORAGE_ID>:<VM-DISK-NAME>,mp=<Path>,backup=<1|0>,replicate=<1|0>
pct set 101 -mp0 wd-backup:vm-100-disk-0,mp=/data-backup,backup=0,replicate=0

# 开启pct容器
# pct start <vmid>
pct start 100

时间来到了 20:20

配置了一个LXC容器模板,并且做了一个备份

然后完整克隆了2个基于这个模板的完整克隆,分别用于NextCloud与OnlyOffice

部署证书吧 了解一下pve用的什么证书

  • 貌似PVE有集成acme脚本?
  • 但是PVE集成的这个acme什么鬼来滴?我根本不懂怎么使用。

安装acme.sh 按照之前的旧方法搞

  • 安装在PVE上,然后同步到各个LXC
# 在PVE上安装acme.sh
curl  https://get.acme.sh | sh
## 居然安装出错,再次尝试还是同样的报错,PVE貌似只能使用他集成的ACME
root@fzpve:~# curl  https://get.acme.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   937    0   937    0     0    795      0 --:--:--  0:00:01 --:--:--   795
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  203k  100  203k    0     0    808      0  0:04:18  0:04:18 --:--:-- 67051
[Fri 29 Oct 2021 09:33:46 PM CST] Installing from online archive.
[Fri 29 Oct 2021 09:33:46 PM CST] Downloading https://github.com/acmesh-official/acme.sh/archive/master.tar.gz
[Fri 29 Oct 2021 09:37:56 PM CST] Extracting master.tar.gz

gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now
sh: 6676: gtar: not found
[Fri 29 Oct 2021 09:37:56 PM CST] Extraction error.

PVE集成的ACME貌似需要注册账户 而且有点繁琐

还是在LXC容器安装ACME试试吧

LXC没有curl,需要安装

apt install curl

然后再安装acme.sh

root@Debian11-Cloud:~# curl  https://get.acme.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   937    0   937    0     0    264      0 --:--:--  0:00:03 --:--:--   264
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  203k  100  203k    0     0   174k      0  0:00:01  0:00:01 --:--:--  174k
[Fri 29 Oct 2021 10:56:08 PM CST] Installing from online archive.
[Fri 29 Oct 2021 10:56:08 PM CST] Downloading https://github.com/acmesh-official/acme.sh/archive/master.tar.gz
[Fri 29 Oct 2021 10:56:12 PM CST] Extracting master.tar.gz
[Fri 29 Oct 2021 10:56:12 PM CST] It is recommended to install socat first.
[Fri 29 Oct 2021 10:56:12 PM CST] We use socat for standalone server if you use standalone mode.
[Fri 29 Oct 2021 10:56:12 PM CST] If you don't use standalone mode, just ignore this warning.
[Fri 29 Oct 2021 10:56:12 PM CST] Installing to /root/.acme.sh
[Fri 29 Oct 2021 10:56:12 PM CST] Installed to /root/.acme.sh/acme.sh
[Fri 29 Oct 2021 10:56:12 PM CST] Installing alias to '/root/.bashrc'
[Fri 29 Oct 2021 10:56:12 PM CST] OK, Close and reopen your terminal to start using acme.sh
[Fri 29 Oct 2021 10:56:12 PM CST] Installing cron job
no crontab for root
no crontab for root
[Fri 29 Oct 2021 10:56:12 PM CST] Good, bash is found, so change the shebang to use bash as preferred.
[Fri 29 Oct 2021 10:56:13 PM CST] OK
[Fri 29 Oct 2021 10:56:13 PM CST] Install success!

配置API key

export Ali_Key="L************S"
export Ali_Secret="O***************************F"

root@Debian11-Cloud:~# export Ali_Key="L************S"
root@Debian11-Cloud:~# export Ali_Secret="O**********************F"

申请证书

申请的是通配符证书

/root/.acme.sh/acme.sh --issue --dns dns_ali -d sgtfz.top -d *.sgtfz.top
### 貌似也是无法申请证书,需要注册账户了。
root@Debian11-Cloud:~# /root/.acme.sh/acme.sh --issue --dns dns_ali -d sgtfz.top -d *.sgtfz.top
[Fri 29 Oct 2021 11:04:00 PM CST] Using CA: https://acme.zerossl.com/v2/DV90
[Fri 29 Oct 2021 11:04:00 PM CST] Create account key ok.
[Fri 29 Oct 2021 11:04:00 PM CST] No EAB credentials found for ZeroSSL, let's get one
[Fri 29 Oct 2021 11:04:00 PM CST] acme.sh is using ZeroSSL as default CA now.
[Fri 29 Oct 2021 11:04:00 PM CST] Please update your account with an email address first.
[Fri 29 Oct 2021 11:04:00 PM CST] acme.sh --register-account -m my@example.com
[Fri 29 Oct 2021 11:04:00 PM CST] See: https://github.com/acmesh-official/acme.sh/wiki/ZeroSSL.com-CA
[Fri 29 Oct 2021 11:04:00 PM CST] Please add '--debug' or '--log' to check more details.
[Fri 29 Oct 2021 11:04:00 PM CST] See: https://github.com/acmesh-official/acme.sh/wiki/How-to-debug-acme.sh

### 注册zerossl账户
/root/.acme.sh/acme.sh --register-account -m sgtdjfz@live.cn --server zerossl
### 注册完成
root@Debian11-Cloud:~# /root/.acme.sh/acme.sh --register-account -m sgtdjfz@live.cn --server zerossl
[Fri 29 Oct 2021 11:34:08 PM CST] No EAB credentials found for ZeroSSL, let's get one
[Fri 29 Oct 2021 11:34:09 PM CST] Registering account: https://acme.zerossl.com/v2/DV90
[Fri 29 Oct 2021 11:34:13 PM CST] Registered
[Fri 29 Oct 2021 11:34:13 PM CST] ACCOUNT_THUMBPRINT='QGg******************_cPkL6QhfI'

## 设置默认CA为zerossl
/root/.acme.sh/acme.sh --set-default-ca  --server zerossl

## 再来申请证书!尼玛!搞错域名了!
/root/.acme.sh/acme.sh --issue --dns dns_ali -d sgtfz.cn -d *.sgtfz.cn

## 惨了!
## 难道又要折腾公网sgtfz.cn的证书了?不管先了。

# 继续申请sgtfz.top的的证书吧!!
/root/.acme.sh/acme.sh --issue --dns dns_ali -d sgtfz.top -d *.sgtfz.top

-----END CERTIFICATE-----
[Fri 29 Oct 2021 11:47:14 PM CST] Your cert is in: /root/.acme.sh/sgtfz.top/sgtfz.top.cer
[Fri 29 Oct 2021 11:47:14 PM CST] Your cert key is in: /root/.acme.sh/sgtfz.top/sgtfz.top.key
[Fri 29 Oct 2021 11:47:14 PM CST] The intermediate CA cert is in: /root/.acme.sh/sgtfz.top/ca.cer
[Fri 29 Oct 2021 11:47:14 PM CST] And the full chain certs is there: /root/.acme.sh/sgtfz.top/fullchain.cer

## 删除本地的sgtfz.cn误操作的证书
/root/.acme.sh/acme.sh --remove -d sgtfz.cn -d *.sgtfz.cn

root@Debian11-Cloud:~# /root/.acme.sh/acme.sh --remove -d sgtfz.cn -d *.sgtfz.cn
[Fri 29 Oct 2021 11:53:50 PM CST] sgtfz.cn is removed, the key and cert files are in /root/.acme.sh/sgtfz.cn
[Fri 29 Oct 2021 11:53:50 PM CST] You can remove them by yourself.

# 删除sgtfz.cn下载的证书目录
rm -r /root/.acme.sh/sgtfz.cn

# 让acme自动更新
root@Debian11-Cloud:~# /root/.acme.sh/acme.sh --upgrade  --auto-upgrade
[Sat 30 Oct 2021 12:14:49 AM CST] Already uptodate!
[Sat 30 Oct 2021 12:14:49 AM CST] Upgrade success!

2021年10月30日 00:10

是时候布置AMP环境了

#根据自己需需要部署nextcloud的环境安装如下软件包
apt install apache2;\
apt install php-fpm;\
apt install php-apcu php-bcmath php-curl php-gd php-gmp php-intl;\
apt install php-imagick php-mbstring php-mysql php-redis php-xml php-zip;\
apt install libmagickcore-6.q16-6-extra;\
apt install ffmpeg;\
apt install redis-server;\
apt install mariadb-server mariadb-client;

配置MariaDB数据库

初始化数据库:

mysql_secure_installation

Enter current password for root (enter for none): #直接按回车即可
Switch to unix_socket authentication [Y/n] y
Change the root password? [Y/n] n #不用设置root用户密码,因为我们使用unix_socket免密
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

数据库的一些基本配置

#登录数据库,root身份下,直接免密登录
mysql

#查看字符集
show variables like '%character%';
# 操作记录
root@Debian11-Cloud:~# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 52
Server version: 10.5.12-MariaDB-0+deb11u1 Debian 11

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show variables like '%character%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8mb4                    |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8mb4                    |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.001 sec)

#修改字符集
cp /etc/mysql/mariadb.conf.d/50-client.cnf{,.backup};\
vi /etc/mysql/mariadb.conf.d/50-client.cnf
[client]
default-character-set = utf8mb4

cp /etc/mysql/mariadb.conf.d/50-mysql-clients.cnf{,.backup};\
vi /etc/mysql/mariadb.conf.d/50-mysql-clients.cnf
[mysql]
default-character-set = utf8mb4

# 再次检查字符集
root@Debian11-Cloud:~# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 53
Server version: 10.5.12-MariaDB-0+deb11u1 Debian 11

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show variables like '%character%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8mb4                    |
| character_set_connection | utf8mb4                    |
| character_set_database   | utf8mb4                    |
| character_set_filesystem | binary                     |
| character_set_results    | utf8mb4                    |
| character_set_server     | utf8mb4                    |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.001 sec)


#针对nextcloud的一些数据库调优
cp /etc/mysql/mariadb.conf.d/50-server.cnf{,.backup};\
vi /etc/mysql/mariadb.conf.d/50-server.cnf
[mysqld]
innodb_buffer_pool_size=1G
innodb_io_capacity=4000
# 单服务器环境使用数据库就加上此配置项,如果此配置项有注释就去掉注释。
skip-external-locking

配置apache

# 开启支持php-fpm模块
a2enmod proxy_fcgi setenvif
a2enmod mpm_event
a2enconf php-fpm
# 操作记录
root@Debian11-Cloud:~# a2enmod proxy_fcgi setenvif
Considering dependency proxy for proxy_fcgi:
Module proxy already enabled
Module proxy_fcgi already enabled
Module setenvif already enabled
root@Debian11-Cloud:~# a2enmod mpm_event
Considering conflict mpm_worker for mpm_event:
Considering conflict mpm_prefork for mpm_event:
Module mpm_event already enabled
# 这儿报错是什么情况?先不管
root@Debian11-Cloud:~# a2enconf php-fpm
ERROR: Conf php-fpm does not exist!
# 正确姿势
a2enconf php7.4-fpm

#开启重写模块
a2enmod rewrite

root@Debian11-Cloud:~# a2enmod rewrite
Enabling module rewrite.
To activate the new configuration, you need to run:
  systemctl restart apache2
root@Debian11-Cloud:~# systemctl restart apache2

# 开启ssl,http2
a2enmod ssl
a2enmod http2

root@Debian11-Cloud:~# a2enmod ssl
Considering dependency setenvif for ssl:
Module setenvif already enabled
Considering dependency mime for ssl:
Module mime already enabled
Considering dependency socache_shmcb for ssl:
Enabling module socache_shmcb.
Enabling module ssl.
See /usr/share/doc/apache2/README.Debian.gz on how to configure SSL and create self-signed certificates.
To activate the new configuration, you need to run:
  systemctl restart apache2
root@Debian11-Cloud:~# a2enmod http2
Enabling module http2.
To activate the new configuration, you need to run:
  systemctl restart apache2


# 隐藏apache2版本号

cp /etc/apache2/conf-available/security.conf{,.backup};\
vi /etc/apache2/conf-available/security.conf
# 隐藏apache版本号。
ServerTokens Prod
# 或是 ServerTokens OS 修改为 ServerTokens Prod
# ServerSignature off 由原来的On改为Off 
ServerSignature off

配置php

# 配置PHP.ini
cp /etc/php/7.4/fpm/php.ini{,.backup};\
vi /etc/php/7.4/fpm/php.ini

# 大概有以下的配置内容
memory_limit = 1024M
post_max_size = 8G
upload_max_filesize = 8G
max_execution_time = 3600
max_input_time = 3600
; 隐藏 PHP 版本号,debian默认已经是off
expose_php = Off
# opcache配置项
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=10000
opcache.save_comments=1
# redis配置项
redis.session.locking_enabled=1
redis.session.lock_retries=-1
redis.session.lock_wait_time=10000
;apc.enable_cli=1 此条目还要在cli目录配置此项开启,否正nextcloud的occ命令无法使用
apc.enable_cli=1

# 配置/cli/PHP.ini
cp /etc/php/7.4/cli/php.ini{,.backup};\
vi /etc/php/7.4/cli/php.ini
# 在配置文件最后添加
apc.enable_cli=1


# 配置www.conf
cp /etc/php/7.4/fpm/pool.d/www.conf{,.backup};\
vi /etc/php/7.4/fpm/pool.d/www.conf

pm = dynamic
pm.max_children = 18
pm.start_servers = 8
pm.min_spare_servers = 4
pm.max_spare_servers = 16

AMP配置大概基本完成,真TM累

创建数据库

时间来到了1:15

root@Debian11-Cloud:~# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 54
Server version: 10.5.12-MariaDB-0+deb11u1 Debian 11

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
# 查看用户的授权方式
# 正常情况下root用户没有设置密码invalid,只有本地登录root用户才能通过unix_socket免密登录。
MariaDB [(none)]> select Host,User,Password,plugin from mysql.user;
+-----------+-------------+----------+-----------------------+
| Host      | User        | Password | plugin                |
+-----------+-------------+----------+-----------------------+
| localhost | mariadb.sys |          | mysql_native_password |
| localhost | root        | invalid  | mysql_native_password |
| localhost | mysql       | invalid  | mysql_native_password |
+-----------+-------------+----------+-----------------------+
3 rows in set (0.001 sec)

#创建数据库
#创建数据库用户及密码

#创建数据库
create database wordpress;
create database nextcloud;

#创建用户及密码
create user 'c***p'@'localhost' identified by 'S**密码**l';
create user 'c***c'@'localhost' identified by 'L**密码**l';

#授权
grant all on wordpress.* to 'c***p'@'localhost';
grant all on nextcloud.* to 'c***c'@'localhost';

#刷新权限
flush privileges;

#查看数据库
show databases;

#查看数据库的用户们
select host,user from mysql.user;

#创建数据库
#创建数据库用户及密码
## 操作记录
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> create database nextcloud;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> create user 'c***p'@'localhost' identified by 'S**密码**l';
Query OK, 0 rows affected (0.005 sec)

MariaDB [(none)]> create user 'c***c'@'localhost' identified by 'L**密码**l';
Query OK, 0 rows affected (0.005 sec)

MariaDB [(none)]> grant all on wordpress.* to 'c***p'@'localhost';
Query OK, 0 rows affected (0.005 sec)

MariaDB [(none)]> grant all on nextcloud.* to 'c***c'@'localhost';
Query OK, 0 rows affected (0.009 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| nextcloud          |
| performance_schema |
| wordpress          |
+--------------------+
5 rows in set (0.000 sec)

MariaDB [(none)]> select host,user from mysql.user;
+-----------+-------------+
| Host      | User        |
+-----------+-------------+
| localhost | c***c       |
| localhost | c***p       |
| localhost | mariadb.sys |
| localhost | mysql       |
| localhost | root        |
+-----------+-------------+
5 rows in set (0.000 sec)

MariaDB [(none)]> select Host,User,Password,plugin from mysql.user;
+-----------+-------------+-------------------------------------------+-----------------------+
| Host      | User        | Password                                  | plugin                |
+-----------+-------------+-------------------------------------------+-----------------------+
| localhost | mariadb.sys |                                           | mysql_native_password |
| localhost | root        | invalid                                   | mysql_native_password |
| localhost | mysql       | invalid                                   | mysql_native_password |
| localhost | c***p       | *D47204E111DE8AA0063727E425BE318FC1CCFF1E | mysql_native_password |
| localhost | c***c       | *89E56EC22FF7C9B9CF3B5D66745C42537E6E2D66 | mysql_native_password |
+-----------+-------------+-------------------------------------------+-----------------------+
5 rows in set (0.001 sec)

挂载磁盘到PCT

时间来到了 1:38

# 命令给pct容器挂载磁盘,非常顺利
pct set 103 -mp0 ssd-data:vm-101-disk-0,mp=/site-data

# 命令pct开机
pct start 103

部署网站

时间来到了 1:48

# 首先安装证书到apache2的目录

# 创建证书存放目录
mkdir /etc/apache2/cert

# 安装证书,证书匹配apache与nginx。
# nginx使用key.pem、chain.pem
# apache使用cert.pem、key.pem、chain.pem
acme.sh --install-cert -d sgtfz.top \
--cert-file      /etc/apache2/cert/sgtfztop_cert.pem  \
--key-file       /etc/apache2/cert/sgtfztop_key.pem  \
--fullchain-file /etc/apache2/cert/sgtfztop_chain.pem \
--reloadcmd     "service apache2 force-reload"
## 操作记录
root@Debian11-Cloud:~# /root/.acme.sh/acme.sh --install-cert -d sgtfz.top \
--cert-file      /etc/apache2/cert/sgtfztop_cert.pem  \
--key-file       /etc/apache2/cert/sgtfztop_key.pem  \
--fullchain-file /etc/apache2/cert/sgtfztop_chain.pem \
--reloadcmd     "service apache2 force-reload"
[Sat 30 Oct 2021 01:56:04 AM CST] Installing cert to: /etc/apache2/cert/sgtfztop_cert.pem
[Sat 30 Oct 2021 01:56:04 AM CST] Installing key to: /etc/apache2/cert/sgtfztop_key.pem
[Sat 30 Oct 2021 01:56:04 AM CST] Installing full chain to: /etc/apache2/cert/sgtfztop_chain.pem
[Sat 30 Oct 2021 01:56:04 AM CST] Run reload cmd: service apache2 force-reload
[Sat 30 Oct 2021 01:56:04 AM CST] Reload success

创建网站的apache配置文件

## 站点配置文件存放路径
## /etc/apache2/sites-available/

#建立NextCloud站点配置文件
vi /etc/apache2/sites-available/nextcloud.conf

<VirtualHost 192.168.33.8:80>
  # nextcloud 根目录
  DocumentRoot /site-data/www/nextcloud/
  # 指定 nextcloud 使用的域名
  ServerName  cloud.sgtfz.top
  # nextcloud 根目录规则
  <Directory /site-data/www/nextcloud/>
    Require all granted
    AllowOverride All
    Options FollowSymLinks MultiViews
    <IfModule mod_dav.c>
      Dav off
    </IfModule>
  </Directory>
</VirtualHost>

<VirtualHost *:443>
  # 开启 HTTP/2
  Protocols h2 h2c http/1.1
  # nextcloud 根目录
  DocumentRoot "/site-data/www/nextcloud/"
  # 指定 nextcloud 使用的域名
  ServerName  cloud.sgtfz.top:443

  # 日志
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

  # Enable/Disable SSL for this virtual host.
  SSLEngine on

  # 证书公钥配置
  SSLCertificateFile /etc/apache2/cert/sgtfztop_cert.pem
  # 证书私钥配置
  SSLCertificateKeyFile /etc/apache2/cert/sgtfztop_key.pem
  # 证书链配置
  SSLCertificateChainFile /etc/apache2/cert/sgtfztop_chain.pem

  SSLUseStapling on
  SSLStaplingReturnResponderErrors off
  SSLStaplingResponderTimeout 5

  #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
  <FilesMatch "\.(cgi|shtml|phtml|php)$">
      SSLOptions +StdEnvVars
  </FilesMatch>
  <Directory /usr/lib/cgi-bin>
      SSLOptions +StdEnvVars
  </Directory>
</VirtualHost>

#建立WordPress站点配置文件
vi /etc/apache2/sites-available/wordpress.conf
<VirtualHost *:80>
  # wordpress 根目录
  DocumentRoot /site-data/www/wordpress/
  # 指定 wordpress 使用的域名
  ServerName  sgtfz.top
  # wordpress 根目录规则
  <Directory /site-data/www/wordpress/>
    Options FollowSymLinks
    AllowOverride All
    Require all granted
  </Directory>
</VirtualHost>

<VirtualHost *:443>
  # 开启 HTTP/2
  Protocols h2 h2c http/1.1

  # wordpress 根目录
  DocumentRoot "/site-data/www/wordpress/"
  # 指定 wordpress 使用的域名
  ServerName  sgtfz.top:443

  # 日志
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

  # Enable/Disable SSL for this virtual host.
  SSLEngine on

  # 证书公钥配置
  SSLCertificateFile /etc/apache2/cert/sgtfztop_cert.pem
  # 证书私钥配置
  SSLCertificateKeyFile /etc/apache2/cert/sgtfztop_key.pem
  # 证书链配置
  SSLCertificateChainFile /etc/apache2/cert/sgtfztop_chain.pem

  SSLUseStapling on
  SSLStaplingReturnResponderErrors off
  SSLStaplingResponderTimeout 5

  #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
  <FilesMatch "\.(cgi|shtml|phtml|php)$">
      SSLOptions +StdEnvVars
  </FilesMatch>
  <Directory /usr/lib/cgi-bin>
      SSLOptions +StdEnvVars
  </Directory>
</VirtualHost>

# 站点总目录配置文件
# 路径 /etc/apache2/conf-available/ 的配置文件
vi /etc/apache2/conf-available/site-data.conf

ServerName localhost:80
# site-data DocumentRoot
<Directory "/site-data/www">
    Options FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

然后开启网站配置文件

a2enconf site-data
a2ensite wordpress
a2ensite nextcloud
# 操作记录
root@Debian11-Cloud:~# a2enconf site-data
Enabling conf site-data.
To activate the new configuration, you need to run:
  systemctl reload apache2
root@Debian11-Cloud:~# a2ensite wordpress
Enabling site wordpress.
To activate the new configuration, you need to run:
  systemctl reload apache2
root@Debian11-Cloud:~# a2ensite nextcloud
Enabling site nextcloud.
To activate the new configuration, you need to run:
  systemctl reload apache2

停止apache2

systemctl stop apache2

上传并导入NextCloud与WordPress的数据库

  • 这我们得先创建一个普通用户来上传文件

创建用户

adduser sgtfz

# 操作记录,按向导操作各种资料留空,至Is the information correct?,直接y即可。
root@Debian11-Cloud:~# adduser sgtfz
Adding user `sgtfz' ...
Adding new group `sgtfz' (1000) ...
Adding new user `sgtfz' (1000) with group `sgtfz' ...
Creating home directory `/home/sgtfz' ...
Copying files from `/etc/skel' ...
New password: 
Retype new password: 
passwd: password updated successfully
Changing the user information for sgtfz
Enter the new value, or press ENTER for the default
        Full Name []: 
        Room Number []: 
        Work Phone []: 
        Home Phone []: 
        Other []: 
Is the information correct? [Y/n] y

# 去TND,搞着搞着就没有保存到密码,现在忘了普通用户的密码了
# 修改普通用户sgtfz密码
passwd sgtfz
# 修改完成,爽呆了~!!

# 登录数据库
mysql

# 选择数据库
use nextcloud;
# 导入nextcloud的数据库
source /home/sgtfz/nextcloud_202110281906.sql;
# 继续wordpress的数据库
use wordpress;
source /home/sgtfz/wordpress_202110281906.sql;
# 顺利完成导入数据库

编辑WordPress与NextCloud配置文件的数据库用户及密码

# 编辑wordpress配置文件wp-config.php
vi /site-data/www/wordpress/wp-config.php

# nextcloud的配置文件还要修改一下目录路径,数据库用户及密码
vi /site-data/www/nextcloud/config/config.php

重启LXC,测试网站

reboot

遇到apache无法启动

报错日志如下:

[Sat Oct 30 03:39:56.096910 2021] [ssl:emerg] [pid 661:tid 139811129806144] AH01958: SSLStapling: no stapling cache available
[Sat Oct 30 03:39:56.096942 2021] [ssl:emerg] [pid 661:tid 139811129806144] AH02311: Fatal error initialising mod_ssl, exiting. See /var/log/apache2/error.log for more information
AH00016: Configuration Failed

禁用以下配置文件,apache就能起来

认真检查这两个网站的配置文件,没有发现有什么不妥啊?那么问题出在哪里?

a2dissite wordpress
a2dissite nextcloud

apache 启动失败已解决

如果长时间没有折腾,真的可以忘记很多以前经历过的事情,所以再好的记忆力都不如认真的记录下来。

  • 查看apache报错日志大概与证书的配置文件相关,我漏了这个配置文件没有检查与配置
  • 就这 /etc/apache2/mods-enabled/ssl.conf
root@Debian11-Cloud:~# cat /etc/apache2/mods-enabled/ssl.conf
<IfModule mod_ssl.c>

        # Pseudo Random Number Generator (PRNG):
        # Configure one or more sources to seed the PRNG of the SSL library.
        # The seed data should be of good random quality.
        # WARNING! On some platforms /dev/random blocks if not enough entropy
        # is available. This means you then cannot use the /dev/random device
        # because it would lead to very long connection times (as long as
        # it requires to make more entropy available). But usually those
        # platforms additionally provide a /dev/urandom device which doesn't
        # block. So, if available, use this one instead. Read the mod_ssl User
        # Manual for more details.
        #
        SSLRandomSeed startup builtin
        SSLRandomSeed startup file:/dev/urandom 512
        SSLRandomSeed connect builtin
        SSLRandomSeed connect file:/dev/urandom 512

        ##
        ##  SSL Global Context
        ##
        ##  All SSL configuration in this context applies both to
        ##  the main server and all SSL-enabled virtual hosts.
        ##

        #
        #   Some MIME-types for downloading Certificates and CRLs
        #
        AddType application/x-x509-ca-cert .crt
        AddType application/x-pkcs7-crl .crl

        #   Pass Phrase Dialog:
        #   Configure the pass phrase gathering process.
        #   The filtering dialog program (`builtin' is a internal
        #   terminal dialog) has to provide the pass phrase on stdout.
        SSLPassPhraseDialog  exec:/usr/share/apache2/ask-for-passphrase

        #   Inter-Process Session Cache:
        #   Configure the SSL Session Cache: First the mechanism
        #   to use and second the expiring timeout (in seconds).
        #   (The mechanism dbm has known memory leaks and should not be used).
        #SSLSessionCache                 dbm:${APACHE_RUN_DIR}/ssl_scache
        SSLSessionCache         shmcb:${APACHE_RUN_DIR}/ssl_scache(512000)
        SSLSessionCacheTimeout  300

        #   Semaphore:
        #   Configure the path to the mutual exclusion semaphore the
        #   SSL engine uses internally for inter-process synchronization.
        #   (Disabled by default, the global Mutex directive consolidates by default
        #   this)
        #Mutex file:${APACHE_LOCK_DIR}/ssl_mutex ssl-cache


        #   SSL Cipher Suite:
        #   List the ciphers that the client is permitted to negotiate. See the
        #   ciphers(1) man page from the openssl package for list of all available
        #   options.
        #   Enable only secure ciphers:
        #SSLCipherSuite HIGH:!aNULL
        #   sgtfz 20211030 这里注意啦!
        SSLCipherSuite ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384

        # SSL server cipher order preference:
        # Use server priorities for cipher algorithm choice.
        # Clients may prefer lower grade encryption.  You should enable this
        # option if you want to enforce stronger encryption, and can afford
        # the CPU cost, and did not override SSLCipherSuite in a way that puts
        # insecure ciphers first.
        # Default: Off
        #SSLHonorCipherOrder on
        # sgtfz 20211030 这里注意啦!
        SSLHonorCipherOrder off
        SSLSessionTickets off

        #   The protocols to enable.
        #   Available values: all, SSLv3, TLSv1, TLSv1.1, TLSv1.2
        #   SSL v2  is no longer supported
        #SSLProtocol all -SSLv3
        #   sgtfz 20211030
        SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1

        #   Allow insecure renegotiation with clients which do not yet support the
        #   secure renegotiation protocol. Default: Off
        #SSLInsecureRenegotiation on

        #   Whether to forbid non-SNI clients to access name based virtual hosts.
        #   Default: Off
        #SSLStrictSNIVHostCheck On

        #   ssl_stapling_cache
        #   sgtfz - 20211030 这里注意啦!
        SSLStaplingCache shmcb:${APACHE_RUN_DIR}/ssl_stapling_cache(128000)

</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

配置nextcloud后台任务

crontab -u www-data -e
# 每10分钟执行一次
*/10 * * * * php -f /site-data/www/nextcloud/cron.php
# 配置顺利完成

又一个不眠之夜

时间来到了 5:13

折腾这方面的东西,也只有晚上没有人打扰思路才能清晰。

但是全程总体非常顺利,Proxmox VE可玩性确实更高!

在这个主机(B85 + E3-1231V3)上运行非常舒服,对比我最古老的那个主机(Z68 + E3-1230V2)明显好不少。

可能是华硕主板B85M(MATX),比微星主板Z68(ATX)更优秀的原因。

微星的Z68启动的时候有PVE有几个报错的提示:ACPI Error

华硕的B85M没有此问题

在华硕B85M主板上的,PVE的VM虚拟机同样的OpenWrt占用资源更低一些,这也许是因为OpenWrt的3个网口都是直接使用硬件直通网卡。

Windows Terminal ssh 连接报错解决

在折腾的中途使用 Windows Terminal ssh 连接服务器却报错

ssh连接到指定服务器报错如下:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:Y+VRt0Y***********************************l4TLM.
Please contact your system administrator.
Add correct host key in C:\\Users\\sgtfz/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in C:\\Users\\sgtfz/.ssh/known_hosts:1
ECDSA host key for 192.168.33.8 has changed and you have requested strict checking.
Host key verification failed.

解决方法

打开当前用户目录路径如下:

  • C:\Users\sgtfz\.ssh
  • 编辑known_hosts文件
# 哪个IP地址无法用ssh连接的,整行删掉即可。
192.168.33.8 ecdsa-sha2-nistp256 AAAAE2VjZHNh****uerLgqcnkItfIAsuyD9*****cP8ipTxIj2Cj6lw=
192.168.33.131 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoY*************f54zj69xxmXTmXunQvUxmkM=
192.168.33.6 ecdsa-sha2-nistp256 AAAAE2V***uerLgqcnkItfIAsuyD9+fhI/JtZ/dXacP8ipTxIj2Cj6lw=
192.168.33.1 ssh-rsa AAAAB3N*************************************E+k0diaOcB

从 Hyper-V 迁移到 Proxmox VE 的计划实施步骤

为从 Hyper-V 迁移到 Proxmox VE 正在做各方面的准备工作,准备2021年10月28日 — 今晚 21:30 进行。

  • 当前的所谓家庭服务器使用的是 Windows server 2019 Hyper-V
  • 需要将家庭服务器主机关机,才能将PVE部署到服务器上
  • 届时将无法使用本地部署的服务:OpenWrt、WordPress、NextCloud
  • 用普通路由器顶替OpenWrt的拨号工作,暂时保证互联网正常工作。
  • 虽然运行的东西不多,但全程手动档,耗时应该比较长,无特殊情况一律勿扰模式。
  • 由于对PVE还不太熟悉,可能会遇到各种翻车的情况出现!

一、备份 Hyper-V 上运行的各种服务配置

我不知道能不能直接备份配置文件,搞好新环境后直接还原配置文件到新环境上呢?貌似这样不太完美
不过配置文件的备份是必需的,到时在新环境可以全程手动抄作业即可。

  • 备份OpenWrt各种配置
  • 备份承载NextCloud与WordPress的Debian各种环境配置
  • NextCloud与WordPress网站数据及数据库已经Rsync到另一台测试机的磁盘上了。
  • 但我已经感觉到头疼了,这个环境配置涉及太多
  • 备份/etc/apache2这个目录的配置文件
  • 备份/etc/mysql这个目录的配置文件
  • 备份/etc/php/7.4/fpm这个目录的配置文件

二、安装 Proxmox VE

  • filesystem 就使用ext4吧。

安装时需要自定义磁盘分区大小

  • hdsize 定义要使用的总硬盘大小,计划用一个128G的固态硬盘安装PVE。
  • swapsize 交换分区大小,最小4GB,最大8GB。计划准备配置4GB
  • maxroot 存储操作系统的根分区,最大限制为hdsize/4,计划配置20GB
  • maxvz 定义lvm-thin pool data分区大小,计划配置80GB左右 datasize=hdsize-rootsize-swapsize-minfree
  • minfree 定义LVM卷组pve中剩余的可用空间。计划配置5GB,超过128GB的可用存储空间默认配置为16GB。
    否则默认hdsize/8, LVM需要VG中的可用空间来创建快照,lvmthin不需要VG中的可用空间来创建快照!

国家,时区,键盘

  • Country: 国家,china
  • Time zone: 时区,Asia/Shanghai
  • Keyboard Layout: 键盘,U.S. English

网卡,主机名,IP地址,DNS

  • Management Interface: 选个PVE用的网卡,用集成网卡吧。
  • Hostname(FQDN): 主机名随便吧,fzpve.lan
  • IP Address(CIDR): 主机地址,192.168.33.3/24
  • Gateway: 网关地址,192.168.33.1
  • DNS Server: DNS服务器地址,223.5.5.5

设置密码、邮箱

  • Password: 设置root密码
  • Confirm: 再次输入root密码
  • Email: 邮箱地址

三、Proxmox VE 基础配置

修改Vi编辑器

   #切换到root身份
   su -

   #使用nano编辑器修改Vi配置文件vimrc.tiny
   nano /etc/vim/vimrc.tiny 
   # 需要修改的内容如下
   " set compatible
   set nocompatible
   set backspace=2

修改Debian软件源为国内清华镜像站,去除Proxmox企业源,修改CT Templates模板源

   # 用vi编辑器修改Debian软件源sources.list
   vi /etc/apt/sources.list

   # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
   deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
   # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
   deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
   # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
   deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
   # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
   deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
   # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free


   # 去除Proxmox企业源
   # 注释掉企业源即可。
   vi /etc/apt/sources.list.d/pve-enterprise.list
   # deb https://enterprise.proxmox.com/debian/pve bullseye pve-enterprise


   # CT Templates LXC模板镜像源,修改为清华镜像站
   # 将 /usr/share/perl5/PVE/APLInfo.pm 文件中默认的源地址 http://download.proxmox.com
   # 替换为 https://mirrors.tuna.tsinghua.edu.cn/proxmox 即可。
   # 可以使用如下命令修改:
   # 首先备份APLInfo.pm配置文件
   cp /usr/share/perl5/PVE/APLInfo.pm /usr/share/perl5/PVE/APLInfo.pm_back

   # 修改APLInfo.pm配置文件
   sed -i 's|http://download.proxmox.com|https://mirrors.tuna.tsinghua.edu.cn/proxmox|g' /usr/share/perl5/PVE/APLInfo.pm
   # 针对 /usr/share/perl5/PVE/APLInfo.pm 文件的修改,重启后生效。

存储和备份方案

使用块级存储 LVM-thin存储类型做后端

  • 主要因为LVM-thin是PVE官方推荐,快照与克隆非常方便,性能各方面较好吧?
  • LVM需要VG中的空闲空间来创建快照,lvmthin不需要VG中的空闲空间来创建快照!
  • 为了方便使用快照,必须用LVM-thin

单个SSD磁盘运行NextCloud Rsync同步备份并结合快照保证数据安全

  • 使用Rsync实时同步到HDD磁盘,比较有效的防止磁盘损坏丢失数据
  • 只在HDD上做快照,因为SSD容量较小且有写入寿命。快照可以避免中毒数据被修改……。

磁盘查看、添加、管理

查看磁盘相关信息的命令有如下:

   # 以下常用查看磁盘相关的命令,实际使用更能理解命令的作用。

   # 查看机器上的所有硬盘及分区情况
   fdisk -l

   # 查看系统当前已挂载的磁盘及挂载目录
   df -h

   # 查看所有磁盘及分区树状结构、类型、挂载点
   lsblk

   # 查看所有磁盘UUID,类型
   blkid

为PVE添加块级存储 LVM-thin

  • 不建议在WebUI管理页添加LVM-thin
  • 强烈建议使用命令进行添加LVM-thin

使用命令行添加 LVM-thin存储

   # 首先确定我们需要添加的物理磁盘
   fdisk -l

   # 创建物理卷PV (volume),这里针对没有分区的硬盘
   pvcreate /dev/sdb   # sdc,sdd,sde

   # 创建卷组VG (group)
   # vgcreate <VGNAME> /dev/sdb
   vgcreate vgdata /dev/sdb

   # 创建 thin-pool (精简池),1TB的SSD预留5G左右的VG空闲空间,目前仅为tmeta扩容做准备。
   # 以便灵活增加tmeta空间,此步骤默认创建的[<poolNAME>_tmeta]容量为100mb左右
   # 我们可以创建精简池后,再增加[<poolNAME>_tmeta]空间为500MB即可,增加tmeta空间[lvol0_pmspare]空间也会同步增加。
   # lvcreate -L 100G -n <poolNAME> <VGNAME>
   # lvconvert --type thin-pool <VGNAME>/<poolNAME>
   lvcreate -L 100G -n fzdata vgdata
   lvconvert --type thin-pool vgdata/fzdata

   # 使用刚才创建的 thin-pool (精简池)
   # pvesm add lvmthin <STORAGE_ID> --vgname <VGNAME> --thinpool <poolNAME>
   pvesm add lvmthin fzthin --vgname vgdata --thinpool fzdata

   # 检查存储状态
   pvesm status
   # PVE存储的配置storage.cfg文件路径为:/etc/pve/storage.cfg

   # 下面是扩容 pool 或 tmata 空间的方法。

   # 如果我们要扩容 pool 就必需保证 VG 有空闲的空间以便扩容
   # 首先查看VG的可用空闲空间VFree
   vgs
   # 或空闲空间PFree
   pvs
   # 扩容 pool 方法
   # lvextend -L+10G <VGNAME>/<poolNAME>
   lvextend -L+10G vgdata/fzdata

   # 如果我们要扩容 tmata 就必需保证 VG 有空闲的空间以便扩容
   # 查看<poolNAME>_tmeta]空间
   lvs -a
   # 或
   lvs -oname,size,data_percent,metadata_percent vgdata/fzdata
   # 或
   lvs -a -oname,attr,size vgdata
   # 扩容[<poolNAME>_tmeta]空间
   # lvextend --poolmetadatasize +900M <VGNAME>/<poolNAME>
   lvextend --poolmetadatasize +900M vgdata/fzdata
   # tmeta空间--即是Web管理页面上的元数据大小
   # 增加tmeta空间同时[lvol0_pmspare]同步增加同样大小的空间,即tmeta增加50MB,就需要100MB的PFree空间。

管理磁盘 日常

日后再说吧

硬件直通配置

1、主板必须开启vt-d

2、修改grub文件

   vi /etc/default/grub
   # GRUB_CMDLINE_LINUX_DEFAULT="quiet"做如下修改(intel的CPU)
   GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on"

3、更新grub

update-grub

4、加载内核模块modules

   vi /etc/modules
   # 内容如下
   vfio
   vfio_iommu_type1
   vfio_pci
   vfio_virqfd

5、刷新initramfs

update-initramfs -u -k all

6、然后重启主机

7、验证是否开启iommu

dmesg | grep 'remapping'

  • 执行命令后显示如下内容,说明开启成功 DMAR-IR: Enabled IRQ remapping in x2apic mode
  • 此时输入命令 find /sys/kernel/iommu_groups/ -type l 出现很多直通组,说明成功了。

8、PCI-E直通要求

  • 执行了前面所有步骤之后,虚拟机 机器必需要选q35。

9、关于显卡直通

暂时不考虑直通显卡吧。

  • 据说新版的PVE7无需做驱动屏蔽,直接开启iommu之后,创建的虚拟机 机器q35,然后添加直通设备即可。
  • 关于直通显卡,在Windows上驱动报错43,尝试下载安装最新版的NVIDIA驱动试试吧!

修改PVE绑定的网卡及IP地址

假如我们更换了网卡或是PCIe网卡更换了插槽位置,可能会导致PVE网络故障。 这会造成无法远程访问并管理PVE,那么就必须进入高级模式,修改绑定的网卡参数了。

   # 首先查看我们的物理网卡及IP地址等相关信息
   ip addr
   # 这可以看到我们所有的网络设备
   # 1:  lo:全称loopback,是回环地址。
   # 2:  enp1s0: 物理网卡,如果有多个网卡,会有多个enp1s1、enp2s0或其他
   # 3:  vmbr0: 桥接网卡,这是PVE桥接网卡,多个桥接网卡也会有多个vmbr1、vmbr2

   # 然后查看interfaces配置文件
   cat /etc/network/interfaces
   # 部分内容如下
   auto lo
   iface lo inet loopback

   auto enp1s0
   iface enp1s0 inet manual

   auto enp2s0
   iface enp2s0 inet manual

   auto vmbr0
   iface vmbr0 inet static
         address 192.168.33.3/24  # PVE后台IP地址
         gateway 192.168.33.1  # 网关
         bridge-ports enp1s0  # PVE桥接绑定的物理网卡,如果对应不上目前的物理网卡必然网络故障。
         bridge-stp off  # 暂时未知,应该与自动激活或开启相关
         bridge-fd 0  # 暂时未知,应该与自动激活或开启相关
   # 我们就能很容易发现问题了

有了上面的例子,我们就很容易的去修改网卡及IP地址的参数了。

四、在Proxmox VE创建虚拟机及LXC容器

VM虚拟机部署OpenWrt

虽然LXC上运行OpenWrt真的非常省CPU资源,但是PPPoE拨号正常却无法提供LAN口设备上网。

  • 查看防火墙表状态没有任何规则内容,重启防火墙后,防火墙表状态有规则内容了,同时LAN口设备也可以正常上网啦。
  • 即使重启了防火墙后可上网了,实际上没有发现的问题,可能还有很多,所以还是算了,不在乎多损耗一些CPU资源了。
  • 再说LXC上运行OpenWrt,在配置LXC的时候还是比较繁琐的,那么就更有理由放弃LXC运行OpenWrt了。

计划网卡直通给OpenWrt。

  • 如果使用硬件直通,就需要选择q35机器咯,那么就再搞一个UEFI启动吧。

VM虚拟机部署OpenWrt的步骤如下:

首先要建立一个VM虚拟机 硬件配置暂定如下:

  • 内存 512MB
  • 处理器 2核心 [host,flags=+aes]
  • BIOS OVMF(UEFI)
  • 显示 标准VGA(安装配置完成后,最后选择无显示)
  • 机器 q35(最新)
  • SCSI控制器 VirtIO SCSI
  • 硬盘随便添加一个1G的,然后需要使用img镜像导入的磁盘,之后要删除这个硬盘的。
  • 网络设备(net0) 随便添加一个网卡,之后要删除,配置直通网卡的哟。
  • EFI磁盘 这个必须要且不能删除。

然后下载OpenWrt

   # 直接在PVE上下载即可
   wget https://downloads.openwrt.org/releases/21.02.0/targets/x86/64/openwrt-21.02.0-x86-64-generic-ext4-combined-efi.img.gz

   # 解压
   gzip -d openwrt-21.02.0-x86-64-generic-ext4-combined-efi.img.gz

   # 将img磁盘直接导入为VM虚拟磁盘,vmid根据现实灵活修改哟。
   # qm importdisk <vmid> <source> <storage> [OPTIONS]
   qm importdisk 101 /root/openwrt-21.02.0-x86-64-generic-ext4-combined-efi.img local-lvm

最后再编辑虚拟机配置

  • 硬件
  • 将之前创建时的网卡删除,添加PCI设备,先添加一个直通网口作为LAN,之后安装好后再添加WAN口
  • 将之前创建虚拟机时的磁盘删除,添加刚才命令导入的虚拟磁盘。
  • 剩下的默认吧,检查配置无误后进入下一环节
  • 选项
  • 开机自动启动 是
  • OS类型 Linux 5.x – 2.6 Kernel
  • 引导顺序 scsi0 (特别注意这必须选导入的OpenWrt磁盘)
  • 剩下的项目默认吧。

至此可以开机了,如果一切正常之后,就可以进入192.168.1.1进行配置了。

创建CT(LXC)容器部署NextCloud与OnlyOffice

这一步就等实际操作后再做记录吧