xiaoguozi's Blog
Pay it forword - 我并不觉的自豪,我所尝试的事情都失败了······习惯原本生活的人不容易改变,就算现状很糟,他们也很难改变,在过程中,他们还是放弃了······他们一放弃,大家就都是输家······让爱传出去,很困难,也无法预料,人们需要更细心的观察别人,要随时注意才能保护别人,因为他们未必知道自己要什么·····
官网:http://gearman.org/

跨多种环境部署 Gearman
http://www.ibm.com/developerworks/cn/opensource/os-gearman/index.html
利用开源的Gearman框架构建分布式图片处理平台-张宴
http://blog.s135.com/dips/
监控:
https://github.com/yugene/Gearman-Monitor

一、简介
Gearman是一个分发任务的程序架构,由三部分组成:
Gearman client:提供gearman client API给应用程序调用。API可以使用C,PHP,PERL,MYSQL UDF等待呢个语言,它是请求的发起者。
Gearman job server:将客户端的请求分发到各个gearman worker的调度者,相当于中央控制器,但它不处理具体业务逻辑。
Gearman worker:提供gearman worker API给应用程序调用,具体负责客户端的请求,并将处理结果返回给客户端。
Mogilefs的分布式文件系统的核心就是用gearman实现的。
这个软件的应用场景很多,比如视频网站的视频处理,分布式日志处理,电子邮件处理,文件同步处理,图片处理等等,只要是可以放开,不影响体验和响应的场 景,需要并行进行大量计算和处理的程序都是可以的。Yahoo在60或更多的服务器上使用gearman每天处理600万个作业。新闻聚合器digg构建 了一个相同规模的gearman网络,每天可处理400000个作业。
Gearman不但可以做为任务分发,还可以做为应用方面的负载均衡。可以让worker放在不同的一堆服务器上,也可以启动放在同一个cpu的多个核 上。比如,应用视频转换程序,不希望web服务器来处理视频格式转换,这时,可以在这一堆服务器上进行任务分发,在上面加载worker处理视频格式,对 外的web服务器就不会被视频转换过程影响。而且扩展方便,加一台服务器到任务调度中心,注册成worker即可,这时job server会在请求到来的时候,将请求发送给空闲的worker。还可以运行多个job server,组成ha架构,如果一个job server当掉了,client和worker会自动迁移到另一台job server上。

二、安装
[Job Server (gearmand) -- 172.16.1.183]
1.首先安装libdrizzle
    #yum install libdrizzle libdrizzle-devel
2.安装gearman(两种方法1.yum2.源码包)。(c版的server)
    1)yum安装
    #rpm -ivh http://dl.iuscommunity.org/pub/ius/stable/Redhat/6/x86_64/epel-release-6-5.noarch.rpm
    #yum install -y gearmand
    2)源码包安装
    #cd /opt/build/
    #wget https://launchpad.net/gearmand/trunk/0.34/+download/gearmand-0.34.tar.gz
    #tar zxf gearmand-0.34.tar.gz
    #cd gearmand-0.34
    #./configure
    #make && make install
3.启动gearman服务
    1)yum安装方式
    #/etc/init.d/gearmand start
    2)源码包安装方式
    #/opt/build/gearmand-0.34/sbin/gearmand -d

    #gearmand -vvv -u root
    INFO Starting up
    INFO Listening on :::4730 (6)
    INFO Creating wakeup pipe
    INFO Creating IO thread wakeup pipe
    INFO Adding event for listening socket (6)
    INFO Adding event for wakeup pipe
    INFO Entering main event loop

worker&&client以php方式
[worker --  172.16.1.180]
安装gearmand如上所示

安装 Gearman PHP extension
1.下载gearman-0.8.0.tgz并安装
    #cd /opt/build/
    #wget http://pecl.php.net/get/gearman-0.8.0.tgz
    # yum install -y libgearman-devel.x86_64
    # yum install -y re2c
    #tar zxf gearman-0.8.0.tgz
    #cd gearman-0.8.0.tgz
    #phpize
    # ./configure
    # make && make install
2.编辑php.ini配置文件加载相应模块并使之生效
    # vim /etc/php.ini
    extension = "gearman.so"
3.查看gearman.so模块是否加载
    # php --info | grep gearman
    gearman
    gearman support => enabled
    libgearman version => 0.14
    PWD => /opt/build/gearman-0.8.0
    _SERVER["PWD"] => /opt/build/gearman-0.8.0
    # php -m | grep gearman
    gearman
4.启动job
gearmand -d
如果当前用户是 root 的话,则需要这样操作:
gearmand -d -u root
缺省会使用 4730 端口,下面会用到。
    注意:如果找不到 gearmand 命令的路径,别忘了用 whereis gearmand 确认

[client -- 172.16.1.181]
    安装如work同。如上所示。

三、测试:
[Job Server (gearmand) -- 172.16.1.183]
启动gearmand

以命令行工具来验证gearman的功能
启动 Worker:gearman -h 172.16.1.183 -w -f wc -- wc -l &
运行Client:gearman -h 172.16.1.183 -f wc < /etc/passwd
42
可以看到验证成功。

以php验证gearman的功能
编写 Worker
worker.php 文件内容如下:
<?php
$worker= new GearmanWorker();
$worker->addServer('172.16.1.183', 4730);
$worker->addFunction('reverse', 'my_reverse_function');
while ($worker->work());
function my_reverse_function($job) {
return strrev($job->workload());
}
?>
设置后台运行 work
php worker.php &
编写 Client
client.php 文件内容如下:
<?php
$client= new GearmanClient();
$client->addServer('172.16.1.183', 4730);
echo $client->do('reverse', 'Hello World!'), "\n";
?>
运行 client
php client.php
输出:!dlroW olleH

Q:

I've been trying to get Gearman compiled on CentOS 5.8 all afternoon. Unfortunately I am restricted to this version of CentOS by my CTO and how he has our entire network configured. I think it's simply because we don't have enough resources to upgrade our network... But anyways, the problem at hand.

I have searched through Server Fault, Stack Overflow, Google, and am unable to locate a working solution. What I have below is stuff I have pieced together from my searching.

Searches have told said to install the following via yum:

yum -y install --enablerepo=remi boost141-devel libgearman-devel e2fsprogs-devel e2fsprogs gcc44 gcc-c++ 

To get the Boost headers working correctly I did this:

cp -f /usr/lib/boost141/* /usr/lib/ cp -f /usr/lib64/boost141/* /usr/lib64/ rm -f /usr/include/boost ln -s /usr/include/boost141/boost /usr/include/boost 

With all of the dependancies installed and paths setup I then download and compile gearmand-1.1.2 just fine.

wget -O /tmp/gearmand-1.1.2.tar.gz https://launchpad.net/gearmand/1.2/1.1.2/+download/gearmand-1.1.2.tar.gz cd /tmp && tar zxvf gearmand-1.1.2.tar.gz ./configure && make -j8 && make install 

That works correctly. So now I need to install the Gearman library for PHP. I have attempted through PECL and downloading the source directly, both result in the same error:

checking whether to enable gearman support... yes, shared not found configure: error: Please install libgearman 

What I don't understand is I installed the libgearman-devel package which also installed the core libgearman. The installation installs libgearman-devel-0.14-3.el5.x86_64, libgearman-devel-0.14-3.el5.i386, libgearman-0.14-3.el5.x86_64, and libgearman-0.14-3.el5.i386.

Is it possible the package version is lower than what is required? I'm still poking around with this, but figured I'd throw this up to see if anyone has a solution while I continue to research a fix.

Thanks!


A:

This should do the trick:

export GEARMAN_LIB_DIR=/usr/include/libgearman 
export GEARMAN_INC_DIR=/usr/include/libgearman

That should work, if not you'll have to do some minor edits to config.m4.


other:

http://gearman.org/gearman_php_extension
http://blog.csdn.net/aidenliu/article/details/7406390
http://www.php.net/manual/en/gearmanclient.dobackground.php
http://www.wenzizone.com/2012/09/27/how_to_fix_rpm_filedigests_payloadisxz_is_needed.html
http://www.2cto.com/os/201206/136785.html
http://blog.s135.com/dips
http://blog.csdn.net/hfahe/article/details/5519582
http://hi.baidu.com/sunjiujiu/item/4406281c952cf47a7b5f2594

posted @ 2013-01-07 16:39 小果子 阅读(7825) | 评论 (0)编辑 收藏
http://blog.sina.com.cn/s/blog_6f2caee40100uhj6.html
1.下载最新的boost
http://www.boost.org/
2.解压文件
tar -xzvf boost_1_45_0.tar.gz 
3.编译bjam
进入boost_1_45_0目录中,运行./bootstrap.sh,完成后会得到一个bjam
4.编译boost 
./bjam --with-date_time --with-system --with-regex --with-thread --with-filesystem --with-serialization --with-iostreams --with-math --with-mpi --with-program_options --with-python --with-math --with-signals --layout=tagged install variant=debug,release link=static --runtime-link=static threading=multi stage
5.查看boost
编译完成后,在/usr/local/include/boost就有最新的boost头文件了,在/usr/local/lib就有编译好的.a库文件了。
虽然usr/local/include和/usr/include都有目录,但GCC是先访问/usr/local/include,所以编译完成后,就可以默认使用boost了。
6.测试boost
vi testboost.cpp
#include <iostream>
#include <boost/version.hpp>
int main()
{
    std::cout<<BOOST_VERSION<<std::endl;
    return 0;
}
编译:g++ -o testboost testboost.cpp
posted @ 2013-01-07 16:38 小果子 阅读(2931) | 评论 (1)编辑 收藏
转自: https://www.akii.org/use-awstats-automatic-analysis-nginx-log.html
使用awstats可以分析apache日志,同样也可以分析nginx日志。本文将详细介绍自动定时切割nginx的访问日志,并使用awstats来定时分析nginx的日志的实现方法。

前言

本文中使用的是awstats 7.0版本。
此版本增加了对win7的支持以及一些更新的特性。

New features/improvements:
- Detect Windows 7.
- Can format numbers according to language.
- More mime types.
- Added geoip_asn_maxmind plugin.
- Geoip Maxmind city plugin have now override file capabilities to complete
missing entries in geoip maxmind database.
- Added graphgooglechartapi to use online Google chart api to build graph.
- Can show map of country to report countries when using graphgooglechartapi.
- Part of codes was change to use more functions and have a cleaner code.
- Added parameter to ignore missing log files when merging for a site on
multiple servers where a single server may not have created a log for a given day.
- Update robots database.
- Added Download tracking where certain mime types are defined as downloads
and HTTP status 206 is tracked as download continuation

Awstats 是在 SourceForge 上发展很快的一个基于 Perl 的 WEB 日志分析工具,一个充分的日志分析让 Awstats 显示您下列资料:

  • 访问次数、独特访客人数,
  • 访问时间和上次访问,
  • 使用者认证、最近认证的访问,
  • 每周的高峰时间(页数,点击率,每小时和一周的千字节),
  • 域名/国家的主机访客(页数,点击率,字节,269域名/国家检测, geoip 检测),
  • 主机名单,最近访问和未解析的 IP 地址名单
  • 大多数看过的进出页面,
  • 档案类型,
  • 网站压缩统计表(mod_gzip 或者 mod_deflate),
  • 使用的操作系统 (每个操作系统的页数,点击率 ,字节, 35 OS detected),
  • 使用的浏览器,
  • 机器人访问(检测 319 个机器人),
  • 蠕虫攻击 (5 个蠕虫家族),
  • 搜索引擎,利用关键词检索找到你的地址,
  • HTTP 协议错误(最近查阅没有找到的页面),
  • 其他基于 URL 的个性报导,链接参数, 涉及综合行销领域目的.
  • 贵网站被加入”最喜爱的书签”.次数.
  • 屏幕大小(需要在索引页补充一些 HTML 标签).
  • 浏览器的支持比例: Java, Flash, RealG2 reader, Quicktime reader, WMA reader, PDF reader.
  • 负载平衡服务器比率集群报告.

Awstats 的运行是需要 PERL 环境的支持,从 awstats 的文档来看,它对 Apache HTTP Server 的支持是非常完美的,而当我们把 Web 服务器换成 Nginx 后,要运行 awstats 变得很麻烦。首先 Nginx 本身对 Perl 的支持是比较弱的,甚至官方也不建议使用;另外在日志格式上有需要修改后才能运行。

日志切割

本文主要介绍通过让 awstats 对日志统计的结果生成静态页面,然后通过 Nginx 输出以达到统计 Nginx 访问日志的效果,其中还包括如何让 Nginx 自动切割日志文件。对于nginx的日志,我的做法是按天切割。然后存入日期形式的目录中并压缩。

需要注意的是,nginx的日志应该遵循以下格式,才可以被awstats识别,如定义日志格式

1
2
3
log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

使用日志格式

1
access_log  /home/www/logs/access.log  main;

这里需要有一个小技巧的提示:把log_format这段代码放在你nginx的http的定义段中,可以在下面的每一个server中引用此格式。不必在每个server里面都去定义格式。
本文不讲如何安装nginx,稍后我将发布我的lnmp一键安装包(linux nginx mysql php)。全编译+优化自动化安装,使用php-fpm运行php的fastcgi进程。

我写了一个定时切割日志的脚本。每天0:00开始执行,切割昨天的日志(交由awstats分析),压缩前天的日志(压缩日志可减小存储空间,为防 止awstats没有分析完就被压缩,所以只压缩前天的日志)。如果你的nginx和log文件放的路径和我的不一样,请对应修改。

1
vim cut_log.sh

输入以下内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/bash
# This script run at 00:00
# cut yesterday log and gzip the day before yesterday log files.
# yesterday logs to awstats
 
# The Nginx logs path
logs_path="/home/www/logs/"
date_dir=${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/$(date -d "yesterday" +"%d")/
gzip_date_dir=${logs_path}$(date -d "-2 day" +"%Y")/$(date -d "-2 day" +"%m")/$(date -d "-2 day" +"%d")/
 
mkdir -p $date_dir
mv ${logs_path}*access.log $date_dir
/usr/local/nginx/sbin/nginx -s reopen
/usr/bin/gzip ${gzip_date_dir}*.log

然后让它每天0时起开始进行,执行crontab -e加入以下代码再按:wq保存退出,这里我将此脚本放在/root/下,切记要给它可执行权限(chmod +x cut_log.sh).

1
00 00 * * * /bin/bash /root/cut_log.sh

这样就可以每天凌里自动切割昨天的日志到以日期为目录结构的目录中。可以留存以后查询。留着昨天的日志交给下面的awstats来分析,压缩前天的日志(前天的已经被分析过了)。

安装和配置awstats

下载最新的 awstats,我使用的是迄今为止最新的7.0版本

安装到/usr/local下,这个路径是习惯。大部分人保持的良好习惯。

1
2
3
wget http://awstats.sourceforge.net/files/awstats-7.0.tar.gz
tar -zxvf awstats-7.0.tar.gz
mv awstats-7.0 /usr/local/awstats

修改权限,wget下载下来的包中权限是非root的,赋予过权限之后,.pl的文件也就可以运行了。

1
2
3
4
chown -R root:root /usr/local/awstats
chmod -R =rwX /usr/local/awstats
chmod +x /usr/local/awstats/tools/*.pl
chmod +x /usr/local/awstats/wwwroot/cgi-bin/*.pl

然后执行 tools 目录中的 awstats_configure.pl 配置向导,创建一个新的统计

运行(注意这里要在当前目录运行。否则会有一些关于标准目录的提示。)

1
2
cd /usr/local/awstats/tools
./awstats_configure.pl

将会有如下一些提示:

1
2
3
4
5
6
7
8
9
10
-----> Running OS detected: Linux, BSD or Unix
 
-----> Check for web server install
 
Enter full config file path of your Web server.
Example: /etc/httpd/httpd.conf
Example: /usr/local/apache2/conf/httpd.conf
Example: c:\Program files\apache group\apache\conf\httpd.conf
Config file path ('none' to skip web server setup):
>none #这里添none并回车,因为我们没有使用apache

回车之后下一个选项

1
2
3
4
5
6
7
8
9
10
11
Your web server config file(s) could not be found.
You will need to setup your web server manually to declare AWStats
script as a CGI, if you want to build reports dynamically.
See AWStats setup documentation (file docs/index.html)
 
-----> Update model config file '/usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf'
 File awstats.model.conf updated.
 
-----> Need to create a new config file ?
Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ?

#这里选Y,创建一个新的配置文件

1
2
3
4
5
6
-----> Define config file name to create
What is the name of your web site or profile analysis ?
Example: www.mysite.com
Example: demo
Your web site, virtual server or profile name:
>akii.org  #这里输入你要分析的域名,或是随便一个你易记的配置名并回车

接下来要定义你的配置文件存放的路径,可用默认

1
2
3
4
5
-----> Define config file path
In which directory do you plan to store your config file(s) ?
Default: /etc/awstats
Directory path to store config file(s) (Enter for default):
> #直接回车,使用默认路径/etc/awstats

回车后的提示

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
-----> Create config file '/etc/awstats/awstats.akii.org.conf'
 Config file /etc/awstats/awstats.akii.org.conf created.
 
-----> Add update process inside a scheduler
Sorry, configure.pl does not support automatic add to cron yet.
You can do it manually by adding the following command to your cron:
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=akii.org
Or if you have several config files and prefer having only one command:
/usr/local/awstats/tools/awstats_updateall.pl now
Press ENTER to continue... #按回车继续
 
A SIMPLE config file has been created: /etc/awstats/awstats.akii.org.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'yuyuanchun.com' with command:
> perl awstats.pl -update -config=akii.org
You can also build static report pages for 'akii.org' with command:
> perl awstats.pl -output=pagetype -config=akii.org
 
Press ENTER to finish... #回车完成配置文件的创建

完成配置文件的创建后,我们还要修改一下。因为我们是按天切割的日志,切割完成后交由awstats去分析。并不是让awstats去分时正在时时 增长的也就是正在被写入的日志,这样的好处是不至于遗漏数据,并且分析已经切割完成的日志,更不用担心会有冲突。坏处是我一天切割一次日志,你要等第二天 才能看昨天的一些详细数据。

修改/etc/awstats/awstats.akii.org.conf,执行:

1
vi /etc/awstats/awstats.akii.org.conf

找到

1
LogFile="/var/log/httpd/mylog.log"

修改为:

1
LogFile="/home/www/logs/%YYYY-24/%MM-24/%DD-24/akii.org_access.log"

如果你的日志路径和我的不一样,请修改成对应的日志文件名。以上的完整路径是切割后保存的nginx日志文件。其中%YYYY-24/%MM-24/%DD-24表示年月日都减去24小时,也就是昨天的日志目录。修改完成后按:wq保存退出。

接下来可以测试一下awstats分析日志了(前提是你已经有了切割过的日志,没有的话可以先退行一下切割日志的脚本/root/cut_log.sh)

首先,还要创建一个awstats用于记录数据的目录

1
mkdir -p /var/lib/awstats

然后运行awstats的wwwroot目录中的awatsts.pl来测试一下

1
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=akii.org

你如果看到类似下面的提示就说明配置文件都正确了。

1
2
3
4
5
6
7
8
9
10
11
12
13
Create/Update database for config "/etc/awstats/awstats.akii.org.conf" by AWStats version 7.0 (build 1.964)
From data in log file "/home/www/logs/2010/07/24/akii.org_access.log"...
Phase 1 : First bypass old records, searching new record...
Direct access after last parsed record (after line 43260)
Jumped lines in file: 43260
 Found 43260 already parsed records.
Parsed lines in file: 0
 Found 0 dropped records,
 Found 0 comments,
 Found 0 blank records,
 Found 0 corrupted records,
 Found 0 old records,
 Found 0 new qualified records

统计分析完成后,结果还在 Awstats 的数据库中。在 Apache 上,可以直接打开 Perl 程序的网页查看统计。 但本文开始时已经提到,Nginx 对 Perl 支持并不好,所以我们要换个方法,利用 awstats 的工具将统计的结果生成静态文件,具体的步骤如下:

  • 首先在 webroot 目录下创建一个文件夹。例:/home/www/awstats
  • 写一个脚本,定期执行让 Awstats 把静态页面生成到该目录中

先生成存放awstats生成的静态文件的目录,我这里用的是/home/www/awstats

1
mkdir -p /home/www/awstats

我们来写一个脚本

1
vim /root/awstats.sh

然后输入以下内容

1
2
3
4
5
#!/bin/bash
mkdir -p /home/www/awstats/akii.org
/usr/local/awstats/tools/awstats_buildstaticpages.pl -update  \
-config=akii.org -lang=cn -dir=/home/www/awstats/akii.org  \
-awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl

上述命令的具体意思如下:

  • /usr/local/awstats/tools/awstats_buildstaticpages.pl Awstats 静态页面生成工具
  • -update -config=akii.org 更新配置项
  • -lang=cn 语言为中文
  • -dir=/home/www/awstats 统计结果输出目录
  • -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl Awstats 日志更新程序路径。

然后在你的nginx的配置文件中,在你想要安置awstats或默认的ip或域名的server段中,加入关于awstats和icon的两个目录配置。

如一个完整案例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
server {
listen       80;
server_name  localhost;
root /home/www;
index index.html;
 
location ~ ^/awstats/ {     # awstats  静态页面目录
        root   /home/www/awstats;
        autoindex on; #可以目录浏览你的多个域名的目录用于分析
        index  index.html;
        access_log off;
}
 
location ~ ^/icon/ {             # 图标目录
        root   /usr/local/awstats/wwwroot;
        index  index.html;
        access_log off;
}
}

接下来可以测试一下脚本是否可以正确执行

还是别忘了给它可执行权限

1
2
chmod +x /root/awstats.sh
/root/awstats.sh

如果你看到它生成了一堆网页,那就说明成功了。

输出信息部分例如

1
2
3
4
5
6
Launch update process : "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=akii.org -update -configdir=
......
Build keywords page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=akii.org -staticlinks -lang=cn -output=keywords
Build errors404 page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=akii.org -staticlinks -lang=cn -output=errors404
20 files built.
Main HTML page is 'awstats.akii.org.html'.

然后可以把它加入自动运行了。

配置awstats脚本自动运行

1
crontab -e

加入

1
00 1 * * * /root/awstats.sh

然后保存退出。

这样就可以每天在凌晨自动分割日志,并且开始自动用awstats分析nginx的日志了。

认证访问

如果你想给你的awstats加上访问密码,可以见这里:nginx为目录或网站加上密码认证

原创文章,写的辛苦。如果你要转载,请保留出处及链接。

参考资料:http://www.ibm.com/developerworks/cn/linux/l-cn-awstats-nginx/index.html

posted @ 2013-01-06 18:05 小果子 阅读(3276) | 评论 (0)编辑 收藏

Fast-CGI:
./configure --prefix=/usr/local/php --enable-fastcgi --enable-force-cgi-redirect --with-config-file-path=/etc --with-zlib --with-mysql --with-xml --with-gd --enable-gd-native-ttf --enable-gd-jis-conv --with-freetype-dir --with-jpeg-dir --with-png-dir --enable-mbstring

PHP4-Server:
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql --with-config-file-path=/etc --with-gd --enable-gd-native-ttf --enable-gd-jis-conv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --enable-xml --enable-mbstring

PHP4-Max:
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --mandir=/usr/share/man --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php/etc --with-openssl=/usr/local/openssl-0.9.7e --with-gd --enable-gd-native-ttf --enable-gd-jis-conv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-bz2 --with-inifile --with-hyperwave --enable-xml --enable-track-vars --enable-dba --enable-dbase --enable-filepro --enable-ftp --enable-versioning --enable-memory-limit --enable-calendar --enable-session --enable-sockets --enable-sysmsg --enable-sysvsem --enable-sysvshm --enable-tokenizer --enable-overload --enable-ctype --enable-sigchild --enable-magic-quotes --enable-roxen-zts --enable-fastcgi --enable-dbx --enable-dio --enable-shmop --enable-mbstring

PHP5-Server:
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-zlib-dir --with-bz2 --with-tiff-dir --with-libxml-dir --with-gd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-ttf --enable-mbstring --with-mysql=/usr/lib/mysql --with-config-file-path=/etc --disable-ipv6 --enable-gd-native-ttf

PHP5-Standard:
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --mandir=/usr/share/man --with-openssl=/usr/local/openssl-0.9.7e --with-zlib --with-bz2 --with-tiff-dir --with-libxml-dir --enable-dio --enable-ftp --with-gd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-bz2-dir --with-ttf --enable-mbstring --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php/etc --disable-ipv6 --enable-gd-native-ttf

PHP5-Max:
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --mandir=/usr/share/man --with-openssl=/usr/local/openssl-0.9.7e --with-zlib --with-bz2 --with-tiff-dir --with-libxml-dir --enable-dio --enable-ftp --with-gd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-bz2-dir --with-ttf --with-inifile --enable-dba --enable-dbase --enable-filepro --enable-versioning --enable-memory-limit --enable-calendar --enable-sockets --enable-sysvsem --enable-sigchild --enable-magic-quotes --enable-roxen-zts --enable-fastcgi --enable-dbx --enable-shmop --enable-mbstring --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php/etc --disable-ipv6 --enable-gd-native-ttf

posted @ 2013-01-05 17:37 小果子 阅读(317) | 评论 (0)编辑 收藏
codeblocks很轻巧也很好用对于c/c++编写在linux下相对于eclipse.
于是乎下了一个,由于是乎想写几个sample玩玩。于是乎拿<unix 高级环境编程> sample来测试。

于是乎建了一个c++ project.
<unix 高级环境编程>里的例子有个apue.h头文件。不是系统自带的。是作者自己写的几个util函数。
网上找编译apue.h头文件一大片。但是都是考来考去,不过核心的都差不多。不过有个方法是编译完
libapue.a静态库后,还需要在apute.h头文件尾巴加"error.c"。。完了拷贝error.c实现到目录。。
看完后。我惊了呆。。好吧。。这库还能这么用。。

既然libapue.a编译完后,apue.h里的函数声明在libapue.a都已经实现,当然包括err_xxx系列的。所以
在apue.h加"error.c"是画蛇添足。。这里不推荐此方法。。

我的环境是mint14下, IDE用的是 codeblocks. 方法中基本都有这么一个步骤:
先在这个网站 http://www.apuebook.com/src.tar.gz 下载tar.gz格式的源码包,然后解压至某个目录,比如说/home/xiaoguozi/下,然后进入目录apue.2e,把文件 Make.defines.linux 中的 WKDIR=/home/xxx/apue.2e 修改为 WKDIR=/home/xiaoguozi/apue.2e ,然后再进入apue.2e目录下的std目录,打开linux.mk,将里面的nawk全部替换为awk
如果用vim编辑的话,可以用 :1,%s/nawk/awk/g 替换字符窜

完了make, 过程中,还遇到了几个问题。(mint下,其他os不太清楚)

1: /usr/include/bits/timex.h:31:7:error: expect ':' , ',' , ';' , '}' or '__attribute__'   
 apue.2e/ipp/ipp.h中 #define status u.st 与 timex.h中的 status 冲突,更改 #define Status u.st

  

2:ARG_MAX 未定义

   在include/apue.h中加入 #define ARG_MAX 4096

   在threadctl/getenv1.c 加入 #include "../include/apue.h"

   在threadctl/getenv3.c 加入 #include "../include/apue.h"

完了之后,make应该就可以成功了

完了在codeblocks项目里引用刚编译完的库,有几个方法:
1)将编译完的库,头文件apue.h拷贝/usr/include,库文件libapue.a拷贝到/usr/lib下,这个是系统目录,gcc编译的时候会在这目录搜寻
2)在项目属性添加静态库引用
添加头文件:依次点击project->bulid options->Search directories,在该标签页中点击Compiler,单击Add按钮添加头文件路径
添加静态库路径:依次点击project->bulid options->Linker setting,在该标签页中点击Add按钮添加静态库路径。

如果之前你建的是c project的话,应该就可以顺利编译通过了,但是对于建立c++的project,仍然提示链接错误,找不到函数实现,
原因是libapue.a是c库,用g++编译的时候要引用c库的话,因为c++编译的时候会在函数加一些额外字符,所以当然会链接错误。
解决也简单的在函数库前加 extern "C",或者直接把apue.h用extern "C"包含,不清楚的补下相应知识。

加点额外的知识关于gcc/g++:
gcc和g++的区别

误区一:gcc只能编译c代码,g++只能编译c++代码
两者都可以,但是请注意:
1.后缀为.c的,gcc把它当作是C程序,而g++当作是c++程序;后缀为.cpp的,两者都会认为是c++程序,注意,虽然c++是c的超集,但是两者对语法的要求是有区别的。C++的语法规则更加严谨一些。
2.编译阶段,g++会调用gcc,对于c++代码,两者是等价的,但是因为gcc命令不能自动和C++程序使用的库联接,所以通常用g++来完成链接,为了统一起见,干脆编译/链接统统用g++了,这就给人一种错觉,好像cpp程序只能用g++似的。

误区二:gcc不会定义__cplusplus宏,而g++会
实际上,这个宏只是标志着编译器将会把代码按C还是C++语法来解释,如上所述,如果后缀为.c,并且采用gcc编译器,则该宏就是未定义的,否则,就是已定义。

误区三:编译只能用gcc,链接只能用g++
严格来说,这句话不算错误,但是它混淆了概念,应该这样说:编译可以用gcc/g++,而链接可以用g++或者gcc -lstdc++。因为gcc命令不能自动和C++程序使用的库联接,所以通常使用g++来完成联接。但在编译阶段,g++会自动调用gcc,二者等价。

gcc和g++的区别 我们在编译c/c++代码的时候,有人用gcc,有人用g++,于是各种说法都来了,譬如c代码用gcc,而c++代码用g++,或者说编译用 gcc,链接用g++,一时也不知哪个说法正确,如果再遇上个extern "C",分歧就更多了,这里我想作个了结,毕竟知识的目的是令人更清醒,而不是更糊涂。

posted @ 2013-01-04 20:23 小果子 阅读(644) | 评论 (0)编辑 收藏
仅列出标题
共58页: First 4 5 6 7 8 9 10 11 12 Last