ceph安裝部署


環境准備

測試環境是4台虛擬機,所有機器都是剛剛安裝好系統(minimal),只配置完網卡和主機名的centos7.7,每個osd增加一塊磁盤,/dev/sdb

  • ceph-admin ---- admin+mon節點
  • ceph-node1 ---- osd節點
  • ceph-node2 ---- osd節點
  • ceph-node3 ---- osd節點

1、首先在所有節點創建一個部署、管理ceph集群的用戶,並授予sudo權限,不建議使用root來運行ceph,同時關閉防火牆和selinux

[root@ceph-admin ~]# useradd cephfsd
[root@ceph-admin ~]# echo "ceph123"|passwd cephfsd --stdin
Changing password for user cephfsd.
passwd: all authentication tokens updated successfully.
[root@ceph-admin ~]# echo "cephfsd ALL = (root,ceph) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/cephfsd
cephfsd ALL = (root,ceph) NOPASSWD:ALL
[root@ceph-admin ~]# chmod 0440 /etc/sudoers.d/cephfsd
[root@ceph-admin ~]# setenforce 0
[root@ceph-admin ~]# sed -i 's/enforcing/disabled/g' /etc/selinux/config
[root@ceph-admin ~]# systemctl stop firewalld.service
[root@ceph-admin ~]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@ceph-admin ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.143.121 ceph-admin
172.16.143.122 ceph-node1
172.16.143.123 ceph-node2
172.16.143.124 ceph-node3
[root@ceph-admin ~]# ntpdate ntp1.aliyun.com
[root@ceph-admin ~]# vim /etc/rc.local
# sync time
ntpdate ntp1.aliyun.com

之后,在admin節點使用cephfsd用戶登錄,開始下一步。

2、配置免密登錄,並把秘鑰推送到所有osd節點,包括admin自身。

# admin上配置免密登錄
[root@ceph-admin ~]# su cephfsd
[cephfsd@ceph-admin root]$ cd
[cephfsd@ceph-admin ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/cephfsd/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/cephfsd/.ssh/id_rsa.
Your public key has been saved in /home/cephfsd/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:pmFVNy8T8fw+HWvDFFEDUljFkjBvnd1lOk8L9/v/558 cephfsd@deploy
The key's randomart image is:
+---[RSA 2048]----+
|          .+X==+=|
|         . o+O.+B|
|        .   o+B=+|
|       .    .oo=+|
|      o S      ++|
|     . +      o.=|
|      .        Bo|
|              . *|
|               E@|
+----[SHA256]-----+
[cephfsd@ceph-admin ~]$ ssh-copy-id ceph-node1
[cephfsd@ceph-admin ~]$ ssh-copy-id ceph-node2
[cephfsd@ceph-admin ~]$ ssh-copy-id ceph-node3
[cephfsd@ceph-admin ~]$ ssh-copy-id ceph-admin

3、配置yum源,這里使用阿里雲的源。(所有節點都要配置yum源。)

# 所有節點都要配置yum源。包括admin和osd和mon。
[cephfsd@ceph-admin ~]$ sudo vim /etc/yum.repos.d/ceph.repo
[Ceph]
name=Ceph packages for $basearch
baseurl=http://mirrors.aliyun.com/ceph/rpm-luminous/el7/$basearch
enabled=1
gpgcheck=0
type=rpm-md
gpgkey=https://mirrors.aliyun.com/ceph/keys/release.asc
priority=1
[Ceph-noarch]
name=Ceph noarch packages
baseurl=http://mirrors.aliyun.com/ceph/rpm-luminous/el7/noarch
enabled=1
gpgcheck=0
type=rpm-md
gpgkey=https://mirrors.aliyun.com/ceph/keys/release.asc
priority=1
[ceph-source]
name=Ceph source packages
baseurl=http://mirrors.aliyun.com/ceph/rpm-luminous/el7/SRPMS
enabled=1
gpgcheck=0
type=rpm-md
gpgkey=https://mirrors.aliyun.com/ceph/keys/release.asc
priority=1
[cephfsd@ceph-admin ~]$ sudo yum clean all

4、在admin上安裝ceph-deploy。

# admin節點上安裝ceph-deploy
[cephfsd@ceph-admin ~]$ sudo yum -y install epel-release
[cephfsd@ceph-admin ~]$ sudo yum -y install ceph ceph-radosgw ceph-deploy  # 如果不做osd,可以不需要安裝ceph和ceph-radosgw,我們這里為了保險都安裝上。
[cephfsd@ceph-admin ~]$ sudo yum -y install htop sysstat iotop iftop ntp ntpdate

5、在所有節點安裝ceph。

如果其他osd節點不能上網,則需要使用自建yum源的方式來使用。

可以參考:http://www.strugglesquirrel.com/2019/04/23/centos7%E9%83%A8%E7%BD%B2ceph/

我們這里能上網,所以我們直接使用yum。

# osd節點配置yum源,這里使用外網的。
[root@ceph-node1 ~]# su cephfsd
[cephfsd@ceph-node1 root]$ cd
[cephfsd@ceph-node1 ~]$
[cephfsd@ceph-node1 ~]$ sudo vim /etc/yum.repos.d/ceph.repo
[Ceph]
name=Ceph packages for $basearch
baseurl=http://mirrors.aliyun.com/ceph/rpm-luminous/el7/$basearch
enabled=1
gpgcheck=0
type=rpm-md
gpgkey=https://mirrors.aliyun.com/ceph/keys/release.asc
priority=1
[Ceph-noarch]
name=Ceph noarch packages
baseurl=http://mirrors.aliyun.com/ceph/rpm-luminous/el7/noarch
enabled=1
gpgcheck=0
type=rpm-md
gpgkey=https://mirrors.aliyun.com/ceph/keys/release.asc
priority=1
[ceph-source]
name=Ceph source packages
baseurl=http://mirrors.aliyun.com/ceph/rpm-luminous/el7/SRPMS
enabled=1
gpgcheck=0
type=rpm-md
gpgkey=https://mirrors.aliyun.com/ceph/keys/release.asc
priority=1
[cephfsd@ceph-node1 ~]$ sudo yum clean all
[cephfsd@ceph-node1 ~]$ sudo yum -y install epel-release
[cephfsd@ceph-node1 ~]$ sudo yum -y install ceph ceph-radosgw
[cephfsd@ceph-node1 ~]$ sudo yum -y install htop sysstat iotop iftop ntp ntpdate
# 其余osd節點也是一樣的操作

也可以在ceph-admin節點,用ceph-deploy安裝。

[cephfsd@ceph-admin ceph]$ cd /etc/ceph/
[cephfsd@ceph-admin ceph]$ setfacl -R -m u:cephfsd:rwx /etc/ceph
[cephfsd@ceph-admin ceph]$ ceph-deploy install ceph-admin ceph-node1 ceph-node2 ceph-node3

6、使用ceph-deploy部署集群:

# 初始化集群配置
[cephfsd@ceph-admin ~]$ cd /etc/ceph
[cephfsd@ceph-admin ceph]$ sudo chown -R cephfsd.cephfsd ./
# mon安裝在ceph-admin上。
[cephfsd@ceph-admin ceph]$ ceph-deploy new ceph-admin
[cephfsd@ceph-admin ceph]$ ls
total 112
-rw-r--r--. 1 cephfsd cephfsd   289 Dec  5 20:21 ceph.conf
-rw-r--r--. 1 cephfsd cephfsd 76854 Dec  5 20:24 ceph-deploy-ceph.log
-rw-------. 1 cephfsd cephfsd    73 Dec  5 23:12 ceph.mon.keyring
-rw-r--r--. 1 cephfsd cephfsd    92 Apr 11  2019 rbdmap

初始化集群主要是生成最基本的配置文件ceph.conf和monitor key文件ceph.mon.keyring,我們要手動修改ceph.conf,添加集群公網和集群網絡的配置

這里,我們測試環境,先不配置公網與集群網絡。

7、修改副本數。

# 修改配置文件ceph.conf,設置osd_pool_default_size副本數為3.
[cephfsd@ceph-admin ceph]$ cat ceph.conf
[global]
fsid = 6d3fd8ed-d630-48f7-aa8d-ed79da7a69eb
mon_initial_members = ceph-admin
mon_host = 172.16.143.121
auth_cluster_required = cephx
auth_service_required = cephx
auth_client_required = cephx
 
osd_pool_default_size = 3

8、安裝monitor服務。

# 我們這里就設置了一台mon節點。
[cephfsd@ceph-admin ceph]$ ceph-deploy mon create-initial
[cephfsd@ceph-admin ceph]$ ls -l
total 112
-rw-------. 1 cephfsd cephfsd    71 Dec  5 23:16 ceph.bootstrap-mds.keyring
-rw-------. 1 cephfsd cephfsd    71 Dec  5 23:16 ceph.bootstrap-mgr.keyring
-rw-------. 1 cephfsd cephfsd    71 Dec  5 23:16 ceph.bootstrap-osd.keyring
-rw-------. 1 cephfsd cephfsd    71 Dec  5 23:16 ceph.bootstrap-rgw.keyring
-rw-------. 1 cephfsd cephfsd    63 Dec  5 23:16 ceph.client.admin.keyring
-rw-r--r--. 1 cephfsd cephfsd   289 Dec  5 20:21 ceph.conf
-rw-r--r--. 1 cephfsd cephfsd 76854 Dec  5 20:24 ceph-deploy-ceph.log
-rw-------. 1 cephfsd cephfsd    73 Dec  5 23:12 ceph.mon.keyring
-rw-r--r--. 1 cephfsd cephfsd    92 Apr 11  2019 rbdmap
9、配置其他osd節點
# mon create-initial會根據ceph.conf進行創建mon,判斷monitor都創建成功后,會進行keyring的收集,這些keyring在后續創建其他成員的時候要用到,接下來我們分發集群keyring
# 這個操作是將集群的admin.keyring分發給指定的節點,這樣這些節點就可以使用ceph命令了,接下來創建mgr
[cephfsd@ceph-admin ceph]$ ceph-deploy admin ceph-node1 ceph-node2 ceph-node3
[cephfsd@ceph-admin ceph]$ ceph-deploy mgr create ceph-admin

10、創建osd

mgr分擔了很多原本monitor的工作,目前它也是重要的一個組件,根據集群規模,可以創建2-3個mgr,不過也沒有必要太多,接下來可以開始創建osd了

刪除磁盤數據(我們是新增的磁盤,可以跳過這步)

# 這里,我們使用的是之前新增的磁盤/dev/sdb,避免與os在同一個分區。
[cephfsd@ceph-admin ceph]$ ceph-deploy disk zap /dev/sdb ceph-node1
[cephfsd@ceph-admin ceph]$ ceph-deploy disk zap /dev/sdb ceph-node2
[cephfsd@ceph-admin ceph]$ ceph-deploy disk zap /dev/sdb ceph-node3

開始創建osd,這里一共創建了三個osd。

# 這里,我們使用的是之前新增的磁盤/dev/sdb,避免與os在同一個分區。
[cephfsd@ceph-admin ceph]$ ceph-deploy osd create --data /dev/sdb ceph-node1
[cephfsd@ceph-admin ceph]$ ceph-deploy osd create --data /dev/sdb ceph-node2
[cephfsd@ceph-admin ceph]$ ceph-deploy osd create --data /dev/sdb ceph-node3

11、查看ceph狀態:

[cephfsd@ceph-admin ceph]$ ceph health
HEALTH_OK
[cephfsd@ceph-admin ceph]$
[cephfsd@ceph-admin ceph]$ ceph -s
  cluster:
    id:     6d3fd8ed-d630-48f7-aa8d-ed79da7a69eb
    health: HEALTH_OK
  
  services:
    mon: 1 daemons, quorum ceph-admin
    mgr: ceph-admin(active)
    mds: cephfs-1/1/1 up  {0=ceph-node3=up:active}, 2 up:standby
    osd: 3 osds: 3 up, 3 in
  
  data:
    pools:   2 pools, 128 pgs
    objects: 21 objects, 7.77KiB
    usage:   3.00GiB used, 27.0GiB / 30.0GiB avail
    pgs:     128 active+clean
[cephfsd@ceph-admin ceph]$ ceph df
GLOBAL:
    SIZE        AVAIL       RAW USED     %RAW USED
    30.0GiB     27.0GiB      3.00GiB         10.02
POOLS:
    NAME                ID     USED        %USED     MAX AVAIL     OBJECTS
    cephfs_data         5           0B         0       8.49GiB           0
    cephfs_metadata     6      7.77KiB         0       8.49GiB          21
    rbd_data            7           0B         0       8.49GiB           0
[cephfsd@ceph-admin ceph]$

至此,osd全部創建成功了。

12、dashboard配置

dashboard其實就是ceph自帶的一個web管理后台。

# 修改/etc/ceph/ceph.conf,增加如下配置。
[cephfsd@ceph-admin ceph]$ vim /etc/ceph/ceph.conf
[mgr]
mgr modules = dashboard

將主節點上的配置文件推送到從節點。

[cephfsd@ceph-admin ceph]$ ceph-deploy --overwrite-conf config push ceph-node1 ceph-node2 ceph-node3

查看當前集群在使用哪幾個模塊

[root@ceph-admin ~]# ceph mgr dump
{
    "epoch": 10,
    "active_gid": 14099,
    "active_name": "ceph-admin",
    "active_addr": "172.16.143.121:6800/15303",
    "available": true,
    "standbys": [],
    "modules": [
        "balancer",
        "restful",
        "status"
    ],
    "available_modules": [
        "balancer",
        "dashboard",
        "influx",
        "localpool",
        "prometheus",
        "restful",
        "selftest",
        "status",
        "zabbix"
    ],
    "services": {
        "dashboard": "http://172.16.143.121:7000/"
    }
}
[root@ceph-admin ~]#

使dashboard可用

[cephfsd@ceph-admin ceph]$ ceph mgr module enable dashboard

查看是否支持dashboard

[root@ceph-admin ~]# ceph mgr module ls
{
    "enabled_modules": [
        "balancer",
        "dashboard",
        "restful",
        "status"
    ],
    "disabled_modules": [
        "influx",
        "localpool",
        "prometheus",
        "selftest",
        "zabbix"
    ]
}

設置dashboard web網頁監控的ip及端口(根據需求配置)10.27.0.130為此主機外網ip

[cephfsd@ceph-admin ceph]$ ceph config-key put mgr/dashboard/server_addr 172.16.143.121
set mgr/dashboard/server_addr
[cephfsd@ceph-admin ceph]$ ceph config-key put mgr/dashboard/server_port 7000
set mgr/dashboard/server_port

可以使用此命令查看當前設置的值

[cephfsd@ceph-admin ceph]$ ceph config-key dump
{
    "mgr/dashboard/server_addr": "172.16.143.121",
    "mgr/dashboard/server_port": "7000"
}
[cephfsd@ceph-admin ceph]$

現在就可以訪問了。

http://172.16.143.121:7000/health

image

13、其他
清理機器上的ceph相關配置:
  停止所有進程: stop ceph-all
  卸載所有ceph程序:ceph-deploy uninstall [{ceph-node}]
  刪除ceph相關的安裝包:ceph-deploy purge {ceph-node} [{ceph-data}]
  刪除ceph相關的配置:ceph-deploy purgedata {ceph-node} [{ceph-data}]
  刪除key:ceph-deploy forgetkeys

  卸載ceph-deploy管理:yum -y remove ceph-dep

部署過程中如果出現任何奇怪的問題無法解決,可以簡單的刪除一切從頭再來:

# ceph-deploy purge ceph-mon1 ceph-mon2 ceph-mon3 ceph-osd1 ceph-osd2
# ceph-deploy purgedata ceph-mon1 ceph-mon2 ceph-mon3 ceph-osd1 ceph-osd2
# ceph-deploy forgetkeys

ceph使用的場景主要有三種,塊存儲場景、對象存儲場景和文件系統存儲場景,接下來會分別介紹。


參考:http://docs.ceph.org.cn/

http://www.strugglesquirrel.com/2019/04/23/centos7%E9%83%A8%E7%BD%B2ceph/

https://www.cnblogs.com/happy1983/p/9246379.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM