该文章采用的ceph-deploy版本为:ceph-deploy-1.5.38-0.noarch
下载地址:https://download.ceph.com/rpm-kraken/el7/noarch/
文章主要针对内网、不能上外网或者外网下载速度很慢的一部分用户。 外网用户和内网用户有差异的地方只有源的配置那部分,,其余部分都是一样的。
ceph的源采用的是公司内部自己的源,如果是外网可以直接用阿里源。
在下面步骤的后面带有 “(节点信息)”的描述,代表在哪个节点上面执行。
本文描述如何在 CentOS 7 下搭建 Ceph 存储集群(STORAGE CLUSTER)。
一共4台机器,其中1个是管理节点,其他3个是ceph节点(一个monitor节点,两个osd节点): admin-node 10.74.125.60 ceph-deploy 管理节点 mon-node 10.74.125.61 monitor ceph节点-监控节点 osd-node1 10.74.125.62 osd1 ceph节点-OSD节点 osd-node2 10.74.125.63 osd2 ceph节点-OSD节点 管理节点:admin-node
ceph节点:mon-node, osd-node1,osd-node2
所有节点:admin-node, mon-node, osd-node1,osd-node2
vi /etc/hosts 将4个虚机的hosts文件里都加上下面内容:
10.74.125.60 admin-node 10.74.125.61 mon-node 10.74.125.62 osd-node1 10.74.125.63 osd-node2然后再重启虚机
用 ping主机名的方式确认网络联通性。解决掉可能存在的主机名解析问题。
ping mon-node ping osd-node1 ping osd-node2如已安装SSH,则直接进行下一步,没有安装的,请安装:
sudo yum install openssh-serverceph-deploy 工具必须以普通用户登录 Ceph 节点,且此用户拥有无密码使用 sudo 的权限,因为它需要在安装软件及配置文件的过程中,不必输入密码。 建议在集群内的所有 Ceph 节点上给 ceph-deploy 创建一个特定的用户,但不要用 “ceph” 这个名字。
因为 ceph-deploy 不支持输入密码,你必须在管理节点上生成 SSH 密钥并把其公钥分发到各 Ceph 节点。 ceph-deploy 会尝试给初始 monitors 生成 SSH 密钥对。
不要用 sudo 或 root 用户。提示 “Enter passphrase” 时,直接回车,口令即为空:
//切换用户,如不特别说明,后续的操作均在该用户下进行
su cheng//生成密钥对
ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/cheng/.ssh/id_rsa): Created directory '/home/cheng/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/cheng/.ssh/id_rsa. Your public key has been saved in /home/cheng/.ssh/id_rsa.pub. The key fingerprint is: SHA256:Tb0VpUOZtmh+QBRjUOE0n2Uy3WuoZVgXn6TBBb2SsGk cheng@admin-node The key's randomart image is: +---[RSA 2048]----+ | .+@=OO*| | *.BB@=| | ..O+Xo+| | o E+O.= | | S oo=.o | | .. . | | . | | | | | +----[SHA256]-----+完成后, /home/zeng/.ssh/ 路径下:
admin-node 多了文件 id_rsa、id_rsa.pub 和 known_hosts; node1, node2, node3 多了文件authorized_keys。
修改 ~/.ssh/config 文件(没有则新增),这样 ceph-deploy 就能用你所建的用户名登录 Ceph 节点了。
Host admin-node Hostname admin-node User cheng Host mon-node Hostname mon-node User cheng Host osd-node1 Hostname osd-node1 User cheng Host osd-node2 Hostname osd-node2 User cheng执行命令修改文件权限。避免出现 “Bad owner or permissions on /home/zeng/.ssh/config”,
sudo chmod 644 ~/.ssh/config 测试ssh能否成功 ssh cheng@mon-node exit ssh cheng@osd-node1 exit ssh cheng@osd-node2 exitCeph 的各 OSD 进程通过网络互联并向 Monitors 上报自己的状态。如果网络默认为 off ,那么 Ceph 集群在启动时就不能上线,直到你打开网络。
cat /etc/sysconfig/network-scripts/ifcfg-enp0s3 //确保ONBOOT 设置成了 yes在 CentOS 和 RHEL 上执行 ceph-deploy 命令时可能会报错。如果你的 Ceph 节点默认设置了 requiretty ,执行
sudo visudo找到 Defaults requiretty 选项,把它改为 Defaults:ceph !requiretty 或者直接注释掉,这样 ceph-deploy 就可以用之前创建的用户(创建部署 Ceph 的用户 )连接了。
注意:编辑配置文件 /etc/sudoers 时,必须用 sudo visudo 而不是文本编辑器。
要使 SELinux 配置永久生效,需修改其配置文件 /etc/selinux/config:
sudo sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config即修改 SELINUX=disabled。
将公司的源放到 /etc/yum.repos.d/ 目录下,如果是外网用户,可以直接用阿里源。
问题:如果在安装后, /etc/yum.repos.d/ 目录下产生了多余的repo文件,请将多余的文件删掉,只保留最初那个源文件
虚机可能装了 python2-setuptools这个包,请先将该包卸载,再安装python-setuptools这个包。
卸载方法:
sudo yum remove python2-setuptools安装方法:
sudo yum install python-setuptools如果仓库没有1.5.38版本的ceph-deploy ,请自行下载:
https://download.ceph.com/rpm-kraken/el7/noarch/
修改 sudo vim /usr/lib/python2.7/site-packages/ceph_deploy/hosts/centos/install.py 文件:
将以下几句话注释掉:
58 # Get EPEL installed before we continue: 59 if adjust_repos: 60 distro.packager.install('epel-release') 61 distro.packager.install('yum-plugin-priorities') 62 #distro.conn.remote_module.enable_yum_priority_obsoletes() 63 logger.warning('check_obsoletes has been enabled for Yum priorities plugin') 64 if version_kind in ['stable', 'testing']: 65 key = 'release' 66 else: 67 key = 'autobuild' 68 69 if adjust_repos: 70 if version_kind in ['stable', 'testing']: 71 #distro.packager.add_repo_gpg_key(gpg.url(key)) 72 73 if version_kind == 'stable': 74 url = 'https://download.ceph.com/rpm-{version}/{repo}/'.format( 75 version=version, 76 repo=repo_part, 77 ) 78 elif version_kind == 'testing': 79 url = 'https://download.ceph.com/rpm-testing/{repo}/'.format(repo=repo_part) 80 81 """remoto.process.run( 82 distro.conn, 83 [ 84 'rpm', 85 '-Uvh', 86 '--replacepkgs', 87 '{url}noarch/ceph-release-1-0.{dist}.noarch.rpm'.format(url=url, dist=dist), 88 ], 89 )""" 90 91 elif version_kind in ['dev', 'dev_commit']: 92 logger.info('skipping install of ceph-release package') 93 logger.info('repo file will be created manually') 94 shaman_url = 'https://shaman.ceph.com/api/repos/ceph/{version}/{sha1}/{distro}/{distro_version}/repo/?arch={arch}'.format( 95 distro=distro.normalized_name, 96 distro_version=distro.normalized_release.major, 97 version=kw['args'].dev, 98 sha1=kw['args'].dev_commit or 'latest', 99 arch=machine 100 ) 101 LOG.debug('fetching repo information from: %s' % shaman_url) 102 content = net.get_chacra_repo(shaman_url) 103 """mirror_install( 104 distro, 105 '', # empty repo_url 106 None, # no need to use gpg here, repos are unsigned 107 adjust_repos=True, 108 extra_installs=False, 109 gpgcheck=gpgcheck, 110 repo_content=content 111 )""" 112 113 else: 114 raise Exception('unrecognized version_kind %s' % version_kind) 115 116 # set the right priority 117 logger.warning('ensuring that /etc/yum.repos.d/ceph.repo contains a high priority') 118 #distro.conn.remote_module.set_repo_priority(['Ceph', 'Ceph-noarch', 'ceph-source']) 119 logger.warning('altered ceph.repo priorities to contain: priority=1') 120 121 if packages: 122 distro.packager.install(packages) 123 124然后删除 /usr/lib/python2.7/site-packages/ceph_deploy/hosts/centos/install.pyc 和 /usr/lib/python2.7/site-packages/ceph_deploy/hosts/centos/install.pyo 两个文件
修改 sudo vim /usr/lib/python2.7/site-packages/ceph_deploy/hosts/init.py 文件:
将56行等号后面的内容改为如下内容
56 distro_name, release, codename = "centos","","1"然后删除 /usr/lib/python2.7/site-packages/ceph_deploy/hosts/init.pyc 和 /usr/lib/python2.7/site-packages/ceph_deploy/hosts/init.pyo 两个文件
在 管理节点 下执行如下步骤:
在管理节点上创建一个目录,用于保存 ceph-deploy 生成的配置文件和密钥对。
cd /home/cheng/ mkdir my-cluster cd my-cluster注:若在后面安装时遇到麻烦,想清除环境重新开始,可以使用以下命令进行清除包和配置:
// 删除安装包 $ ceph-deploy purge admin-node mon-node osd-node1 osd-node2 // 清除配置 $ ceph-deploy purgedata admin-node mon-node osd-node1 osd-node2 $ ceph-deploy forgetkeys创建集群并初始化监控节点:
这里mon-node是monitor节点,所以执行:
ceph-deploy new mon-node完成后,my-clster 下多了3个文件:ceph.conf、ceph-deploy-ceph.log 和 ceph.mon.keyring。
问题:如果出现 “[ceph_deploy][ERROR ] RuntimeError: remote connection got closed, ensure requiretty is disabled for mon-node”,执行 sudo visudo 将 Defaults requiretty 注释掉。
内容如下:
[global] fsid = a610ebcd-1df1-49ca-a6ee-3b0df53f26ef mon_initial_members = mon-node mon_host = 10.74.125.61 auth_cluster_required = cephx auth_service_required = cephx auth_client_required = cephx filestore_xattr_use_omap = true把 Ceph 配置文件里的默认副本数从 3 改成 2 ,这样只有两个 OSD 也可以达到 active + clean 状态。把 osd_pool_default_size = 2 加入 [global] 段:
osd_pool_default_size = 2把 public_network 写入 Ceph 配置文件的 [global] 段:
public_network = {ip-address}/{netmask}完整的配置如下:
[global] fsid = a610ebcd-1df1-49ca-a6ee-3b0df53f26ef mon_initial_members = mon-node mon_host = 10.74.125.61 auth_cluster_required = cephx auth_service_required = cephx auth_client_required = cephx filestore_xattr_use_omap = true osd_pool_default_size = 2 public_network = 10.74.125.0/23在所有节点上安装ceph:
ceph-deploy install admin-node mon-node osd-node1 osd-node2问题:[ceph_deploy][ERROR ] RuntimeError: Failed to execute command: yum -y install epel-release
解决方法1:
重新拉取yum缓存,这样做大多数RuntimeError: Failed to execute command: yum -y install xxxxx 错误都可解决
解决方法2: sudo yum -y remove epel-release
完成上述操作后,当前目录里应该会出现这些密钥环:
{cluster-name}.client.admin.keyring{cluster-name}.bootstrap-osd.keyring{cluster-name}.bootstrap-mds.keyring{cluster-name}.bootstrap-rgw.keyring用 ceph-deploy 把配置文件和 admin 密钥拷贝到管理节点和 Ceph 节点,这样你每次执行 Ceph 命令行时就无需指定 monitor 地址和 ceph.client.admin.keyring 了
ceph-deploy admin mon-node osd-node1 osd-node2修改密钥权限(ceph节点)
chmod +r /etc/ceph/ceph.client.admin.keyring建议在每个 mon 中都创建独立的 ceph-mgr,只会active一个,其他的standby
ceph-deploy mgr create mon-node两条命令
ceph health ceph -sdashboard其实就是一个web管理后台
结果:
{ "epoch": 27, "active_gid": 4118, "active_name": "ceph01", "active_addr": "192.168.20.148:6804/12748", "available": true, "standbys": [], "modules": [ "balancer", "restful", "status" ], "available_modules": [ "balancer", "dashboard", "influx", "localpool", "prometheus", "restful", "selftest", "status", "zabbix" ], "services": {} }结果:
{ "enabled_modules": [ "balancer", "dashboard", "restful", "status" ], "disabled_modules": [ "influx", "localpool", "prometheus", "selftest", "zabbix" ] }可以使用此命令查看当前设置的值
ceph config-key dump结果:
{ "mgr/dashboard/server_addr": "10.74.x.x", "mgr/dashboard/server_port": "7000" }现在就可以在浏览器上面输入链接:10.74.x.x:7000 进行访问了。 界面类似这样:
参考文献: https://www.cnblogs.com/zengzhihua/p/9829472.html https://www.jianshu.com/p/cc254cf8842b
技 术 无 他, 唯 有 熟 尔。 知 其 然, 也 知 其 所 以 然。 踏 实 一 些, 不 要 着 急, 你 想 要 的 岁 月 都 会 给 你。