最新发表

Apache支持perl在web的应用

apache支持perl在web的应用

1、安装apache
如apache安装在/usr/local/apache2/
2、安装perl
perl默认在linux系统里是自带的,

PS:要注意安装版本的差异,版本过低会报错
Can’t locate Apache/Response.pm in @INC …

Found this issue in Aurora SPARC Linux 2.0 (Fedora Core 3 for SPARC) when trying to install… turns out that after installing all the modules for rt, I still had an ancient verion of CGI.pm, which was not intended to correctly detect the mod_perl2 modules vs. regular mod_perl. Upgrading CGI via CPAN quickly resolved this problem after an embarrassing number of hours troubleshooting.

If Apache refuses to start after you add PerlRequire bin/webmux.pl to your config and you’re sure you’ve got a valid mod_perl2 installation, try upgrading CGI to the latest version.

3、安装mod_perl
如我现在版本

tar zxvf mod_perl-2.0-current.tar.gz
cd mod_perl-2.0.4
perl Makefile.PL
make
make test
make install

PS:如果apache在运行帐号的权限是nobody的话,而mod_perl-2.0.4是在root在目录下,在make test的过程将会报错
You are running the test suite under user ‘root’.
Apache cannot spawn child processes as ‘root’, therefore
we attempt to run the test suite with user ‘nobody’ (99:99).
The problem is that the path (including all parent directories):
/root/mod_perl-2.0.4/t
must be ‘rwx’ by user ‘nobody’, so Apache can read and write under that
path.

建议将mod_perl-2.0.4 放在/tmp目录下

安装后将会在/usr/local/apache2/modules/有一个mod_perl.so
ls /usr/local/apache2/modules/mod_perl.so

4、配置http.conf
在http.conf里
a、载入模块
LoadModule perl_module modules/mod_perl.so
b、<IfModule mime_module>里加入后缀解析
AddHandler cgi-script .cgi .pl

c、vhost设置里加入执行

<VirtualHost *:80>
ServerName www.588k.com
DocumentRoot /opt/wwwroot/www.588k.com
ScriptAlias /perl/ “/opt/wwwroot/www.588k.com/perl/”               ##/opt/wwwroot/www.588k.com/perl为网站的documentroot的perl目录

<Location /perl>
SetHandler perl-script
PerlHandler ModPerl::Registry
Options +ExecCGI
allow from all
PerlSendHeader On
</Location>

</VirtualHost>

5、测试
先重启apache
在documentroot下建立test.pl 内容如下

#!/usr/bin/perl -w
use CGI;
{
my $q = new CGI;
print $q->header(),
$q->start_html(”hello perl world!”),
$q->h1(’hello perl world, by sakia’),
$q->end_html();
}

通过http://www.588k.com/perl/test.pl如果能够正常输出
hello perl world, by sakia

配置成功

VMware conversion error: Error: Unable to obtain the IP address of the target virtual machine running the Converter helper server.

While running VMware converter, one may encounter this error;

Error: Unable to obtain the IP address of the target virtual machine running the Converter helper server.

For those who may not know how to fix it, it’s really easy (and I feel a little ashamed that I have to post the solution here, but who knows, someone may need the help, so step forward my young Padawan, and pay attention)…

The helper virtual machine must be able to establish an SSH connection with the source computer. By default the helper virtual machine gets its IP address assigned by DHCP. If there is no DHCP server available on the network chosen for the target virtual machine you must manually assign it an IP address.

大致翻译:Converter转化机必须能ssh连接源机器。默认情况下Converter转化机通过DHCP来获取目标虚拟机的IP地址,如果网络内没有DHCP服务器对目标虚拟机分配IP,那必须手工来设定目标虚拟机的IP地址
所以如果没有对目标虚拟机设置一个ip的话,将会出现上述的报错

利用sendmail发送附件

sendmail发附件需要用uuencode命令这个命令在sharutils组件中,可以远程安装

apt-get install sharutils
yum install sharutils

也可以用rpm安装,可以去安装光盘里找。如我的redhat 5.2 x_86_64系统,rpm包:sharutils-4.6.1-2.x86_64.rpm
安装后有uuencode命令

开启sendmail服务
#/etc/rc.d/init.d/sendmail start

现在就可以发送附件了
uuencode /root/tmp.tar tmp.tar | mail -s “tmp.tar” xxx@email.com

注:如上发送时如果加上邮件内容
uuencode /root/tmp.tar tmp.tar | mail -s “tmp.tar” xxx@email.com < >test….
>EOF
如此发送的话,邮件内容将会覆盖掉附件。

shmmax的含义与设置小结

shmmax内核参数定义单个共享内存段的最大值,即单个进程的最大内存使用量,如果该参数设置小于某些进程的设置,那么就会被分配多个共享内存段。这在繁忙的系统中可能成为性能负担,带来系统问题。32位CPU的寻址空间是4G,32位机器shmmax一般不能超过4G

老版本CentOS、Redhat的shmmax默认值为33554432字节(33554432bytes/1024/1024=32MB)。现在新版本是
[root@localhost ~]# cat /proc/sys/kernel/shmmax
4294967295

长久修改shmmax的值:
vi /etc/sysctl.conf 编辑这个文件,在最后一行加入
kernel shmmax = 807374182
然后执行以下命令使配置生效:
/sbin/sysctl -p

临时更改该值:
echo 字节数 > /proc/sys/kernel/shmmax

按照以上方法更改,在每次重启系统时,该值会被自动还原。如果想永久更改,可以修改/etc/sysctl.conf文件,设置:
kernel.shmmax = 字节数

注:vi /etc/sysctl.conf 编辑这个文件,在最后一行加入
kernel shmmax = 807374182
重启生效.

php-fpm报错

[ERROR] fpm_unix_conf_wp(), line 124: please specify user and group other than root, pool ‘default’

安装完php-cgi 不能启动

[ERROR] fpm_unix_conf_wp(), line 124: please specify user and group other than root, pool ‘default’

出现些错误提示,请修改 php-fpm.conf,将注释去掉

Unix user of processes
PHP, nginx ,

apache rewrite转nginx–对大括号(花括号)的支持

在nginx中这样写规则
rewrite [\w]{5,20} /index.php last; 是无法启动的
解决的办法是加上两个双引号
rewrite “[\w]{5,20}” /index.php last; 这样就OK了
应该可以说是完全兼容apache的语法的,只需要改下RewriteRule为Rewrite,后面的
的这样对应改

[R] -> redirect;
[P] -> last;
[R,L] -> redirect;
[P,L] -> last;
[PT,L] -> last;

nginx rewrite中支持4种类型的转向:

跳转型的
redirect:302跳转到rewrite后的地址
permanent:301永久定向到rewrite后的地址,对搜索引擎更友好
代理型的
last:重新将rewrite后的地址在server标签中执行
break:将rewrite后的地址在当前location标签中执行

《奋斗》和《蜗居》的区别

  奋斗的编剧叫石康,纯爷们,确切年龄41岁;
  蜗居的编剧叫六六,纯娘们,大概年龄36岁。
  
  奋斗是一个老男人写的浪漫主义的奇幻喜剧;
  蜗居是一个小女人写的现实主义的恐怖杯具。
  
  奋斗说的是北京那旮旯的事儿;
  蜗居说的是上海一面德额事体。
  
  奋斗讲了几对年轻无知的男女的混乱爱情故事,主讲‘情’;
  蜗居讲了一帮青春渐逝的男女的疯狂同居故事,主讲‘性’。
  
  奋斗努力把青涩理想的青年慢慢塑造成成熟稳重的男人;
  蜗居试图把抛妻弃子的男人快速改造成重情重义的男子。
  
  奋斗描绘了一个过于理想的风华青年在遇到他妈的老情人的滴血认亲后,不想放弃梦想选择认贼作父的故事,是一个儿童童话。
  蜗居诉说了一个爱慕虚荣的美貌少女在看到她妈的大女儿的残酷生活后,不敢面对生活选择出卖肉体的故事,是一个成人寓言。
  
  奋斗讲的是年轻人如何盖房子;
  蜗居讲的是年轻人如何买房子。
  
  奋斗中的主人翁们坚定不移的在清华大学毕业的男人的正确领导下,最终取得了结婚的重大成果;
  蜗居中的各角色们始终紧密团结围绕在复旦大学毕业的女人的周围,最终取得了买房的重大胜利。
  
  
  看了奋斗,觉得故事好假;
  看了蜗居,觉得人生好假。
  
  奋斗让女人不相信男人;
  蜗居让男人不相信女人。
  
  奋斗让一些初入社会的小青年盼望自己有一个出国在外、还未相认、终生未娶、富甲一方、幡然悔悟、注重亲情的生父;
  蜗居让一些涉世未深的小姑娘幻想自己找一个出手大方、萍水相逢、宝刀未老、权倾朝野、执迷不悟、滥情至上的干爹。
  
  奋斗描述了富家子弟的逍遥生活,粉饰了富人“身在福中不知福,饱汉不知饿汉饥”的无耻行径,控诉了资本主义的黑暗;
  蜗居刻画了劳苦大众的悲惨人生,抒发了人民“安得广厦千万间,大批寒士俱欢颜”的美好愿望,赞美了社会主义的和谐。
  
  
  奋斗也许会给人带来希望;
  蜗居一定会让人感觉绝望。
  
  喜欢奋斗的观众有些真的去奋斗了;
  喜欢蜗居的观众有些真的当二奶了。
  
  奋斗是冷酷现实的迷幻剂,满足了80后最后逝去的一丝幻想情节;
  蜗居是残酷现实的催化剂,刺痛了80后正在面临的一个严酷现实。

python-mysqldb模块安装

已安装:
Python 2.5.4
mysql 安装客户端

安装mysqldb的模块。
解压:
[root@localhost]# tar xfz MySQL-python-1.2.3c1.tar.gz
[root@localhost]# cd MySQL-python-1.2.3c1 #进入MySQL-python目录,查看site.cfg文件的mysql-config配置,如果与实际不符合,请自行修改

[root@localhost]# python setup.py build #注意啦,这一步是一定要做的,不然就安装不成功。

[root@localhost]# python setup.py install #正式安装

然后进入:
$python
>>>import MySQLdb
搞定
一切正常,好啦.

问题1:
[root@localhost]# python setup.py build
Traceback (most recent call last):
File “setup.py”, line 5, in
from setuptools import setup, Extension
ImportError: No module named setuptools

1、下载一个文件
[root@localhost]# wget http://peak.telecommunity.com/dist/ez_setup.py
2、运行安装 setuptools:
[root@localhost]# python ez_setup.py
3、然后build,install

PS:如果没外网
1、先运行python ez_setup.py,有个一个下载的文件。
如我这个版本:http://pypi.python.org/packages/2.5/s/setuptools/setuptools-0.6c11-py2.5.egg
2、去有公网的机器下载
wget “http://pypi.python.org/packages/2.5/s/setuptools/setuptools-0.6c11-py2.5.egg”
3、然后传到与ez_setup.py同一目录下,然后运行
[root@localhost]# python ez_setup.py

问题2:

当我在MySQLdb的源码路径build及install完,并导入模块时,发生警告:
>>> import MySQLdb
/usr/local/lib/python2.5/site-packages/MySQL_python-1.2.3c1-py2.5-linux-x86_64.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/local/lib/python2.5/site-packages/MySQL_python-1.2.3c1-py2.5-linux-x86_64.egg/_mysql.pyc, but /root/MySQL-python-1.2.3c1 is being added to sys.path
import sys, pkg_resources, imp

原因是,install后MySQLdb模块已经被放到python的site-pachages目录中;但我在当前目录也存在相同的模块,所以可能会重复导入。只要切换到其他目录运行就可以了。

Kernel reports EDAC i5000: SPD Protocol Error, Bits= 0×40000

Problem:
The kernel repeatedly prints errors messages similar to the following:
EDAC i5000 MC0: NON-FATAL Errors found!!! 1st NON-FATAL Err Reg= 0×40000
EDAC i5000: SPD Protocol Error, Bits= 0×40000

Description:
This is caused by the optional IPMI card and the i5000_edac kernel module trying to access the platforms EDAC (Error Detection and Correction) information at the same time.

Solution:
The workaround for this problem is to prevent the i5000_edac module from loading. To do this, add the following line to the /etc/modprobe.d/blacklist file:

blacklist i5000_edac

SCWS-1.0.4 php分词模块安装

scws   php分词模块

以 Linux(FreeBSD) 操作系统为例

1. 取得 scws-1.0.4 的代码
wget http://www.ftphp.com/scws/down/scws-1.0.4.tar.bz2

2. 解开压缩包
tar jxvf scws-1.0.4.tar.bz2

3. 进入目录执行配置脚本和编译
cd scws-1.0.4
./configure –prefix=/usr/local/scws
make
make install

注:这里和通用的 GNU 软件安装方式一样,具体选项参数执行 ./configure –help 查看。
常用的三个选项为:
–prefix=<scws的安装目录>
–disable-mmap     <这表示禁用 MMAP 来读取 xdb,在 debian, ubuntu 的部分 Linux 中建议关闭 mmap>
–enable-developer <这表示以开发者模式编译,主要是用于调试编译时加入了 -g 选项及部分标准输出的信息>

4. 正常的话已经编译并安装成功到 /usr/local/scws 中了,执行下面命令看看文件是否存在
ls -al /usr/local/scws/lib/libscws.la

5. 试试执行 scws-cli 文件
/usr/local/scws/bin/scws -h
scws (scws-cli/1.0.4)
Simple Chinese Word Segmentation – Command line usage.
Copyright (C)2007 by hightman.

6 用 wget 下载并解压词典,或从主页下载然后自行解压再将 *.xdb 放入 /usr/local/scws/etc 目录中
wget http://www.ftphp.com/scws/down/scws-dict-chs-gbk.tar.bz2
tar xvjf scws-dict-chs-gbk.tar.bz2

tar jxvf scws-dict-chs-gbk.tar.bz2
cp dict.xdb /usr/local/scws/etc/

7. 这样就好顺利安装完毕可以使用 libscws 这套 C-API 了

8. 在 php 中调用分词,安装 php 扩展

1) 进入源码目录的 phpext/ 目录 ( cd ~/scws-1.0.4 )
2) 执行 phpize (在PHP安装目录的bin/目录下)
3) 执行 ./configure –with-scws=/usr/local/scws
若 php 安装在特殊目录 $php_prefix, 则请在 configure 后加上 –with-php-config=$php_prefix/bin/php-config
4) make  && make install
5) 在 php.ini 中加入以下几行

[scws]
;
; 注意请检查 php.ini 中的 extension_dir 的设定值是否正确, 否则请将 extension_dir 设为空,
; 再把 extension = scws.so 指定绝对路径。
;
extension = scws.so
scws.default.charset = gbk
scws.default.fpath = /usr/local/scws/etc

6) 命令行下执行 php -m 就能看到 scws 了或者在 phpinfo() 中看看关于 scws 的部分,记得要重启 web 服务器
才能使新的 php.ini 生效。