ES集群安装与使用
2、准备
Elasticsearch:http://www.elasticsearch.org/download
elasticsearch-head:http://mobz.github.io/elasticsearch-head/
Linux环境:两台
2、ES安装
1. 解压elasticsearch-1.4.2.tar.gz, tar -zvxfelasticsearch-1.4.2.tar.gz,在当前路径生成目录:elasticsearch-1.4.2;
2. 配置es。修改ES_HOME/config/elasticsearch.yml文件,将node.name的值设置为“test-node1”,表示当前这个es服务节点名字为test-node1。
3.启动ES。进入ES安装目录,执行命令:bin/elasticsearch-d -Xms512m -Xmx512m,然后在浏览器输入http://ip:9200/,查看页面信息,是否正常启动。status=200表示正常启动了,还有一些es的版本信息,name为配置文件中node.name的值。
4、elasticsearchservicewrapper安装
这个是对elasticsearch执行命令的包装服务,安装之后,方便elasticsearch的启动,停止等等操作。
(1)下载elasticsearchservicewrapper
https://github.com/elasticsearch/elasticsearch-servicewrapper,然后将目录下的service目录拷贝至ES_HOME/bin目录下。
(2)简单配置jvm的内存
修改ES_HOME/bin/service/elasticsearch.conf,set.default.ES_HEAP_SIZE=1024,该值根据机器的配置可自定义。
(3)安装启动服务
执行命令:ES_HOME/bin/service/elasticsearch install
(4)启动/停止/重启服务
执行命令:ES_HOME/bin/service/elasticsearch start/stop/restart
4启动es
Cd/usr/local/elasticsearch-0.18.7/bin/service
./elasticsearch start ------后台运行
5 停止es
/elasticsearch stop
附:插件的主要命令
./elasticsearchconsole ------前台运行
./elasticsearch start ------后台运行
./elasticsearchinstall -------添加到系统自动启动
./elasticsearchremove -----取消随系统自动启动
4. 在另外一台机器上,安装同样的步骤安装ES,将node.name的值设置为test-node2,必须和之前配置值不同。两台es服务同时起来,因为配置文件中均默认cluster.name=elasticsearch,所以这两台机器自动构建成一个集群,集群名字为elasticsearch。
4、head插件安装
插件安装方法1:
1.elasticsearch/bin/plugin -installmobz/elasticsearch-head
2.运行es
3.打开http://localhost:9200/_plugin/head/
插件安装方法2:
1.https://github.com/mobz/elasticsearch-head下载zip 解压
2.建立elasticsearch-1.4.2\plugins\head\_site文件
3.将解压后的elasticsearch-head-master文件夹下的文件copy到_site
4.运行es
5.打开http://localhost:9200/_plugin/head/
(2)bigdesk
bigdesk是集群监控插件,通过该插件可以查看整个集群的资源消耗情况,cpu、内存、http链接等等。
执行命令安装:sudo elasticsearch/bin/plugin -install lukas-vlcek/bigdesk
安装完成之后,在浏览器输入:http://ip:9200/_plugin/bigdesk/#nodes ,显示界面
点击test-node1节点,可以查看单个节点的资源使用情况,包括JVM、Thread Pools、OS、Process、HTTP&Transport、Indice、File system。
curl: -X 后面跟 RESTful : GET, POST ...
-d 后面跟数据。 (d = data tosend)
1. create:
指定 ID 来建立新记录。(貌似PUT, POST都可以)
$ curl -XPOST localhost:9200/films/md/2 -d'
{ "name":"hei yi ren","tag": "good"}'
使用自动生成的 ID 建立新纪录:
$ curl -XPOST localhost:9200/films/md -d '
{ "name":"ma da jia sijia3", "tag": "good"}'
2. 查询:
2.1 查询所有的 index, type:
$ curl localhost:9200/_search?pretty=true
2.2 查询某个index下所有的type:
$ curl localhost:9200/films/_search
2.3 查询某个index 下, 某个 type下所有的记录:
$ curllocalhost:9200/films/md/_search?pretty=true
2.4 带有参数的查询:
$ curllocalhost:9200/films/md/_search?q=tag:good
{"took":7,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":2,"max_score":1.0,"hits":[{"_index":"film","_type":"md","_id":"2","_score":1.0,"_source" :
{ "name":"hei yi ren","tag":"good"}},{"_index":"film","_type":"md","_id":"1","_score":0.30685282,"_source" :
{ "name":"ma da jia sijia", "tag": "good"}}]}}
2.5 使用JSON参数的查询: (注意 query 和 term 关键字)
$ curl localhost:9200/film/_search -d '
{"query" : { "term": {"tag":"bad"}}}'
3. update
$ curl -XPUT localhost:9200/films/md/1 -d {...(data)... }
4. 删除。 删除所有的:
$ curl -XDELETE localhost:9200/films