Wednesday, May 13, 2009

freeBSD文档

之前没有注意到. 以为freeBSD的文档会滞后发布版本的.

因为怎么看freeBSD的文档(http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/index.html) 都是长得一样的.

其实细看一下, 至少可以找到一点不同:

Handbook开头第一段正文就有版本信息:
Welcome to FreeBSD! This handbook covers the installation and day to day use of FreeBSD 6.4-RELEASE and FreeBSD 7.2-RELEASE.

这是7.2发布版本的Handbook

旧的版本文档可以从这里得到: http://docs.freebsd.org/doc

freeBSD还有一点做得比gentoo好的, 就是文档和版本一起发布的. 位于/usr/share/doc下.

可能gentoo是没有版本的概念的吧....

使用不同IP去mount NFS空间

NFS服务器是使用IP去区别哪些机器可以mount它export出来的空间的.

现在, 有这样的需要:

1. NFS服务器只export了一个指定的可用的IP, 不方便修改(Boss管的就是烦)

现在需要把此IP迁移到另一台服务器上. 此服务器已经存在一个可用IP

使用这个指定export IP有两种方法:
1. 使用独立的ethernet interface
2. 作为interface的一个别名(alias)

使用上面两种方法绑定IP后, 新的问题:
#mount -t nfs Source:/Path /Target
上面的命令是使用哪个IP的呢?

在不作任何配置前, mount是不会使用新的IP去通信的, 也就是说, mount时会出现:
deny Permission之类的Error

解决方式是修改route表, 强制数据的流向

现服务器默认的route表:

jessinio@pdc:/mnt/Share$ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.20.239.0 * 255.255.254.0 U 0 0 0 eth0
localnet * 255.255.254.0 U 0 0 0 eth0
default 10.20.238.1 0.0.0.0 UG 100 0 0 eth0

增加记录:
$sudo route add -host 192.168.18.38 gw 10.20.238.1 dev eth1

其中, eth1就是指定export IP的网卡
192.168.18.38为NFS服务器

意思是说: 所有到192.168.18.38的数据包, 都使用eth1发送.

这是使用多一个网卡去完成的. 当使用同一个网卡时怎么处理?

# route add -host 192.168.18.38 gw 10.20.238.1 dev eth0:0

如上, 只是dev的参数成为了eth0:0(别名), 如下:


jessinio@pdc:/mnt/Share$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:10:5c:fc:66:42
inet addr:10.20.239.95 Bcast:10.20.239.255 Mask:255.255.254.0
inet6 addr: fe80::210:5cff:fefc:6642/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:18501 errors:0 dropped:0 overruns:0 frame:0
TX packets:13880 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2422289 (2.4 MB) TX bytes:2936218 (2.9 MB)

eth0:0 Link encap:Ethernet HWaddr 00:10:5c:fc:66:42
inet addr:10.20.239.194 Bcast:10.20.239.255 Mask:255.255.254.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

Tuesday, May 12, 2009

网卡硬件情况查看

前几天玩solaris的时候, 也是被网卡的驱动烦着. 奶奶的今天又被windows下的网卡驱动烦!!

今天安装了一台windows server 2003, 竟然网卡没有驱动! 更不可思议的是主板上明显是RTL牌的网卡.

windows还有不支持RTL芯片的网卡的??

想当初玩linux(Redflag)时, 搞不掂网卡安装了张RTL牌的网卡就OK了. windows还没有RTL的驱动. 我日

对比了一下linux与windows的硬件情况查看, 基本是一样的!!

首先. 在系统没有网卡驱动是什么牌时看不出厂商名的(至少windows是这样的).

在这时候, 只能看只两个ID:
1. vendor ID
2. device ID

下面是windows的ID查看方法:

"我的电脑" => 右键查看硬件的信息:



VEN为vendor的缩写, 因此vendor的ID为10EC
DEV为device的缩写, 因此device的ID为8168

其它信息, 如rev等等这里不提了

linux下的信息获取:

jessinio@niolaptop ~ $ sudo lspci -nn|grep net
02:00.0 Ethernet controller [0200]: Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller [10ec:8168] (rev 01)

得到了vendor ID和device ID之后呢??

来这里search一下就知道是哪芯片了:

http://www.pcidatabase.com

solaris和freeBSD下也是类似的, 只是命令程序不同, freeBSD下是pciconf, solaris是prtconf

至于, 为什么网卡是属于PCI总线下的sub-system, 就要了解计算机的体系了.

PC, 或者说是计算机, 内部有了很多子系统的, 子系统其实也可以称了嵌入系统. wikipedia是这样定义BUS的:
In computer architecture, a bus is a subsystem that transfers data between computer components inside a computer or between computers.

这个URL是关于计算机的总线的:
http://en.wikipedia.org/wiki/Computer_bus

下面说到现在的PC机(或者一般的计算机)都是把网卡连接到PCI BUS上的:

Whereas network cards used to be expansion cards that plug into a computer bus, the low cost and ubiquity of the Ethernet standard means that most newer computers have a network interface built into the motherboard. These either have Ethernet capabilities integrated into the motherboard chipset or implemented via a low cost dedicated Ethernet chip, connected through the PCI (or the newer PCI express) bus.


SUN的work station之类的专有硬件本人没有摸, 不说

计算机的hostname

本人喜欢使用: Name-other 这样的命名.

之前, 在使用的linux下, 也出现过hostname不附合命名不合规定而出过问题. 今天, 也是windows下出现了.

在windows下出现还是相当麻烦的. 首先, 系统是使用中文的, google时只能对中文搜索. 其次, windows的出错提示乱来

hostname的命名规定查了一下:

From RFC 952

A "name" (Net, Host, Gateway, or Domain name) is a text string up
to 24 characters drawn from the alphabet (A-Z), digits (0-9), minus
sign (-), and period (.). Note that periods are only allowed when
they serve to delimit components of "domain style names".

No blank or space characters are permitted as part of a
name. No distinction is made between upper and lower case. The first
character must be an alpha character [Relaxed in RFC 1123] . The last
character must not be a minus sign or period.

From RFC 1035

labels 63 octets or less
names 255 octets or less

[snip] limit the label to 63 octets or less.

To simplify implementations, the total length of a domain name (i.e.,
label octets and label length octets) is restricted to 255 octets or
less.


From RFC 1123

One aspect of host name syntax is hereby changed: the
restriction on the first character is relaxed to allow either a
letter or a digit. Host software MUST support this more liberal
syntax.

Host software MUST handle host names of up to 63 characters and
SHOULD handle host names of up to 255 characters.

发现: Name-Other这种文件没有违反命名规定, 但是在一些软件中使用就会有不同的反映.


为了出现这样后果很难处理(至少要reboot机器), 排查也有难度. 应该注意hostname的命名方法.


只使用letter和digit是最安全的.

Monday, May 11, 2009

gentoo下安装virtualbox

好久没有玩过virtualbox了, 今天想安装一个玩玩, 本人老久前还有保留了一份VDI文件, 希望本次可以继续使用.

本次安装版本: 2.2( virtualbox的更新速度太快了 )

安装好软件后, 就是利用上次得到保留的VDI文件. 其实一直都不明白什么叫VDI. 网上查了一把, 应该与Virtual desktop infrastructure (VDI) 同名不同义(http://en.wikipedia.org/wiki/Virtual_Desktop_Infrastructure)

我想它的意思应该是: virtual disk image
在下面的URL中, 我看到了virtual disk image三个单词 (^_^)
* http://forums.virtualbox.org/viewtopic.php?p=29276#29276

使用virtual disk image文件:
菜单操作:
* File -> "virtual media manager" -> Add
把指定的vdi文件加入去就OK了.

这一步骤等同于: 为电脑增加一个硬盘(当然, 这个硬盘已经早就安装好了操作系统的)

然后, 增加machine:
菜单操作:
* Machine -> New -> Next -> 选择正确的OS类型和内存等等参数 -> Use existing hard disk

这一步骤等同于: 让系统(Machine)使用指定的VDI文件为master disk

但是start Machine的时候, 出错了:

Kernel driver not installed (rc=-1908)

The VirtualBox Linux kernel driver (vboxdrv) is either not loaded or there is a permission problem with /dev/vboxdrv. Re-setup the kernel module by executing

'/etc/init.d/vboxdrv setup

as root. Users of Ubuntu, Fedora or Mandriva should install the DKMS package first. This package keeps track of Linux kernel changes and recompiles the vboxdrv kernel module if necessary.

本人记得在ubuntu下, 运行上面的那句话就100% OK的, 那么在gentoo下怎么处理呢?


使用下面的方法:
# modprobe vboxdrv

Sunday, May 10, 2009

blogspot的文章发布日期调整

本人的blog中有一堆是draft的文章. 这都是需要Scheduled的. 说白了就是修改文章的发布日期.

blogspot的每篇文章, 有一"post options"的.

options中就有一项是: "post date and time", 这里就是文章的发布日期

之前使用过, 只是不理解. blogspot中, 每次Schedule文章并不是马上起作用的! 是需要一定的时间才能表示出来.

如下面调整文章的发布日期后出现:

Your post will be automatically published on 5/11/09 at 4:16 AM.

blogspot系统中有一个最小schedule时间. 如:
Scheduled outage at 2:00AM PDT on Monday (5/11). (这个时间位于导航栏上)

只能你设置的日期超来这个最小时间, 那么, 就会在指定的时间出现.

freeBSD与gentoo内核源代码的得到

freeBSD与gentoo这两个系统的包管理有相似的处理方式.

常常更新内核, 这就首先要得到内核的源代码, 如下:

1. freeBSD下:

# cp /usr/share/examples/cvsup/standard-supfile /root/
修改此文件内的host参数, 然后:
# cvsup /root/standard-supfile
最新的内核的代码就会在/usr/src下

2. gentoo下:
# emerge gentoo-sources
照样, 在/usr/src下有最新的内核代码.

Saturday, May 9, 2009

系统时间也引发软件安装出错

今天在freeBSD下安装软件时, 报了一个错:
# make install
===> Vulnerability check disabled, database not found
===> Extracting for libtool-1.5.26
=> MD5 Checksum OK for libtool-1.5.26.tar.gz.
=> SHA256 Checksum OK for libtool-1.5.26.tar.gz.
===> Patching for libtool-1.5.26
===> Applying FreeBSD patches for libtool-1.5.26
===> Configuring for libtool-1.5.26
checking for a BSD-compatible install... /usr/bin/install -c -o root -g wheel
checking whether build environment is sane... configure: error: newly created file is older than distributed files!
Check your system clock
===> Script "configure" failed unexpectedly.
Please report the problem to ade@FreeBSD.org [maintainer] and attach the
"/usr/ports/devel/libtool15/work/libtool-1.5.26/config.log" including the
output of the failure of your make command. Also, it might be a good idea to
provide an overview of all packages installed on your system (e.g. an `ls
/var/db/pkg`).
*** Error code 1

Stop in /usr/ports/devel/libtool15.


主要的ERROR信息为:
error: newly created file is older than distributed files!
Check your system clock

调整时间:
ntpdate 202.130.120.114

结果就OK了.


freeBSD在安装软件时还测试文件的create time的?

Thursday, May 7, 2009

SA至少需要是半个network administrator

今天深深地感受到不懂网络的SA当网络问题到来时, 是多么的无助与无力.

只关心着自己的机器, 只会处于被动状态. 就算向信息部反映, 求助也只是浪费大部份时间.

自己应该有整套技术基础.

网络技术的学习迫在眉急, 需要提升到routine中.

同事建议我应该去考个网络技术认证. 想了想, 的确比Linux的认证来得实在, 可以考虑

是ibus输入法还是dbus的问题?

使用ibus有几十天了. 在gentoo下很方便配置. 共体算满意.

但还是有了bug(其实不清楚是ibus的问题还是dbus的问题): 当电脑使用时间比较长时(我的电脑一般都是suspend的), ibus就没法被调用. 甚至使调用它的X窗件程序都无响应.

平时比较忙, 碰到这个问题时, 一般是kill了Xorg-server的. 今天受不了, 就跑到console下(X下使用ibus的程序都会freeze):
# /etc/init.d/dbus restart

呃......重启dbus就好了. 所以, 不清楚是ibus的问题还是dbus的问题.

dbus脚本使用了dbus-daemon程序. 本想查一下dbus-daemon的日志的. 结果没有找到.

看到了start-stop-daemon命令的一个小技巧, 命令行如下:
start-stop-daemon --start --pidfile /var/run/dbus.pid --exec /usr/bin/dbus-daemon -- --system

其中, 我关注"--"参数的用法, 解释如下:
With --start, start-stop-daemon checks for the existence of a specified
process. If such a process exists, start-stop-daemon does nothing, and
exits with error status 1 (0 if --oknodo is specified). If such a
process does not exist, it starts an instance, using either the exe‐
cutable specified by --exec, (or, if specified, by --startas). Any
arguments given after -- on the command line are passed unmodified to
the program being started. If --retry is specified then start-stop-
daemon will check that the process(es) have terminated.

意思是""--""后面的全部东西在不处理的情况下传递给要调用的程序

Tuesday, May 5, 2009

mp3的id3

什么是id3?
ID3 is a metadata container most often used in conjunction with the MP3 audio file format,It allows information such as the title, artist, album, track number, or other information about the file to be stored in the file itself.

上面是wikipedia的解释. 说白了就是mp3的描述信息段.

到目前, 有三个版本:
1. id3v1
2. id3v1.1
3. id3v2(到现在有三个版, 2.2, 2.3(广泛使用的版本)和2.4

id3v2是国际化, 可扩展的解决方案. 有部分与id3v1不兼容(it has little to no relation to the ID3v1 standard).

id3的位置, 在v1版本中, id3信息段是放在文件的最后的(The tag was placed at the end of the file to maintain compatibility with older media players.)
到了v2版本, id3信息段是放在前最前面的(ID3v2 tags are of variable size, and usually occur at the start of the file, to aid streaming media.)

网上流传的一段gbk转uft-8编码是这样做的:
def has_id3v1(filename):
f = open(filename, 'rb+')
try: f.seek(-128, 2)
except IOError: pass
else: return (f.read(3) == "TAG")


这应该是不考虑v1.1Enhanced tag的(v1.1是非官方的, 并且: is only supported by few programs, not including XMMS or Winamp)


id3v1是固定长度方式的, 到了idv2后, 是可以自定义的. 结构会复杂很多, 如下:


http://ample.sourceforge.net/developers.shtml
没事做, 自己写的读取id3信息的脚本:
#coding:utf-8
import os,sys
import array

song = open("/home/jessinio/jessinio/music/信乐队/死了都要爱.mp3")
header = song.read()
print "Header ID: " + header[:0x03]
print "Version: " + repr(header[0x03:0x05])
print "Flags: " + repr(header[0x05])
total_length = array.array("L")
total_length.fromstring(header[0x06:0x0a])
total_length.byteswap()
print "Size: " + str( total_length[0] )
song.seek(0,0)
header = song.read(total_length[0])
print header

def get_id(header, frame_header_id_s = 0x0a):
# init : 0x0a
# frame_header_id_s = 0x0a
frame_header_id_e = frame_header_id_s + 3
print "Frame Header ID: " + header[frame_header_id_s:frame_header_id_e + 1]

size_s = frame_header_id_e + 1
size_e = size_s + 3
length = array.array("L")
length.fromstring(header[size_s:size_e + 1])
length.byteswap()
print "Size: " + str(length[0])

frame_flags_s = size_e + 1
frame_flags_e = frame_flags_s + 1
print "Frame Flags: " + repr(header[frame_flags_s:frame_flags_e + 1])
frame_context_s = frame_flags_e + 1
print "Frame Context: prefix:%s, surfix:%s " % (repr(header[frame_context_s]), header[frame_context_s + 1:frame_context_s + length[0]].decode("gbk").encode("utf8"))
next = frame_context_s + length[0]
print "####: " + str( next )
return next

next_point = 0x0a
for i in range(15):
start_point = next_point
next_point = get_id(header, start_point)


上面上堆工夫做的事就是:
import mutagen
metadata = mutagen.id3.ID3("/home/jessinio/jessinio/music/信乐队/死了都要爱.mp3")

Monday, May 4, 2009

乱码的E文叫什么?

一直都不知道应该怎么翻"乱码"成E文关键字.

使用: encoding problem ?

今天在看id3的故事时(http://en.wikipedia.org/wiki/ID3), 无意看到一个词: http://en.wikipedia.org/wiki/Mojibake
wikipedia中这样描述:
Mojibake
(文字化け ?, pronounced /mod͜ʑibake/) is the happenstance of incorrect, unreadable characters shown when computer software fails to render a text correctly according to its associated character encoding.

看上去像是日本词的发音翻译.

不过, 使用google去搜索这个关键字时, 也不是很多结果.

Sunday, May 3, 2009

gentoo下使用mplayer乱码

使用电脑就奶奶的烦心的就是:
* 想不折腾时它不让你傻傻用, 偏偏是问题!

奶奶的, 今晚我真的是被气死了.

老久没有看过影片了, 今天突然很想看一部<<最终幻想VII>>, 可是mplayer这个鸟东西偏偏是不能显示字幕!

我没有编译这个功能? 我是看着USE在发呆呀:

[ebuild R ] media-video/mplayer-1.0_rc2_p28450 USE="X a52 aac alsa ass doc dts dv dvd encode gif gtk iconv ipv6 jpeg live mad md5sum mmx mp2 mp3 opengl oss png quicktime theora truetype unicode vorbis x264 xscreensaver xv xvid -3dnow -3dnowext -aalib (-altivec) -amrnb -amrwb -arts -bidi -bindist -bl -cddb -cdio -cdparanoia -cpudetection -custom-cflags -custom-cpuopts -debug -dga -dirac -directfb -dvb (-dvdnav) -dxr3 -enca -esd -fbcon -ftp -ggi -jack -joystick -ladspa -libcaca -lirc -lzo -mmxext -mng -musepack -nas -nemesi -openal -pnm -pulseaudio -pvr -radio -rar (-real) -rtc -samba -schroedinger -sdl -speex -sse -sse2 -ssse3 -svga -teletext -tga -v4l -v4l2 -vidix -win32codecs -xanim -xinerama -xvmc -zoran" VIDEO_CARDS="-mga -s3virge -tdfx -vesa" 0 kB


明明就有truetype和unicode嘛!! 为什么不行?

气得最后我连mplayer的GUI界面(gnome-mplayer)都安装了, 搞了通还是不行!

看影片的心情一点一点的被磨掉!!!!

没有办法了, 只能对自己说: 我就算不看影片, 奶奶的我也要把你搞好.

气火火的去看man手册. 不断地search着subtitle, 目光在"-ass (FreeType only)"中停顿下来. mplayer的truetype不起作用? 试了一下使用freetype, 呃.....有字幕了!


下面总结一下mplayer使用中文字幕的方法:
未知配置: mplayer的truetype和unicode编译参数的作用是未知, 本人的mplayer是有这两个参数的.

1. ~/.mplayer/config需要两个配置:
font=/home/jessinio/.mplayer/wqy-zenhei.ttc
subcp=cp936

font为字体文件的路径
subcp为字体的编码(不知道为什么使用utf8就不行, 目前只能使用cp936)

2. 使用-ass参数启动mplayer

又是 23:45, 看个屁影片呀!

Friday, May 1, 2009

问题的出现比问题的解决来得快, 多

写blog, 其实我没有区分过重要到达什么程度才写下来. 我只是觉得解决的过程是有意义的我都会写下来. 但是这会出现几个问题:
1. 问题的描述需要较多的时间
主要是要为问题找合理的解决方法并且需要证据, 就算自己的结果是错的, 也至少花了时间和精力去努力过, 找求证是需要较多的时间. 不是google找到几行命令就满意的


2. 生活中碰到的且满足写下来的条件的问题会越来越多.
因为习惯了一种对待问题的方法, 所以....见到有意义的问题老是想写下来的. 这样就慢慢发现, 生活中出现的问题越来越多....其实也不是问题多, 问题每天都是那么多的, 只是习惯了一种方式, 老是会这样做. 导至blog中的draft文件越来越多. 现在blog有第二个功能了: 就是做自己的schedule

其实有很多有意义的, 好玩的都想好好的写下来, 但是"人在江湖, 人不由己", 没有过多的时间去处理.

为什么读书时期没有去试着处理呢?

ctrl-s引发的问题

在使用terminal时, 有时会不小心按到ctr-s, 这时....呃..... freeze了!!

怎么解开?

google了一下, 发现解开的方法: ctrl-q

然后想了想: 这样下去不是个办法呀. ctrl-s为什么要被搞成这种没有意义的用途呢(至少我还没有想到)

ctrl-s能不能被map到其它作用?
刚开始, 猜是terminal软件的问题, 但是测试了一下, urxvt和terminal(xfce下默认安装的一个软件)都对ctrl-s起作用. 好像自己的是想法是不对的.

找着找着, 跑入了linux的历史......

什么是tty?
The name of the program comes from teletypewriter, abbreviated "TTY".
* http://en.wikipedia.org/wiki/Teleprinter
就是输入与输出的设备. tty的man手册中写到:
tty - print the file name of the terminal connected to standard input
* 为什么没有说standard output的呢?
命令运行的结果:
jessinio@nio-laptop ~ $ tty
/dev/pts/9

什么是终端?
终端其实应该叫terminal emulate
* http://en.wikipedia.org/wiki/Terminal_emulator

tty是设备(就算pts也是模拟的), terminal amulator算是使用tty的一个软件, terminal amulator是用户与tty设备的纽带.

现在知道用户的会被两次处理:
1. 被terminal emulator处理.
1. 被tty处理.

之前猜测是terminal emulator的处理, 其实是tty的处理.

tty的设置有专用的命令, 如下:

stty - change and print terminal line settings

现有的设置:
jessinio@nio-laptop ~ $ stty -a|less
speed 38400 baud; rows 32; columns 116; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = ;
eol2 = ; swtch = ; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk brkint ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
-iuclc -ixany imaxbel iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab3 bs0 vt0 ff0
isig -icanon iexten -echo -echoe -echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke

去掉ctrl-s的作用:

非常激动的发现了新的作用, 如下:
jessinio@nio-laptop ~ $ stty stop ^-
(i-search)`':

出现了向前搜索!!我之前一直认为bash是没有这个功能的(不想使用arrow键)

把这命令行加到~/.bashrc下即可!(当然, terminal emulator需要是login shell)