lizongbo at 618119.com 工作,生活,Android,前端,Linode,Ubuntu,nginx,java,apache,tomcat,Resin,mina,Hessian,XMPP,RPC

2010年04月11日

Windows下安装配置Apache cassandra 0.5.1

Filed under: Java — 标签:, — lizongbo @ 14:34

cassandra是facebook开源的,代码托管在apache,主页是:http://cassandra.apache.org/
目前版本0.5.1,首先下载最新版:
http://apache.freelamp.com/cassandra/0.5.1/apache-cassandra-0.5.1-bin.tar.gz
来源:
http://cassandra.apache.org/download/

解压到D:\Java\,生成到目录为:D:\Java\apache-cassandra-0.5.1
运行D:\Java\apache-cassandra-0.5.1\bin\cassandra.bat      ,提示错误信息如下:

D:\Java\apache-cassandra-0.5.1\bin>cassandra.bat
找不到路径 – D:\Java\apache-cassandra-0.5.1\bin\lib
系统找不到指定的驱动器。
Starting Cassandra Server
Listening for transport dt_socket at address: 8888
Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/cassandra/
service/CassandraDaemon
Caused by: java.lang.ClassNotFoundException: org.apache.cassandra.service.Cassan
draDaemon
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
Could not find the main class: org.apache.cassandra.service.CassandraDaemon.  Pr
ogram will exit.

打开cassandra.bat一看,发现取的CASSANDRA_HOME是当前目录,估计cassandra的开发者不用windows操作系统开发,或者是已经配置过环境变量CASSANDRA_HOME。
于是对照Apache Tomcat的bat文件,在cassandra.bat的 SETLOCAL后面加上一行 “cd ..”。然后重新运行bat。程序启动成功。

(http://ahuaxuan.javaeye.com/blog/603106 这篇文章说”在环境变量配置中加入CD=xxxx/cassandra根目录”是不合理的,CD本身就是调用cd命令输出当前路径,
即使要加全局环境变量,也是直接配置类似CASSANDRA_HOME=D:\Java\apache-cassandra-incubating- 0.5.1即可)
cassandra-cli.bat在SETLOCAL后面加上两行:“cd ..
if NOT DEFINED CASSANDRA_HOME set CASSANDRA_HOME=%CD%”
修改后,也能成功启动。

cassandra.bat 此时会发现“我的电脑”里多了一个磁盘目录P,从cassandra.bat中可以看到是运行了以下命令:
subst P: “%CASSANDRA_HOME%\lib”
P:
set CLASSPATH=P:\

这个命令将 cassandra的lib目录用subst命令映射成了一个虚拟盘符。
再次运行cassandra.bat时可以看到提示信息:“已经对驱动器运行过 SUBST”。
于是运行subst /D P: 删除映射。

cassandra.bat对同一台机器启动两个进程不友好,于是继续修改cassandra.bat。
主要是设置classpath这段修改后如下:
———————-
REM ***** CLASSPATH library setting *****
REM Shorten lib path for old platforms
rem subst P: “%CASSANDRA_HOME%\lib”
rem P:
rem set CLASSPATH=P:\
for %%i in (%CASSANDRA_HOME%\lib\*.jar) do call :append %%i
goto okClasspath
:append
set CLASSPATH=%CLASSPATH%;%*
goto :eof
———————-

接下来发现conf/storage-conf.xml的配置也不支持同一台机器的启动多个进程。
继续修改,做成相对路径:

<CommitLogDirectory>var/lib/cassandra/commitlog</CommitLogDirectory>
<DataFileDirectories>
<DataFileDirectory>var/lib/cassandra/data</DataFileDirectory>
</DataFileDirectories>
<CalloutLocation>var/lib/cassandra/callouts</CalloutLocation>
<StagingFileDirectory>var/lib/cassandra/staging</StagingFileDirectory>

log4j.properties里也需要改成相对路径。
log4j.appender.R.File=var/log/cassandra/system.log

(最终核实,多节点通讯是以ip作为key,一台机器启动两个进程是可以,但是互为主备是没戏了。)

接下来测试数据的添加和删除。
先测试命令方式的,参考:http://wiki.woodpecker.org.cn/moin/ApacheCassandra
双击运行cassandra-cli.bat

Welcome to cassandra CLI.

Type ‘help’ or ‘?’ for help. Type ‘quit’ or ‘exit’ to quit.
cassandra> connect 127.0.0.1/9160 //连接到指定的ip和端口,
Connected to 127.0.0.1/9160
cassandra> set Keyspace1.Standard1[‘lizongbo’][‘name’] = ‘lizonbo’
Value inserted.
cassandra> set Keyspace1.Standard1[‘lizongbo’][‘age’] = ’80’
Value inserted.
cassandra> set Keyspace1.Standard1[‘lizongbo’][‘blogurl’] = ‘http://618119.com
Value inserted.
cassandra> get Keyspace1.Standard1[‘lizongbo’]
=> (column=name, value=lizonbo, timestamp=1270967368859)
=> (column=blogurl, value=http://618119.com, timestamp=1270967384812)
=> (column=age, value=80, timestamp=1270967377281)
Returned 3 results.
cassandra> get Keyspace1.Standard1[‘lizongbo’][‘blogurl’]
=> (column=blogurl, value=http://618119.com, timestamp=1270967384812)
cassandra>

2007年12月7日

在Tomcat 6.0.14中安装配置awstats

Filed under: Apache,DNS,IP,Tomcat — 标签:, , , , — lizongbo @ 18:30

在Tomcat 6.0.x中配置awstats
需要下载的文件有:

perl : http://downloads.activestate.com/ActivePerl/Windows/5.8/ActivePerl-5.8.8.822-MSWin32-x86-280952.msi
来源: http://www.activestate.com/store/activeperl/download/

http://update.cz88.net/soft/qqwry.rar
http://awstats.sourceforge.net/files/awstats-6.8.tar.gz

geoip插件相关:
http://www.maxmind.com/download/geoip/api/pureperl/Geo-IP-PurePerl-1.18.tar.gz
http://www.maxmind.com/download/geoip/database/GeoIP.dat.gz
http://www.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
http://www.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz

安装过程可参考

参考: http://blog.zhangjianfeng.com/article/317
PurePerl.pm的安装可参考:
http://topic.csdn.net/u/20070323/11/903dd121-10d8-42d2-b4eb-a6cb60a22e8a.html

其它配置可参考:
http://www.chedong.com/blog/archives/000410.html

http://blogger.org.cn/blog/more.asp?name=chenjiejacky&id=20464

安装perl之后,确认环境变量里PATH有perl的bin目录
Path=E:\oracle\product\10.2.0\client_1\bin;D:\Perl\bin;
D:\Java\jdk1.6.0_03\bin;E:\oracle\product\10.2.0\db_1\bin;
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;
C:\Program Files\Microsoft SQL Server\80\Tools\BINN

1.为了控制查看awstats的权限,我在
E:\apache-tomcat-6.0.14\conf\tomcat-users.xml的内容配置为:

<?xml version=’1.0′ encoding=’utf-8′?>
<tomcat-users>
<role rolename=”awstats”/>
<user username=”awstats” password=”awstats” roles=”awstats”/>
</tomcat-users>

2.由于权限限制

E:\apache-tomcat-6.0.14\webapps\awstats\META-INF\context.xml,内容为:

<!– tomcat 6.0 need privileged is true for CGIServlet –>
<Context reloadable=”true” privileged=”true” >

</Context>

(注意目录是META-INF,不是WEB-INF)否则启动的时候会出下面的错误信息:

[ERROR]main-org.apache.catalina.startup.HostConfig-Error deploying web application directory awstats
java.lang.SecurityException: Servlet of class org.apache.catalina.servlets.CGIServlet is privileged and cannot be loaded by this web application
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1134)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4045)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4351)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
3.配置web.xml,增加权限控制
web.xml的内容为:

<?xml version=”1.0″ encoding=”UTF-8″?>
<web-app xmlns=”http://java.sun.com/xml/ns/j2ee” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd” version=”2.4″>
<servlet>
<servlet-name>cgi</servlet-name>
<servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
<init-param>
<param-name>clientInputTimeout</param-name>
<param-value>100</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>cgiPathPrefix</param-name>
<param-value>WEB-INF/cgi-bin</param-value>
</init-param>
<load-on-startup>5</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cgi</servlet-name>
<url-pattern>/cgi-bin/*</url-pattern>
</servlet-mapping>
<!– Define reference to the user database for looking up roles –>
<resource-env-ref>
<description>
Link to the UserDatabase instance from which we request lists of
defined role names. Typically, this will be connected to the global
user database with a ResourceLink element in server.xml or the context
configuration file for the Manager web application.
</description>
<resource-env-ref-name>users</resource-env-ref-name>
<resource-env-ref-type>org.apache.catalina.UserDatabase</resource-env-ref-type>
</resource-env-ref>
<!– Define a Security Constraint on this Application –>
<security-constraint>
<web-resource-collection>
<web-resource-name>awstats status</web-resource-name>
<url-pattern>/cgi-bin/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>awstats</role-name>
</auth-constraint>
</security-constraint>
<!– Define the Login Configuration for this Application –>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Awstats status,username: awstats,password: awstats</realm-name>
</login-config>
<!– Security roles referenced by this web application –>
<security-role>
<description>
The role that is required to log in to the Manager Application
</description>
<role-name>awstats</role-name>
</security-role>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
</welcome-file-list>
</web-app>

4.调整文件夹目录

E:\APACHE~1.14\webapps\awstats 的目录

007-12-07 18:14 <DIR> .
007-12-07 18:14 <DIR> ..
007-12-07 08:48 <DIR> classes
007-12-07 08:48 <DIR> css
007-12-07 08:48 <DIR> docs
007-12-07 08:48 <DIR> icon
007-12-07 08:49 211 index.jsp
007-12-07 08:48 <DIR> js
007-12-07 08:56 <DIR> logs
007-12-07 08:48 <DIR> META-INF
007-11-24 22:05 6,721 README.TXT
007-12-07 08:47 <DIR> WEB-INF

E:\APACHE~1.14\webapps\awstats\WEB-INF 的目录

2007-12-07 08:47 <DIR> .
2007-12-07 08:47 <DIR> ..
2007-12-07 08:56 <DIR> cgi-bin
2007-12-07 08:47 <DIR> tools
2007-12-07 08:42 2,389 web.xml

E:\APACHE~1.14\webapps\awstats\WEB-INF\cgi-bin 的目录

007-12-07 08:56 <DIR> .
007-12-07 08:56 <DIR> ..
006-02-09 06:26 5,407 awredir.pl
007-12-07 08:56 2,343 awstats.localhost.conf
007-12-07 08:55 2,340 awstats.localhost.conf.bak
007-11-24 03:18 60,544 awstats.model.conf
007-11-24 03:18 556,625 awstats.pl
007-12-07 08:56 13,569 awstats122007.localhost.txt
006-07-27 09:37 1,847 awstatsext.conf
007-12-07 08:56 678 dnscachelastupdate.localhost.hash
007-12-03 12:18 1,079,842 GeoIP.dat
007-09-13 04:08 2,020,543 GeoIPASNum.dat
007-12-03 16:25 25,914,398 GeoLiteCity.dat
007-12-07 08:48 <DIR> lang
007-12-07 08:48 <DIR> lib
007-03-15 14:35 184 perl插件安装说明.txt
007-12-07 08:54 <DIR> plugins
007-12-05 17:58 6,812,739 QQWry.Dat

E:\APACHE~1.14\webapps\awstats\WEB-INF\cgi-bin\plugins 的目录

2007-12-07 08:54 <DIR> .
2007-12-07 08:54 <DIR> ..
2006-02-09 06:26 3,682 clusterinfo.pm
2006-02-09 06:26 2,960 decodeutfkeys.pm
2007-12-07 08:48 <DIR> example
2007-12-07 08:54 <DIR> geo
2006-05-06 11:51 7,203 geoip.pm
2006-02-09 06:26 3,736 geoipfree.pm
2006-09-04 15:04 112,953 geoip_city_maxmind.pm
2006-05-06 11:54 16,885 geoip_isp_maxmind.pm
2006-05-06 11:54 16,919 geoip_org_maxmind.pm
2006-05-06 11:54 22,283 geoip_region_maxmind.pm
2004-01-01 05:41 5,074 graphapplet.pm
2006-02-09 06:26 5,206 hashfiles.pm
2005-02-19 21:50 7,169 hostinfo.pm
2006-02-09 06:26 2,439 ipv6.pm
2005-04-11 05:08 2,501 qqhostinfo.pm
2005-03-28 11:29 7,603 qqwry.pl
2006-02-09 06:26 4,689 rawlog.pm
2006-02-09 06:26 1,890 timehires.pm
2006-02-09 06:26 2,954 timezone.pm
2006-07-30 03:20 8,212 tooltips.pm
2006-02-09 06:26 4,799 urlalias.pm
2006-02-09 06:26 3,616 userinfo.pm

我的awstats.localhost.conf配置如下:

Include=”common.conf”
PageCode=”GB2312″ # UTF-8
LogFile=”E:/apache-tomcat-6.0.14/logs/access.log”
SiteDomain=”618119.com”
LoadPlugin=”decodeutfkeys”
LoadPlugin=”hashfiles”
LoadPlugin=”geoip”
LoadPlugin=”tooltips”
LoadPlugin=”qqhostinfo”
LoadPlugin=”geoip_city_maxmind GEOIP_STANDARD GeoLiteCity.dat”
LoadPlugin=”geoip_org_maxmind GEOIP_STANDARD GeoIPASNum.dat”
LogFormat=1
HostAliases=”localhost 618119.com www.618119.com
DirIcons=”/awstats/icon”
DNSLookup=1
DirData=”.”
DirCgi=”/cgi-bin”
AllowToUpdateStatsFromBrowser=1

Include=”awstatsext.conf”

一个非常有用的参考地址: http://www.antezeta.com/awstats.html

扩展设置:
# form http://www.antezeta.com/awstats.html

ExtraSectionName1=”Google Searches – Top 50″
ExtraSectionCodeFilter1=”200 304″
ExtraSectionCondition1=”REFERER,(.*www\.google.*)”
ExtraSectionFirstColumnTitle1=”Search”
ExtraSectionFirstColumnValues1=”REFERER,p=([^&]+)||REFERER,q=([^&]+)||REFERER,as_p=([^&]+)||REFERER,as_q=([^&]+)”
ExtraSectionFirstColumnFormat1=”<a href=’http://www.google.cn/search?q=%s’ title=’Click to execute search’>%s</a>”
ExtraSectionStatTypes1=PHBL
ExtraSectionAddAverageRow1=0
ExtraSectionAddSumRow1=1
MaxNbOfExtra1=50
MinHitExtra1=1

ExtraSectionName2=”Google crawls – Top 50″
ExtraSectionCodeFilter2=”200 304″
ExtraSectionCondition2=”UA,(.*Googlebot.*)”
ExtraSectionFirstColumnValues2=”URL,(.*)”
ExtraSectionFirstColumnFormat2=”<a href=’http://618119.com%s’ title=’Item Crawled’>%s</a>”
ExtraSectionStatTypes2=PHBL
ExtraSectionAddAverageRow2=0
ExtraSectionAddSumRow2=1
MaxNbOfExtra2=50
MinHitExtra2=1

ExtraSectionName3=”sitemap.xml.gz downloads by Useragent”
ExtraSectionCodeFilter3=”200 304″
ExtraSectionCondition3=”URL,(^\/sitemap\.xml\.gz)”
ExtraSectionFirstColumnTitle3=”UA”
ExtraSectionFirstColumnValues3=”UA,(.*)”
ExtraSectionStatTypes3=HBL
ExtraSectionAddAverageRow3=0
ExtraSectionAddSumRow3=1
MaxNbOfExtra3=10
MinHitExtra3=1

ExtraSectionName4=”Referring Sites by domain – Top 25″
ExtraSectionCodeFilter4=”200 304″
# Filter on ANY REFERER except “mysite”. Change mysite to your domain name.
ExtraSectionCondition4=”REFERER,^(?!http:\/\/www\.618119\.com)”
ExtraSectionFirstColumnTitle4=”Site”
ExtraSectionFirstColumnValues4=”REFERER,^[hH][tT][tT][pP]:\/\/([^\/]+)\/”
ExtraSectionFirstColumnFormat4=”<a href=’http://%s/’ rel=’nofollow’ title=’http://%s/ [new window]’>%s</a>”
ExtraSectionStatTypes4=PHL
ExtraSectionAddAverageRow4=1
ExtraSectionAddSumRow4=1
MaxNbOfExtra4=25
MinHitExtra4=1

ExtraSectionName5=”Top 30 RSS Readers/Spiders”
ExtraSectionCodeFilter5=”200 304″
ExtraSectionCondition5=”URL,\.xml|\.rdf|\.rss|\/feed”
ExtraSectionFirstColumnTitle5=”RSS Reader/Spider”
ExtraSectionFirstColumnValues5=”UA,(.*)”
ExtraSectionStatTypes5=HBL
ExtraSectionAddAverageRow5=1
ExtraSectionAddSumRow5=1
MaxNbOfExtra5=30
MinHitExtra5=1

ExtraSectionName6=”Downloads (diff,doc,pdf,rtf,sh,tgz,zip) – Top 10″
ExtraSectionCodeFilter6=”200 304″
ExtraSectionCondition6=”URL,(.*((\.diff)|(\.doc)|(\.pdf)|(\.rtf)|(\.sh)|(\.tgz)|(\.zip)))”
ExtraSectionFirstColumnTitle6=”Download”
ExtraSectionFirstColumnValues6=”URL,(.*)”
ExtraSectionFirstColumnFormat6=”%s”
ExtraSectionStatTypes6=HBL
ExtraSectionAddAverageRow6=0
ExtraSectionAddSumRow6=1
MaxNbOfExtra6=10
MinHitExtra6=1

2007年12月6日

给wordpress加上记录Combined格式日志的功能

Filed under: Apache,Web Server — 标签:, , , , — lizongbo @ 18:23

由于我是合租的web主机,因此开通的ftp里没权限看到站点的access.log,

由于wordpress是通过.htaccess中配置的urlrewrite将http请求重定向到index.php 这个入口,

因此只要在index.php里加上记录日志的操作,基本上大部分请求都可以记录下来,

查了下资料,没看见现成的代码,于是对照着 Combined各式的日志,

自己写了一段代码来实现这个功能.

代码如下:

[code]

<?php
/* Short and sweet */
define(‘WP_USE_THEMES’, true);
/**
为我的wordpress增加记录web日志的功能
author: lizongbo
site: http://618119.com
*/

$webaccesslog=”webaccess”.gmdate(“Y-m-d”).”.log”;
$accesslog=$_SERVER[‘REMOTE_ADDR’].” – – “.gmdate(“[d/M/Y:H:i:s +0800] “);
$accesslog=$accesslog.”\””.$_SERVER[“REQUEST_METHOD”].” “.$_SERVER[“REQUEST_URI”].” “;
$accesslog=$accesslog.$_SERVER[“SERVER_PROTOCOL”].”\””;
$accesslog=$accesslog.” 200 2007 \””;
if(!empty($_SERVER[“HTTP_REFERER”])){
$accesslog=$accesslog.$_SERVER[“HTTP_REFERER”];
}else{
$accesslog=$accesslog.”-“;
}
$accesslog=$accesslog.”\” \””.$_SERVER[“HTTP_USER_AGENT”].”\””.”\r\n”;
$webaccess=fopen($webaccesslog,”a”);
fwrite($webaccess,$accesslog);
/*下面的写法 io 操作太多,被废弃了
fwrite($webaccess,$_SERVER[‘REMOTE_ADDR’]);
fwrite($webaccess,” – – “);
fwrite($webaccess,gmdate (“[d/M/Y:H:i:s +0800] “));//不知道怎么加时区,于是写死了
fwrite($webaccess,”\””);
fwrite($webaccess,$_SERVER[“REQUEST_METHOD”]);
fwrite($webaccess,” “);
fwrite($webaccess,$_SERVER[“REQUEST_URI”]);
fwrite($webaccess,” “);
fwrite($webaccess,$_SERVER[“SERVER_PROTOCOL”]);
fwrite($webaccess,”\””);
fwrite($webaccess,” 200 2007 \””);//强行写死了状态码和内容长度
if(!empty($_SERVER[“HTTP_REFERER”])){
fwrite($webaccess,$_SERVER[“HTTP_REFERER”]);
}else{
fwrite($webaccess,”-“);
}
fwrite($webaccess,”\” \””);
fwrite($webaccess,$_SERVER[“HTTP_USER_AGENT”]);
fwrite($webaccess,”\””);
fwrite($webaccess,”\r\n”);
*/

fclose($webaccess);
require(‘./wp-blog-header.php’);
?>

[/code]

这样,记录下来的日志就可以通过ftp下载到本地,然后再用 awstats 进行分析了.

Older Posts »

Powered by WordPress