2 Ekim 2016 Pazar

SolrCloud yeni bir başlangıç

Daha önce hızlıca SolrCloud hakkında konuşmuştuk. Şimdi hızlı bir şekilde temel komutları gözden geçirelim.

bin/solr start -e cloud
Default ayarlarla kurulumu tamamlıyoruz. Daha sonra tekrar çalıştırmak istediğimizde aşağıdaki şekilde çalıştırabiliriz.

bin/solr start -cloud -p 8983 -s "example/cloud/node1/solr" -m 2g
bin/solr start -cloud -p 7574 -s "example/cloud/node2/solr" -z localhost:9983 -m 2g
Sistem default ayarlarla ayağa kalktıktan sonra aşağıdaki şekilde kontrol ediyoruz.

➜  solr-6.0.0 bin/solr status

Found 2 Solr nodes:

Solr process 4600 running on port 7574
{
  "solr_home":"/Users/volkan/project/solr/solr-6.0.0/example/cloud/node2/solr",
  "version":"6.0.0 48c80f91b8e5cd9b3a9b48e6184bd53e7619e7e3 - nknize - 2016-04-01 14:41:49",
  "startTime":"2016-10-01T20:15:22.133Z",
  "uptime":"0 days, 0 hours, 3 minutes, 27 seconds",
  "memory":"91.5 MB (%18.6) of 490.7 MB",
  "cloud":{
    "ZooKeeper":"localhost:9983",
    "liveNodes":"2",
    "collections":"1"}}


Solr process 4497 running on port 8983
{
  "solr_home":"/Users/volkan/project/solr/solr-6.0.0/example/cloud/node1/solr",
  "version":"6.0.0 48c80f91b8e5cd9b3a9b48e6184bd53e7619e7e3 - nknize - 2016-04-01 14:41:49",
  "startTime":"2016-10-01T20:15:15.915Z",
  "uptime":"0 days, 0 hours, 3 minutes, 34 seconds",
  "memory":"74.3 MB (%15.1) of 490.7 MB",
  "cloud":{
    "ZooKeeper":"localhost:9983",
    "liveNodes":"2",
    "collections":"1"}}

Solr kendi içinde 3 farklı config yapısıyla geliyor. Biz bunlardan "data_driven_schema_configs" olanı seçip üzerinde çalışacağız.

Bu ayar yapısında tanımlamasını yapmadığımız "field" lar otomatikmen en uygun olana çevrilir. Klasik ElasticSearch kur çalıştır yapısı gibi düşünebilirsiniz. Ama gerçek anlamda işi olan biri default ayarlarla yetinemez ;)

 server/solr/configsets/data_driven_schema_configs/conf/ dizininde işimiz bittikten sonra yapılan değişiklikleri zookeeper'a göndermemiz gerekiyor. Solr içinde zookeeper yönetmek için güzel bir script mevcut. Bununla işlerimizi rahatlıkla hâlledebiliyoruz.

➜  solr-6.0.0 ./server/scripts/cloud-scripts/zkcli.sh -zkhost localhost:9983
usage: ZkCLI
 -c,--collection    for linkconfig: name of the collection
 -cmd                    cmd to run: bootstrap, upconfig, downconfig,
                         linkconfig, makepath, put, putfile,get,getfile,
                         list, clear, updateacls
 -d,--confdir       for upconfig: a directory of configuration files
 -h,--help               bring up this help page
 -n,--confname      for upconfig, linkconfig: name of the config set
 -name              name of the cluster property to set
 -r,--runzk         run zk internally by passing the solr run port -
                         only for clusters on one machine (tests, dev)
 -s,--solrhome      for bootstrap, runzk: solrhome location
 -val               value of the cluster to set
 -z,--zkhost        ZooKeeper host address
Examples:
zkcli.sh -zkhost localhost:9983 -cmd bootstrap -solrhome /opt/solr
zkcli.sh -zkhost localhost:9983 -cmd upconfig -confdir /opt/solr/collection1/conf -confname myconf
zkcli.sh -zkhost localhost:9983 -cmd downconfig -confdir /opt/solr/collection1/conf -confname myconf
zkcli.sh -zkhost localhost:9983 -cmd linkconfig -collection collection1 -confname myconf
zkcli.sh -zkhost localhost:9983 -cmd makepath /apache/solr
zkcli.sh -zkhost localhost:9983 -cmd put /solr.conf 'conf data'
zkcli.sh -zkhost localhost:9983 -cmd putfile /solr.xml /User/myuser/solr/solr.xml
zkcli.sh -zkhost localhost:9983 -cmd get /solr.xml
zkcli.sh -zkhost localhost:9983 -cmd getfile /solr.xml solr.xml.file
zkcli.sh -zkhost localhost:9983 -cmd clear /solr
zkcli.sh -zkhost localhost:9983 -cmd list
zkcli.sh -zkhost localhost:9983 -cmd clusterprop -name urlScheme -val https
zkcli.sh -zkhost localhost:9983 -cmd updateacls /solr

Aşağıdaki şekilde yaptığımız değişiklikleri Zookeeper'a gönderiyoruz.

solr-6.0.0-> ./server/scripts/cloud-scripts/zkcli.sh -zkhost localhost:9983 -cmd upconfig -confdir server/solr/configsets/data_driven_schema_configs/conf -confname gettingstarted
Yaptığımız değişikliklerin yansıması için;

curl http://localhost:8983/solr/admin/collections?name=gettingstarted&action=RELOAD&wt=json

Bundan sonra shar sayısı ve diğer bütün ayarlar için şuraya bir göz atmak gerekiyor; https://cwiki.apache.org/confluence/display/solr/Collections+API Temel bir şeyleri yazalım.

Backup; Sunucu da öncelikle örnek bir dizin açalım. Daha sonra bu dizine "solr" kullanıcısı için yazma yetkisi verelim

mkdir -p /home/backup/solr 
sudo chown solr:solr /home/backup/solr
curl http://localhost:8983/solr/admin/collections?action=BACKUP&name=gettingstarted&collection=gettingstarted&location=/home/backup/solr&async=1000

async komutu ile arka planda bu süreç çalışmaya devam edecek. Daha sonra ürecin durumunu öğrenmek için

curl http://localhost:8983/solr/admin/collections?action=REQUESTSTATUS&requestid=1000

Süreci farklı şekilde gözden geçirmek adına, hızlıca bir collection oluşturalım;

solr-6.0.0-> bin/solr create_collection -shards 2 -replicationFactor 2 -c test -d server/solr/configsets/data_driven_schema_configs

Bu collection için 2 shard oluşturduk. replicationFactor ise 3 dedik. Şu demek; Bütün datamız ikiye bölünecek. (shard sayısı) replicationFactor ise datanın kaç katı alan kullanacağımızı belirliyor.

Datanın toplam boyutu * replicationFactor kadar yerimiz olmalı. "replicationFactor" 2 olduğunda her sunucuda birebir kopya var demek. 3 olduğunda ek olarak birer "shard"'ın daha kopyası elimizde demek. 4 desek her "shard"'ın 2 yedeği olacak demek. "shard" sayısını daha sonra artırabilirsiniz. Mevcut "shard"ları bölebilirsiniz. API linkinde bu bilgiler mevcut. Aşağıdaki örnek data basımı yaptık.

solr-6.0.0-> bin/post -c test3 example/films

solr-6.0.0-> bin/post -h

Usage: post -c  [OPTIONS] 
    or post -help

   collection name defaults to DEFAULT_SOLR_COLLECTION if not specified

OPTIONS
=======
  Solr options:
    -url  (overrides collection, host, and port)
    -host  (default: localhost)
    -p or -port  (default: 8983)
    -commit yes|no (default: yes)

  Web crawl options:
    -recursive  (default: 1)
    -delay  (default: 10)

  Directory crawl options:
    -delay  (default: 0)

  stdin/args options:
    -type  (default: application/xml)

  Other options:
    -filetypes [,,...] (default: xml,json,jsonl,csv,pdf,doc,docx,ppt,pptx,xls,xlsx,odt,odp,ods,ott,otp,ots,rtf,htm,html,txt,log)
    -params "=[&=...]" (values must be URL-encoded; these pass through to Solr update request)
    -out yes|no (default: no; yes outputs Solr response to console)
    -format solr (sends application/json content as Solr commands to /update instead of /update/json/docs)


Examples:

* JSON file: bin/post -c wizbang events.json
* XML files: bin/post -c records article*.xml
* CSV file: bin/post -c signals LATEST-signals.csv
* Directory of files: bin/post -c myfiles ~/Documents
* Web crawl: bin/post -c gettingstarted http://lucene.apache.org/solr -recursive 1 -delay 1
* Standard input (stdin): echo '{commit: {}}' | bin/post -c my_collection -type application/json -out yes -d
* Data as string: bin/post -c signals -type text/csv -out yes -d $'id,value\n1,0.47'

➜  solr-6.0.0 du -hs example/cloud/node1/solr/test3_shard1_replica1
 76K example/cloud/node1/solr/test3_shard1_replica1
➜  solr-6.0.0 du -hs example/cloud/node1/solr/test3_shard2_replica2
 64K example/cloud/node1/solr/test3_shard2_replica2
➜  solr-6.0.0 du -hs example/cloud/node1/solr/test3_shard1_replica3
 76K example/cloud/node1/solr/test3_shard1_replica3
➜  solr-6.0.0 du -hs example/cloud/node2/solr/test3_shard2_replica1
 64K example/cloud/node2/solr/test3_shard2_replica1
➜  solr-6.0.0 du -hs example/cloud/node2/solr/test3_shard1_replica2/
 76K example/cloud/node2/solr/test3_shard1_replica2/
➜  solr-6.0.0 du -hs example/cloud/node2/solr/test3_shard2_replica3
 64K example/cloud/node2/solr/test3_shard2_replica3




Umarım faydası olur :)

Hiç yorum yok: