You are here

run_elasticsearch.sh in Search API Elasticsearch 7

#!/bin/bash

check_port_http_code() {
    http_code=`echo $(curl -s -o /dev/null -w "%{http_code}" "http://localhost:$1")`
    return `test $http_code = "$2"`
}

wget http://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-${ES_VER}.tar.gz
tar -xzf elasticsearch-${ES_VER}.tar.gz

elasticsearch-${ES_VER}/bin/plugin -install elasticsearch/elasticsearch-mapper-attachments/${ES_MAPPER_ATTACHMENTS_VER}
elasticsearch-${ES_VER}/bin/plugin -install elasticsearch/elasticsearch-transport-thrift/${ES_TRANSPORT_THRIFT_VER}
elasticsearch-${ES_VER}/bin/plugin -install geocluster-facet --url https://github.com/zenobase/geocluster-facet/releases/download/${ES_GEOCLUSTER_FACET_VER}/geocluster-facet-${ES_GEOCLUSTER_FACET_VER}.jar
elasticsearch-${ES_VER}/bin/plugin -install http-basic-auth --url https://github.com/Asquera/elasticsearch-http-basic/releases/download/${ES_HTTP_BASIC_AUTH_VER}/elasticsearch-http-basic-${ES_HTTP_BASIC_AUTH_VER}.jar

export JAVA_OPTS="-server"

for i in 0 1
do
    echo "Setup node #$i"

    let "http_port = 9200 + $i"
    let "thrift_port = 9500 + $i"

    config_yml=elasticsearch-${ES_VER}/config/elasticsearch-$http_port.yml

    echo "Creating config $config_yml"

    cp elasticsearch-${ES_VER}/config/elasticsearch.yml $config_yml

    echo "index.number_of_shards: 2" >> $config_yml
    echo "index.number_of_replicas: 0" >> $config_yml
    echo "discovery.zen.ping.multicast.enabled: false" >> $config_yml
    echo "http.port: $http_port" >> $config_yml
    echo "thrift.port: $thrift_port" >> $config_yml

    # enable udp
    echo "bulk.udp.enabled: true" >> $config_yml
    echo "bulk.udp.bulk_actions: 5" >> $config_yml

    if [ $i -eq 1 ] ; then
      echo "http.basic.enabled: TRUE" >> $config_yml
      echo "http.basic.user: testuser" >> $config_yml
      echo "http.basic.password: testpassword" >> $config_yml
    fi

    echo "Starting server on http port: $http_port"

    elasticsearch-${ES_VER}/bin/elasticsearch -Des.config=$config_yml &

    while ! check_port_http_code $http_port 200; do
        echo -n "."
        sleep 2s
    done
    echo ""
    echo "Server #$i is up"
done

echo "two elasticsearch nodes should be up"

File

tests/bin/run_elasticsearch.sh
View source
  1. #!/bin/bash
  2. check_port_http_code() {
  3. http_code=`echo $(curl -s -o /dev/null -w "%{http_code}" "http://localhost:$1")`
  4. return `test $http_code = "$2"`
  5. }
  6. wget http://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-${ES_VER}.tar.gz
  7. tar -xzf elasticsearch-${ES_VER}.tar.gz
  8. elasticsearch-${ES_VER}/bin/plugin -install elasticsearch/elasticsearch-mapper-attachments/${ES_MAPPER_ATTACHMENTS_VER}
  9. elasticsearch-${ES_VER}/bin/plugin -install elasticsearch/elasticsearch-transport-thrift/${ES_TRANSPORT_THRIFT_VER}
  10. elasticsearch-${ES_VER}/bin/plugin -install geocluster-facet --url https://github.com/zenobase/geocluster-facet/releases/download/${ES_GEOCLUSTER_FACET_VER}/geocluster-facet-${ES_GEOCLUSTER_FACET_VER}.jar
  11. elasticsearch-${ES_VER}/bin/plugin -install http-basic-auth --url https://github.com/Asquera/elasticsearch-http-basic/releases/download/${ES_HTTP_BASIC_AUTH_VER}/elasticsearch-http-basic-${ES_HTTP_BASIC_AUTH_VER}.jar
  12. export JAVA_OPTS="-server"
  13. for i in 0 1
  14. do
  15. echo "Setup node #$i"
  16. let "http_port = 9200 + $i"
  17. let "thrift_port = 9500 + $i"
  18. config_yml=elasticsearch-${ES_VER}/config/elasticsearch-$http_port.yml
  19. echo "Creating config $config_yml"
  20. cp elasticsearch-${ES_VER}/config/elasticsearch.yml $config_yml
  21. echo "index.number_of_shards: 2" >> $config_yml
  22. echo "index.number_of_replicas: 0" >> $config_yml
  23. echo "discovery.zen.ping.multicast.enabled: false" >> $config_yml
  24. echo "http.port: $http_port" >> $config_yml
  25. echo "thrift.port: $thrift_port" >> $config_yml
  26. # enable udp
  27. echo "bulk.udp.enabled: true" >> $config_yml
  28. echo "bulk.udp.bulk_actions: 5" >> $config_yml
  29. if [ $i -eq 1 ] ; then
  30. echo "http.basic.enabled: TRUE" >> $config_yml
  31. echo "http.basic.user: testuser" >> $config_yml
  32. echo "http.basic.password: testpassword" >> $config_yml
  33. fi
  34. echo "Starting server on http port: $http_port"
  35. elasticsearch-${ES_VER}/bin/elasticsearch -Des.config=$config_yml &
  36. while ! check_port_http_code $http_port 200; do
  37. echo -n "."
  38. sleep 2s
  39. done
  40. echo ""
  41. echo "Server #$i is up"
  42. done
  43. echo "two elasticsearch nodes should be up"