1. 升级规划与评估
服务器硬件升级前需要进行全面的规划和评估,确保升级过程顺利。更多学习教程www.fgedu.net.cn
# dmidecode -t system | grep -E “Manufacturer|Product Name|Serial Number”
Manufacturer: Dell Inc.
Product Name: PowerEdge R750
Serial Number: ABCD1234
# 查看CPU信息
# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
CPU(s): 64
On-line CPU(s) list: 0-63
Thread(s) per core: 2
Core(s) per socket: 32
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 143
Model name: Intel(R) Xeon(R) Gold 6326 CPU @ 2.90GHz
Stepping: 6
CPU MHz: 2900.000
CPU max MHz: 3500.0000
CPU min MHz: 800.0000
BogoMIPS: 5800.00
Virtualization: VT-x
L1d cache: 1.5 MiB
L1i cache: 1 MiB
L2 cache: 40 MiB
L3 cache: 48 MiB
# 查看内存信息
# dmidecode -t memory | grep -E “Size|Type|Speed|Manufacturer” | head -20
Size: 32 GB
Type: DDR4
Speed: 3200 MT/s
Manufacturer: Samsung
Size: 32 GB
Type: DDR4
Speed: 3200 MT/s
Manufacturer: Samsung
Size: 32 GB
Type: DDR4
Speed: 3200 MT/s
Manufacturer: Samsung
# lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINT
NAME SIZE TYPE FSTYPE MOUNTPOINT
sda 1.8T disk
├─sda1 512M part vfat /boot/efi
├─sda2 1G part xfs /boot
└─sda3 1.8T part LVM_member
├─ol-root 500G lvm xfs /
├─ol-swap 32G lvm swap [SWAP]
└─ol-var 1.3T lvm xfs /var
sdb 3.6T disk
└─sdb1 3.6T part LVM_member
└─data-app 3.6T lvm xfs /data
sdc 3.6T disk
└─sdc1 3.6T part LVM_member
└─data-db 3.6T lvm xfs /oracle
# 查看RAID配置(Dell服务器)
# /opt/dell/srvadmin/bin/omreport storage vdisk
List of Virtual Disks in the System
Controller PERC H755 Front (Slot 1)
ID : 0
Status : Ok
Name : Virtual Disk 0
State : Ready
Hot Spare Policy : Dedicated Hot Spare
Encrypted : No
Layout : RAID-10
Size : 1,795.50 GB (1,928,510,423,040 bytes)
Device Name : /dev/sda
Bus Protocol : SAS
Media : HDD
Read Policy : Adaptive Read Ahead
Write Policy : Write Back
Cache Policy : Direct I/O
Stripe Element Size : 64 KB
Disk Cache Policy : Disabled
# ip link show
1: lo:
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0:
link/ether 00:11:22:33:44:55 brd ff:ff:ff:ff:ff:ff
3: eth1:
link/ether 00:11:22:33:44:56 brd ff:ff:ff:ff:ff:ff
# 查看网卡详情
# ethtool eth0
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 1000baseT/Full
10000baseT/Full
25000baseCR/Full
25000baseSR/Full
Supported pause frame use: Symmetric
Supports auto-negotiation: Yes
Supported FEC modes: Not reported
Advertised link modes: 1000baseT/Full
10000baseT/Full
25000baseCR/Full
Speed: 25000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
Link detected: yes
2. 内存升级操作
内存升级是最常见的硬件升级操作,需要注意内存条的兼容性和插槽位置。学习交流加群风哥微信: itpux-com
# free -h
total used free shared buff/cache available
Mem: 125Gi 2.1Gi 118Gi 8.5Mi 4.8Gi 122Gi
Swap: 32Gi 0B 32Gi
# 查看内存插槽信息
# dmidecode -t memory | grep -E “Size|Locator|Type|Speed” | grep -v “No Module”
Size: 32 GB
Locator: DIMM_A1
Type: DDR4
Speed: 3200 MT/s
Size: 32 GB
Locator: DIMM_A2
Type: DDR4
Speed: 3200 MT/s
Size: 32 GB
Locator: DIMM_A3
Type: DDR4
Speed: 3200 MT/s
Size: 32 GB
Locator: DIMM_A4
Type: DDR4
Speed: 3200 MT/s
# 查看空闲内存插槽
# dmidecode -t memory | grep -B1 “No Module Present”
Size: No Module Present
Locator: DIMM_B1
Size: No Module Present
Locator: DIMM_B2
Size: No Module Present
Locator: DIMM_B3
Size: No Module Present
Locator: DIMM_B4
# 1. 记录当前内存配置
# dmidecode -t memory > /backup/memory_config_before.txt
# 2. 检查内存兼容性
# cat /proc/meminfo | grep -E “MemTotal|MemFree|MemAvailable”
MemTotal: 131072000 kB
MemFree: 123456789 kB
MemAvailable: 128000000 kB
# 3. 停止关键服务
# systemctl stop oracle
# systemctl stop weblogic
# systemctl stop nginx
# 4. 同步数据并卸载文件系统
# sync
# umount /data
# 5. 关闭系统
# shutdown -h now
Connection to fgedu closed by remote host.
Connection to fgedu closed.
# 查看新内存容量
# free -h
total used free shared buff/cache available
Mem: 251Gi 2.5Gi 245Gi 8.5Mi 3.5Gi 246Gi
Swap: 32Gi 0B 32Gi
# 验证内存识别
# dmidecode -t memory | grep -E “Size|Locator” | grep -v “No Module”
Size: 32 GB
Locator: DIMM_A1
Size: 32 GB
Locator: DIMM_A2
Size: 32 GB
Locator: DIMM_A3
Size: 32 GB
Locator: DIMM_A4
Size: 32 GB
Locator: DIMM_B1
Size: 32 GB
Locator: DIMM_B2
Size: 32 GB
Locator: DIMM_B3
Size: 32 GB
Locator: DIMM_B4
# 运行内存测试
# memtester 16G 1
memtester version 4.5.1 (64-bit)
Copyright (C) 2001-2020 Charles Cazabon.
Licensed under the GNU General Public License version 2 (only).
pagesize is 4096
pagesizemask is 0xfffffffffffff000
want 16384MB (17179869184 bytes)
got 16384MB (17179869184 bytes), trying mlock …locked.
Loop 1/1:
Stuck Address : ok
Random Value : ok
Compare XOR : ok
Compare SUB : ok
Compare MUL : ok
Compare DIV : ok
Compare OR : ok
Compare AND : ok
Sequential Increment: ok
Solid Bits : ok
Block Sequential : ok
Checkerboard : ok
Bit Spread : ok
Bit Flip : ok
Walking Ones : ok
Walking Zeroes : ok
8-bit Writes : ok
16-bit Writes : ok
Done.
3. CPU升级操作
CPU升级需要考虑主板兼容性和散热系统,通常需要专业人员进行操作。
# lscpu | grep -E “Socket|Core|Thread|Model name”
Thread(s) per core: 2
Core(s) per socket: 32
Socket(s): 1
Model name: Intel(R) Xeon(R) Gold 6326 CPU @ 2.90GHz
# 查看CPU支持的扩展指令集
# lscpu | grep Flags
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 invpcid_single intel_ppin ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts pku ospke avx512_vnni md_clear flush_l1d arch_capabilities
# 查看CPU温度
# sensors
coretemp-isa-0000
Adapter: ISA adapter
Package id 0: +38.0°C (high = +85.0°C, crit = +100.0°C)
Core 0: +36.0°C (high = +85.0°C, crit = +100.0°C)
Core 1: +37.0°C (high = +85.0°C, crit = +100.0°C)
Core 2: +36.0°C (high = +85.0°C, crit = +100.0°C)
Core 3: +38.0°C (high = +85.0°C, crit = +100.0°C)
# 1. 查看主板支持的CPU型号
# dmidecode -t baseboard | grep -E “Manufacturer|Product Name”
Manufacturer: Dell Inc.
Product Name: 0H3K5M
# 2. 查看BIOS版本
# dmidecode -t bios | grep -E “Vendor|Version|Release Date”
Vendor: Dell Inc.
Version: 2.8.1
Release Date: 12/15/2024
# 3. 检查当前CPU负载
# mpstat -P ALL 1 5
Linux 5.4.17-2136.302.7.2.el7uek.x86_64 (fgedu.net.cn) 04/03/2026 _x86_64_ (64 CPU)
10:00:00 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
10:00:01 AM all 5.23 0.00 1.25 0.50 0.00 0.25 0.00 0.00 0.00 92.77
10:00:01 AM 0 3.00 0.00 1.00 0.00 0.00 0.00 0.00 0.00 0.00 96.00
10:00:01 AM 1 4.00 0.00 2.00 0.00 0.00 1.00 0.00 0.00 0.00 93.00
# 4. 记录当前CPU配置
# lscpu > /backup/cpu_config_before.txt
# 查看新CPU信息
# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
CPU(s): 128
On-line CPU(s) list: 0-127
Thread(s) per core: 2
Core(s) per socket: 32
Socket(s): 2
NUMA node(s): 2
Vendor ID: GenuineIntel
CPU family: 6
Model: 143
Model name: Intel(R) Xeon(R) Gold 6346 CPU @ 3.10GHz
Stepping: 6
CPU MHz: 3100.000
CPU max MHz: 3800.0000
CPU min MHz: 800.0000
# 验证NUMA配置
# numactl –hardware
available: 2 nodes (0-1)
node 0 cpus: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
node 0 size: 128 GB
node 0 free: 125 GB
node 1 cpus: 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
node 1 size: 128 GB
node 1 free: 126 GB
node distances:
node 0 1
0: 10 21
1: 21 10
# 运行CPU压力测试
# stress –cpu 128 –timeout 60
stress: info: [12345] dispatching hogs: 128 cpu, 0 io, 0 vm, 0 hdd
stress: info: [12345] successful run completed in 60s
4. 存储升级操作
存储升级包括硬盘扩容、RAID配置调整、存储控制器升级等操作。学习交流加群风哥QQ113257174
# lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINT,MODEL
NAME SIZE TYPE FSTYPE MOUNTPOINT MODEL
sda 1.8T disk PERC H755
├─sda1 512M part vfat /boot/efi
├─sda2 1G part xfs /boot
└─sda3 1.8T part LVM_member
sdb 3.6T disk PERC H755
└─sdb1 3.6T part LVM_member
sdc 3.6T disk PERC H755
└─sdc1 3.6T part LVM_member
# 查看磁盘健康状态
# smartctl -a /dev/sda | grep -E “Model|Serial|Capacity|SMART overall”
Model Family: Dell PERC H755 Front (Dell)
Device Model: DELL PERC H755
Serial Number: ABCD1234
User Capacity: 1,928,510,423,040 bytes [1.82 TB]
SMART overall-health self-assessment test result: PASSED
# 查看磁盘性能
# hdparm -tT /dev/sda
/dev/sda:
Timing cached reads: 25824 MB in 1.99 seconds = 12978.45 MB/sec
Timing buffered disk reads: 1234 MB in 3.00 seconds = 411.33 MB/sec
# 1. 查看新添加的硬盘
# lsblk | grep sd
sda 1.8T disk
sdb 3.6T disk
sdc 3.6T disk
sdd 3.6T disk
sde 3.6T disk
# 2. 使用Dell工具创建RAID
# /opt/dell/srvadmin/bin/omconfig storage controller action=createvdisk controller=1 adisk=0:1:0,0:1:1 raid=r10 size=max readpolicy=ara writepolicy=wb
Command successful!
# 3. 查看新创建的虚拟磁盘
# /opt/dell/srvadmin/bin/omreport storage vdisk
List of Virtual Disks in the System
Controller PERC H755 Front (Slot 1)
ID : 1
Status : Ok
Name : Virtual Disk 1
State : Ready
Layout : RAID-10
Size : 3,591.00 GB (3,857,020,846,080 bytes)
Device Name : /dev/sdd
# 1. 创建物理卷
# pvcreate /dev/sdd
Physical volume “/dev/sdd” successfully created.
# 2. 创建卷组
# vgcreate vg_backup /dev/sdd
Volume group “vg_backup” successfully created
# 3. 创建逻辑卷
# lvcreate -l 100%FREE -n lv_backup vg_backup
Logical volume “lv_backup” created.
# 4. 格式化文件系统
# mkfs.xfs /dev/vg_backup/lv_backup
meta-data=/dev/vg_backup/lv_backup isize=512 agcount=4, agsize=235929600 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=943718400, imaxpct=5
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=460800, version=2
= sectsz=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
# 5. 挂载文件系统
# mkdir /backup
# mount /dev/vg_backup/lv_backup /backup
# 6. 添加到fstab
# echo “/dev/vg_backup/lv_backup /backup xfs defaults 0 0” >> /etc/fstab
# 7. 验证
# df -h /backup
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_backup-lv_backup 3.6T 33M 3.6T 1% /backup
5. 网络升级操作
网络升级包括网卡更换、网络带宽升级、网络拓扑调整等操作。
# ip addr show
1: lo:
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
2: eth0:
link/ether 00:11:22:33:44:55 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.10/24 brd 192.168.1.255 scope global eth0
valid_lft forever preferred_lft forever
# 查看网卡驱动信息
# ethtool -i eth0
driver: i40e
version: 2.22.18
firmware-version: 8.30 0x80008e3a 1.2740.0
expansion-rom-version:
bus-info: 0000:3b:00.0
supports-statistics: yes
supports-test: yes
supports-eeprom-access: yes
supports-register-dump: yes
supports-priv-flags: yes
# 查看网络统计信息
# ethtool -S eth0 | head -20
NIC statistics:
rx_packets: 123456789
tx_packets: 98765432
rx_bytes: 123456789012
tx_bytes: 98765432109
rx_broadcast: 123456
tx_broadcast: 65432
rx_multicast: 78901
tx_multicast: 34567
rx_errors: 0
tx_errors: 0
tx_dropped: 0
# 1. 加载bonding模块
# modprobe bonding
# 2. 创建bond配置文件
# cat > /etc/sysconfig/network-scripts/ifcfg-bond0 << EOF
DEVICE=bond0
NAME=bond0
TYPE=Bond
BONDING_MASTER=yes
IPADDR=192.168.1.10
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
BONDING_OPTS="mode=4 miimon=100 lacp_rate=1"
ONBOOT=yes
EOF
# 3. 配置从网卡
# cat > /etc/sysconfig/network-scripts/ifcfg-eth0 << EOF
DEVICE=eth0
NAME=eth0
TYPE=Ethernet
MASTER=bond0
SLAVE=yes
ONBOOT=yes
EOF
# cat > /etc/sysconfig/network-scripts/ifcfg-eth1 << EOF
DEVICE=eth1
NAME=eth1
TYPE=Ethernet
MASTER=bond0
SLAVE=yes
ONBOOT=yes
EOF
# 4. 重启网络服务
# systemctl restart NetworkManager
# 5. 验证bond状态
# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v5.4.17-2136.302.7.2.el7uek.x86_64
Bonding Mode: IEEE 802.3ad Dynamic link aggregation
Transmit Hash Policy: layer2 (0)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth0
MII Status: up
Speed: 25000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:11:22:33:44:55
Slave queue ID: 0
Aggregator ID: 1
Actor Churn State: none
Partner Churn State: none
Slave Interface: eth1
MII Status: up
Speed: 25000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:11:22:33:44:56
Slave queue ID: 0
Aggregator ID: 1
6. 迁移方案设计
服务器迁移需要制定详细的方案,确保业务平稳过渡。更多学习教程公众号风哥教程itpux_com
# cat > /opt/migration/checklist.txt << EOF 服务器迁移评估清单 ================== 1. 硬件评估 [ ] 新服务器硬件配置确认 [ ] 存储容量评估 [ ] 网络带宽评估 [ ] 电源功率评估 2. 软件评估 [ ] 操作系统版本兼容性 [ ] 应用软件版本兼容性 [ ] 中间件版本兼容性 [ ] 数据库版本兼容性 3. 数据评估 [ ] 数据总量统计 [ ] 数据迁移时间估算 [ ] 数据一致性校验方案 [ ] 数据备份方案 4. 网络评估 [ ] IP地址规划 [ ] DNS配置更新 [ ] 防火墙规则迁移 [ ] 负载均衡配置 5. 业务评估 [ ] 业务停机时间窗口 [ ] 业务影响范围 [ ] 回滚方案 [ ] 应急预案 EOF # 统计数据量 # du -sh /data /oracle /backup 3.6T /data 2.8T /oracle 1.5T /backup # 估算迁移时间 # echo "数据总量: 7.9TB" # echo "网络带宽: 10Gbps" # echo "预计迁移时间: $((7900 * 1024 * 1024 * 8 / 10000 / 3600)) 小时" 数据总量: 7.9TB 网络带宽: 10Gbps 预计迁移时间: 185 小时
# cat > /opt/migration/plan.md << EOF 服务器迁移计划 ============== 一、迁移目标 - 源服务器: fgedu-old (192.168.1.10) - 目标服务器: fgedu-new (192.168.1.20) - 迁移时间: 2026-04-05 22:00 - 2026-04-06 06:00 二、迁移步骤 阶段一: 准备阶段 (T-7天) 1. 新服务器硬件安装调试 2. 操作系统安装配置 3. 网络配置和安全加固 4. 依赖软件安装 阶段二: 预迁移 (T-3天) 1. 数据全量同步 2. 配置文件迁移 3. 应用部署测试 4. 数据一致性校验 阶段三: 迁移实施 (T日) 1. 停止业务服务 (22:00) 2. 增量数据同步 (22:00-23:00) 3. 最终数据校验 (23:00-00:00) 4. DNS切换 (00:00) 5. 服务启动验证 (00:00-01:00) 6. 业务验证 (01:00-02:00) 阶段四: 收尾阶段 (T+1天) 1. 监控观察 2. 旧服务器保留 3. 文档更新 三、回滚方案 - 保留旧服务器运行状态 - 准备快速切回脚本 - 回滚决策点: T日02:00前 EOF
7. 数据迁移实施
数据迁移是服务器迁移的核心环节,需要确保数据完整性和一致性。
# 1. 全量同步
# rsync -avz –progress /data/ root@192.168.1.20:/data/
sending incremental file list
./
file1.dat
file2.dat
dir1/
dir1/file3.dat
…
sent 3.67T bytes received 123456 bytes 45.67M bytes/sec
total size is 3.67T speedup is 1.00
# 2. 增量同步
# rsync -avz –delete –progress /data/ root@192.168.1.20:/data/
sending incremental file list
./
modified_file.dat
new_file.dat
sent 1.23G bytes received 456 bytes 12.34M bytes/sec
total size is 3.67T speedup is 2987.65
# 3. 数据校验
# cd /data && find . -type f -exec md5sum {} \; > /tmp/source_md5.txt
# ssh root@192.168.1.20 “cd /data && find . -type f -exec md5sum {} \;” > /tmp/target_md5.txt
# diff /tmp/source_md5.txt /tmp/target_md5.txt
# echo “数据校验完成,无差异”
# 1. 创建LVM快照
# lvcreate -L 100G -s -n lv_data_snap /dev/vg_data/lv_data
Logical volume “lv_data_snap” created.
# 2. 挂载快照
# mkdir /mnt/snap
# mount /dev/vg_data/lv_data_snap /mnt/snap
# 3. 同步快照数据
# rsync -avz /mnt/snap/ root@192.168.1.20:/data/
# 4. 卸载并删除快照
# umount /mnt/snap
# lvremove /dev/vg_data/lv_data_snap
Do you really want to remove active logical volume vg_data/lv_data_snap? [y/n]: y
Logical volume “lv_data_snap” successfully removed
# 使用存储复制(如需要)
# 在存储阵列上配置远程复制
# 查看复制状态
# /opt/storage/bin/replication_status.sh
Replication Pair: fgedu_data
Status: Synchronized
Progress: 100%
Last Sync: 2026-04-03 10:00:00
8. 应用迁移实施
应用迁移需要确保应用配置和运行环境的正确迁移。author:www.itpux.com
# 1. 打包应用配置
# tar -czvf /backup/app_config.tar.gz /etc/nginx /etc/systemd/system/*.service /opt/app/config
# 2. 传输配置文件
# scp /backup/app_config.tar.gz root@192.168.1.20:/backup/
# 3. 在目标服务器解压
# ssh root@192.168.1.20 “cd / && tar -xzvf /backup/app_config.tar.gz”
# 迁移数据库
# 1. 导出数据库
# mysqldump -u root -p –all-databases –single-transaction –master-data=2 > /backup/all_databases.sql
Enter password:
# 验证导出文件
# ls -lh /backup/all_databases.sql
-rw-r–r– 1 root root 15G Apr 3 10:00 /backup/all_databases.sql
# 2. 传输数据库文件
# rsync -avz –progress /backup/all_databases.sql root@192.168.1.20:/backup/
# 3. 导入数据库
# ssh root@192.168.1.20 “mysql -u root -p < /backup/all_databases.sql"
# 1. 迁移WebLogic配置
# tar -czvf /backup/weblogic_config.tar.gz /opt/IBM/WebSphere/AppServer/profiles/fgedu_dmgr01/config
# 2. 迁移Tomcat配置
# tar -czvf /backup/tomcat_config.tar.gz /opt/tomcat/conf /opt/tomcat/webapps
# 3. 迁移Nginx配置
# tar -czvf /backup/nginx_config.tar.gz /etc/nginx /var/log/nginx
# 迁移定时任务
# 1. 导出crontab
# crontab -l > /backup/crontab_backup.txt
# 2. 在目标服务器导入
# ssh root@192.168.1.20 “crontab /backup/crontab_backup.txt”
# 迁移系统用户
# 1. 导出用户信息
# awk -F: ‘$3 >= 1000 {print $0}’ /etc/passwd > /backup/users.txt
# awk -F: ‘$3 >= 1000 {print $0}’ /etc/group > /backup/groups.txt
# awk -F: ‘$3 >= 1000 {print $0}’ /etc/shadow > /backup/shadows.txt
# 2. 在目标服务器创建用户
# while read line; do
user=$(echo $line | cut -d: -f1)
uid=$(echo $line | cut -d: -f3)
gid=$(echo $line | cut -d: -f4)
home=$(echo $line | cut -d: -f6)
shell=$(echo $line | cut -d: -f7)
useradd -u $uid -g $gid -d $home -s $shell $user
done < /backup/users.txt
9. 验证与测试
迁移完成后需要进行全面的验证和测试,确保系统正常运行。
# 1. 检查系统服务状态
# systemctl list-units –type=service –state=running | grep -E “nginx|mysql|java”
nginx.service loaded active running The nginx HTTP and reverse proxy server
mysql.service loaded active running MySQL Server
weblogic.service loaded active running WebLogic Server
# 2. 检查端口监听
# netstat -tlnp | grep -E “80|443|3306|7001”
tcp6 0 0 :::80 :::* LISTEN 1234/nginx
tcp6 0 0 :::443 :::* LISTEN 1234/nginx
tcp6 0 0 :::3306 :::* LISTEN 2345/mysqld
tcp6 0 0 :::7001 :::* LISTEN 3456/java
# 3. 检查磁盘空间
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ol-root 500G 15G 485G 3% /
/dev/mapper/vg_data-lv_data 3.6T 2.8T 800G 78% /data
/dev/mapper/vg_backup-lv_backup 3.6T 33M 3.6T 1% /backup
# 4. 检查内存使用
# free -h
total used free shared buff/cache available
Mem: 251Gi 45Gi 200Gi 1.2Gi 5.5Gi 203Gi
Swap: 32Gi 0B 32Gi
# 1. Web服务验证
# curl -I http://fgedudb
HTTP/1.1 200 OK
Server: nginx/1.24.0
Date: Thu, 03 Apr 2026 10:00:00 GMT
Content-Type: text/html
Connection: keep-alive
# 2. 数据库连接验证
# mysql -u root -p -e “SELECT 1”
Enter password:
+—+
| 1 |
+—+
| 1 |
+—+
# 3. 应用接口验证
# curl -s http://fgedudb:8080/api/health | jq .
{
“status”: “UP”,
“components”: {
“db”: {
“status”: “UP”
},
“diskSpace”: {
“status”: “UP”
}
}
}
# 4. 性能测试
# ab -n 10000 -c 100 http://fgedudb/
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd
…
Complete requests: 10000
Failed requests: 0
Total transferred: 51200000 bytes
HTML transferred: 25600000 bytes
Requests per second: 5678.91 [#/sec] (mean)
Time per request: 17.608 [ms] (mean)
Time per request: 0.176 [ms] (mean, across all concurrent requests)
Transfer rate: 28394.56 [Kbytes/sec] received
10. 回滚方案与应急预案
制定完善的回滚方案和应急预案,确保迁移失败时能够快速恢复。
# cat > /opt/migration/rollback.sh << 'EOF' #!/bin/bash echo "开始执行回滚操作..." echo "时间: $(date)" # 1. 停止新服务器服务 echo "停止新服务器服务..." ssh root@192.168.1.20 "systemctl stop nginx mysql weblogic" # 2. 切换DNS echo "切换DNS记录..." nsupdate << EOF server dns.fgedu.net.cn zone fgedu.net.cn update delete fgedu.net.cn A update add fgedu.net.cn 300 A 192.168.1.10 send EOF # 3. 启动旧服务器服务 echo "启动旧服务器服务..." systemctl start nginx mysql weblogic # 4. 验证服务 echo "验证服务状态..." sleep 10 curl -I http://fgedudb echo "回滚完成!" echo "时间: $(date)" EOF chmod +x /opt/migration/rollback.sh
# cat > /opt/migration/emergency_plan.md << EOF 服务器迁移应急预案 ================== 一、常见问题及处理 1. 数据同步失败 现象: rsync报错,数据不完整 处理: - 检查网络连接 - 检查磁盘空间 - 重新执行同步 - 必要时执行回滚 2. 服务启动失败 现象: 应用无法正常启动 处理: - 检查日志文件 - 检查配置文件 - 检查端口占用 - 检查依赖服务 3. 数据库连接失败 现象: 应用无法连接数据库 处理: - 检查数据库服务状态 - 检查网络连接 - 检查用户权限 - 检查连接配置 4. 性能异常 现象: 系统响应缓慢 处理: - 检查资源使用 - 检查系统负载 - 检查网络延迟 - 必要时回滚 二、联系人信息 - 项目负责人: 风哥 13800138000 - 网络管理员: 风哥1号 13900139000 - 数据库管理员: 风哥2号 13700137000 - 应用管理员: 王五 13600136000 三、决策流程 1. 发现问题 -> 评估影响 -> 上报负责人
2. 30分钟内无法解决 -> 启动回滚
3. 回滚后 -> 分析原因 -> 制定改进方案
EOF
本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html
