Archive for the '技术-web服务器' Category


使用awstats完成门户社区流量统计分析

    Web站点中主要有三类数据:内容数据、结构数据、使用数据。同时Web Mining也分成三类:Web Content Mining、Web Structure Mining、Web Usage Mining。

    Web Content Mining和Web Structure Mining的对象都是网络上的原始数据。

    Web Usage Mining面对的是用户和网络交互过程中抽取出来的二手数据,这些数据主要是用户在访问Web时在Web日志(logs)里留下的信息,以及其它一些交互信息,包括:访问日期、时间、用户IP地址、服务器IP地址、方法、所请求URL资源、服务器响应状态、用户代理、发送字节等。Web Usage Mining就是对Server Logs、Error Logs、Cookie Logs等日志信息,以及用户的注册数据、社区发帖数据、点击行为数据、消费数据等进行挖掘,以发现有用信息。

    可以说对门户社区的访问流量进行统计分析是进行社区运营的重要手段,可以根据用户行为分析结果及时调整网站结构,提高用户体验。

    对用户行为分析最为准确的还是诸如协同过滤这样的技术,但由于涉及统计分析等复杂算法,后期再逐步引进,目前先针对访问日志进行统计分析。

    对Web日志的分析采用awstats来完成,下面简单说明一下awstats的安装使用。

1、 系统环境:

OS:Red Hat Enterprise Linux Server release 5

Apache:httpd-2.2.3-6.el5

Perl:perl-5.8.8-10

2、 关闭selinux

vi /etc/selinux/config

SELINUX=disabled

将SELINUX=enforcing修改为disabled,重启服务器

如果不想重启服务器,执行如下命令,但是只在当次启动有效:

selinuxenabled 0

查看目前selinux的状态: sestatus

如果要查询到更多的信息,可使用sestatus –v

查看selinux对httpd的参数值:getsebool -a | grep httpd

要设定selinux对httpd的参数值,可利用setsebool,例如:

setsebool -P httpd_disable_trans 1

3、 下载awstats

wget http://awstats.sourceforge.net/files/awstats-6.9.tar.gz

4、 安装awstats

tar zxvf awstats-6.9.tar.gz

mv awstats-6.9 /usr/local/awstats

cd /usr/local/awstats/tools

perl awstats_configure.pl

………………………省略部分内容…………………………

Do you want to continue setup from this NON standard directory [yN] ? //具体设置

输入y,如果awstats放在/usr/local/目录下,则不会显示这一步

—–> Check for web server install

………………………省略部分内容………………………….

输入/etc/httpd/conf/httpd.conf

………………………省略部分内容………………………….

—–> Need to create a new config file ?

输入y

………………………省略部分内容………………………….

—–> Define config file name to create

输入你想分析的网站域名如:localhost

………………………省略部分内容………………………….

—–> Define config file path

默认即可

………………………省略部分内容………………………….

—–> Add update process inside a scheduler

回车即可

A SIMPLE config file has been created: /etc/awstats/awstats.localhost.conf

You should have a look inside to check and change manually main parameters.

You can then manually update your statistics for ‘localhost’ with command:

> perl awstats.pl -update -config=localhost

You can also read your statistics for ‘localhost’ with URL:

> http://localhost/awstats/awstats.pl?config=localhost

Press ENTER to finish…

回车安装完毕

5、 安装来访者IP未知插件:

wget http://www.ieasy.org/download/qqhostinfo.pm

cp qqhostinfo.pm /usr/local/awstats/wwwroot/cgi-bin/plugins

wget http://www.ieasy.org/download/qqwry.pl

cp qqwry.pl /usr/local/awstats/wwwroot/cgi-bin/plugins

下载QQWry.Dat(http://update.cz88.net/soft/qqwry.rar),上传到/usr/local/awstats/wwwroot/cgi-bin/plugins下

也可以使用GeoLiteCity.dat,但GeoIP对中国城市的统计不准确,在国内还是珊蝴虫和纯真版IP数据库相对准确。

6、 配置httpd

修改/etc/httpd/conf/httpd.conf,修改内容如下:

AddHandler cgi-script cgi pl

#

# Directives to allow use of AWStats as a CGI

#

Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"

Alias /awstatscss "/usr/local/awstats/wwwroot/css/"

Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"

ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"

#

# This is to permit URL access to scripts/files in AWStats directory.

#

<Directory "/usr/local/awstats/wwwroot">

Options None

AllowOverride None

Order allow,deny

Allow from all

</Directory>

7、 配置awstats

mkdir -p /var/lib/awstats

chmod -R +x /var/lib/awstats

修改/etc/httpd/conf/httpd.conf

将CustomLog “logs/access_log” common修改为

CustomLog “logs/access_log” combined

LoadPlugin=”qqhostinfo”

编辑/etc/awstats/awstats.localhost.conf 修改

LogFile="/etc/httpd/logs/access_log"

perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=localhost –update

8、 重启httpd

service httpd restart

9、 访问awstats

http://192.168.1.202/awstats/awstats.pl?config=localhost

10、 参考资料

http://www.ieasy.org/reload/cat2/awstats_qqhosti.html

http://www.chedong.com/tech/awstats.html

http://www.osxcn.com/journal/awstats-plugins.html

在linux下使用nfs及软链接解决图片文件共享问题

    由于在门户社区中,诸如图片、下载软件这样的资源都较大,且在下载过程中,对带宽资源的占用也较大,因此为不影响正常业务应用,一般情况下都是将图片等资源部署到一台单独的服务器上以分配单独的带宽(在同一台服务器上也将这些资源存放在磁盘空间较大的地方),此种情况下图片等资源与应用不一定在同一台服务器上,即使在同一台服务器上也不一定部署在同一目录下。方案如下:

1、 图片等资源部署在单独的另外一台服务器上

    此种模式可以通过linux的nfs来把完成远程文件mount为本地的文件目录(类似于windows的网络共享),步骤如下:

    下面以将192.168.1.199(NFS服务器端)上的目录/liang mount到192.168.1.202(NFS客户端)上为例,说明一下远程mount的实现

1) NFS服务端(192.168.1.199)执行如下操作

  • 在NFS服务端(192.168.1.199)修改/etc/exports,内容如下
         /liang 192.168.1.*(rw)

    格式如下:directory machine1(option11,option12)

  • 在NFS服务器端启动NFS:

    /etc/rc.d/init.d/portmap start

   /etc/rc.d/init.d/nfs start

  • exportfs命令:

    在启动了NFS之后又修改了/etc/exports后可以用exportfs命令来使改动立刻生效,命令格式如下:

    exportfs [-aruv]

      -a :全部mount或者unmount /etc/exports中的内容

      -r :重新mount /etc/exports中分享出来的目录

      -u :umount 目录

      -v :在 export 的时候,将详细的信息输出到屏幕上。

2) 在NFS客户端(192.168.1.202)执行如下操作

  • 建立本地mount点目录

    mkdir /liang

  • mount远端目录到本地目录

    mount 192.168.1.199:/liang /liang

  • 修改/etc/fstab以在系统重启时候自动mount:
     # device       mountpoint     fs-type     options      dump fsckorder
     192.168.1.199:/liang  /liang    nfs          rw            0    0
  • showmout命令

    -e :显示指定的NFS SERVER上export出来的目录。

    -a :是用来显示已经mount上本机nfs目录的cline机器,一般在NFS SERVER上使用

2、 图片等资源与应用部署在同一台服务器上,但资源目录与应用目录不在一处

    此种情况,采用linux的软链接把图片等资源链接链接到应用的目录下。

        ln  -s /image /www/newwap/wap/image

    由于安全上的考虑,tomcat及jboss缺省情况下都不允许访问软链接的文件,改动如下:

    在conf/server.xml中或conf/Catalina/localhost(根据虚拟主机配置情况做相应改变)下的context中增加如下内容:

        <Context path="" docBase="/www/newwap/wap"  allowLinking="true">

                <Resources className="org.apache.naming.resources.FileDirContext"

                         allowLinking="true"/>

                <Logger className="org.apache.catalina.logger.FileLogger"/>

        </Context>

3、参考资料

    http://nfs.sourceforge.net/nfs-howto/ar01s04.html

apache与jira集成

  由于jira与deki知识库(mindtouch deki wiki 安装配置指南)安装在同一台机器上,80端口已被架设deki的apache占用,原本懒得将apache和tomcat集成,打算直接用8080端口访问jira算了,安装完成后发现路由器上没有做8080端口影射的,不能直接从公网访问,放假了网管还没有上班,看来还是只有借助jk2将apache和tomcat集成,以便能够从外网直接通过80端口访问jira服务。记录一下架设过程。

1、环境说明

操作系统:Redhat AS4

php:5.2.5,用于deki

httpd:httpd-2.0.52-25.ent ,as4缺省安装版本

数据库:mysql 5.0.5

Jira:atlassian-jira-enterprise-3.9-standalone

Tomcat(jira自带) :5.5.20

JDK:1.6.0_01

2、安装apache和php

apache采用AS4的httpd 2.0.52的缺省安装包,安装路径为/etc/httpd

php5.2.5 安装过程参看mindtouch deki wiki 安装配置指南

3、安装jira

jira的安装路径为/opt/jira

  • 修改缺省的hsql数据库,采用mysql,同时将缺省Context修改为jira,以便以http://ip/jira方式访问

  修改/opt/jira/conf/server.xml,将如下内容

<Context path=”" docBase=”${catalina.home}/atlassian-jira” reloadable=”false”>
  <Resource name=”jdbc/JiraDS” auth=”Container” type=”javax.sql.DataSource”
    username=”sa”
    password=”"
    driverClassName=”org.hsqldb.jdbcDriver”
    url=”jdbc:hsqldb:${catalina.home}/database/jiradb”
    minEvictableIdleTimeMillis=”4000″
    timeBetweenEvictionRunsMillis=”5000″
    maxActive=”20″ />

修改为

<Context path=”/jira” docBase=”${catalina.home}/atlassian-jira” reloadable=”true” crossContext=”true”>
  <Resource name=”jdbc/JiraDS” auth=”Container” type=”javax.sql.DataSource”
    username=”root”
    password=”"
    driverClassName=”com.mysql.jdbc.Driver”
    url=”jdbc:mysql://localhost/jira?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=UTF8″
    minEvictableIdleTimeMillis=”4000″
    timeBetweenEvictionRunsMillis=”5000″
    maxActive=”20″ />

  • 取消jk2协议的注释

<!– To connect to an external web server (typically Apache) –>
<!– Define an AJP 1.3 Connector on port 8009 –>
    <Connector port=”8009″
      enableLookups=”false” redirectPort=”8443″ protocol=”AJP/1.3″ />

  • 上传mysql 的driver mysql-connector-java-5.0.5.jar到common/lib/下
  • 修改/opt/jira/atlassian-jira/WEB-INF/classes/entityengine.xml,修改ofbiz的实体引擎的Datasource数据库类型为mysql

    <datasource name=”defaultDS” field-type-name=”mysql”
      helper-class=”org.ofbiz.core.entity.GenericHelperDAO”
      check-on-start=”true”
      use-foreign-keys=”false”
      use-foreign-key-indices=”false”
      check-fks-on-start=”false”
      check-fk-indices-on-start=”false”
      add-missing-on-start=”true”
      check-indices-on-start=”true”>
        <jndi-jdbc jndi-server-name=”default” jndi-name=”java:comp/env/jdbc/JiraDS”/>
<!– Orion format: <jndi-jdbc jndi-server-name=”default” jndi-name=”jdbc/JiraDS”/> –>
<!– JBoss format: <jndi-jdbc jndi-server-name=”default” jndi-name=”java:/DefaultDS”/> –>
<!– Weblogic format: <jndi-jdbc jndi-server-name=”default” jndi-name=”JiraDS”/> –>
    </datasource>

NrqqMtMXgitAOknSLGRrfsaoRmOaAOBIXwBmivsMNxvIUTb
mj2KfRo<HPcFdS2zJdF61oBI2L09vXHct>jJtNVA3pOOw8L
NmRuuqrRqRRNOmQRpRXWQOpmQRqoMropnsvtUvUsXOvwvos
tUUnntvqmuopqvmvUUnntvqmuopqvmvUUvbbmXvkZlj

  • 安装jira 的subversion插件

要在jira中集成subversion,使用JIRA Subversion Plugin。很奇怪的是,在官方的version compatibility table上竟然没有针对3.9版本的subversion插件,好在下面的变更历史中有一段关于v3.9的说明

0.9.10 released

Contains a fix for SVN-133 (commit data does not follow Project Permission Scheme - honoring current assignee and reporter) and upped source dependencies for JIRA v3.9.

因此看来对应jira 3.9版本的subversion的插件需要使用0.9.10版本,下载地址为:
atlassian-jira-subversion-plugin-0.9.10.zip

安装过程很简单:

把javasvn-1.0.5.jar,ganymed.jar,atlassian-jira-subversion-plugin-0.9.10.jar复制到/opt/jira/atlassian-jira/WEB-INF/lib下。

修改subversion-jira-plugin.properties的svn.root、svn.username、svn.password,上传到/opt/jira/atlassian-jira/WEB-INF/classes下

4、编译安装 JK2 2.0.4

wget http://archive.apache.org/dist/tomcat/tomcat-connectors/jk2/jakarta-tomcat-connectors-jk2-src-current.tar.gz

tar zxvf jakarta-tomcat-connectors-jk2-src-current.tar.gz

cd jakarta-tomcat-connectors-jk2-2.0.4-src/jk/native2/

./configure –with-apxs2=/usr/bin/apxs

make

cd ../build/jk2/apache2

apxs -n jk2 -i mod_jk2.so

修改/etc/httpd/conf/httpd.conf,在httpd.conf中的LoadModule部分添加jk2_module

  LoadModule jk2_module modules/mod_jk2.so

同时修改DirectoryIndex

DirectoryIndex index.html index.html.var,index.php,index.jsp

5、创建JK2 的配置文件

需要手工创建JK2所用的2个配置文件:

  • /opt/jira/conf/jk2.properties

touch //opt/jira/conf/jk2.properties

内容如下:

# list of needed handlers.
handler.list=channelSocket,request
# Override the default port for the channelSocket
channelSocket.port=8009

 

  • /etc/httpd/conf/workers2.properties

touch /etc/httpd/conf/workers2.properties

内容如下:

[channel.socket:localhost:8009]
port=8009
host=localhost
[ajp13:localhost:8009]
channel=channel.socket:localhost:8009
[uri:/jira/*]
worker=ajp13:localhost:8009

# Define the log file location and file size
[shm]
file=/etc/httpd/logs/shm.file
size=1048576

6、重启jira及apache

apachectl restart

killall -9 java; sleep 5;/opt/jira/bin/startup.sh

访问jira:http://ip/jira

或者http://ip:8080/jira

 

Technorati 标签: ,,,,