环境准备
# TODO 安装 Java 环境即可
安装及配置
- 安装过程
$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.3.zip
$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.3.zip.sha512
shasum -a 512 -c elasticsearch-6.5.3.zip.sha512
$ unzip elasticsearch-6.5.3.zip
$ cd elasticsearch-6.5.3/
# 启动
$ ./bin/elasticsearch -d -p pid
# 停止只能杀进程
$ kill `cat pid`
- 配置
配置文件在config目录下, 同时也可以在执行时配置ES_PATH_CONF属性来进行修改,比如ES_PATH_CONF=/path/to/my/config ./bin/elasticsearch。
1. elasticsearch.yml 为 es 基础配置文件
2. jvm.options 为 jvm 相关配置
3. log4j2.properties 为日志配置文件
- 配置数据及日志文件
在elasticsearch.yml文件中存在如下两个配置项,修改即可
path:
data: /var/lib/elasticsearch
logs: /var/log/elasticsearch
- 节点配置
# 集群名称
cluster.name: wc-elk
# 当前主机信息
# node.name: ${HOSTNAME}
node.name: es-n1
# network.host: ${ES_NETWORK_HOST}
network.host: 172.xxx.xxx.35
# 端口配置
# http.port: 9200
# 集群主机配置
discovery.zen.ping.unicast.hosts: ["172.xxx.xxx.35", "172.xxx.xxx.36","172.xxx.xxx.37"]
安装插件
这里以 IK Analysis 插件为例
IK Analysis 插件是一款专门用于 Elasticsearch 的分词器,可以友好的处理中文
$ ./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.5.1/elasticsearch-analysis-ik-6.5.1.zip
查看状态
- 查看节点信息
# GET <es_ip>:<port>/_cat/nodes?v
$ curl 172.xxx.xxx.35:9200/_cat/nodes?v
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
172.xxx.xxx.35 59 9 1 0.47 0.49 0.50 mdi * es-1
172.xxx.xxx.36 64 11 0 0.41 0.37 0.39 mdi - es-2
172.xxx.xxx.37 52 8 0 0.16 0.15 0.19 mdi - es-3
- 查看 ES 健康状态
# GET <es_ip>:<port>/_cat/health?v
$ GET 172.xxx.xxx.35:9200/_cat/health?v
epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1544703447 20:17:27 wc-elk green 3 3 22 11 2 0 0 4 42.9ms 100.0%
- 查看所有 index 状态
# GET <es_ip>:<port>/_cat/indices?v
$ GET 172.xxx.xxx.35:9200/_cat/indices?v
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open .kibana 9aPp-WYKTcuSOW1i85sDRw 1 1 4 0 45.5kb 22.7kb
green open jobbole PFfMJirfSuCvmLTJqOOYEw 5 1 5375 1636 856.7mb 427.2mb
green open wc_test-2018.11.09 TGbYRDvWTaOk5bvbpRhEhw 5 1 20084 0 21.6mb 10.7mb
- 查看某个 index 相关数据
# GET <es_ip>:<port>/_cat/indices/<index名称>?v
$ curl 172.xxx.xxx.35:9200/_cat/indices/jobbole_blog?v
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open jobbole_blog G1g6HRDpQjKAsqBhJwrktg 5 1 5375 816 393.9mb 200.8mb
- 删除某个 index
# 先删除
# DELETE <es_ip>:<port>/<index 名称>?pretty
$ DELETE 172.xxx.xxx.35:9200/jobbole_blog?pretty
# 查看结果
# GET <es_ip>:<port>/_cat/indices?v
$ DELETE 172.xxx.xxx.35:9200/_cat/indices?v
- 所有记录
# POST <es_ip>:<port>/<index名称>/_search?pretty
$ curl 172.xxx.xxx.35:9200/jobbole_blog/_search?pretty
- 删除所有记录
# DELETE <es_ip>:<port>/<index名称>/<index 类型>/<记录id>?pretty
$ DELETE 172.xxx.xxx.35:9200/jobbole_blog/doc/2?pretty
- 获取内存等统计
# GET <es_ip>:<port>/<index名称>/_stats?pretty
$ GET 172.xxx.xxx.35:9200/jobbole/_stats?pretty