• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            xiaoguozi's Blog
            Pay it forword - 我并不覺(jué)的自豪,我所嘗試的事情都失敗了······習(xí)慣原本生活的人不容易改變,就算現(xiàn)狀很糟,他們也很難改變,在過(guò)程中,他們還是放棄了······他們一放棄,大家就都是輸家······讓愛(ài)傳出去,很困難,也無(wú)法預(yù)料,人們需要更細(xì)心的觀察別人,要隨時(shí)注意才能保護(hù)別人,因?yàn)樗麄兾幢刂雷约阂裁础ぁぁぁぁ?/span>
            官網(wǎng):http://gearman.org/

            跨多種環(huán)境部署 Gearman
            http://www.ibm.com/developerworks/cn/opensource/os-gearman/index.html
            利用開(kāi)源的Gearman框架構(gòu)建分布式圖片處理平臺(tái)-張宴
            http://blog.s135.com/dips/
            監(jiān)控:
            https://github.com/yugene/Gearman-Monitor

            一、簡(jiǎn)介
            Gearman是一個(gè)分發(fā)任務(wù)的程序架構(gòu),由三部分組成:
            Gearman client:提供gearman client API給應(yīng)用程序調(diào)用。API可以使用C,PHP,PERL,MYSQL UDF等待呢個(gè)語(yǔ)言,它是請(qǐng)求的發(fā)起者。
            Gearman job server:將客戶端的請(qǐng)求分發(fā)到各個(gè)gearman worker的調(diào)度者,相當(dāng)于中央控制器,但它不處理具體業(yè)務(wù)邏輯。
            Gearman worker:提供gearman worker API給應(yīng)用程序調(diào)用,具體負(fù)責(zé)客戶端的請(qǐng)求,并將處理結(jié)果返回給客戶端。
            Mogilefs的分布式文件系統(tǒng)的核心就是用gearman實(shí)現(xiàn)的。
            這個(gè)軟件的應(yīng)用場(chǎng)景很多,比如視頻網(wǎng)站的視頻處理,分布式日志處理,電子郵件處理,文件同步處理,圖片處理等等,只要是可以放開(kāi),不影響體驗(yàn)和響應(yīng)的場(chǎng) 景,需要并行進(jìn)行大量計(jì)算和處理的程序都是可以的。Yahoo在60或更多的服務(wù)器上使用gearman每天處理600萬(wàn)個(gè)作業(yè)。新聞聚合器digg構(gòu)建 了一個(gè)相同規(guī)模的gearman網(wǎng)絡(luò),每天可處理400000個(gè)作業(yè)。
            Gearman不但可以做為任務(wù)分發(fā),還可以做為應(yīng)用方面的負(fù)載均衡。可以讓worker放在不同的一堆服務(wù)器上,也可以啟動(dòng)放在同一個(gè)cpu的多個(gè)核 上。比如,應(yīng)用視頻轉(zhuǎn)換程序,不希望web服務(wù)器來(lái)處理視頻格式轉(zhuǎn)換,這時(shí),可以在這一堆服務(wù)器上進(jìn)行任務(wù)分發(fā),在上面加載worker處理視頻格式,對(duì) 外的web服務(wù)器就不會(huì)被視頻轉(zhuǎn)換過(guò)程影響。而且擴(kuò)展方便,加一臺(tái)服務(wù)器到任務(wù)調(diào)度中心,注冊(cè)成worker即可,這時(shí)job server會(huì)在請(qǐng)求到來(lái)的時(shí)候,將請(qǐng)求發(fā)送給空閑的worker。還可以運(yùn)行多個(gè)job server,組成ha架構(gòu),如果一個(gè)job server當(dāng)?shù)袅耍琧lient和worker會(huì)自動(dòng)遷移到另一臺(tái)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.啟動(dòng)gearman服務(wù)
                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配置文件加載相應(yīng)模塊并使之生效
                # 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.啟動(dòng)job
            gearmand -d
            如果當(dāng)前用戶是 root 的話,則需要這樣操作:
            gearmand -d -u root
            缺省會(huì)使用 4730 端口,下面會(huì)用到。
                注意:如果找不到 gearmand 命令的路徑,別忘了用 whereis gearmand 確認(rèn)

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

            三、測(cè)試:
            [Job Server (gearmand) -- 172.16.1.183]
            啟動(dòng)gearmand

            以命令行工具來(lái)驗(yàn)證gearman的功能
            啟動(dòng) Worker:gearman -h 172.16.1.183 -w -f wc -- wc -l &
            運(yùn)行Client:gearman -h 172.16.1.183 -f wc < /etc/passwd
            42
            可以看到驗(yàn)證成功。

            以php驗(yàn)證gearman的功能
            編寫(xiě) Worker
            worker.php 文件內(nèi)容如下:
            <?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());
            }
            ?>
            設(shè)置后臺(tái)運(yùn)行 work
            php worker.php &
            編寫(xiě) Client
            client.php 文件內(nèi)容如下:
            <?php
            $client= new GearmanClient();
            $client->addServer('172.16.1.183', 4730);
            echo $client->do('reverse', 'Hello World!'), "\n";
            ?>
            運(yù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 小果子 閱讀(7889) | 評(píng)論 (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
            進(jìn)入boost_1_45_0目錄中,運(yùn)行./bootstrap.sh,完成后會(huì)得到一個(gè)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庫(kù)文件了。
            雖然usr/local/include和/usr/include都有目錄,但GCC是先訪問(wèn)/usr/local/include,所以編譯完成后,就可以默認(rèn)使用boost了。
            6.測(cè)試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 小果子 閱讀(2982) | 評(píng)論 (1)編輯 收藏
            轉(zhuǎn)自: https://www.akii.org/use-awstats-automatic-analysis-nginx-log.html
            使用awstats可以分析apache日志,同樣也可以分析nginx日志。本文將詳細(xì)介紹自動(dòng)定時(shí)切割nginx的訪問(wèn)日志,并使用awstats來(lái)定時(shí)分析nginx的日志的實(shí)現(xiàn)方法。

            前言

            本文中使用的是awstats 7.0版本。
            此版本增加了對(duì)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 上發(fā)展很快的一個(gè)基于 Perl 的 WEB 日志分析工具,一個(gè)充分的日志分析讓 Awstats 顯示您下列資料:

            • 訪問(wèn)次數(shù)、獨(dú)特訪客人數(shù),
            • 訪問(wèn)時(shí)間和上次訪問(wèn),
            • 使用者認(rèn)證、最近認(rèn)證的訪問(wèn),
            • 每周的高峰時(shí)間(頁(yè)數(shù),點(diǎn)擊率,每小時(shí)和一周的千字節(jié)),
            • 域名/國(guó)家的主機(jī)訪客(頁(yè)數(shù),點(diǎn)擊率,字節(jié),269域名/國(guó)家檢測(cè), geoip 檢測(cè)),
            • 主機(jī)名單,最近訪問(wèn)和未解析的 IP 地址名單
            • 大多數(shù)看過(guò)的進(jìn)出頁(yè)面,
            • 檔案類(lèi)型,
            • 網(wǎng)站壓縮統(tǒng)計(jì)表(mod_gzip 或者 mod_deflate),
            • 使用的操作系統(tǒng) (每個(gè)操作系統(tǒng)的頁(yè)數(shù),點(diǎn)擊率 ,字節(jié), 35 OS detected),
            • 使用的瀏覽器,
            • 機(jī)器人訪問(wèn)(檢測(cè) 319 個(gè)機(jī)器人),
            • 蠕蟲(chóng)攻擊 (5 個(gè)蠕蟲(chóng)家族),
            • 搜索引擎,利用關(guān)鍵詞檢索找到你的地址,
            • HTTP 協(xié)議錯(cuò)誤(最近查閱沒(méi)有找到的頁(yè)面),
            • 其他基于 URL 的個(gè)性報(bào)導(dǎo),鏈接參數(shù), 涉及綜合行銷(xiāo)領(lǐng)域目的.
            • 貴網(wǎng)站被加入”最喜愛(ài)的書(shū)簽”.次數(shù).
            • 屏幕大小(需要在索引頁(yè)補(bǔ)充一些 HTML 標(biāo)簽).
            • 瀏覽器的支持比例: Java, Flash, RealG2 reader, Quicktime reader, WMA reader, PDF reader.
            • 負(fù)載平衡服務(wù)器比率集群報(bào)告.

            Awstats 的運(yùn)行是需要 PERL 環(huán)境的支持,從 awstats 的文檔來(lái)看,它對(duì) Apache HTTP Server 的支持是非常完美的,而當(dāng)我們把 Web 服務(wù)器換成 Nginx 后,要運(yùn)行 awstats 變得很麻煩。首先 Nginx 本身對(duì) Perl 的支持是比較弱的,甚至官方也不建議使用;另外在日志格式上有需要修改后才能運(yùn)行。

            日志切割

            本文主要介紹通過(guò)讓 awstats 對(duì)日志統(tǒng)計(jì)的結(jié)果生成靜態(tài)頁(yè)面,然后通過(guò) Nginx 輸出以達(dá)到統(tǒng)計(jì) Nginx 訪問(wèn)日志的效果,其中還包括如何讓 Nginx 自動(dòng)切割日志文件。對(duì)于nginx的日志,我的做法是按天切割。然后存入日期形式的目錄中并壓縮。

            需要注意的是,nginx的日志應(yīng)該遵循以下格式,才可以被awstats識(shí)別,如定義日志格式

            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;

            這里需要有一個(gè)小技巧的提示:把log_format這段代碼放在你nginx的http的定義段中,可以在下面的每一個(gè)server中引用此格式。不必在每個(gè)server里面都去定義格式。
            本文不講如何安裝nginx,稍后我將發(fā)布我的lnmp一鍵安裝包(linux nginx mysql php)。全編譯+優(yōu)化自動(dòng)化安裝,使用php-fpm運(yùn)行php的fastcgi進(jìn)程。

            我寫(xiě)了一個(gè)定時(shí)切割日志的腳本。每天0:00開(kāi)始執(zhí)行,切割昨天的日志(交由awstats分析),壓縮前天的日志(壓縮日志可減小存儲(chǔ)空間,為防 止awstats沒(méi)有分析完就被壓縮,所以只壓縮前天的日志)。如果你的nginx和log文件放的路徑和我的不一樣,請(qǐng)對(duì)應(yīng)修改。

            1
            vim cut_log.sh

            輸入以下內(nèi)容

            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時(shí)起開(kāi)始進(jìn)行,執(zhí)行crontab -e加入以下代碼再按:wq保存退出,這里我將此腳本放在/root/下,切記要給它可執(zhí)行權(quán)限(chmod +x cut_log.sh).

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

            這樣就可以每天凌里自動(dòng)切割昨天的日志到以日期為目錄結(jié)構(gòu)的目錄中。可以留存以后查詢(xún)。留著昨天的日志交給下面的awstats來(lái)分析,壓縮前天的日志(前天的已經(jīng)被分析過(guò)了)。

            安裝和配置awstats

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

            安裝到/usr/local下,這個(gè)路徑是習(xí)慣。大部分人保持的良好習(xí)慣。

            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

            修改權(quán)限,wget下載下來(lái)的包中權(quán)限是非root的,賦予過(guò)權(quán)限之后,.pl的文件也就可以運(yùn)行了。

            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

            然后執(zhí)行 tools 目錄中的 awstats_configure.pl 配置向?qū)В瑒?chuàng)建一個(gè)新的統(tǒng)計(jì)

            運(yùn)行(注意這里要在當(dāng)前目錄運(yùn)行。否則會(huì)有一些關(guān)于標(biāo)準(zhǔn)目錄的提示。)

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

            將會(huì)有如下一些提示:

            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并回車(chē),因?yàn)槲覀儧](méi)有使用apache

            回車(chē)之后下一個(gè)選項(xiàng)

            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,創(chuàng)建一個(gè)新的配置文件

            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  #這里輸入你要分析的域名,或是隨便一個(gè)你易記的配置名并回車(chē)

            接下來(lái)要定義你的配置文件存放的路徑,可用默認(rèn)

            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):
            > #直接回車(chē),使用默認(rèn)路徑/etc/awstats

            回車(chē)后的提示

            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... #按回車(chē)?yán)^續(xù)
             
            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... #回車(chē)完成配置文件的創(chuàng)建

            完成配置文件的創(chuàng)建后,我們還要修改一下。因?yàn)槲覀兪前刺烨懈畹娜罩荆懈钔瓿珊蠼挥蒩wstats去分析。并不是讓awstats去分時(shí)正在時(shí)時(shí) 增長(zhǎng)的也就是正在被寫(xiě)入的日志,這樣的好處是不至于遺漏數(shù)據(jù),并且分析已經(jīng)切割完成的日志,更不用擔(dān)心會(huì)有沖突。壞處是我一天切割一次日志,你要等第二天 才能看昨天的一些詳細(xì)數(shù)據(jù)。

            修改/etc/awstats/awstats.akii.org.conf,執(zhí)行:

            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"

            如果你的日志路徑和我的不一樣,請(qǐng)修改成對(duì)應(yīng)的日志文件名。以上的完整路徑是切割后保存的nginx日志文件。其中%YYYY-24/%MM-24/%DD-24表示年月日都減去24小時(shí),也就是昨天的日志目錄。修改完成后按:wq保存退出。

            接下來(lái)可以測(cè)試一下awstats分析日志了(前提是你已經(jīng)有了切割過(guò)的日志,沒(méi)有的話可以先退行一下切割日志的腳本/root/cut_log.sh)

            首先,還要?jiǎng)?chuàng)建一個(gè)awstats用于記錄數(shù)據(jù)的目錄

            1
            mkdir -p /var/lib/awstats

            然后運(yùn)行awstats的wwwroot目錄中的awatsts.pl來(lái)測(cè)試一下

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

            你如果看到類(lèi)似下面的提示就說(shuō)明配置文件都正確了。

            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

            統(tǒng)計(jì)分析完成后,結(jié)果還在 Awstats 的數(shù)據(jù)庫(kù)中。在 Apache 上,可以直接打開(kāi) Perl 程序的網(wǎng)頁(yè)查看統(tǒng)計(jì)。 但本文開(kāi)始時(shí)已經(jīng)提到,Nginx 對(duì) Perl 支持并不好,所以我們要換個(gè)方法,利用 awstats 的工具將統(tǒng)計(jì)的結(jié)果生成靜態(tài)文件,具體的步驟如下:

            • 首先在 webroot 目錄下創(chuàng)建一個(gè)文件夾。例:/home/www/awstats
            • 寫(xiě)一個(gè)腳本,定期執(zhí)行讓 Awstats 把靜態(tài)頁(yè)面生成到該目錄中

            先生成存放awstats生成的靜態(tài)文件的目錄,我這里用的是/home/www/awstats

            1
            mkdir -p /home/www/awstats

            我們來(lái)寫(xiě)一個(gè)腳本

            1
            vim /root/awstats.sh

            然后輸入以下內(nèi)容

            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 靜態(tài)頁(yè)面生成工具
            • -update -config=akii.org 更新配置項(xiàng)
            • -lang=cn 語(yǔ)言為中文
            • -dir=/home/www/awstats 統(tǒng)計(jì)結(jié)果輸出目錄
            • -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl Awstats 日志更新程序路徑。

            然后在你的nginx的配置文件中,在你想要安置awstats或默認(rèn)的ip或域名的server段中,加入關(guān)于awstats和icon的兩個(gè)目錄配置。

            如一個(gè)完整案例:

            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  靜態(tài)頁(yè)面目錄
                    root   /home/www/awstats;
                    autoindex on; #可以目錄瀏覽你的多個(gè)域名的目錄用于分析
                    index  index.html;
                    access_log off;
            }
             
            location ~ ^/icon/ {             # 圖標(biāo)目錄
                    root   /usr/local/awstats/wwwroot;
                    index  index.html;
                    access_log off;
            }
            }

            接下來(lái)可以測(cè)試一下腳本是否可以正確執(zhí)行

            還是別忘了給它可執(zhí)行權(quán)限

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

            如果你看到它生成了一堆網(wǎng)頁(yè),那就說(shuō)明成功了。

            輸出信息部分例如

            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'.

            然后可以把它加入自動(dòng)運(yùn)行了。

            配置awstats腳本自動(dòng)運(yùn)行

            1
            crontab -e

            加入

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

            然后保存退出。

            這樣就可以每天在凌晨自動(dòng)分割日志,并且開(kāi)始自動(dòng)用awstats分析nginx的日志了。

            認(rèn)證訪問(wèn)

            如果你想給你的awstats加上訪問(wèn)密碼,可以見(jiàn)這里:nginx為目錄或網(wǎng)站加上密碼認(rèn)證

            原創(chuàng)文章,寫(xiě)的辛苦。如果你要轉(zhuǎn)載,請(qǐng)保留出處及鏈接。

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

            posted @ 2013-01-06 18:05 小果子 閱讀(3305) | 評(píng)論 (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 小果子 閱讀(340) | 評(píng)論 (0)編輯 收藏
            codeblocks很輕巧也很好用對(duì)于c/c++編寫(xiě)在linux下相對(duì)于eclipse.
            于是乎下了一個(gè),由于是乎想寫(xiě)幾個(gè)sample玩玩。于是乎拿<unix 高級(jí)環(huán)境編程> sample來(lái)測(cè)試。

            于是乎建了一個(gè)c++ project.
            <unix 高級(jí)環(huán)境編程>里的例子有個(gè)apue.h頭文件。不是系統(tǒng)自帶的。是作者自己寫(xiě)的幾個(gè)util函數(shù)。
            網(wǎng)上找編譯apue.h頭文件一大片。但是都是考來(lái)考去,不過(guò)核心的都差不多。不過(guò)有個(gè)方法是編譯完
            libapue.a靜態(tài)庫(kù)后,還需要在apute.h頭文件尾巴加"error.c"。。完了拷貝error.c實(shí)現(xiàn)到目錄。。
            看完后。我驚了呆。。好吧。。這庫(kù)還能這么用。。

            既然libapue.a編譯完后,apue.h里的函數(shù)聲明在libapue.a都已經(jīng)實(shí)現(xiàn),當(dāng)然包括err_xxx系列的。所以
            在apue.h加"error.c"是畫(huà)蛇添足。。這里不推薦此方法。。

            我的環(huán)境是mint14下, IDE用的是 codeblocks. 方法中基本都有這么一個(gè)步驟:
            先在這個(gè)網(wǎng)站 http://www.apuebook.com/src.tar.gz 下載tar.gz格式的源碼包,然后解壓至某個(gè)目錄,比如說(shuō)/home/xiaoguozi/下,然后進(jìn)入目錄apue.2e,把文件 Make.defines.linux 中的 WKDIR=/home/xxx/apue.2e 修改為 WKDIR=/home/xiaoguozi/apue.2e ,然后再進(jìn)入apue.2e目錄下的std目錄,打開(kāi)linux.mk,將里面的nawk全部替換為awk
            如果用vim編輯的話,可以用 :1,%s/nawk/awk/g 替換字符竄

            完了make, 過(guò)程中,還遇到了幾個(gè)問(wèn)題。(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應(yīng)該就可以成功了

            完了在codeblocks項(xiàng)目里引用剛編譯完的庫(kù),有幾個(gè)方法:
            1)將編譯完的庫(kù),頭文件apue.h拷貝/usr/include,庫(kù)文件libapue.a拷貝到/usr/lib下,這個(gè)是系統(tǒng)目錄,gcc編譯的時(shí)候會(huì)在這目錄搜尋
            2)在項(xiàng)目屬性添加靜態(tài)庫(kù)引用
            添加頭文件:依次點(diǎn)擊project->bulid options->Search directories,在該標(biāo)簽頁(yè)中點(diǎn)擊Compiler,單擊Add按鈕添加頭文件路徑
            添加靜態(tài)庫(kù)路徑:依次點(diǎn)擊project->bulid options->Linker setting,在該標(biāo)簽頁(yè)中點(diǎn)擊Add按鈕添加靜態(tài)庫(kù)路徑。

            如果之前你建的是c project的話,應(yīng)該就可以順利編譯通過(guò)了,但是對(duì)于建立c++的project,仍然提示鏈接錯(cuò)誤,找不到函數(shù)實(shí)現(xiàn),
            原因是libapue.a是c庫(kù),用g++編譯的時(shí)候要引用c庫(kù)的話,因?yàn)閏++編譯的時(shí)候會(huì)在函數(shù)加一些額外字符,所以當(dāng)然會(huì)鏈接錯(cuò)誤。
            解決也簡(jiǎn)單的在函數(shù)庫(kù)前加 extern "C",或者直接把a(bǔ)pue.h用extern "C"包含,不清楚的補(bǔ)下相應(yīng)知識(shí)。

            加點(diǎn)額外的知識(shí)關(guān)于gcc/g++:
            gcc和g++的區(qū)別

            誤區(qū)一:gcc只能編譯c代碼,g++只能編譯c++代碼
            兩者都可以,但是請(qǐng)注意:
            1.后綴為.c的,gcc把它當(dāng)作是C程序,而g++當(dāng)作是c++程序;后綴為.cpp的,兩者都會(huì)認(rèn)為是c++程序,注意,雖然c++是c的超集,但是兩者對(duì)語(yǔ)法的要求是有區(qū)別的。C++的語(yǔ)法規(guī)則更加嚴(yán)謹(jǐn)一些。
            2.編譯階段,g++會(huì)調(diào)用gcc,對(duì)于c++代碼,兩者是等價(jià)的,但是因?yàn)間cc命令不能自動(dòng)和C++程序使用的庫(kù)聯(lián)接,所以通常用g++來(lái)完成鏈接,為了統(tǒng)一起見(jiàn),干脆編譯/鏈接統(tǒng)統(tǒng)用g++了,這就給人一種錯(cuò)覺(jué),好像cpp程序只能用g++似的。

            誤區(qū)二:gcc不會(huì)定義__cplusplus宏,而g++會(huì)
            實(shí)際上,這個(gè)宏只是標(biāo)志著編譯器將會(huì)把代碼按C還是C++語(yǔ)法來(lái)解釋?zhuān)缟纤觯绻缶Y為.c,并且采用gcc編譯器,則該宏就是未定義的,否則,就是已定義。

            誤區(qū)三:編譯只能用gcc,鏈接只能用g++
            嚴(yán)格來(lái)說(shuō),這句話不算錯(cuò)誤,但是它混淆了概念,應(yīng)該這樣說(shuō):編譯可以用gcc/g++,而鏈接可以用g++或者gcc -lstdc++。因?yàn)間cc命令不能自動(dòng)和C++程序使用的庫(kù)聯(lián)接,所以通常使用g++來(lái)完成聯(lián)接。但在編譯階段,g++會(huì)自動(dòng)調(diào)用gcc,二者等價(jià)。

            gcc和g++的區(qū)別 我們?cè)诰幾gc/c++代碼的時(shí)候,有人用gcc,有人用g++,于是各種說(shuō)法都來(lái)了,譬如c代碼用gcc,而c++代碼用g++,或者說(shuō)編譯用 gcc,鏈接用g++,一時(shí)也不知哪個(gè)說(shuō)法正確,如果再遇上個(gè)extern "C",分歧就更多了,這里我想作個(gè)了結(jié),畢竟知識(shí)的目的是令人更清醒,而不是更糊涂。

            posted @ 2013-01-04 20:23 小果子 閱讀(688) | 評(píng)論 (0)編輯 收藏
            僅列出標(biāo)題
            共58頁(yè): First 4 5 6 7 8 9 10 11 12 Last 
            久久99精品九九九久久婷婷| 国产—久久香蕉国产线看观看 | 久久天堂电影网| a高清免费毛片久久| 久久最近最新中文字幕大全| 精品久久久无码中文字幕| 精品久久久久久国产牛牛app | 久久发布国产伦子伦精品| 国产精品视频久久| 久久国内免费视频| 99久久免费国产特黄| 亚洲精品NV久久久久久久久久 | 久久99精品久久久久久不卡| 伊人久久无码精品中文字幕| 国产日产久久高清欧美一区| 欧美日韩精品久久免费| 丁香五月综合久久激情| 精品久久久噜噜噜久久久| 亚洲AV无码1区2区久久| 国产69精品久久久久777| 久久精品国产亚洲Aⅴ香蕉 | 色偷偷88888欧美精品久久久| 精品99久久aaa一级毛片| av午夜福利一片免费看久久| 久久久久波多野结衣高潮| 久久精品无码专区免费| 免费观看久久精彩视频| 久久香综合精品久久伊人| 人妻中文久久久久| 久久亚洲欧美日本精品| 99久久99久久久精品齐齐 | 久久99精品国产麻豆| 久久精品国产久精国产果冻传媒| 97超级碰碰碰碰久久久久| 久久综合综合久久97色| 日本道色综合久久影院| 亚洲国产成人久久综合碰碰动漫3d| 久久综合给久久狠狠97色| 7777精品久久久大香线蕉 | 久久久久亚洲av毛片大| 久久精品国产色蜜蜜麻豆|