glusterfs实战系列-3:replicate模式

Replacte模式简介:
为 glusterfs提供了类似RAID-1的功能。Replicate会复制文件或者文件夹到各个subvolumes里。因此,如果replicate部分设置了4个subvolume,那就会4分的文件或者文件夹的拷贝副本。replicate同样提供了高可用,比如如果其中的一个subvolume down掉了(或者说一台存储服务器坏了,网络连接出现问题)replicate依然可以使用冗余的拷贝副本来提供服务。
Replicate同样提供了自动修复功能,比如,如果一台crash掉的服务器恢复了,这台服务器上存储的过期的文件或者文件夹就会被更新成最新的版本。Replicate使用了后端文件系统的扩展功能来跟踪文件或者文件夹的版本来提供自动恢复的功能
本文环境:二台服务器,一台测试机均为CentOS-5.2操作系统,
服务器1的ip为:192.168.10.252,共享目录/home/gluterfs
服务器2的Ip为:192.168.10.253 , 共享目录是/data
测试机的ip为192.168.10.14 , 挂载点为/mnt
一 服务器1的安装和配置
1 .首先安装fuse 扩展
[root@test-1 ~]# tar zvxf fuse-2.8.3.tar.gz
[root@test-1 ~]# cd fuse-2.8.3
[root@test-1 ~]# ./configure --enable-dependency-tracking --enable-lib --enable-util
[root@test-1 ~]# make
[root@test-1 ~]# make install
2. 检查fuse 是否安装正确,如果不正确后面启动和挂载glusterfs 时候都会报错
[root@test-1 ~]# ll /dev/fuse
crw-rw-rw- 1 root root 10, 229 Apr 23 14:08 /dev/fuse
3. 安装服务器端
[root@test-1 ~]# cd ..
[root@test-1 ~]# tar zvxf glusterfs-2.0.0rc1.tar.gz
[root@test-1 ~]# cd glusterfs-2.0.0rc1
[root@test-1 ~]# ./configure
glusterfs实战系列-3:replicate模式_第1张图片
[root@test-1 ~]# make
[root@test-1 ~]# make install
4. 创建本地的共享点1
[root@test-1 ~]# mkdir /data
[root@test-1 ~]# chmod 777 /data
5 开始配置服务器端配置文件,首先先备份示例文件
[root@test-1 ~]#cd /usr/local/etc/glusterfs
[root@test-1 ~]# mkdir bak
[root@test-1 ~]# mv *.sample bak
[root@test-1 ~]# vi glusterfsd.vol(配置如下)
volume brick
type storage/posix # POSIX FS translator
option directory /data
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
subvolumes locker
option auth.addr.brick.allow * # Allow access to "brick" volume
option auth.addr.locker.allow *
end-volume
6 . 启动服务器端
[root@test-1 glusterfs]# glusterfsd -l /var/log/glusterfs.log -f /usr/local/etc/glusterfs/glusterfsd.vol -p /var/run/glusterfs.pid
启动的过程中指定了pid文件位置和日志文件位置
7 验证服务启动是否正常,端口监听
[root@test-1 glusterfs]# netstat -nltp |grep 6996 |grep -v grep
tcp 0 0 0.0.0.0:6996 0.0.0.0:* LISTEN 27698/glusterfsd
[root@test-1 glusterfs]#
二 服务器端2的安装和配置
1 .首先安装fuse 扩展
[root@test-2~]# tar zvxf fuse-2.8.3.tar.gz
[root@test-2~]# cd fuse-2.8.3
[root@test-2~]# ./configure --enable-dependency-tracking --enable-lib --enable-util
[root@test-2~]# make
[root@test-2~]# make install
2. 检查fuse 是否安装正确,如果不正确后面启动和挂载glusterfs 时候都会报错
[root@test-2~]# ll /dev/fuse
crw-rw-rw- 2root root 10, 229 Apr 23 14:08 /dev/fuse
3. 安装服务器端
[root@test-2~]# cd ..
[root@test-2~]# tar zvxf glusterfs-2.0.0rc1.tar.gz
[root@test-2~]# cd glusterfs-2.0.0rc1
[root@test-2~]# ./configure
clip_image002[1]
[root@test-2~]# make
[root@test-2~]# make install
4. 创建本地的共享点1 同时挂载硬盘分区
[root@test-2~]# mkdir /home/gluster
[root@test-2~]# mount /dev/sdb1 /home/gluster/
[root@test-2~]# chmod 777 /home/gluster/
5. 查看挂载是否正常
[root@test-2~]# df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
7.0G 3.4G 3.2G 52% /
/dev/sda1 99M 12M 83M 13% /boot
tmpfs 125M 0 125M 0% /dev/shm
/dev/sdb1 4.0G 8.0M 3.8G 1% /home/gluster
6 开始配置服务器端配置文件,首先先备份示例文件
[root@test-2~]#cd /usr/local/etc/glusterfs
[root@test-2~]# mkdir bak
[root@test-2~]# mv *.sample bak
[root@test-2~]# vi glusterfsd.vol(配置如下)
volume brick
type storage/posix # POSIX FS translator
option directory /home/gluster
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
subvolumes locker
option auth.addr.brick.allow * # Allow access to "brick" volume
option auth.addr.locker.allow *
end-volume
7 . 启动服务器端
[root@test-2glusterfs]# glusterfsd -l /var/log/glusterfs.log -f /usr/local/etc/glusterfs/glusterfsd.vol -p /var/run/glusterfs.pid
启动的过程中指定了pid文件位置和日志文件位置
8 验证服务启动是否正常,端口监听
[root@test-2glusterfs]# netstat -nltp |grep 6996 |grep -v grep
tcp 0 0 0.0.0.0:6996 0.0.0.0:* LISTEN 27698/glusterfsd
[root@test-2glusterfs]#
三 客户端的安装和配置
1. 和服务器端同样的安装操作此处不多说了,接下来配置客户端配置文件
[root@localhost glusterfs]#cd /usr/local/etc/glusterfs
[root@localhost glusterfs]# mkdir bak
[root@localhost glusterfs]# mv *.sample bak
[root@localhost glusterfs]# vi glusterfs.vol
volume client1
type protocol/client
option transport-type tcp/client
option remote-host 192.168.10.252 #//server ip
option remote-port 6996
option remote-subvolume locker
end-volume
volume client2
type protocol/client
option transport-type tcp/client
option remote-host 192.168.10.253 #//server ip
option remote-port 6996
option remote-subvolume locker
end-volume
volume bricks
type cluster/replicate
subvolumes client1 client2
end-volume
2. 首先挂载fuse 模块
[root@localhost glusterfs]#modprobe fuse
3 开始客户端的挂载,把服务器端对文件系统挂载到本地的/mnt 目录
[root@localhost glusterfs]#glusterfs -l /var/log/glusterfs.log -f /usr/local/etc/glusterfs/glusterfsd.vol -p /var/run/glusterfs.pid
同样指定了pid文件和日志文件
4 看看是否挂载成了本地文件系统
[root@localhost glusterfs]# df �Ch
Filesystem Size Used Avail Use% Mounted on
/dev/hda2 5.7G 2.1G 3.4G 39% /
/dev/hda1 99M 12M 83M 12% /boot
tmpfs 252M 0 252M 0% /dev/shm
glusterfs 11G 3.2G 7.2G 31% /mnt
[root@localhost glusterfs]# mount | tail -1
glusterfs#/usr/local/etc/glusterfs/glusterfs.vol on /data type fuse (rw,allow_other,default_permissions,max_read=131072)
[root@localhost glusterfs]#
三 测试部分
1. 在客户端的挂在点上创建文件
[root@localhost mnt]# cd /mnt
[root@localhost mnt]# touch test
2. 然后再两个服务器端查看, 可以看到2 个服务器同时产生了副本
[root@test-1 gluster]# cd /home/gluster/ (服务器-1
[root@test-1 gluster]# ls
test
[root@test-2 data]# cd /data (服务器-2
[root@test-2 data]# ls
test
3. 挂掉服务器端1 ,然手再续在客户端创建新文件
[root@test-1 gluster]# kill -9 `cat /var/run/glusterfs.pid` (服务器-1
[root@localhost mnt]# touch test2
[root@localhost mnt]# ls
test test2
[root@localhost mnt]#
4. 然后分别查看两个服务器端的数据变换
[root@test-1 gluster]# cd /home/gluster/ (服务器-1
[root@test-1 gluster]# ls
test
[root@test-2 data]# cd /data (服务器-2
[root@test-2 data]# ls
test test2
5. 现在启动服务器-1 ,然后查看数据是否同步过来
[root@test-1 gluster]#glusterfsd -l /var/log/glusterfs.log -f /usr/local/etc/glusterfs/glusterfsd.vol -p /var/run/gluterfs.pid
[root@test-1 gluster]# cd /home/gluster/ (服务器-1
[root@test-1 gluster]# ls
test (暂时无变化)
6. 现在在客户端重新查询一下数据,以把请求复制到服务器-1 上,这样两个服务器的内容就一致了
[root@localhost mnt]# cd /mnt
[root@localhost mnt]# ls
test test2
7. 到服务器-1 上看test2 文件是否已经复制过来了
[root@test-1 gluster]# cd /home/gluster/ (服务器-1
[root@test-1 gluster]# ls
test test2( 已经复制成功)

你可能感兴趣的:(模式,实战,GlusterFS,休闲,replicate)