ソースコードでSolrをローカルで起動する



Locally Launch Solr Source Code



まず、solr5.5.0のソースコードをダウンロードします。 http://apache.fayea.com/lucene/solr/5.5.0/solr-5.5.0-src.tgz 解凍が完了すると、いくつかのディレクトリに分割されます。ただし、Solrはantによってコンパイルされます。これをMavenモードに変換して、dev-tools / mavenとそれに対応する説明があることを確認します:Copy the Maven POM templates from under dev-tools/maven/ to the maven-build/ directory using the following command from the top-level directory: ant get-maven-poms Note that you will need to do this whenever changes to the POM templates are committed. For this reason, it's a good idea run 'ant get-maven-poms' after you update from origin.ソースコードのトップレベルディレクトリであるAntget-maven-pomsで実行すると、プロンプトでivyが検出され、インストールされていないため、ivyの公式Webサイトからダウンロードします。アイビーはアリのプラグインに属しています。 jarパッケージをantインストールディレクトリのlibにコピーする必要があります。このコマンドを実行した後、ビルドを実行できます。アイビーの紹介については、以下を参照してください。 http://www.cnblogs.com/ungshow/archive/2009/07/08/1519111.html ant get-maven-poms Buildfile: /Users/mazhiqiang/develop/study/solr-5.5.0/build.xml resolve: resolve: ivy-availability-check: ivy-fail: ivy-configure: [ivy:configure] :: Apache Ivy 2.4.0 - 20141213170938 :: http://ant.apache.org/ivy/ :: [ivy:configure] :: loading settings :: file = /Users/xxx/develop/study/solr-5.5.0/lucene/ivy-settings.xml resolve: [ivy:retrieve] downloading https://repo1.maven.org/maven2/junit/junit/4.10/junit-4.10.jar ... [ivy:retrieve] ................. (247kB) [ivy:retrieve] .. (0kB) [ivy:retrieve] [SUCCESSFUL ] junit#junit4.10!junit.jar (3616ms) [ivy:retrieve] downloading https://repo1.maven.org/maven2/com/carrotsearch/randomizedtesting/randomizedtesting-runner/2.3.2/randomizedtesting-runner-2.3.2.jar ... [ivy:retrieve] ................ (232kB) [ivy:retrieve] .. (0kB) [ivy:retrieve] [SUCCESSFUL ] com.carrotsearch.randomizedtesting#randomizedtesting-runner2.3.2!randomizedtesting-runner.jar (2142ms) ivy-availability-check: …. -append-module-dependencies-properties: [echo] Get maven dependencies called under: /Users/mazhiqiang/develop/study/solr-5.5.0/lucene/.. -get-maven-poms: [copy] Copying 57 files to /Users/mazhiqiang/develop/study/solr-5.5.0/maven-build BUILD SUCCESSFUL Total time: 20 minutes 13 seconds何度か失敗した後、私は1時間投げて、ついに成功しました。 Ivyもmavenに似ていますが、使用されるリポジトリはユーザーディレクトリ/.ivy/にあります。生成されたpomファイルは、プロジェクトディレクトリに従ってmaven-buildディレクトリに配置され、最上位ディレクトリに直接コピーされます。私の環境構成で使用されているsolrのバージョンは5.5.0ですが、生成されたpom.xmlはアイデアとともにインポートされます。問題が非常に大きい後、直接開始することはできません。 IDEのJVMパラメータ設定でSolrHomeを設定することを好むIDEに関係なく、VM引数は一般的に-Dsolr.solr.home = solr / example / solrを行に書き込みます。いいえ、絶対パスを使用できます。 Solrは、StartSolrJettyファイルをデバッグコードのエントリファイルとして使用します。ここで、サーバーが使用するポートとSolrのwebappsディレクトリを設定できます。通常、設定する必要はありません。デフォルトのものはデバッグできます。 SolrHomeもコードで設定できます。 System.setProperty( 'solr.solr.home'、 'E:\ Work \ solr-4.2.0-src-idea \ solr \ example \ solr')現在、ルートディレクトリとして例が使用されていますsolr構成の。他のsolr構成ディレクトリーがある場合は、それらを設定できます。 [実行]をクリックすると、デバッグは同じです。他の問題は実行できないはずです。プロンプトなど、サーブレットコンテナによって使用されるポートに注意してください。FAILEDroot@ xxxxx:8983:java.net.BindException:アドレスはすでに使用されています:JVM_Bindは、現在のポートが使用されていることを示します。それを変更。エラーがない場合は、起動に成功した後、ブラウザにアドレスを入力できます。http:// localhost:8983 / solr /は、次のインターフェイスを表示できます。

githubからlucene-solrプロジェクトをフォークします。 https://github.com/clamaa/lucene-solr このバージョンは6であるため、以前に使用された一部のjarと互換性がない可能性があります(一部の非推奨クラスは削除されています)。

アイデアから始める

solrソースコードをダウンロードした後、アイデアIDEを起動コンテナとして使用する場合は、ルートディレクトリでantアイデアを実行し、StartSolrJetty.main関数を開始します。 resolve: idea: [copy] Copying 81 files to /Users/xxx/develop/workspace/github/lucene-solr -post-idea-instructions: [echo] [echo] To complete IntelliJ IDEA setup, you must manually configure [echo] File | Project Structure | Project | Project SDK. [echo] [echo] You won't have to do this in the future if you define property [echo] ${idea.jdk}, e.g. in ~/lucene.build.properties, ~/build.properties [echo] or lucene/build.properties, with a value consisting of the [echo] following two XML attributes/values (adjust values according to [echo] JDKs you have defined locally - see [echo] File | Project Structure | Platform Settings | SDKs): [echo] [echo] idea.jdk = project-jdk-name='1.8' project-jdk-type='JavaSDK' [echo] BUILD SUCCESSFUL Total time: 3 minutes 9 seconds アイデアを持ってプロジェクトをインポートした後、すべてのJavaクラスと構成ファイル情報を直接表示できます。 SolrDispatchFilterを変更します。理論的には、現在のServletContextコンテキストでsolr.solr.homeプロパティを読み取る必要があります。直接開始できるように、ローカル絶対パスに直接変更します:// String solrHome = (String) config.getServletContext().getAttribute(SOLRHOME_ATTRIBUTE) String solrHome = '/Users/xxx/develop/workspace/github/lucene-solr/solr/server/solr'スタートアップクラスとしてorg.apache.solr.client.solrj.StartSolrJettyを使用するには、bb.setWar( 'solr / webapp / web')を変更する必要があります。次の情報を出力すると、起動は成功します:objc[5820]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined. Connected to the target VM, address: '127.0.0.1:61273', transport: 'socket' 0 INFO (main) [ ] o.e.j.u.log Logging initialized @975ms 292 INFO (main) [ ] o.e.j.s.Server jetty-9.3.8.v20160314 >>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP 633 INFO (main) [ ] o.e.j.w.StandardDescriptorProcessor NO JSP Support for /solr, did not find org.eclipse.jetty.jsp.JettyJspServlet 697 INFO (main) [ ] o.a.s.s.SolrDispatchFilter SolrDispatchFilter.init(): root@xxxxx 773 INFO (main) [ ] o.a.s.c.SolrResourceLoader new SolrResourceLoader for directory: '/Users/mazhiqiang/develop/workspace/github/lucene-solr/solr/server/solr' 9565 INFO (main) [ ] o.a.s.c.SolrResourceLoader JNDI not configured for solr (NoInitialContextEx) 9565 INFO (main) [ ] o.a.s.c.SolrResourceLoader solr home defaulted to 'solr/' (could not find system property or JNDI) 9582 INFO (main) [ ] o.a.s.c.SolrXmlConfig Loading container configuration from /Users/mazhiqiang/develop/workspace/github/lucene-solr/solr/server/solr/solr.xml 9785 INFO (main) [ ] o.a.s.c.CorePropertiesLocator Config-defined core root directory: /Users/mazhiqiang/develop/workspace/github/lucene-solr/solr/server/solr 9853 INFO (main) [ ] o.a.s.c.CoreContainer New CoreContainer 313239742 9853 INFO (main) [ ] o.a.s.c.CoreContainer Loading cores into CoreContainer [instanceDir=/Users/mazhiqiang/develop/workspace/github/lucene-solr/solr/server/solr] 9855 WARN (main) [ ] o.a.s.c.CoreContainer Couldn't add files from /Users/mazhiqiang/develop/workspace/github/lucene-solr/solr/server/solr/lib to classpath: /Users/mazhiqiang/develop/workspace/github/lucene-solr/solr/server/solr/lib 9893 INFO (main) [ ] o.a.s.h.c.HttpShardHandlerFactory created with socketTimeout : 600000,connTimeout : 60000,maxConnectionsPerHost : 20,maxConnections : 10000,corePoolSize : 0,maximumPoolSize : 2147483647,maxThreadIdleTime : 5,sizeOfQueue : -1,fairnessPolicy : false, 10404 INFO (main) [ ] o.a.s.u.UpdateShardHandler Creating UpdateShardHandler HTTP client with params: 10408 INFO (main) [ ] o.a.s.l.LogWatcher SLF4J impl is org.slf4j.impl.Log4jLoggerFactory 10409 INFO (main) [ ] o.a.s.l.LogWatcher Registering Log Listener [Log4j (org.slf4j.impl.Log4jLoggerFactory)] 10415 INFO (main) [ ] o.a.s.c.CoreContainer Security conf doesn't exist. Skipping setup for authorization module. 10416 INFO (main) [ ] o.a.s.c.CoreContainer No authentication plugin used. 10615 INFO (main) [ ] o.a.s.c.CorePropertiesLocator Looking for core definitions underneath /Users/mazhiqiang/develop/workspace/github/lucene-solr/solr/server/solr 10658 INFO (main) [ ] o.a.s.c.CorePropertiesLocator Found 0 core definitions 10746 INFO (main) [ ] o.a.s.s.SolrDispatchFilter user.dir=/Users/mazhiqiang/develop/workspace/github/lucene-solr 10746 INFO (main) [ ] o.a.s.s.SolrDispatchFilter SolrDispatchFilter.init() done 10772 INFO (main) [ ] o.e.j.s.h.ContextHandler Started root@xxxxx{/solr,file:///Users/mazhiqiang/develop/workspace/github/lucene-solr/solr/webapp/web/,AVAILABLE}{solr/webapp/web} 10802 INFO (main) [ ] o.e.j.s.ServerConnector Started root@xxxxx{HTTP/1.1,[http/1.1]}{0.0.0.0:8983} 10802 INFO (main) [ ] o.e.j.s.Server Started @11904ms以前に開始したプロジェクトでmmseg4jトークナイザーを使用する必要がある場合は、これらのjarもクラスパスに追加する必要があります。そうしないと、次のエラーが発生します。Caused by: java.lang.ClassNotFoundException: com.chenlb.mmseg4j.solr.MMSegTokenizerFactory at java.net.URLClassLoader$1.run(URLClassLoader.java:372) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:360) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:340) at org.apache.solr.core.SolrResourceLoader.findClass(SolrResourceLoader.java:520)必要なjarパッケージをIDEのクラスパスに配置した後、起動に問題はありません。 solrサービスを開始し、Web(http:// localhost:8983 / solr)を介してデバッグできます。 Solrの起動プロセスには主に次のものが含まれます。1。SolrHomeの取得:JNDI、システムプロパティ、デフォルトディレクトリの取得を試みます2.起動時に使用されるクラスローダーSolrResourceLoaderをインスタンス化します3. solrhomeの下にsolr.xmlファイルをロードし、ConfigSolrとしてパッケージ化します4.インスタンス化しますCoreContainerとCoreContainerを介したコアのロード5.core.propertiesを含むフォルダーを探す場合は、SolrHomeをトラバースし、次にコアとして6.マルチスレッドのロードコア7. solrconfig.xmlをロードし、各コアをロードするときにSolrConfigにロードします。 8.schema.xmlパッケージをIndexSchemaにリロードします。9。最後にSolrCoreをインスタンス化します。