LoginSignup
7
10

More than 5 years have passed since last update.

Cephクラスタを構築してみた(CentOS7)

Posted at

構成

・OS:CentOS7
・ceph:13.2.2
・サーバー構成:OSD兼MONノード3台、MDSノード1台、管理ノード1台

OSD(Object Storage Daemon):データのレプリカの作成など
MON(Monitor):障害監視 
MDS(Metadeta Server Daemon):CephFSによるクライアントからのアクセス制御

OS設定

・Firewall,SELinux無効化

systemctl stop firewalld
systemctl disable firewalld
vi /etc/selinux/config ←「disabled」に変更

・hosts設定
「/etc/hosts」ファイルに以下を追記

192.168.11.115 ceph-node1.vsphere.local ceph-node1
192.168.11.116 ceph-node2.vsphere.local ceph-node2
192.168.11.117 ceph-node3.vsphere.local ceph-node3
192.168.11.118 ceph-mds.vsphere.local ceph-mds
192.168.11.119 ceph-admin.vsphere.local ceph-admin

・管理ノードでの鍵作成(管理ノード)
ssh-keygen -t rsa
・ノードへの公開鍵コピー

ssh-copy-id root@ceph-node1.vsphere.local
ssh-copy-id root@ceph-node2.vsphere.local
ssh-copy-id root@ceph-node3.vsphere.local
ssh-copy-id root@ceph-mds.vsphere.local

Cephインストールと設定(管理ノード)

・リポジトリ追加

cat << EOM > /etc/yum.repos.d/ceph.repo
[ceph-noarch]
name=Ceph noarch packages
baseurl=https://download.ceph.com/rpm-mimic/el7/noarch
enabled=1
gpgcheck=1
type=rpm-md
gpgkey=https://download.ceph.com/keys/release.asc
EOM

・ceph-deployパッケージインストール
yum install ceph-deploy
・パッケージ確認

[root@ceph-admin ~]# rpm -qa | grep ceph
ceph-deploy-2.0.1-0.noarch

・pythonツールインストール
yum install python-setuptools
※これをしないと、以下エラーが出た

[root@ceph-admin my-cluster]# ceph-deploy
Traceback (most recent call last):
  File "/bin/ceph-deploy", line 18, in <module>
    from ceph_deploy.cli import main
  File "/usr/lib/python2.7/site-packages/ceph_deploy/cli.py", line 1, in <module>
    import pkg_resources
ImportError: No module named pkg_resources

・クラスタ用ディレクトリ作成
mkdir /root/my-cluster
cd /root/my-cluster
・my-clusterにOSDノードを登録
ceph-deploy new ceph-node1.vsphere.local ceph-node2.vsphere.local ceph-node3.vsphere.local
・設定ファイル確認

[root@ceph-admin my-cluster]# cat ceph.conf
[global]
fsid = 2281bd02-48d8-4be2-be94-e28e3b84273c
mon_initial_members = ceph-node1, ceph-node2, ceph-node3
mon_host = 192.168.11.115,192.168.11.116,192.168.11.117
auth_cluster_required = cephx
auth_service_required = cephx
auth_client_required = cephx

・ノード群にCeph関連パッケージをインストール
GPGキーやEPELリポジトリ、CephリポジトリなどのCephに関連するパッケージがインストールされる

[root@ceph-admin my-cluster]# ceph-deploy install ceph-node1.vsphere.local ceph-node2.vsphere.local ceph-node3.vsphere.local ceph-admin.vsphere.local ceph-mds.vsphere.local
中略
[ceph-mds.vsphere.local][DEBUG ] Complete!
[ceph-mds.vsphere.local][INFO  ] Running command: ceph --version
[ceph-mds.vsphere.local][DEBUG ] ceph version 13.2.2 (02899bfda814146b021136e9d8e80eba494e1126) mimic (stable)

※時間がかかった場合、
[ceph_deploy][ERROR ] RuntimeError: NoSectionError: No section: 'ceph'
と出た。
その際、実行中だったサーバーとその後ろだけ残して再実行
例(ceph-admin.vsphere.localを実行中だった場合):
ceph-deploy install ceph-admin.vsphere.local ceph-mds.vsphere.local

・ceph.confファイルの「mon_host」に従い、監視のノードを構成
ceph-deploy mon create-initial
※「mon_host」がドメイン名無しで記載されているため、その名前で名前解決できないとエラーとなった
・cephコマンドを利用可能にする
ceph-deploy admin ceph-node1.vsphere.local ceph-node2.vsphere.local ceph-node3.vsphere.local ceph-admin.vsphere.local ceph-mds.vsphere.local
・cephコマンドの確認(監視ノードの稼働確認)
ceph mon stat
・OSD設定
各ノードの/dev/sdbをデータ用として指定する

ceph-deploy osd create --data /dev/sdb ceph-node1.vsphere.local
ceph-deploy osd create --data /dev/sdb ceph-node2.vsphere.local
ceph-deploy osd create --data /dev/sdb ceph-node3.vsphere.local

・OSDノードの状況確認

[root@ceph-admin my-cluster]# ceph osd stat
3 osds: 3 up, 3 in; epoch: e23

・MDSノード設定
ceph-deploy mds create ceph-mds.vsphere.local
・MDSノードの状況確認

[root@ceph-admin my-cluster]# ceph mds stat
, 1 up:standby

・cephストレージクラスタ全体の状態確認

[root@ceph-admin my-cluster]# ceph health
HEALTH_OK
[root@ceph-admin my-cluster]# ceph -s
  cluster:
    id:     2281bd02-48d8-4be2-be94-e28e3b84273c
    health: HEALTH_OK

  services:
    mon: 3 daemons, quorum ceph-node1,ceph-node2,ceph-node3
    mgr: ceph-admin(active)
    osd: 3 osds: 3 up, 3 in

  data:
    pools:   4 pools, 32 pgs
    objects: 14  objects, 1.5 KiB
    usage:   3.0 GiB used, 147 GiB / 150 GiB avail
    pgs:     32 active+clean

・Manager作成

ceph-deploy mgr create ceph-admin.vsphere.local
ceph mgr module enable dashboard
ceph dashboard create-self-signed-cert
ceph dashboard set-login-credentials <username> <password>
radosgw-admin user create --uid=<username> --display-name=<displayname> --system
# ここで表示されたJSON形式ユーザー情報を適当なファイルに保存
ceph dashboard set-rgw-api-access-key <JSONの access key>
ceph dashboard set-rgw-api-secret-key <JSONの secret key>

# ダッシュボード再起動
ceph mgr module disable dashboard
ceph mgr module enable dashboard

・ダッシュボードにアクセス
https://192.168.11.119:8443

オブジェクトストレージ作成(管理ノード)

・プール作成
ceph osd pool create pool01 128
128:プールのプレースメントグループ(レプリカをどのOSDノードに割り当てるかを計算するために必要な値)の数
・プールのリスト表示
ceph osd lspools
・オブジェクトをプールと紐づけ
ceph osd map pool01 obj01
・テスト

[root@ceph-admin ~]# echo "Test01" > testfile01.txt ←テストファイル作成
[root@ceph-admin ~]# rados put obj01 ./testfile01.txt --pool=pool01 ←pool01の中のobj01としてテストファイルをput
[root@ceph-admin ~]# rados -p pool01 ls ←pool01が持つオブジェクトを確認
obj01
[root@ceph-admin ~]# rados get obj01 ./output01.txt --pool=pool01 ←obj01をoutput.txtに書き出し
[root@ceph-admin ~]# cat output01.txt
Test01

ブロックストレージ作成(管理ノード)

・プール作成
ceph osd pool create pool02 10
・プール初期化
rbd pool init pool02
・イメージファイル作成(4GB)
rbd create vol01 -p pool02 --size 10G --image-feature layering
・イメージファイル確認

[root@ceph-admin ~]# rbd -p pool02 ls -l
NAME    SIZE PARENT FMT PROT LOCK
vol01 10 GiB          2

・イメージファイルとクライアントのデバイスをマッピング

[root@ceph-admin ~]# rbd map vol01 -p pool02
/dev/rbd0

・マッピング確認

[root@ceph-admin ~]# rbd showmapped
id pool   image snap device
0  pool02 vol01 -    /dev/rbd0

・デバイス確認

[root@ceph-admin dev]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   50G  0 disk
tqsda1            8:1    0  500M  0 part /boot
mqsda2            8:2    0 49.5G  0 part
  tqcentos-root 253:0    0 45.6G  0 lvm  /
  mqcentos-swap 253:1    0  3.9G  0 lvm  [SWAP]
sr0              11:0    1 1024M  0 rom
rbd0            252:0    0   10G  0 disk

・ファイルシステム構築

[root@ceph-admin /]# mkdir /ceph-disk
[root@ceph-admin /]# fdisk /dev/rbd0
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xf4439926.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1):
First sector (8192-20971519, default 8192):
Using default value 8192
Last sector, +sectors or +size{K,M,G} (8192-20971519, default 20971519):
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@ceph-admin /]# mkfs.xfs -f /dev/rbd0
meta-data=/dev/rbd0              isize=512    agcount=16, agsize=163840 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=2621440, imaxpct=25
         =                       sunit=1024   swidth=1024 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=8 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@ceph-admin /]# mount /dev/rbd0 /ceph-disk
[root@ceph-admin /]# df -T
Filesystem              Type     1K-blocks    Used Available Use% Mounted on
/dev/mapper/centos-root xfs       47781076 1785548  45995528   4% /
devtmpfs                devtmpfs   1928504       0   1928504   0% /dev
tmpfs                   tmpfs      1940480       0   1940480   0% /dev/shm
tmpfs                   tmpfs      1940480    8984   1931496   1% /run
tmpfs                   tmpfs      1940480       0   1940480   0% /sys/fs/cgroup
/dev/sda1               xfs         508588  301556    207032  60% /boot
tmpfs                   tmpfs       388096       0    388096   0% /run/user/1000
/dev/rbd0               xfs       10475520   33328  10442192   1% /ceph-disk

参考

http://docs.ceph.com/docs/mimic/start/quick-ceph-deploy/
http://metonymical.hatenablog.com/entry/2018/07/07/200337

7
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
10