![在新硬件上从软件 RAID 和 EXT3 迁移到 RAID-Z?](https://linux22.com/image/885497/%E5%9C%A8%E6%96%B0%E7%A1%AC%E4%BB%B6%E4%B8%8A%E4%BB%8E%E8%BD%AF%E4%BB%B6%20RAID%20%E5%92%8C%20EXT3%20%E8%BF%81%E7%A7%BB%E5%88%B0%20RAID-Z%EF%BC%9F.png)
我有一台现有的、实时的 Ubuntu 服务器...支持许多服务,运行良好 - 但安装在老化的硬件上。我想在新硬件上保留(几乎)相同的配置 - 但采用 ZFS 和 RAID-Z 代替旧服务器上现有的软件 RAID 和 EXT-3 解决方案。
我在新服务器上安装了 Ubuntu,并将其暴露到我的 LAN(在不同的静态 IP 上),并建立了合适的 ZFS 配置。迁移众多服务(例如邮件、Web 应用程序、VPN、代理、防火墙、数据库等)的配置比我最初预想的要复杂得多。如果采用“手动”迁移策略,我预计停机时间会比可接受的要长得多。
是否有任何工具可以使此过程更容易(并且更不容易出错)?是否有更简单的策略可以实现相同的最终结果?
答案1
克隆机器的方法有很多种。制作映像,然后在其他硬件上恢复映像。但是,如果您想将服务器移动到新硬件,停机时间很短(几分钟内),您可以使用本文。本文假设使用 Debian Linux 系统,但这也适用于 Ubuntu。
安装基础系统
在开始热克隆之前,您需要做以下几件事:
正在运行的最小安装(最多需要 10 分钟) 正在运行的网卡 按照您希望的方式安装的磁盘和分区 安装了 ssh 和 rsync 没有其他正在运行的服务(除了 sshd,如果您像示例中那样远程执行此操作)。停止 inetd、atd、crond、klogd、syslogd
同步数据
使用 rsync,我们可以将 old_machine 同步到 new_machine。rsync 仅传输差异,因此您可以随时停止并重新启动 rsync,也可以在几天后重新同步而无需从头开始,或者重新运行 rsync 以传输所有已更改的文件。
排除 rsync 的模式
某些文件不应传输,因为它们是硬件特定的、默认可用的、或自动生成的。
这些特定于您的硬件和分区设置:
/boot/
/lib/modules
/etc/modules
/etc/lilo.conf
/etc/fstab
/etc/mtab
这些已经可用。/proc
是运行内核提供的虚拟文件系统,/dev
是来自基础安装的设备树,lost+found
是在分区格式化期间创建的目录:
/proc
/dev
lost+found/
排除这些是因为您想要为每台机器保留单独的日志,并且您希望(现在)为每台机器设置不同的网络:
/var/log
/etc/network/interfaces
排除文件包含所有这些条目,每个条目占一行。如果不清楚,请参阅man rsync
这是一个示例 hotclone_exclude 文件,您可以将其存储在 /root 目录中并使用 rsync 命令引用:
/boot/
/lib/modules
/etc/modules
/etc/lilo.conf
/etc/fstab
/etc/mtab
/proc
/dev
lost+found/
/var/log
/etc/network/interfaces
/root
警告:如果您有网络安装,您也需要将它们添加到排除文件中!
同步数据
rsync -e ssh -avz --exclude-from=/root/hotclone_exclude old_server:/ /
切换服务器!
停止 old_server 上的服务
重新运行 rsync(由于大多数传输已经完成,因此不会花费很长时间)
更新 new_server 上的 /etc/network/interfaces 以包含 old_server 的 IP 地址 在 old_server 上运行 ifdown -a 在 new_server 上运行 ifdown -a 在 new_server 上运行 ifup -a
将旧服务器不加改变地放在一边作为备用(小心为上)。
一切已准备就绪。
进一步注意:如果您需要从特定包中排除文件,您可以使用 apt-file 获取它们,它将为apt-file packagename
您提供该包中的文件列表及其安装位置。
例子:
$apt-file list trash-cli
trash-cli: /usr/bin/restore-trash
trash-cli: /usr/bin/trash
trash-cli: /usr/bin/trash-empty
trash-cli: /usr/bin/trash-list
trash-cli: /usr/bin/trash-put
trash-cli: /usr/lib/python2.7/dist-packages/integration_tests/__init__.py
trash-cli: /usr/lib/python2.7/dist-packages/integration_tests/assert_equals_with_unidiff.py
trash-cli: /usr/lib/python2.7/dist-packages/integration_tests/describe_trash_list.py
trash-cli: /usr/lib/python2.7/dist-packages/integration_tests/files.py
trash-cli: /usr/lib/python2.7/dist-packages/integration_tests/output_collector.py
trash-cli: /usr/lib/python2.7/dist-packages/integration_tests/test_file_descriptions.py
trash-cli: /usr/lib/python2.7/dist-packages/integration_tests/test_filesystem.py
trash-cli: /usr/lib/python2.7/dist-packages/integration_tests/test_persist.py
trash-cli: /usr/lib/python2.7/dist-packages/integration_tests/test_restore_trash.py
trash-cli: /usr/lib/python2.7/dist-packages/integration_tests/test_trash_empty.py
trash-cli: /usr/lib/python2.7/dist-packages/integration_tests/test_trash_put.py
trash-cli: /usr/lib/python2.7/dist-packages/integration_tests/trashinfo.py
trash-cli: /usr/lib/python2.7/dist-packages/trash_cli-0.12.7.egg-info/PKG-INFO
trash-cli: /usr/lib/python2.7/dist-packages/trash_cli-0.12.7.egg-info/SOURCES.txt
trash-cli: /usr/lib/python2.7/dist-packages/trash_cli-0.12.7.egg-info/dependency_links.txt
trash-cli: /usr/lib/python2.7/dist-packages/trash_cli-0.12.7.egg-info/entry_points.txt
trash-cli: /usr/lib/python2.7/dist-packages/trash_cli-0.12.7.egg-info/top_level.txt
trash-cli: /usr/lib/python2.7/dist-packages/trashcli/__init__.py
trash-cli: /usr/lib/python2.7/dist-packages/trashcli/cmds.py
trash-cli: /usr/lib/python2.7/dist-packages/trashcli/list_mount_points.py
trash-cli: /usr/lib/python2.7/dist-packages/trashcli/trash.py
trash-cli: /usr/lib/python2.7/dist-packages/unit_tests/test_available_trash_dirs.py
trash-cli: /usr/lib/python2.7/dist-packages/unit_tests/test_characterization.py
trash-cli: /usr/lib/python2.7/dist-packages/unit_tests/test_joining_paths.py
trash-cli: /usr/lib/python2.7/dist-packages/unit_tests/test_list_mount_points.py
trash-cli: /usr/lib/python2.7/dist-packages/unit_tests/test_parser.py
trash-cli: /usr/lib/python2.7/dist-packages/unit_tests/test_parsing_trashinfo_contents.py
trash-cli: /usr/lib/python2.7/dist-packages/unit_tests/test_trash.py
trash-cli: /usr/lib/python2.7/dist-packages/unit_tests/test_trash_new_tests.py
trash-cli: /usr/lib/python2.7/dist-packages/unit_tests/test_trash_put.py
trash-cli: /usr/lib/python2.7/dist-packages/unit_tests/test_trashdir.py
trash-cli: /usr/share/doc/trash-cli/changelog.Debian.gz
trash-cli: /usr/share/doc/trash-cli/copyright
trash-cli: /usr/share/man/man1/restore-trash.1.gz
trash-cli: /usr/share/man/man1/trash-empty.1.gz
trash-cli: /usr/share/man/man1/trash-list.1.gz
trash-cli: /usr/share/man/man1/trash-put.1.gz
trash-cli: /usr/share/man/man1/trash.1.gz
trash-cli: /usr/share/pyshared/integration_tests/__init__.py
trash-cli: /usr/share/pyshared/integration_tests/assert_equals_with_unidiff.py
trash-cli: /usr/share/pyshared/integration_tests/describe_trash_list.py
trash-cli: /usr/share/pyshared/integration_tests/files.py
trash-cli: /usr/share/pyshared/integration_tests/output_collector.py
trash-cli: /usr/share/pyshared/integration_tests/test_file_descriptions.py
trash-cli: /usr/share/pyshared/integration_tests/test_filesystem.py
trash-cli: /usr/share/pyshared/integration_tests/test_persist.py
trash-cli: /usr/share/pyshared/integration_tests/test_restore_trash.py
trash-cli: /usr/share/pyshared/integration_tests/test_trash_empty.py
trash-cli: /usr/share/pyshared/integration_tests/test_trash_put.py
trash-cli: /usr/share/pyshared/integration_tests/trashinfo.py
trash-cli: /usr/share/pyshared/trash_cli-0.12.7.egg-info/PKG-INFO
trash-cli: /usr/share/pyshared/trash_cli-0.12.7.egg-info/SOURCES.txt
trash-cli: /usr/share/pyshared/trash_cli-0.12.7.egg-info/dependency_links.txt
trash-cli: /usr/share/pyshared/trash_cli-0.12.7.egg-info/entry_points.txt
trash-cli: /usr/share/pyshared/trash_cli-0.12.7.egg-info/top_level.txt
trash-cli: /usr/share/pyshared/trashcli/__init__.py
trash-cli: /usr/share/pyshared/trashcli/cmds.py
trash-cli: /usr/share/pyshared/trashcli/list_mount_points.py
trash-cli: /usr/share/pyshared/trashcli/trash.py
trash-cli: /usr/share/pyshared/unit_tests/test_available_trash_dirs.py
trash-cli: /usr/share/pyshared/unit_tests/test_characterization.py
trash-cli: /usr/share/pyshared/unit_tests/test_joining_paths.py
trash-cli: /usr/share/pyshared/unit_tests/test_list_mount_points.py
trash-cli: /usr/share/pyshared/unit_tests/test_parser.py
trash-cli: /usr/share/pyshared/unit_tests/test_parsing_trashinfo_contents.py
trash-cli: /usr/share/pyshared/unit_tests/test_trash.py
trash-cli: /usr/share/pyshared/unit_tests/test_trash_new_tests.py
trash-cli: /usr/share/pyshared/unit_tests/test_trash_put.py
trash-cli: /usr/share/pyshared/unit_tests/test_trashdir.py
如果你没有,你可以使用以下方式安装sudo apt install apt-file
有关更多有用的工具,请参阅@drysdam 回答这里和@Ressu 回答这里
资料来源:
http://olivier.sessink.nl/publications/hotcloning/
http://olivier.sessink.nl/publications/hotcloning/exclude.txt
man rsync
https://superuser.com/questions/82923/how-to-list-files-of-a-debian-package-without-install