Ubuntu 上安装 drbd8-utils 之后 创建资源 失败。 查看版本信息 发现内核模块和用户空间的管理工具的版本不匹配 ubuntu14.4.04 kernel中编译的 drbd module 版本是 8.4.5, 而官方trusty所提供的drbd8-utils的版本只到8.4.4, 只能手动编译了
How-to deploy flask web applications use wsgi behind apache
Flask是一个使用Python编写的轻量级Web应用框架。基于Werkzeug WSGI工具箱和Jinja2 模板引擎。 Flask使用BSD授权。 Flask也被称为“microframework”,因为它使用简单的核心,用extension增加其他功能。Flask没有默认使用的数据库、窗体验证工具。然而,Flask保留了扩增的弹性,可以用Flask-extension加入这些功能:ORM、窗体验证工具、文件上传、各种开放式身份验证技术。 WSGI Web服务器网关接口(Python Web Server Gateway Interface,缩写为WSGI)是为Python语言定义的Web服务器和Web应用程序或框架之间的一种简单而通用的接口。自从WSGI被开发出来以后,许多其它语言中也出现了类似接口。
How-to resolve Target WSGI script xxx.wsgi cannot be loaded as Python module
情景再现: 在我将 Flask应用程序部署到 Apache 的时候,我得到了一个 500 internal sever error 的错误。 查看错误日志得到下面信息
[Tue Jun 21 11:29:46 2016] [notice] Apache/2.2.15 (Unix) DAV/2 PHP/5.3.3 mod_ssl/2.2.15 OpenSSL/1.0.1e-fips mod_wsgi/3.2 Python/2.7.3 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming # [Tue Jun 21 11:29:49 2016] [error] [client 172.16.7.158] mod_wsgi (pid=1334): Target WSGI script '/var/www/html/report/report.wsgi' cannot be loaded as Python module. [Tue Jun 21 11:29:49 2016] [error] [client 172.16.7.158] mod_wsgi (pid=1334): Exception occurred processing WSGI script '/var/www/html/report/report.wsgi'. [Tue Jun 21 11:29:49 2016] [error] [client 172.16.7.158] Traceback (most recent call last): [Tue Jun 21 11:29:49 2016] [error] [client 172.16.7.158] File "/var/www/html/report/report.wsgi", line 10, in <module> [Tue Jun 21 11:29:49 2016] [error] [client 172.16.7.158] from report import app as application [Tue Jun 21 11:29:49 2016] [error] [client 172.16.7.158] File "/var/www/html/report/report.py", line 11, in <module> [Tue Jun 21 11:29:49 2016] [error] [client 172.16.7.158] from flask import Flask [Tue Jun 21 11:29:49 2016] [error] [client 172.16.7.158] ImportError: No module named falsk
Python 应用程序是 通过源码编译的,安装目录为 /usr/local/Python2.7.3 Flask 模块是存在的, 问题就在 为啥 找不到她呢???
How-to Make mod_wsgi use python2.7.3 instead of python2.6.6
Bytes-to-human and human-to-bytes converter
#!/usr/bin/env python
"""
Bytes-to-human / human-to-bytes converter.
Based on: http://goo.gl/kTQMs
Working with Python 2.x and 3.x.
Author: Giampaolo Rodola' <g.rodola [AT] gmail [DOT] com>
License: MIT
"""
# see: http://goo.gl/kTQMs
SYMBOLS = {
'customary' : ('B', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'),
'customary_ext' : ('byte', 'kilo', 'mega', 'giga', 'tera', 'peta', 'exa',
'zetta', 'iotta'),
'iec' : ('Bi', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi'),
'iec_ext' : ('byte', 'kibi', 'mebi', 'gibi', 'tebi', 'pebi', 'exbi',
'zebi', 'yobi'),
}
def bytes2human(n, format='%(value).1f %(symbol)s', symbols='customary'):
"""
Convert n bytes into a human readable string based on format.
symbols can be either "customary", "customary_ext", "iec" or "iec_ext",
see: http://goo.gl/kTQMs
>>> bytes2human(0)
'0.0 B'
>>> bytes2human(0.9)
'0.0 B'
>>> bytes2human(1)
'1.0 B'
>>> bytes2human(1.9)
'1.0 B'
>>> bytes2human(1024)
'1.0 K'
>>> bytes2human(1048576)
'1.0 M'
>>> bytes2human(1099511627776127398123789121)
'909.5 Y'
>>> bytes2human(9856, symbols="customary")
'9.6 K'
>>> bytes2human(9856, symbols="customary_ext")
'9.6 kilo'
>>> bytes2human(9856, symbols="iec")
'9.6 Ki'
>>> bytes2human(9856, symbols="iec_ext")
'9.6 kibi'
>>> bytes2human(10000, "%(value).1f %(symbol)s/sec")
'9.8 K/sec'
>>> # precision can be adjusted by playing with %f operator
>>> bytes2human(10000, format="%(value).5f %(symbol)s")
'9.76562 K'
"""
n = int(n)
if n < 0:
raise ValueError("n < 0")
symbols = SYMBOLS[symbols]
prefix = {}
for i, s in enumerate(symbols[1:]):
prefix[s] = 1 << (i+1)*10
for symbol in reversed(symbols[1:]):
if n >= prefix[symbol]:
value = float(n) / prefix[symbol]
return format % locals()
return format % dict(symbol=symbols[0], value=n)
def human2bytes(s):
"""
Attempts to guess the string format based on default symbols
set and return the corresponding bytes as an integer.
When unable to recognize the format ValueError is raised.
>>> human2bytes('0 B')
0
>>> human2bytes('1 K')
1024
>>> human2bytes('1 M')
1048576
>>> human2bytes('1 Gi')
1073741824
>>> human2bytes('1 tera')
1099511627776
>>> human2bytes('0.5kilo')
512
>>> human2bytes('0.1 byte')
0
>>> human2bytes('1 k') # k is an alias for K
1024
>>> human2bytes('12 foo')
Traceback (most recent call last):
...
ValueError: can't interpret '12 foo'
"""
init = s
num = ""
while s and s[0:1].isdigit() or s[0:1] == '.':
num += s[0]
s = s[1:]
num = float(num)
letter = s.strip()
for name, sset in SYMBOLS.items():
if letter in sset:
break
else:
if letter == 'k':
# treat 'k' as an alias for 'K' as per: http://goo.gl/kTQMs
sset = SYMBOLS['customary']
letter = letter.upper()
else:
raise ValueError("can't interpret %r" % init)
prefix = {sset[0]:1}
for i, s in enumerate(sset[1:]):
prefix[s] = 1 << (i+1)*10
return int(num * prefix[letter])
Extra: for an alternative version as simple as possible (no global vars, no extra args, easier to customize) see here: http://code.google.com/p/pyftpdlib/source/browse/trunk/test/bench.py?spec=svn984&r=984#137
来自 http://code.activestate.com/recipes/578019-bytes-to-human-human-to-bytes-converter/
How-to use Flask and mysql to build a simple monitor
本文主要讲述的是: 如何使用 Flask + Mysql + Highcharts 构建一个简单的监控系统 以监控系统内存为例的简易 Demo,文档参考 运维之路 的教程。 整体思路是:
- 收集数据
- 存储数据
- 展示数据
建库建表
Couchbase CLI Notes
cbreset_password
Syntax
The basic syntax to reset the administrative password:
cbreset_password [hostname]:[port]
#./bin/cbreset_password 127.0.0.1:8091
Please enter the new administrative password (or <Enter> for system generated password):
Running this command will reset administrative password.
Do you really want to do it? (yes/no)yes
Resetting administrative password...
Password for user Administrator was successfully replaced.
未完待续 ...
Bash Arrays
如果你使用的是类UNIX的shell 你可能对bash 的 数组不是很熟悉。虽然没有向P语言(Perl, Python, PHP)那样强大,但是它们往往是很有用处的。 Bash 数组只有索引编号,但是它们是单独的。也就是说你不必定义所有索引。整个数组可以通过封闭括号中的数组项分配:
arr=(Hello World)
单个项目可以用熟悉的数组语法被分配(除非你已经习惯了Basic或Fortran):
arr[0]=Hello arr[1]=World
但是,当你要引用数组项它变得有点难看:
echo ${arr[0]} ${arr[1]}
man 手册中的部分内容: 大括号是必需的,以避免与路径扩展冲突。
How-to use dot to draw flow chart
Graphviz (Graph Visualization Software的缩写) 是AT Labs-Research开发的图形绘制工具,他可以很方便的用来绘制结构化的图形网络,支持多种格式输出,生成图片的质量和速度都不错.Graphviz本身是开源的产品,下载可以到 这里,以及他的演示界面 Graphviz在windows上和Linux上都可以顺利运行.它的强大主要体现在“所思即所得"(WYTIWYG,what you think is what you get),这是和office的“所见即所得“(WYSIWYG,what you see is what you get)完全不同的一种方式。
graphviz中包含了众多的布局器:
- dot 默认布局方式,主要用于有向图
- neato 基于spring-model(又称force-based)算法
- twopi 径向布局
- circo 圆环布局
- fdp 用于无向图
graphviz的设计初衷是对有向图/无向图等进行自动布局,开发人员使用dot脚本定义图形元素,然后选择算法进行布局,最终导出结果。
使用graphviz的一般流程为:
- 定义一个图,并向图中添加需要的顶点和边
- 为顶点和边添加样式
- 使用布局引擎进行绘制
基础知识
graphviz包含3种元素,图,顶点和边。每个元素都可以具有各自的属性,用来定义字体,样式,颜色,形状等。下面是一些简单的示例,可以帮助我们快速的了解graphviz的基本用法。
图的属性
节点属性
边属性
Ubuntu 安装 Graphviz
sudo apt-get install graphviz -y
dot usage
dot -? Usage: dot [-Vv?] [-(GNE)name=val] [-(KTlso)<val>] <dot files> (additional options for neato) [-x] [-n<v>] (additional options for fdp) [-L(gO)] [-L(nUCT)<val>] (additional options for memtest) [-m<v>] (additional options for config) [-cv] -V - Print version and exit -v - Enable verbose mode -Gname=val - Set graph attribute 'name' to 'val' -Nname=val - Set node attribute 'name' to 'val' -Ename=val - Set edge attribute 'name' to 'val' -Tv - Set output format to 'v' -Kv - Set layout engine to 'v' (overrides default based on command name) -lv - Use external library 'v' -ofile - Write output to 'file' -O - Automatically generate an output filename based on the input filename with a .'format' appended. (Causes all -ofile options to be ignored.) -P - Internally generate a graph of the current plugins. -q[l] - Set level of message suppression (=1) -s[v] - Scale input by 'v' (=72) -y - Invert y coordinate in output -n[v] - No layout mode 'v' (=1) -x - Reduce graph -Lg - Don't use grid -LO - Use old attractive force -Ln<i> - Set number of iterations to i -LU<i> - Set unscaled factor to i -LC<v> - Set overlap expansion factor to v -LT[*]<v> - Set temperature (temperature factor) to v -m - Memory test (Observe no growth with top. Kill when done.) -m[v] - Memory test - v iterations. -c - Configure plugins (Writes $prefix/lib/graphviz/config with available plugin information. Needs write privilege.) -? - Print usage and exit
待续 ...