Gluster集群搭建-安装Gluster环境

来源:互联网 发布:网络舆情引导员 编辑:程序博客网 时间:2024/06/04 17:55

安装前准备:
1. Windows系统
2. Xshell远程ssh软件
3. 安装好CentOS虚拟机的VMware Workstation软件
参考文档
1. GlusterFS下载地址
http://download.gluster.org/pub/gluster/glusterfs/ 安装包下载地址,这里面包含源码编译包下载,rpm包下载
2.GlusterFS安装教程
http://gluster.readthedocs.io/en/latest/Quick-Start-Guide/Quickstart/ 官网
http://www.centoscn.com/image-text/config/2015/1021/6326.html 其他网址
http://www.centoscn.com/image-text/install/2016/0604/7377.html 其他网址
以下都是在虚拟机ping的通外网的情况下安装的。

安装前准备

(1) 用Xshell连接CentOS系统,虚拟机的IP地址是192.168.220.135,输入账号root,再输入root密码即可进入到系统了。
(2) 下载安装包,一个是rpm包下载安装,一个是源码包编译安装,一个是命令自动安装。安装包的下载网址我在上面已经告诉大家了,我用的是源码包编译的方式安装。首先需要在网上下载下来安装包,将安装包拷贝到虚拟机中。

[root@localhost home]# yum update   // 更新一下yum云[root@localhost ~]# yum install wget –y  // 安装wget,下载源码包,这是一种方式[root@localhost ~]# yum install lrzsz –y   // 安装lrzsz,方便向虚拟中传输文件。因为网络的原因,我选择的就是这种方式,通过Windows先将源码包下载下来,然后再传送到虚拟机中[root@localhost ~]# rz         // 传送安装包[root@localhost ~]# lsanaconda-ks.cfg  glusterfs-3.4.2.tar.gz  install.log  install.log.syslog[root@localhost ~]#

安装Gluster

(1)我用的是3.4.2的版本,当然大家可以用更高版本的,用更高版本的时候,编译风险也就更高,毕竟不是自动获取的Gluster。现在开始编译源码包。

[root@localhost ~]# tar -zxvf glusterfs-3.4.2.tar.gz   // 解压安装包[root@localhost ~]# cd glusterfs-3.4.2       // 进入到安装包,会发现很多文件[root@localhost glusterfs-3.4.2]#aclocal.m4       autogen.sh    config.h.in   contrib         doc                  glusterfs.spec     libglusterfs  missing     rpcapi              ChangeLog     config.sub    COPYING-GPLV2   extras               glusterfs.spec.in  ltmain.sh     NEWS        THANKSargp-standalone  cli           configure     COPYING-LGPLV3  glusterfs-api.pc.in  INSTALL            Makefile.am   py-compile  xlatorsAUTHORS          config.guess  configure.ac  depcomp         glusterfsd           install-sh         Makefile.in   README[root@localhost glusterfs-3.4.2]#[root@localhost glusterfs-3.4.2]# yum install gcc flex bison openssl-devel –y //安装必要的需求包[root@localhost glusterfs-3.4.2]# ./configure       // 检测环境,没有问题即可进行下一步,如果有问题的话,一般都是缺包,所以大家记得安装对应的安装包[root@localhost glusterfs-3.4.2]# make   // make编译一下包[root@localhost glusterfs-3.4.2]# make install   //  安装Gluster[root@localhost glusterfs-3.4.2]# ln -s /usr/local/sbin/gluster /usr/sbin/gluster // 将gluster命令连接到我们的系统命令中

(2)启动Gluster服务

[root@localhost glusterfs-3.4.2]# /etc/init.d/glusterd status    //  查看服务是否启动glusterd is stopped[root@localhost glusterfs-3.4.2]# /etc/init.d/glusterd start     //  启动服务Starting glusterd:                                         [  OK  ][root@localhost glusterfs-3.4.2]#[root@localhost glusterfs-3.4.2]# chkconfig glusterd on        // 设置服务开机自动启动[root@localhost glusterfs-3.4.2]#

集群搭建

(1) 一台机器搭好了环境,此时就需要搭建集群了,因为是虚拟机,所以我们使用克隆即可完成集群的搭建,如果是实体机,还需要大家一个个敲命令啦!
首先在我们的Windows上得硬盘中创建一个集群的文件夹,里面创建四个文件夹,分别是server01,server02,server03,server04,以便我们克隆将他们放置在文件中便于区分。接下来将我们刚才搭建好的虚拟机关机。
(2) 在虚拟机中,点击上边栏中的虚拟机——》管理——》克隆
(3) 弹出的框框——》下一步——》克隆源——》下一步——》克隆类型为完整类型——》下一步——》虚拟机名称改为erver01——》位置选择我们刚才创建的server01文件夹——》完成。克隆完关闭即可,我们就可以在VM上看到我们的server01虚拟机。
(4) 打开虚拟机,然后账号密码都是和母机一样的,然后我们还是需要dhclient一下,自动获取IP地址,OK,第一台server机器成功克隆完毕。我们就可以用Xshell软件连接虚拟机了。
(5) 同理,我们继续对母机进行克隆,虚拟机的名字分别是server02,03,04,位置分别是我们创建的那三个server文件夹中。克隆完毕后,即可打开虚拟机,然后dhclient一下自动获取IP,再用Xshell连接操作即可。
(6) 我们的母体机器可以名字可以改成client了,然后启动机器,以便后面用它作为客户机挂载远程机器。

集群配置

(1) 配置hosts文件夹

[root@localhost ~]# vi /etc/hosts      // 编辑hosts文件夹将以下内容填写到配置文件中:192.168.220.135 client192.168.220.136 server01192.168.220.137 server02192.168.220.138 server03192.168.220.139 server04当然,这个是根据你自己的虚拟机IP地址确定的配置信息。将hosts文件拷贝到其他机器中,记得输入yes和密码[root@localhost ~]# scp /etc/hosts root@server01:/etc/hostsThe authenticity of host 'server01 (192.168.220.136)' can't be established.RSA key fingerprint is 1b:f9:32:57:5a:df:9c:f5:58:e1:cd:1f:2c:9f:07:75.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added 'server01,192.168.220.136' (RSA) to the list of known hosts.root@server01's password: hosts                                                                                                    100%  282     0.3KB/s   00:00    [root@localhost ~]#同理其他机器:scp /etc/hosts root@server02:/etc/hostsscp /etc/hosts root@server03:/etc/hostsscp /etc/hosts root@server04:/etc/hosts

(2) 配置静态IP,我们dhclient都是动态获取的,为了防止IP改变,我们需要对IP进行静态配置。

[root@localhost ~]# cat /etc/resolv.conf     // 获取IP地址的GATEWAY; generated by /sbin/dhclient-scriptsearch localdomainnameserver 192.168.220.2[root@localhost ~]# netnetreport  netstat    [root@localhost ~]# netstat -rnKernel IP routing tableDestination     Gateway         Genmask         Flags   MSS Window  irtt Iface192.168.220.0   0.0.0.0         255.255.255.0   U         0 0          0 eth00.0.0.0         192.168.220.2   0.0.0.0         UG        0 0          0 eth0[root@localhost ~]# 以上nameserver192.168.220.2就是我们要的GATEWAY。[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0  // 配置静态IPDEVICE=eth0                  // 网卡名字根据ifconfig出来的结果来填HWADDR=00:0C:29:7A:AF:58     // 网卡MAC地址也是根据ifconfig结果来填TYPE=EthernetUUID=66f2b6c2-4a25-4b0b-9404-086c6ec628f3ONBOOT=yesNM_CONTROLLED=yesBOOTPROTO=noneIPADDR=192.168.220.135        // IP地址是根据ifconfig出来的结果来填PREFIX=24GATEWAY=192.168.220.2        // GATEWAY根据上面的方式获取根据自己的电脑IP和GATEWAY配置静态IP。 [root@localhost ~]# /etc/init.d/network restart      //检查是否配置成功Shutting down interface eth0:                              [  OK  ]Shutting down loopback interface:                          [  OK  ]Bringing up loopback interface:                            [  OK  ]Bringing up interface eth0:  Determining if ip address 192.168.220.135 is already in use for device eth0...                                                           [  OK  ][root@localhost ~]#如果出现以上信息,则表示配置成功,可以重启。

同理,将其他四台server机器一样的步骤配置静态IP地址,这个不在累赘了。(这里注意,一定要按照你ifconfig出来的网卡名字,IP地址和MAC地址来配置那个静态文件,不要把IP地址和MAC地址写错了。一般母机好配置,主要是server机器,ifconfig后发现变化了eth1和MAC地址,还有IP地址,千万别配置错了,要不后面出不来效果。)
(3) 配置成功后,重启后再连接我们可以看到我们的五台主机名字变成了client,server01,02,03,04等字样,如果没变,则表示配置的IP地址有问题,大家检查一下。

集群的简单操作

(1) 关闭防火墙

[root@client ~]# service iptables status     // 查看防火墙状态Table: filterChain INPUT (policy ACCEPT)num  target     prot opt source               destination         1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 5    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT)num  target     prot opt source               destination         1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT)num  target     prot opt source               destination         [root@client ~]#好吧,上面的防火墙都开着呢。[root@client ~]# service iptables stop       // 简单关闭iptables: Setting chains to policy ACCEPT: filter          [  OK  ]iptables: Flushing firewall rules:                         [  OK  ]iptables: Unloading modules:                               [  OK  ][root@client ~]# service iptables status      // 查看状态iptables: Firewall is not running.[root@client ~]# chkconfig iptables off      // 设置开机关闭防火墙[root@client ~]# chkconfig --list iptables     // 查看防火墙配置iptables        0:off   1:off   2:off   3:off   4:off   5:off   6:off[root@client ~]#

同理在其他机器上一样执行这个命令。
(2) 关闭SELinux

[root@client ~]# getenforce       // 查看SELiunx的状态Enforcing[root@client ~]# setenforce 0      // 设置当前为关闭[root@client ~]# getenforce       //  查看一下状态Permissive[root@client ~]# vi /etc/selinux/config    // 设置开机不启动[root@client ~]# cat /etc/selinux/config # This file controls the state of SELinux on the system.# SELINUX= can take one of these three values:#     enforcing - SELinux security policy is enforced.#     permissive - SELinux prints warnings instead of enforcing.#     disabled - No SELinux policy is loaded.SELINUX=disabled# SELINUXTYPE= can take one of these two values:#     targeted - Targeted processes are protected,#     mls - Multi Level Security protection.SELINUXTYPE=targeted [root@client ~]#

同理,其他四台机器同样的道理。
(3) 加入集群节点

在任何一台server机器上都行[root@server01 ~]# gluster help     // 帮助文档volume info [all|<VOLNAME>] - list information of all volumesvolume create <NEW-VOLNAME> [stripe <COUNT>] [replica <COUNT>] [transport <tcp|rdma|tcp,rdma>] <NEW-BRICK> ... [force] - create a new volume of specified type with mentioned bricksvolume delete <VOLNAME> - delete volume specified by <VOLNAME>volume start <VOLNAME> [force] - start volume specified by <VOLNAME>volume stop <VOLNAME> [force] - stop volume specified by <VOLNAME>volume add-brick <VOLNAME> [<stripe|replica> <COUNT>] <NEW-BRICK> ... [force] - add brick to volume <VOLNAME>volume remove-brick <VOLNAME> [replica <COUNT>] <BRICK> ... {start|stop|status|commit|force} - remove brick from volume <VOLNAME>volume rebalance <VOLNAME> [fix-layout] {start|stop|status} [force] - rebalance operationsvolume replace-brick <VOLNAME> <BRICK> <NEW-BRICK> {start [force]|pause|abort|status|commit [force]} - replace-brick operationsvolume set <VOLNAME> <KEY> <VALUE> - set options for volume <VOLNAME>volume help - display help for the volume commandvolume log rotate <VOLNAME> [BRICK] - rotate the log file for corresponding volume/brickvolume sync <HOSTNAME> [all|<VOLNAME>] - sync the volume information from a peervolume reset <VOLNAME> [option] [force] - reset all the reconfigured optionsvolume geo-replication [<VOLNAME>] [<SLAVE-URL>] {start|stop|config|status|log-rotate} [options...] - Geo-sync operationsvolume profile <VOLNAME> {start|info|stop} [nfs] - volume profile operationsvolume quota <VOLNAME> <enable|disable|limit-usage|list|remove> [path] [value] - quota translator specific operationsvolume top <VOLNAME> {[open|read|write|opendir|readdir [nfs]] |[read-perf|write-perf [nfs|{bs <size> count <count>}]]|[clear [nfs]]} [brick <brick>] [list-cnt <count>] - volume top operationsvolume status [all | <VOLNAME> [nfs|shd|<BRICK>]] [detail|clients|mem|inode|fd|callpool] - display status of all or specified volume(s)/brickvolume heal <VOLNAME> [{full | info {healed | heal-failed | split-brain}}] - self-heal commands on volume specified by <VOLNAME>volume statedump <VOLNAME> [nfs] [all|mem|iobuf|callpool|priv|fd|inode|history]... - perform statedump on bricksvolume list - list all volumes in clustervolume clear-locks <VOLNAME> <path> kind {blocked|granted|all}{inode [range]|entry [basename]|posix [range]} - Clear locks held on pathpeer probe <HOSTNAME> - probe peer specified by <HOSTNAME>peer detach <HOSTNAME> [force] - detach peer specified by <HOSTNAME>peer status - list status of peerspeer help - Help command for peer quit - quithelp - display command optionsexit – exit[root@server01 ~]# gluster peer probe server02peer probe: success[root@server01 ~]# gluster peer probe server03peer probe: success[root@server01 ~]# gluster peer probe server04peer probe: success[root@server01 ~]# gluster peer statusNumber of Peers: 3Hostname: server02Port: 24007Uuid: e3b697dd-428d-4c15-85b5-0bbd3dba1ef6State: Peer in Cluster (Connected)Hostname: server03Port: 24007Uuid: 0d61b1c9-9e98-4fec-b9ef-4add193009f6State: Peer in Cluster (Connected)Hostname: server04Port: 24007Uuid: 57144cf3-2d3a-437d-9391-293390a85d9aState: Peer in Cluster (Connected)[root@server01 ~]#显示全部连接成功!

(4) 创建一个分布式卷

首先在四台机器上创建一个能够存放文件系统的文件夹[root@server01 ~]# mkdir /Data[root@server02 ~]# mkdir /Data[root@server03 ~]# mkdir /Data[root@server04 ~]# mkdir /Data[root@server01 ~]# gluster volume create dht server01:/Data/dht1 server02:/Data/dht2 server03:/Data/dht3 server04:/Data/dht4 force    // 创建一个分布式卷dhtvolume create: dht: success: please start the volume to access data   [root@server01 ~]# gluster volume start dht       // 启动这个分布式卷volume start: dht: success[root@server01 ~]# gluster volume status dht      // 查看这个卷的情况Status of volume: dhtGluster process                     Port    Online  Pid------------------------------------------------------------------------------Brick server01:/Data/dht1               49152   Y   1610Brick server02:/Data/dht2               49152   Y   1554Brick server03:/Data/dht3               49152   Y   1532Brick server04:/Data/dht4               49152   Y   1549NFS Server on localhost                 2049    Y   1620NFS Server on server02                  2049    Y   1564NFS Server on server03                  2049    Y   1542NFS Server on server04                  2049    Y   1559There are no active volume tasks[root@server01 ~]#

(5) 挂在分布式卷

[root@server01 ~]# mount -t glusterfs server01:/dht /mnt/   // 挂在server01卷到server01的mnt路径下[root@server01 ~]# [root@server01 ~]# df –h     // 查看磁盘大小Filesystem            Size  Used Avail Use% Mounted on/dev/mapper/VolGroup-lv_root                       18G 1003M   16G   7% /tmpfs                 491M     0  491M   0% /dev/shm/dev/sda1             477M   52M  400M  12% /bootserver01:/dht          69G  4.0G   62G   7% /mnt[root@server01 ~]#

(6) 使用分布式卷

[root@server01 mnt]# touch file{001..010}  // 创建十个文件[root@server01 mnt]# lsfile001  file002  file003  file004  file005  file006  file007  file008  file009  file010[root@server01 mnt]#在集群机器上查看文件分布情况:[root@server01 Data]# cd dht1/[root@server01 dht1]# lsfile002  file004  file005  file008  file009[root@server01 dht1]#[root@server02 Data]# cd dht2/[root@server02 dht2]# lsfile010[root@server02 dht2]#[root@server03 Data]# cd dht3/[root@server03 dht3]# lsfile003  file006[root@server03 dht3]#[root@server04 Data]# cd dht4/[root@server04 dht4]# lsfile001  file007[root@server04 dht4]#

以上是十个文件在server机器上得分布情况。

详细的搭建文档请点击这里下载

0 0