1、準備環境php
4臺adminos7.4 環境,存儲節點上兩塊磁盤(sda操做系統,sdb數據盤)node
client
admin
storage1
storage2
storage3
2、配置環境python
一、修改主機名(對應節點上執行)linux
# hostnamectl set-hostname client
# hostnamectl set-hostname admin
# hostnamectl set-hostname storage1
# hostnamectl set-hostname storage2
# hostnamectl set-hostname storage3
二、配置hosts文件(每一個節點上均執行)git
# cat <<"EOF">/etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.8.91 client
172.16.8.92 admin
172.16.8.93 admin
172.16.8.94 storage1
172.16.8.95 storage2
172.16.8.96 storage3
EOF
三、修改sudo配置文件,註釋下面行(每一個節點上均執行)
執行visudo命令註釋下面一行github
#Defaults requiretty
1
四、ceph的官方源在國外,網速比較慢,此處添加ceph源爲清華源(每一個節點上均執行)web
# cat <<END >/etc/yum.repos.d/ceph.repo
[Ceph]
name=Ceph packages for $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/ceph/rpm-mimic/el7/x86_64/
enabled=1
gpgcheck=1
type=rpm-md
gpgkey=https://download.ceph.com/keys/release.ascjson
[Ceph-noarch]
name=Ceph noarch packages
baseurl=https://mirrors.tuna.tsinghua.edu.cn/ceph/rpm-mimic/el7/noarch/
enabled=1
gpgcheck=1
type=rpm-md
gpgkey=https://download.ceph.com/keys/release.ascbootstrap
[ceph-source]
name=Ceph source packages
baseurl=https://mirrors.tuna.tsinghua.edu.cn/ceph/rpm-mimic/el7/SRPMS/
enabled=1
gpgcheck=1
type=rpm-md
gpgkey=https://download.ceph.com/keys/release.asc
END
五、關閉selinux和firewall(各個節點)vim
# setenforce 0
# sed -i "s/SELINUX=enforcing/SELINUX=permissive/g" /etc/selinux/config
# systemctl disable firewalld.service
# systemctl stop firewalld.service
六、各個節點更新系統(各個節點)
# yum update -y
注意:若是最新操做系統:此步驟能夠省略
七、建立用戶並設置密碼爲Changeme_123(各個節點)
# useradd admin
# echo Changeme_123 | passwd --stdin admin
八、配置sudo權限(各個節點)
# echo -e 'Defaults:admin !requiretty\nadmin ALL = (root) NOPASSWD:ALL' | tee /etc/sudoers.d/ceph
# chmod 440 /etc/sudoers.d/ceph
九、安裝NTP(各個節點)
# yum -y install ntp
修改配置文件/etc/ntp.conf
server NTP-server
注意:
NTP-server修改成本身的NTP服務器,若是局域網內無NTP服務器,此處能夠用默認配置,採用centos官方ntp服務器
啓動服務並設置開機啓動
# systemctl start ntpd
# systemctl enable ntpd
查看ntp狀態
# ntpq -p
注意:
若是ntp時鐘不一樣步,後面ceph服務起不來!
九、重啓(各個節點)
# reboot
3、安裝和配置ceph(如下操做均在admin節點上執行)
一、配置互信
# su - admin
$ ssh-keygen -t dsa -f ~/.ssh/id_dsa -N ""
$ ssh-copy-id 172.16.8.91
$ ssh-copy-id 172.16.8.92
$ ssh-copy-id 172.16.8.93
$ ssh-copy-id 172.16.8.94
$ ssh-copy-id 172.16.8.95
exit
二、安裝ceph-deploy包
$ sudo yum -y install ceph-deploy
1
注意:最新版的ceph-deploy是2.0,安裝操做系統用mimal的ISo會報以下錯誤,須要安裝python-setuptools
[root@storage1 ceph]# ceph-deploy --help
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
# yum install python-setuptools
三、建立配置文件目錄
$ mkdir /etc/ceph
四、建立集羣
$ cd /etc/ceph
$ ceph-deploy new storage1 storage2 storage3
注意:若是須要指定網絡,建立命令跟如下參數
--cluster-network
--public-network
五、在各個節點上安裝ceph包
# yum -y install ceph ceph-radosgw
六、、設置monitor和key
$ ceph-deploy mon create-initial
注意:執行完成後會在/etc/ceph目錄多如下內容:
ceph.client.admin.keyring
ceph.bootstrap-mgr.keyring
ceph.bootstrap-osd.keyring
ceph.bootstrap-mds.keyring
ceph.bootstrap-rgw.keyring
ceph.bootstrap-rbd.keyring
ceph.bootstrap-rbd-mirror.keyring
七、將ceph.client.admin.keyring拷貝到各個節點上
# ceph-deploy admin storage1 storage2 storage3
八、安裝MGR
# ceph-deploy mgr create storage1 storage2 storage3
九、啓動osd,若是磁盤比較多,安裝規劃磁盤名稱,重複執行便可
# ceph-deploy osd create --data /dev/sdb storage1
# ceph-deploy osd create --data /dev/sdb storage2
# ceph-deploy osd create --data /dev/sdb storage3
拓展:
默認採用的是bluestore,若是須要指定更詳細的參數請參照下面步驟:
使用filestore
9.1.一、使用filestore採用journal模式(每一個節點數據盤須要兩塊盤或兩個分區)
建立邏輯卷
vgcreate data /dev/sdb
lvcreate --size 100G --name log data
9.1.二、建立OSD
# ceph-deploy osd create --filestore --fs-type xfs --data /dev/sdc --journal data/log storage1
# ceph-deploy osd create --filestore --fs-type xfs --data /dev/sdc --journal data/log storage2
# ceph-deploy osd create --filestore --fs-type xfs --data /dev/sdc --journal data/log storage3
使用bluestore
9.2.一、建立邏輯卷
vgcreate cache /dev/sdb
lvcreate --size 100G --name db-lv-0 cache
vgcreate cache /dev/sdb
lvcreate --size 100G --name wal-lv-0 cache
9.2.二、建立OSD
# ceph-deploy osd create --bluestore storage1 --data /dev/sdc --block-db cache/db-lv-0 --block-wal cache/wal-lv-0
# ceph-deploy osd create --bluestore storage2 --data /dev/sdc --block-db cache/db-lv-0 --block-wal cache/wal-lv-0
# ceph-deploy osd create --bluestore storage3 --data /dev/sdc --block-db cache/db-lv-0 --block-wal cache/wal-lv-0
關於filestore和bluestore的區別這篇文章作了詳細的說明,在有ssd的狀況下bluestore優點比較明顯。
http://www.yuncunchu.org/portal.php?mod=view&aid=74
1
wal & db 的大小問題
使用混合機械和固態硬盤設置時,block.db爲Bluestore建立足夠大的邏輯卷很是重要 。一般,block.db應該具備 儘量大的邏輯卷。
建議block.db尺寸不小於4% block。例如,若是block大小爲1TB,則block.db 不該小於40GB。
若是不使用快速和慢速設備的混合,則不須要爲block.db(或block.wal)建立單獨的邏輯卷。Bluestore將在空間內自動管理這些內容block。
十、驗證
$ ceph health
HEALTH_OK
4、ceph集羣對外提供塊存儲服務(均在client上執行)
一、經過admin用戶登陸client節點
[admin@client ~]$ sudo chmod 644 /etc/ceph/ceph.client.admin.keyring
二、建立一個存儲池
[admin@client ~]$ ceph osd pool create test 128
注意:
建立pool 一般在建立pool以前,須要覆蓋默認的pg_num,官方推薦:
若少於5個OSD, 設置pg_num爲128。
5~10個OSD,設置pg_num爲512。
10~50個OSD,設置pg_num爲4096。
超過50個OSD,能夠參考pgcalc計算
三、建立一個10G的塊
[admin@client ~]$ rbd create disk01 --size 10G --image-feature layering
# rbd create --size 10G disk01 --pool test
四、查看rbd
[admin@client ~]$ rbd ls -l
NAME SIZE PARENT FMT PROT LOCK
disk01 10240M 2
五、將10G的塊映射到本地
[admin@client ~]$ sudo rbd map disk01
/dev/rbd0
注意:
由於adminos7默認內核版本比較低,ceph的一些特性沒法使用,須要手動禁用才能map成功。命令以下
$ rbd feature disable test/disk01 exclusive-lock object-map fast-diff deep-flatten
六、查看映射
[admin@client ~]$ rbd showmapped
id pool image snap device
0 rbd disk01 - /dev/rbd0
七、格式化爲xfs格式
[admin@client ~]$ sudo mkfs.xfs /dev/rbd0
八、掛載rbd0到本地的目錄中
[admin@client ~]$ sudo mount /dev/rbd0 /mnt
[admin@client ~]$ df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/cl-root xfs 26G 1.8G 25G 7% /
devtmpfs devtmpfs 2.0G 0 2.0G 0% /dev
tmpfs tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs tmpfs 2.0G 8.4M 2.0G 1% /run
tmpfs tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/vda1 xfs 1014M 231M 784M 23% /boot
tmpfs tmpfs 396M 0 396M 0% /run/user/0
/dev/rbd0 xfs 10G 33M 10G 1% /mnt
5、使用ceph集羣提供cephfs文件系統
一、在admin節點上執行以下命令,啓用storage1上的mds服務
[admin@admin ceph]$ ceph-deploy mds create storage1
二、在storage1節點上進行以下操做
[admin@storage1 ~]$ sudo chmod 644 /etc/ceph/ceph.client.admin.keyring
三、建立名爲cephfs_data的pool
[admin@storage1 ~]$ ceph osd pool create cephfs_data 128
pool 'cephfs_data' created
四、建立名爲cephfs_metadata的pool
[admin@storage1 ~]$ ceph osd pool create cephfs_metadata 128
pool 'cephfs_metadata' created
五、啓用pool
[admin@storage1 ~]$ ceph fs new cephfs cephfs_metadata cephfs_data
new fs with metadata pool 2 and data pool 1
六、查看
[admin@storage1 ~]$ ceph fs ls
name: cephfs, metadata pool: cephfs_metadata, data pools: [cephfs_data ]
七、查看mds狀態
[admin@storage1 ~]$ ceph mds stat
e4: 1/1/1 up {0=storage1=up:creating}
如下操做在client節點上
八、安裝rpm包
[root@client ~]# yum -y install ceph-fuse
九、獲取admin的key
[root@client ~]# ssh admin@storage1 "sudo ceph-authtool -p /etc/ceph/ceph.client.admin.keyring" > admin.key
[root@client ~]# chmod 600 admin.key
十、掛載
[root@client ~]# mount -t ceph storage1:6789:/ /mnt -o name=admin,secretfile=admin.key
[root@client ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/cl-root xfs 26G 1.9G 25G 7% /
devtmpfs devtmpfs 2.0G 0 2.0G 0% /dev
tmpfs tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs tmpfs 2.0G 8.4M 2.0G 1% /run
tmpfs tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/vda1 xfs 1014M 231M 784M 23% /boot
tmpfs tmpfs 396M 0 396M 0% /run/user/0
172.16.8.94:6789:/ ceph 78G 21G 58G 27% /mnt
6、安裝RGW
radosgw的FastCGI能夠支持多種類型的WebServer,如Apache二、Nginx等。Ceph從Hammer版本開始,在使用Ceph-deploy的狀況下默認使用內置的civetweb替代舊版本的Apache2部署方式。
6.一、安裝rgw服務
# ceph-deploy rgw create storage1 storage2 storage3
6.二、查看狀態
[root@storage1 ceph]# ceph -s
cluster:
id: 9eb106eb-2af4-4aaf-bcdb-58e95bce828c
health: HEALTH_OK
services:
mon: 3 daemons, quorum storage1,storage2,storage3
mgr: storage3(active), standbys: storage1, storage2
osd: 3 osds: 3 up, 3 in
rgw: 3 daemons active
data:
pools: 4 pools, 32 pgs
objects: 189 objects, 2.2 KiB
usage: 3.0 GiB used, 237 GiB / 240 GiB avail
pgs: 32 active+clean
io:
client: 48 KiB/s rd, 0 B/s wr, 57 op/s rd, 38 op/s wr
7、安裝dashboard
mimic 版 dashboard 安裝
一、添加mgr 功能
# ceph-deploy mgr create node1 node2 node3
二、開啓dashboard 功能
# ceph mgr module enable dashboard
三、建立證書
# ceph dashboard create-self-signed-cert
四、建立 web 登陸用戶密碼
# ceph dashboard set-login-credentials user-name password
五、查看服務訪問方式
# ceph mgr services
六、在/etc/ceph/ceph.conf中添加
[mgr]
mgr modules = dashboard
七、設置dashboard的ip和端口
ceph config-key put mgr/dashboard/server_addr 192.168.8.106
ceph config-key put mgr/dashboard/server_port 7000
八、登陸:
https://172.16.8.94:7000
8、經過grafana監控ceph
一、啓用Prometheus監控模塊:
# ceph mgr module enable prometheus
# ss -tlnp|grep 9283
LISTEN 0 5 :::9283 :::* users:(("ceph-mgr",pid=3715,fd=70))
二、安裝Prometheus:
下載軟件包
wget https://github.com/prometheus/prometheus/releases/download/v1.5.2/prometheus-1.5.2.linux-amd64.tar.gz
將prometheus拷貝到/usr/local/bin/下
# tar -zxvf prometheus-*.tar.gz
# cd prometheus-*
# cp prometheus promtool /usr/local/bin/
# prometheus --version
prometheus, version 2.3.2 (branch: HEAD, revision: 71af5e29e815795e9dd14742ee7725682fa14b7b)
build user: root@5258e0bd9cc1
build date: 20180712-14:02:52
go version: go1.10.3
三、配置prometheus服務
# mkdir /etc/prometheus
# mkdir /var/lib/prometheus
四、建立 /usr/lib/systemd/system/prometheus.service
# vim /usr/lib/systemd/system/prometheus.service ###配置啓動項
[Unit]
Description=Prometheus
Documentation=https://prometheus.io
[Service]
Type=simple
WorkingDirectory=/var/lib/prometheus
EnvironmentFile=-/etc/prometheus/prometheus.yml
ExecStart=/usr/local/bin/prometheus \
--config.file /etc/prometheus/prometheus.yml \
--storage.tsdb.path /var/lib/prometheus/
[Install]
WantedBy=multi-user.target
五、建立配置文件
# vim /etc/prometheus/prometheus.yml ##配置配置文件
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['172.16.8.94:9090'] #storage1的IP
- job_name: 'ceph'
static_configs:
- targets:
- 172.16.8.94:9283
- 172.16.8.95:9283
- 172.16.8.96:9283
六、啓動服務
# systemctl daemon-reload
# systemctl start prometheus
# systemctl status prometheus
七、驗證:
http://172.16.8.94:9090/graph
六、安裝grafana:
# yum -y localinstall https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.2.2-1.x86_64.rpm
# systemctl start grafana-server
# systemctl status grafana-server
七、登陸grafana
http://172.16.8.94:9000/
默認用戶名和密碼:admin/admin,登陸後須要修改密碼。
八、添加數據源
參照:
http://blog.51cto.com/wangzhijian/2156186
下載json
https://grafana.com/dashboards/917
附錄:
一、卸載
在admin節點上執行卸載rpm包
$ ceph-deploy purge admin storage1 storage2 storage3
在admin節點上執行,刪除配置
$ ceph-deploy purgedata admin storage1 storage2 storage3
$ ceph-deploy forgetkeys
二、修復一個HEALTH_WARN
[root@storage1 ~]# ceph -s
cluster:
id: 9eb106eb-2af4-4aaf-bcdb-58e95bce828c
health: HEALTH_WARN
application not enabled on 1 pool(s)
services:
mon: 3 daemons, quorum storage1,storage2,storage3
mgr: storage3(active), standbys: storage1, storage2
osd: 3 osds: 3 up, 3 in
rgw: 3 daemons active
data:
pools: 5 pools, 96 pgs
objects: 2.79 k objects, 9.8 GiB
usage: 18 GiB used, 222 GiB / 240 GiB avail
pgs: 96 active+clean
經過ceph health detail查看緣由
[root@storage1 ~]# ceph health detail
HEALTH_WARN application not enabled on 1 pool(s)
POOL_APP_NOT_ENABLED application not enabled on 1 pool(s)
application not enabled on pool 'test'
use 'ceph osd pool application enable <pool-name> <app-name>', where <app-name> is 'cephfs', 'rbd', 'rgw', or freeform for custom applications.
解決辦法
# ceph osd pool application enable test rbd
三、刪除 pool
先在ceph.conf 增長下面:
mon_allow_pool_delete = true
並重啓ceph-mon:
systemctl restart ceph-mon@storage1--------------------- 做者:二進制-程序猿 原文:https://blog.csdn.net/wylfengyujiancheng/article/details/85613361