最新发表

linux下apache支持中文名的解决方法

原日文网址:http://www.seya.org/mt/archives/2003/10/31_webdav2.html

1、下载相关文件并解压
WebDAV Resources JP有Apache2对应的mod_encoding的最新版本下载

# wget http://webdav.todo.gr.jp/download/mod_encoding-20021209.tar.gz
# wget http://webdav.todo.gr.jp/download/experimental/mod_encoding.c.apache2.20040616
# tar zxfv mod_encoding-20021209.tar.gz
# cp mod_encoding.c.apache2.20020616 mod_encoding-20021209/mod_encoding.c

2、iconv_hook编译和安装
安装mod_encoding前首先需要安装iconv_hook。

$ cd mod_encoding-20021209/lib
$ ./configure
$ make
# make install
完成上面操作后,iconv_hook相关so文件放到/usr/local/lib下面。
打开/etc/ld.so.conf文件,添加一行指向iconv_book的所在路径,即”/usr/local/lib”

# vi /etc/ld.so.conf
添加/usr/local/lib

# ldconfig

3、 mod_encoding模块的编译
进入mod_encoding-20021209.tar.gz的解压目录,即mod_encoding-20021209
–with-iconv-hook[=DIR]  use iconv.h from iconv_hook in DIR
(default is /usr/local/include/iconv_hook)

# ./configure –with-apxs=/usr/sbin/apxs –with-iconv-hook=/usr/local/include
# make

我在执行make命令编译时,会报如下错误:
/usr/local/apache2/bin/apxs -c -I/usr/local/include -liconv_hook mod_encoding.c
/usr/local/apache2/build/libtool –silent –mode=compile gcc -prefer-pic   -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -g -O2 -pthread -I/usr/local/apache2/include -I/usr/local/apache2/include   -I/usr/local/apache2/include -I/usr/local/include -c -o mod_encoding.lo mod_encoding.c && touch mod_encoding.slo
mod_encoding.c: In function `get_client_encoding’:
mod_encoding.c:174: warning: assignment makes pointer from integer without a cast
mod_encoding.c:181: `regex_t’ undeclared (first use in this function)
mod_encoding.c:181: (Each undeclared identifier is reported only once
mod_encoding.c:181: for each function it appears in.)
mod_encoding.c:181: parse error before ‘)’ token
mod_encoding.c: At top level:
mod_encoding.c:187: parse error before “return”
mod_encoding.c: In function `set_server_encoding’:
mod_encoding.c:213: warning: assignment makes pointer from integer without a cast
mod_encoding.c: In function `add_client_encoding’:
mod_encoding.c:239: `REG_EXTENDED’ undeclared (first use in this function)
mod_encoding.c:239: `REG_ICASE’ undeclared (first use in this function)
mod_encoding.c:239: `REG_NOSUB’ undeclared (first use in this function)
mod_encoding.c:244: warning: assignment makes pointer from integer without a cast
mod_encoding.c: In function `default_client_encoding’:
mod_encoding.c:270: warning: assignment makes pointer from integer without a cast
mod_encoding.c: At top level:
mod_encoding.c:301: warning: initialization from incompatible pointer type
mod_encoding.c:305: warning: initialization from incompatible pointer type
mod_encoding.c:309: warning: initialization from incompatible pointer type
mod_encoding.c:313: warning: initialization from incompatible pointer type
mod_encoding.c:317: warning: initialization from incompatible pointer type
mod_encoding.c: In function `mod_enc_parse’:
mod_encoding.c:499: warning: passing arg 2 of `ap_pbase64encode’ makes pointer from integer without a cast
mod_encoding.c:501: warning: passing arg 3 of `apr_table_set’ makes pointer from integer without a cast
apxs:Error: Command failed with rc=65536
.
make: *** [mod_encoding.so] Error 1

原因很明显,是regex.h未包含进来,解决办法也很简单,用vi打开mod_encoding.c,
在#include <httpd.h>那一段的前面加上如下一行:
#include <regex.h>

再编译应该就可以通过了

#ls -l mod_encoding.o  查看是否已经生成了mod_encoding.o文件,如果是,则make成功继续下边的操作。
# gcc -shared -o mod_encoding.so mod_encoding.o -Wc,-Wall -L/usr/local/lib -Llib -liconv_hook

生成mod_encoding.so文件,将该文件拷贝到你的模块存放目录,一般为${APACHE_HOME}/modules/
# cp mod_encoding.so /usr/local/apache/modules/mod_encoding.so

4、 httpd.confd的設定
这个是我的设置文件

LoadModule headers_module modules/mod_headers.so
LoadModule encoding_module modules/mod_encoding.so
<IfModule mod_headers.c>
Header add MS-Author-Via “DAV”
</IfModule>
<IfModule mod_encoding.c>
EncodingEngine    on
NormalizeUsername on
SetServerEncoding GBK
DefaultClientEncoding UTF-8 GBK GB2312
AddClientEncoding “(Microsoft .* DAV $)” UTF-8 GBK GB2312
AddClientEncoding “Microsoft .* DAV” UTF-8 GBK GB2312
AddClientEncoding “Microsoft-WebDAV*” UTF-8 GBK GB2312
</IfModule>

在shell中将unix时间戳转换为系统时间

用date +%s可以得到UNIX的时间戳,

如date +%s
1273460780

date转化为系统时间

date -d ’1970-01-01 UTC 1273460780 seconds’ +”%Y-%m-%d %T %z”

2010-05-10 11:06:20 +0800  (时间格式自行设计)

也可以用awk

awk ‘BEGIN{x=strftime(“%b %d %T CST %Y”, “1273460780″);print x}’

May 10 11:06:20 CST 2010

UNIX时间戳 就是1970-01-01到某个时间的总秒数。
可以自己编个程序算一算

keepalived常见报错问题

master、backup的/var/log/messagse显示
Nov 23 17:46:41 SN2008-06-070 Keepalived_vrrp: receive an invalid ip number count associated with VRID!
Nov 23 17:46:41 SN2008-06-070 Keepalived_vrrp: bogus VRRP packet received on eth0 !!!
Nov 23 17:46:41 SN2008-06-070 Keepalived_vrrp: VRRP_Instance(VI_1) Dropping received VRRP packet…
Nov 23 17:46:42 SN2008-06-070 Keepalived_vrrp: receive an invalid ip number count associated with VRID!
Nov 23 17:46:42 SN2008-06-070 Keepalived_vrrp: bogus VRRP packet received on eth0 !!!
Nov 23 17:46:42 SN2008-06-070 Keepalived_vrrp: VRRP_Instance(VI_1) Dropping received VRRP packet…
解决方法:
改变配置文件/etc/keepalived/keepalived.conf中virtual_router_id为另一个值即可。,与网络中不能重复。

kcore是什么

What is the /proc/kcore?

Trick

/proc/kcore is the Server memory. You aren’t going to save any disk space by trying to remove it.
It is the ‘image’ file for all your memory; this actually contains the data and information that is currently in your physical RAM.

/proc/kcore is an image of the RAM of the Server. The entire /proc file system does not exist on the disk. Instead, it is a collection of files that the kernel generates on the fly to give information on different processes, and other information.

If the sight of it bothers you (or if you don’t want nosy people reading what’s in you RAM) you can disable /proc support in your kernel.

由此可以看出,它是反应你当前物理内存中数据的一个镜像文件,删除它不能过节省你磁盘的任空间

windows下rsync使用

rsync 官方站点

http://rsync.samba.org/

http://samba.anu.edu.au/rsync/download.html

[ WINDOWS 2003 RSYNC 客户端 ]
rsync for windows download :

http://switch.dl.sourceforge.net/sourceforge/sereds/cwRsync_4.0.4_Installer.zip

下载后安装,安装目录比如C:\Program Files\cwRsync

安装后,启动Windows操作系统的命令窗口,直接运行rsync会报错。

此时要在Windows里加一下cwrsync的path,见此文

windows中添加PATH环境变量

正常运行rsync命令后就像在linux下使用rsync一样使用了

注意:rsync参数  -a等于-rlptgoD,

-o, –owner 保持文件属主信息
-g, –group 保持文件属组信息

由于在Windows下无法运行chown命令,所以会报错,但不影响同步,建议用 -rlptD来 代替 -a 参数

如:rsync -rlptDzv 192.168.0.5::www ./www

可以写批处理来运行备份或是同步等等应用,也可以加载计划任务里来定时运行

windows中添加PATH环境变量

以cwrsync为例,软件安装完毕后,启动Windows操作系统的命令窗口,在安装目录(比如C:\Program Files\cwRsync\bin)下运行rsync是ok的,但是在其他任意目录下运行rsync就会报错,如下图

这意味着我们还不能使用rsync命令,这是因为:虽然我们以经安装了cwrsync,而安装目录下也包含了rsync这个命令,但计算机不知道去哪里去找这两个命令。但是我们如果说进入到cwrsync的安装目录下的bin目录,再依次运行rsync命令,又是可以正常运行的。 计算机是如何查找命令的呢?Windows操作系统根据Path环境变量来查找命令。 Path环境变量的值是一系列路径,Windows操作系统会在这一系列的路径中查找命令。注意:在Windows操作系统里是不区分大小写的,而在Linux系统里,我们应该设置PATH环境变量。

在Windows平台上设置环境变量如果下图:

我的电脑->属性->高级->环境变量->系统变量中添加环境变量

对于Windows系统而言,名为Path的环境变量以经存,可以直修改该环境变量,在该环境变量值后面追加C:\Program Files\cwRsync\bin。然后新开一个命令窗口,运行path看看新加的环境变量是否存在了。

再在任何目录下运行rsync命令就都ok了

一般建议在用户变量里,去添加环境变量

用户变量与系统变量的区别:用户变量和系统变量并没有什么太大的区别,只是用户变量只对当前用户有效,而系统变量对所有用户有效。不过,系统变量会排在用户变量前面,如果说,两个地方都包含了rsync命令,则优先执行Path系统变量路径里包含的rsync命令。

SecureCRT连接SSH超时后自动断开

为什么SecureCRT连接到sshd服务器后在一段时间内不操作就会自动断开呢?

SecureCRT 保持连接

原因:
这是因为客户端与服务器之间存在路由器,防火墙以及为了本身的安全性,在超过特定的时间后就会把空闲连接断开。或者是服务器端设置了断开空闲连接。

解决方法:
既然会断开超时的空闲连接,那么我们就应该让客户端与服务器之间的连接“忙”起来,方法有两个:

从服务器方面入手:
修改/etc/ssh/sshd_config配置文件 ClientAliveInterval 300(默认为0)
这个参数的是意思是每5分钟,服务器向客户端发一个消息,用于保持连接
service sshd reload 生效

从客户端入手:
上面是配置需要服务器权限,如果没有服务器权限则可以使用这个方法,其思想是:客户端向服务器发一个消息,用于保持连接
secureCRT在选项 终端 反空闲 中设置每隔多少秒发送一个字符串,或者是NO-OP协议包
putty:putty -> Connection -> Seconds between keepalives ( 0 to turn off ), 默认为0, 改为300.

SecureCRT rz 上传rar,gif文件不正确及上传大容量文件失败问题解决

linux 与 windows 文件传输:rz/sz
ZModem is a full-duplex file transfer protocol that supports fast data transfer rates and effective error detection. ZModem is very user friendly, allowing either the sending or receiving party to initiate a file transfer. ZModem supports multiple file (”batch”) transfers, and allows the use of wildcards when specifying filenames. ZModem also supports resuming most prior ZModem file transfer attempts.

rz,sz是便是Linux/Unix同Windows进行ZModem文件传输的命令行工具

windows端需要支持ZModem的telnet/ssh客户端(比如SecureCRT)

运行命令rz,即是接收文件,SecureCRT就会弹出文件选择对话框,选好文件之后关闭对话框,文件就会上传到当前目录

注意:单独用rz会有两个问题:上传中断、上传文件变化(md5不同),解决办法是上传是用rz -be,并且去掉弹出的对话框中“Upload files as ASCII”前的勾选。

-a, –ascii
-b, –binary 用binary的方式上传下载,不解释字符为ascii
-e, –escape
强制escape 所有控制字符,比如Ctrl+x,DEL等

rar,gif等文件文件采用 -b 用binary的方式上传。

文件比较大而上传出错的话,采用参数 -e

如果用不带参数的rz命令上传大文件时,常常上传一半就断掉了,很可能是rz以为上传的流中包含某些特殊控制字符,造成rz提前退出。

一次怪异的Ucenter头像无法上传问题

LAMP系统

Discuz    access denied for agent changed 错误

为了解决中文路径以及中文文件名下载问题,安装了mod_encoding模块
过了一段时间后才发现ucenter上传头像图片出现莫名的access denied for agent changed错误,查遍了所有的官方以及非官方的资料,都没有找到正确的解决方法。
咨询官方技术人员,给后台权限他们查看配置等,无果。

后来在网上发现有同样的问题。说是安装了mod_encoding后出现的问题。想起也曾经安装过这个模块。赶紧注释掉,发现一切都ok了。
最终发现,将mod_encoding取消后,所有症状消失。想其原因有可能是该模块将url编码转换,导致ucenter无法获取到正确的user- agent值,出现错误。。。不过疑问是,,为什么这个问题属于间歇性问题,也就是说,有时候出现,有时候不出现。。
目前办法:取消该模块的使用

ls 文件按时间排序

ls -lrt   最新的在最后面。
ls -lt 显示最近被修改文件的长列表,较旧的文件跟在后面。