1、单向同步A->B
主机A,IP:192.168.0.135
[root@server35 ~]# yum install rsync -y
[root@server35 ~]# yum install xinetd -y
[root@server35 ~]# mkdir /opt/sersync
[root@server35 ~]# vim /etc/rsyncd.conf
uid=root
gid=root
max connections=36000
use chroot=no
log file=/var/log/rsyncd.log
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock
[sersync]
path=/opt/sersync
comment = test files
ignore errors = yes
read only = no
hosts allow = 192.168.0.152
hosts deny = *
[root@server35 ~]# vim /etc/xinetd.d/rsync
disable = no
[root@server35 ~]# /etc/init.d/xinetd restart
主机B,IP192.168.0.152
lftp i:~> get pub/docs/sersync/sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@test ~]# tar zxf sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@test ~]# yum install rsync xinetd -y
[root@test ~]# mkdir /opt/tongbu
[root@server35 ~]# vim /etc/xinetd.d/rsync
disable = no
[root@server35 GNU-Linux-x86]# /etc/init.d/xinetd restart
[root@test GNU-Linux-x86]# vim confxml.xml
<attrib start="true"/>
<modify start="true"/>
<sersync>
<localpath watch="/opt/tongbu">
<remote ip="192.168.2.135" name="sersync"/>
[root@test GNU-Linux-x86]# ./sersync2 -r -d
然后在tongbu中建立文件就会同步到135的sersync
2、添加一个同步目录
A主机:
[root@server35 opt]# mkdir sersync1
[root@server35 opt]# vim /etc/rsyncd.conf 添加
[sersync1]
path=/opt/sersync1
comment = test files
ignore errors = yes
read only = no
hosts allow = 192.168.0.152
hosts deny = *
[root@server35 opt]# /etc/init.d/xinetd restart
B主机:
[root@test GNU-Linux-x86]# cp confxml.xml confxml-1.xml
[root@test GNU-Linux-x86]# vim confxml-1.xml
<sersync>
<localpath watch="/opt/tongbu1">
<remote ip="192.168.2.135" name="sersync1"/>
[root@test GNU-Linux-x86]# mkdir /opt/tongbu1
[root@test GNU-Linux-x86]# ./sersync2 -r -d -o confxml-1.xml
tongbu1就会和sersync1同步
3、DRDB双向同步
[root@server35 ~]# yum install make gcc rpm-build flex kernel-devel -y
lftp i:~> get pub/docs/drbd/rhel6/drbd-8.4.3.tar.gz
[root@server35 ~]# tar zxf drbd-8.4.3.tar.gz
[root@server35 ~]# cd drbd-8.4.3
[root@server35 drbd-8.4.3]# ./configure --enable-spec --with-km
[root@server35 drbd-8.4.3]# rpmbuild -bb drbd.spec
[root@server35 drbd-8.4.3]# cp ~/drbd-8.4.3.tar.gz ../rpmbuild/SOURCES/
[root@server35 drbd-8.4.3]# rpmbuild -bb drbd.spec
[root@server35 drbd-8.4.3]# rpmbuild -bb drbd-km.spec
[root@server35 x86_64]# rpm -ivh *
添加虚拟磁盘2G
[root@server35 ~]# fdisk -cu /dev/vdb
Command (m for help): n
ommand action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First sector (2048-4194303, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4194303, default 4194303):
Using default value 4194303
Command (m for help): t
Hex code (type L to list codes): 8e
Command (m for help): w
[root@server35 ~]# pvcreate /dev/vdb1
[root@server35 ~]# vgcreate drbdvg /dev/vdb1
[root@server35 ~]# lvcreate -L 1G -n demo drbdvg
[root@server35 ~]# vim /etc/drbd.d/drbd.res
resource demo{
meta-disk internal;
device /dev/drbd1;
syncer {
verify-alg sha1;
}
net {
allow-two-primaries;
}
on server35.example.com {
disk /dev/drbdvg/demo;
address 192.168.2.135:7789;
}
on test.example.com {
disk /dev/drbdvg/demo;
address 192.168.2.152:7789;
}
}
[root@server35 x86_64]# scp * 192.168.2.152:/root/
然后在152上
[root@test ~]# rpm -ivh drbd-*
添加硬盘做同样操作
在135上
[root@server35 ~]# scp /etc/drbd.d/drbd.res 192.168.2.152:/etc/drbd.d
[root@server35 ~]# drbdadm create-md demo 创建DRBR块
[root@server35 ~]# /etc/init.d/drbd start
然后启动152的drbd
[root@server35 ~]# drbdsetup /dev/drbd1 primary --force将152的磁盘设为主磁盘
[root@server35 ~]# cat /proc/drbd 查看drbd状态
[root@server35 ~]# drbdsetup /dev/drbd1 primary --force 强制为主磁盘
[root@server35 ~]# mkfs.ext4 /dev/drbd1 格式化磁盘
[root@server35 ~]# mount /dev/drbd1 /mnt/挂载磁盘到mnt,建立文件
[root@server35 ~]# umount /mnt/ 卸载之后,在第二磁盘上查看
[root@server35 ~]# drbdadm secondary demo 设置为第二磁盘
[root@test ~]# drbdsetup /dev/drbd1 primary --force
[root@test ~]# mount /dev/drbd1 /mnt/查看建立的文件!