0%

ceph 简介以日常运维问题

Ceph是一个统一的分布式存储系统,设计初衷是提供较好的性能、可靠性和可扩展性

架构

自下向上,可以将Ceph系统分为四个层次:

  • 基础存储系统RADOS(Reliable, Autonomic, Distributed Object Store,即可靠的、自动化的、分布式的对象存储)ceph一切都以对象形式存储,是ceph的基础
  • 基础库LIBRADOS
  • 高层应用接口:包括了三个部分:RADOS GW(RADOS Gateway)、 RBD(Reliable Block Device)和Ceph FS(Ceph File System)
  • 应用层

组件介绍

  • OSD ( Object Storage Device)
1
实际存储数据的进程。通常一个OSD daemon绑定一个物理磁盘。Client write/read 数据最终都会走到OSD去执行write/read操作。
  • Monitor
1
2
负责监控整个集群健康状态
OSD和monitor之间相互传输节点状态信息,共同得出系统的总体工作状态,并形成一个全局系统状态记录数据结构,即cluster map(monmap osdmap pgmap等)。这个数据结构与RADOS提供的特定算法相配合,便实现了Ceph“无需查表,算算就好”的核心机制以及若干优秀特性
  • Object
1
Ceph最底层的存储单元是Object对象,每个Object包含元数据和原始数据。
  • PG
1
PG全称Placement Grouops,是一个逻辑的概念,引入PG这一层其实是为了更好的分配数据和定位数据。
  • Libradio
1
Rados提供库,因为RADOS是协议很难直接访问,因此上层的RBD、RGW和CephFS都是通过librados访问的
  • CRUSH
1
CRUSH是Ceph使用的数据分布算法,类似一致性哈希,让数据分配到预期的地方。
  • RBD
1
RBD全称RADOS block device,是Ceph对外提供的块设备服务。
  • RGW
1
RGW全称RADOS gateway,是Ceph对外提供的对象存储服务,接口与S3和Swift兼容。
  • MDS
1
MDS全称Ceph Metadata Server,是CephFS服务依赖的元数据服务。

io流程

  1. client 创建cluster handler。
  2. client 读取配置文件。 client 连接上monitor,获取集群map信息。
  3. client 读写io 根据crshmap 算法请求对应的主osd数据节点。
  4. 主osd数据节点同时写入另外两个副本节点数据。
  5. 主节点及副本节点写入状态都成功后,返回给client,io写入完成。

io算法流程

  1. File用户需要读写的文件。File->Object映射:

a. ino (File的元数据,File的唯一id ,rbd即为block_name_prefix)。
b. ono(File切分产生的某个object的累加的序号,默认以4M切分一个块大小)。
c. oid(object id: ino + ono)。

  1. Ceph指定一个静态hash函数计算oid的值,得到pgid。Object->PG映射:

a. hash(oid) & mask-> pgid 。
b. mask = PG总数m(m为2的整数幂)-1 。

  1. PG(Placement Group),用途是对object的存储进行组织和位置映射, 采用CRUSH算法,将pgid代入其中,然后得到一组OSD。PG->OSD映射:

a. CRUSH(pgid)->(osd1,osd2,osd3) 。

rbd io类似

日常运维问题

磁盘损坏(osd下线)

osd 自动摘掉

参考下线流程

osd下线

1
2
3
4
5
6
7
8
9
10
11
12
# 备份crush map
ceph osd getcrushmap -o crushmap-17:26
# 权重改为0
ceph osd crush reweight osd.570 0
ceph osd tree|grep down
ceph -s
# 下线osd
ceph osd crush remove osd.570
ceph -s
ceph osd tree
# 删除对应osd
ceph osd rm osd.570

monitor 节点迁移

集群扩容缩容

日常割接

手动更改集群故障域

新集群上线

测试流程

性能测试

集群:

顺序读写
    - 带宽
    - iops
    - latency
随机读写
    - 带宽
    - iops
    - latency
混合读写
    - 带宽
    - iops
    - latency

单盘:

顺序读写
    - 带宽
    - iops
    - latency
随机读写
    - 带宽
    - iops
    - latency
混合读写
    - 带宽
    - iops
    - latency

稳定性测试

模拟线上故障等

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

今天主要讲下 qbus 落地到hdfs的组件–flume,的容器化过程,希望能给在座的有把服务迁移到容器的各位,提供一个解决方案,可能不是最好,但是它很真实。


flume 在qbus 服务中作用:

消费各个业务的topic数据,持久化到hdfs。

hulk流程

  • user 通过 hulk 开通落地到hdfs服务,hulk脚本把相关配置存在zookeeper中。

  • 本地脚本cron遍历读取zk配置(每个机器消费集群维护一个cluster_list)

  • 机器本地起flume进程消费,写hdfs。

服务痛点:

可用性

  • hdfs集群割接断网
  • flume机器down机
  • 某些topic量过于大

配额/负载均衡

  • 业务短时间内开启多个进程

运维成本

  • 多处配置文件维护(cluster.conf,burrow.list)

  • 手动进程增添,跨机器之后配置不统一

  • 进程存在哪台机器,未知

最初运维改善

  1. 可用性监控

  2. 运维工具编写

    • 配置批量增删改查工具

    • 机器整体迁移工具

思考-容器能为我们带来什么?

  • 可用性更强
    hulk容器有保活功能。挂掉自动拉起

  • 资源配比均衡
    不用考虑机器上进程超载状况

  • 增添副本更加方便
    有接口,可以直接操作

  • 运维成本更低
    迁移,更改配置更加方便

而且各进程之间没有什么数据同步,基本无状态,非常适合容器场景。

容器化面对的问题

如何实现以下问题

  1. hdfs授权

  2. 配置

  3. 监控

  4. 动态调整

  5. 无痛迁移

最终实现

  • 自动授权

    • [x]系统部配合出授权接口
    • 我们自己用golang包成工具,嵌入到容器中,每次容器启动的时候自动授权
  • 配置存取

    • 从zookeeper迁移到qcm, 制定新的配置模板,由hulk写入到qcm配置中心

* [x] 容器读取qcm http接口
  • 监控

    • 容器主进程自动check服务进程

    • 根据topic流量和lag情况进行副本动态调整

    • 每次调整之后的结果,包括pod_num,lag情况,partition数量都记录在数据库中,做到有据可查,也能及时发现异常情况

* [x] 设置黑名单功能,对异常业务进行隔离
  • hulk用户无缝迁移
    • 使用相同consumer group
    • hulk 开发配合特征识别新老版本进程(新建走新流程)

总结

其实在这个过程当中工作量具体分配如下:

content 工作量/时间 占比
发现问题 10%
提出方案 10%
沟通/跨部门沟通 30%
优化/确定方案 10%
上线 30%
后续问题处理 10%

所以沟通尤其跨部门沟通也是技术活儿,

ToDo:

  • 授权优化
  • 不同特征topic配置优化

基本的东西之所以基本,不是因为简单,而是因为重要。


巴赫抗躁动、海顿抗抑郁、莫扎特抗失眠、贝多芬抗萎靡、柴科夫斯基抗饥饿、马勒抗瞌睡、拉赫玛尼诺夫抗寂寞。最后还必须得指出一个最管用的:布鲁克纳,


我是个俗气至顶的人,见山是山,见海是海,见花便是花。唯独见了你,云海开始翻涌,江潮开始澎湃,昆虫的小触须挠着全世界的痒。你无需开口,我和天地万物便通通奔向你。


曾经我自诩半个诗人,见山是深情伟岸,见海是热情澎湃,见花见草信他们皆有故事,云海江潮,虫鸣鸟啼都暗藏情愫。唯独见了你,山川沉默,海面静谧,云海不再翻涌,江潮不再澎湃,花鸟鱼虫被光与尘凝固,世界万籁俱寂,只剩下你。


有位文豪说得好:「看一个作家的水平,不是看他发表了多少文字,而要看他的废纸篓里扔掉了多少。」我觉得同样的理论适用于编程。好的程序员,他们删掉的代码,比留下来的还要多很多。如果你看见一个人写了很多代码,却没有删掉多少,那他的代码一定有很多垃圾。


你们对我的百般注解和识读,并不构成万分之一的我,却是一览无遗的你们。


不被理性升华的愤怒只会成为恶产生的源头.


关于「情怀」。

我觉得吧,什么是情,是你对某个事物,某一项工作的投入,你身在其中,你专注你付出,你觉得这个是值得的。而这个怀,就是在这个过程中,你若遇到的事情,合不合你意,你都能装下,能包容,能坚持一直以来的方向。这样在遇到一些选择的时候,你即使心中有其他声音干扰,也仍然能做出正确的抉择。从某种意义上来说,也算是一种信仰吧。有的人说是装逼,其实情怀这东西,每个人都有,只不过大家用的不同罢了。


一只船孤独的航行在海上,它既不寻求幸福,也不逃避幸福,它只是向前航行,底下是沉静碧蓝的大海,而头顶是金色的太阳。 – 莱蒙托夫


她就像个小公主——站在森林里双臂一张,蝴蝶都飞过来、小鹿都跑过来,森林里的生灵都围着坐着听她唱歌。


你要做个不动声色的大人了,不准情绪化,不准偷偷想念,不准回头看,去过自己另外的生活。你要听话,不是所有的鱼都会生活在同一片海里。 – 村上春树

无序记录python使用中的技巧,

centos6 安装python2.7

1
2
3
4
5
6
7
8
yum install -y zlib-devel bzip2-devel openssl-devel xz-libs wget mysql-devel 
wget https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz
tar -zxvf Python-2.7.8.tgz
cd Python-2.7.8
./configure --prefix=/usr/local
make && make install
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
/usr/local/bin/python2.7 get-pip.py

python 字典比较

json_tools.diff()

python list filter (过滤list 中含有”topic”的元素,生成一个新的字典)

list(filter(lambda x: "topic" in x , confs_list)

判断变量是否存在

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

python中检测某个变量是否有定义

第一种方法使用内置函数locals():
locals():获取已定义对象字典

'testvar' in locals().keys()
1
第二种方法使用内置函数dir():
dir():获取已定义对象列表

'testvar' in dir()
1
第三种方法使用内置函数vars():
vars():获取已定义对象字典

vars().has_key('testvar')

lambda, filter, map

lambda 匿名函数

格式: fun_name = lambda x : x+2(表达式)

1
x=lambda x:x*x if x%2==0 else x

sort lambda (按照第三列排序)

l=[(‘b’, ‘atom’, 2), (‘c’, ‘big’, 12), (‘a’, ‘tom’, 21)]
l.sort(key=lambda l: (l[2]))
l
[(‘b’, ‘atom’, 2), (‘c’, ‘big’, 12), (‘a’, ‘tom’, 21)]

参考:
https://github.com/gpakosz/.tmux
https://www.linkedin.com/pulse/how-i-use-tmux-iterm2-robert-freiberger
http://cenalulu.github.io/linux/tmux/

操作步骤:

1
2
3
4
5
6
7
8
安装tmux
$ brew install tmux
下载配置文件 (配置文件依赖于powerline-status 需要pip安装)
$ cd
$ git clone https://github.com/gpakosz/.tmux.git
$ ln -s -f .tmux/.tmux.conf
$ cp .tmux/.tmux.conf.local .
$ reload 配置 C-a + r

使用方法:

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname

attach:

tmux a  #  (or at, or attach)

attach to named:

tmux a -t myname

list sessions:

tmux ls

kill session:

tmux kill-session -t myname

Kill all the tmux sessions:

tmux ls | grep : | cut -d. -f1 | awk '{print substr($1, 0, length($1)-1)}' | xargs kill

In tmux, hit the prefix ctrl+b (my modified prefix is ctrl+a) and then:

Sessions

:new<CR>  new session
s  list sessions
$  name session

Windows (tabs)

c  create window
w  list windows
n  next window
p  previous window
f  find window
,  name window
&  kill window

Panes (splits)

%  vertical split
"  horizontal split

o  swap panes
q  show pane numbers
x  kill pane
+  break pane into window (e.g. to select text by mouse to copy)
-  restore pane from window
⍽  space - toggle between layouts
<prefix> q (Show pane numbers, when the numbers show up type the key to goto that pane)
<prefix> { (Move the current pane left)
<prefix> } (Move the current pane right)
<prefix> z toggle pane zoom

Sync Panes

You can do this by switching to the appropriate window, typing your Tmux prefix (commonly Ctrl-B or Ctrl-A) and then a colon to bring up a Tmux command line, and typing:

1
:setw synchronize-panes

You can optionally add on or off to specify which state you want; otherwise the option is simply toggled. This option is specific to one window, so it won’t change the way your other sessions or windows operate. When you’re done, toggle it off again by repeating the command. tip source

Resizing Panes

You can also resize panes if you don’t like the layout defaults. I personally rarely need to do this, though it’s handy to know how. Here is the basic syntax to resize panes:

PREFIX : resize-pane -D (Resizes the current pane down)
PREFIX : resize-pane -U (Resizes the current pane upward)
PREFIX : resize-pane -L (Resizes the current pane left)
PREFIX : resize-pane -R (Resizes the current pane right)
PREFIX : resize-pane -D 20 (Resizes the current pane down by 20 cells)
PREFIX : resize-pane -U 20 (Resizes the current pane upward by 20 cells)
PREFIX : resize-pane -L 20 (Resizes the current pane left by 20 cells)
PREFIX : resize-pane -R 20 (Resizes the current pane right by 20 cells)
PREFIX : resize-pane -t 2 20 (Resizes the pane with the id of 2 down by 20 cells)
PREFIX : resize-pane -t -L 20 (Resizes the pane with the id of 2 left by 20 cells)

Copy mode:

Pressing PREFIX [ places us in Copy mode. We can then use our movement keys to move our cursor around the screen. By default, the arrow keys work. we set our configuration file to use Vim keys for moving between windows and resizing panes so we wouldn’t have to take our hands off the home row. tmux has a vi mode for working with the buffer as well. To enable it, add this line to .tmux.conf:

setw -g mode-keys vi

With this option set, we can use h, j, k, and l to move around our buffer.

To get out of Copy mode, we just press the ENTER key. Moving around one character at a time isn’t very efficient. Since we enabled vi mode, we can also use some other visible shortcuts to move around the buffer.

For example, we can use “w” to jump to the next word and “b” to jump back one word. And we can use “f”, followed by any character, to jump to that character on the same line, and “F” to jump backwards on the line.

Function                vi             emacs
Back to indentation     ^              M-m
Clear selection         Escape         C-g
Copy selection          Enter          M-w
Cursor down             j              Down
Cursor left             h              Left
Cursor right            l              Right
Cursor to bottom line   L
Cursor to middle line   M              M-r
Cursor to top line      H              M-R
Cursor up               k              Up
Delete entire line      d              C-u
Delete to end of line   D              C-k
End of line             $              C-e
Goto line               :              g
Half page down          C-d            M-Down
Half page up            C-u            M-Up
Next page               C-f            Page down
Next word               w              M-f
Paste buffer            p              C-y
Previous page           C-b            Page up
Previous word           b              M-b
Quit mode               q              Escape
Scroll down             C-Down or J    C-Down
Scroll up               C-Up or K      C-Up
Search again            n              n
Search backward         ?              C-r
Search forward          /              C-s
Start of line           0              C-a
Start selection         Space          C-Space
Transpose chars                        C-t

Misc

d  detach
t  big clock
?  list shortcuts
:  prompt

Configurations Options:

# Mouse support - set to on if you want to use the mouse
* setw -g mode-mouse off
* set -g mouse-select-pane off
* set -g mouse-resize-pane off
* set -g mouse-select-window off

# Set the default terminal mode to 256color mode
set -g default-terminal "screen-256color"

# enable activity alerts
setw -g monitor-activity on
set -g visual-activity on

# Center the window list
set -g status-justify centre

# Maximize and restore a pane
unbind Up bind Up new-window -d -n tmp \; swap-pane -s tmp.1 \; select-window -t tmp
unbind Down
bind Down last-window \; swap-pane -s tmp.1 \; kill-window -t tmp

Notes:

操作多个pane

+ : + setw synchronize-panes

Changelog:

Request an Update:

We Noticed that our Cheatsheet is growing and people are coloberating to add new tips and tricks, so please tweet to me what would you like to add and let’s make it better!

鼠标模式

+ m

分布式系统离不开一致性问题的讨论。哈哈。结合Google总结下

其中一致性大致分为强一致性弱一致性最终一致性。而一致性越强大概率是以牺牲读写效率为前提。

CAP 理论

C

Paxos算法

gossip协议

raft算法

因为kafka集群的问题引发对系统io的相关优化,所以此优化针对kafka等大量io的应用场景。

IO调度器

参考: https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/6/html/performance_tuning_guide/ch06s04s02

  • cfq

centos6 默认是cfq(Completely Fair Queuing), 每个进程维护一个io队列,然后调度器对每个队列进行轮询,相对于每个进程是公平的。每个进程可以设置io读写优先级。

  • Deadline

对于读写操作有截止时间,对读和写操作用两条不同的队列管理,可以解决读取饥饿的现象。因为操作系统对读请求是同步处理的,写入请求可以异步处理。操作系统可以数据写到内存,然后对IO队列中的请求做合并,提高IO的吞吐量。通过设置read_expire < write_expire时间,避免读取操作处于饥饿调度的状态。对于数据库存储应用,Deadline是最佳的IO Scheduler,甚至很多PCIE卡作为设备内置默认参数。

  • NOOP

是建立在FIFO调度模型之上的,并合相邻IO请求。Noop容易出现读取操作饥饿现象,使用NOOP调度,需要磁盘有足够的IO能力。对于SSD基于闪存技术存储介质和SAN存储,NOOP也是首选的调度器。

脏页相关配置

系统数据写入磁盘可以异步进行,这样效率可能会更高。对于IO比较大的机器,可以把脏页大小的阈值调到,更多的使用系统内存来优化磁盘写入速度(所谓优化是尽量让io更多顺序的进行,同一时间点只读或者只写,因为磁盘顺序读写的速度很快).

  • dirty_ratio 系统总内存的百分比,太小导致系统强制脏页写回到磁盘,这个会阻塞系统接受写入请求。
  • dirty_background_ratio 文件系统的写入缓冲区的大小,达到这个百分比时,pdflush进程开始启动,把数据写回到磁盘,但是不影响正常的读写请求。

但是调大脏页率有会带来数据丢失的危险,要有所取舍。

所以我们也可以继续调整下面两个参数

  • dirty_writeback_centisecs,控制 pdflush/flush/kdmflush等进程的唤醒时间。默认30s

  • dirty_expire_centisecs,控制dirty page刷盘时间点。默认5s

减小这两个参数可以使脏页尽快落盘,避免数据丢失,也可解决 io spike 现象。同时io_await也会下降。

文件系统

做了lvm的机器io性能会下降,所以用来频繁io的机器, 最好不要用lvm。

一般会选用xfs,因为Ext4最大只支持16T分区,xfs可以到100T+,顺序读写性能也更好一点,更适合操作大文件。

记录一些关键问题点,不是部署文档,不是部署文档。

数据采集类型

  • counter

  • gauge

查询语法

函数使用

AlertManager

报警组件使用,

alertmanager 高可用

alertmanager 高可用模式 基于gossip机制同步告警状态,

nginx 反向代理

prometheus 官方推荐的登录验证方式为 basic auth 我们可以借助强大的nginx来实现。 把数据接口加上验证,这样监控数据就不会随意被内网的同事们看到了。。

basic auth 配置

使用htpasswd生成用户名密码

“””
htpasswd -c /usr/local/nginx/conf/.htpasswd user1
“””

nginx配置文件

“””

server {
    listen       8081;
    server_name  localhost;


    location / {
        auth_basic           "Prometheus";
        auth_basic_user_file /usr/local/nginx/conf/.htpasswd;
        autoindex on;
        proxy_pass        http://127.0.0.1:6789/;
    }
...
}

“””

prometheus启动命令调整为

“””
/usr/local/prometheus/prometheus –config.file=/usr/local/prometheus/prometheus.yml –log.level=info –web.enable-admin-api –web.listen-address=127.0.0.1:6789
“””