yum localinstall https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/rpm/elasticsearch/2.3.4/elasticsearch-2.3.4.rpm
rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch cat >> /etc/yum.repos.d/elasticsearch.repo <<EOF [elasticsearch-2.x] name=Elasticsearch repository for 2.x packages baseurl=https://packages.elastic.co/elasticsearch/2.x/centos gpgcheck=1 gpgkey=https://packages.elastic.co/GPG-KEY-elasticsearch enabled=1 EOF yum install elasticsearch sudo /bin/systemctl daemon-reload sudo /bin/systemctl enable elasticsearch.service
查看 RPM 包中所含檔案
[root@localhost ~]# rpm -ql elasticsearch-2.3.4-1.noarch /etc/elasticsearch /etc/elasticsearch/elasticsearch.yml /etc/elasticsearch/logging.yml /etc/elasticsearch/scripts /etc/init.d/elasticsearch /etc/sysconfig/elasticsearch /usr/lib/sysctl.d /usr/lib/sysctl.d/elasticsearch.conf /usr/lib/systemd/system/elasticsearch.service /usr/lib/tmpfiles.d /usr/lib/tmpfiles.d/elasticsearch.conf /usr/share/elasticsearch/LICENSE.txt /usr/share/elasticsearch/NOTICE.txt /usr/share/elasticsearch/README.textile /usr/share/elasticsearch/bin /usr/share/elasticsearch/bin/elasticsearch /usr/share/elasticsearch/bin/elasticsearch-systemd-pre-exec /usr/share/elasticsearch/bin/elasticsearch.in.sh /usr/share/elasticsearch/bin/plugin /usr/share/elasticsearch/lib /usr/share/elasticsearch/lib/HdrHistogram-2.1.6.jar /usr/share/elasticsearch/lib/apache-log4j-extras-1.2.17.jar /usr/share/elasticsearch/lib/commons-cli-1.3.1.jar /usr/share/elasticsearch/lib/compiler-0.8.13.jar /usr/share/elasticsearch/lib/compress-lzf-1.0.2.jar /usr/share/elasticsearch/lib/elasticsearch-2.3.4.jar /usr/share/elasticsearch/lib/guava-18.0.jar /usr/share/elasticsearch/lib/hppc-0.7.1.jar /usr/share/elasticsearch/lib/jackson-core-2.6.6.jar /usr/share/elasticsearch/lib/jackson-dataformat-cbor-2.6.6.jar /usr/share/elasticsearch/lib/jackson-dataformat-smile-2.6.6.jar /usr/share/elasticsearch/lib/jackson-dataformat-yaml-2.6.6.jar /usr/share/elasticsearch/lib/jna-4.1.0.jar /usr/share/elasticsearch/lib/joda-convert-1.2.jar /usr/share/elasticsearch/lib/joda-time-2.9.4.jar /usr/share/elasticsearch/lib/jsr166e-1.1.0.jar /usr/share/elasticsearch/lib/jts-1.13.jar /usr/share/elasticsearch/lib/log4j-1.2.17.jar /usr/share/elasticsearch/lib/lucene-analyzers-common-5.5.0.jar /usr/share/elasticsearch/lib/lucene-backward-codecs-5.5.0.jar /usr/share/elasticsearch/lib/lucene-core-5.5.0.jar /usr/share/elasticsearch/lib/lucene-grouping-5.5.0.jar /usr/share/elasticsearch/lib/lucene-highlighter-5.5.0.jar /usr/share/elasticsearch/lib/lucene-join-5.5.0.jar /usr/share/elasticsearch/lib/lucene-memory-5.5.0.jar /usr/share/elasticsearch/lib/lucene-misc-5.5.0.jar /usr/share/elasticsearch/lib/lucene-queries-5.5.0.jar /usr/share/elasticsearch/lib/lucene-queryparser-5.5.0.jar /usr/share/elasticsearch/lib/lucene-sandbox-5.5.0.jar /usr/share/elasticsearch/lib/lucene-spatial-5.5.0.jar /usr/share/elasticsearch/lib/lucene-spatial3d-5.5.0.jar /usr/share/elasticsearch/lib/lucene-suggest-5.5.0.jar /usr/share/elasticsearch/lib/netty-3.10.5.Final.jar /usr/share/elasticsearch/lib/securesm-1.0.jar /usr/share/elasticsearch/lib/snakeyaml-1.15.jar /usr/share/elasticsearch/lib/spatial4j-0.5.jar /usr/share/elasticsearch/lib/t-digest-3.0.jar /usr/share/elasticsearch/modules /usr/share/elasticsearch/modules/lang-expression /usr/share/elasticsearch/modules/lang-expression/antlr4-runtime-4.5.1-1.jar /usr/share/elasticsearch/modules/lang-expression/asm-5.0.4.jar /usr/share/elasticsearch/modules/lang-expression/asm-commons-5.0.4.jar /usr/share/elasticsearch/modules/lang-expression/lang-expression-2.3.4.jar /usr/share/elasticsearch/modules/lang-expression/lucene-expressions-5.5.0.jar /usr/share/elasticsearch/modules/lang-expression/plugin-descriptor.properties /usr/share/elasticsearch/modules/lang-expression/plugin-security.policy /usr/share/elasticsearch/modules/lang-groovy /usr/share/elasticsearch/modules/lang-groovy/groovy-2.4.6-indy.jar /usr/share/elasticsearch/modules/lang-groovy/lang-groovy-2.3.4.jar /usr/share/elasticsearch/modules/lang-groovy/plugin-descriptor.properties /usr/share/elasticsearch/modules/lang-groovy/plugin-security.policy /usr/share/elasticsearch/modules/reindex /usr/share/elasticsearch/modules/reindex/plugin-descriptor.properties /usr/share/elasticsearch/modules/reindex/reindex-2.3.4.jar /usr/share/elasticsearch/plugins /var/lib/elasticsearch /var/log/elasticsearch /var/run/elasticsearch
啟動
/etc/init.d/elasticsearch start
連結測試
[root@localhost ~]# curl -X GET http://localhost:9200/ { "name" : "Jack of Hearts", "cluster_name" : "elasticsearch", "version" : { "number" : "2.3.4", "build_hash" : "e455fd0c13dceca8dbbdbb1665d068ae55dabe3f", "build_timestamp" : "2016-06-30T11:24:31Z", "build_snapshot" : false, "lucene_version" : "5.5.0" }, "tagline" : "You Know, for Search" }
cd /usr/local/src/ wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v1.9.4/elasticsearch-analysis-ik-1.9.4.zip cd /usr/share/elasticsearch/plugins mkdir ik cd ik unzip /usr/local/src/elasticsearch-analysis-ik-1.9.4.zip /etc/init.d/elasticsearch restart
curl -XDELETE http://localhost:9200/information/news/_mapping?pretty curl -XDELETE http://localhost:9200/information/?pretty curl -XPUT http://localhost:9200/information curl -XPOST http://localhost:9200/information/news/_mapping?pretty -d' { "news": { "_all": { "analyzer": "ik_max_word", "search_analyzer": "ik_max_word", "term_vector": "no", "store": "false" }, "properties": { "content": { "type": "string", "store": "no", "term_vector": "with_positions_offsets", "analyzer": "ik_max_word", "search_analyzer": "ik_max_word", "include_in_all": "true", "boost": 8 } } } }' curl -XPOST http://localhost:9200/information/news/ -d' {"title": "越南胡志明遊記·教堂·管風琴的天籟之音","content":"這是我平生第一次去教堂,也是第一次完整的參加宗教儀式。當我駐足教堂外的時候,耳邊傳來天籟之音,是管風琴,確切的說是電子風琴。真正的管風琴造價昂貴,管風琴通常需要根據教堂尺寸定製,無法量產。我記得中國只有4座管風琴,深圳音樂廳有一座。"} ' curl -XPOST http://localhost:9200/information/news/ -d' {"title": "越南胡志明遊記·信仰·法事","content":"佛經的形成過程是與佛教的發展相始終的,按照佛教發展的時間順序,最早形成的是小乘佛教三藏,之後形成的是大乘佛教三藏,最後形成的是密宗三藏。"} ' curl -XPOST http://localhost:9200/information/news/_search -d' { "query" : { "term" : { "content" : "佛經" }}, "highlight" : { "pre_tags" : ["<strong>", "<strong>"], "post_tags" : ["</strong>", "</strong>"], "fields" : { "content" : {} } } }' curl -XPOST http://localhost:9200/information/news/_search -d' { "query" : { "term" : { "content" : "中國" }}, "highlight" : { "pre_tags" : ["<b>", "<i>"], "post_tags" : ["</b>", "</i>"], "fields" : { "content" : {} } } }'