[TOC] ## 一、下载 下载地址:[https://www.elastic.co/cn/downloads/elasticsearch](https://www.elastic.co/cn/downloads/elasticsearch) ![](https://img.kancloud.cn/85/ca/85caf98d387d1c630fa2ba6f587b0c61_2648x1020.png) 获取历史版本: ![](https://img.kancloud.cn/db/7f/db7fb5745f30b468c0181d1c4d95dcbb_2940x1122.png) ## 二、安装 ### 2. 配置xpack ![](https://img.kancloud.cn/60/e1/60e1ec516a2ef06112fb7b34142cb641_1104x148.png) #### 2.1. 生成证书 ``` bin/elasticsearch-certutil cert -out config/elastic-certificates.p12 -pass "" ``` #### 2.2. 修改配置 ``` vim config/elasticsearch.yml ``` 修改config目录下elasticsearch.yml文件,在最后新增以下参数 ``` xpack.security.enabled: true xpack.security.transport.ssl.enabled: true xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.keystore.path: elastic-certificates.p12 xpack.security.transport.ssl.truststore.path: elastic-certificates.p12 ``` 配置elasticsearch.yml ``` cluster.name: my-es network.host: 0.0.0.0 node.name: node-1 cluster.initial_master_nodes: ["node-1"] http.cors.enabled: true http.cors.allow-origin: "*" bootstrap.memory_lock: false bootstrap.system_call_filter: false xpack.security.enabled: true xpack.security.transport.ssl.enabled: true xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.keystore.path: elastic-certificates.p12 xpack.security.transport.ssl.truststore.path: elastic-certificates.p12 ``` ## 三、启动 ``` bin/elasticsearch ``` > 后台运行:bin/elasticsearch -d ## 四、初始化密码 两种方式二选一 ### 4.1. 自动生成密码 ``` bin/elasticsearch-setup-passwords auto ``` ### 4.2. 手动设置密码 ``` bin/elasticsearch-setup-passwords interactive ``` > 【重要】记录密码,很多地方需要验证密码。如:logstash,kibana。 ``` Changed password for user apm_system PASSWORD apm\_system = vKqf8FtzpUqPDrYfbsjt Changed password for user kibana_system PASSWORD kibana_system = 45CnPubkY740mul0BGst Changed password for user kibana PASSWORD kibana = 45CnPubkY740mul0BGst Changed password for user logstash_system PASSWORD logstash_system = KIUsb7e2cJePAWH5KW1t Changed password for user beats_system PASSWORD beats_system = zAnlSRyBEWJ1oOyUjxSK Changed password for user remote_monitoring_user PASSWORD remote_monitoring_user = K1YDZxvqURqIVylvUq0J Changed password for user elastic PASSWORD elastic = 7kgH0ARRpwLbhrdCTvrO ``` ## 五、IK分词器 查询数据,都是使用的默认的分词器,分词效果不太理想,会把text的字段分成一个一个汉字,然后搜索的时候也会把搜索的句子进行分词,所以这里就需要更加智能的分词器IK分词器了 ### 5.1. 下载 下载地址:[https://github.com/medcl/elasticsearch-analysis-ik/releases](https://github.com/medcl/elasticsearch-analysis-ik/releases) > 这里你需要根据你的**Es的版本来下载对应版本的IK** ### 5.2. 将解压文件复制到 es的安装目录/plugin/ik下面即可 ![](https://img.kancloud.cn/ee/92/ee923b0d3d3bc6c3c3d3ed7345045a07_2182x182.png) ### 5.3. 重启es并检查插件是否安装成功 [http://localhost:9200/\_cat/plugins](http://localhost:9200/_cat/plugins) ![](https://img.kancloud.cn/55/f1/55f1c184776929f0756c3851d7fd0c09_1582x188.png) ## 六、访问 1. 验证密码 [http://localhost:9200](http://localhost:9200) 打开浏览器,输入我们的elasticsearch的网址,比如本地的[http://localhost:9200/](http://localhost:9200/) ,然后会弹出一个输入框,让我们输入账号和密码 ![](https://img.kancloud.cn/51/da/51da4625a24c08eaf2508653fe3c2515_666x472.png) ![](https://img.kancloud.cn/b7/18/b718b96455c75ce810a63cdb946dbfd6_1048x540.png) 2. 查看索引 [http://localhost:9200/\_cat/indices?v](http://localhost:9200/_cat/indices?v) ![](https://img.kancloud.cn/00/a4/00a454bb2417089b1be63de060378f1e_2534x1956.png) 3. 查看插件 [http://localhost:9200/\_cat/plugins](http://localhost:9200/_cat/plugins) ![](https://img.kancloud.cn/55/f1/55f1c184776929f0756c3851d7fd0c09_1582x188.png) 4. 查看状态 [http://localhost:9200/\_cluster/health?pretty=true](http://localhost:9200/_cluster/health?pretty=true) ![](https://img.kancloud.cn/96/5a/965ab9e717ff208d6bac2eb4f49cc90c_814x550.png)