当前位置: 首页 > 工具软件 > Lucene4c > 使用案例 >

linux lucene环境搭建,linux下安装lucene

谈桐
2023-12-01

Plucene基于java lucene项目创建

安装方法:

perl -MCPAN -e “install Plucene”

perl -MCPAN -e “install Plucene::Simple”

CLucene

CLucene是C++版的全文检索引擎,完全移植于Lucene,采用 STL 编写。有php扩展,对中文支持不是很好。

http://sourceforge.net/projects/clucene/

Lucene4c

The Lucene4c project is an implementation of the Lucene search engine in C, built on

top of the Apache Portable

Runtime.

Nutch

Nutch 是一个开源Java 实现的搜索引擎。它提供了我们运行自己的搜索引擎所需的全部工具。包括全文搜索和Web爬虫。

http://lucene.apache.org/nutch

http://nutch.sourceforge.net/docs/en/about.html

===============================================

使用tomcat可以跳过第六步

一 安装java环境

[root@dev ~]# java -version

java version "1.4.2"

gcj (GCC) 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)

[root@dev ~]# rpm -qa |grep java

java-1.4.2-gcj-compat-1.4.2.0-26jpp

注:通常,您不必使用 RPM 卸载 JRE,因为 RPM

可以在您安装新版本时自动卸载旧版本的 JRE!除非您准备永久删除 JRE,否则请跳过本节内容。

[root@dev ~]# rpm  -e java-1.4.2-gcj-compat-1.4.2.0-26jpp

[root@dev ~]# chmod 755

jdk-6u10-beta-bin-b24-linux-i586-14_may_2008-rpm.bin\?e\=1212404509\&h\=a151b74ce54cda9cba81a7444944c0ba

[root@dev

~]#./jdk-6u10-beta-bin-b24-linux-i586-14_may_2008-rpm.bin\?e\=1212404509\&h\=a151b74ce54cda9cba81a7444944c0ba

一路空格后健入yes

[root@dev ~]# vi

/etc/profile

set

JAVA_HOME=/usr/java/jdk1.6.0_10

export JAVA_HOME

set

PATH=$PATH:$JAVA_HOME/bin

export PATH

set

CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

export CLASSPATH

bourne shell家族中赋值不用set,这个郁闷了我好久没找到变量无效的原因。

[root@dev ~]# source /etc/profile

用文本编辑器新建一个Test.java文件,在其中输入以下代码并保存:

public class Test {

public static void main(String args[]) {

System.out.println("A new jdk test !");

}

}

编译:在shell终端执行命令 javac Test.java

如果出错可能是javac还没装,先接着下面安装javac后,再返回到这里测试。

运行:在shell终端执行命令 java Test

当shell下出现“A new jdk test !”字样则jdk运行正常。

二 安装ant

http://ant.apache.org/bindownload.cgi

ant是一个基于JAVA的自动化脚本引擎,脚本格式为XML。除了做JAVA编译相关任务外,ANT还可以通过插件实现很多应用的调用,比make脚本来说还要好维护一些。

[root@dev ~]# tar zxvf apache-ant-1.7.0-bin.tar.gz

[root@dev ~]# mv apache-ant-1.7.0 /usr/local/

[root@dev ~]# vi /etc/profile

在JAVA_HOME前加上

ANT_HOME=/usr/local/apache-ant-1.7.0

export ANT_HOME

编辑

set

PATH=$PATH:$JAVA_HOME/bin:$ANT_HOME/bin

[root@dev ~]# source /etc/profile

三 安装lucene

wget

http://apache.mirror.phpchina.com/lucene/java/lucene-2.3.2.tar.gz

不是lucene-2.3.2-src.tar.gz哦,这个无lucene-demos-2.3.2.jar

[root@dev ~]# tar zxvf lucene-2.3.2.tar.gz

[root@dev ~]# mv lucene-2.3.2 /usr/local

四 安装javac

https://javacc.dev.java.net/files/documents/17/26776/javacc-4.0.tar.gz

[root@dev ~]# wget

https://javacc.dev.java.net/files/documents/17/26776/javacc-4.0.tar.gz

[root@dev ~]# gunzip javacc-4.0.tar.gz

[root@dev ~]# tar -xvf javacc-4.0.tar

[root@dev ~]# mv javacc-4.0 /usr/local/

[root@dev ~]# cd /usr/local/lucene-2.3.2

[root@dev ~]# echo javacc.home=/usr/local/javacc-4.0

> ~/build.properties

[root@dev ~]# ant

五 测试lucene

再修改/etc/profile,在CLASSPATH前加上

LUCENE_HOME=/usr/local/lucene-2.3.2

修改变量

CLASSPATH=.:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar:${LUCENE_HOME}/lucene-core-2.3.2.jar:${LUCENE_HOME}/lucene-demos-2.3.2.jar

#source /etc/profile

生成索引

[root@dev ~]# cd ./src/demo

[root@dev demo]# java org.apache.lucene.demo.IndexFiles

/usr/local/lucene-2.3.2/docs

Exception in thread "main" java.lang.NoClassDefFoundError:

org/apache/lucene/demo/IndexFiles

Caused by: java.lang.ClassNotFoundException:

org.apache.lucene.demo.IndexFiles

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:307)

at

sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)

at java.lang.ClassLoader.loadClass(ClassLoader.java:252)

at

java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)

Could not find the main class: org.apache.lucene.demo.IndexFiles.

Program will exit.

出现以上错误估计是CLASSPATH没写对。

搜索...,输入以下命令就会出现搜索提示符。

[root@dev demo]# java org.apache.lucene.demo.SearchFiles

六 安装php-java bridge

php/Java bridge

What is php/Java bridge?

The php/Java bridge is an optimized, XML-based network protocol,

which can be used to connect a native script engine, PHP, with a

Java or ECMA 335 virtual machine. It is more than 50 times faster

than local RPC via SOAP, requires less resources on the web-server

side, and it is faster and more reliable than direct communication

via the Java Native Interface. read more...

http://php-java-bridge.sourceforge.net

[root@dev ~]# wget --limit-rate=15000

http://nchc.dl.sourceforge.net/sourceforge/php-java-bridge/php-java-bridge_5.2.2.tar.gz

[root@dev php-java-bridge-5.2.2]# /opt/lampp/bin/phpize

&& ./configure --disable-servlet

--with-java=/usr/java/jdk1.6.0_10

&& make CFLAGS="-m32"

&& make install

./configure: line 2969: php-config: command not found

./configure: line 2970: php-config: command not found

configure: error: Cannot find php-config. Please use

--with-php-config=PATH

缺少xampp开发包和php-config 路径设置

http://sourceforge.net/project/showfiles.php?group_id=61776&package_id=60248

[root@dev ~]# tar -zxvf xampp-linux-devel-xxx.tar.gz

[root@dev ~]# mv lampp/* /opt/lampp/

mv: cannot overwrite directory `/opt/lampp/lib'

mv: cannot overwrite directory `/opt/lampp/modules'

mv: cannot overwrite directory `/opt/lampp/share'

手动一个个移啦

[root@dev php-java-bridge-5.2.2]# /opt/lampp/bin/phpize

&& ./configure --disable-servlet

--with-php-config=/opt/lampp/bin/php-config

--with-java=/usr/java/jdk1.6.0_10

&& make CFLAGS="-m32"

&& make install

make[1]: *** [php/java/bridge/JavaBridgeIllegalStateException.o]

Error 1

make[1]: Leaving directory

`/root/php-java-bridge-5.2.2/server'

make: *** [/root/php-java-bridge-5.2.2/modules/stamp] Error 2

报两个错,不去理它

[root@dev php-java-bridge-5.2.2]# cp modules/java.so

/opt/lampp/modules/

vi /opt/lampp/etc/php.ini

加上

extension="java.so"

[root@dev php-java-bridge-5.2.2]# /opt/lampp/lampp start

Starting XAMPP for Linux 1.6.1...

PHP Warning: PHP Startup: Unable to load dynamic library

'/opt/lampp/lib/php/extensions/no-debug-non-zts-20060613/java.so' -

/opt/lampp/lib/php/extensions/no-debug-non-zts-20060613/java.so:

cannot open shared object file: No such file or directory in

Unknown on line 0

[root@dev php-java-bridge-5.2.2]# cp modules/java.so

/opt/lampp/lib/php/extensions/no-debug-non-zts-20060613/

[root@dev php-java-bridge-5.2.2]# /opt/lampp/lampp start

Starting XAMPP for Linux 1.6.1...

Exception in thread "main" java.lang.NoClassDefFoundError:

php/java/bridge/Standalone

Caused by: java.lang.ClassNotFoundException:

php.java.bridge.Standalone

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:307)

at

sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)

at java.lang.ClassLoader.loadClass(ClassLoader.java:252)

at

java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)

Could not find the main class: php.java.bridge.Standalone. Program

will exit.

不行咯,换成用tomcat

七 安装tomcat

http://tomcat.apache.org/tomcat-6.0-doc/setup.html

[root@dev ~]# wget --limit-rate=20000

http://apache.mirror.phpchina.com/tomcat/tomcat-6/v6.0.16/bin/apache-tomcat-6.0.16.tar.gz

[root@dev ~]# tar -zxvf apache-tomcat-6.0.16.tar.gz

[root@dev ~]# mv apache-tomcat-6.0.16 /usr/local/apache-tomcat

[root@dev ~]# vi /etc/profile

export JDK_HOME=${JAVA_HOME}

export CATALINA_BASE=/usr/local/apache-tomcat

export CATALINA_HOME=/usr/local/apache-tomcat

[root@dev ~]# source /etc/profile

[root@dev ~]# vi /etc/rc.d/rc.local

/usr/local/apache-tomcat/bin/startup.sh

vi

/usr/local/apache-tomcat/conf/server.xml

port="8080" protocol="HTTP/1.1"

connectionTimeout="20000"

URIEncoding="UTF-8"#增加此行

redirectPort="8443">

appBase="webapps"

unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">

中增加以下内容,将weblucene设为根目录

reloadable="true" debug="0" crossContext="true" />

server.xml默认有下面一行:

这样允许任何人只要telnet到服务器的8005端口,输入"SHUTDOWN",然后回车,服务器立即就被关掉了。

从安全的角度上考虑,我们需要把这个shutdown指令改成一个别人不容易猜测的字符串。

例如修改如下:

,这样就只有在telnet到8006,并且输入"lizongbo"才能够关闭Tomcat.

注意:这个修改不影响shutdown.bat的执行。运行shutdown.bat一样可以关闭服务器。

参考Tomcat安全文档英文链接:http://jakarta.apache.org/tomcat/faq/security.html#8005

还有两个问题需要注意:

1、 对于tomcat3.1中,屏蔽目录文件自动列出的方法是什么?

缺省情况下,如果你访问tomcat下的一个web应用,那么如果你输入的是一个目录名,而且该目录下没有一个可用的welcome文件,那么tomcat会将该目录下的所有文件列出来,如果你想屏蔽这个缺省行为,那么可以修改conf/web.xml文件,将其中的:

default

org.apache.catalina.servlets.DefaultServlet

debug

0

listings

true

1修改为:

default

org.apache.catalina.servlets.DefaultServlet

debug

0

listings

false

1

# cd /usr/local/apache-tomcat/bin

# mv shutdown.sh shutdown.sh.old

# vi /usr/local/apache-tomcat/bin/shutdown.sh

//创建新的shutdown.sh关闭服务脚本

#!/bin/sh

TOMCAT_PID=`/bin/netstat -anp|/bin/grep :8080 |/bin/gawk '{print

$7}' |/bin/gawk -F [/] '{print $1}'`

/bin/kill -9 $TOMCAT_PID 2>/dev/null

if [ $? -ne 0 ];then

echo 'Tomcat is not running.'

else

echo "Succeed to shutdown tomcat."

fi

# chmod a+x shutdown.sh //为新建的脚本文件增加执行权限

八 apache整合

可以避免打8080

编辑apache http.conf

servername devs.c1gstudio.com

ProxyPass / balancer://cluster/

BalancerMember http://192.168.54.96:8080/

 类似资料: