pre.cjk { font-family: "Nimbus Mono L",monospace; }h2.western { font-family: "Liberation Sans",sans-serif; font-size: 16pt; }h2.cjk { font-family: "思源黑体 CN Regular"; font-size: 16pt; }h2.ctl { font-family: "Lohit Devanagari"; font-size: 16pt; }h1 { margin-bottom: 0.21cm; }h1.western { font-family: "Liberation Sans",sans-serif; font-size: 18pt; }h1.cjk { font-family: "思源黑体 CN Regular"; font-size: 18pt; }h1.ctl { font-family: "Lohit Devanagari"; font-size: 18pt; }p { margin-bottom: 0.25cm; line-height: 120%; }a:link { }tt.cjk { font-family: "Nimbus Mono L",monospace; }
块设备快速入门
学习本节,必须在已经执行完 的基础上。首先保证已经部署的 是 active
+ clean状态。
The
Ceph Block Device is also known as or Block Device.
ceph-client 必须是一台单独的虚拟机,但不要使用与部署Ceph
Storage Cluster相同的一台物理机的虚拟机,
除非你没有别的机器。
安装 Ceph
-
[talen@ceph_admin mycluster]$ cat ~/.ssh/config
-
-
Host ceph_node1
-
-
Hostname ceph_node1
-
-
User talen
-
-
Host ceph_node2
-
-
Hostname ceph_node2
-
-
User talen
-
-
Host ceph_monitor
-
-
Hostname ceph_monitor
-
-
User talen
-
-
Host ceph_client 添加服务器到ssh_config
-
-
Hostname ceph_client
-
-
User talen
-
确保你有合适的内核版本。具体可查看OS推荐里的信息。
-
在管理节点上,使用ceph-deploy安装ceph到客户端节点,这里主机名为ceph_client。
-
ceph-deploy install ceph_client
-
在管理节点上,使用ceph-deploy部署ceph配置文件与认证文件ceph.client.admin.keyring 到客户端。
-
ceph-deploy admin ceph_client
认为文件保存在客户端的/etc/ceph目录下,确保talen用户可以访问此文件
-
sudo chmod +r /etc/ceph/ceph.client.admin.keyring
-
验证:
-
[root@ceph_client ceph]# su - talen
-
-
Last login: Thu Sep 17 11:30:51 CST 2015 from 192.168.100.199 on pts/1
-
-
[talen@ceph_client ~]$ cd /etc/ceph/
-
-
[talen@ceph_client ceph]$ ll
-
-
total 8
-
-
-rw-------. 1 root root 63 Sep 17 11:33 ceph.client.admin.keyring
-
-
-rw-r--r--. 1 root root 265 Sep 17 11:33 ceph.conf
-
-
-rw-------. 1 root root 0 Sep 14 18:42 tmp5AWVt0
-
-
-rw-------. 1 root root 0 Sep 17 11:33 tmpY_56Be
-
-
[talen@ceph_client ceph]$ sudo chmod +r /etc/ceph/ceph.client.admin.keyring
-
-
[talen@ceph_client ceph]$ ll
-
-
total 8
-
-
-rw-r--r--. 1 root root 63 Sep 17 11:33 ceph.client.admin.keyring
-
-
-rw-r--r--. 1 root root 265 Sep 17 11:33 ceph.conf
-
-
-rw-------. 1 root root 0 Sep 14 18:42 tmp5AWVt0
-
-
-rw-------. 1 root root 0 Sep 17 11:33 tmpY_56Be
-
-
[talen@ceph_client ceph]$ ceph status
-
-
cluster 08416be1-f6e7-4c5a-b7b3-7eb148b0c467
-
-
health HEALTH_WARN
-
-
clock skew detected on mon.ceph_node2, mon.ceph_monitor
-
-
Monitor clock skew detected
-
-
monmap e3: 3 mons at {ceph_monitor=10.0.2.33:6789/0,ceph_node1=10.0.2.31:6789/0,ceph_node2=10.0.2.32:6789/0}
-
-
election epoch 6, quorum 0,1,2 ceph_node1,ceph_node2,ceph_monitor
-
-
osdmap e15: 3 osds: 3 up, 3 in
-
-
pgmap v192: 192 pgs, 2 pools, 0 bytes data, 0 objects
-
-
15463 MB used, 9079 MB / 24543 MB avail
-
-
192 active+clean
-
-
[talen@ceph_client ceph]$
pre.cjk { font-family: "Nimbus Mono L",monospace; }h2.western { font-family: "Liberation Sans",sans-serif; font-size: 16pt; }h2.cjk { font-family: "思源黑体 CN Regular"; font-size: 16pt; }h2.ctl { font-family: "Lohit Devanagari"; font-size: 16pt; }p { margin-bottom: 0.25cm; line-height: 120%; }a:link { }tt.cjk { font-family: "Nimbus Mono L",monospace; }
客户端使用块设备
-
首先在客户端节点创建一个块设备镜像文件,大小4G,名称暂定为foo.
[talen@ceph_client
ceph]$ rbd create foo --size 4096 -m 10.0.2.33 -k
/etc/ceph/ceph.client.admin.keyring
-
然后在客户端节点映射镜像文件到一个块设备/dev/rbd0。
[talen@ceph_client
ceph]$ sudo rbd map foo --name client.admin -m 10.0.2.33 -k
/etc/ceph/ceph.client.admin.keyring
/dev/rbd0
-
在客户端服务器上为新块设备创建文件系统,这里以EXT4为例进行格式化。
[talen@ceph_client
rbd]$ ll /dev/rbd/rbd/foo
lrwxrwxrwx.
1 root root 10 Sep 17 15:09 /dev/rbd/rbd/foo -> ../../rbd0
[talen@ceph_client
rbd]$ sudo mkfs.ext4 -m0 /dev/rbd0
mke2fs
1.42.9 (28-Dec-2013)
Discarding
device blocks: done
Filesystem
label=
OS
type: Linux
Block
size=4096 (log=2)
Fragment
size=4096 (log=2)
Stride=1024
blocks, Stripe width=1024 blocks
262144
inodes, 1048576 blocks
0
blocks (0.00%) reserved for the super user
First
data block=0
Maximum
filesystem blocks=1073741824
32
block groups
32768
blocks per group, 32768 fragments per group
8192
inodes per group
Superblock
backups stored on blocks:
32768,
98304, 163840, 229376, 294912, 819200, 884736
Allocating
group tables: done
Writing
inode tables: done
Creating
journal (32768 blocks): done
Writing
superblocks and filesystem accounting information: done
[talen@ceph_client
rbd]$
-
挂载已经格式化好的文件系统盘。
[talen@ceph_client rbd]$ mkdir /mnt/ceph-block-device
mkdir: cannot create directory ‘/mnt/ceph-block-device’: Permission denied
[talen@ceph_client rbd]$ sudo mkdir /mnt/ceph-block-device
[talen@ceph_client rbd]$ sudo mount /dev/rbd0 /mnt/ceph-block-device/
[talen@ceph_client rbd]$ cd /mnt/ceph-block-device/
[talen@ceph_client ceph-block-device]$ touch testfile
touch: cannot touch ‘testfile’: Permission denied
[talen@ceph_client ceph-block-device]$ sudo touch testfile
[talen@ceph_client ceph-block-device]$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/centos-root 7022592 1410872 5611720 21% /
devtmpfs 933432 0 933432 0% /dev
tmpfs 942208 0 942208 0% /dev/shm
tmpfs 942208 8560 933648 1% /run
tmpfs 942208 0 942208 0% /sys/fs/cgroup
/dev/vda1 508588 139920 368668 28% /boot
/dev/rbd0 3997376 16376 3964616 1% /mnt/ceph-block-device
[talen@ceph_client ceph-block-device]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 6.7G 1.4G 5.4G 21% /
devtmpfs 912M 0 912M 0% /dev
tmpfs 921M 0 921M 0% /dev/shm
tmpfs 921M 8.4M 912M 1% /run
tmpfs 921M 0 921M 0% /sys/fs/cgroup
/dev/vda1 497M 137M 361M 28% /boot
/dev/rbd0 3.9G 16M 3.8G 1% /mnt/ceph-block-device
[talen@ceph_client ceph-block-device]$
下面来测试一下
[talen@ceph_client ceph-block-device]$ sudo cp /boot/* /mnt/ceph-block-device/
cp: omitting directory ‘/boot/grub’
cp: omitting directory ‘/boot/grub2’
[talen@ceph_client ceph-block-device]$
[talen@ceph_admin mycluster]$ ceph -w
cluster 08416be1-f6e7-4c5a-b7b3-7eb148b0c467
health HEALTH_WARN
clock skew detected on mon.ceph_node2, mon.ceph_monitor
Monitor clock skew detected
monmap e3: 3 mons at {ceph_monitor=10.0.2.33:6789/0,ceph_node1=10.0.2.31:6789/0,ceph_node2=10.0.2.32:6789/0}
election epoch 6, quorum 0,1,2 ceph_node1,ceph_node2,ceph_monitor
osdmap e15: 3 osds: 3 up, 3 in
pgmap v218: 192 pgs, 2 pools, 136 MB data, 45 objects
15888 MB used, 8654 MB / 24543 MB avail
192 active+clean
2015-09-17 15:37:20.759666 mon.0 [WRN] mon.1 10.0.2.32:6789/0 clock skew 0.916739s > max 0.05s
2015-09-17 15:39:38.416394 mon.0 [INF] pgmap v219: 192 pgs: 192 active+clean; 136 MB data, 15888 MB used, 8654 MB / 24543 MB avail; 36 B/s wr, 0 op/s
2015-09-17 15:39:49.853666 mon.0 [INF] pgmap v220: 192 pgs: 192 active+clean; 143 MB data, 15901 MB used, 8641 MB / 24543 MB avail; 20610 B/s wr, 0 op/s
2015-09-17 15:39:52.633944 mon.0 [INF] pgmap v221: 192 pgs: 192 active+clean; 165 MB data, 15934 MB used, 8608 MB / 24543 MB avail; 613 B/s rd, 2076 kB/s wr, 8 op/s
2015-09-17 15:39:53.739112 mon.0 [INF] pgmap v222: 192 pgs: 192 active+clean; 176 MB data, 15981 MB used, 8561 MB / 24543 MB avail; 1360 B/s rd, 5313 kB/s wr, 22 op/s
2015-09-17 15:39:56.360405 mon.0 [INF] pgmap v223: 192 pgs: 192 active+clean; 188 MB data, 16009 MB used, 8533 MB / 24543 MB avail; 5369 kB/s wr, 22 op/s
2015-09-17 15:40:18.457344 mon.0 [INF] pgmap v224: 192 pgs: 192 active+clean; 192 MB data, 16039 MB used, 8503 MB / 24543 MB avail; 647 kB/s wr, 2 op/s
2015-09-17 15:40:21.161880 mon.0 [INF] pgmap v225: 192 pgs: 192 active+clean; 203 MB data, 16055 MB used, 8487 MB / 24543 MB avail; 649 kB/s wr, 2 op/s
2015-09-17 15:40:25.202123 mon.0 [INF] pgmap v226: 192 pgs: 192 active+clean; 216 MB data, 16102 MB used, 8440 MB / 24543 MB avail; 4418 kB/s wr, 18 op/s
2015-09-17 15:40:27.279849 mon.0 [INF] pgmap v227: 192 pgs: 192 active+clean; 226 MB data, 16129 MB used, 8413 MB / 24543 MB avail; 4107 kB/s wr, 17 op/s
2015-09-17 15:40:28.366190 mon.0 [INF] pgmap v228: 192 pgs: 192 active+clean; 233 MB data, 16160 MB used, 8382 MB / 24543 MB avail; 4050 kB/s wr, 17 op/s
2015-09-17 15:40:29.458292 mon.0 [INF] pgmap v229: 192 pgs: 192 active+clean; 233 MB data, 16185 MB used, 8357 MB / 24543 MB avail; 2276 kB/s wr, 11 op/s
2015-09-17 15:40:30.713275 mon.0 [INF] pgmap v230: 192 pgs: 192 active+clean; 241 MB data, 16197 MB used, 8345 MB / 24543 MB avail; 3627 kB/s wr, 20 op/s
2015-09-17 15:41:00.788336 mon.0 [INF] pgmap v231: 192 pgs: 192 active+clean; 241 MB data, 16197 MB used, 8345 MB / 24543 MB avail; 408 B/s wr, 0 op/s