AWS で Tomcat 7 に Solr4.5 インストールしたときの メモ

Tomcat と Solr の配置

cd /home/hoge/work/
tar xvfz solr-4.5.0.tgz
tar xvfz apache-tomcat-7.0.42.tar.gz
cd apache-tomcat-7.0.42

cp -r /home/hoge/work/solr-4.5.0/example/solr /home/hoge/work/apache-tomcat-7.0.42
cp -r /home/hoge/work/solr-4.5.0/contrib /home/hoge/work/apache-tomcat-7.0.42/solr
cp -r /home/hoge/work/solr-4.5.0/dist /home/hoge/work/apache-tomcat-7.0.42/solr
cp /home/hoge/work/solr-4.5.0/example/lib/ext/* /home/hoge/work/apache-tomcat-7.0.42/lib # <- 重要 ハマりポイント1

mkdir /home/hoge/work/apache-tomcat-7.0.42/webapps/solr
cd /home/hoge/work/apache-tomcat-7.0.42/webapps/solr
jar xvf /home/hoge/work/solr-4.5.0/example/webapps/solr.war


Tomcat に Solr を組み込む設定

mkdir /home/hoge/work/apache-tomcat-7.0.42/conf/Catalina
mkdir /home/hoge/work/apache-tomcat-7.0.42/conf/Catalina/localhost
vi /home/hoge/work/apache-tomcat-7.0.42/conf/Catalina/localhost/solr.xml
<?xml version="1.0" encoding="utf-8"?>
<Context docBase="solr" debug="0"
crossContext="true">
<Environment name="solr/home" type="java.lang.String" 
value="/home/hoge/work/apache-tomcat-7.0.42/solr" override="true"/>
</Context>


Tomcat の 日本語対応の設定

vi /home/hoge/work/apache-tomcat-7.0.42/conf/server.xml

    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" useBodyEncodingForURI="true"/>


Solr の 日本語対応の設定

vi /home/hoge/work/apache-tomcat-7.0.42/webapps/solr/WEB-INF/web.xml 追記

<!-- Any path (name) registered in solrconfig.xml will be sent to that filter
-->
<filter>
<filter-name>SetCharacterEncoding</filter-name>
<filter-class>org.apache.catalina.filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>


コア collection1 の ライブラリパス修正の設定 # <- 重要 ハマりポイント2

vi /home/hoge/work/apache-tomcat-7.0.42/solr/collection1/conf/solrconfig.xml

  <lib dir="/home/hoge/work/apache-tomcat-7.0.42/solr/contrib/extraction/lib" regex=".*\.jar" />
  <lib dir="/home/hoge/work/apache-tomcat-7.0.42/solr/dist/" regex="solr-cell-\d.*\.jar" />

  <lib dir="/home/hoge/work/apache-tomcat-7.0.42/solr/contrib/clustering/lib/"regex=".*\.jar" />
  <lib dir="/home/hoge/work/apache-tomcat-7.0.42/solr/dist/" regex="solr-clustering-\d.*\.jar" />

  <lib dir="/home/hoge/work/apache-tomcat-7.0.42/solr/contrib/langid/lib/" regex=".*\.jar" />
  <lib dir="/home/hoge/work/apache-tomcat-7.0.42/solr/dist/" regex="solr-langid-\d.*\.jar" />

  <lib dir="/home/hoge/work/apache-tomcat-7.0.42/solr/contrib/contrib/velocity/lib" regex=".*\.jar" />
  <lib dir="/home/hoge/work/apache-tomcat-7.0.42/solr/dist/" regex="solr-velocity-\d.*\.jar" />


起動

/home/hoge/work/apache-tomcat-7.0.42/bin/startup.sh # 起動
tailf /home/hoge/work/apache-tomcat-7.0.42/logs/catalina.out # ログ確認


フィードのテスト

cd /home/hoge/work/solr-4.5.0/example/exampledocs
vi post.sh #修正

#URL=http://localhost:8983/solr/update
URL=http://localhost:8080/solr/update

#curl $URL --data-binary @$f -H 'Content-type:application/xml'
curl $URL --data-binary @$f -H 'Content-type:text/xml; charset=utf-8'

vi hoge.xml # フィードするドキュメント
<add>
  <doc>
    <field name="id">hoge</field>
    <field name="name">hoge 0</field>
    <field name="features">kakkoii</field>
    <field name="features">かっこいい</field>
    <field name="price">0</field>
    <field name="inStock">true</field>
  </doc>
</add>

sh post.sh hoge.xml # フィード