Bash
RHEL8~10修改IP
#!/bin/bash
# 默认网络配置参数
INTERFACE_NAME="eth0"
PREFIX="21"
GATEWAY="172.16.0.2"
DNS="172.16.0.233"
IP_ADDRESS=""
# 解析命令行参数
while [[ $# -gt 0 ]]; do
case $1 in
--ip)
IP_ADDRESS="$2"
shift 2
;;
*)
echo "未知参数: $1"
exit 1
;;
esac
done
# 检查是否提供了IP地址
if [ -z "$IP_ADDRESS" ]; then
echo "错误: 必须通过 --ip 参数指定IP地址"
echo "用法: $0 --ip <IP地址>"
exit 1
fi
# 配置IPv4静态地址
echo "配置IP地址和子网掩码..."
nmcli con mod ${INTERFACE_NAME} ipv4.addresses ${IP_ADDRESS}/${PREFIX}
# 配置网关
echo "配置网关..."
nmcli con mod ${INTERFACE_NAME} ipv4.gateway ${GATEWAY}
# 配置DNS
echo "配置DNS服务器..."
nmcli con mod ${INTERFACE_NAME} ipv4.dns ${DNS}
# 设置为手动配置模式
echo "设置为静态IP配置..."
nmcli con mod ${INTERFACE_NAME} ipv4.method manual
# 启用连接
echo "应用网络配置..."
nmcli con up ${INTERFACE_NAME}
# 显示配置结果
echo "网络配置已完成!"
echo "配置详情:"
echo " IP地址: ${IP_ADDRESS}/${PREFIX}"
echo " 网关: ${GATEWAY}"
echo " DNS: ${DNS}"
RHEL8~10扩容分区
#!/bin/bash
# LVM自动扩容脚本(修正版)
# 适用于已扩容的磁盘设备
set -e # 遇到错误时退出
echo "=== LVM自动扩容脚本 ==="
# 配置变量
DISK="/dev/sdb"
PARTITION="/dev/sdb1"
VG_NAME="rl"
LV_NAME="root"
MOUNT_POINT="/"
# 1. 检查磁盘是否存在
if [ ! -b "$DISK" ]; then
echo "错误: 磁盘 $DISK 不存在"
exit 1
fi
# 2. 检查分区是否存在
if [ ! -b "$PARTITION" ]; then
echo "错误: 分区 $PARTITION 不存在"
exit 1
fi
# 3. 先修复GPT分区表,再调整分区大小
echo "正在修复GPT分区表并调整分区 ${PARTITION} 大小..."
# 分两步执行:先修复GPT,再调整分区大小
echo "fix" | parted ---pretend-input-tty "$DISK" print >/dev/null 2>&1 || true
parted "$DISK" resizepart 1 100%
# 4. 刷新分区表
echo "刷新分区表..."
partprobe "$DISK"
# 5. 等待系统识别新分区
sleep 2
# 6. 扩展物理卷
echo "扩展物理卷 ${PARTITION}..."
pvresize "$PARTITION"
# 7. 检查是否有可用空间扩展逻辑卷
echo "检查逻辑卷可扩展空间..."
FREE_EXTENTS=$(vgs --noheadings -o free_count "$VG_NAME" 2>/dev/null | tr -d ' ')
if [ "$FREE_EXTENTS" != "0" ] && [ -n "$FREE_EXTENTS" ]; then
echo "扩展逻辑卷 ${VG_NAME}-${LV_NAME}..."
lvextend -l +100%FREE "/dev/${VG_NAME}/${LV_NAME}"
# 8. 扩展文件系统
echo "扩展文件系统..."
if mount | grep "$MOUNT_POINT" | grep -q xfs; then
xfs_growfs "$MOUNT_POINT"
elif mount | grep "$MOUNT_POINT" | grep -q ext; then
resize2fs "/dev/${VG_NAME}/${LV_NAME}"
else
echo "警告: 无法识别的文件系统类型"
fi
else
echo "没有可用空间扩展逻辑卷"
fi
# 9. 显示结果
echo "=== 扩容完成 ==="
df -h "$MOUNT_POINT"
echo "=================="
echo "扩容操作已完成!"
Powershell
Windows Server 2025启用ReFS重复数据删除功能并配置去重计划
Enable-DedupVolume -Volume "D:" -UsageType HyperV
Enable-DedupVolume -Volume "E:" -UsageType Default
Get-DedupSchedule
Set-DedupSchedule -Name BackgroundOptimization -Enabled $false
Set-DedupSchedule -Name PriorityOptimization -Enabled $false
New-DedupSchedule -Name "NightlyOptimization" -Type Optimization -DurationHours 3 -Memory 20 -Cores 50 -Priority Low -Days @(1,2,3,4,5,6,0) -Start (Get-Date "2016-08-08 03:30:00") -InputOutputThrottle 20
New-DedupSchedule -Name "NightlyGarbageCollection" -Type GarbageCollection -DurationHours 3 -Memory 20 -Cores 50 -Priority Low -Days @(1,2,3,4,5,6,0) -Start (Get-Date "2016-08-08 03:30:00") -InputOutputThrottle 20
New-DedupSchedule -Name "NightlyScrubbing" -Type Scrubbing -DurationHours 3 -Memory 20 -Cores 50 -Priority Low -Days @(1,2,3,4,5,6,0) -Start (Get-Date "2016-08-08 03:30:00") -InputOutputThrottle 20
Set-DedupSchedule -Name "NightlyOptimization" -Type Optimization -DurationHours 3 -Memory 20 -Cores 50 -Priority Low -Days @(1,2,3,4,5,6,0) -Start (Get-Date "2016-08-08 03:30:00") -InputOutputThrottle 5
Set-DedupSchedule -Name "NightlyGarbageCollection" -Type GarbageCollection -DurationHours 3 -Memory 20 -Cores 50 -Priority Low -Days @(1,2,3,4,5,6,0) -Start (Get-Date "2016-08-08 03:30:00") -InputOutputThrottle 5
Set-DedupSchedule -Name "NightlyScrubbing" -Type Scrubbing -DurationHours 3 -Memory 20 -Cores 50 -Priority Low -Days @(1,2,3,4,5,6,0) -Start (Get-Date "2016-08-08 03:30:00") -InputOutputThrottle 5
Windows Server 2025配置分层存储池并格式化为ReFS格式
$PhysicalDisks = (Get-PhysicalDisk -CanPool $True)
$PhysicalDisks
New-StoragePool -FriendlyName "ALFD-SP" -StorageSubsystemFriendlyName "Windows Storage*" -PhysicalDisks $PhysicalDisks -WriteCacheSize 16GB
Get-StoragePool
Remove-StoragePool "ALFD-SP"
remove-storagetier -FriendlyName "ALFD-HT"
remove-storagetier -FriendlyName "ALFD-ST"
New-StorageTier -StoragePoolFriendlyName "ALFD-SP" -FriendlyName "ALFD-HT" -MediaType HDD -ResiliencySettingName "Parity" -NumberOfColumns 6
New-StorageTier -StoragePoolFriendlyName "ALFD-SP" -FriendlyName "ALFD-ST" -MediaType SSD
get-storagetier "ALFD-HT"
$ST = Get-StorageTier -FriendlyName "ALFD-ST"
$HT = Get-StorageTier -FriendlyName "ALFD-HT"
Remove-VirtualDisk -FriendlyName "ALFD-OTHER-VD"
New-VirtualDisk -StoragePoolFriendlyName "ALFD-SP" -FriendlyName "ALFD-VM-VD" -StorageTiers $ST, $HT -StorageTierSizes 4TB,4TB
$disk = Get-Disk | Where-Object { $_.FriendlyName -eq "ALFD-VM-VD" }
Initialize-Disk -Number $disk.Number -PartitionStyle GPT
New-Partition -DiskNumber $disk.Number -UseMaximumSize -DriveLetter D | Format-Volume -FileSystem ReFS -Force -Full:$false
New-VirtualDisk -StoragePoolFriendlyName "ALFD-SP" -FriendlyName "ALFD-OTHER-VD" -StorageTiers $ST, $HT -StorageTierSizes 1TB,5TB
$disk = Get-Disk | Where-Object { $_.FriendlyName -eq "ALFD-OTHER-VD" }
Initialize-Disk -Number $disk.Number -PartitionStyle GPT
New-Partition -DiskNumber $disk.Number -UseMaximumSize -DriveLetter E | Format-Volume -FileSystem ReFS -Force -Full:$false
Get-StoragePool "ALFD-SP"
Get-StoragePool "ALFD-SP" | Select-Object SupportsStorageTiers
Python