Archive

Archive for the ‘linux’ Category

nginx 小记 (无法获取get post cookie)

August 4th, 2010 陈毓端 No comments

之前给朋友公司架设了nginx phpcgi 应用环境

今天告诉我无法获取get post cookie等

查了php.ini 没用问题

找了半天,原来nginx.conf 

include        fastcgi_params;

被注释了 开启。即可。

Categories: linux, php Tags:

redhat 更新源 到centos

July 9th, 2010 陈毓端 No comments
前两天答应一朋友给他安装两台新采购服务器的LAMP环境,晚上抽时间SSH的登录。
我也没有看服务器都安装了什么。
编译mysql时候碰到
configure: error: no acceptable C compiler found in $PATH
天哪 连GCC G++ 基本库都没装
因为是redhat 习惯的
yum install gcc g++
no
This system is not registered with RHN.
RHN support will be disabled.
提示系统未注册RHN
悲哀 伪开源的约束
只能更新源的 采用centos的源
操作步骤:
cd /etc/yum.repos.d/
vi centos.repo
[base]
name=CentOS-$releasever – Base
baseurl=http://centos.ustc.edu.cn/centos/5/os/i386/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
重新安装
yum install gcc g++
Categories: linux Tags:

深入研究FastCGI 第一步

June 25th, 2010 陈毓端 No comments
说道FastCGI 大家都觉得它比CGI的效率高 具体高在那?很多人会说CGI需要不断的fork 对系统压力大。
其实第一次接触FastCGI是在应用Nginx环境时候,今天再次理下FastCGI 到底是什么?
从官方(http://www.fastcgi.com)的About FastCGI
第一句话就告诉我们:
FastCGI is simple because it is actually CGI with only a few extensions.
FastCGI 其实是一些简单CGI的扩展
Like CGI, FastCGI is also language-independent. For instance, FastCGI provides a way to improve the performance of the thousands of Perl applications that have been written for the Web.
如CGI ,FastCGI也具备语言无关系性。例如,FastCGI 提供一种的方法来提高Prel应用程序的处理能力。
既然是简单的CGI扩展那它的优势在那呢? 难道又是所谓的“重复造车”?
再看看官方的一句重要的解释
Like CGI, FastCGI runs applications in processes isolated from the core Web server, which provides greater security than APIs. (APIs link application code into the core Web server, which means that a bug in one API-based application can corrupt another application or the core server; a malicious API-based application can, for example, steal key security secrets from another application or the core server.)
如CGI , FastCGI 独立运行于WEB服务器的核心进程。并提供大量的安全API。 后面的英文我觉得说的有点严肃。它告诉我们一个问题,FastCGI出现问题之后,以至于不会破坏WEB server的核心进程,一句话WEB server 还可以使用脱离FastCGI的应用。
简单的说就是某些核心应用的托管。 如 托管 Nginx的PHP 解析器进程。
spawn-fcgi.c的核心代码
static int fcgi_spawn_connection(char *appPath, char **appArgv, char *addr, unsigned short port, const char *unixsocket, int fork_count, int child_count, int pid_fd, int nofork);
static int find_user_group(const char *user, const char *group, uid_t *uid, gid_t *gid, const char **username);
最近真的要看看里面的代码。
Nginx的fast-cgi 源码在: src/http/modules/ngx_http_fastcgi_module.c  可以详细的研究下,再次鞭策自己。
FastCGI 的API文档:http://www.fastcgi.com/drupal/node/5
Categories: c, linux, 编程语言 Tags:

小型vps nginx+php-cgi 内存过大应急预案

April 30th, 2010 陈毓端 No comments

朋友买了台vps 内存在512M ,有时候多个cgi进程是的内存使用过大 导致502错误

除了基本的优化外 ,这里就不写了,网上一堆。

应急预案脚本

#!/bin/sh
function fastCgiRestart(){
killall -9 php-cgi
/usr/local/bin/spawn-fcgi -a 127.0.0.1 -p 9000   -u www -f /usr/local/php5/bin/php-cgi
}
function startNginx(){
/usr/local/nginx/sbin/nginx -t
}
while true
do
echo `free | awk ‘{print $3}’` | awk ‘{print $2}’ >a
usemem=`cat a`
echo `free | awk ‘{print $2}’` | awk ‘{print $2}’ >b
countmem=`cat b`
usememcache=”$usemem”
sysmemcache=”$countmem”

if [ $usememcache -gt 511111 ] ; then
fastCgiRestart
startNginx
else
echo ’sys is ok’
fi
sleep 5
done

注释:

# if [ $usememcache -gt 511111 ] ; then   表示但内存达到511111 时候重启php-cgi具体的参数可以依照内存的大小而定

总之这个《应急预案》是主动出击,保证站点的运行。


Categories: linux Tags:

gnome-terminal 错误记录

April 25th, 2010 陈毓端 No comments

今天我的redhat5启动发生如下错误:在为 gnome-terminal 装入或保存配置信息时发生错误。您的某些配置设置可能不能正常工作。

打开终端:rm -rf /tmp/*

重启 ok。

Categories: linux Tags:

mmseg 安装错误 error: ’strncmp’ was not declared in this scope

October 13th, 2009 陈毓端 No comments

mmseg 安装错误

  1. css/UnigramCorpusReader.cpp: In member function 'virtual int css::UnigramCorpusReader::open(const char*, const char*)':
  2. css/UnigramCorpusReader.cpp:89: error: 'strncmp' was not declared in this scope
  3. make[2]: *** [UnigramCorpusReader.lo] Error 1
  4. make[2]: Leaving directory `/lamp/mmseg-0.7.3/src'
  5. make[1]: *** [all-recursive] Error 1
  6. make[1]: Leaving directory `/lamp/mmseg-0.7.3'
  7. make: *** [all] Error 2

解决办法

  1. vim src/css/UnigramCorpusReader.cpp

添加

  1. #include <string.h>

ok!

Categories: c, linux Tags:

一个awk 引发的Imagick 编译问题

July 10th, 2009 陈毓端 No comments

今天在部署服务器的时候  用到图片处理ImageMagick 模块.这个模块也不知道安装了多少次了。一点问题都没有。
在这台服务器上编译 老提示:
checking if ImageMagick version is at least 6.2.4……. configure: error: no. You need at least Imagemagick version 6.2.4 to use Imagick.
见鬼 用
root@ubuntu8server:convert –version
Version: ImageMagick 6.5.2-6 2009-07-10 Q16

我的版本明明在 6.5.2-6   无语

尝试强行关闭错误:
root@ubuntu8server: vim ./configure
#if test “$IMAGEMAGICK_VERSION_MASK” -ge 6002004; then
3959    #                     { echo “$as_me:$LINENO: result: found version $IMAGEMAGICK_VERSION_ORIG” >&5
3960  #echo “${ECHO_T}found version $IMAGEMAGICK_VERSION_ORIG” >&6; }
3961    #             else
3962       #                  { { echo “$as_me:$LINENO: error: no. You need at least Imagemagick version 6.2.4 to               #         use            Imagick.” >&5
3963 # echo “$as_me: error: no. You need at least Imagemagick version 6.2.4 to use Imagick.” >&2;}
3964   #  { (exit 1); exit 1; }; }
3965   #              fi
把这些强行屏蔽了。

继续编译 又提示:

checking if ImageMagick version is at least 6.2.4… checking for MagickWand.h header file… found in /usr/local/ImageMagick/include/ImageMagick/wand/MagickWand.h
checking if PHP version is at least 5.1.3… ./configure: line 4026: awk: command not found
./configure: line 4028: test: -ge: unary operator expected
configure: error: no. You need at least PHP version 5.1.3 to use Imagick.

天哪 我的php 版本是 PHP Version 5.2.6-2

实在无语。

没有办法再仔细分析  报错消息 突然在不起眼的角落发现这么一段提示:
./configure: line 3954: awk: command not found

意思是 找不到 awk 这个命令 。不会吧 这个命令都没有,不至于吧。
试下shell 还真提示 awk: command not found
没有办法 安装awk吧,我安装的是gawk ,它是awk的进化版 ,包涵里awk的功能。
ftp://ftp.gnu.org/gnu/gawk/gawk-3.1.4.tar.gz
tar zvxf gawk-3.1.4.tar.gz
cd gawk-3.1.4
./configure
make && make install

gawk安装完成
执行shell
awk
Usage: awk [POSIX or GNU style options] -f progfile [--] file …
…..
表示成功 ,继续编译imagick

一切顺利 ,扩展成功。

Categories: linux Tags:

ffmpeg 视频截图

July 6th, 2009 陈毓端 No comments

晚上给公司宣传网站做视频上传程序时,突然心血来潮想做个视频截图,以便获取图片,为方便以后给前台做展示使用。
在上一家公司, 也给java的程序员说过ffmpeg。他们也应用了。php也可以使用ffmpeg-php扩展ffmpeg。但是我个人觉的这个效率可能不太高。
还是决定用shell 去执行,或放在服务器端的让任务去执行。

下面简单介绍下安装和使用:


wget http://www.ffmpeg.org/releases/ffmpeg-0.5.tar.bz2
tar -xjvf ffmpeg-0.5.tar.bz2
cd ffmpeg-0.5
./configure --prefix=/usr/local/ffmpeg
make && make install

找个视频
我用的是rmvb格式《叶问》电影,改名为 yw.rmvb

执行:
root@cyd-laptop:~/Desktop# ffmpeg -i 'yw.rmvb' -ss 78 -s 400*200 -f image2 'yw.jpg'

会生成一幅yw.jpg的图片

如果用php调用 就写个简单的shell脚本
#! /bin/sh
ffmpeg -i $1 -ss $2 -s $3 -f image2 $4

参数解释:
-i : 目标文件

-ss: 截取的时间位置(时间段) 格式也可 h:m:s

-s: 生成图片大小 可以直接写 特殊的代号 如`sqcif’==>128×96 详见官方文档

-f: 生成对象格式 又 image2,avi 详见官方文档

最后是文件名称(yw.jpg)。

展示一张截图吧:

yw1

官方地址:
http://www.ffmpeg.org/ffmpeg-doc.html

Categories: linux Tags: , ,

用rsync 备份服务器

July 5th, 2009 陈毓端 2 comments

服务器的内容备份是网站维护很常见的工作。

rsync是linux下常见的第三方备份工具,同时也可用来做网站镜像,服务器内容分离如图片,静态页面等多服务器的分离。

rsync的官方介绍:http://www.samba.org/rsync/

目前最新版本为:Rsync version 3.0.6 released

安装:
wget http://www.samba.org/ftp/rsync/src/rsync-3.0.6.tar.gz
tar zvxf rsync-3.0.6.tar.gz
cd rsync/rsync-3.0.6
./configure
make && make install

配置服务器端:
[root@localhost rsync-3.0.6]# vim /etc/rsyncd.conf

uid = nobody
gid = nobody
use chroot = no
max connections = 4
strict modes =yes
port = 873 //rsync守护进程的一个特权TCP端口873
hosts allow =* //允许的ip地址
#hosts deny = 禁止的ip地址
[blogImages]
path = /data/hi/face/ //备份的图片地址
comment = blogImagesMove //欢迎文字 可以不写
ignore errors
read only = yes
list =yes
auth users = chenyuduan //登录验证
secrets file = /etc/rsync.pwd
transfer logging = yes
pid file = /tmp/rsync/rsyncd.pid
lock file = /tmp/rsync/rsyncd.lock
log file = /tmp/rsync/rsyncd.log

生产认证文件
[root@localhost rsync-3.0.6]# vim /etc/rsync.pwd
chenyuduan:xxxxxxx //[用户名:密码]

改变认证文件的权限
[root@localhost rsync-3.0.6]# chmod 600 /etc/rsync.pwd

启动 rsync
[root@localhost rsync-3.0.6]# /usr/bin/rsync rsyncd –daemon

同样客户端也需要安装rsync 这里就不写了,方法一样。

测试例子
1 在服务器端的 /data/hi/face/(可以改成上面配置定义ptah的目录) 建立写文件
2 在客户端 指向
rsync -vzrtopg –progress 用户名@服务器端的ip地址::模块 同步的目录
如上面配置:
rsync -vzrtopg –progress chenyuduan@xxx.xxx.xxx.xxx::blogImages /data/hi/face/

输入密码
xxxxxx

ok 完毕

Categories: linux Tags: , ,

调整im 机器人的数据发送方式

June 24th, 2009 陈毓端 No comments

之前的im机器人是用c的system调用shell的curl来实现数据传送。测试了两天感觉上不是很舒服。决定调整为c的libcurl API发送数据。
就这个小小的调整,涉及到一堆的修改。
最主要的如下:
1 制作 curl发送的动态链接库 so文件
2 修改im机器人的makefile 文件

curl 发送的so动态连接库:
curl_so_head.h
#include “stdio.h”
#include “curl/curl.h”
#include “stdlib.h”
#include “string.h”
#include “dlfcn.h”
void c2(char *msg,char *from,char *robot); // 设置了msg:消息 from:来源 robot:机器人类型

curl_so.c

#include “curl_so_head.h”
void c2(char *msg,char *from,char *robot)
{
CURL *curl;
CURLcode res;
char *s=”&msg=”;
char *s1=”&from=”;
char *s2=”&robot=”;
char pp[200];
strcpy(pp,s);
strcat(pp,msg);
strcat(pp,s1);
strcat(pp,from);
strcat(pp,s2);
strcat(pp,robot);

curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL,”http://xxxx.xxx.xxx.php”);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS,pp);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}

}
这个是发送调用程序:

void *SoLib;
int (*So)();
SoLib=dlopen(“so_curl.so”,RTLD_LAZY); //so_curl.so是上面操作生成的so文件
So = dlsym( SoLib, “c2″);
(*So)( msg,from,robot); //msg,from,robot表示需要的 消息 来源 robot 机器人类型

修改makefile文件 主要是要在 gcc 后面加上 -ldl 参数 .

ok 目前这项应用就到此吧。后期可能还要加新东西。

Categories: linux, 编程语言 Tags: , , ,