4个月宝宝厌奶期怎么办?(转)

2010年9月10日 16hot 没有评论

我儿子4个月多几天,最近吃奶都不好好吃,老是把奶嘴含在嘴里假吃,头转来转去东看西看的.吃一次奶起码要40分钟,平时吃210ML,现在只吃150ML,一天才吃4餐.中间有一餐是米粉加奶粉的,我真怕这样子营养不够.有没有什么好办法啊?

第1招 不用强迫手段

很多家长都担心宝宝喝太少会长不大,于是采用强迫的方式。但是这种做法反而会让宝宝对吃产生恐惧。其实只要宝宝身高、体重等发展状况,都在可以接受的范围内,并不需要强迫他喝奶,这个时期家长应该思考,如何协助宝宝接受半流质的辅食,而非强迫他喝奶。

第2招 改变喂食方式

当宝宝出现厌奶的征兆,爸妈可以从改善喂食方式做起,采取较为随性的方式,不需要按表作业。以少量多餐为原则,等宝宝想吃的时候再吃。可以通过游戏消耗宝宝的体力,例如按摩、肢体活动等,当他精力耗尽、感到饥饿时,进食的状况也会获得改善。

第3招 营造用餐环境

进食的环境尽量柔和、安静。因为此阶段的宝宝开始对外界感到好奇,用餐时若有人在旁逗弄他,或出现很多能吸引他注意力的玩具、声音,宝宝会觉得这些事情比吃饭更有趣,自然就不想吃了。

第4招 奶嘴洞大小要适当

有时候宝宝喝奶少,可能是因为奶瓶上奶嘴的奶洞太小,使宝宝吸得不顺畅,因此喝的量才减少。先将奶瓶倒过来,检查一下奶瓶奶嘴的奶洞,是否能顺利流出,通常最佳的速度是1秒1滴,滴不出来或滴得太快,对宝宝都不好。

第5招 不要常换奶粉

看到宝宝不爱喝奶,家长可能直接想到:是不是这个牌子的奶粉宝宝喝腻了?可以更换别的奶粉,但更换速度不要太频繁,宝宝会没有时间适应。如果要换 新牌子,也不要一下子全部换,最好和别牌子的奶粉混合搭配,并观察一周排便状况,若排便正常,表示适应良好,此时才可以更换全新的奶粉。进入厌奶期后,更 换奶粉牌子的效果有限,如果试换了一两次仍没有起色,就可以放弃使用这个方法了。

第6招 适时添加辅食

4个月大左右的宝宝,还是以母乳或配方奶为主,辅食大约吃一两餐即可,因此当宝宝感到厌倦,不妨给他一点新的尝试。可从米粉或稀释的果汁开始,陆 续再加入蔬菜泥和果泥。不过记得要遵守1次加1种的原则,从1小茶匙开始,再慢慢加份量。每种辅食可先尝试3~5天,并观察宝宝的状况。

如果他不喜欢或是皮肤出现疹子、便便变稀等情形,建议先暂缓添加此种辅食,等过阵子再尝试。若是有过敏的家庭史,建议喂食母乳或部分水解奶粉到宝宝6个月大,之后再添加辅食,而添加的辅食以低致过敏性为优先。

第7招 轻松对待厌奶

照顾宝宝的人,其心情和压力会直接传达给宝宝,当照顾者焦虑或强迫宝宝喝奶时,他都能感受到,因而产生抗拒。只要宝宝各方面都健康、正常,也没有生病,家长们就可以放宽心,用顺其自然的态度面对待宝宝的厌奶期,不要和宝宝为了吃展开痛苦的拉距战。

怎样帮宝宝轻松度过厌奶期

我的宝宝为什么喝得那么少,该怎么办才好?别担心,如果宝宝不是因为生病厌食,那他可能是进入了厌奶期。只要用对方法,就不必烦恼宝宝长不大哦!
问题1 发生原因&时间

生理、心理皆会影响

生理因素 当宝宝厌奶时,首先要观察一下,是不是身体不舒服所导致的。如果还并发了呕吐、便秘、腹胀、腹泻、发烧等症状,应该立刻就医治疗。

心理因素 由于从出生开始,宝宝每天喝的都是同一种食物,一段时间后,可能会产生厌恶喝奶的情况,这也是宝宝在提醒爸妈,该给他吃些不同的东西了。适时给宝宝流质食物,便会逐渐恢复胃口,如果宝宝活动力佳、精神也好,只是食欲稍差,爸妈并不用太担心。

4~6个月会发生

宝宝4~6个月大时,好奇心与日俱增,因为脖子的肌肉张力较好,开始对身边的事物感到新奇,也会分散他吃东西的注意力,此时正为常见的厌奶期。

舌头碰到东西往外吐的反应也会消失,如果没有适当添加辅食,用小汤匙喂食以训练宝宝的口腔协调功能,宝宝日后可能会只喝奶不想吃固体食物,出现明显的厌食,会营养不均衡。

哺喂母乳的妈妈,当宝宝出现厌奶时,千万不要因此停止哺乳,只要同时提供软流质的辅食,母乳可以哺喂到2岁。 问题2 辨别厌奶的方法

计算奶量

如何知道宝宝是不是进入厌奶期了呢?这是令很多爸妈感到疑惑的问题。宝宝进入厌奶期之后,最明显的症状就是吃的奶量变少了,因此可以计算宝宝每天所喝的奶量,如果低于所需的奶量,没有生病发烧,且到了4~6个月大,宝宝就可能已经进入厌奶期。

宝宝每天所需的奶量

一般而言,4个月内的宝宝,计算奶量的公式是以宝宝的体重和每天的餐次来计算。

(体重×120~150毫升)÷餐次/(天)=一餐的奶量

Example 4个月大的宝宝,体重大约6千克,一天大约喝6餐。

(6千克×120~150毫升)÷6=120~150毫升/每餐

问题3 生长&发育

对应生长曲线表

宝宝生长好不好,是很多家长关心的事,如果又碰上厌奶,会不会对发育造成影响呢?宝宝的身心动作发展,像是头部控制及肌肉张力、人际互动若都符合 其年龄,代表他的发展是正常的。至于身高、体重和头,本来就是因人而异,不需要跟别的宝宝比较。每次带宝宝看健儿门诊时,医护人员都会测量并记录,不妨将 这些数据,对应儿童健康手册上的生长曲线,观察一下是否在正常范围中,若是数值都正常,爸妈就可以放心。

善用儿童健康手册

假设宝宝的生长曲线一直都在50%左右,到了厌奶期,刚开始并不会有太大变化。正常来说,在25%~75%之间都属于可接受的范围。但如果宝宝吃 得很少,又没有额外添加营养食品或辅食,生长曲线就会下降,可能从50%掉到10%,这就表示厌奶已经对宝宝造成生长上的影响。

其实想要多了解宝宝生长发育是否正常,好好利用儿童健康手册,就能获得非常多的信息!手册中会有宝宝每个月应该发展的评估项目,家长不妨自行检视一下,看看自己的宝宝,有没有符合他的月龄该会做的事,通过儿童健康手册,就能轻松掌握宝宝的生长状况。

每个孩子都有段厌奶期的,没有关系的,过段时间就好了的。

没什么事的

宝宝和成人一样,也有胃口不好的 时候,饱不饱,他自己最知道,如果他很快喝完奶或提前哭,就表示可以再增加奶量;如果喝了一点点就不喝了,爸爸妈妈应先搞清楚,宝宝有没有不舒服,环境中 是否有吸引、令他分心的事情,而不必勉强他喝到一定的量,同时,也不必要严守3小时喂食1次的方式,差个半小时、1小时,并没有关系;睡前的一餐,给他喝 多一点,宝宝可能就一觉到天亮,不会半夜吵着喝奶。

不用担心的,你强硬给他吃,只有令他越来越讨厌吃奶,过一段时间就没事的,现在尽量少吃多餐

宝宝厌奶期,首先要换别的牌子奶粉.

或者,每天给他吃马铃薯泥,蕃薯泥,果泥,面条,鱼肉,米粉

分类: 转载 标签:

Using Serial Devices in FreeBSD / How to set a terminal baud rate

2010年8月24日 16hot 没有评论

http://www.clearchain.com/blog/posts/using-serial-devices-in-freebsd-how-to-set-a-terminal-baud-rate

Recently I was working on a php command line program that required access to a serial port.

Initially developed under Linux the program was then shifted to it’s permanent location on a FreeBSD server. This is where we first started having problems. Initially we discovered the server didn’t have a native serial port. We fixed this using a USB to serial converter/dongle (FTDI Chipset). This was fine as FreeBSD has the ufdti kernel module. Upon loading the module new devices appears in /dev

crw-rw----  1 uucp  dialer    0, 157 Oct  6 08:39 /dev/cuaU0
crw-rw----  1 uucp  dialer    0, 158 Oct  6 08:39 /dev/cuaU0.init
crw-rw----  1 uucp  dialer    0, 159 Oct  6 08:39 /dev/cuaU0.lock
crw-rw-rw-  1 root  wheel     0, 154 Jan  8 10:50 /dev/ttyU0
crw-------  1 root  wheel     0, 155 Oct  6 08:39 /dev/ttyU0.init
crw-------  1 root  wheel     0, 156 Oct  6 08:39 /dev/ttyU0.lock

We attempted to connect to our device using screen (screen /dev/ttyU0 115200) and everything worked as expected. We could send AT commands to the device all ok.
We then stopped screen and ran our php program. It ended up hanging on a fgets call to the serial port. This is really strange we though.
Next we queried the port to find out what baud rate it was set at:

>stty -f /dev/ttyu0
speed 9600 baud;
lflags: echoe echoke echoctl
oflags: tab0
cflags: cs8 -parenb

Strange we thought as we’d just connected with screen at 115200. Under linux we use screen to set the baud rate, all other programs accessing the port use the port at 115200. So what had set it back to 9600 baud?
We tried to use stty to set the speed:

>stty -f /dev/ttyU0 speed 115200
>stty -f /dev/ttyu0
speed 9600 baud;
lflags: echoe echoke echoctl
oflags: tab0
cflags: cs8 -parenb

What on earth was happening? We set the speed to 115200 but directly quering the port again indicated it was still at 9600 baud? At this point we were perplexed.
Eventually we found the solution. The newer FreeBSD terminal drivers provide the *.init devices, in this case /dev/ttyU0.init . These devices indicate the terminal settings to be applied to the terminal when the device is closed. Whilst Linux leaves the device in the same state the last program put the port into, FreeBSD restores the terminals state to what ever is specified in the init file. So a quick command:

> stty -f /dev/ttyU0.init -icanon -isig -echo echoe echok echoke echoctl -icrnl -ixany -imaxbel ignpar -opost -onlcr -oxtabs cs8 -parenb -hupcl clocal

And then to check:

> stty -f /dev/ttyU0
speed 115200 baud;
lflags: -icanon -isig -echo echoe echok echoke echoctl
iflags: -icrnl -ixany -imaxbel ignpar
oflags: -opost -onlcr -oxtabs
cflags: cs8 -parenb -hupcl clocal

Excellent. The terminal was now configured exactly how we wanted. We ran the program and it worked like a charm!

分类: BSD/linux, 转载 标签:

入手HTC HD2

2010年8月20日 16hot 没有评论

开始准备购买HTC的Android系统的手机,但是要么配置太低,要么价格太高。看来看去,都不甚理想。

后来看到HD2,可以运行Android 2.1,2.2了。虽然是双系统,那也说明有独立运行Android的可能了啊。毕竟目前国外有个团队在研发呢。

于是和老婆商量了下,两人一起买了两台,人手一台。谁也不用郁闷、眼红。呵呵

配置:

CPU 1G
内存 576
ROM 512
系统 Windows Mobile 6.5

在中关村鼎好买的。水货,价格适中。

WP-Syntax语法

2010年8月8日 16hot 没有评论

Usage

Wrap code blocks with <pre lang="LANGUAGE" line="1"> and </pre> where LANGUAGE is a GeSHi supported language syntax. See below for a full list of supported languages. The line attribute is optional.

Example 1: PHP, no line numbers

<pre lang="php">
<div id="foo">
<?php
  function foo() {
    echo "Hello World!\\n";
  }
?>
</div>
</pre>

Example 2: Java, with line numbers

<pre lang="java" line="1">
public class Hello {
  public static void main(String[] args) {
    System.out.println("Hello World!");
  }
}
</pre>

Example 3: Ruby, with line numbers starting at 18

<pre lang="ruby" line="18">
class Example
  def example(arg1)
    return "Hello: " + arg1.to_s
  end
end
</pre>

Example 4: If your code already has html entities escaped, use escaped="true" as an option

<pre lang="xml" escaped="true">
&lt;xml&gt;Hello&lt;/xml&gt;
</pre>

Supported Languages

The following languages are supported in the lang attribute:

abap, actionscript, actionscript3, ada, apache, applescript, apt_sources, asm, asp, autoit, avisynth, bash, bf, bibtex, blitzbasic, bnf, boo, c, c_mac, caddcl, cadlisp, cil, cfdg, cfm, cmake, cobol, cpp-qt, cpp, csharp, css, d, dcs, delphi, diff, div, dos, dot, eiffel, email, erlang, fo, fortran, freebasic, genero, gettext, glsl, gml, bnuplot, groovy, haskell, hq9plus, html4strict, idl, ini, inno, intercal, io, java, java5, javascript, kixtart, klonec, klonecpp, latex, lisp, locobasic, lolcode lotusformulas, lotusscript, lscript, lsl2, lua, m68k, make, matlab, mirc, modula3, mpasm, mxml, mysql, nsis, oberon2, objc, ocaml-brief, ocaml, oobas, oracle11, oracle8, pascal, per, pic16, pixelbender, perl, php-brief, php, plsql, povray, powershell, progress, prolog, properties, providex, python, qbasic, rails, rebol, reg, robots, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, sql, tcl, teraterm, text, thinbasic, tsql, typoscript, vb, vbnet, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xml, xorg_conf, xpp, z80

(Bold languages just highlight the more popular ones.)

Styling Guidelines

WP-Syntax colors code using the default GeSHi colors. It also uses inline styling to make sure that code highlights still work in RSS feeds. It uses a default wp-syntax.css stylesheet for basic layout. To customize your styling, copy the default wp-content/plugins/wp-syntax/wp-syntax.css to your theme’s template directory and modify it. If a file named wp-syntax.css exists in your theme’s template directory, this stylesheet is used instead of the default. This allows theme authors to add their own customizations as they see fit.

Advanced Customization

WP-Syntax supports a wp_syntax_init_geshi action hook to customize GeSHi initialization settings. Blog owners can handle the hook in a hand-made plugin or somewhere else like this:

<?php
add_action('wp_syntax_init_geshi', 'my_custom_geshi_styles');

function my_custom_geshi_styles(&$geshi)
{
    $geshi->set_brackets_style('color: #000;');
    $geshi->set_keyword_group_style(1, 'color: #22f;');
}
?>

This allows for a great possibility of different customizations. Be sure to review the GeSHi Documentation.



分类: 转载 标签:

HAST – Highly Available Storage

2010年7月22日 16hot 没有评论

值得关注的高可用存储方案: http://wiki.freebsd.org/HAST

分类: BSD/linux 标签: ,

今天你孝了没有(转)

2010年7月21日 16hot 没有评论

在整理文件夹的时候,看到这篇以前拷贝的文章,看了后还是很受教育。特此贴出来和大家分享。

——————————————————————————————————————————

媳妇说:“煮淡一点你就嫌没有味道,现在煮咸 一点你却说咽不下。你究竟怎想怎么
样?”

母亲一见儿子回来,二话不说便把饭菜往嘴里送。她怒瞪他一眼。他试了一口,马上吐
出来, 儿子说:“我不是说过了吗,妈有病不能吃太咸!” “那好!妈是你的,以后
由你来煮!”媳妇怒气冲冲地回房。儿子无奈地轻叹一声,然后对母亲说:“妈,别吃
了,我去煮个面给?”

“仔,你是不是有话想跟妈说,是就说好了,别憋在心里!”

“妈,公司下个月升我职,我会很忙,至于老婆,她说很想出来工作,所以……”

母亲马上意识到儿子的意思:“仔,不要送妈去老人院。”声音似乎在哀求。

儿子沉默片刻,他是在寻找更好的理由。 “妈,其实老人院并没有甚么不好?知道老
婆一但工作,一定没有时间好好服侍。老人院有吃有住有人服侍照顾, 不是比在家里
好得多吗?”

“可是,阿财叔他……”

洗了澡,草草吃了一碗方便面,儿子便到书房去。他茫然地伫立于窗前,有些犹豫不
决。母亲年轻便守寡,含辛茹苦将他抚养成人,供他出国读书。但她从不用年轻时的牺
牲当作要胁他孝顺的筹码,反而是妻子以婚姻要胁他!真的要让母亲住老人院吗?他问
自己,他有些不忍。 “可以陪你下半世的人是你老婆,难道是你妈吗?”阿财叔的儿
子总是这样提醒他。 “你妈都这么老了,好命的话可以活多几年,为何不趁这几年好
好孝顺她呢?树欲静而风不息,子欲养而亲不在啊!”亲戚总是这样劝他。儿子不敢再
想下去,深怕自己真的会改变初衷。

晚,太阳收敛起灼热的金光,躲在山后憩息。一间建在郊外山岗的一座贵族老人院。

是的,钱用得越多,儿子才心安理得。当儿子领着母亲步入大厅时,崭新的电视机,42
英寸的荧幕正播放着一部喜剧,但观众一点笑声也没有。

几个衣着一样,发型一样的老妪歪歪斜斜地坐在发沙上,神情呆滞而落寞。有个老人在
自言自语,有个正缓缓弯下腰,想去捡掉在地上的一块饼干吃。儿子知道母亲喜欢光
亮,所以为她选了一间阳光充足的房间。从窗口望出去,树荫下,一片芳草如茵。几名
护士推着坐在轮椅的老者在夕阳下散步,四周悄然寂静得令人心酸。纵是夕阳无限好,
毕竟已到了黄昏,他心中低低叹息。

“妈,我……我要走了!”母亲只能点头。他走时,母亲频频挥手,她张着没有牙的
嘴,苍白干燥的咀唇在嗫嚅着,一副欲语还休的样子。儿子这才注意到母亲银灰色的头
发,深陷的眼窝以及打着细褶的皱脸。母亲,真的老了!

他霍然记起一则儿时旧事。那年他才6岁,母亲有事回乡,不便携他同行,于是把他寄
住在阿财叔家几天。母亲临走时,他惊恐地抱着母亲的腿不肯放,伤心大声号哭道:
“妈妈不要丢下我!妈妈不要走!” 最后母亲没有丢下他。

他连忙离开房间,顺手把门关上,不敢回头,深恐那记忆像鬼魅似地追缠而来。

他回到家,妻子与岳母正疯狂的把母亲房里的一切扔个不亦乐乎。身高3英寸的奖杯
──那是他小学作文比赛《我的母亲》第1名的胜利品!华英字典──那是母亲整个月
省吃省用所买给他的第1份生日礼物!还有母亲临睡前要擦的风湿油,没有他为她擦,
带去老人院又有甚么意义呢?

“够了,别再扔了!”儿子怒吼道。

“这么多垃圾,不把它扔掉,怎么放得下我的东西。” 岳母没好气地说。

“就是嘛!你赶快把你妈那张烂床给抬出去,我明天要为我妈添张新的!”

一堆童年的照片展现在儿子眼前,那是母亲带他到动物园和游乐园拍的照片。

“它们是我妈的财产,一样也不能丢!”

“你这算甚态度?对我妈这么大声,我要你向我妈道歉!” (这算什么儿子,把自己
的母亲送到养老院,然后把岳母接来住,要就一起去送,要就留自己的母亲)

“我娶你就要爱你的母亲,为甚么?嫁给我就不能爱我的母亲?”

雨后的黑夜分外冷寂,街道萧瑟,行人车辆格外稀少。一辆宝马在路上飞驰,频频闯红
灯,陷黄格,呼一声又飞驰而过。那辆轿车一路奔往山岗上的那间老人院,停车直奔上
楼,推开母亲卧房的门。他幽灵似地站着,母亲正抚摸着风湿痛的双腿低泣。 她见到
儿子手中正拿着那瓶风湿油,显然感到安慰的说:“妈忘了带,幸好你拿来!”他走到
母亲身边,跪了下来。 “很晚了,妈自己擦可以了,你明天还要上班,回去吧!”

他嗫嚅片刻,终于忍不住啜泣道:“妈,对不起,请原谅我!我们回家去吧!”

~~后语~~

随着自己愈长大,看着父母亲脸庞从年轻变憔悴,头发从乌丝变白发,动作从迅捷变缓
慢,多心疼!父母亲总是将最好、最宝贵的留给我们,像蜡烛不停的燃烧自己,照亮孩
子!而我呢?有没有腾出一个空间给我的父母,或者只是在当我需要停泊岸时,才会想
起他们……

其实父母亲要的真的不多,只是一句随意的问候「爸、妈,你们今天好吗?」随意买的
宵夜,煮一顿再普通不过的晚餐,睡前帮他们盖盖被子,天冷帮他们添衣服、戴手套
….都能让他们高兴温馨很久。有时,我常在想:我希望我的子女以后如何对我。那现
在,我有没有如此对待我的父母?我相信,人是环环相扣的;现在,你如何对待你的父
母;以后,你的子女就如何待你。

朋友,人世间最难报的就是父母恩,愿我们都能:以反哺之心奉敬父母,以感恩之心孝
顺父母!

~共勉之~

生命不要求我们成为最好的,只要求我们作最大的努力!

老人安养院墙上发现的一篇文章

孩子!当你还很小的时候,我花了很多时间,教你慢慢用汤匙、用筷子吃东西。教你系
鞋带、扣扣子、溜滑梯、教你穿衣服、梳头发、拧鼻涕。这些和你在一起的点点滴滴,
是多么的令我怀念不已。所以,当我想不起来,接不上话时,请给我一点时间,等我一
下,让我再想一想……极可能最后连要说什么,我也一并忘记。孩子!你忘记我们练习
了好几百回,才学会的第一首娃娃歌吗?是否还记得每天总要我绞尽脑汁,去回答不知
道你从哪里冒出来的吗?所以,当我重复又重复说着老掉牙的故事,哼着我孩提时代的
儿歌时,体谅我。让我继续沉醉在这些回忆中吧!切望你,也能陪着我闲话家常吧!孩
子,现在我常忘了扣扣子、系鞋带。吃饭时,会弄脏衣服,梳头发时手还会不停的抖,
不要催促我,要对我多一点耐心和温柔,只要有你在一起,就会有很多的温暖涌上心
头。

孩子!如今,我的脚站也站不稳,走也走不动。所以,请你紧紧的握着我的手,陪着
我,慢慢的。就像当年一样,我带着你一步一步地走。

若为人子女也不懂得如何体谅他们,那他们便只能于痛苦中渡过余生,黑暗中逝去……

[今天你孝了没有?]

分类: 转载 标签:

实战:用Carp实现故障转移和负载均衡集群(转)

2010年7月21日 16hot 没有评论

在服务器b上修改大致相同,只是carp网卡的有一点变动
ee /etc/rc.conf       #配置rc.conf文件,分别建立carp虚拟网卡。增加如下内容
cloned_interfaces=”carp0 carp1″
ifconfig_carp0=”vhid 1 advbase 5 advskew 100 pass passwd 192.168.1.100/24″
ifconfig_carp1=”vhid 2 advbase 5 pass passwd 192.168.1.100/24″

ee /etc/sysctl.conf     #修改sysctl文件启用carp的arpbalance和carp抢占功能。增加如下内容
net.inet.carp.preempt=1
net.inet.carp.arpbalance=1

重启两台服务器即 可生效。
如果不想重启服务器,立即生效则进行下列命令
服务器a
ifconfig carp0 create
ifconfig carp0 vhid 1 advbase 5 pass passwd 192.168.0.100/24
ifconfig carp1 create
ifconfig carp1 vhid 2 advbase 5 advskew 100 passwd 192.168.0.100/24
sysctl net.inet.carp.preempt=1
sysctl net.inet.carp.arpbalance=1

服务器b

ifconfig carp0 create
ifconfig carp0 vhid 1 advbase 5 advskew 100 pass passwd 192.168.0.100/24
ifconfig carp1 create
ifconfig carp1 vhid 2 advbase 5 passwd 192.168.0.100/24
sysctl net.inet.carp.preempt=1
sysctl net.inet.carp.arpbalance=1

ok,现在可以看到效果了。如果两台服务器正常,则客户请求分 别由两台服务器均衡的提供服务。当断掉其中一台服务器,则另一台服务器,可立即接管所有服务。当这台服务器恢复服务,则又会自动启用负载均衡。

分类: BSD/linux 标签: ,

FreeBSD 7.0 用ng_fec实现双网卡绑定笔记(转)

2010年7月21日 16hot 没有评论

参考了网友在5.x、6.3下双网卡绑定的文档,于是自己在7.0下做了次实验,结果成功通过。

自己做了些修改,留个笔记。

1. 编译和加载netgraph.ko、ng_fecko、ng_socket.ko模块

a. 编译
#cd /usr/src/sys/modules/netgraph/
#cd netgraph/ && make && make install clean
#cd ../fec && make && make install clean
#cd ../socket && make && make install clean

b. 加载
#cat << EOF >> /boot/loader.conf
ng_ether_load=”YES”
ng_fec_load=”YES”
ng_socket_load=”YES”
EOF

c. 修改rc.conf
#sed -i.bak -e ‘s/^\(defaultrouter\)/#\1/’ -e ‘s/^\(ifconfig_\)/#\1/’ /etc/rc.conf

2. 编辑启动脚本
# cat << EOF > /etc/bonding
#!/bin/sh
MYIP=xxx.xxx.xxx.xxx
GW=xxx.xxx.xxx.xxx
NIC1=bge0
NIC2=bge1

/usr/sbin/ngctl mkpeer fec dummy fec
/usr/sbin/ngctl msg fec0: add_iface ‘”‘\${NIC1}’”‘
/usr/sbin/ngctl msg fec0: add_iface ‘”‘\${NIC2}’”‘
/usr/sbin/ngctl msg fec0: set_mode_inet
/sbin/ifconfig fec0 promisc
/sbin/ifconfig \${NIC1} promisc
/sbin/ifconfig \${NIC2} promisc
/sbin/ifconfig fec0 inet \${MYIP} netmask 0xfffffe00
/sbin/ifconfig fec0 up
/sbin/route add default \${GW}
EOF

# chmod 400 /etc/bonding
# echo “sh /etc/bonding” >> /etc/rc.local

3. 重启系统
# reboot

# ifconfig
bge0: flags=28943 metric 0 mtu 1500
options=9b
ether 00:13:21:c8:54:6b
media: Ethernet autoselect (1000baseTX )
status: active
bge1: flags=28943 metric 0 mtu 1500
options=9b
ether 00:13:21:c8:54:6b
media: Ethernet autoselect (1000baseTX )
status: active
lo0: flags=8049 metric 0 mtu 16384
inet 127.0.0.1 netmask 0xff000000
fec0: flags=28943 metric 0 mtu 1500
ether 00:13:21:c8:54:6b
inet xxx.xxx.xxx.xxx netmask 0xfffffe00 broadcast xxx.xxx.xxx.xxx
media: Ethernet none
status: active

原文: http://www.cublog.cn/u/17709/showart_573233.html

分类: BSD/linux 标签: ,

FreeBSD Netgraph Interface Bonding

2010年7月21日 16hot 没有评论

The following is used on FreeBSD to combine two physical interfaces (fxp1, fxp2) into a single virtual interface (ngeth0). This method allows one to take the feeds from a traditional two-output tap and present a single virtual interface to NSM applications.

#!/bin/sh
kldload ng_ether
ifconfig fxp1 promisc -arp up
ifconfig fxp2 promisc -arp up

ngctl mkpeer . eiface hook ether
ngctl mkpeer ngeth0: one2many lower one
ngctl connect fxp1: ngeth0:lower lower many0
ngctl connect fxp2: ngeth0:lower lower many1

ifconfig ngeth0 -arp up

Remember to replace fxp1 and fxp2 with the interfaces on your FreeBSD system (e.g., em0, em1, etc.).

References

ngctl(8)
I believe I first heard of this technique here.

分类: BSD/linux, 转载 标签: ,

FreeBSD下使用csync2分布同步

2010年7月21日 16hot 没有评论

1、简述

最近因项目需要,找了相关的开源同步解决方案。由于采用FreeBSD系统,有些Linux专用的程序,是不能使用的了。即使可以使用,配置起来太 麻烦,需要Linux虚拟环境。这样代价太高。rsync,mrsync,等都看了遍,最终选择了csync2。

官方网站: http://oss.linbit.com/csync2/

使用手册: http://oss.linbit.com/csync2/paper.pdf

官方发布的正式版是1.34,需要sqlite2的支持。如果想用sqlite3,就需要从他们svn更新最新源码回来。SVN里的版本已经支持 sqlite3了。

使用SVN获取最新源码:

$ svn co  http://svn.linbit.com/csync2/trunk csync2-trunk

由于SVN的源码文件里,没有configure文件,需要自己手工生成。源码目录里有个autogen.sh文件,需要修改下,才能执行。

$ cd csync2-trunk
$ vi autogen.sh

aclocal-1.7
autoheader
automake-1.7 –add-missing –copy
autoconf

改为

aclocal-1.9
autoheader
automake-1.9 –add-missing –copy
autoconf

具体版本号,视里面已经安装的aclocal和automake版本来设置。

然后执行:

$ autogen.sh

执行过程中,会提示一些信息,基本不用管它。这时候生成configure文件了。不过如果现在就执行./configure,还会报4437行错误。将那行注释掉就好了。

#AM_PATH_LIBGNUTLS(1.0.0,0 ,  AC_MSG_ERROR([[gnutls not found; install gnutls, gnutls-openssl and libtasn1 packages for your system or run configure with --disable-gnutls]]) )

2、安装

在安装之前先安装相关的依赖包。下面时我用ports安装csync2-1.34时自动安装上的依赖包:

$pkg_info -r csync2-1.34_8
Information for csync2-1.34_8:

Depends on:
Dependency: pkg-config-0.23_1
Dependency: libtasn1-2.6
Dependency: sqlite-2.8.17_1
Dependency: libiconv-1.13.1_1
Dependency: gettext-0.18_1
Dependency: popt-1.14_1
Dependency: librsync-0.9.7_2
Dependency: libgpg-error-1.7_1
Dependency: libgcrypt-1.4.5
Dependency: gnutls-2.8.6_1

由于SVN版本使用的是sqlite3,所以还需要安装sqlite3-3.6.23.1_1。这些软件包,在/usr/ports 中安装就可以了。

# setenv LOCALBASE /usr/local/
# env CPPFLAGS=”-I${LOCALBASE}/include” LDFLAGS=”-L${LOCALBASE}/lib” LIBGNUTLS_CONFIG=”${LOCALBASE}/bin/pkg-config gnutls” ./configure
# make
# make install

没有什么意外的话,就OK了。如果提示缺什么软件包,到ports里安装。

3、配置

下面是源码包里带的配置文件范例:

% cat csync2.cfg
# Csync2 Example Configuration File
# ———————————
#
# Please read the documentation:
# http://oss.linbit.com/csync2/paper.pdf

# group mygroup
# {
#     host host1 host2 (host3);
#     host host4@host4-eth2;
#
#     key /etc/csync2.key_mygroup;
#
#     #
#     # WARNING:
#     # You CANNOT use paths containing a symlink
#     # component in include/exclude options!
#     #
#     # Here is a real-life example:
#     # Suppose you have some 64bit Linux systems
#     # and /usr/lib/ocf is what you want to keep
#    # in sync. On 64bit Linux systems, /usr/lib
#     # is usually a symlink to /usr/lib64.
#     # This does not work:
#     #   include /usr/lib/ocf;
#     # But this does work:
#     #   include /usr/lib64/ocf;
#     #
#
#     include /etc/apache;
#     include %homedir%/bob;
#     exclude %homedir%/bob/temp;
#     exclude *~ .*;
#
#     action
#     {
#         pattern /etc/apache/httpd.conf;
#         pattern /etc/apache/sites-available/*;
#         exec “/usr/sbin/apache2ctl graceful”;
#         logfile “/var/log/csync2_action.log”;
#         do-local;
#        # you can use do-local-only if the execution
#        # should be done locally only
#        # do-local-only;
#     }
#
#     # The backup-directory needs to be created first!
#     backup-directory /var/backups/csync2;
#     backup-generations 3;
#
#     auto none;
# }
#
# prefix homedir
# {
#     on host[12]: /export/users;
#     on *:        /home;
# }

下面是我的配置:

# vi /usr/local/etc/csync2.cfg

# Csync2 Example Configuration File
# ———————————
#
# Please read the documentation:
# http://oss.linbit.com/csync2/paper.pdf

group mygroup
{
host fb1.isyi.com fb50.isyi.com fb51.isyi.com;

key /opt/etc/isyi.key;
include /opt/www/test;

action
{
pattern /opt/www/test/*;
exec “echo ok >> /tmp/csync2.log”;
}
auto younger;
}

配置好后,还需要修改/etc/hosts文件,将主机名和IP设置好。这个配置,三台服务器都需要配置一样。

192.168.56.1  fb1.isyi.com
192.168.56.50 fb50.isyi.com
192.168.56.51 fb51.isyi.com

生成key文件,这个key文件,需要复制到三台服务器,保证一样,否则不能同步:

# cd /opt/etc/
# csync2 -k isyi.key

生成CERT文件,需要在三台服务器分别生成:

setenv etc_path “/usr/local/etc”
openssl genrsa -out ${etc_path}/csync2_ssl_key.pem 1024
openssl req -batch -new -key ${etc_path}/csync2_ssl_key.pem -out ${etc_path}/csync2_ssl_cert.csr
openssl x509 -req -days 2000 -in ${etc_path}/csync2_ssl_cert.csr -signkey ${etc_path}/csync2_ssl_key.pem -out ${etc_path}/csync2_ssl_cert.pem

4、启动服务

分别在三台服务器执行:

# /usr/local/sbin/csync2 -ii -vv&

5、执行同步

在主服务器,需要向其他服务器同步的服务器执行:

# /usr/local/sbin/csync2 -xvv

6、附录

6.1、csync2的help

% ./csync2

csync2 SNAPSHOT – cluster synchronization tool, 2nd generation
LINBIT Information Technologies GmbH <http://www.linbit.com>
Copyright (C) 2004, 2005  Clifford Wolf <clifford@clifford.at>
This program is free software under the terms of the GNU GPL.

Usage: ./csync2 [-v..] [-C config-name] \
[-D database-dir] [-N hostname] [-p port] ..

With file parameters:
-h [-r] file..      Add (recursive) hints for check to db
-c [-r] file..      Check files and maybe add to dirty db
-u [-d] [-r] file.. Updates files if listed in dirty db
-o [-r] file..      Create list of files in compare-mode
-f [-r] file..      Force this file in sync (resolve conflict)
-m file..       Mark files in database as dirty

Simple mode:
-x [-d] [[-r] file..]   Run checks for all given files and update
remote hosts.

Without file parameters:
-c  Check all hints in db and eventually mark files as dirty
-u [-d] Update (transfer dirty files to peers and mark as clear)

-H  List all pending hints from status db
-L  List all file-entries from status db
-M  List all dirty files from status db

-S myname peername  List file-entries from status db for this
synchronization pair.

-T              Test if everything is in sync with all peers.

-T filename         Test if this file is in sync with all peers.

-T myname peername  Test if this synchronization pair is in sync.

-T myname peer file Test only this file in this sync pair.

-TT As -T, but print the unified diffs.

The modes -H, -L, -M and -S return 2 if the requested db is empty.
The mode -T returns 2 if both hosts are in sync.

-i  Run in inetd server mode.
-ii Run in stand-alone server mode.
-iii    Run in stand-alone server mode (one connect only).

-R  Remove files from database which do not match config entries.

Modifiers:
-r  Recursive operation over subdirectories
-d  Dry-run on all remote update operations

-B  Do not block everything into big SQL transactions. This
slows down csync2 but allows multiple csync2 processes to
access the database at the same time. Use e.g. when slow
lines are used or huge files are transferred.

-A  Open database in asynchronous mode. This will cause data
corruption if the operating system crashes or the computer
loses power.

-I  Init-run. Use with care and read the documentation first!
You usually do not need this option unless you are
initializing groups with really large file lists.

-X  Also add removals to dirty db when doing a -TI run.
-U  Don’t mark all other peers as dirty when doing a -TI run.

-G Group1,Group2,Group3,…
Only use this groups from config-file.

-P peer1,peer1,…
Only update this peers (still mark all as dirty).
Only show files for this peers in -o (compare) mode.

-F  Add new entries to dirty database with force flag set.

-t  Print timestamps to debug output (e.g. for profiling).

-s filename
Print timestamps also to this file.

-W fd   Write a list of directories in which relevant files can be
found to the specified file descriptor (when doing a -c run).
The directory names in this output are zero-terminated.

Creating key file:
./csync2 -k filename

Csync2 will refuse to do anything when a /var/etc/csync2.lock file is found.

分类: BSD/linux 标签: ,