Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Gluster集群搭建-操作Gluster集群

Gluster集群搭建-操作Gluster集群

編輯:關於Android編程

安裝前准備:

1. Windows系統

2. Xshell遠程ssh軟件

3. 在CentOS上安裝好Gluster集群的集群機

 

創建四種卷

(1) 分布式卷(哈希卷)

[root@server01 ~]# gluster volume create dht server01:/Data/dht1 server02:/Data/dht2 server03:/Data/dht3 server04:/Data/dht4 force  // 創建一個名為dht的哈希卷
volume create: dht: success: please start the volume to access data
[root@server01 ~]#

[root@server01 ~]# gluster volume start dht    // 啟動哈希卷
volume start: dht: success
[root@server01 ~]# gluster volume  status    // 查看卷的情況
Status of volume: dht
Gluster process                     Port    Online  Pid
------------------------------------------------------------------------------
Brick server01:/Data/dht1               49153   Y   1787
Brick server02:/Data/dht2               49153   Y   1631
Brick server03:/Data/dht3               49153   Y   1607
Brick server04:/Data/dht4               49153   Y   1626
NFS Server on localhost                 2049    Y   1797
NFS Server on server02                  2049    Y   1641
NFS Server on server03                  2049    Y   1617
NFS Server on server04                  2049    Y   1636

There are no active volume tasks
[root@server01 ~]#

(2) 復制卷

[root@server01 ~]# gluster volume create afr replica 2 server01:/Data/afr1 server02:/Data/afr2 server03:/Data/afr3 server04:/Data/afr4 force   // 創建一組備份為2的復制卷
volume create: afr: success: please start the volume to access data
[root@server01 ~]# gluster volume start afr     // 啟動復制卷
volume start: afr: success
[root@server01 ~]# gluster volume status afr    // 查看復制卷的大小
Status of volume: afr
Gluster process                     Port    Online  Pid
------------------------------------------------------------------------------
Brick server01:/Data/afr1               49154   Y   1823
Brick server02:/Data/afr2               49154   Y   1647
Brick server03:/Data/afr3               49154   Y   1623
Brick server04:/Data/afr4               49154   Y   1643
NFS Server on localhost                 2049    Y   1833
Self-heal Daemon on localhost               N/A Y   1840
NFS Server on server02                  2049    Y   1659
Self-heal Daemon on server02                N/A Y   1663
NFS Server on server03                  2049    Y   1633
Self-heal Daemon on server03                N/A Y   1639
NFS Server on server04                  2049    Y   1655
Self-heal Daemon on server04                N/A Y   1659

There are no active volume tasks
[root@server01 ~]#

注意:這裡的文件夾數,必須是replica的倍數,而且最好文件夾在一台機器上不要出現兩個,因為復制卷有復制的屬性,可能將兩個備份全部放置在一台機器上,數據不安全。

(3) 條帶卷

[root@server01 Data]# gluster volume create stp stripe 2 server01:/Data/stp1 server02:/Data/stp2 server03:/Data/stp3 server04:/Data/stp4 force  // 創建一個條帶卷
volume create: stp: success: please start the volume to access data
[root@server01 Data]# gluster volume start stp   // 啟動條帶卷
volume start: stp: success
[root@server01 Data]# gluster volume status stp  // 查看條帶卷的狀態
Status of volume: stp
Gluster process                     Port    Online  Pid
------------------------------------------------------------------------------
Brick server01:/Data/stp1               49155   Y   1873
Brick server02:/Data/stp2               49155   Y   1672
Brick server03:/Data/stp3               49155   Y   1646
Brick server04:/Data/stp4               49155   Y   1667
NFS Server on localhost                 2049    Y   1883
NFS Server on server02                  2049    Y   1682
NFS Server on server04                  2049    Y   1677
NFS Server on server03                  2049    Y   1656

There are no active volume tasks
[root@server01 Data]#

(4) 哈希+復制卷

[root@server01 ~]# gluster volume create dht_afr replica 2 server01:/Data/dht_afr1 server02:/Data/dht_afr2 server03:/Data/dht_afr3 server04:/Data/dht_afr4 server01:/Data/dht_afr5 server02:/Data/dht_afr6 server03:/Data/dht_afr7 server04:/Data/dht_afr8 force   // 創建8個brick,2備份的哈希+復制卷
volume create: dht_afr: success: please start the volume to access data
[root@server01 ~]# gluster volume start dht_afr   // 啟動卷
volume start: dht_afr: success
[root@server01 ~]# gluster volume status dht_afr  // 查看卷的情況
Status of volume: dht_afr
Gluster process                     Port    Online  Pid
------------------------------------------------------------------------------
Brick server01:/Data/dht_afr1               49156   Y   1911
Brick server02:/Data/dht_afr2               49156   Y   1690
Brick server03:/Data/dht_afr3               49156   Y   1662
Brick server04:/Data/dht_afr4               49156   Y   1683
Brick server01:/Data/dht_afr5               49157   Y   1920
Brick server02:/Data/dht_afr6               49157   Y   1699
Brick server03:/Data/dht_afr7               49157   Y   1671
Brick server04:/Data/dht_afr8               49157   Y   1692
NFS Server on localhost                 2049    Y   1930
Self-heal Daemon on localhost               N/A Y   1937
NFS Server on server02                  2049    Y   1709
Self-heal Daemon on server02                N/A Y   1716
NFS Server on server04                  2049    Y   1702
Self-heal Daemon on server04                N/A Y   1709
NFS Server on server03                  2049    Y   1681
Self-heal Daemon on server03                N/A Y   1688

There are no active volume tasks
[root@server01 ~]#

(5) 查看所有卷的情況

[root@server01 ~]# gluster volume info   // 查看命令

Volume Name: dht
Type: Distribute
Volume ID: fe5af0f8-1b43-46ab-ad91-da87b4e99e62
Status: Started
Number of Bricks: 4
Transport-type: tcp
Bricks:
Brick1: server01:/Data/dht1
Brick2: server02:/Data/dht2
Brick3: server03:/Data/dht3
Brick4: server04:/Data/dht4

Volume Name: afr
Type: Distributed-Replicate
Volume ID: b2705571-054f-4532-909d-54af0a372fe7
Status: Started
Number of Bricks: 2 x 2 = 4
Transport-type: tcp
Bricks:
Brick1: server01:/Data/afr1
Brick2: server02:/Data/afr2
Brick3: server03:/Data/afr3
Brick4: server04:/Data/afr4

Volume Name: stp
Type: Distributed-Stripe
Volume ID: e2dd3d60-a168-4bb2-bbf7-fdca2b8795a9
Status: Started
Number of Bricks: 2 x 2 = 4
Transport-type: tcp
Bricks:
Brick1: server01:/Data/stp1
Brick2: server02:/Data/stp2
Brick3: server03:/Data/stp3
Brick4: server04:/Data/stp4

Volume Name: dht_afr
Type: Distributed-Replicate
Volume ID: 1661d1e5-7fbd-472a-a602-f844c33cf451
Status: Started
Number of Bricks: 4 x 2 = 8
Transport-type: tcp
Bricks:
Brick1: server01:/Data/dht_afr1
Brick2: server02:/Data/dht_afr2
Brick3: server03:/Data/dht_afr3
Brick4: server04:/Data/dht_afr4
Brick5: server01:/Data/dht_afr5
Brick6: server02:/Data/dht_afr6
Brick7: server03:/Data/dht_afr7
Brick8: server04:/Data/dht_afr8
[root@server01 ~]#

遠程掛載文件系統

(1) 在client上測試是否連通(掛載文件系統掛哪個集群主機都行)

[root@client ~]# ping server01
PING server01 (192.168.220.136) 56(84) bytes of data.
64 bytes from server01 (192.168.220.136): icmp_seq=1 ttl=64 time=1.71 ms
64 bytes from server01 (192.168.220.136): icmp_seq=2 ttl=64 time=0.301 ms
64 bytes from server01 (192.168.220.136): icmp_seq=3 ttl=64 time=0.317 ms
^C
--- server01 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2250ms
rtt min/avg/max/mdev = 0.301/0.777/1.714/0.662 ms

(2) 創建掛載文件夾

[root@client ~]# mkdir /mnt/dht /mnt/afr /mnt/stp /mnt/dht_afr 
[root@client ~]# ls /mnt/
afr  dht  dht_afr  stp
[root@client ~]#

(3) 掛載文件到遠端client

[root@client ~]# 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% /boot
[root@client ~]# mount -t glusterfs server01:/dht /mnt/dht    // 掛載dht卷到/mnt/dht
[root@client ~]# mount -t glusterfs server01:/afr /mnt/afr   // 掛載afr卷到/mnt/afr
[root@client ~]# mount -t glusterfs server01:/stp /mnt/stp   // 掛載stp卷到/mnt/stp
[root@client ~]# mount -t glusterfs server01:/dht_afr /mnt/dht_afr  // 掛載dht_afr卷到/mnt/dht_afr
[root@client ~]# 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% /boot
server01:/dht          69G  4.0G   62G   7% /mnt/dht
server01:/afr          35G  2.0G   31G   7% /mnt/afr
server01:/stp          69G  4.0G   62G   7% /mnt/stp
server01:/dht_afr      69G  4.0G   62G   7% /mnt/dht_afr
[root@client ~]#

(4) 將掛載文件寫入/etc/fstab

[root@client ~]# vi /etc/fstab
最後添加如下內容
server01:/dht           /mnt/dht                glusterfs defaults,_netdev 0 0
server01:/afr           /mnt/afr                glusterfs defaults,_netdev 0 0
server01:/stp           /mnt/stp                glusterfs defaults,_netdev 0 0
server01:/dht_afr       /mnt/dht_afr            glusterfs defaults,_netdev 0 0

然後我們就可以一個命令掛載四個文件了
[root@client ~]# umount /mnt/dht   // 卸載剛才掛載的文件
[root@client ~]# umount /mnt/afr
[root@client ~]# umount /mnt/stp
[root@client ~]# umount /mnt/dht_afr/
[root@client ~]# 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% /boot

[root@client ~]# mount -a          // 一鍵掛載所有文件系統
[root@client ~]# dh –f             // 查看掛載情況
-bash: dh: command not found
[root@client ~]# 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% /boot
server01:/dht          69G  4.0G   62G   7% /mnt/dht
server01:/afr          35G  2.0G   31G   7% /mnt/afr
server01:/stp          69G  4.0G   62G   7% /mnt/stp
server01:/dht_afr      69G  4.0G   62G   7% /mnt/dht_afr
[root@client ~]#

使用samba服務器共享到Windows端

(1) client安裝Samba服務器

[root@client ~]# yum install samba samba-client samba-swat –y  // 安裝Samba全家桶

[root@client ~]# /etc/init.d/smb status   // 查看服務情況
smbd is stopped
[root@client ~]# /etc/init.d/smb start    // 開啟服務
Starting SMB services:                                     [  OK  ]
[root@client ~]# chkconfig smb on      // 設置開機啟動Samba
[root@client ~]# chkconfig --list smb     // 查看啟動情況設置
smb             0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@client ~]#

(2) 修改配置文件

[root@client ~]# vi /etc/samba/smb.conf  // 編輯配置文件

來到最後一行,添加如下:
[public]
        comment = Public for gluster file
        path = /mnt       // 共享目錄
        browseable = yes   // 是否可以浏覽
        writable = yes      // 是否可以寫數據
        public = yes        // 是否允許非賬戶用戶浏覽
[root@client dht]# chmod 777 /mnt/dht /mnt/afr /mnt/stp /mnt/dht_afr // 為文件夾賦寫權限
[root@client dht]# ls /mnt/
afr  dht  dht_afr  stp
[root@client dht]# ls -l /mnt/
total 56
drwxrwxrwx. 3 root root  8192 Aug  1 01:35 afr
drwxrwxrwx. 4 root root 16384 Aug  1 02:51 dht
drwxrwxrwx. 3 root root 16384 Aug  1 01:51 dht_afr
drwxrwxrwx. 3 root root  8192 Aug  1 01:46 stp
[root@client dht]#

(3) 添加samba用戶

[root@client ~]# adduser smbuser     // 添加centos用戶
[root@client ~]# smbpasswd -a smbuser // 將centos用戶添加到samba用戶組中
New SMB password:                 // 輸入密碼
Retype new SMB password:
Added user smbuser.
[root@client ~]# smbpasswd -e smbuser // 將samba用戶添加到samba列表中
Enabled user smbuser.
[root@client ~]# /etc/init.d/smb restart    // 重啟服務
Shutting down SMB services:                                [  OK  ]
Starting SMB services:                                     [  OK  ]
[root@client ~]#

(4) Windows端測試登陸

在計算機最上面中,輸入ip地址,第一次需要輸入賬號:smbuser和密碼,即可進入到共享目錄中。

我們可以看到兩個文件夾,一個smbuser文件夾是我們的centos的用戶目錄,一個public文件夾是我們共享目錄,打開public即可往裡面存入數據。

GlusterFS的高級應用

(1) 需求分析

現在要求一個學校中用到Gluster存儲,並且數據可以用samba服務器共享到Windows目錄下。

條件一:

一個公共共享目錄,這個目錄中,工具區和文件區都同屬於公共區,這個只有超級用戶擁有絕對權限,其他學院管理員擁有對本系文件的讀寫操作,對其他系文件和工具區文件只有浏覽權限。

條件二:

在各個學院中,管理員有對學院文件區域絕對管理權限,學生對自己創建的文件有絕對管理權,其他人對別人的文件和管理員的文件有浏覽權限。

條件三:

學院中的區域只能夠給自己學院的學生和管理員浏覽,其他人只能在共享區才能看到其他學院的文件目錄。在共享區,除了管理員有創建權權限,學生只有浏覽權限

(2) 創建用戶

Tools管理員賬號:superadmin

軟件管理員賬號:softmin     軟件普通帳戶:softuser

經管管理員賬號:economicmin     經管普通用戶:economicuser

教育管理員賬號:educationmin    教育普通用戶:educationuser

[root@client /]# useradd -s /sbin/nologin softmin
[root@client /]# useradd -g softmin -s /sbin/nologin softuser
[root@client /]# useradd -s /sbin/nologin economicmin
[root@client /]# useradd -g economicmin -s /sbin/nologin economicuser
[root@client /]# useradd -s /sbin/nologin educationmin
[root@client /]# useradd -g educationmin -s /sbin/mologin educationuser
[root@client /]# useradd -s /sbin/nologin superadmin
[root@client /]# smbpasswd -a softmin 
New SMB password:
Retype new SMB password:
Added user softmin.
[root@client /]# smbpasswd -a softuser
New SMB password:
Retype new SMB password:
Added user softuser.
[root@client /]# smbpasswd -a economicmin 
New SMB password:
Retype new SMB password:
Added user economicmin.
[root@client /]# smbpasswd -a economicuser
New SMB password:
Retype new SMB password:
Added user economicuser.
[root@client /]# smbpasswd -a educationmin
New SMB password:
Retype new SMB password:
Added user educationmin.
[root@client /]# smbpasswd -a educationuser
New SMB password:
Retype new SMB password:
Added user educationuser.
[root@client /]# smbpasswd -a superadmin
New SMB password:
Retype new SMB password:
Added user superadmin.
[root@client /]#

(3) 創建文件,實現共享

[root@client /]# mkdir /mnt/dht/School /mnt/dht/School/soft /mnt/dht/School/economic /mnt/dht/School/education /mnt/dht/School/share /mnt/dht/School/share/soft /mnt/dht/School/share/economic /mnt/dht/School/share/education /mnt/dht/School/share/tools            // 創建文件夾
[root@client /]# ls -l /mnt/dht/School/
total 64
drwxr-xr-x. 2 root root 16384 Aug  1 04:28 economic
drwxr-xr-x. 2 root root 16384 Aug  1 04:28 education
drwxr-xr-x. 6 root root 16384 Aug  1 04:28 share
drwxr-xr-x. 2 root root 16384 Aug  1 04:28 soft
[root@client /]# ls -l /mnt/dht/School/share/
total 64
drwxr-xr-x. 2 root root 16384 Aug  1 04:28 economic
drwxr-xr-x. 2 root root 16384 Aug  1 04:28 education
drwxr-xr-x. 2 root root 16384 Aug  1 04:28 soft
drwxr-xr-x. 2 root root 16384 Aug  1 04:28 tools
[root@client /]#

(4) 更改文件權限

[root@client /]# chown softmin.softmin /mnt/dht/School/soft && chown economicmin.economicmin /mnt/dht/School/economic && chown educationmin.educationmin /mnt/dht/School/education && chown superadmin.superadmin /mnt/dht/School/share   // 更改用戶的所屬權限

[root@client /]# chown 1775 /mnt/dht/School/soft /mnt/dht/School/economic /mnt/dht/School/education /mnt/dht/School/share   // 更改在這個目錄下讀寫權限,不能刪除
[root@client /]# chown -R 0775 /mnt/dht/School/share

[root@client /]# chown softmin.softmin /mnt/dht/School/share/soft && chown economicmin.economicmin /mnt/dht/School/share/economic && chown educationmin.educationmin /mnt/dht/School/share/education && chown superadmin.superadmin /mnt/dht/School/share/tools 
[root@client /]# chown 1775 /mnt/dht/School/share/soft /mnt/dht/School/share/economic /mnt/dht/School/share/education

修改普通用戶在學院的寫權限,即在本學院創建文件自己擁有絕對的權限,其他人除了管理員,不能對其刪除,只能修改
修改各學院管理用戶在學院的寫權限,即在本學院創建文件自己擁有絕對的權限,其他人除了管理員,不能對其刪除,只能修改
[root@client /]# chmod g+w /mnt/dht/School/soft /mnt/dht/School/economic /mnt/dht/School/education /mnt/dht/School/share /mnt/dht/School/share/soft /mnt/dht/School/share/economic /mnt/dht/School/share/education
[root@client /]# chmod o+t /mnt/dht/School/soft /mnt/dht/School/economic /mnt/dht/School/education /mnt/dht/School/share /mnt/dht/School/share/soft /mnt/dht/School/share/economic /mnt/dht/School/share/education
[root@client /]#

(5) 配置samba文件

[root@client /]# vi /etc/samba/smb.conf     // 編輯文件
將這些配置寫入到這個文件末尾:
[soft]
    comment = This is a directory of soft college
    path = /mnt/dht/School/soft
    public = no
    admin users = softmin
    valid users = @softmin
    writable = yes
    create mask = 0750
    driectory mask = 0750
[economic]
    comment = This is a directory of soft economic
    path = /mnt/dht/School/economic
    public = no
    admin users = economic
    valid users = @economic
    writable = yes
    create mask = 0750
    driectory mask = 0750

[education]
    comment = This is a directory of soft education
    path = /mnt/dht/School/education
    public = no
    admin users = education
    valid users = @education
    writable = yes
    create mask = 0750
    driectory mask = 0750

[Share]
     comment = This is a share directory.
     path = /mnt/dht/School/share
     public = no
     valid users = superadmin,@softmin,@softmin,@education
     writable = yes
     create mask = 0755
     directory mask = 0755

[root@client /]# /etc/init.d/smb restart     // 重啟samba服務器
Shutting down SMB services:                                [  OK  ]
Starting SMB services:                                     [  OK  ]
[root@client /]#

(6) 以上實現了文件的權限問題,接下來實現文件大小問題

[root@server01 ~]# gluster volume quota dht limit-usage /School 100MB
limit set on /School
[root@server01 ~]# gluster volume quota dht limit-usage /School/soft 10MB
limit set on /School/soft
[root@server01 ~]# gluster volume quota dht limit-usage /School/economic 10MB
limit set on /School/economic
[root@server01 ~]# gluster volume quota dht limit-usage /School/education 10MB
limit set on /School/education
[root@server01 ~]# gluster volume quota dht limit-usage /School/share 70MB
limit set on /School/share
[root@server01 ~]# gluster volume quota dht list
    path          limit_set      size
----------------------------------------------------------------------------------
/School                   100MB               0Bytes
/School/soft               10MB               0Bytes
/School/economic           10MB               0Bytes
/School/education          10MB               0Bytes
/School/share              70MB               0Bytes
[root@server01 ~]#

(7) 測試

Windows鍵+R ,輸入cmd
輸入net use * /del
輸入Y,把網絡掛載刪除掉

Microsoft Windows [版本 6.1.7601]
版權所有 (c) 2009 Microsoft Corporation。保留所有權利。

C:\Users\gluster>net use * /del
您有以下的遠程連接:

                    \\192.168.220.135\IPC$
繼續運行會取消連接。

您想繼續此操作嗎? (Y/N) [N]: y
命令成功完成。


C:\Users\gluster>net use * /del
列表是空的。


C:\Users\gluster>

在我的電腦中輸入IP地址,然後輸入賬號和密碼,即可看到所有的共享文件夾

進入到soft文件夾下,因為用的是softmin用戶,所以在soft文件夾下可以新建文件夾,可以拷貝文件,最大文件拷貝大小是10MB,多余這個數據就會拷貝失敗。這個用戶無法訪問到其他專業的文件夾,如果點擊需要輸入賬號和密碼。

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved