關(guān)于solr的集群主要分為主從和SolrCloud兩種。主從,比較適合以讀為主的場景。SolrCloud適合數(shù)據(jù)量大,時(shí)不時(shí)會(huì)有更新的情形。那么solr的主從配置很簡單。在solrconfig.xml中找到<requestHandler name="/replication" class="solr.ReplicationHandler" > 。這里的replication主要解決主從復(fù)制的。它主要實(shí)現(xiàn):在主進(jìn)行數(shù)據(jù)寫操作,在slave節(jié)點(diǎn)進(jìn)行讀操作。當(dāng)并發(fā)量大些,可以通過擴(kuò)展slave節(jié)點(diǎn)數(shù)來應(yīng)對,多個(gè)slave做一個(gè)反向代理和負(fù)載均衡(在本文中,就不做說明了,如有需要,可以使用nginx或者apache等負(fù)載軟件),供查詢使用。好了,先看看主節(jié)點(diǎn)配置:
<requestHandler name="/replication" class="solr.ReplicationHandler" > <!-- To enable simple master/slave replication, uncomment one of the sections below, depending on whether this solr instance should be the "master" or a "slave". If this instance is a "slave" you will also need to fill in the masterUrl to point to a real machine. --> <lst name="master"> <str name="replicateAfter">commit</str> <str name="replicateAfter">startup</str> <str name="confFiles">schema.xml,stopWords.txt,spellings.txt,synonyms.txt</str> </lst> <!-- <lst name="slave"> <str name="masterUrl">http://your-master-hostname:8983/solr</str> <str name="pollInterval">00:00:60</str> </lst> -->
master 標(biāo)志該core 為主節(jié)點(diǎn)。復(fù)制的行為發(fā)生在commit、startup之后。cofFiles表示,向從節(jié)點(diǎn)復(fù)制的配置文件(記住,主從的solrconfig.xml配置不一樣,不要把solrconfig.xml也復(fù)制到從節(jié)點(diǎn)了)。 再看看slave節(jié)點(diǎn)的配置,slave配置很簡單,把上面的配置文件中master那段注釋掉。把slave那段放開即可。將masterUrl換成master的url,格式:http://your-master-host:port/solr/your_core_name。具體配置如下:
<requestHandler name="/replication" class="solr.ReplicationHandler" > <!-- To enable simple master/slave replication, uncomment one of the sections below, depending on whether this solr instance should be the "master" or a "slave". If this instance is a "slave" you will also need to fill in the masterUrl to point to a real machine. --> <!-- <lst name="master"> <str name="replicateAfter">commit</str> <str name="replicateAfter">startup</str> <str name="confFiles">schema.xml,stopwords.txt</str> </lst> --> <lst name="slave"> <str name="masterUrl">http://192.9.104.116:8090/solr/POI</str> <str name="pollInterval">00:00:20</str> </lst> </requestHandler>
pollInterval 表示多久向master同步一次數(shù)據(jù),數(shù)據(jù)格式{時(shí)}:{分}:{秒}。這個(gè)要根據(jù)你的業(yè)務(wù)場景。如果更新比較頻繁,就把這個(gè)值調(diào)小點(diǎn),反之,就調(diào)大些。在同步數(shù)據(jù)時(shí),根據(jù)網(wǎng)絡(luò)和機(jī)器配置等不同,slave之間的數(shù)據(jù)會(huì)存在不同步的情況。如果,你對此有要求,需要注意了。總之,任何一種集群方案都不是萬能的。solr的主從模式目前存在諸多問題,比如:主節(jié)點(diǎn)有單點(diǎn)故障等等,希望后續(xù)的版本會(huì)有些改進(jìn)。新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注