官網: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 小果子 閱讀(7880) |
評論 (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 小果子 閱讀(2975) |
評論 (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 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 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 | 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 小果子 閱讀(3299) |
評論 (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 小果子 閱讀(334) |
評論 (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 小果子 閱讀(681) |
評論 (0) |
編輯 收藏