xin 发布的文章

架构逻辑示意图:

实际部署中ceph-deploy 可以和ceph node 在同一个节点。

1570587908894

安装前环境配置

ceph 节点设置

以操作系统centos7.x为例子
# 启用依赖源
sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# 添加ceph源
cat /etc/yum.repos.d/ceph.repo
[ceph-noarch]
name=Ceph noarch packages
baseurl=https://download.ceph.com/rpm-luminous/el7/noarch
enabled=1
gpgcheck=1
type=rpm-md
gpgkey=https://download.ceph.com/keys/release.asc

# 推荐使用国内镜像
[ceph-noarch]
name=Ceph noarch packages
baseurl=http://mirrors.ustc.edu.cn/ceph/rpm-luminous/el7/noarch
enabled=1
gpgcheck=1
type=rpm-md
gpgkey=http://mirrors.ustc.edu.cn/ceph/keys/release.asc
sudo yum makecache

安装NTP

sudo yum install ntp ntpdate ntp-doc -y

# 配置NTP
sudo ntpdate pool.ntp.org 
sudo systemctl restart ntpdate
sudo systemctl restart ntpd
sudo systemctl enable ntpd
sudo systemctl enable ntpdate

ssh 服务

sudo yum install openssh-server -y

创建ceph用户

ssh user@ceph-server
sudo useradd -d /home/{username} -m {username}
sudo passwd {username}
# 对于您添加到每个Ceph节点的新用户,请确保该用户具有 sudo特权。

echo "{username} ALL = (root) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/{username}
sudo chmod 0440 /etc/sudoers.d/{username}

测试环境直接停掉防火墙

sudo systemctl stop firewalld
sudo systemctl disable firewalld

yum 加速插件

sudo yum install yum-plugin-priorities

修改每个节点的/etc/hosts,如:

10.201.7.2  node1  # 和hostname一致
10.201.7.3  node2
10.201.7.4  node3

ceph-deploy 节点配置

配置部署节点(ceph-deploy)到ceph的节点的免密钥

# 此步骤不要使用sudo 或root 帐号
ssh-keygen

ssh-copy-id {username}@node1
ssh-copy-id {username}@node2
ssh-copy-id {username}@node3

(推荐)配置ssh 默认使用ceph 用户

# Modify the ~/.ssh/config 

Host node1
   Hostname node1
   User {username}
Host node2
   Hostname node2
   User {username}
Host node3
   Hostname node3
   User {username}
sudo chmod 600 ~/.ssh/config

安装

每个ceph节点执行

sudo yum install ceph -y

如果需要在某个节点安装对象存储网关,在该节点执行

sudo yum install ceph-radosgw -y

ceph-deploy 节点

sudo yum install ceph-deploy -y
mkdir my-cluster
cd my-cluster

ceph-deploy new node1
# 初始化mon
ceph-deploy mon create-initial
# 传递密钥
ceph-deploy admin node1 node2 node3
# 部署mgr
ceph-deploy mgr create node1 
# 部署osd
ceph-deploy osd create --data /dev/vdb node1  # 如果你的虚拟机没有多的磁盘, 需要添加新的磁盘
ceph-deploy osd create --data /dev/vdb node2
ceph-deploy osd create --data /dev/vdb node3  
# 部署RGW
ceph-deploy rgw create node1  # 默认端口: 7480

任意ceph节点

# 检查集群健康
sudo ceph -s

import asyncio
import datetime
import websockets


async def producer(ws, path):
    while 1:
        await asyncio.sleep(1)
        now = datetime.datetime.utcnow().isoformat() + "T" + '1'
        await ws.send(now)


async def now(ws, path):
    while 1:
        await asyncio.sleep(3)
        now = datetime.datetime.utcnow().isoformat() + "Z" + "3"
        await ws.send(now)


async def handler(websocket, path):
    # 协程并发执行的例子
    await asyncio.gather(now(websocket, path), producer(websocket, path), return_exceptions=True)

start_server = websockets.serve(handler, "127.0.0.1", 5678)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()

hug 目前提供三种接口:

  • 本地函数调用
  • 命令行 : 基于 标准库Argparse
  • http server 基于: Falcon

字段验证:

  • 采用python3函数参数注释方式验证
  • 一个验证要么验证通过返回验证后的值, 要么抛出异常

路由:

指令:

这个指令有点魔法,可以改变默认参数的值

分开成多个文件

@hug.extend_api('/something')

测试API:

def tests_happy_birthday():
    response = hug.test.get(happy_birthday, 'happy_birthday', {'name': 'Timothy', 'age': 25})
    assert response.status == HTTP_200
    assert response.data is not None