文書の表示以前のリビジョンバックリンク文書の先頭へ この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。 ====== Fedora VPS サーバーを rsync で複製する😍 ====== 転送元: skv001 転送先: skv0001 とする。\\ ===== rsyncによる複製 ===== ==== 転送先(skv0001)の前準備 ==== === rsync をインストールしておく === <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">dnf</font> install <font color="#A347BA">-y</font> rsync </pre></html></WRAP> </WRAP> === sudo の後もエージェントフォワードを引き継ぐ方法 === <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">visudo</font> </pre></html></WRAP> <WRAP color_mincode><html><pre> <font color="#FF5F5F">Defaults</font><font color="#FFFFFF"> env_keep = </font><font color="#D7D787">"COLORS DISPLAY HOSTNAME HISTSIZE KDEDIR LS_COLORS"</font> <font color="#FF5F5F">Defaults</font><font color="#FFFFFF"> env_keep += </font><font color="#D7D787">"MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE"</font> <font color="#FF5F5F">Defaults</font><font color="#FFFFFF"> env_keep += </font><font color="#D7D787">"LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES"</font> <font color="#FF5F5F">Defaults</font><font color="#FFFFFF"> env_keep += </font><font color="#D7D787">"LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE"</font> <font color="#FF5F5F">Defaults</font><font color="#FFFFFF"> env_keep += </font><font color="#D7D787">"LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY"</font> <font color="#FF5F5F">Defaults</font><font color="#FFFFFF"> env_keep += </font><font color="#D7D787">"SSH_AUTH_SOCK"</font> </pre></html></WRAP> </WRAP> ※env_keep の最後尾に **Defaults env_keep += "SSH_AUTH_SOCK"** を追記する。 === 一時的に ssh での root ログインを許可 === sshd の設定 <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">vi</font> <u style="text-decoration-style:solid">/etc/ssh/sshd_config</u> </pre></html></WRAP> <WRAP color_mincode><html><pre> <font color="#FF5F5F">PermitRootLogin</font><font color="#FFFFFF"> yes</font> <font color="#FF5F5F">PasswordAuthentication</font><font color="#FFFFFF"> yes</font> </pre></html></WRAP> </WRAP> sshd の設定反映 <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">systemctl</font> restart sshd </pre></html></WRAP> </WRAP> root の公開キーを登録 <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">mkdir</font> /root/.ssh <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">nano</font> /root/.ssh/authorized_keys </pre></html></WRAP> <WRAP color_mincode><html><pre> ecdsa-sha2-nistp521 AAAAE2VjZHNhLXNo... </pre></html></WRAP> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">chmod</font> 700 /root/.ssh <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">chmod</font> 600 /root/.ssh/authorized_keys </pre></html></WRAP> </WRAP> ==== rsync 転送開始 ==== 転送元(skv001)で以下のコマンドを実行する。\\ <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">rsync</font> <font color="#A347BA">-rtlzvogpHAXP</font> <font color="#A347BA">--delete</font> <font color="#A347BA">--exclude</font> <u style="text-decoration-style:solid">/dev/</u> <font color="#A347BA">--exclude</font> <u style="text-decoration-style:solid">/proc/</u> <font color="#A347BA">--exclude</font> <u style="text-decoration-style:solid">/sys/</u> <font color="#A347BA">--exclude</font> <u style="text-decoration-style:solid">/var/run/</u> <font color="#A347BA">--exclude</font> <u style="text-decoration-style:solid">/var/lock/</u> <font color="#A347BA">--exclude</font> ifcfg<font color="#12488B"><b>*</b></font> <font color="#A347BA">--exclude</font> ssh_host_<font color="#12488B"><b>*</b></font> <font color="#A347BA">--exclude</font> fstab <font color="#A347BA">--block-size=4096</font> <font color="#A347BA">-e</font> <font color="#A2734C">"ssh -p12345"</font> <u style="text-decoration-style:solid">/</u> skv0001:/ </pre></html></WRAP> <WRAP color_result><html><pre> [sudo] tomoyan のパスワード: The authenticity of host '[skv0001]:12345 ([2401:2500:102:3014:153:126:156:195]:12345)' can't be established. ECDSA key fingerprint is SHA256:qPFDtQYOONtw4n5VXMhJ8+ArBePgdR9uPS0vCndYbTc. Are you sure you want to continue connecting (yes/no/[fingerprint])? <b class=DiYE>yes</b> root@skv0001's password: sending incremental file list 〜省略〜 sent 736,315,419 bytes received 1,528,581 bytes 1,585,056.93 bytes/sec total size is 3,347,008,738 speedup is 4.54 </pre></html></WRAP> </WRAP> ==== 転送元と転送先でファイルシステムが違う、または、パーティション構成が違う場合 ==== **転送先(skv0001)を再起動**する前に以下の手順が必要である。\\ <wrap em>注意!! これを行ってから再起動しないと転送先が起動不能になる。</wrap>\\ === 転送元 === 転送元は LVM の ext4 ファイルシステムである。 <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">parted</font> <font color="#A347BA">-l</font> </pre></html></WRAP> <WRAP color_result><html><pre> モデル: HPT VD12-0 (scsi) ディスク /dev/sdb: 1000GB セクタサイズ (論理/物理): 512B/512B パーティションテーブル: msdos ディスクフラグ: 番号 開始 終了 サイズ タイプ ファイルシステム フラグ 1 1049kB 1000GB 1000GB primary lvm モデル: HPT VD12-1 (scsi) ディスク /dev/sdc: 7001GB セクタサイズ (論理/物理): 512B/512B パーティションテーブル: gpt ディスクフラグ: 番号 開始 終了 サイズ ファイルシステム 名前 フラグ 1 1049kB 7001GB 7001GB lvm </pre></html></WRAP> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269">df</font> <font color="#A347BA">-BM</font> <font color="#A347BA">-T</font> </pre></html></WRAP> <WRAP color_result><html><pre> ファイルシス タイプ 1M-ブロック 使用 使用可 使用% マウント位置 devtmpfs devtmpfs 8012M 0M 8012M 0% /dev tmpfs tmpfs 8024M 1M 8024M 1% /dev/shm tmpfs tmpfs 8024M 2M 8022M 1% /run tmpfs tmpfs 8024M 0M 8024M 0% /sys/fs/cgroup /dev/mapper/fedora-root ext4 9952M 244M 9180M 3% / /dev/mapper/fedora-usr ext4 9952M 4529M 4895M 49% /usr tmpfs tmpfs 8024M 1M 8024M 1% /tmp /dev/mapper/fedora-home ext4 4912M 449M 4191M 10% /home /dev/mapper/fedora-boot ext4 614M 206M 364M 37% /boot /dev/mapper/fedora-var ext4 7468524M 6138649M 1017249M 86% /var tmpfs tmpfs 1605M 1M 1605M 1% /run/user/42 tmpfs tmpfs 1605M 0M 1605M 0% /run/user/1001 </pre></html></WRAP> </WRAP> === 転送先 === 転送先は btrfs ファイルシステムである。 <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">parted</font> <font color="#A347BA">-l</font> </pre></html></WRAP> <WRAP color_result><html><pre> モデル: Virtio Block Device (virtblk) ディスク /dev/vda: 275GB セクタサイズ (論理/物理): 512B/512B パーティションテーブル: msdos ディスクフラグ: 番号 開始 終了 サイズ タイプ ファイルシステム フラグ 1 1049kB 525MB 524MB primary ext4 boot 2 525MB 2690MB 2164MB primary linux-swap(v1) 3 2690MB 275GB 272GB primary btrfs </pre></html></WRAP> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269">df</font> <font color="#A347BA">-BM</font> <font color="#A347BA">-T</font> </pre></html></WRAP> <WRAP color_result><html><pre> ファイルシス タイプ 1M-ブロック 使用 使用可 使用% マウント位置 /dev/vda3 btrfs 259579M 10458M 247838M 5% / devtmpfs devtmpfs 995M 0M 995M 0% /dev tmpfs tmpfs 1002M 0M 1002M 0% /dev/shm tmpfs tmpfs 1002M 2M 1001M 1% /run tmpfs tmpfs 1002M 0M 1002M 0% /sys/fs/cgroup tmpfs tmpfs 1002M 1M 1002M 1% /tmp /dev/vda3 btrfs 259579M 10458M 247838M 5% /home /dev/vda1 ext4 477M 207M 245M 46% /boot tmpfs tmpfs 201M 0M 201M 0% /run/user/1001 </pre></html></WRAP> </WRAP> === 転送先で再起動してしまう前に GRUB2 を再インストールする === <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">grub2-install</font> /dev/vda </pre></html></WRAP> <WRAP color_result><html><pre> Installing for i386-pc platform. Installation finished. No error reported. </pre></html></WRAP> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">grub2-mkconfig</font> <font color="#A347BA">-o</font> /boot/grub2/grub.cfg </pre></html></WRAP> <WRAP color_result><html><pre> enerating grub configuration file ... Found linux image: /boot/vmlinuz-4.1.10-200.fc22.x86_64 Found initrd image: /boot/initramfs-4.1.10-200.fc22.x86_64.img Found linux image: /boot/vmlinuz-4.1.8-100.fc21.x86_64 Found linux image: /boot/vmlinuz-4.0.4-202.fc21.x86_64 Found initrd image: /boot/initramfs-4.0.4-202.fc21.x86_64.img Found linux image: /boot/vmlinuz-0-rescue-7725dfc225d14958a625ddaaaea5962b Found initrd image: /boot/initramfs-0-rescue-7725dfc225d14958a625ddaaaea5962b.img done </pre></html></WRAP> </WRAP> === 最新 kernel の initramfs を再作成する === <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">cp</font> /boot/initramfs-4.1.10-200.fc22.x86_64.img /boot/initramfs-4.1.10-200.fc22.x86_64.img.bak <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">dracut</font> <font color="#A347BA">-f</font> /boot/initramfs-4.1.10-200.fc22.x86_64.img 4.1.10-200.fc22.x86_64 </pre></html></WRAP> </WRAP> ==== 転送先(skv0001)を再起動 ==== <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269">ssh</font> skv0001 <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">reboot</font> </pre></html></WRAP> <WRAP color_result><html><pre> Connection to skv0001 closed by remote host. Connection to skv0001 closed. </pre></html></WRAP> </WRAP> ==== 転送元(skv001)の前準備 ==== httpd、mysql-server、sendmailなどのサービスを停止する🤔\\ ※サービスを停止した状態で複製する必要があるもの...😉\\ <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269">ssh</font> skv001 <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">systemctl</font> stop httpd <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">systemctl</font> stop mariadb </pre></html></WRAP> </WRAP> ==== rsync 転送(2回目)開始 ==== 転送元(skv001)で以下のコマンドを実行する。\\ <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">rsync</font> <font color="#A347BA">-rtlzvogpHAXP</font> <font color="#A347BA">--delete</font> <font color="#A347BA">--exclude</font> <u style="text-decoration-style:solid">/dev/</u> <font color="#A347BA">--exclude</font> <u style="text-decoration-style:solid">/proc/</u> <font color="#A347BA">--exclude</font> <u style="text-decoration-style:solid">/sys/</u> <font color="#A347BA">--exclude</font> <u style="text-decoration-style:solid">/var/run/</u> <font color="#A347BA">--exclude</font> <u style="text-decoration-style:solid">/var/lock/</u> <font color="#A347BA">--exclude</font> ifcfg<font color="#12488B"><b>*</b></font> <font color="#A347BA">--exclude</font> ssh_host_<font color="#12488B"><b>*</b></font> <font color="#A347BA">--exclude</font> fstab <font color="#A347BA">--block-size=4096</font> <font color="#A347BA">-e</font> <font color="#A2734C">"ssh -p12345"</font> <u style="text-decoration-style:solid">/</u> skv0001:/ </pre></html></WRAP> <WRAP color_result><html><pre> [sudo] tomoyan のパスワード: root@skv0001's password: sending incremental file list 〜省略〜 sent 4,864,296 bytes received 243,750 bytes 101,149.43 bytes/sec total size is 3,334,430,460 speedup is 652.78 </pre></html></WRAP> </WRAP> === ssh の root ログインを拒否に戻す === sshd の設定 <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">nano</font> <u style="text-decoration-style:solid">/etc/ssh/sshd_config</u> </pre></html></WRAP> <WRAP color_mincode><html><pre> <font color="#FF5F5F">PermitRootLogin</font><font color="#FFFFFF"> no</font> <font color="#FF5F5F">PasswordAuthentication</font><font color="#FFFFFF"> no</font> </pre></html></WRAP> </WRAP> sshd の設定反映 <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">systemctl</font> restart sshd </pre></html></WRAP> </WRAP> ==== 転送元 (skv001) の SoftEther VPN を停止する ==== tomoyan.softether.net を取り合うので skv001 のサービスを停止する。\\ <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">systemctl</font> stop softether-vpnserver <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">systemctl</font> stop softether-vpnclient <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">systemctl</font> disable softether-vpnserver </pre></html></WRAP> <WRAP color_result><html><pre> Removed /etc/systemd/system/multi-user.target.wants/softether-vpnserver.service. </pre></html></WRAP> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">systemctl</font> disable softether-vpnclient </pre></html></WRAP> <WRAP color_result><html><pre> Removed /etc/systemd/system/multi-user.target.wants/softether-vpnclient.service. </pre></html></WRAP> </WRAP> ===== 参考文献 ===== [[system_manage:fedora_29_vps_duplicate|Fedora 29 VPS の複製]] (非公開)\\ <del>[[|さくらのVPSで上位プランに移行するための手順 - さくらインターネット創業日記]]</del>\\ [[http://www.drk7.jp/MT/archives/001862.html|さくら VPS 旧プランから 2G 新プランへの移行手順 :: drk7jp]]\\ ==== 付録 ==== [[tw>tomoyan596/status/1364969792873111557|さぁ、お腹も満たされたので、データセンター内で数百GBなお引越しを開始します🤤 / Twitter]]\\ [[tw>tomoyan596/status/1364992372275224576|お引越し先が、ご臨終しました😅💦 / Twitter]]\\ [[tw>tomoyan596/status/1365125896932220928|転送先のsshホストキー🔑のグループがおかしくなり、再セットが必要になって起動不能になった原因が不明です🤯GIDは一致しています🤔 / Twitter]]\\ linux/rsync/fedora_vps_duplicate.txt 最終更新: 2025/02/26 17:54by ともやん