elasticsearch安装

前提条件:安装JDK1.7+


get https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.4.1.tar.gz
tar zxvf elasticsearch-1.4.1.tar.gz -C /usr/local

elasticsearch使用默認配置即可,默認的cluster name為:elasticsearch。
啟動

启动ElasticSearch很简单,执行安装目录下bin/elasticsearch即可;ElasticSearch 1.0.0的启动机制有一些变化,默认在前台运行,-d参数表示在后台运行;另外还提供-p参数,后接文件名,保存当前ElasticSearch进程的pid,方便关闭进程;

# 背景啟動
/usr/local/elasticsearch-1.4.1/bin/elasticsearch -d
# 測試是否已動
curl -X GET http://localhost:9200
# 檢視叢集狀態
curl -X GET http://localhost:9200/_cluster/health?pretty

curl -XGET http://localhost:9200/_cluster/nodes/
# 叢集停止
curl -XPOST http://localhost:9200/_cluster/nodes/_shutdown
# 單一節點停止
curl -XPOST http://localhost:9200/_cluster/nodes/<node id>/_shutdown

如果是要提供外部服務記得要關掉防火牆

CentOS7
# Check the Status of Firewalld

systemctl status firewalld
# Stop Firewalld

systemctl stop firewalld
# Disable Firewalld

systemctl disable firewalld

vi /etc/selinux/config
# change

SELINUX=disabled

reboot

練習用

# 新增
curl -XPOST http://localhost:9200/megacorp/employee/1 -d '{
  "first_name": "John",
  "last_name": "Smith",
  "age": 25,
  "about": "I love to go rock climbing",
  "interests": [
    "sports",
    "music"
  ]
}'

# 讀取
curl -XGET http://localhost:9200/megacorp/employee/1 

# 修改
curl -XPUT http://localhost:9200/megacorp/employee/1 -d '{
  "first_name": "John",
  "last_name": "Smith",
  "age": 25,
  "about": "I love to go rock climbing",
  "interests": [
    "sports",
    "music"
  ]
}'

# 刪除
curl -XDELETE http://localhost:9200/megacorp/employee/1

curl -XGET 'http://localhost:9200/megacorp/employee/_search' -d '{
    "query" : {
        "term" : { "user" : "kimchy" }
    }
}'

# 搜尋
curl -XGET 'http://localhost:9200/megacorp/employee/_search' -d '{
    "query" : {
        "match" : {
            "last_name" : "Smith"
        }
    }
}'

# 全文搜尋
curl -XGET 'http://localhost:9200/megacorp/employee/_search' -d '{
    "query" : {
        "match" : {
            "about" : "rock climbing"
        }
    }
}'




安装Marvel

Marvel是Elasticsearch的管理和监控工具,在开发环境下免费使用。它包含了一个叫做Sense的交互式控制台,使用户方便的通过浏览器直接与Elasticsearch进行交互。

Elasticsearch线上文档中的很多示例代码都附带一个View in Sense的链接。点击进去,就会在Sense控制台打开相应的实例。安装Marvel不是必须的,但是它可以通过在你本地Elasticsearch集群中运行示例代码而增加与此书的互动性。

Marvel是一个插件,可在Elasticsearch目录中运行以下命令来下载和安装:

./bin/plugin -i elasticsearch/marvel/latest

你可能想要禁用监控,你可以通过以下命令关闭Marvel:

echo 'marvel.agent.enabled: false' >> ./config/elasticsearch.yml

如果你安装了Marvel(作为管理和监控的工具),就可以在浏览器里通过以下地址访问它:

http://localhost:9200/_plugin/marvel/


posted @ 2015-04-04 18:18  JamesFan  阅读(172)  评论(0编辑  收藏  举报