Category: Uncategorized


If you try to install 5.3.6 on by patching sources you will most likely see a lot of error messages similar to the following:

$ ./configure
cat: confdefs.h: No such file or directory
./configure: 490: ac_fn_c_try_run: not found
./configure: 490: 5: Bad file descriptor
./configure: 490: :: checking for pthreads_cflags: not found
./configure: 490: 6: Bad file descriptor
./configure: 490: checking for pthreads_cflags… : not found
cat: confdefs.h: No such file or directory
./configure: 490: ac_fn_c_try_run: not found
cat: confdefs.h: No such file or directory
./configure: 490: ac_fn_c_try_run: not found
cat: confdefs.h: No such file or directory
./configure: 490: ac_fn_c_try_run: not found
cat: confdefs.h: No such file or directory
./configure: 490: ac_fn_c_try_run: not found
cat: confdefs.h: No such file or directory
./configure: 490: ac_fn_c_try_run: not found
cat: confdefs.h: No such file or directory
./configure: 490: ac_fn_c_try_run: not found
cat: confdefs.h: No such file or directory
./configure: 490: ac_fn_c_try_run: not found
cat: confdefs.h: No such file or directory
./configure: 490: ac_fn_c_try_run: not found
./configure: 492: 5: Bad file descriptor
./configure: 492: :: result: : not found
./configure: 492: 6: Bad file descriptor
./configure: 492: : Permission denied
./configure: 495: 5: Bad file descriptor
./configure: 495: :: checking for pthreads_lib: not found
./configure: 495: 6: Bad file descriptor
./configure: 495: checking for pthreads_lib… : not found
cat: confdefs.h: No such file or directory
./configure: 555: ac_fn_c_try_run: not found
cat: confdefs.h: No such file or directory
./configure: 555: ac_fn_c_try_run: not found
cat: confdefs.h: No such file or directory
./configure: 555: ac_fn_c_try_run: not found
./configure: 557: 5: Bad file descriptor
./configure: 557: :: result: : not found
./configure: 557: 6: Bad file descriptor
./configure: 557: : Permission denied
./configure: 633: 5: Bad file descriptor
./configure: 633: :: result: : not found
./configure: 633: 6: Bad file descriptor
./configure: 633: : Permission denied
./configure: 635: 5: Bad file descriptor
./configure: 635: :: result: Configuring SAPI modules: not found
./configure: 635: 6: Bad file descriptor
./configure: 635: Configuring SAPI modules: not found
./configure: 666: 5: Bad file descriptor

See what happened when using buildconf earlier..

$ ./buildconf –force
Forcing buildconf
buildconf: checking installation…
buildconf: autoconf version 2.64 (ok)
buildconf: Your version of autoconf likely contains buggy cache code.
Running vcsclean for you.
To avoid this, install autoconf-2.13.
Can’t figure out your VCS, not cleaning.

This is not a regular warning and it cannot be neglected. You have to use autoconf-2.13. This is because the newer version of autoconf cannot process scripts which are meant for autoconf 2.13. So just install autoconf-2.13 and then do the compilation again..

sudo apt-get install autoconf2.13

Also if you have a low memory machine, then you might get error such as:

[lots of compile output]

/bin/sh /home/ibb_admin/temp/php-5.3.0/libtool –silent –preserve-dup-deps –mode=compile gcc -I/home/ibb_admin/temp/php-5.3.0/ext/fileinfo/libmagic -Iext/fileinfo/ -I/home/ibb_admin/temp/php-5.3.0/ext/fileinfo/ -DPHP_ATOM_INC -I/home/ibb_admin/temp/php-5.3.0/include -I/home/ibb_admin/temp/php-5.3.0/main -I/home/ibb_admin/temp/php-5.3.0 -I/home/ibb_admin/temp/php-5.3.0/ext/date/lib -I/home/ibb_admin/temp/php-5.3.0/ext/ereg/regex -I/usr/include/libxml2 -I/opt/include -I/opt/include/freetype2 -I/usr/include/imap -I/usr/kerberos/include -I/home/ibb_admin/temp/php-5.3.0/ext/mbstring/oniguruma -I/home/ibb_admin/temp/php-5.3.0/ext/mbstring/libmbfl -I/home/ibb_admin/temp/php-5.3.0/ext/mbstring/libmbfl/mbfl -I/opt/include/mysql -I/usr/include/mysql -I/home/ibb_admin/temp/php-5.3.0/ext/sqlite3/libsqlite -I/home/ibb_admin/temp/php-5.3.0/TSRM -I/home/ibb_admin/temp/php-5.3.0/Zend    -I/usr/include -g -O2  -c /home/ibb_admin/temp/php-5.3.0/ext/fileinfo/libmagic/apprentice.c -o ext/fileinfo/libmagic/apprentice.lo
virtual memory exhausted: Cannot allocate memory
make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1

So just upgrade the gcc compiler to its latest version and also add –disable-fileinfo to ./configure

Hence full installation procedure would be similar to:

sudo apt-get install autoconf2.13
wget http://us.php.net/get/php-5.3.6.tar.bz2/from/us.php.net/mirror
tar -xjf php-5.3.6.tar.bz2
cd php-5.3.6/
./buildconf –force
./configure –disable-fileinfo –enable-fpm –with-zlib –enable-pdo –with-pdo-mysql –enable-sockets –with-mysql –enable-calendar –with-iconv –enable-exif –enable-soap –enable-ftp –enable-wddx –with-zlib –with-bz2 –with-gettext –with-xmlrpc –enable-pcntl –enable-soap –enable-bcmath –enable-mbstring –enable-dba –with-openssl –with-mhash –with-mcrypt –with-xsl –with-curl –with-pcre-regex –with-gd –enable-gd-native-ttf –with-ldap –enable-pdo –with-pdo-mysql –with-mysql –with-sqlite –with-pdo-sqlite –enable-zip–enable-sqlite-utf8 –with-pear

Of course, your php configure options can be different.



问题:
cron计划任务,定义每五分钟运行一次,可是每运行一次就能收到cron发的邮件通知,这样会导致每天收到很多邮件

解决方法:
将运行结果定向到一个文件中去,比如,
echo “######” > aaa 就不会收到邮件了

Centos使用NTP自动同步系统时间

安装ntp服务
#yum install ntp (安前最好,先查看一下是否已经安装了rpm -ql ntp )

将本机默认时区设为上海
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

添加任务计划 (crontab -l 查看当前用户任务计划)
crontab -e
0-59/10 * * * * /usr/sbin/ntpdate asia.pool.ntp.org

同时建议修改一下 /etc/sysconfig/ntpd 文件
vim /etc/sysconfig/ntpd
SYNC_HWCLOCK=yes
(改成 yes BIOS 的时间也会跟着一起改变。)

asia.pool.ntp.org 亚洲的时间服务器,速度还可以,
到这里可以找到世界各地的时间服务器: http://www.pool.ntp.org/

隐藏Apache的版本

让我们着眼于2个参数,分别为ServerTokens和ServerSignature,通过控制这2个阀门应该就能起到一些作用,比如我们可以在配置文件中这么写:

ServerTokens ProductOnly
ServerSignature Off

ServerTokens
这个阀门用于控制服务器是否相应来自客户端的请求,向客户端输出服务器系统类型或内置模块等重要的系统信息。

* 在主配置文件中提供全局控制
* 默认阀值为”Full”(ServerTokens Full),所以,如果你的Linux发行版本没有更改过这个阀值的话,所有与你的系统有关的敏感信息都会向全世界公开(恐怖哦~)。比如RHEL会将该阀值更改为”ServerTokens OS”,而Debian依然使用默认的”Full”阀值

以apache-2.0.55为例,阀值可以设定为以下某项(后面为相对应的Banner Header):

ProductOnly >>> Server: Apache
Major >>> Server: Apache/2
Minor >>> Server: Apache/2.0
Minimal >>> Server: Apache/2.0.55
OS >>> Server: Apache/2.0.55 (Debian)
Full (or not specified) default >>> Server: Apache/2.0.55 (Debian) PHP/5.1.2-1
+b1 mod_ssl/2.0.55 OpenSSL/0.9.8b

ServerSignature
这个阀门控制由系统生成的页面(错误信息,mod_proxy ftp directory listing等等)的页脚中如何显示信息。

* 可在全局设置文件中控制,或是通过.htaccess文件控制
* 默认为”off “(ServerSignature Off),有些Linux发行版本可能会打开这个阀门,比如Debian在默认的虚拟主机上默认将这个阀门设置为开放
* 全局阀门的阀值会被虚拟主机或目录单位的配置文件中的阀值所覆盖,所以,必须确保这样的事情不应该发生

可用的阀值为下面所示:

Off (default): 不输出任何页脚信息 (如同Apache1.2以及更旧版本,用于迷惑)
On:输出一行关于版本号以及处于运行中的虚拟主机的ServerName
(2.0.44之后的版本,由ServerTokens负责是否输出版本号)
EMail: 创建一个发送给ServerAdmin的”mailto”

注意*上述关于如何设置2个阀门从而尽量减少敏感信息泄露的方法,并不会使你的服务器真的更安全,如果你现在使用的版本比较旧,请务必尽快将系统升级,降低被蠕虫攻击的风险。

php默认会输出header信息:
Date: Tue, 15 Apr 2008 13:58:46 GMT
Server: Apache/2.2.8
X-Powered-By: PHP/5.2.3
这样一下子php信息就全曝光了。怎样解决呢。

网上一搜中文,还真找不到相关信息。用英文一搜搜到了(下面是原文)

If you have read my previous tip, “Hide apache software version“, you have seen how you can configure apache to provide only a minimal amount of information about the installed software versions in its banner. But if you are using the PHP module in your web server (as most of us are), then there is one additional step that need to be completed, and this is what I will show you in this tip.

After implementing the apache directives ServerTokens and ServerSignature as shown in “Hide apache software version“, we test its functionality against a regular html file and we get the following response:

HEAD http://remote_server.com/index.html
200 OK
Connection: close
Date: Fri, 16 Jun 2006 01:13:23 GMT
Server: Apache
Content-Type: text/html; charset=UTF-8
Client-Date: Fri, 16 Jun 2006 21:42:53 GMT
Client-Peer: 192.168.0.102:80
Client-Response-Num: 1

This looks good. But if we do the same thing against an URL that is a PHP file:

HEAD http://remote_server.com/index.php 200 OK Connection: close Date: Fri, 16 Jun 2006 01:16:30 GMT Server: Apache Content-Type: text/html; charset=UTF-8 Client-Date: Fri, 16 Jun 2006 21:48:13 GMT Client-Peer: 192.168.0.102:80 Client-Response-Num: 1 X-Powered-By: PHP/5.1.2-1+b1

Ups… As we can see PHP adds its own banner:

X-Powered-By: PHP/5.1.2-1+b1…

Let’s see how we can disable it. In order to prevent PHP from exposing the fact that it is installed on the server, by adding its signature to the web server header we need to locate in php.ini the variable expose_php and turn it off.

By default expose_php is set to On.

In your php.ini (based on your Linux distribution this can be found in various places, like /etc/php.ini, /etc/php5/apache2/php.ini, etc.) locate the line containing “expose_php On” and set it to Off:

expose_php = Off

After making this change PHP will no longer add it’s signature to the web server header. Doing this, will not make your server more secure… it will just prevent remote hosts to easily see that you have PHP installed on the system and what version you are running.

结果简单的让人吃惊,只是需要修改php.ini 的 expose_php 把默认的 On改成 Off 就行了。

ERROR: unknown key name ‘UNIX_TIMESTAMP’ in /usr/local/etc/sphinx.conf line 575 col 24.

That line defines the query we use:

sql_query = \
SELECT id, idx_type, customer_id, website_page_id, title, \
UNIX_TIMESTAMP(date_added) AS date_added, \
url, content \
FROM main.pages

> SELECT id, idx_type, customer_id, website_page_id, title, \

Remove trailing spaces from this line.

Could be a bug in the config parser, maybe try writing the query on a single line without
using the “\” line breaks.

ssh 隧道建立:

ssh 隧道建立(本地内网mysql外部公网mysql同步):
ssh -L 127.0.0.1:3307:58.68.232.69:3306 -CfNg xxx.xxx.xxx.xxx
ssh -R 0.0.0.0:3307:localhost:3306 xxx.xxx.xxx.xxx -fN

sphinx –rotate机制详解

sphinx的searchd在启动时会创建一个 .spl 锁文件,并在关闭时会删除它。在indexer创建索引时如果发现有 .spl文件,则不会创建新索引,因为这时已经标志sphinx正在运行中,除非使用 –rotate。

roate运行机制

->indexer完成索引
->发送SIGHUP 给searchd(同时在终端输出索引已经完成)
->searchd接到中断信号->等待所有子进程退出
->重命名 当前索引为旧索引为 .old
->重命名 .new 索引文件作为当前索引
->尝试加载当前索引文件->如果加载失败,searchd会把.old文件回滚为当前文件,并把刚建立的新索引重命名为 .new
->加载成的话:完成无缝衔接

综上:解决问题的办法是:

关闭searchd :killall -9 searchd
重启 searchd :searchd -c ../sphinx.conf

Note:在有的时候需要注意建立索引时是否有warning之类的信息,这些信息也会导致rotate失败

cp 不再詢問是否覆蓋的方式

在 Linux 使用 cp 遇到檔案覆蓋時,預設不會詢問並且直接覆蓋。但為了要達到詢問是否覆蓋的功能,大部份的 Linux 在~/.bashrc 都有設定 alias cp=’cp -i’ (prompt before overwrite)
但是問題來了,cp -i  只能回答 y 或 n,並沒有類似 unzip 有 [A]ll, [N]one (全部覆蓋或全部不覆蓋)的選項,所以每個檔案要回答,也造成了不少困擾,即使下了 cp -f ,也因為 alias 的設定自動變成了 cp -i -f 而失效。
如果要強制全部覆蓋有幾種方式:
1. 忽略 alias
cp  ….
2.全部自動回答 yes
cp ….. –reply=yes
3.取消 cp 的 alias
unalias cp
cp ….

Pasted from

MySQL汉字字段按拼音排序

我们的MySQL使用latin1的默认字符集,也就是说,对汉字字段直接使用GBK内码的编码进行存储,当需要对一些有汉字的字段进行拼音排序时(特别涉及到类似于名字这样的字段时),默认无法通过order by关键字正确排序。

经过网上查找,网上的办法大多是针对使用utf8字符集的数据库,主要的方法有:
1)直接转换字段为gbk,比如:
SELECT * FROM table ORDER BY CONVERT( chinese_field USING gbk ) ;
或者干脆将相应字段改为gbk字符集。

我在我的数据库测试了上面的方法,或者直接按字段排序,都不行,主要是排序结果不理想。

2)查表法
创建一个新表,用来存储拼音声母和使用该声母的汉字首字的对应关系。然后写一个函数,每次排序时通过转换为gbk再查表的方法得到字段内容首字的声母的方法。

这个方法我也试了,太麻烦,而且针对我的数据库,也不能正确排序。

后来,我查询了汉字编码的一些资料,发现GBK内码编码时本身就采用了拼音排序的方法(常用一级汉字3755个采用拼音排序,二级汉字就不是了,但考虑到人名等都是常用汉字,因此只是针对一级汉字能正确排序也够用了)。根据这个原理,直接按字段排序就应该可以的(我的数据库使用Latin1 字符集,存的汉字本来就是GBK内码),但我试了以后发现不行。参考上面方法2的查表法,我把字段内容转换为16进制编码,再排,就OK了!

这就是最终的办法:SELECT * FROM table ORDER BY hex( chinese_field ) 简单吧!

这是我的例子数据排序输出的结果,如下图:

附:汉字编码方式简介
ASCII

ASCII码是7位编码,编码范围是0×00-0x7F。ASCII字符集包括英文字母、阿拉伯数字和标点符号等字符。其中0×00-0×20和0x7F共33个控制字符。

只支持ASCII码的系统会忽略每个字节的最高位,只认为低7位是有效位。HZ字符编码就是早期为了在只支持7位ASCII系统中传输中文而设计的编码。早期很多邮件系统也只支持ASCII编码,为了传输中文邮件必须使用BASE64或者其他编码方式。

GB2312

GB2312 是基于区位码设计的,区位码把编码表分为94个区,每个区对应94个位,每个字符的区号和位号组合起来就是该汉字的区位码。区位码一般 用10进制数来表示,如1601就表示16区1位,对应的字符是“啊”。在区位码的区号和位号上分别加上0xA0就得到了GB2312编码。

区位码中01-09区是符号、数字区,16-87区是汉字区,10-15和88-94是未定义的空白区。它将收录的汉字分成两级:第一级是常用汉字计 3755个,置于16-55区,按汉语拼音字母/笔形顺序排列;第二级汉字是次常用汉字计3008个,置于56-87区,按部首/笔画顺序排列。一级汉字 是按照拼音排序的,这个就可以得到某个拼音在一级汉字区位中的范围,很多根据汉字可以得到拼音的程序就是根据这个原理编写的。

GB2312字符集中除常用简体汉字字符外还包括希腊字母、日文平假名及片假名字母、俄语西里尔字母等字符,未收录繁体中文汉字和一些生僻字。可以用繁体汉字测试某些系统是不是只支持GB2312编码。

GB2312的编码范围是0xA1A1-0x7E7E,去掉未定义的区域之后可以理解为实际编码范围是0xA1A1-0xF7FE。

EUC-CN可以理解为GB2312的别名,和GB2312完全相同。

区位码更应该认为是字符集的定义,定义了所收录的字符和字符位置,而GB2312及EUC-CN是实际计算机环境中支持这种字符集的编码。HZ和 ISO-2022-CN是对应区位码字符集的另外两种编码,都是用7位编码空间来支持汉字。区位码和GB2312编码的关系有点像 和。

GBK

GBK 编码是GB2312编码的超集,向下完全兼容GB2312,同时GBK收录了Unicode基本多文种平面中的所有CJK汉字。同 GB2312一样,GBK也支持希腊字母、日文假名字母、俄语字母等字符,但不支持韩语中的表音字符(非汉字字符)。GBK还收录了GB2312不包含的 汉字部首符号、竖排标点符号等字符。

GBK的整体编码范围是为0×8140-0xFEFE,不包括低字节是0×7F的组合。高字节范围是0×81-0xFE,低字节范围是0×40-7E和0×80-0xFE。

低字节是0×40-0x7E的GBK字符有一定特殊性,因为这些字符占用了ASCII码的位置,这样会给一些系统带来麻烦。

有些系统中用0×40-0x7E中的字符(如“|”)做特殊符号,在定位这些符号时又没有判断这些符号是不是属于某个 GBK字符的低字节,这样就会造成错误判断。在支持GB2312的环境下就不存在这个问题。需要注意的是支持GBK的环境中小于0×80的某个字节未必就 是ASCII符号;另外就是最好选用小于0×40的ASCII符号做一些特殊符号,这样就可以快速定位,且不用担心是某个汉字的另一半。Big5编码中也 存在相应问题。

CP936和GBK的有些许差别,绝大多数情况下可以把CP936当作GBK的别名。

GB18030

GB18030编码向下兼容GBK和GB2312,兼容的含义是不仅字符兼容,而且相同字符的编码也相同。GB18030收录了所有Unicode3.1 中的字符,包括中国少数民族字符,GBK不支持的韩文字符等等,也可以说是世界大多民族的文字符号都被收录在内。

GBK和GB2312都是双字节等宽编码,如果算上和ASCII兼容所支持的单字节,也可以理解为是单字节和双字节混合的变长编码。GB18030编码是变长编码,有单字节、双字节和四字节三种方式。

GB18030 的单字节编码范围是0×00-0x7F,完全等同与ASCII;双字节编码的范围和GBK相同,高字节是0×81-0xFE,低字节的编码范围是0×40 -0x7E和0×80-FE;四字节编码中第一、三字节的编码范围是0×81-0xFE,二、四字节是0×30-0×39。

Windows 中CP936代码页使用0×80来表示欧元符号,而在GB18030编码中没有使用0×80编码位,用其他位置来表示欧元符号。这可以理解为是 GB18030向下兼容性上的一点小问题;也可以理解为0×80是CP936对GBK的扩展,而GB18030只是和GBK兼容良好。

unicode

每一种语言的不同的编码页,增加了那些需要支持不同语言的软件的复杂度。因而人们制定了一个世界标准,叫做unicode。unicode为每个字符提供 了唯一的特定数值,不论在什么平台上、不论在什么软件中,也不论什么语言。也就是说,它世界上使用的所有字符都列出来,并给每一个字符一个唯一特定数值。

Unicode的最初目标,是用1个16位的编码来为超过65000字符提供映射。但这还不够,它不能覆盖全部历史上的文字,也不能解决传输的问题 (implantation head-ache’s),尤其在那些基于网络的应用中。已有的软件必须做大量的工作来程序16位的数据。

因 此,Unicode用一些基本的保留字符制定了三套编码方式。它们分别是UTF-8,UTF-16和UTF-32。正如名字所示,在UTF-8中,字符是 以8位序列来编码的,用一个或几个字节来表示一个字符。这种方式的最大好处,是UTF-8保留了ASCII字符的编码做为它的一部分,例如,在UTF-8 和ASCII中,“A”的编码都是0×41.

UTF-16和UTF-32分别是Unicode的16位和32位编码方式。考虑到最初的目的,通常说的Unicode就是指UTF-16。在讨论Unicode时,搞清楚哪种编码方式非常重要。

UTF-8

Unicode Transformation Format-8bit,允许含BOM,但通常不含BOM。是用以解决国际上字符的一种多字节编码,它对英文使用8位(即一个字节),中文使用24为(三 个字节)来编码。UTF-8包含全世界所有国家需要用到的字符,是国际编码,通用性强。UTF-8编码的文字可以在各国支持UTF8字符集的浏览器上显 示。如,如果是UTF8编码,则在外国人的英文IE上也能显示中文,他们无需下载IE的中文语言支持包。

GBK的文字编码是用双字节来表示的,即不论中、英文字符均使用双字节来表示,为了区分中文,将其最高位都设定成1。GBK包含全部中文字符,是国家编码,通用性比UTF8差,不过UTF8占用的数据库比GBD大。

GBK、GB2312等与UTF8之间都必须通过Unicode编码才能相互转换:

GBK、GB2312→Unicode→UTF8

UTF8→Unicode→GBK、GB2312

对于一个网站、论坛来说,如果英文字符较多,则建议使用UTF-8节省空间。不过现在很多论坛的插件一般只支持GBK。

Windows的ANSI

为使计算机支持更多语言,通常使用 0×80~0xFF 范围的 2 个字节来表示 1 个字符。比如:汉字 ‘中’ 在中文操作系统中,使用 [0xD6,0xD0] 这两个字节存储。

  不同的国家和地区制定了不同的标准,由此产生了 GB2312, BIG5, JIS 等各自的编码标准。这些使用 2 个字节来代表一个字符的各种汉字延伸编码方式,称为 ANSI 编码。在简体中文系统下,ANSI 编码代表 GB2312 编码,在日文操作系统下,ANSI 编码代表 JIS 编码。

  不同 ANSI 编码之间互不兼容,当信息在国际间交流时,无法将属于两种语言的文字,存储在同一段 ANSI 编码的文本中。

Powered by WordPress | Theme: Motion by 85ideas.