Linux glusterfs 3.5.x 高可用性
周氏一族,整理技术文档,给下一代留点教程......应用场景
项目http采用了高可用性keepalive,双入口接入,那么就存在一个问题,每台服务器的web文件或者接口,需要两台都同时同步,所以,就想到了文件共享。
glusterfs 是在nfs的前提下,进行了升级,而且最近还共享给了apache基金会,发展得很快,最新的版本3.5.x 是比较成熟了,修复了很多bug,很多知名运营商都在用它,特别是搞网盘的,就我所知搜狗是用它最多的营运商之一。
网络结构
192.168.1.202 glusterfs-server 后端存储
192.168.1.203 glusterfs-server 后端存储
192.168.1.204 glusterfs-client 前端调用(挂载)
服务器系统(要求)
CentOS release 6.3 (Final) x64bit
安装步骤:
-------------下面是两台后端存储的配置,配置一样的,不一样会单独说明-----------
1、加入gluster yum 源,这样可以获取最新的version
cd /etc/yum.repos.d/
wget http://download.gluster.org/pub/gluster/glusterfs/3.5/3.5.1/EPEL.repo/glusterfs-epel.repo
如果这个链接不行,则自己搞一个,也是很简单的事情,如下
# cat glusterfs-epel.repo
# Place this file in your /etc/yum.repos.d/ directory
name=GlusterFS is a clustered file-system capable of scaling to several petabytes.
baseurl=http://download.gluster.org/pub/gluster/glusterfs/LATEST/EPEL.repo/epel-$releasever/$basearch/
enabled=1
skip_if_unavailable=1
gpgcheck=1
gpgkey=http://download.gluster.org/pub/gluster/glusterfs/LATEST/EPEL.repo/pub.key
name=GlusterFS is a clustered file-system capable of scaling to several petabytes.
baseurl=http://download.gluster.org/pub/gluster/glusterfs/LATEST/EPEL.repo/epel-$releasever/noarch
enabled=1
skip_if_unavailable=1
gpgcheck=1
gpgkey=http://download.gluster.org/pub/gluster/glusterfs/LATEST/EPEL.repo/pub.key
name=GlusterFS is a clustered file-system capable of scaling to several petabytes. - Source
baseurl=http://download.gluster.org/pub/gluster/glusterfs/LATEST/EPEL.repo/epel-$releasever/SRPMS
enabled=0
skip_if_unavailable=1
gpgcheck=1
gpgkey=http://download.gluster.org/pub/gluster/glusterfs/LATEST/EPEL.repo/pub.key
2、查看一下yum源加载是否成功
http://s3.运维网.com/wyfs02/M02/44/7C/wKiom1Ph0BrwbnDpAAJvxDXWqXo984.jpg很明显,已经加载成功。
3、那就开始yum吧,非常简单
yum -y install glusterfs-server
4、yum完之后,安装好glusterfs,会在/etc/init.d/下面有两个配置启动文件
glusterd glusterfsd // 一一启动它便可
# /etc/init.d/glusterd start && /etc/init.d/glusterfsd start
5、接下来,在hosts下面,添加两个后端存储的ip/hostname 对应关系
# vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.202 server202
192.168.1.203 server203
6、分别从两台机器,添加对方节点,例如202添加203,203添加202
前面是202添加203
# gluster peer probe server203
peer probe: success.
# gluster peer status
Number of Peers: 1
Hostname: server203
Uuid: 04aa2530-379b-40ff-9fc1-66552b1defe7
State: Peer in Cluster (Connected)
下面是203添加202的
# gluster peer probe server202
peer probe: success.
# gluster peer status
Number of Peers: 1
Hostname: server202
Uuid: 05b8fede-9576-4ffa-b525-40c1218d8bac
State: Peer in Cluster (Connected)
#
//gluster peer status 是查看节点状态
7、创建一个主目录,用来作为后端存储的根目录,我们就在/data下面吧
mkdir /data
chmod -R 1777 /data
8、随便找一个后端存储节点,202也好,203也罢,随便你,然后两条命令,边可以创建volume
gluster volume create zhou replica 2 transport tcp server202:/data server203:/data force
gluster volume start zhou
注意:8.1只需要一台创建即可,不能两台都创建,否则会提示volume zhou 已经存在
volume create: zhou: failed: Volume zhou already exists 8.2"replica 2",他的意思,是指我要把创建冗余数据,也就是说,前端写入的数据,会同时写到202和203,如果不加这个参数,前端挂载,只会写入其中一台,不会同步
8.3在后面,必须加上 force,否则它会提示你,必须加,同样道理,移除的时候,也得加force
9、假如,我们刚刚8的步骤,是在202上面创建的,那么,我们来203看一下情况
# gluster volume status
Status of volume: zhou
Gluster process Port OnlinePid
------------------------------------------------------------------------------
Brick server202:/data 49153 Y 45883
Brick server203:/data 49153 Y 45012
NFS Server on localhost 2049 Y 45026
Self-heal Daemon on localhost N/A Y 45030
NFS Server on server202 2049 Y 45897
Self-heal Daemon on server202 N/A Y 45901
Task Status of Volume zhou
------------------------------------------------------------------------------
There are no active volume tasks
很明显,已经开始集群了。
-----------------------------下面是前端挂载的配置(服务器是192.168.0.204)-----------------
10、同样道理,要加载yum 源,这里不多说
11、开始安装 glusterfs-client
yum -y install glusterfs-client
12、yum完之后,就可以使用这条命令来挂载了
mount -t glusterfs server202:/zhou /data/
注意:挂载之前,先要编辑host对应ip,否则怎么知道你这个server202是什么飞机来的,而且还要先创建/data文件,这样才能挂载,完全命令如下:
mkdir /data
chmod -R 1777 /data
mount -t glusterfs server202:/zhou /data/
----------------------------下面是前端测试效果----------------
13、在204,创建文件到/data,为了保障起见,连续创建两个
14、在202,ll /data,正常情况下会看到 13 步骤所创建的文件,看不到就是你的问题了
15、在203,ll /data,正常情况下会看到 13 步骤所创建的文件,看不到就是你的问题了
16、把202关机,在204,创建文件,此时你会发现创建会有点缓慢,但是没关系,一样会创建成功
17、到203,ll /data,正常情况下会看到 16 步骤所创建的文件,看不到就是你的问题了
18、在17步骤,当202死机,在204创建文件有点慢,不急,再创建几个文件试试,你会发现,这下子会很快,这是正常情况的,因为202挂了,你在204创建的文件,它会自动创建到203当中
19、把202开机,你会发现,202挂掉的这一个期间,203所创建的文件,202已经同步过来了
20、同样道理,你把203关机试一下,效果一样的
21、高可用性集群搭建成功
--------------------------下面是前端配合hhtp测试下载-------------------------
22、yum安装httpd,这里不多说了
yum -y install httpd
23、修改httpd默认目录
vi /etc/httpd/conf/httpd.conf
修改 DocumentRoot "/data"
重启 httpd restart
24、随便在204创建一个文件
http://s3.运维网.com/wyfs02/M02/44/81/wKioL1Ph2YvQdHEhAAFwiBim7eI352.jpg
25、网页打开一下http://192.168.1.204/good.html
http://s3.运维网.com/wyfs02/M02/44/81/wKiom1Ph2MSB60cQAAD8mg7yVfM447.jpg
你会发现,成功了,换句话说,以后apache文件,直接放在 后端存储即可,不需要两台都同时放一样的html文件,省了很多无用功。
当然,除了存放 html文件外,也可以放其他你自己想要的东西,例如mp3,电影,等等乱七八糟...
---------------------------下面是常见问题汇集--------------------------------------
# gluster peer status
Connection failed. Please check if gluster daemon is operational.
麻烦,您把进程先开起来 /etc/init.d/glusterd start && /etc/init.d/glusterfsd start
# gluster peer probe server202
peer probe: failed: Probe returned with unknown errno 107
帅锅,请关闭iptables防火墙,谢谢
# gluster volume remove-brick zhou server202:/data
WARNING: running remove-brick commands without an explicit option is deprecated, and will be removed in the next version of GlusterFS.
To forcibly remove a brick in the next version of GlusterFS, you will need to use "remove-brick force".
不管是创建volume还是移除,全部在后面加一个force
---------------------------下面是常见问题汇集--------------------------------------
help一下,看看有那些管理工具
# gluster volume help
volume info - list information of all volumes
volume create ?... - create a new volume of specified type with mentioned bricks
volume delete- delete volume specified by
volume start - start volume specified by
volume stop - stop volume specified by
volume add-brick[ ]... - add brick to volume
volume remove-brick... - remove brick from volume
volume rebalance {start|stop|status} - rebalance operations
volume replace-brick {start |pause|abort|status|commit } - replace-brick operations
volume set - set options for volume
volume help - display help for the volume command
volume log rotate - rotate the log file for corresponding volume/brick
volume sync - sync the volume information from a peer
volume reset - reset all the reconfigured options
volume profile{start|stop|info } - volume profile operations
volume quota{enable|disable|list [ ...]|remove | default-soft-limit } |
volume quota{limit-usage []} |
volume quota{alert-time|soft-timeout|hard-timeout} {} - quota translator specific operations
volume top{open|read|write|opendir|readdir|clear} |
volume top{read-perf|write-perf} - volume top operations
volume status ] - display status of all or specified volume(s)/brick
volume heal[{full | statistics {heal-count {replica }} |info {healed | heal-failed | split-brain}}] - self-heal commands on volume specified by
volume statedump ... - perform statedump on bricks
volume list - list all volumes in cluster
volume clear-locks kind {blocked|granted|all}{inode |entry |posix } - Clear locks held on path
各个参数的作用个,一目了然,大家不用我解释了吧
页:
[1]