Replicate(前身是AFR)为glusterfs提供了类似RAID-1的功能。
Replicate会复制文件或者文件夹到各个subvolumes里。
因此,如果replicate部分设置了4个subvolume,那就会4分的文件或者文件夹的拷贝副本。
replicate同样提供了高可用,比如如果其中的一个subvolume down掉了(或者说一台存储服务器坏了,网络连接出现问题)replicate依然可以使用冗余的拷贝副本来提供服务。
Replicate同样提供了自动修复功能,比如,如果一台crash掉的服务器恢复了,这台服务器上存储的过期的文件或者文件夹就会被更新成最新的版本。
Replicate使用了后端文件系统的扩展功能来跟踪文件或者文件夹的版本来提供自动恢复的功能
#############################
volume replicate-example
type cluster/replicate
subvolumes brick1 brick2 brick3
end-volume
############################
上面的例子将会把所有文件都复制到brick1 brick2 brick3中
所有读的操作都会从第一台活着的sbuvolume进行,如果三个sub-volume都是启用的状态,就从brick1读;如果brick1 down了,就从brick2读。
如果读的操作刚刚完成brick1就down了,复制就会传递给brick2.
############################
概念讲完了,下面看看具体的实施吧。

一.实验环境
目的:让两台server的磁盘空间进行复制,相当与raid1,所需3台服务器,两台server,一台client,IP分别为:
192.168.4.189----------------glusterfs_server01
192.168.4.190----------------glusterfs_server02
192.168.4.188----------------glusterfs_client
系统使用centos5.1,有个奇怪的问题是系统使用centos4.4的时候编译glusterfs的时候总报错,用centos5.1就没事,这问题还以待研究
二.安装
1.首先安装fuse
tar -zxvf fuse-2.7.4.tar.gz
cd fuse-2.7.4
./configure -enable-dependency-tracking -enable-kernel-module -enable-lib -enable-util
make && make isntall
2.安装glusterfs
tar -zxvf glusterfs-2.0.0rc1.tar.gz
cd glusterfs-2.0.0rc1
./configure
make && make install
两台glusterfs_server和glusterfs_client端操作一样
三. 配置
gluster_server端的操作
1.gluster_server端服务器有一个单独的硬盘/dev/hdb,对/dev/hdb分区并mount到/disk上,执行chmod 777 /disk
  两台server一样的操作
2.配置文件的修改
glusterfs_server01上:
mv glusterfs-server.vol.sample glusterfs-server.vol
vi /usr/local/etc/glusterfs/glusterfs-server.vol
修改后内容如下:
### Export volume “brick” with the contents of “/disk/export” directory.
volume brick
type storage/posix # POSIX FS translator
option directory /disk/export # Export this directory
end-volume
volume locker
type features/posix-locks
subvolumes brick
end-volume
### Add network serving capability to above brick.
volume server
type protocol/server
option transport-type tcp/server
option bind-address 192.168.4.189 # Default is to listen on all interfaces
option listen-port 6996 # Default is 6996
subvolumes locker
option auth.addr.brick.allow * # Allow access to “brick” volume
option auth.addr.locker.allow *
end-volume

glusterfs_server02上:
mv glusterfs-server.vol.sample glusterfs-server.vol
vi /usr/local/etc/glusterfs/glusterfs-server.vol
修改后内容如下:
### Export volume “brick” with the contents of “/disk/export” directory.
volume brick
type storage/posix # POSIX FS translator
option directory /disk/export # Export this directory
end-volume
volume locker
type features/posix-locks
subvolumes brick
end-volume
### Add network serving capability to above brick.
volume server
type protocol/server
option transport-type tcp/server
option bind-address 192.168.4.190 # Default is to listen on all interfaces
option listen-port 6996 # Default is 6996
subvolumes locker
option auth.addr.brick.allow * # Allow access to “brick” volume
option auth.addr.locker.allow *
end-volume
3.mkdir -p /disk/export    两台server操作一样
gluster_client端的操作:
cd /usr/local/etc/glusterfs/
mv glusterfs-client.vol.sample  glusterfs-client.vol
修改后的内容如下:
### Add client feature and attach to remote subvolume
volume client0
type protocol/client
option transport-type tcp/client
option remote-host 192.168.4.189 # IP address of the remote brick
option remote-port 6996 # default server port is 6996
option remote-subvolume locker # name of the remote volume
end-volume
volume client1
type protocol/client
option transport-type tcp/client
option remote-host 192.168.4.190
option remote-port 6996
option remote-subvolume locker
end-volume
volume bricks
type cluster/replicate
subvolumes client0 client1
end-volume

四. 操作
glusterfs_server端的操作
1.glusterfsd -f /usr/local/etc/glusterfs/glusterfs-server.vol  启动server端
2.ps -ef | grep glusterfs                                      查看进程存在不存在
3.netstat -ln | grep 6996                                      查看端口是否监听
两台server一样
glusterfs_client端的操作
1.modprobe -i fuse                加载fuse模块
2.glusterfs -l /tmp/glusterfs.log -f /usr/local/etc/glusterfs/glusterfs-client.vol /mnt      挂载到/mnt上,同时可以查看 /tmp下的glusterfs.log日志
3.[root@glusterfs_client glusterfs]# df -h
文件系统              容量  已用 可用 已用% 挂载点
/dev/hda1             8.5G  5.0G  3.2G  62% /
tmpfs                 125M     0  125M   0% /dev/shm
glusterfs             3.0G   69M  2.8G   3% /mnt
看看/mnt的容量是一台server的磁盘容量,是的话就证明OK!!!
五. 测试
1.glusterfs_client端的/mnt目录下:
  touch {1,2,3,4,5,6,7,8,9,10}
2.到glusterfs_server的/disk/export目录下ls
server01:
   [root@glusterfs_server01 export]# ls
    1  2  3  4  5  6  7  8  9
server02:
  [root@glusterfs_server02 export]# ls
   1  2  3  4  5  6  7  8  9
由上面看到,9个新的文件是都创建到了两个server的/disk/export中
到此,我的试验就算完成了,而且试验目的也达成了
3.在server端进行一个破坏性的实验,把server02的gluster进程杀掉,到client端看,发现/mnt的空间还是3G,但是到/mnt下看刚touch文件是没问题的都可以访问,
  我们在mkdir {a,b,c,d,e,f,g,h}建立几个目录,在把server02端的进程glusterfs启动,到server02的/disk/export下看刚建立的a,b,c,d,e,...几个文件夹已经复制过来了