【solr专题之四】在Tomcat 中部署Solr4.x 分类: H_HISTORY 2014-07-17 16:08 1286人阅读 评论(0) 收藏

1、安装Tomcat

(1)下载并解压至/opt/tomcat中
# cd /opt/jediael
# tar -zxvf apache-tomcat-7.0.54.tar.gz 
# mv apache-tomcat-7.0.54 tomcat   将目录重命名为tomcat
# ls
apache-tomcat-7.0.54.tar.gz rh tomcat

(2)配置conf/tomcat-users.xml ,以方便管理及通过页面进行配置
<role rolename="manager-gui"/>
<user username="tomcat" password="tomcat" roles="manager-gui"/>

(3)启动tomcat并验证
# bin/startup.sh
Using CATALINA_BASE: /opt/jediael/tomcat
Using CATALINA_HOME: /opt/jediael/tomcat
Using CATALINA_TMPDIR: /opt/jediael/tomcat/temp
Using JRE_HOME: /usr/java/jdk1.7.0_51
Using CLASSPATH: /opt/jediael/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
Tomcat started.

打开http://ip:8080/,正常登录
打开http://ip:8080/manager/html,使用用户名密码tomcat/tomcat进行登录

2、部署Solr
(1)将solr解压后的example/solr目录复制至/opt/jediael/solr/example/solr
# mkdir -p /opt/jediael/solr/example
# cp -rf /opt/jediael/solr-4.9.0/example/solr /opt/jediael/solr/example

(2)将dist/solr-4.9.0.war复制至/opt/jediael/solr/example/solr,并重命名为solr.war
# pwd
/opt/jediael/solr/example/solr
# cp /opt/jediael/solr-4.9.0/dist/solr-4.9.0.war solr.war
# ls
bin collection1 README.txt solr.war solr.xml zoo.cfg

(3)配置solrconfig.xml ,指定数据目录
# pwd
/opt/jediael/solr/example/solr/collection1
 vi conf/solrconfig.xml 
修改以下内容:
  <dataDir>${solr.data.dir:}</dataDir>
  <dataDir>${solr.data.dir:/opt/jediael/solr/example/solr/collection1/data}</dataDir>
解释如下:which is true for running the Jetty server provided with the example, but incorrect for Tomcat running as a service.
例上述配置马上生效:

export JAVA_OPTS="$JAVA_OPTS -Dsolr.data.dir=/opt/jediael/solr/example/solr/collection1/data"
(4)在tomcat中指向上述程序包
至少启动一次tomcat,才会生成此目录
在/opt/jediael/tomcat/conf/Catalina/localhost/创建一个新文件:
# cd /opt/jediael/tomcat/conf/Catalina/localhost/
# ls
# vi solr.xml
内容如下:
<?xml version="1.0" encoding="utf-8"?>
<Context docBase="/opt/jediael/solr/example/solr/solr.war" debug="0" crossContext="true">
  <Environment name="solr/home" type="java.lang.String" value="/opt/jediael/solr/example/solr" override="true"/>
</Context>

(5)复制jar文件及log4j的配置文件
# cp /opt/jediael/solr-4.9.0/example/lib/ext/* /opt/jediael/tomcat/lib/
# mkdir logs
# pwd
/opt/jediael/solr/example/solr
# cp /opt/jediael/solr-4.9.0/example/resources/log4j.properties /opt/jediael/tomcat/lib/
# vi  /opt/jediael/tomcat/lib/log4j.properties 
修改:
solr.log=/opt/jediael/solr/example/solr/logs/
(6)复制jar包
[# pwd
/opt/jediael/solr/example/solr
# mkdir lib
# cp /opt/jediael/solr-4.9.0/dist/*.jar lib/
# cp /opt/jediael/solr-4.9.0/contrib/velocity/lib/* lib/ 

3、启动并验证
(1)启动tomcat
bin/startup.sh

(2)验证以下页面
http://ip:8080/manager/html  查看运行状态
http://ip:8080/solr/
http://ip:8080/solr/collection1/browse




4、分析

(1)上述war包被解压至 /opt/jediael/tomcat/webapps/solr,其内容如下:

# ls
admin.html  css  favicon.ico  img  js  META-INF  tpl  WEB-INF

除war包外的内容:

# lsbin collection1 lib logs README.txt solr.war solr.xml zoo.cfg

保留在原来位置,并没变化。

Repeat the above steps with different installation directories to run multiple instances of Solr side-by-side.






版权声明:本文为博主原创文章,未经博主允许不得转载。

posted @ 2014-07-17 16:08  lujinhong2  阅读(159)  评论(0编辑  收藏  举报