ceph安装配置
簡介
ceph是一個開源分布式存儲系統,支持PB級別的存儲,支持對 象存儲,塊存儲和文件存儲,高性能,高可用,可擴展。
部署網絡建議架構圖
部署
部署架構圖,本次實驗部署jewel版本
實驗環境的Vagrantfile
lab1節點既作admin節點又作node節點,lab2,lab3只作為node節點,lab4作為作測試使用ceph的節點
# -*- mode: ruby -*- # vi: set ft=ruby :ENV["LC_ALL"] = "en_US.UTF-8"Vagrant.configure("2") do |config|(1..4).each do |i|config.vm.define "lab#{i}" do |node|node.vm.box = "centos-7.4-docker-17"node.ssh.insert_key = falsenode.vm.hostname = "lab#{i}"node.vm.network "private_network", ip: "11.11.11.11#{i}"node.vm.provision "shell",inline: "echo hello from node #{i}"node.vm.provider "virtualbox" do |v|v.cpus = 3v.customize ["modifyvm", :id, "--name", "lab#{i}", "--memory", "3096"]file_to_disk = "lab#{i}_vdb.vdi"unless File.exist?(file_to_disk)# 50GBv.customize ['createhd', '--filename', file_to_disk, '--size', 50 * 1024]endv.customize ['storageattach', :id, '--storagectl', 'IDE', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', file_to_disk]endendend end 復制代碼配置阿里ceph源
在所有節點執行如下操作
cat >/etc/yum.repos.d/ceph.repo<<EOF [ceph] name=ceph baseurl=http://mirrors.aliyun.com/ceph/rpm-jewel/el7/x86_64/ gpgcheck=0 priority=1[ceph-noarch] name=cephnoarch baseurl=http://mirrors.aliyun.com/ceph/rpm-jewel/el7/noarch/ gpgcheck=0 priority=1[ceph-source] name=Ceph source packages baseurl=http://mirrors.163.com/ceph/rpm-jewel/el7/SRPMS enabled=0 gpgcheck=1 type=rpm-md gpgkey=http://mirrors.163.com/ceph/keys/release.asc priority=1 EOF yum makecache 復制代碼在admin節點安裝ceph-deploy
lab1 節點
# 官方源 # 如果已經配置了上面的阿里源,不需要再配置如下的源 # 推薦使用阿里源,因為官方源速度太慢 cat >/etc/yum.repos.d/ceph.repo<<EOF [ceph-noarch] name=Ceph noarch packages baseurl=https://download.ceph.com/rpm-jewel/el7/noarch enabled=1 gpgcheck=1 type=rpm-md gpgkey=https://download.ceph.com/keys/release.asc EOF# 更新系統軟件 # 此操作可省略 # yum update -y# 安裝 ceph-deploy yum install -y ceph-deploy 復制代碼配置admin節點連接node節點
安裝之后需要配置admin節點可以ssh無密碼登錄每個node節點和測試節點,用戶需要有sudo權限
# 在每一個node節點執行 useradd ceph echo 'ceph' | passwd --stdin ceph echo "ceph ALL = (root) NOPASSWD:ALL" > /etc/sudoers.d/ceph chmod 0440 /etc/sudoers.d/ceph # 配置sshd可以使用password登錄 sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config systemctl reload sshd # 配置sudo不需要tty sed -i 's/Default requiretty/#Default requiretty/' /etc/sudoers# 在所有節點配置hosts # 包括要進行ceph測試的機器 # 使用vagrant實驗時注意 # 由于vagrant會自動把主機名解析為 127.0.0.1 # 所以在實驗時如果在ceph集群內任意一臺機器進行實驗時 # 注意把本機名解析為 127.0.0.1 的行注釋,如下所示 # 127.0.0.1 lab1 lab1 cat >>/etc/hosts<<EOF 11.11.11.111 lab1 11.11.11.112 lab2 11.11.11.113 lab3 11.11.11.113 lab4 EOF# 在admin節點執行 # 創建ceph用戶,配置sshkey登錄 # 由于lab1節點作為node節點時已經創建過ceph用戶 # 第一條命令可能會出錯,忽略即可 useradd ceph su - ceph ssh-keygen ssh-copy-id ceph@lab1 ssh-copy-id ceph@lab2 ssh-copy-id ceph@lab3 ssh-copy-id ceph@lab4 復制代碼在admin節點創建集群
在lab1節點執行如下操作,node的主機名一定要設置正確 lab1, lab2, lab3。否則可能會無法實驗成功
# 不要使用sudo也不要使用root用戶運行如下的命令 su - ceph mkdir my-cluster cd my-cluster # 創建lab1為monitor ceph-deploy new lab1# 查看配置文件 ls -l# 配置ceph.conf [global] ... # 如果有多個網卡,應該配置如下選項, # public network是公共網絡,負責集群對外提供服務的流量 # cluster network是集群網絡,負載集群中數據復制傳輸通信等 # 本次實驗使用同一塊網卡,生境環境建議分別使用一塊網卡 public network = 11.11.11.0/24 cluster network = 11.11.11.0/24# 安裝 ceph 包 # 如果按照官方文檔安裝方法 會重新配置安裝官方ceph源 # 由于網絡問題,安裝可能會出錯,需要多次執行 # ceph-deploy install 其實只是會安裝 ceph ceph-radosgw 兩個包 # ceph-deploy install lab1 lab2 lab3 # 推薦使用阿里源安裝,因為使用ceph-deploy安裝會很慢 # 使用如下命令手動安裝包,替代官方的 ceph-deploy install 命令 # 如下操作在所有node節點上執行 yum install -y ceph ceph-radosgw# 部署monitor和生成keys ceph-deploy mon create-initial ls -l *.keyring# 復制文件到node節點 ceph-deploy admin lab1 lab2 lab3# 部署manager (luminous+)12及以后的版本需要部署 # 本次部署 jewel 版本 ,不需要執行如下命令 # ceph-deploy mgr create lab1# 添加osd 以磁盤方式 # 本次實驗采用此種方法 # sdb 為虛擬機添加的磁盤設置名 ceph-deploy osd create lab1:sdb lab2:sdb lab3:sdb# 在node節點創建目錄 rm -rf /data/osd1 mkdir -pv /data/osd1 chmod 777 -R /data/osd1 chown ceph.ceph -R /data/osd1# 添加osd 以文件目錄方式 ceph-deploy osd prepare lab1:/data/osd1 lab2:/data/osd1 lab3:/data/osd1 ceph-deploy osd activate lab1:/data/osd1 lab2:/data/osd1 lab3:/data/osd1# 查看狀態 ssh lab1 sudo ceph health ssh lab1 sudo ceph -s 復制代碼清理集群
# 如果安裝過程出錯,使用如下命令清理之后重新開始 ceph-deploy purge lab1 lab2 lab3 ceph-deploy purgedata lab1 lab2 lab3 ceph-deploy forgetkeys rm ceph.* 復制代碼擴展集群
提高可用性
- 在lab1上運行metadata server 為后續使用cephfs
 - 在lab2,lab3運行monitor和manager提高集群可用性
 
部署RGW使用Ceph Object Gateway
提供S3/Swift存儲功能,實現S3和Swift兼容的接口,可以使用S3或Swift的命令行工具或SDK來使用ceph
# 啟動 rgw ceph-deploy rgw create lab1# 修改配置 /etc/ceph/ceph.conf # 使用 rgw 監聽在 80 端口 # lab1 為啟動 rgw 的主機名 [client.rgw.lab1] rgw_frontends = "civetweb port=80"# 重啟 rgw systemctl restart ceph-radosgw@rgw.lab1# 訪問測試 curl -I http://11.11.11.111/ 復制代碼使用ceph存儲
應用存儲使用架構圖
對象存儲
# 安裝ceph yum install -y ceph# 復制相關文件到要使用ceph-client的機器 ceph-deploy admin lab4# 測試 # 存儲文件 echo 'hello ceph oject storage' > testfile.txt ceph osd pool create mytest 8 rados put test-object-1 testfile.txt --pool=mytest# 查看讀取文件 rados -p mytest ls rados get test-object-1 testfile.txt.1 --pool=mytest cat testfile.txt.1# 查看文件位置 ceph osd map mytest test-object-1# 刪除文件 rados rm test-object-1 --pool=mytest# 刪除pool ceph osd pool rm mytest mytest --yes-i-really-really-mean-it 復制代碼塊存儲
# 安裝ceph yum install -y ceph# 復制相關文件到要使用ceph-client的機器 ceph-deploy admin lab4# 創建塊設備鏡像 rbd create foo --size 4096 --image-feature layering rbd info foo rados -p rbd ls# 映射鏡像到塊設備 sudo rbd map foo --name client.admin# 使用塊設備創建文件系統 sudo mkfs.ext4 -m0 /dev/rbd/rbd/foo# 掛載使用 sudo mkdir /mnt/ceph-block-device sudo mount /dev/rbd/rbd/foo /mnt/ceph-block-device cd /mnt/ceph-block-device echo 'hello ceph block storage' > testfile.txt# 清理 cd ~ sudo umount -lf /mnt/ceph-block-device sudo rbd unmap foo rbd remove foo rados -p rbd ls 復制代碼S3對象存儲
11.11.11.111 為安裝了 RGW 的機器
# 安裝 yum install -y ceph ceph-radosgw# 復制相關文件到要使用ceph-client的機器 ceph-deploy admin lab4# 創建S3所需要的pool ceph osd pool create .rgw 128 128 ceph osd pool create .rgw.root 128 128 ceph osd pool create .rgw.control 128 128 ceph osd pool create .rgw.gc 128 128 ceph osd pool create .rgw.buckets 128 128 ceph osd pool create .rgw.buckets.index 128 128 ceph osd pool create .rgw.buckets.extra 128 128 ceph osd pool create .log 128 128 ceph osd pool create .intent-log 128 128 ceph osd pool create .usage 128 128 ceph osd pool create .users 128 128 ceph osd pool create .users.email 128 128 ceph osd pool create .users.swift 128 128 ceph osd pool create .users.uid 128 128# 查看 rados lspools# 訪問測試 curl -I http://11.11.11.111/# 創建S3用戶 # 保存如下命令返回的 user access_key secret_key radosgw-admin user create --uid=foo --display-name=foo --email=foo@foo.com# 創建admin用戶 radosgw-admin user create --uid=admin --display-name=admin# 允許admin讀寫users信息 radosgw-admin caps add --uid=admin --caps="users=*"# 允許admin讀寫所有的usage信息 radosgw-admin caps add --uid=admin --caps="usage=read,write"# 安裝s3測試工具 yum install -y s3cmd# 配置s3cmd, 只需指定Access Key和Secret Key,其他默認即可 s3cmd --configure# 修該生成的配置文件 vim $HOME/.s3cfg host_base = 11.11.11.111 host_bucket = 11.11.11.111/%(bucket) use_https = False# 創建Bucket s3cmd mb s3://mybucket s3cmd ls# 上傳Object echo 'hello ceph block storage s3' > hello.txt s3cmd put hello.txt s3://mybucket# 查看Object s3cmd ls s3://mybucket# 下載Object cd /tmp s3cmd get s3://mybucket/hello.txt cd ~# 刪除bucket下所有對象 s3cmd del -rf s3://mybucket/ s3cmd ls -r s3://mybucket# 刪除Bucket s3cmd mb s3://mybucket1 s3cmd rb s3://mybucket1# 刪除S3用戶 radosgw-admin user rm --uid=foo radosgw-admin user rm --uid=admin# 刪除pool ceph osd pool delete .rgw .rgw --yes-i-really-really-mean-it ceph osd pool delete .rgw.root .rgw.root --yes-i-really-really-mean-it ceph osd pool delete .rgw.control .rgw.control --yes-i-really-really-mean-it ceph osd pool delete .rgw.gc .rgw.gc --yes-i-really-really-mean-it ceph osd pool delete .rgw.buckets .rgw.buckets --yes-i-really-really-mean-it ceph osd pool delete .rgw.buckets.index .rgw.buckets.index --yes-i-really-really-mean-it ceph osd pool delete .rgw.buckets.extra .rgw.buckets.extra --yes-i-really-really-mean-it ceph osd pool delete .log .log --yes-i-really-really-mean-it ceph osd pool delete .intent-log .intent-log --yes-i-really-really-mean-it ceph osd pool delete .usage .usage --yes-i-really-really-mean-it ceph osd pool delete .users .users --yes-i-really-really-mean-it ceph osd pool delete .users.email .users.email --yes-i-really-really-mean-it ceph osd pool delete .users.swift .users.swift --yes-i-really-really-mean-it ceph osd pool delete .users.uid .users.uid --yes-i-really-really-mean-it 復制代碼CephFS存儲
# 安裝ceph yum install -y ceph ceph-fuse# 復制相關文件到要使用ceph-client的機器 ceph-deploy admin lab4# CephFS需要使用兩個Pool來分別存儲數據和元數據 ceph osd pool create fs_data 128 ceph osd pool create fs_metadata 128 ceph osd lspools# 創建一個CephFS ceph fs new cephfs fs_metadata fs_data# 查看 ceph fs ls# 使用內核提供的功能 掛載CephFS # 由于可能會有bug,建議使用 4.0 以上的內核 # 優點是性能比使用ceph-fuse更好 # name,secret 為 /etc/ceph/ceph.client.admin.keyring 里的內容 mkdir /mnt/mycephfs mount -t ceph lab1:6789,lab2:6789,lab3:6789:/ /mnt/mycephfs -o name=admin,secret=AQBoclRaiilZJBAACLjqg2OUOOB/FNa20UJXYA== df -h cd /mnt/mycephfs echo 'hello ceph CephFS' > hello.txt cd ~ umount -lf /mnt/mycephfs rm -rf /mnt/mycephfs# 使用 ceph-fuse 掛載CephFS mkdir /mnt/mycephfs ceph-fuse -m lab1:6789 /mnt/mycephfs df -h cd /mnt/mycephfs echo 'hello ceph CephFS' > hello.txt cd ~ umount -lf /mnt/mycephfs rm -rf /mnt/mycephfs# 清理 # 停止 metadata server # 本次部署在lab1,去lab1停止服務 systemctl stop ceph-mds@lab1 ceph fs rm cephfs --yes-i-really-mean-it ceph osd pool delete fs_data fs_data --yes-i-really-really-mean-it ceph osd pool delete fs_metadata fs_metadata --yes-i-really-really-mean-it# 開啟 metadata server # 方便以后使用 cephfs systemctl start ceph-mds@lab1本文轉自掘金-ceph安裝配置
總結
                            
                        - 上一篇: Git之原有基础开发新功能
 - 下一篇: 0027-生成圆