设为首页 收藏本站
查看: 680|回复: 0

[经验分享] Linux glusterfs 3.5.x 高可用性

[复制链接]

尚未签到

发表于 2019-2-1 11:19:28 | 显示全部楼层 |阅读模式
  周氏一族,整理技术文档,给下一代留点教程......
  

  应用场景

  项目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
  如果这个链接不行,则自己搞一个,也是很简单的事情,如下
  [root@server203 yum.repos.d]# cat glusterfs-epel.repo
  # Place this file in your /etc/yum.repos.d/ directory
  

  [glusterfs-epel]
  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
  

  [glusterfs-noarch-epel]
  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
  

  [glusterfs-source-epel]
  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源加载是否成功

很明显,已经加载成功。

  

  3、那就开始yum吧,非常简单
  yum -y install glusterfs-server
  

  4、yum完之后,安装好glusterfs,会在/etc/init.d/下面有两个配置启动文件
  glusterd    glusterfsd      // 一一启动它便可
  [root@server203 ~]# /etc/init.d/glusterd start && /etc/init.d/glusterfsd start
  

  5、接下来,在hosts下面,添加两个后端存储的ip/hostname 对应关系
  [root@New_server ~]# 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
  [root@New_server ~]# gluster peer probe server203
  peer probe: success.
  [root@New_server ~]# gluster peer status
  Number of Peers: 1
  

  Hostname: server203
  Uuid: 04aa2530-379b-40ff-9fc1-66552b1defe7
  State: Peer in Cluster (Connected)
  

  下面是203添加202的
  [root@server203 ~]# gluster peer probe server202
  peer probe: success.
  [root@server203 ~]# gluster peer status
  Number of Peers: 1
  

  Hostname: server202
  Uuid: 05b8fede-9576-4ffa-b525-40c1218d8bac
  State: Peer in Cluster (Connected)
  [root@server203 ~]#
  

  //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看一下情况
  [root@server203 ~]# gluster volume status
  Status of volume: zhou
  Gluster process                                         Port    Online  Pid
  ------------------------------------------------------------------------------
  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创建一个文件

  25、网页打开一下  http://192.168.1.204/good.html

  你会发现,成功了,换句话说,以后apache文件,直接放在 后端存储即可,不需要两台都同时放一样的html文件,省了很多无用功。
  当然,除了存放 html文件外,也可以放其他你自己想要的东西,例如mp3,电影,等等乱七八糟...
  

  

  ---------------------------下面是常见问题汇集--------------------------------------
  [root@server203 ~]# gluster peer status
  Connection failed. Please check if gluster daemon is operational.
  麻烦,您把进程先开起来   /etc/init.d/glusterd start && /etc/init.d/glusterfsd start
  

  [root@server203 ~]# gluster peer probe server202
  peer probe: failed: Probe returned with unknown errno 107
  帅锅,请关闭iptables防火墙,谢谢
  

[root@New_server ~]# 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一下,看看有那些管理工具
  [root@New_server ~]# gluster volume help
  volume info [all|] - list information of all volumes
  volume create  [stripe ] [replica ] [transport ] ?... [force] - create a new volume of specified type with mentioned bricks
  volume delete  - delete volume specified by
  volume start  [force] - start volume specified by
  volume stop  [force] - stop volume specified by
  volume add-brick  [ ]  ... [force] - add brick to volume
  volume remove-brick  [replica ]  ... [start|stop|status|commit|force] - remove brick from volume
  volume rebalance  [fix-layout] {start|stop|status} [force] - rebalance operations
  volume replace-brick    {start [force]|pause|abort|status|commit [force]} - replace-brick operations
  volume set    - set options for volume
  volume help - display help for the volume command
  volume log rotate  [BRICK] - rotate the log file for corresponding volume/brick
  volume sync  [all|] - sync the volume information from a peer
  volume reset  [option] [force] - reset all the reconfigured options
  volume profile  {start|stop|info [nfs]} - 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} [nfs|brick ] [list-cnt ] |
  volume top  {read-perf|write-perf} [bs  count ] [brick ] [list-cnt ] - volume top operations
  volume status [all |  [nfs|shd||quotad]] [detail|clients|mem|inode|fd|callpool|tasks] - 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  [nfs|quotad] [all|mem|iobuf|callpool|priv|fd|inode|history]... - perform statedump on bricks
  volume list - list all volumes in cluster
  volume clear-locks   kind {blocked|granted|all}{inode [range]|entry [basename]|posix [range]} - Clear locks held on path
  

  各个参数的作用个,一目了然,大家不用我解释了吧
  





运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-670397-1-1.html 上篇帖子: GlusterFS客户端进程分析 下篇帖子: GlusterFS集群文件系统基础与实践
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表