Chinaunix首页 | 论坛 | 博客
  • 博客访问: 81299
  • 博文数量: 33
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 217
  • 用 户 组: 普通用户
  • 注册时间: 2015-03-24 17:05
文章分类
文章存档

2016年(2)

2015年(31)

我的朋友

分类: LINUX

2015-05-19 16:05:04

尊重作者劳动成果    如有侵犯,请留言,本人将即刻删除。只为互相学习。

转载地址:http://blog.163.com/xiangfei209@126/blog/static/9869567420121014104649874/

由于时间关系以下内容,本人未曾验证,仅供参考学习。

1.前言

在这篇教程中,我是用三个系统,2台服务器和一个客户端:
server1.example.com: IP address 192.168.0.100 (服务器)
server2.example.com: IP address 192.168.0.101 (服务器)
client1.example.com: IP address 192.168.0.102 (客户端)
这三个系统之间应该能够相互解析到对方的主机名,如果不能通过DNS完成,你可以在这个三个系统上用下列命令编辑/etc/hosts文件:

vi /etc/hosts

127.0.0.1 localhost.localdomain localhost
192.168.0.100 server1.example.com server1
192.168.0.101 server2.example.com server2
192.168.0.102 client1.example.com client1

# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

(你也可以在先前的设置当中使用IP地址而非主机名,如果你更喜欢使用IP地址,你在这里可以不关心主机名是否能被解析到)

2.设置GlusterFS服务器

server1.example.com/server2.example.com:

Debian Squeeze源中有GlusterFS,因此你可以用下列命令安装它:

apt-get install glusterfs-server

这个命令可以查看你刚才安装的GlusterFS的版本(本例中为3.0.5)

glusterfs –version

root@server1:~# glusterfs –version
glusterfs 3.0.5 built on Jul 13 2010 16:44:21
Repository revision: v3.0.5
Copyright (c) 2006-2009 Gluster Inc.
GlusterFS comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of GlusterFS under the terms of the GNU General Public License.
root@server1:~#

下面我们创建一些新的文件夹:

mkdir /data/
mkdir /data/export
mkdir /data/export-ns

现在我们在GlusterFS服务器上创建/etc/glusterfs/glusterfsd.vol配置文件(我们首先备份原始/etc/glusterfs/glusterfsd.vol文件),并设定/data/export作为共享和只允许192.168.0.102 = client1.example.com访问这个共享:

cp /etc/glusterfs/glusterfsd.vol /etc/glusterfs/glusterfsd.vol_orig
cat /dev/null > /etc/glusterfs/glusterfsd.vol

vi /etc/glusterfs/glusterfsd.vol

volume posix
type storage/posix
option directory /data/export
end-volume

volume locks
type features/locks
subvolumes posix
end-volume

volume brick
type performance/io-threads
option thread-count 8
subvolumes locks
end-volume

volume server
type protocol/server
option transport-type tcp
option auth.addr.brick.allow 192.168.0.102
subvolumes brick
end-volume

请注意,如果使用多个ip地址的话 (如192.168.*)你可以通过在参数中添加逗号,指定多个IP地址(例如.192.168.0.102,192.168.0.103).
最后我们启动GlusterFS服务器:

/etc/init.d/glusterfs-server start

3.设置GlusterFS客户端

client1.example.com:

在客户端上,我们用下列命令安装GlusterFS客户端:

apt-get install glusterfs-client

然后我们创建下列文件夹:

mkdir /mnt/glusterfs

下面我们创建/etc/glusterfs/glusterfs.vol 文件(在创建之前,我们首先备份原始/etc/glusterfs/glusterfs.vol 文件):

cp /etc/glusterfs/glusterfs.vol /etc/glusterfs/glusterfs.vol_orig
cat /dev/null >/etc/glusterfs/glusterfs.vol

vi /etc/glusterfs/glusterfs.vol

volume remote1
type protocol/client
option transport-type tcp
option remote-host server1.example.com
option remote-subvolume brick
end-volume

volume remote2
type protocol/client
option transport-type tcp
option remote-host server2.example.com
option remote-subvolume brick
end-volume

volume replicate
type cluster/replicate
subvolumes remote1 remote2
end-volume

volume writebehind
type performance/write-behind
option window-size 1MB
subvolumes replicate
end-volume

volume cache
type performance/io-cache
option cache-size 512MB
subvolumes writebehind
end-volume

请确保你在option remote-host 这一行中填入了你服务器的正确主机名和IP地址!
大功告成!下面我们可以用下面两个命令的其中一条挂载GlusterFS文件系统到/mnt/glusterfs :

glusterfs -f /etc/glusterfs/glusterfs.vol /mnt/glusterfs

或者

mount -t glusterfs /etc/glusterfs/glusterfs.vol /mnt/glusterfs

你会在下面输出中找到新的共享…….

mount

root@client1:~# mount
/dev/sda1 on / type ext3 (rw,errors=remount-ro)
tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
udev on /dev type tmpfs (rw,mode=0755)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)
fusectl on /sys/fs/fuse/connections type fusectl (rw)
/etc/glusterfs/glusterfs.vol on /mnt/glusterfs type fuse.glusterfs (rw,allow_other,default_permissions,max_read=131072)
root@client1:~#

… and…

df -h
root@client1:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 29G 778M 27G 3% /
tmpfs 249M 0 249M 0% /lib/init/rw
udev 244M 100K 244M 1% /dev
tmpfs 249M 0 249M 0% /dev/shm
/etc/glusterfs/glusterfs.vol
18G 848M 16G 5% /mnt/glusterfs
root@client1:~#

(server1.example.com和 server2.example.com 都为GlusterFS文件系统留有 18GB 空间, 但是因为数据是镜像的,所以我们在客户端上 看不到36GB的数据,只有18GB
)

你可以通过修改/etc/fstab 让客户端在启动的时候自动挂载GlusterFS,而不用每次都手动挂载.
打开/etc/fstab ,添加下列行

vi /etc/fstab

[...]
/etc/glusterfs/glusterfs.vol /mnt/glusterfs glusterfs defaults,_netdev 0 0

测试完你修改的 /etc/fstab能正常工作,重启这个客户端:

reboot

在重新启动后,你应该就能在输出中找到这个共享…..

df -h
… and…
mount

如果修改/etc/fstab 不起作用,取消你在/etc/fstab 的修改,可以在/etc/rc.local文件里添加下面这行(在exit 0前):

vi /etc/rc.local

[...]
/bin/mount -t glusterfs /etc/glusterfs/glusterfs.vol /mnt/glusterfs
[...]

确保在网络正常的情况下挂载共享.

4测试

现在我们在GlusterFS共享上创建一些测试文件:

client1.example.com:

touch /mnt/glusterfs/test1
touch /mnt/glusterfs/test2

现在让我们在server1.example.com和server2.example.com上分别检查检查/data/export 文件夹,test1和test2文件应该已经分发到了每个节点。

server1.example.com/server2.example.com:

ls -l /data/export
root@server1:~# ls -l /data/export
total 0
-rw-r–r– 1 root root 0 2012-03-29 14:51 test1
-rw-r–r– 1 root root 0 2012-03-29 14:51 test2
root@server1:~#

现在我们关闭server1.example.com ,并在 client1.example.com的GlusterFS上添加或删除一些文件。

server1.example.com:

shutdown -h now
client1.example.com:
touch /mnt/glusterfs/test3
touch /mnt/glusterfs/test4
rm -f /mnt/glusterfs/test2

这些改变就能在server2.example.com的/data/export 文件夹中看到:

server2.example.com:

ls -l /data/export
root@server2:~# ls -l /data/export
total 0
-rw-r–r– 1 root root 0 2012-03-29 14:51 test1
-rw-r–r– 1 root root 0 2012-03-29 14:52 test3
-rw-r–r– 1 root root 0 2012-03-29 14:52 test4
root@server2:~#

我们再次启动server1.example.com 并看一下/data/export文件夹:

server1.example.com:

ls -l /data/export
root@server1:~# ls -l /data/export
total 0
-rw-r–r– 1 root root 0 2012-03-29 14:51 test1
-rw-r–r– 1 root root 0 2012-03-29 14:51 test2
root@server1:~#

正如你所见,server1.example.com关闭的时候并没有同步.这个很好解决,我们只需要在 client1.example.com查看一下GlusterFS共享就可以了:

client1.example.com:

ls -l /mnt/glusterfs/
root@client1:~# ls -l /mnt/glusterfs/
total 8
-rw-r–r– 1 root root 0 2012-03-29 14:51 test1
-rw-r–r– 1 root root 0 2012-03-29 14:52 test3
-rw-r–r– 1 root root 0 2012-03-29 14:52 test4
root@client1:~#

现在再次看一下server1.example.com 的/data/export文件夹,你就应该能在server1.example.com节点上发现刚刚修改的文件已经被同步了:

Server1.example.com:

ls -l /data/export
root@server1:~# ls -l /data/export
total 8
-rw-r–r– 1 root root 0 2012-03-29 14:51 test1
-rw-r–r– 1 root root 0 2012-03-29 14:52 test3
-rw-r–r– 1 root root 0 2012-03-29 14:52 test4
root@server1:~#

5 链接

? GlusterFS:
? Debian: (210)

原文:
阅读(780) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~