注:笔者环境 linux centos7
ElasticSearch 6.6.2 版本下载地址 https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.6.2.tar.gz
[root@nn01 ~]# tar -zxvf elasticsearch-6.6.2.tar.gz
[root@nn01 ~]# mv elasticsearch-6.6.2 /usr
es 不支持root 用户启动,添加es 用户
[root@nn01 ~]# adduser esuser
[root@nn01 ~]# passwd esuser
New password: testesuser
添加权限:
[root@nn01 ~]# chown -R esuser /usr/elasticsearch-6.6.2/
vi /etc/security/limits.conf
添加如下内容:
* soft nofile 65536
* hard nofile 65536
* soft nproc 4096
* hard nproc 4096
用户修改配置sysctl.conf
vi /etc/sysctl.conf
添加下面配置:
vm.max_map_count=262144
并执行命令,让修改生效:
sysctl -p
检验是否生效
[root@nn01 elasticsearch-6.6.2]# sysctl -a | grep "vm.max_map_count"
vm.max_map_count = 262144
vi /etc/security/limits.d/90-nproc.conf
修改*为4096或指定esuser 用户修改成更大
* soft nproc 4096
root soft nproc unlimited
修改 network.host: 为服务器所对应的ip地址
[root@nn01 config]# vi elasticsearch.yml
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: nn01
centos 下安装需要添加这一步 在elasticsearch.yml 文件末尾加上
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
切换用户启动
[root@nn01 config]# su esuser
[esuser@nn01 elasticsearch-6.6.2]$ ./bin/elasticsearch
后台启动命令后加 &
./bin/elasticsearch &
下载地址 https://artifacts.elastic.co/downloads/kibana/kibana-6.6.2-linux-x86_64.tar.gz
笔者安装的版本是与ElasticSearch一致的
解压:
[root@nn01 ~]# tar -zxvf kibana-6.6.2-linux-x86_64.tar.gz
[root@nn01 ~]# mv kibana-6.6.2-linux-x86_64 /usr
注: elasticsearch.url必须是主节点的url
[root@nn01 config]# cd /usr/kibana-6.6.2-linux-x86_64/config
[root@nn01 config]# vi kibana.yml
# To allow connections from remote users, set this parameter to a non-loopback address.
server.host: "nn01"
....
# The URLs of the Elasticsearch instances to use for all your queries.
elasticsearch.hosts: ["http://nn01:9200"]
./bin/kibana &
日志如下:
.....
log [09:05:51.846] [info][listening] Server running at http://nn01:5601
log [09:05:52.689] [info][status][plugin:[email protected]] Status changed from yellow to green - Ready
上述启动成功:查看日志有几条warning
如下:
log [09:05:36.591] [warning][plugin] Skipping non-plugin directory at /usr/kibana-6.6.2-linux-x86_64/src/legacy/core_plugins/ems_util
log [09:05:37.797] [warning][security] Generating a random key for xpack.security.encryptionKey. To prevent sessions from being invalidated on restart, please set xpack.security.encryptionKey in kibana.yml
log [09:05:37.803] [warning][security] Session cookies will be transmitted over insecure connections. This is not recommended.
log [09:05:39.437] [warning][reporting] Generating a random key for xpack.reporting.encryptionKey. To prevent pending reports from failing on restart, please set xpack.reporting.encryptionKey in kibana.yml
http://nn01:5601
点击他们提供的样本数据瞧瞧有啥好玩的不,进入后如下:
Kibana 至此安装完成
查看Kibana是否启动
netstat -tlp|grep 5601
tcp 0 0 es06.bigdata.test.cn:5601 *:* LISTEN 5310/./bin/../node/
先通过kibana 往es put些数据 当然也可以直接通过命令行 curl 命令put
命令行方式如下:
curl -H "Content-Type: application/json" -XPUT 'http://nn01:9200/myappname/myblog/1?pretty' -d '
{
"title": "我的标题",
"content": "我的内容"
}'
pretty 参数是想得出的结果是美化后的 json 数据。
这里笔者统一以kibana Dev Tools 方式添加数据,数据样例采用ElasticSearch 权威
指南样例数据如下:
PUT /megacorp/employee/1
{
"first_name" : "John",
"last_name" : "Smith",
"age" : 25,
"about" : "I love to go rock climbing",
"interests": [ "sports", "music" ]
}
PUT /megacorp/employee/2
{
"first_name" : "Jane",
"last_name" : "Smith",
"age" : 32,
"about" : "I like to collect rock albums",
"interests": [ "music" ]
}
PUT /megacorp/employee/3
{
"first_name" : "Douglas",
"last_name" : "Fir",
"age" : 35,
"about": "I like to build cabinets",
"interests": [ "forestry" ]
}
put 数据到ES 后通过Kibana 查看如下图:
这里通过Kibana可对ElasticSearch中的数据进行简单查询与聚合,也可进行匹配查询等,详细见 ElasticSearch权威指南
简单样例有如下方式:
当然上述操作也可在浏览器中直接操作
如下:
http://hdp06:8577/megacorp/employee/_search?q=first_name:Ja*
浏览器返回
{"took":6,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":1,"max_score":1.0,"hits":[{"_index":"megacorp","_type":"employee","_id":"2","_score":1.0,"_source":{
"first_name" : "Jane",
"last_name" : "Smith",
"age" : 32,
"about" : "I like to collect rock albums",
"interests": [ "music" ]
}
}]}}
先获取目前节点情况
GET /_cluster/health
添加新节点:前置步骤跟安装ES 单机版一样,安装完单机先验证是否可以正常使用,可以正常使用则按如下步骤将新节点加入集群中,ES 需要在每个节点安装。
[root@dn01 ~]# scp elasticsearch-6.6.2.tar.gz root@dn01:/root
[root@dn02 ~]# scp elasticsearch-6.6.2.tar.gz root@dn02:/root
[root@nn01 config]# vi elasticsearch.yml
cluster.name: bmsoft-es
node.name: master
[esuser@dn02 config]$ vi elasticsearch.yml
cluster.name: bmsoft-es
node.name: es-dn02
discovery.zen.ping.unicast.hosts: ["nn01"]
node 通过cluster.name 与 discovery.zen.ping.unicast.hosts 找到所需要加入的集群。
参考文档