Solr-4.10.3は、Tomcatを介してSolrCloudクラスターモードを開始します



Solr 4 10 3 Starts Solrcloud Cluster Mode Through Tomcat



Pythonエンジニアのための2019Unicorn Enterprise Heavy Recruitment Standard >>> hot3.png

1.1環境への準備:

システム環境:CentOS Linuxリリース7.2.1511(コア)



ソフトウェア環境:Javaとzookeeperを含むHadoop環境が構築されました

Javaバージョン「1.7.0_79」



Zookeeper 3.4.5-cdh5.2.0

Apache-tomcat-7.0.47.tar.gz

Solr-4.10.3.tgz



## 1.2Solrのインストール### 1.2.1Tomcatのインストール

tar -zxvf apache-tomcat-7.0.47.tar.gz mv apache-tomcat-7.0.47 /opt/beh/core/tomcat chown -R hadoop:hadoop /opt/beh/core/tomcat/

### 1.2.2Tomcatにsolr.warを追加する

1.solr.warをsolrの例からtomcatwebappsディレクトリにコピーします

tar -zxvf solr-4.10.3.tgz chown -R hadoop:hadoop solr-4.10.3 cp solr-4.10.3/example/webapps/solr.war /opt/beh/core/tomcat/webapps/ mv solr-4.10.3 /opt/

2. tomcatを起動し、solr.warを自動的に解凍します

su – hadoop sh /opt/beh/core/tomcat/bin/startup.sh Using CATALINA_BASE: /opt/beh/core/tomcat Using CATALINA_HOME: /opt/beh/core/tomcat Using CATALINA_TMPDIR: /opt/beh/core/tomcat/temp Using JRE_HOME: /opt/beh/core/jdk Using CLASSPATH: /opt/beh/core/tomcat/bin/bootstrap.jar:/opt/beh/core/tomcat/bin/tomcat-juli.jar Tomcat started.

3. warパッケージを削除し、Tomcatを閉じます

$ cd /opt/beh/core/tomcat/webapps/ $ rm -f solr.war $ jps 10596 Bootstrap $ kill 10596

### 1.2.3 solrサービスの依存jarパッケージを追加する5つの依存jarパッケージがあり、tomcat(元の45パッケージ)の下のsolrlibにコピーします。

$ cd /opt/solr-4.10.3/example/lib/ext/ $ ls jcl-over-slf4j-1.7.6.jar jul-to-slf4j-1.7.6.jar log4j-1.2.17.jar slf4j-api-1.7.6.jar slf4j-log4j12-1.7.6.jar $ cp * /opt/beh/core/tomcat/webapps/solr/WEB-INF/lib/

### 1.2.4log4j.propertiesを追加します

$ cd /opt/beh/core/tomcat/webapps/solr/WEB-INF/ $ mkdir classes $ cp /opt/solr-4.10.3/example/resources/log4j.properties classes/

### 1.2.5SolrCoreの作成コアをsolrの例からsolrディレクトリにコピーします

$ mkdir -p /opt/beh/core/solr $ cp -r /opt/solr-4.10.3/example/solr/* /opt/beh/core/solr $ ls bin collection1 README.txt solr.xml zoo.cfg

solrの拡張jarをコピーします

$ cd /opt/beh/core/solr $ cp -r /opt/solr-4.10.3/contrib . $ cp -r /opt/solr-4.10.3/dist/ .

contribとdistを使用するように構成します

$ cd collection1/conf/ $ vi solrconfig.xml

### 1.2.6 SolrCoreのロードtomcatのsolr構成ファイルweb.xmlを変更し、solrcoreをロードするように指定します

$ cd /opt/beh/core/tomcat/webapps/solr/WEB-INF $ vi web.xml Modify /put/your/solr/home/here Is /opt/beh/core/solr

### 1.2.7Tomcatを起動する

$ cd /opt/beh/core/tomcat $ ./bin/startup.sh

Webページを表示 http://172.16.13.181:8080/solr 画像

## 1.3Solrcloudの構成### 1.3.1システム環境の構成3台のマシン

ホストIP

Solr001 172.16.13.180 10.10.1.32

Solr002 172.16.13.181 10.10.1.33

Solr003 172.16.13.182 10.10.1.34

### 1.3.2動物園の飼育係を構成する

$ cd $ZOOKEEPER_HOME $ vi zoo.cfg # The number of milliseconds of each tick tickTime=2000 # The number of ticks that the initial # synchronization phase can take initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=5 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. dataDir=/opt/beh/data/zookeeper # the port at which the clients will connect clientPort=2181 # # Be sure to read the maintenance section of the # administrator guide before turning on autopurge. # # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance # # The number of snapshots to retain in dataDir autopurge.snapRetainCount=3 # Purge task interval in hours # Set to '0' to disable auto purge feature autopurge.purgeInterval=1 maxClientCnxns=0 server.1=solr001:2888:3888 server.2=solr002:2888:3888 server.3=solr003:2888:3888

myidを設定すると、3台のマシンをそれぞれ番号1、2、および3に変更する必要があります。 Zookeeperをそれぞれ起動します

$ zkServer.sh start

動物園の飼育係のステータスを表示する

$ zkServer.sh status JMX enabled by default Using config: /opt/beh/core/zookeeper/bin/../conf/zoo.cfg Mode: follower

1.3.3Tomcatを構成する

スタンドアロンバージョンで構成されたTomcatを各マシンに個別にコピーします

$ scp -r tomcat solr002:/opt/beh/core/ $ scp -r tomcat solr003:/opt/beh/core/

1.3.4SolrCoreをコピーする

$ scp -r solr solr002:/opt/beh/core/ $ scp -r solr solr003:/opt/beh/core/

zookeeperを使用して構成ファイルを一律に管理する

$ cd /opt/solr-4.10.3/example/scripts/cloud-scripts $ ./zkcli.sh -zkhost 10.10.1.32:2181,10.10.1.33:2181,10.10.1.34:2181 -cmd upconfig -confdir /opt/beh/core/solr/collection1/conf -confname solrcloud

zookeeperにログインすると、新しく作成されたsolrcloudフォルダーが表示されます。

$ zkCli.sh [zk: localhost:2181(CONNECTED) 1] ls / [configs, zookeeper] [zk: localhost:2181(CONNECTED) 2] ls /configs [solrcloud]

各ノードのTomcat構成ファイルを変更し、DzkHostを追加してzookeeperサーバーのアドレスを指定します

$ cd /opt/beh/core/tomcat/bin $ vi catalina.sh JAVA_OPTS='-DzkHost=10.10.1.32:2181,10.10.1.33:2181,10.10.1.34:2181' At the same time, also modify the boot jvm memory here JAVA_OPTS='-server -Xmx4096m -Xms2048m -DzkHost=10.10.1.32:2181,10.10.1.33:2181,10.10.1.34:2181'

solrcloudのWeb構成を変更します。各マシンは、独自のIPアドレスに変更されます。

$ cd /opt/beh/core/solr $ vi solr.xml ${host:10.10.1.32} ${jetty.port:8080}

### 1.3.5Tomcatを起動する

すべてのマシンを起動する必要があります

$ cd /opt/beh/core/tomcat $ ./bin/startup.sh

Webポートにログインして表示します

http://172.16.13.181:8080/solr

誰でもします

### 1.3.6ノードの追加Solrcloudは、ノードを追加するのに便利です。

  1. このノードのjdkを構成します
  2. 設定されたノードからTomcatディレクトリ全体をコピーします
  3. 構成されたノードからsolrディレクトリー全体をコピーします
  4. /opt/beh/core/solr/solr.xml構成ファイルをローカルIPアドレスに変更します
  5. collection1の下のデータディレクトリを削除します
  6. Tomcatを開始します
Check the tomcat log to see if it started successfully $ tail –f /opt/beh/core/tomcat/logs/catalina.out November 30, 2016 4:46:03 pm org.apache.coyote.AbstractProtocol init Information: Initializing ProtocolHandler ['ajp-bio-8009'] November 30, 2016 4:46:03 pm org.apache.catalina.startup.Catalina load Information: Initialization processed in 868 ms November 30, 2016 4:46:03 pm org.apache.catalina.core.StandardService startInternal Information: Starting service Catalina November 30, 2016 4:46:03 pm org.apache.catalina.core.StandardEngine startInternal Information: Starting Servlet Engine: Apache Tomcat/7.0.47 November 30, 2016 4:46:03 pm org.apache.catalina.startup.HostConfig deployDirectory Information: Deploying web application directory /opt/beh/core/tomcat/webapps/ROOT May be stuck here for a few minutes 。。。 Information: Server startup in 332872 ms 6133 [coreZkRegister-1-thread-1] INFO org.apache.solr.cloud.ZkController – We are http://10.10.1.36:8080/solr/collection1/ and leader is http://10.10.1.33:8080/solr/collection1/ 6134 [coreZkRegister-1-thread-1] INFO org.apache.solr.cloud.ZkController – No LogReplay needed for core=collection1 baseURL=http://10.10.1.36:8080/solr 6134 [coreZkRegister-1-thread-1] INFO org.apache.solr.cloud.ZkController – Core needs to recover:collection1 6134 [coreZkRegister-1-thread-1] INFO org.apache.solr.update.DefaultSolrCoreState – Running recovery - first canceling any ongoing recovery 6139 [RecoveryThread] INFO org.apache.solr.cloud.RecoveryStrategy – Starting recovery process. core=collection1 recoveringAfterStartup=true 6140 [RecoveryThread] INFO org.apache.solr.cloud.RecoveryStrategy – ###### startupVersions=[] 6140 [RecoveryThread] INFO org.apache.solr.cloud.RecoveryStrategy – Publishing state of core collection1 as recovering, leader is http://10.10.1.33:8080/solr/collection1/ and I am http://10.10.1.36:8080/solr/collection1/ 6141 [RecoveryThread] INFO org.apache.solr.cloud.ZkController – publishing core=collection1 state=recovering collection=collection1 6141 [RecoveryThread] INFO org.apache.solr.cloud.ZkController – numShards not found on descriptor - reading it from system property 6165 [RecoveryThread] INFO org.apache.solr.cloud.RecoveryStrategy – Sending prep recovery command to http://10.10.1.33:8080/solr WaitForState: action=PREPRECOVERY&core=collection1&nodeName=10.10.1.36%3A8080_solr&coreNodeName=core_node4&state=recovering&checkLive=true&onlyIfLeader=true&onlyIfLeaderActive=true 6180 [zkCallback-2-thread-1] INFO org.apache.solr.common.cloud.ZkStateReader – A cluster state change: WatchedEvent state:SyncConnected type:NodeDataChanged path:/clusterstate.json, has occurred - updating... (live nodes size: 4) 8299 [RecoveryThread] INFO org.apache.solr.cloud.RecoveryStrategy – Attempting to PeerSync from http://10.10.1.33:8080/solr/collection1/ core=collection1 - recoveringAfterStartup=true 8303 [RecoveryThread] INFO org.apache.solr.update.PeerSync – PeerSync: core=collection1 url=http://10.10.1.36:8080/solr START replicas=[http://10.10.1.33:8080/solr/collection1/] nUpdates=100 8306 [RecoveryThread] WARN org.apache.solr.update.PeerSync – no frame of reference to tell if we've missed updates 8306 [RecoveryThread] INFO org.apache.solr.cloud.RecoveryStrategy – PeerSync Recovery was not successful - trying replication. core=collection1 8306 [RecoveryThread] INFO org.apache.solr.cloud.RecoveryStrategy – Starting Replication Recovery. core=collection1 8306 [RecoveryThread] INFO org.apache.solr.cloud.RecoveryStrategy – Begin buffering updates. core=collection1 8307 [RecoveryThread] INFO org.apache.solr.update.UpdateLog – Starting to buffer updates. FSUpdateLog{state=ACTIVE, tlog=null} 8307 [RecoveryThread] INFO org.apache.solr.cloud.RecoveryStrategy – Attempting to replicate from http://10.10.1.33:8080/solr/collection1/. core=collection1 8325 [RecoveryThread] INFO org.apache.solr.handler.SnapPuller – No value set for 'pollInterval'. Timer Task not started. 8332 [RecoveryThread] INFO org.apache.solr.cloud.RecoveryStrategy – No replay needed. core=collection1 8332 [RecoveryThread] INFO org.apache.solr.cloud.RecoveryStrategy – Replication Recovery was successful - registering as Active. core=collection1 8332 [RecoveryThread] INFO org.apache.solr.cloud.ZkController – publishing core=collection1 state=active collection=collection1 8333 [RecoveryThread] INFO org.apache.solr.cloud.ZkController – numShards not found on descriptor - reading it from system property 8348 [RecoveryThread] INFO org.apache.solr.cloud.RecoveryStrategy – Finished recovery process. core=collection1 8379 [zkCallback-2-thread-1] INFO org.apache.solr.common.cloud.ZkStateReader – A cluster state change: WatchedEvent state:SyncConnected type:NodeDataChanged path:/clusterstate.json, has occurred - updating... (live nodes size: 4)

Webページを表示し、4番目のノードを正常に追加します

collection1にはシャードshard1があり、shard1には4つのコピーがあり、そのうちの黒い点のIPは33がマスターコピーであることがわかります。

#2クラスター管理## 2.1コレクションの作成2つのシャードでコレクションを作成し、各シャードには2つのコピーがあります

$ curl 'http://172.16.13.180:8080/solr/admin/collections?action=CREATE&name=collection2&numShards=2&replicationFactor=2&wt=json&indent=true'

さらに、Webページで直接 ''のリンクを開くこともできます。2つの方法の結果は同じです。

#2.2コレクションを削除する

$ curl 'http://172.16.13.180:8080/solr/admin/collections?action=DELETE&name=collection2&wt=json&indent=true'

## 2.3IK中国語トークナイザーの構成### 2.3.1スタンドアロン構成

1.iパッケージをダウンロードします

http://code.google.com/p/ik-analyzer/downloads/list

IKアナライザー2012FF_hf1.zipをダウンロード

2.解凍してサーバーにアップロードします

3.jarパッケージをコピーします

cp IKAnalyzer2012FF_u1.jar /opt/solr/apache-tomcat-7.0.47/webapps/solr/WEB-INF/lib/

4.構成ファイルとワードブレーカーストップ辞書をコピーします

cp IKAnalyzer.cfg.xml /opt/solr/solrhome/contrib/analysis-extras/lib/ cp stopword.dic /opt/solr/solrhome/contrib/analysis-extras/lib/

5. fieldTypeを定義し、中国語のトークナイザーを使用します

cd /opt/solr/solrhome/solr/collection1/conf vi schema.xml

6.Tomcatを再起動します

cd /opt/solr/apache-tomcat-7.0.47/ ./bin/shutdown.sh ./bin/startup.sh

7.テスト用のWebページ

title_ikまたはcontent_ikは[フィールド]の下にあり、text-ikは[フィールド名/フィールドタイプの分析]の[タイプ]の下にあります。[値の分析]をクリックして分析します。

### 2.3.2クラスターバージョンの構成1.jarパッケージと構成ファイル、およびワードブレーカーストップワード辞書を各ノードの対応する場所にコピーします。

cp IKAnalyzer2012FF_u1.jar /opt/beh/core/tomcat/webapps/solr/WEB-INF/lib/ cp IKAnalyzer.cfg.xml stopword.dic /opt/beh/core/solr/contrib/analysis-extras/lib/

2. schema.xml構成ファイルを変更してfieldTypeを定義し、中国語のワードブレーカーを使用します

スタンドアロン構成を参照してください

3.構成ファイルをzookeeperにアップロードします

cd /opt/solr-4.10.3/example/scripts/cloud-scripts ./zkcli.sh -zkhost 10.10.1.32:2181,10.10.1.33:2181,10.10.1.34:2181 -cmd upconfig -confdir /opt/beh/core/solr/collection1/conf -confname solrcloud

4.すべてのノードでTomcatを再起動します

5.任意のノードのWebページを開いて、IKトークナイザーが正常に構成されていることを確認します。

#3統合HDFS ## 3.1構成の変更Solrはhdfsを統合します。主に、hdfsにインデックスを格納するために、構成ファイルsolrconfig.xmlを調整します。

cd /opt/beh/core/solr/collection1/conf vi solrconfig.xml 1. Modify the default configuration of the section to the following configuration: hdfs://beh/solr true 1 true 16384 true true true 16 192 /opt/beh/core/hadoop/etc/hadoop 2. Modify solr.lock.type Change ${solr.lock.type:native} to ${solr.lock.type:hdfs}

## 3.3構成ファイルをzookeeperにアップロードする

cd /opt/solr-4.10.3/example/scripts/cloud-scripts ./zkcli.sh -zkhost 10.10.1.32:2181,10.10.1.33:2181,10.10.1.34:2181 -cmd upconfig -confdir /opt/beh/core/solr/collection1/conf -confname solrcloud

## 3.4Tomcatを再起動します

cd /opt/solr/apache-tomcat-7.0.47/ ./bin/shutdown.sh ./bin/startup.sh

3.5チェック

hdfsディレクトリを表示する

$ hadoop fs -ls /solr Found 2 items drwxr-xr-x - hadoop hadoop 0 2016-12-06 15:31 /solr/collection1 $ hadoop fs -ls /solr/collection1 Found 4 items drwxr-xr-x - hadoop hadoop 0 2016-12-06 15:31 /solr/collection1/core_node1 drwxr-xr-x - hadoop hadoop 0 2016-12-06 15:31 /solr/collection1/core_node2 drwxr-xr-x - hadoop hadoop 0 2016-12-06 15:31 /solr/collection1/core_node3 drwxr-xr-x - hadoop hadoop 0 2016-12-06 15:31 /solr/collection1/core_node4 $ hadoop fs -ls /solr/collection1/core_node1 Found 1 items drwxr-xr-x - hadoop hadoop 0 2016-12-06 15:31 /solr/collection1/core_node1/data

ページを表示すると、collection1のデータパスが対応するhdfsディレクトリに割り当てられていることがわかります。

画像

転載:https://my.oschina.net/xiaozhublog/blog/801287