2009年6月25日星期四

ubuntu 网卡安装

机器类型 hp u6012cn, ubuntu9.04自带的r8169 网卡驱动太新,跑不起来.
1. 找到主板型号945GCT-HM
2. 通过1 找到网卡型号 板载网卡 集成 10/100 Mps Realtek RTL8101E 网卡
3. 到 realtek 官网http://152.104.125.41/ 搜索得到对应的驱动下载页
4. uname -a linux kernel 2.6.28.11-generic
5. 找到对应的linux 驱动
6. 通过驱动自带redme 进行安装
7. 搞定 可乐一杯

2009年6月13日星期六

emacs cedet+ecb+cscope+gdb-ui

http://www.360doc.com/content/080321/14/7821_1133699.html
cedet: collection of emacs development environment tools
ecb : Emacs Code Browser

配上 php python 调试, 便于开发

http://www.linuxjournal.com/article/7876 emacs+gdb

---------------------
http://downloads.sourceforge.net/mingw/gdb-6.8-mingw-3.tar.bz2?modtime=1208982015&big_mirror=1

解压里面的bin/gdb.exe放到mingw/bin里面,然后就可以用了。

这个是mingw的下载主页,上面的链接就是在这个里面的。
http://sourceforge.net/project/showfiles.php?group_id=2435

2009年6月9日星期二

Repository moved permanently to xxxx please relocate

可以在http://subversion.tigris.org/faq.html#301-error 找到答案

之前的配置为



DAV svn
SVNParentPath /data/svn/

AuthType Basic
AuthName "Authorization Realm"
AuthUserFile /etc/svnpwdfile
Require valid-user
# SVNListParentPath on

DocumentRoot /data/svn/
ServerName svn.example.cn


貌似正确,可在浏览器里正常 svn checkout时的时候就报Repository moved permanently to xxxx please relocate 错误

原因在faq里明显 就是apache 迷惑了, 可是不设DocumentRoot 就会报错. 解决办法也简单乱设一个有效的路径.... 妈的 居然这样就过了

mysql create database指定字符集

解决乱码,很基础的问题. 但如果不留意会犯
create database redmine character set utf8;

2009年6月8日星期一

批量svn lock

目的:想要svn批量lock一些文件
1.第一次实现
用php实现,原理是应用svn list ,根据传进来的地址进行递归. 将文件lock/unlock
缺点: 不够灵活,每次都要改代码
2.第二次实现
在之前的基础上加入 enable disable filter 参数
优点:相对方便,不用每次都改代码
缺点:无法满足特殊需求, 还是无法避免动代码
3.第三次实现
php脚本只用来通过svn遍历指定目录下的所有文件, 其他的依靠命令来处理就好了
例如:php listsvn.php file:///data/svn/shop/working/b2b1.2/ | grep -e "/ctl\..*\.php" -i | xargs -I % svn unlock %
优点: 足够灵活,足够强大
缺点: 呵呵 每行命令有点长,
总结: 优点远大于缺点

http协议状态码

服务器返回给客户端的状态码。这个信息非常有价值,因为它指示了请求的结果,或者是被成功响应了(以2开头),或者被重定向了(以3开头),或者出错了(以4开头),或者产生了服务器端错误(以5开头)。完整的状态码列表参见HTTP规范(RFC2616第10章)。

http://www.w3.org/Protocols/rfc2616/rfc2616.txt

解决vista系统部分CHM打不开,“无法正常显示”的问题

转:http://www.cnblogs.com/lqb/archive/2009/01/24/1380639.html
解决vista系统部分CHM打不开,“无法正常显示”的问题
症状:显示左侧目录树,右侧内容提示为“无法显示网页”。
原因:Microsoft系统安全性升级导致。
解法:属性页->解除锁定即可。
不只vista有这个问题,只要是NTFS分区都有这个问题

apache+fcgid+redmine安装心得

freebsd 70 apache22 fcgid redmine

如果是还未安装配置,请先看文尾处的参考资料 进行配置.勿阅读本文 免得造成疑惑

安装过程 一波三折,断断续续花了一周时间
1.装fastcgi
2.redmine 安装
首先是在安装ruby上折腾颇多
如果是在freebsd下ruby的包尽量用,可以省力不少.通过 pkg_info | grep ruby 时刻关注所装的包,因为ruby的包之间互为依存. 一定要留意.在调试中出现问题 google 找到原因,大多情况是因为缺包或者包版本不对造成的

关键节点
Test the installation by running WEBrick web server:
ruby script/server webrick -e production
Once WEBrick has started, point your browser to http://localhost:3000/.
You should now see the application welcome page.
如果测试通过表示基本安装已经完成,

3. 整合apache
这时我犯了个致命错误导致文件,用apache fastcgid 模式可以跑起来但是 css js 全部无法加载
解决:
1. 首先还是同过 . redmine/dispatch.fcgi 来测试包是否有问题. 包依赖我是通过这种方式解决掉的, 可当此步骤通过后 依然无法加载css js
2. 排除了ruby的问题,当然怀疑到 httpd.conf 配置问题, 查看/var/log/httpd-error.log经过反复排查 无误, 告失败
3. 这时候想到了.htaccess 的问题,找到 redmine/public/.htaccess 进行调试 不得要领
4. 有些抓狂, 再找到redmine/log/production.log
看到错误
ActionController::RoutingError (No route matches "/stylesheets/jstoolbar.css"
google之 无果,但是想到了 .htaccess 是通过rewrite 将访问转到 dispatch.fcgi上的想到问题应该是出在了rewrite上
打开rewrite log
RewriteLog "/var/log/rewrite.log"
RewriteLogLevel 3

5. 查看结果 rewriteCond %{REQUEST_FILENAME} !-f 失效 js css都通过 dispatch.fcgi 在解析,这当然找不到
可为什么会出现这个问题?依然是个问号 继续google之. 没有答案 为了调试,我把.htaccess 进行了删减 来排查问题
之前的疑问全部浮出水面

RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]


RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]


RewriteRule ^(.*)$ dispatch.cgi [QSA,L]

当我把 mod_fastcgi.c IfModule mod_cgi.c 两段去掉时.一切正常了. 头绪来了 mod_fastcgi mod_fcgid mod_cgi 其中至少跑了两个. 那么问题出在我在配置fcgid 的时候没有将mod_cgi 去掉所导致的问题. 我靠.
把 LoadModule cgi_module libexec/apache22/mod_cgi.so 注释掉,干掉 .htaccess 重新 svn update 重启apache 一切ok!

6.总结
当出现问题时 一定要查看log(各种log 服务的 软件的),通过log问题一块块排查 不能慌乱. 注意思考 依靠网络 但不依赖网络

参考:
1.安装fastcgid
http://www.cyberciti.biz/faq/freebsd-apache22-fastcgi-php-configuration/
(如安此文章出现问题请查看我的另一篇文章 http://leafghost.blogspot.com/2009/06/apache2fastcgi.html )
2.redmine 安装
http://www.redmine.org/wiki/redmine/RedmineInstall
3.整合 apache
http://www.redmine.org/wiki/1/HowTo_configure_Apache_to_run_Redmine

2009年6月1日星期一

apache2配置fastcgi

参考:http://www.cyberciti.biz/faq/freebsd-apache22-fastcgi-php-configuration/

遇到一个问题
[notice] mod_fcgid: process /usr/local/www/phpPgAdmin/images/themes/default/title.png(2905) exit(communication error), terminated by calling exit(), return code: 255
除了php都无法加载
解决办法, 把 SetHandler fcgid-script 注释掉 换上 AddHandler fcgid-script .php就成了

疑问:
1.FCGIWrapper /usr/local/bin/php-cgi .php 是做什么的
2.[notice] mod_fcgid: call /data/www/shop/shopadmin/index.php with wrapper /usr/local/bin/php-cgi 怎么解决?

没测过, 但是直观感觉是网站快了.. 呵呵

unix jobs

假设你发现前台运行的一个程序需要很长的时间,但是需要干其他的事情,你就可以用 Ctrl-Z ,终止这个程序,然后可以看到系统提示:
[1]+ Stopped /root/bin/rsync.sh
然后我们可以把程序调度到后台执行:(bg 后面的数字为作业号)
#bg 1
[1]+ /root/bin/rsync.sh &
用 jobs 命令查看正在运行的任务:
#jobs
[1]+ Running /root/bin/rsync.sh &
如果想把它调回到前台运行,可以用
#fg 1
/root/bin/rsync.sh
这样,你在控制台上就只能等待这个任务完成了。

& 将指令丢到后台中去执行
[ctrl]+z 將前台任务丟到后台中暂停
jobs 查看后台的工作状态
fg %jobnumber 将后台的任务拿到前台来处理
bg %jobnumber 将任务放到后台中去处理
kill 管理后台的任务

chrome about:

转:http://www.chromefans.org/chrome-tutorial/full-list-of-google-chrome-abount-command.htm
Like most other browsers, Google Chrome can be fine-tuned by typing "about:command" to show information about version number, memory usage, cached files, plug-ins and more details. Here's the full list:

1. about:cache - A list of all the web pages cached by Google Chrome
2. about:dns - Prefetching DNS records produced benefits
3. about:histograms - A list of histograms for Google Chrome's internal metrics
4. about:internets - Google Chrome's humorous Easter egg
5. about:memory - Measuring memory usage in a multi-process browser
6. about:network - Used for I/O tracking
7. about:plugins - The list of plug-ins that are available in Google Chrome
8. about:stats - A list of internal counters and timers
9. about:version - Shows the version number the browser, WebKit and JavaScript V8 engine
10. view-cache:[URL] - Shows you some under-the-hood cache details
11. view-source:[URL] - Shows the source code.

ports更新方式(cvsup portsnap)

1. cvsup -L 2 /root/ports-supfile
cp /usr/share/examples/cvsup/ports-supfile /root/
修改 ports-supfile 依据位置使用 cvsup1 ~ cvsup13.tw.freebsd.org服务器
也可通过 -h 来指定更新服务器

ports-supfile文件中ports-all 表示我们要更新 /usr/ports 目录下的所有档案。您也可以只更新其中的部份目录,只要将 ports-all 以井字号 "#" 标示起来,并将档案中 ports-base 那一行的 # 移除,接着您就可以依您所要更新的目录来要移除其它的 # 字号。例如,我们只要更新 /usr/ports/www 这个目录,将 ports-all 以 # 标示起来之后,我们还要移除 ports-base 及 ports-www 开头的 #。

2. portsnap fetch update
Portsnap 是一套用以安全地分发 FreeBSD 的系统。 每隔大约一个小时, 就会生成一份 ports 的最新 “快照”, 它会被打包并进行数字签名。 这些文件接下来将通过 HTTP 来分发。

下载压缩的 Ports 套件快照到 /var/db/portsnap。您可以根据需要在这之后关闭 Internet 连接。
# portsnap fetch
假如您是首次运行 Portsnap, 则需要将快照释放到 /usr/ports:
# portsnap extract
如果您已经有装好的 /usr/ports 而您只想更新,则应执行下面的命令:
# portsnap update

因为是下载压缩包,所以速度要比cvs 一个个拉要快很多,
————————————————————-----------------

使用方法:
/etc/portsnap.conf 里面更改
SERVERNAME=portsnap.hshh.org
portsnap简介:
portsnap从freebsd6.0开始引进系统,给与用户方便的更新系统ports
portsnap的命令比较少
fetch 获取数据
extract 释放全部ports
update 更新ports
第一次使用可以 portsnap fetch extract
以后使用可以 portsnap fetch update
如果写在cron可以用 portsnap cron update

3.总结
如果很急只想更新部分ports 可以用cvsup.如果想一劳永逸还是portsnap 更舒适
http://www.twbsd.org/chs/book/index.php?ch=10

参考:http://freebsd.chinaunix.net/doc/2007/01/17/1123592.shtml

大量小文件的实时同步方案

转:http://blog.daviesliu.net/2008/04/24/sync/

大量小文件的实时同步方案

davies 发表于 2008 年 04 月 24 日

传统的文件同步方案有rsync(单向) 和 unison(双向)等,它们需要扫描所有文件后进行比对,差量传输。如果文件数量达到了百万甚至千万量级,扫描所有文件将非常耗时。而且正在发生变化的往往是其中很少的一部分,这是非常低效的方式。

之前看了Amazon的Dynamo的设计文档,它们每个节点的数据是通过Hash Tree来实现同步,既有通过日志来同步的软实时特点(msyql, bdb等),也可以保证最终数据的一致性(rsync, unison等)。Hash Tree的大体思路是将所有数据存储成树状结构,每个节点的Hash是其所有子节点的Hash的Hash,叶子节点的Hash是其内容的Hash。这样一旦某个节点发生变化,其Hash的变化会迅速传播到根节点。需要同步的系统只需要不断查询跟节点的hash,一旦有变化,顺着树状结构就能够在logN级别的时间找到发生变化的内容,马上同步。

文件系统天然的是树状结构,尽管不是平衡的数。如果文件的修改时间是可靠的,可以表征文件的变化,那就可以用它作为文件的Hash值。另一方面,文件的修改通常是按顺序执行的,后修改的文件比早修改的文件具有更大的修改时间,这样就可以把一个目录内的最大修改时间作为它的修改时间,以实现Hash Tree。这样,一旦某个文件被修改,修改时间的信息就会迅速传播到根目录。

一般的文件系统都不是这样做的,目录的修改时间表示的是目录结构最后发生变化的时间,不包括子目录,否则会不堪重负。因为我们需要自己实现这个功能,利用Linux 2.6内核的新特性inotify获得某个目录内文件发生变化的信息,并把其修改时间传播到它的上级目录(以及再上级目录)。Python 有 pyinotify,watch.py的代码如下:

  1. #!/usr/bin/python
  2. from pyinotify import *
  3. import os, os.path
  4. flags = IN_CLOSE_WRITE|IN_CREATE|IN_Q_OVERFLOW
  5. dirs = {}
  6. base = '/log/lighttpd/cache/images/icon/u241'
  7. base = 'tmp'
  8. class UpdateParentDir(ProcessEvent):
  9. def process_IN_CLOSE_WRITE(self, event):
  10. print 'modify', event.pathname
  11. mtime = os.path.getmtime(event.pathname)
  12. p = event.path
  13. while p.startswith(base):
  14. m = os.path.getmtime(p)
  15. if m <>
  16. print 'update', p
  17. os.utime(p, (mtime,mtime))
  18. elif m > mtime:
  19. mtime = m
  20. p = os.path.dirname(p)
  21. process_IN_MODIFY = process_IN_CLOSE_WRITE
  22. def process_IN_Q_OVERFLOW(self, event):
  23. print 'over flow'
  24. max_queued_events.value *= 2
  25. def process_default(self, event):
  26. pass
  27. wm = WatchManager()
  28. notifier = Notifier(wm, UpdateParentDir())
  29. dirs.update(wm.add_watch(base, flags, rec=True, auto_add=True))
  30. notifier.loop()

在已经有Hash Tree的时候,同步就比较简单了,不停地获取根目录的修改时间并顺着目录结构往下找即可。需要注意的是,在更新完文件后,需要设置修改时间为原文件的修改时间,目录也是,保证Hash Tree的一致性,否则没法同步。mirror.py的代码如下

  1. #!/usr/bin/python
  2. import sys,time,re,urllib
  3. import os,os.path
  4. from os.path import exists, isdir, getmtime
  5. src = sys.argv[1]
  6. dst = sys.argv[2]
  7. def local_mirror(src, dst):
  8. if exists(dst) and mtime == getmtime(dst):
  9. return
  10. if not isdir(src):
  11. print 'update:', dst
  12. open(dst,'wb').write(open(src).read())
  13. else:
  14. if not exists(dst):
  15. os.makedirs(dst)
  16. for filename in os.listdir(src):
  17. local_mirror(os.path.join(src,filename), os.path.join(dst,filename))
  18. os.utime(dst, (mtime,mtime))
  19. def get_info(path):
  20. f = urllib.urlopen(path)
  21. mtime = f.headers.get('Last-Modified')
  22. if mtime:
  23. mtime = time.mktime(time.strptime(mtime, '%a, %d %b %Y %H:%M:%S %Z'))
  24. content = f.read()
  25. f.close()
  26. return int(mtime), content
  27. p = re.compile(r'([\d.]+?) +([\w/]+)')
  28. def remote_mirror(src, dst):
  29. mtime, content = get_info(src)
  30. if exists(dst) and mtime == int(getmtime(dst)):
  31. return
  32. print 'update:', dst, src
  33. if not src.endswith('/'):
  34. open(dst,'wb').write(content)
  35. else:
  36. if not exists(dst):
  37. os.makedirs(dst)
  38. for mt,filename in p.findall(content):
  39. mt = int(float(mt))
  40. lpath = dst+filename
  41. if not exists(lpath) or int(getmtime(lpath)) != mt:
  42. remote_mirror(src+filename, lpath)
  43. os.utime(dst, (mtime,mtime))
  44. if src.startswith('http://'):
  45. mirror = remote_mirror
  46. else:
  47. mirror = local_mirror
  48. while True:
  49. mirror(src, dst)
  50. time.sleep(1)

如果源文件不在同一台机器上,可以通过NFS等共享过来。或者可以通过支持列目录的HTTP服务器来访问远程目录,mirror.py 已经支持这种访问方式。server.py 是用webpy做的一个简单的只是列目录的文件服务器。由于瓶颈在IO上,它的性能不是关键。server.py的代码如下:

  1. #!/usr/bin/python
  2. import os,os.path
  3. import web
  4. import time
  5. root = 'tmp'
  6. HTTP_HEADER_TIME = '%a, %d %b %Y %H:%M:%S %Z'
  7. class FileServer:
  8. def GET(self, path):
  9. path = root + path
  10. if not os.path.exists(path):
  11. return 404
  12. mtime = time.localtime(os.path.getmtime(path))
  13. web.header('Last-Modified', time.strftime(HTTP_HEADER_TIME, mtime))
  14. if os.path.isdir(path):
  15. for file in os.listdir(path):
  16. if file.startswith('.'): continue
  17. p = os.path.join(path,file)
  18. m = os.path.getmtime(p)
  19. if os.path.isdir(p):
  20. file += '/'
  21. print m, file
  22. else:
  23. print open(path,'rb').read()
  24. urls = (
  25. "(/.*)", "FileServer",
  26. )
  27. if __name__ == '__main__':
  28. web.run(urls, globals())

为了获得更好性能,以达到更好的实时性,Hash Tree最好是平衡的,比如BTree。如果一个文件发生变化,同步它需要进行的IO操作为N*M,其中N为数的层数,M为每层的文件数目。现在我们N为2,M最大为10000,适当减少它可以获得更好的性能,比如N为4,M为100。在以后创建目录结构时,最好能够考虑这方面的因素。

之前hongqn推荐过一个利用inotify的文件同步方案,同步方式类似于mysql和bdb等,由于过于复杂导致不可靠而没有采用。上面这个方案只用了一百多行Python代码就基本解决问题了,是不是很帅?:-)