1. 程式人生 > >使用CEPH提供塊裝置

使用CEPH提供塊裝置

Yum

點選圖中CentOS7就可以下載網易的repo檔案,將其拷貝到/etc/yum.repos.d/目錄下就能線上使用網易的源了。

EPEL: Extra Packages for Enterprise Linux

點選上圖中的連結,將會下載一個名為epel-release-latest-7.noarch.rpm的軟體包,只要把它安裝上,/etc/yum.repos.d/目錄下將會出現新的repo檔案

使用CEPH提供塊裝置

1、CEPH預設有一個儲存池

[[email protected] ceph_conf]# ceph osd lspools

2、為了能夠給客戶端提供塊裝置,需要建立image

3、在預設的池中建立一個10GB

大小,名為demo-image的映象

[[email protected] ceph_conf]# rbd create demo-image --image-feature layering --size 10G

4、另一種建立方法:指定在rbd這個池裡建立一個名為image的映象

[[email protected] ceph_conf]# rbd create rbd/image --image-feature layering --size 10G

5、列出映象

[[email protected] ceph_conf]# rbd list

6、檢視image的詳情

[[email protected]

 ceph_conf]# rbd info image

7、調整image映象的大小為7GB(體驗而已,不推薦減小操作)

[[email protected] ceph_conf]# rbd resize --size 7G image --allow-shrink

8、調整image映象的大小為15GB

[[email protected] ceph_conf]# rbd resize --size 15G image 

[[email protected] ceph_conf]# rbd info image

客戶端使用RBD塊裝置

1、在Client上安裝客戶端軟體包

[[email protected]

 ~]# yum install -y ceph-common

2、把配置檔案和使用者金鑰檔案拷貝給客戶端

[[email protected] ceph_conf]# scp /etc/ceph/ceph.conf 192.168.4.10:/etc/ceph/

[[email protected] ceph_conf]# scp /etc/ceph/ceph.client.admin.keyring 192.168.4.10:/etc/ceph/

3、客戶端把CEPHimage映象作為本地磁碟使用

[[email protected] ~]# rbd list

[[email protected] ~]# rbd map image

[[email protected] ~]# lsblk   多出一個15GBrbd0

4、使用RBD塊裝置

[[email protected] ~]# mkfs.xfs /dev/rbd0 

[[email protected] ~]# mount /dev/rbd0 /mnt/

[[email protected] ~]# df -h /mnt/

[[email protected] ~]# echo "hello world" >> /mnt/hi.txt

[[email protected] ~]# cat /mnt/hi.txt

5、檢視image映象的快照

[[email protected] ~]# rbd snap ls image

6、為image建立一個名為image-snap1的快照

[[email protected] ~]# rbd snap create image --snap image-snap1

[[email protected] ~]# rbd snap ls image

7、模擬誤刪除

[[email protected] ~]# rm  -f  /mnt/hi.txt 

8、還原快照,以還原誤刪除的檔案

(1)解除安裝映象

[[email protected] ~]# umount /mnt/

(2)使用image-snap1還原快照

[[email protected] ~]# rbd snap rollback image --snap image-snap1

(3)掛載映象,檢視是否已還原

[[email protected] ~]# mount /dev/rbd0 /mnt/

[[email protected] ~]# ls /mnt/

[[email protected] ~]# cat /mnt/hi.txt 

通過快照建立映象

1、設定image-snap1為保護狀態

[[email protected] ~]# rbd snap protect image --snap image-snap1

2、使用image的快照image-snap1克隆一個新的image-clone映象

[[email protected] ~]# rbd clone image --snap image-snap1 image-clone --image-feature layering

3、檢視新映象與父映象的關係

[[email protected] ~]# rbd info image-clone  

找到它的parentrbd/[email protected]

4、合併映象,使得image-clone沒有父映象,它可以獨立使用

[[email protected] ~]# rbd flatten image-clone

[[email protected] ~]# rbd info image-clone  此時,它已沒有parent

刪除掛載

[[email protected] ~]# rbd showmapped  可以檢視到映象到本地的塊裝置對映

[[email protected] ~]# umount /mnt/

[[email protected] ~]# rbd unmap image   取消對映

[[email protected] ~]# rbd showmapped

[[email protected] ~]# lsblk   發現rbd0已經不存在了

刪除快照

[[email protected] ~]# rbd snap ls image  列出image的快照

[[email protected] ~]# rbd snap unprotect image --snap image-snap1

[[email protected] ~]# rbd snap rm image --snap image-snap1

刪除映象

[[email protected] ~]# rbd rm image

[[email protected] ~]# rbd list

安裝KVM虛擬機器,磁碟儲存在CEPH叢集上

1、將物理主機設定成為CEPH客戶端

[[email protected] ~]# yum install -y ceph-common

[[email protected] ~]# scp 192.168.4.1:/etc/ceph/ceph.conf /etc/ceph/

[[email protected] ~]# scp 192.168.4.1:/etc/ceph/ceph.client.admin.keyring /etc/ceph/

2、新建一個名為vm1-image的映象,作為KVM虛擬機器的磁碟

[[email protected] ~]# rbd create vm1-image --image-feature layering --size 10G

3、檢視映象資訊

[[email protected] ~]# rbd info vm1-image

[[email protected] ~]# qemu-img info rbd:rbd/vm1-image

4、在virt-manager圖形介面中,建立新的虛擬機器,名為rhel7-ceph1,按正常步驟建立即可。當虛擬機器建立完成後,將會啟動,此時,點選強制關機。

5、KVM虛擬機器在使用CEPH的時候,需要認證,我們可以建立一個secret(相當於通行證)

(1)在物理主機上建立一臨時檔案

[[email protected] ~]# vim /tmp/secret.xml

<secret ephemeral='no' private='no'>

    <usage type='ceph'>

        <name>client.admin secret</name>

    </usage>

</secret>

(2)利用臨時檔案生成secret通行證資訊

[[email protected] ~]# virsh secret-list  檢視secret

[[email protected] ~]# virsh secret-define --file /tmp/secret.xml 

[[email protected] ~]# virsh secret-list   已經生成secret

6、將kvmsecretceph的管理員使用者client.admin進行關聯

(1)檢視管理員的keyring

[[email protected] ~]# cat /etc/ceph/ceph.client.admin.keyring 

(2)關聯secretkeyring

[[email protected] ~]# virsh secret-set-value --secret f59c54be-d479-41a6-a09c-cf2f7ffc57cb --base64 AQDaDSpboImwIBAAzX800q+H0BCNq9xq2xQaJA==

7、匯出rhel7-ceph1xml檔案

[[email protected] ~]# virsh dumpxml rhel7-ceph1 > /tmp/vm.xml

8、修改vm.xml

[[email protected] ~]# vim /tmp/vm.xml

找到以下內容:

    <disk type='file' device='disk'>

      <driver name='qemu' type='qcow2'/>

      <source file='/var/lib/libvirt/images/rhel7-ceph1.qcow2'/>

      <target dev='vda' bus='virtio'/>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>

</disk>

將其改為

    <disk type='network' device='disk'>

      <driver name='qemu' type='raw'/>

      <auth username='admin'>

          <secret type='ceph' uuid='f59c54be-d479-41a6-a09c-cf2f7ffc57cb'/>

      </auth>

      <source protocol='rbd' name='rbd/vm1-image'>

          <host name='192.168.4.1' port='6789'/>

      </source>

      <target dev='vda' bus='virtio'/>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>

    </disk>

9、在virt-manager中將rhel7-ceph1刪除

10、使用修改過的vm.xml生成虛擬機器

[[email protected] ~]# virsh  define  /tmp/vm.xml

Virt-manager中將會出現rhel7-ceph1虛擬機器

11、修改虛擬機器配置,把IDE CDROM1連線光碟檔案,然後在Boot Options中勾選啟用引導選單,把光碟作為第一啟動介質

使用CEPH FS為客戶端提供檔案系統(相當於NFS),注意,這種方式還不成熟,不建議用在生產環境下。

1、準備node4作為MDS(元資料伺服器)

2、在node4上安裝軟體包

[[email protected] ~]# yum install -y ceph-mds

3、在node1上配置node4MDS

[[email protected] ceph_conf]# cd /root/ceph_conf/  進入配置檔案目錄

4、同步adminkeyringnode4

[[email protected] ceph_conf]# ceph-deploy admin node4

5、在NODE4上啟用mds服務(在node1上操作)

[[email protected] ceph_conf]# ceph-deploy mds create node4

6、建立儲存池。至少有兩個池,一個用於儲存資料,一個用於儲存元資料。

[[email protected] ceph_conf]# ceph osd pool create cephfs_data 128

[[email protected] ceph_conf]# ceph osd pool create cephfs_metadata 128

注:128是指,池中有128PG(歸置組)

7、檢視MDS狀態

[[email protected] ceph_conf]# ceph mds stat

8、建立檔案系統

[[email protected] ceph_conf]# ceph fs new myfs1 cephfs_metadata cephfs_data

9、檢視檔案系統

[[email protected] ceph_conf]# ceph fs ls

10、客戶端掛載CEPH FS

[[email protected] ~]# mkdir /mnt/cephfs   ceph auth list  檢視adminkey

[[email protected] ~]# mount -t ceph 192.168.4.1:6789:/ /mnt/cephfs/ -o name=admin,secret=AQDaDSpboImwIBAAzX800q+H0BCNq9xq2xQaJA==

[[email protected] ~]# df -h /mnt/cephfs/

物件儲存

1、什麼是物件,參見:http://storage.ctocio.com.cn/281/12110781.shtml

2、新建虛擬機器,用於RGW

node5.tedu.cn 192.168.4.5 

需要node1可以免密登陸到node5Node5也需要cephyum源。Node1可以通過名字訪問node5

3、在node1遠端為node5安裝RGW

[[email protected] ceph_conf]# ceph-deploy install --rgw node5

4、同步keyring等檔案到node5

[[email protected] ceph_conf]# ceph-deploy admin node5

5、啟動RGW服務

[[email protected] ceph_conf]# ceph-deploy rgw create node5

[[email protected] ~]# systemctl status [email protected]\*

6、RGW內建了一個WEB伺服器civetweb。為了使用者訪問方便,將RGW埠改為80(預設是7480

[[email protected] ~]# vim /etc/ceph/ceph.conf 追加以下內容

[client.rgw.node5]

host=node5

rgw_frontends="civetweb port=80"

[[email protected] ~]# systemctl restart [email protected]\*   重啟服務

7、客戶端驗證

[[email protected] ~]# curl http://192.168.4.5

RGW客戶端的使用

1s3是亞馬遜提供的一個命令列客戶端

[[email protected] ~]# rpm -ihv s3cmd-2.0.1-1.el7.noarch.rpm 

2、建立用於RGW訪問的使用者

[[email protected] ~]# radosgw-admin user create --uid="testuser" --display-name="First User"  注意以下輸出的資訊

"keys": [

        {

            "user": "testuser",

            "access_key": "2OEWOIA7G6GZZ22UI0E4",

            "secret_key": "FrOzh6NQC1Ak3C4SXNSaLAEFPy5SyPu9MC02mtdm"

        }

    ],

3、在客戶端上配置s3

[[email protected] ~]# s3cmd --configure

Access Key:2OEWOIA7G6GZZ22UI0E4

Secret Key: FrOzh6NQC1Ak3C4SXNSaLAEFPy5SyPu9MC02mtdm

Default Region [US]:   注意直接回車,不要改

S3 Endpoint [s3.amazonaws.com]: 192.168.4.5

DNS-style bucket+hostname:port template for accessing a bucket [%(bucket)s.s3.amazonaws.com]:  %(bucket)s.192.168.4.5

When using secure HTTPS protocol all communication with Amazon S3

servers is protected from 3rd party eavesdropping. This method is

slower than plain HTTP, and can only be proxied with Python 2.7 or newer

Use HTTPS protocol [Yes]: No

Test access with supplied credentials? [Y/n] y

Save settings? [y/N] y

配置檔案最終儲存在了/root/.s3cfg

4、客戶端配置完成,就可以執行上傳、下載、刪除等操作了

[[email protected] ~]# s3cmd ls  檢視

[[email protected] ~]# s3cmd mb s3://my_bucket  建立一個容器(資料夾)

[[email protected] ~]# s3cmd put /var/log/messages s3://my_bucket  上傳檔案

[[email protected] ~]# s3cmd ls s3://my_bucket  檢視my_bucket中的內容

[[email protected] ~]# s3cmd get s3://my_bucket/messages /tmp/  下載

[[email protected] ~]# s3cmd del  s3://my_bucket/messages  刪除

相關推薦

使用CEPH提供裝置

Yum:點選圖中CentOS7就可以下載網易的repo檔案,將其拷貝到/etc/yum.repos.d/目錄下就能線上使用網易的源了。EPEL: Extra Packages for Enterprise Linux點選上圖中的連結,將會下載一個名為epel-release-

Ceph裝置(RBD)常用命令

建立塊裝置映像 rbd create --size {megabytes} {pool-name}/{image-name} 例項: [ceph-deploy@ceph-admin ~]$ rbd create --size 1024 foo

Ceph叢集的裝置對映到本地目錄的過程

 客戶端使用儲存下來的金鑰能夠對映雲硬碟池rbd001上的雲硬碟,許可權為讀寫。 # cd ~ 把從web端下載好的金鑰檔案client.rbdmix.keyring和配置檔案ceph.conf

初試 Ceph 儲存之裝置、檔案系統、物件儲存

目錄 Ceph 儲存介紹 環境、軟體準備 Ceph 塊裝置 Ceph 檔案系統 Ceph 物件儲存 1、Ceph 儲存介紹 Ceph 是一個開源的分散式儲存系統,包括物件儲存、塊裝置、檔案系統。它可靠性高、管理方便、伸縮性強,能夠輕鬆應對PB

Ceph實踐總結之:Centos 下RBD裝置客戶端的配置

    如果客戶端需要重啟,需要將掛載目錄先解除安裝,重啟之後再重新執行rbd map,以及mount 的操作,否則系統在重啟的過程中會被卡在"Umounting file system"這個操作上。解除安裝命令如下:

Ceph設備、文件系統、對象存儲的使用

ceph 塊設備/對象存儲/文件系統 上面左邊是我的個人微信,如需進一步溝通,請加微信。 右邊是我的公眾號“Openstack私有雲”,如有興趣,請關註。 繼上篇《Ceph 之 使用ceph-deploy部署ceph集群》,ceph集群搭建完成之後,接下來就是使用了,ceph集群可以提供給塊設備、文

裝置之三

一、I/O排程器 1.1 資料結構 在將請求提交給塊裝置時,核心提供了各種排程策略,這些排程器用於重排和排程I/O請求以獲得最優的效能。I/O排程器在核心中被稱為elevator。核心使用瞭如下資料結構來實現和管理I/O排程器: struct elevator_type {

裝置驅動之二

一、將塊裝置新增到系統 register_blkdev並沒有真正將裝置新增到系統中,想要將裝置新增到系統中,需要使用如下API: void blk_register_region(dev_t devt, unsigned long range, struct module *module,

裝置驅動程式之一

一、塊裝置概述 linux支援的兩種重要的裝置型別分別是字元裝置和塊裝置,塊裝置可以隨機地以固定大小的塊傳送資料。與字元裝置相比,塊裝置有以下幾個特殊之處: 塊裝置可以從資料的任何位置進行訪問 塊資料總是以固定長度進行傳輸,即便請求的這是一個位元組 對塊裝置的訪問有大量的快

《Linux Device Drivers》第十六章 裝置驅動程式——note

簡介 一個塊裝置驅動程式主要通過傳輸固定大小的隨機資料來訪問裝置 Linux核心視塊裝置為與字元裝置相異的基本裝置型別 Linux塊裝置驅動程式介面使得塊裝置可以發揮其最大的功效,但是其複雜程式又是程式設計者必須面對的一個問題 一個數據塊指的是固

工作常用檢視裝置命令lsblk詳解

lsblk命令可以列出所有可用塊裝置的資訊,比如我們說的邏輯磁碟,而df -h檢視的是檔案系統級別的資訊。lsblk命令包含在util-linux包中,yum安裝util-linux包即可,util-linux包含多個命令工具。 [[email protected] ~]# df -h Files

裝置核心引數max_segments和max_sectors_kb解析

linux塊裝置在處理io時會受到一些引數(裝置的queue limits引數,以下簡稱limits引數)的影響,比如一個請求中允許的最大扇區數,最大segment數等。這些引數可以在/sys/block//queue/下檢視,塊裝置在初始化時會設定預設值。這裡主要分析max_segments和ma

《5.linux驅動開發-第10部分-5.10.裝置驅動介紹》

《5.linux驅動開發-第10部分-5.10.塊裝置驅動介紹》 第一部分、章節目錄 5.10.1.正確理解塊裝置驅動的概念 5.10.2.塊裝置驅動框架簡介 5.10.3.塊裝置驅動案例分析1 5.10.4.塊裝置驅動案例分析2 5.10.5.塊裝置驅動案例分析3 第二部分、章節介

虛擬機器裝置掛載引數錯誤導致無法開機問題處理

故障現象 給虛擬機器增加一個卷後,重啟無法進入系統。   故障原因 /etc/fstab中填寫的檔案系統型別與分割槽實際檔案系統不一致。   處理方法 將虛擬機器系統卷掛載到其他虛擬機器上,修改/etc/fstab為正確配置。   排查過程 同事給一臺虛擬機器

裝置層bdev程式設計簡介

介紹 塊裝置是支援以固定大小的塊讀取和寫入資料的儲存裝置。這些塊通常為512或4096位元組。裝置可以是軟體中的邏輯構造,或者對應於諸如NVMe SSD的物理裝置。 塊裝置層包含單個通用庫lib/bdev,以及實現各種型別的塊裝置的許多可選模組(作為單獨的庫)。通用庫的公共標頭檔案是bdev.h,它是與任

Linux Shell 判斷裝置節點是否存在

/************************************************************************* * Linux Shell 判斷塊裝置節點是否存在 * 說明: * 能牌問shell指令碼-f不能判

Linux裝置驅動

推薦書:《Linux核心原始碼情景分析》   1.字元裝置驅動和使用中等待某一事件的方法①查詢方式②休眠喚醒,但是這種沒有超時時間③poll機制,在休眠喚醒基礎上加一個超時時間④非同步通知,非同步通知實際上就是發訊號⑤輸入子系統,這樣比較通用 2.塊裝置相對於字元裝置驅動邏輯的變化①對於硬碟對

如何提高Linux下裝置IO的整體效能?

編輯手記:本文主要講解Linux IO排程層的三種模式:cfp、deadline和noop,並給出各自的優化和適用場景建議。 作者簡介: 鄒立巍 Linux系統技術專家。目前在騰訊SNG社交網路運營部 計算資源平臺組,負責內部私有云平臺的建設和架構規劃設計。 曾任新浪動態應用平臺系統架構師,負責微

Linux裝置驅動總結

《Linux裝置驅動程式》第十六章 塊裝置驅動程式讀書筆記 簡介 一個塊裝置驅動程式主要通過傳輸固定大小的隨機資料來訪問裝置 Linux核心視塊裝置為與字元裝置相異的基本裝置型別 Linux塊裝置驅動程式介面使得塊裝置可以發揮其最大的功效,但是其複雜程式又是程式設計者必須

Linux驅動開發04:裝置驅動和網路裝置驅動

介紹 因為塊裝置驅動和網路裝置驅動實際中用得較少,所以只給出驅動模板,我也沒有具體測試,等到實際用到是再研究吧,溜了溜了。 塊裝置驅動模板 struct xxx_dev { int size; struct request_q