一、环境介绍
IP | hostname | IOS | |
10.2.152.131 | node-01 | centos 7.4 | admin |
10.2.152.132 | node-02 | centos 7.4 | node |
二、安装CMake-v3.12.4
下载源码
$: wget https://github.com/Kitware/CMake/archive/v3.12.4.tar.gz
解压
tar zxf v3.12.4.tar.gz
编译安装
$: cd CMake-3.12.4
$: ./bootstrap
$: make && make install
检查
$: cmake --version
三、yum安装依赖库
$:yum install -y libffi-devel boost cryptopp-devel fcgi-devel libatomic_op-devel libedit-devel boost-devel fuse-devel libtool libuuid-devel libblkid-devel keyutils-libs-devel cryptopp-devel fcgi-devel libcurl-devel expat-devel gperftools-devel libedit-devel libatomic_ops-devel snappy-devel libaio-devel xfsprogs-devel libudev-devel libcrypto++-dev libcrypto++-utils
$:yum install -y fuse fuse-devel
四、安装leveldb-1.20
下载地址:
https://github.com/google/leveldb/releases
解压并编译
$: tar -zxvf leveldb-1.20.tar.gz -C /usr/local/
$: cd /usr/local/leveldb-1.20
$: make
将新编译的动态库链接到原来的动态库
$:cd /usr/local/levedb-1.20/out-shared/
$:cp libleveldb.so* /usr/lib64/
$:cd /usr/lib64
$:rm libleveldb.so libleveldb.so.1
$:ln -s libleveldb.so.1.20 libleveldb.so
$:ln -s libleveldb.so.1.20 libleveldb.so.1
替换头文件
$: cd /usr/local/leveldb-1.20/include
$: cp -r leveldb/ /usr/include/
五、安装gcc-8.2.0
$: wget https://mirrors.ustc.edu.cn/gnu/gcc/gcc-8.2.0/gcc-8.2.0.tar.gz
$: tar zxf gcc-8.2.0.tar.gz
$: cd gcc-8.2.0
$: ./contrib/download_prerequisites
$: mkdir gcc-build-8.2.0
$: cd gcc-build-8.2.0
$: ../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
参数解释:
–enable-checking=release 增加一些检查,也可以–disable-checking生成的编译器在编译过程中不做额外检查
–enable-languages=c,c++ 你要让你的gcc支持的编程语言
–disable-multilib 取消多目标库编译(取消32位库编译)
$: make && make install
替换gcc的动态库
$: cp /usr/local/lib64/libstdc++.so.6.0.25 /usr/lib64
$: rm -rf /usr/lib64/libstdc++.so.6
$: ln -s /usr/lib64/libstdc++.so.6.0.25 /usr/lib64/libstdc++.so.6
替换yum安装的gcc
$: rm -rf /usr/bin/gcc
$: rm -rf /usr/bin/g++
$: rm -rf /usr/bin/c++
$: rm -rf /usr/bin/cc
$:ln -s /usr/local/bin/gcc /usr/bin/gcc
$:ln -s /usr/local/bin/gcc /usr/bin/cc
$:ln -s /usr/local/bin/g++ /usr/bin/g++
$:ln -s /usr/local/bin/c++ /usr/bin/c++
六、源码安装ceph-v11.2.1
(1)克隆ceph项目
源码包下载:http://download.ceph.com/tarballs/
$:git clone https://github.com/ceph/ceph.git
(2)安装依赖
$:cd ceph
$:./install-deps.sh
(3)运行脚本
$:./do_cmake.sh
(4)编译安装
$: cd build
$: make && make install
(5)检查
$:ceph -v
ERROR1:
用find /* -name 'rados*' 发现在/usr/lib/python2.7/site-packages/下有 rados.so 和rados-0-py2.7.egg-info两个文件
拷贝这两个文件到/usr/lib/python2.7/dist-packages/下。
cp /usr/local/lib64/python2.7/site-packages/rados.so /usr/lib/python2.7/site-packages/
cp /usr/local/lib64/python2.7/site-packages/rados-2.0.0-py2.7.egg-info /usr/lib/python2.7/site-packages/ -r
cp /usr/local/lib64/librados.so.3 /usr/lib64/
ERROR2:
cp /usr/local/lib/python2.7/site-packages/* /usr/lib64/python2.7/ -r
七、配置ceph集群准备工作
(1)实现ssh无密码登录
Master节点上:
$: ssh-keygen -t rsa //一路回车即可
$:ssh-copy-id zc@10.2.152.132 //传递master上的秘钥到node上
验证:
$:ssh root@10.2.152.132
(2)修改/etc/hosts文件(master && node)
$: cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.2.152.131 node-01
10.2.152.132 node-02
(3)实现NTP时间同步
$:yum install ntp ntpdate ntp-doc
$:ntpdate -u ntp1.aliyun.com
(4)关闭防火墙和SElinux(master && node)
关闭防火墙
启动: systemctl start firewalld
关闭: systemctl stop firewalld
查看状态: systemctl status firewalld
开机禁用: systemctl disable firewalld
开机启用: systemctl enable firewalld
关闭Selinux
查看
$: getenforce
Disabled表示关闭;Enforcing表示开启
$:/usr/sbin/sestatus -v
SELinux status: disabled
临时关闭
setenforce 1 //设置SELinux 成为enforcing模式 (开)
setenforce 0 //设置SELinux 成为permissive模式(关)
永久关闭
$:vi /etc/selinux/config
将SELINUX=enforcing改为SELINUX=disabled
设置后需要重启才能生效
八、配置ceph集群
节点关系示意图:node1作为监控和管理节点,node2作为osd节点,其关系如下图所示:
启用Mon节点(node-01)
(1)在/etc和/var/log目录下创建ceph目录
$:mkdir -p /etc/ceph/
$:mkdir -p /var/log/ceph
(2)给集群分配惟一 ID (即 fsid )
$:uuidgen
(3)在/etc/ceph/下,创建 Ceph 配置文件, Ceph 默认使用 ceph.conf ,其中的 ceph 是集群名字
$:cd /etc/ceph
$:touch ceph.conf
(4)把此UUID 写入 Ceph 配置文件
将创建的unique ID值写入到ceph.conf配置文件中;
fsid = e6477d75-ce6f-495e-aec6-ce3d975608ee
在ceph.conf中填写monitor节点成员名称和ip地址;
mon initial members = node-01
mon host = 10.2.152.131
$:cat ceph.conf
[global]
fsid = 09127e36-c9dd-4232-970e-afccea6bc8c8
mon initial members = node-01
mon host = 10.2.152.131
(5)创建monitor keying
$:ceph-authtool --create-keyring /tmp/ceph.mon.keyring --gen-key -n mon. --cap mon 'allow *'
$: ls /tmp/ceph.mon.keyring
/tmp/ceph.mon.keyring
$: cat /tmp/ceph.mon.keyring
[mon.]
key = AQDKxg1cvM1QDBAAma0YiMKFCtHtRdRKF6E7Ag==
caps mon = "allow *"
(6)生成管理员秘钥环,创建client.admin keyring
$: ceph-authtool --create-keyring /etc/ceph/ceph.client.admin.keyring --gen-key -n client.admin --cap mon 'allow *' --cap osd 'allow *' --cap mds 'allow'
creating /etc/ceph/ceph.client.admin.keyring
$: ls /etc/ceph/
ceph.client.admin.keyring ceph.conf
$: cat /etc/ceph/ceph.client.admin.keyring
[client.admin]
key = AQBZxw1c4hMBKhAA5maRVeKl/43gNhbALzm7Ng==
caps mds = "allow"
caps mon = "allow *"
caps osd = "allow *"
(7)将client.admin的key添加到monitor的keyring中
$: ceph-authtool /tmp/ceph.mon.keyring --import-keyring /etc/ceph/ceph.client.admin.keyring
(8)用规划好的主机名、对应 IP 地址、和 FSID 生成一个监视器图,并保存为 /tmp/monmap
monmaptool --create --add {hostname} {ip-address} --fsid {uuid} /tmp/monmap
例如:
$:monmaptool --create --add node-01 10.2.152.131 --fsid 09127e36-c9dd-4232-970e-afccea6bc8c8 /tmp/monmap
(9)创建monitor工作目录
sudo mkdir /var/lib/ceph/mon/{cluster-name}-{hostname}
例如:
$:mkdir -p /var/lib/ceph/mon/ceph-node-01
(10)仔细斟酌 Ceph 配置文件,公共的全局配置包括这些:
$: cat ceph.conf
[global]
fsid = 09127e36-c9dd-4232-970e-afccea6bc8c8
mon initial members = node-01
mon host = 10.2.152.131
auth cluster required = cephx
auth service required = cephx
auth client required = cephx
public network = 10.2.152.0/24
注:若将cephx改为none是为了方便搭建测试环境,关闭了ceph的安全认证,建议在实际运行环境之中开启。
(11)用监视器图和密钥环组装守护进程所需的初始数据
ceph-mon [--cluster {cluster-name}] --mkfs -i {hostname} --monmap /tmp/monmap --keyring /tmp/ceph.mon.keyring
例如:
$:ceph-mon --mkfs -i node-01 --monmap /tmp/monmap --keyring /tmp/ceph.mon.keyring
(12)建一个空文件 done ,表示监视器已创建、可以启动了
$: touch /var/lib/ceph/mon/ceph-node-01/done
$: touch /var/lib/ceph/mon/ceph-node-01/sysvinit
启动监视器。
在 Ubuntu 上用 Upstart :
$:sudo ceph-mon --id=slave1 [cluster={cluster-name}]
要使此守护进程开机自启,需要创建两个空文件,像这样:
$:sudo touch /var/lib/ceph/mon/{cluster-name}-{hostname}/upstart
例如:
$:sudo touch /var/lib/ceph/mon/ceph-slave1/upstart
在 Debian/CentOS/RHEL 上用 sysvinit :
$:/etc/init.d/ceph start mon.node-01
(13)确认下集群的运行状态
$:ceph -s
cluster:
id: f42905e0-cd33-4155-a61b-4b9c4725e0f4
health: HEALTH_OK
services:
mon: 1 daemons, quorum node-01 (age 48s)
mgr: no daemons active
osd: 0 osds: 0 up, 0 in
data:
pools: 0 pools, 0 pgs
objects: 0 objects, 0 B
usage: 0 B used, 0 B / 0 B avail
pgs:
编辑CrushMap,启用osd节点