部署基于tomcat 8 的solrCloud 5.5集群
部署基于tomcat 8 的solrCloud 5.5集群
@(OTHERS)[solr]
- 部署基于tomcat 8 的solrCloud 55集群
- 一版本及準(zhǔn)備工作
- 二準(zhǔn)備solr相關(guān)webapp內(nèi)容并復(fù)制至tomcat
- 三準(zhǔn)備配置文件并上傳至zk
- 注意這里使用了managed-schema而不是schemaxml之后再分析
- 四準(zhǔn)備solr的索引數(shù)據(jù)目錄及配置
- 五配置tomcat并啟動(dòng)
- 有個(gè)小問(wèn)題如果上面的URL不加上indexhtml則加載不成功看哪里的設(shè)置把默認(rèn)加載index的配置去掉了這會(huì)不會(huì)影響索引等下試一下
- 六添加其它節(jié)點(diǎn)
- 七創(chuàng)建core
- 八使用API索引與搜索
- 1索引
- 2索引
- 九zk中的內(nèi)容
- 十創(chuàng)建新的core
(一)版本及準(zhǔn)備工作
1、下載并解壓tomcat, solr至目錄/home/hadoop/tomcat, /home/hadoop/solr
其中版本為:
(二)準(zhǔn)備solr相關(guān)webapp內(nèi)容,并復(fù)制至tomcat
1、將/home/hadoop/solr-5.5.2/server/lib/ext/*中的jar包復(fù)制到/home/hadoop/solr-5.5.2/server/solr-webapp/webapp/WEB-INF/lib,主要是slf4j與log4j相關(guān)的jar包,tomcat加載solr時(shí)要用到這些jar包。
cp /home/hadoop/solr-5.5.2/server/lib/ext/* /home/hadoop/solr-5.5.2/server/solr-webapp/webapp/WEB-INF/lib2、將上述solr webapp整個(gè)目錄復(fù)制到tomcat/webapps中,并重命名為solr
cp -r /home/hadoop/solr-5.5.2/server/solr-webapp/webapp /home/hadoop/tomcat-8.5.4/webapps/solr(三)準(zhǔn)備配置文件并上傳至zk
1、準(zhǔn)備一個(gè)collection配置文件
一個(gè)collection需要至少schema.xml與solrconfig 2份配置文件,除此以外還有一些stopword,同義詞等配置文件。我們使用官方提供的基本配置basic_configs
注意這里使用了managed-schema,而不是schema.xml。之后再分析。
2、將配置文件上傳至zk
java -classpath .:/home/hadoop/tomcat-8.5.4/webapps/solr/WEB-INF/lib/* org.apache.solr.cloud.ZkCLI -cmd upconfig -zkhost 10.120.69.101:2181,10.120.69.100:2181,10.120.69.102:2181/solr55 -confdir /home/hadoop/solr-5.5.2/conf/basic_configs -confname basic_configs然后再到zk中檢查配置是否成功上傳。
(四)準(zhǔn)備solr的索引數(shù)據(jù)目錄及配置
1、創(chuàng)建用于保存索引文件的目錄
mkdir /disk1/solr55/data/solr-core chown -R hadoop:hadoop /disk1/solr55注意這個(gè)目錄的權(quán)限。
2、將solr.xml復(fù)制到上述目錄
cp /home/hadoop/solr-5.5.2/server/solr/solr.xml /disk1/solr55/data/solr-core/3、 修改solr.xml,修改hostPort和Tomcat端口一致
<int name="hostPort">8080</int>(五)配置tomcat并啟動(dòng)
1、在tomca/conf目錄下創(chuàng)建Catalina/localhost目錄
mkdir -p /home/hadoop/tomcat-8.5.4/conf/Catalina/localhost2、在上述目錄中創(chuàng)建solr.xml,此為Solr/home的配置文件。
<?xml version="1.0" encoding="UTF-8"?><Context docBase="/home/hadoop/tomcat-8.5.4/webapps/solr" debug="0" crossContext="true"> <Environment name="solr/home" type="java.lang.String" value="/disk1/solr55/data/solr-core/" override="true"/> </Context>3、修改bin/catalina.sh中的JAVA_OPTS變量,加上zk的配置:
JAVA_OPTS="$JAVA_OPTS -DzkHost=10.120.69.101:2181,10.120.69.100:2181,10.120.69.102:2181/solr55"4、啟動(dòng)tomcat
bin/startup.sh注意先為幾個(gè)腳本加上權(quán)限:
chmod +x startup.sh shutdown.sh catalina.sh5、驗(yàn)證UI
http://10.120.69.104:8080/solr/index.html
有個(gè)小問(wèn)題:如果上面的URL不加上index.html則加載不成功,看哪里的設(shè)置把默認(rèn)加載index的配置去掉了。這會(huì)不會(huì)影響索引,等下試一下。
6、建一個(gè)測(cè)試collection驗(yàn)證功能
因?yàn)槟壳爸挥幸慌_(tái)機(jī)器,所以只能建一個(gè)shard, 一個(gè)副本了。
配置文件使用上面的basic_configs
然后在UI上查看是否已經(jīng)創(chuàng)建成功。
(六)添加其它節(jié)點(diǎn)
1、將/home/hadoop/solr-5.5.2、/home/hadoop/tomcat-8.5.4與/disk1/solr55/data/ 三個(gè)目錄復(fù)制到其它機(jī)器相同的目錄中。
2、啟動(dòng)tomcat
(七)創(chuàng)建core
curl ‘http://10.120.69.104:8080/solr/admin/collections?action=CREATE&name=collection_2&numShards=2&replicationFactor=2&collection.configName=basic_configs’
創(chuàng)建的2個(gè)core分別如下圖:
(八)使用API索引與搜索
1、索引
public class IndexDemo {private static final String DEFAULT_COLLECTION = "collection4";//private static final String SOLR_ZK = "10.120.69.101:2181/solr";private static final String SOLR_ZK = "10.120.69.101:2181/solr55";public static void main(String[] args) throws SolrServerException, IOException {SolrInputDocument doc = new SolrInputDocument();// 實(shí)例化索引Docdoc.addField("id", "index_demo");// 添加主鍵//doc.addField("qualifier_col", "valuedemo");// 添加主鍵CloudSolrClient client = new CloudSolrClient(SOLR_ZK);// cloud模式client.setDefaultCollection(DEFAULT_COLLECTION);client.add(doc);//client.add("collection1", doc);client.commit();client.close();}}2、索引
public class QueryDemo {private static final String DEFAULT_COLLECTION = "collection4";private static final String SOLR_ZK = "10.120.69.101:2181/solr55"; // private static final String SOLR_ZK = "10.120.69.101:2181/solr";public static void main(String[] args) throws SolrServerException, IOException {try (CloudSolrClient client = new CloudSolrClient(SOLR_ZK);) {// cloud模式//根據(jù)id查docSolrDocument doc = client.getById(DEFAULT_COLLECTION, "index_demo");if(null != doc){for (String field : doc.getFieldNames()) {System.out.println(field + " : " + doc.getFieldValues(field));}}//根據(jù)field查docSolrQuery query = new SolrQuery();//query.setQuery(mQueryString);query.setRequestHandler("/query");// query.set("q", "qualifier_col:valuedemo");//返回index_demo// query.set("q", "qualifier_col:valuedemo OR id:index_demo2");//返回index_demo// query.set("q", "qualifier_col:valuedemo AND id:index_demo2");//返回空// query.set("q", "qualifier_col:valuede*");//返回index_demoQueryResponse response = client.query(DEFAULT_COLLECTION, query);for(SolrDocument doc2 :response.getResults()){System.out.println(doc2.getFieldValue("id"));}}}}(九)zk中的內(nèi)容
[zk: 10.120.69.101(CONNECTED) 16] get /solr5/ configs clusterstate.json aliases.json live_nodes overseer overseer_elect collections通過(guò)命令上傳的配置文件都在configs目錄中,collections中是各個(gè)collection的信息。
其它目錄的詳細(xì)信息以后再分析。
(十)創(chuàng)建新的core
1、準(zhǔn)備配置文件
2、上傳至zk
java -classpath .:/home/hadoop/tomcat-8.5.4/webapps/solr/WEB-INF/lib/* org.apache.solr.cloud.ZkCLI -cmd upconfig -zkhost 10.120.69.101:2181,10.120.69.100:2181,10.120.69.102:2181/solr55 -confdir /home/hadoop/solr/myconf/ -confname myconf3、創(chuàng)建core
curl 'http://10.120.69.104:8080/solr/admin/collections?action=CREATE&name=collection2&numShards=2&replicationFactor=1&collection.configName=myconf' 創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的部署基于tomcat 8 的solrCloud 5.5集群的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: hbase获取region以及读取每个r
- 下一篇: RDD, DataFrame or Da