在Linux上快速搭建计数器

   对外发布网站会有人不断访问,那么怎么来统计访问网站的人数呢?目前有很多方法,例如流量统计和IP统计等。这里介绍的是计数器(Counter)。通过计数器,网站人员能及时掌握浏览网站的人数。现在互联网上的很多服务器采用的都是Linux操作系统,那么如何在Linux上快速搭建属于自己的计数器呢?

    安装与配置

    在Linux平台上有wwwcount-2.6-3.i386.rpm软件包,可搭建基本的计数器,而且很简单。该软件包的安装和配置方法如下:

    1.首先下载wwwcount-2.6-6.i386.rpm。网址是http: //speakeasy.rpmfind.net/linux/RPM/PLD/dists/ra/PLD/i386/PLD/RPMS/wwwcount -2.6-6.i386.html。输入下面的命令:
    #rpm -Uvh wwwcount-2.6-6.i386.rpm

    此时,系统会自动在/var/lib/wwwcount/data目录下打开一个my.dat文件。用户需要设置my.dat文件的权限,并在/var/www/html中打开一个范例文件wc-example.html。用户只要察看wc-example.html文件的源代码,即可将计数器挂上网站。

    2.接着下载wwwcount2.6.tar.gz文件。网址是http: //www.muquit.com/muquit/software/Count/Count2.6/Count2.6/download/src/wwwcount2.6.tar.gz。下载完后,就开始安装、设置与使用了。

    3.登录Linux主机,进入/usr/local/src目录,对wwwcount2.6.tar.gz文件进行解压操作。命令如下:
    # cd /usr/local/src
    # tar -zxvf wwwcount2.6.tar.gz

    4.接着开始对刚解压的文件进行设置,可以参见下面的过程:

       
       
        
        # ./Count-config   //开始设定
……
◆ cgi-bin dierctory [/usr/local/etc/httpd/cgi-bin]: 
/usr/local/apache/cgi-bin  //Apache默认的cgi-bin的目录
……
◆ Base directory [/usr/local/etc/Counter]: 
/usr/local/Counter // wwwcount安装的目录
You need to enter the directory of the configuration file. 
◆ Config directory [/usr/local/Counter/conf]:   //默认按回车键
You will create this file later by running the program “Gen_conf”. 
◆ Name of the configuration file [count.cfg]:  //默认按回车键
You need to enter the directory of the counter data file. 
◆ Data directory [/usr/local/Counter/data]:  //默认按回车键
You need to enter the directory of the Log file. 
◆ Log directory [/usr/local/Counter/Log]:  //默认按回车键
◆ Name of the log file [Count2.6.log]:    //默认按回车键
You entered: 
++++++++++++++++++++++++++++++ 
CgiBinDir=/usr/local/apache/cgi-bin 
……
++++++++++++++++++++++++++++++ 
Everything looks ok [y|n]? y  //确定以上设置没问题后就按y
       
       


    5.接下来输入“./configure”命令,开始一些测试主机情况。

    6.如果想要让计数器每点击一次就增加一个数的话,在Makefile文件中找到“Makefile #COUNT_RELOAD= -DCOUNT_RELOAD=1 ”这行(大约在33行),将注解“#”符号取消,保存后退出。

    7.输入命令“make clean”,然后开始编译可执行文件。

    8.接着使用“./Gen-conf”命令设置主机信息,过程如下:

       
       
        
        …… 
Continue [y|n]? y  //按下y确定
Enter your fully qualified domain name [no default]: 
game1.com.cn //需要输入主机名与域名
◆ Enter your IP address [no default]: 221.7.128.164  
◆ Does your host have any nickname [y|n]:
? y  //如果主机有多个名称,那就按y,否则按n
◆ Enter your host's nickname (FQDN) [no default]: 
www.game1.com.cn  //如果上面按y,才会出现需要填另一个主机名
◆ Do you want to allow automatic file creation [y|n]
? n  //通常不希望自动产生文件
◆ Do you want the program to run in strict mode [y|n]? y  
◆ Do you want to ignore access hits from your own host [y|n]? y
//用户自己访问,如果想计入其内,就按y。
……
       
       


    9.开始进行安装,过程如下:

       
       
        
        # ./Count-install
Your configuration: 
……
Continue [y|n]? y  //查看上面的设置信息是否正确,正确的话就开始安装
◆ Do you know the user and group id of httpd' child process [y|n]:? y  
◆ Enter user id of httpd's child process [no default]:? nobody  
◆ Enter group id of httpd's child process [no default]:? nobody
//如果用户不清楚,可以在httpd.conf文件中查找相关的设置
       
       


    到此,安装就完成了。

    应用

    要使用上面搭建的计数器也很简单,只要在网页文件中的任何地方加入下面代码,就可以显示出计数器图形了:

       
       
        
        <img SRC=“http://www.game1.com.cn/cgi-bin/Count.cgi?dd=A&ft=0&sh=T&pad=Y&df=test.dat”>
       
       


    其中test.dat文件放在/usr/local/Counter/data目录下,用户可以参照下面对这个文件进行一些操作:

       
       
        
        #cd /usr/local/Counter/data 
#echo 1 > test.dat 
#chown nobody:nobody test.dat 
#chmod 644 test.dat
       
       
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值