Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
Data replication is a critical process in maintaining data availability, redundancy, and disaster recovery in any IT environment. In a Linux environment, data replication ensures that data is consistently copied from one location to another, allowing for seamless access and recovery in case of hardware failure or other issues. This article will guide you through the process of setting up data replication in Linux using tools like rsync and DRBD (Distributed Replicated Block Device).
Examples:
rsync
is a powerful and versatile command-line utility for synchronizing files and directories between two locations over a network or locally. It is commonly used for backups and mirroring.
Install rsync:
sudo apt-get update
sudo apt-get install rsync
Basic rsync Command: To replicate data from a source directory to a destination directory:
rsync -avz /path/to/source/ /path/to/destination/
-a
: Archive mode (preserves permissions, symbolic links, etc.)-v
: Verbose (provides detailed output)-z
: Compress data during transferUsing rsync Over SSH: To replicate data to a remote server:
rsync -avz -e ssh /path/to/source/ user@remote_host:/path/to/destination/
DRBD
is a distributed replicated storage system for the Linux platform. It mirrors the content of block devices (such as hard disks, partitions, or logical volumes) between hosts.
Install DRBD:
sudo apt-get update
sudo apt-get install drbd-utils
Configure DRBD:
Edit the DRBD configuration file (/etc/drbd.d/global_common.conf
) and define the resources in /etc/drbd.d/myresource.res
.
Example configuration (/etc/drbd.d/myresource.res
):
resource myresource {
on node1 {
device /dev/drbd0;
disk /dev/sda1;
address 192.168.1.1:7788;
meta-disk internal;
}
on node2 {
device /dev/drbd0;
disk /dev/sdb1;
address 192.168.1.2:7788;
meta-disk internal;
}
}
Initialize DRBD:
sudo drbdadm create-md myresource
sudo drbdadm up myresource
Primary/Secondary Setup: On the primary node:
sudo drbdadm -- --overwrite-data-of-peer primary myresource
Verify DRBD Status:
cat /proc/drbd
Mount the DRBD Device: On the primary node:
sudo mkfs.ext4 /dev/drbd0
sudo mount /dev/drbd0 /mnt