1、虚拟机环境准备
准备4台镜像为CentOS 7.6的虚拟机,前三台添加一块100G的硬盘,给osd做存储使用
服务器 |
IP |
角色 |
monitor |
192.168.18.180 |
admin, osd, mon, mgr |
osd1 |
192.168.18.181 |
osd, mds |
osd2 |
192.168.18.182 |
osd, mds |
client |
192.168.18.183 |
client |
四台机器都关闭防火墙:
systemctl stop firewalld
systemctl disable firewalld
setenforence 0
且禁用selinux:
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
所有服务器均修改主机名:hostnamectl set-hostname [name],
通过修改hosts文件,实现集群主机名与主机名之间相互能够解析,所有的服务器都需要设置hosts:vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.18.180 monitor
192.168.18.181 osd1
192.168.18.182 osd2
192.168.18.183 client
实现SSH免密登录:在管理节点使用ssh-keygen生成ssh keys发布到各节点:
ssh-keygen #一直回车,不设密码
ssh-copy-id monitor
ssh-copy-id osd1
ssh-copy-id osd2
ssh-copy-id client
测试ssh无交互式验证:ssh osd1
2、yum源配置
对所有节点都配置阿里yum源:
wget -0 /etc/yum.repos.d/Cent0S-Base.repo h_t_t_p://mirrors.aliyun.com/repo/Centos-7.repo
对所有节点配置ceph源:vim /etc/yum.repos.d/ceph.repo
[ceph]
name=ceph
baseurl=h_t_t_p://mirrors.163.com/ceph/rpm-luminous/el7/x86 64
gpgcheck=9
ceph-noarch7
name=ceph-noarch
baseurl=h_t_t_p://mirrors.163.com/ceph/rpm-luminous/el7/noarch
gpgcheck=9
也可直接复制如下命令
cat > /etc/yum.repos.d/ceph.repo <<-'EOF
[ceph]
name=ceph
baseurl=h_t_t_p://mirrors.163.com/ceph/rpm-luminous/el7/x86 64
gpgcheck=9
ceph-noarch1
name=ceph-noarch
baseurl=h_t_t_p://mirrors.163.com/ceph/rpm-luminous/e17/noarch
gpgcheck=9
EOF
所有节点安装epel-release:
yum -y install epel-release yum-plugin-priorities yum-utils ntpdate
3、每台服务器部署ceph
使用ceph-deploy科研极大地简化ceph集群的配置过程。以下安装中,ceph-deploy是ceph集群部署工具,其他软件是依赖包:
yum install -y ceph-deploy ceph ceph-radosgw snappy leveldb gdisk python-argparse gperftools-libs yum-plugin-priorities yum-utils ntpdate
4、管理节点admin上部署服务
在/etc/ceph目录操作,创建一个新集群,并设置monitor为mon节点:
cd /etc/ceph
ceph-deploy new monitor
执行完毕后,可以看到/etc/ceph目录中生成了三个文件,其中有一个ceph配置文件可以做各种参数优化。
修改副本数。配置文件的默认副本数从3改成2,这样只有3个osd也能达到active + clean状态:vim ceph.conf
[global]
fsid = 085c7b61-cac0-494b-9bfc-18fe2cc2deb0
mon_initial_members = cong11
mon_host = 192.168.1.11
auth_cluster_required = cephx
auth_service_required = cephx
auth_client_required = cephx
osd_pool_default_size = 2 #最后添加这行
安装ceph monitor
ceph-deploy mon create monitor
收集节点的keyring文件:
ceph-deploy gatherkeys monitor
cat ceph.client.admin.keyring
部署osd服务。添加玩硬盘直接使用,不要分区:
ceph-deploy osd create monitor --data /dev/sdb
ceph-deploy osd create osd1 --data /dev/sdb
ceph-deploy osd create osd2 --data /dev/sdb
查看osd状态:
ceph-deploy osd list monitor osd1 osd2
部署mgr管理服务。
ceph-deploy mgr create monitor
统一集群配置。用ceph-deploy把配置文件和admin密钥拷贝到所有节点,这样每次执行Ceph命令行时就无需指定monitor地址和ceph.client.admin.keyring了。
ceph-deploy admin monitor osd1 osd2
各节点修改ceph.client.admin.keyring权限:
chmod +r /etc/ceph/ceph.client.admin.keyring
5、可视化管理dashboard
下载ceph-dash:
mkdir /ceph-dash
cd /ceph-dash
git clone h_t_t_ps://github.com/Crapworks/ceph-dash.git
安装python-pip:
yum -y install python-pip
启动ceph-dash:
cd /ceph-dash/ceph-dash./ceph-dash.py
修改端口。默认端口是5000,如果想修改端口:
vi ./ceph-dash.py
app.run(host='0.0.0.0', port=8000, debug=True)