2011年10月20日星期四

Linux 字体的一些概念

google + baidu 得到的结果,不保证准确。

字体有矢量字体和位图字体两种类型。矢量字体中的字形由数学曲线描述,这种字体由于需要计算,因此显示速度慢,但是该字体可以任意缩放,主要包括Truetype,Type1,OpenType等;位图字体又叫点阵字体,字形由点组成,显示速度快,但是缩放后会有锯齿。显示字形时要将矢量字体转换为位图字体,这个过程称为光栅化。

FreeType 是字体函数库。应用程序通过FreeType可以访问字体文件,获取字体信息,字形数据,而无需关心字体文件的位置。
相关文档参见:http://www.unixresources.net/linux/clf/kylix/archive/00/00/59/21/592188.html

X包含两种字体系统:原始的核心X11字体系统和Xft系统。 Xft比核心X11字体系统对缩放字形支持要好,并且提供了更多的功能。另外,Xft和核心X11字体系统是不兼容的。Xft 是 FreeType 之上的库,编写 Xft 库是为了给X应用程序提供一个能访问 FreeType 字体光栅化引擎和X渲染的接口。对于不支持渲染的X服务器,还要提供一个访问原始核心X11字体系统的功能。
相关文档参见:http://www.x.org/archive/X11R6.8.2/doc/fonts.html
https://wiki.archlinux.org/index.php/Font_Configuration_%28%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87%29#X.E7.9A.84.E5.AD.97.E4.BD.93.E9.85.8D.E7.BD.AE.E5.92.8C.E7.BE.8E.E5.8C.96
http://it.china-b.com/olbf/468958.html

Fontconfig 配置了程序如何选取字形,主要配置文件为 /etc/fonts/fonts.conf。除了字体信息外,还定义了字体的cache目录以及用户的字体目录。
具体配置方法参见:http://www.xfree86.org/~dawes/4.3.0/fonts2.html#4
https://wiki.archlinux.org/index.php/Font_Configuration_%28%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87%29

最后记录两个命令:
fc-cache 添加新字体后刷新cache,否则新字体无法使用。
fc-list 查看所有配置过的字体。
xlsfont 查看所有的X字体。

快速配置字体的方案:http://www.ikde.org/news/linux_font_config_from_beginner_to_expert_1/

2011年10月17日星期一

vsftpd 配置虚拟用户

最近配置两遍VSFTPD的虚拟用户了,第一次去google,第二次ssh到第一次的机器上运行history。。。现在记录一下vsftpd使用虚拟用户需要的相关配置:

1 配置vsftpd使用的虚拟用户,以及虚拟用户配置文件的目录。
本示例中虚拟用户映射到系统真实的notes用户,虚拟用户的配置目录在 /etc/vsftpd/vsftpd_user_conf  

chroot_local_user=YES
guest_enable=YES
guest_username=notes
user_config_dir=/etc/vsftpd/vsftpd_user_conf
virtual_use_local_privs=YE

2 在一个文件中配置虚拟用户的账户名和密码,该文件奇数行为用户名,偶数行为密码。
本示例中该文件为 /etc/vsftpd/userlist,虚拟用户名为tom,密码为456b7016a91

#cat /etc/vsftpd/userlist
tom
456b7016a91

3 利用该文件生成数据库文件,可能需要安装 db4-utils

yum -y install db4-utils
db_load -T -t hash -f /etc/vsftpd/userlist /etc/vsftpd/vsftpd_login.db

4 配置虚拟用户 tom 的具体权限

#cat /etc/vsftpd/vsftpd_user_conf/tom
local_root=/home/video_files
write_enable=YES
anon_other_write_enable=YES
anon_umask=022
allow_writeable_chroot=YES

4 配置 vsftpd 使用 PAM 验证:

pam_service_name=vsftpd

5 PAM验证使用刚才生成的数据库文件:

#cat /etc/pam.d/vsftpd
auth required /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
account required /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login

2011年6月14日星期二

rsync delete 参数

抄的抄的,原文见: http://superuser.com/questions/156664/rsync-delete-options
我好奇的是什么时候才需要考虑具体的delete方式。

--del/--delete_during Deletes files from the destination dir as they are copied (saves memory compared to --delete-before: --delete-before makes a separate scan to look for deleteables)
--delete Deletes files in the destination directory if they don't exist in the source directory.
--delete-before Delete files in the destination directory before coping file-with-same-name from source directory
--delete-during Delete files in the destination directory WHILE copying file-with-same-name from source directory
--delete-delay Mark deletes during transfer, but wait until transfer is complete
--delete-after Receiver deletes after transfer, not before...If some other part of the rsync moved extra files elsewhere, you'd want this instead of --delete-delay, because --delete-delay decides what its going to delete in the middle of transfer, whereas --delete-after checks the directory for files that should be deleted AFTER everything is finished.
--delete-excluded Deletes files from the destination directory that are explicitly excluded from transferring from the source directory.


The point of rsync is not copying, it is archiving. This is an important distinction. Processing deleted/changed files is critical, and in many cases nuanced.

Most of the other options are space or performance related. When you delete the files is important if you want to make sure the transfer is successful before you do anything, but if your device is too small to handle 2 copies of all the information, you need to delete as you go, etc. It's a little wacky because of it's long history across multiple platforms: some options have been added so that people who were used to certain behaviour wouldn't be confused.

2011年6月1日星期三

linux的系统时间与硬件时间

用了 opensuse 11.4 后发现系统时间一直比当前时间快8个小时,明显是时区有问题,但是/etc/localtime 又没有错误,今天查了查资料,搞清楚了几个概念。
1 GMT:格林威治时间。基本可以理解为一个标准时间,时区的原点,按照经线将地球分为24个时区。
2 UTC:世界协调时间。由于地球不是正圆的,自传速度也不一样,因此按照经线来均分地球时区有些不太精确。此时间相当于对GMT的修正,实际还是GMT时间。中国位于东8区,又称为CST(China Standard Time) CST时间 = UTC时间 + 8小时。
3 硬件时间:即通过电池在BIOS里记录的时间。Linux 对此时间的判断有两种可能:a 该时间表示本地时间;b 该时间表示 UTC 时间。Linux启动时会读取硬件时间,并根据 /etc/sysconfig/clock 中的 HWCLOCK 判断该时间记录的是本地时间还是 UTC 时间。
4 系统时间:就是 Linux 系统中显示的本地时间,该时间取决于系统开机后读取的时间以及当前的时区设置。时区配置文件为 /etc/localtime。/usr/share/zoneinfo 下保存了所有时区的配置文件,找个合适的,复制到 /etc/localtime 就可以了。

有了以上概念就不难理解了,在时区配置没有问题的情况下,一定是 Linux 在启动时读取硬件时间出了问题。只要将硬件时钟配置正确,并让 Linux 正确的读出来就问题就可以解决了。考虑到 windows 在启动时会将硬件时间设定为系统时间,因此 Linux 最好也采用此配置,否则启动 windows 后,windows 时钟可能会不正确。另外,系统时间是本地时间,而硬件时间则是 UTC 时间,看起来也不舒服。

修正方式如下:

方法1,读取硬件时间作为本地时间
1 hwclock --localtime 读取硬件时间。
2 如果要将该时间设置为系统时间,则将该时间写回系统 hwclock --localtime --hctosys,这时系统时间应该就变正确了
3 对于openSUSE12.2之前的版本:修改/etc/sysconfig/clock 中的HWCLOCK,由--utc 为 --localtime 否则下次重启还会出现问题。对于openSUSE 12.2:修改/etc/adjtime 将第三行从UTC更改为LOCAL。

办法 2,直接修改系统时间
1 date -s 设置系统时间
2 将系统时间写回硬件时钟 hwclock --localtime --systohc
3 修改/etc/sysconfig/clock


查看和设置时间的几个例子:

1 显示本地时间
# date
Thu Jun 2 21:48:44 CST 2011

2 查看硬件时间(指定硬件时间即为本地时间)
# hwclock --localtime
Thu Jun 2 21:48:47 2011 -0.239341 seconds

3 查看硬件时间 (指定硬件时间为 UTC 时间,则会对该时间+8,转换为本地时间后再显示出来)
# hwclock --utc
Fri Jun 3 05:48:49 2011 -0.125543 seconds

4 指明硬件时间为本地时间,并将该时间设置为系统时间
# hwclock --localtime --hctosys

5 指明硬件时间为本地时间,并将系统时间写回到 BIOS 中
# hwclock --localtime --systohc

2011年4月25日星期一

Mail Exchangers 避免循环转发

比如 abc.com 有以下3条 mx 记录:

abc.com. IN MX 0 0.abc.com.
abc.com. IN MX 10 11.abc.com.
abc.com. IN MX 10 12.abc.com.
abc.com. IN MX 20 21.abc.com.


向 0.abc.com 投递失败后,发送方会向 11 或者 12 进行投递,若 11 和 12 只有转发功能,则依然需要查询 mx 记录,然后再次进行投递。11 收到邮件后可能会投递给 12,12 收到邮件后会投递给 11,循环由此产生。
为解决此问题,转发服务器会自动 disable 优先级不高于自己的 mx 记录(即只保留优先级比自己高的记录),从而达到此目的。

比如对于 abc.com,11 在收到邮件后,根据自己的优先级10,会仅仅向 0 转发邮件,而停止向 12 和 21 的转发,这样就避免了循环投递的情况。

不过可以假设一个存在view情况,在 view1 中 11 的优先级高于 12,但是在 view2中 12 的优先级高于 11,这样是不是依然可能存在循环投递的情况。

nslookup 和 dig 的差别

One major difference between nslookup and dig is that dig doesn't apply the search list

nslookup 和 name server 的差别

To query like a resolver, you use nslookup's default settings. To query like a name server, use set norecurse and set nosearch. On the command line, that's nslookup -norecurse -nosearch.

简单的说,nslookup默认采用searchlist并在查询时设置递归位。经过set -norecurse 和 set -nosearch 后,nslookup的行为和name server的行为一致。