- 确认 redhat 版本号:
bash
> cat /etc/redhat-release:
> Red Hat Enterprise Linux release 9.2 (Plow)
- 新建 elasticsearch 目录:
bash
> cd /data/software && mkdir elasticsearch && cd elasticsearch
- 下载 elasticsearch-7.17.3-linux-x86_64.tar.gz:
bash
> wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.17.3-linux-x86_64.tar.gz
下载失败也可以去其他地方下载( 比如迅雷 ),然后上传到该目录。
- 解压 elasticsearch-7.17.3-linux-x86_64.tar.gz:
bash
> tar -xzf elasticsearch-7.17.3-linux-x86_64.tar.gz
bash
> cd elasticsearch-7.17.3 && mkdir data && mkdir tmpdir
- cd config && vim elasticsearch.yml,添加如下内容:
bash
cluster.initial_master_nodes: ["es-node-1"] // 不加启动 es 会报错 the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
path.data: /data/software/elasticsearch/elasticsearch-7.17.3/data
path.logs: /data/software/elasticsearch/elasticsearch-7.17.3/logs
network.host: 0.0.0.0 // 不加只能使用 http://127.0.0.1:9200 访问,不能用 具体 ip 访问
ingest.geoip.downloader.enabled: false // 不加可能如果网络不好,java 调用 es api 会超时,然后 es 日志会发现类似 "error downloading geoip database [GeoLite2-Country.mmdb]" 的错误
- 修改 es 的默认 /tmp 目录:
有时候启动 es 会报类似 "Exception in thread "main" java.nio.file.AccessDeniedException: /tmp/elasticsearch-8523317643108022907..." 的错误,因为 No space left 或者 no permission 等,可以手动修改 es 默认使用的 /tmp 目录:
bash
1. vim /data/software/elasticsearch/elasticsearch-7.17.3/bin/elasticsearch,在 "if [ -z "$ES_TMPDIR" ]; then" 上一行新增 ES_TMPDIR="/data/software/elasticsearch/elasticsearch-7.17.3/tmpdir"
2. vim /data/software/elasticsearch/elasticsearch-7.17.3/bin/elasticsearch-env,在 "if [ ! -z "$ES_JAVA_HOME" ]; then" 上一行新增 ES_JAVA_HOME="/data/software/elasticsearch/elasticsearch-7.17.3/jdk"
- 启动 es:
bash
1. cd /data/software/elasticsearch/elasticsearch-7.17.3/bin && ./elasticsearch // 前台启动
2. cd /data/software/elasticsearch/elasticsearch-7.17.3/bin && ./elasticsearch -d // 后台启动
-
安装 ik分词器:
-
下载 elasticsearch-analysis-ik-7.17.3.zip( 下载地址:https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.17.3/elasticsearch-analysis-ik-7.17.3.zip )
-
cd /data/software/elasticsearch/elasticsearch-7.17.3/plugins && mkdir analysis-ik
-
将下载好的 elasticsearch-analysis-ik-7.17.3.zip 上传到 analysis-ik 目录
-
unzip elasticsearch-analysis-ik-7.17.3.zip
-
重启 elasticSearch
-
elasticSearch 常见 API:
-
http://127.0.0.1:9200/_cat/nodes?v # 查看所有节点
-
http://127.0.0.1:9200/_cat/health?v # 查看 elasticSearch 健康状况
-
http://127.0.0.1:9200/_cat/indices?v # 查看所有索引信息
-
http://127.0.0.1:9200/index_article # 查看索引 index_article 的信息
-
http://127.0.0.1:9200/index_article DELETE # 删除索引 index_article
-
http://127.0.0.1:9200/index_article/_mapping DELETE # 删除索引 index_article
-
http://127.0.0.1:9200/index_article/_search # 查询索引 index_article 中的全部数据
-
http://127.0.0.1:9200/_analyze # 测试分词器分词效果
POST
{
"text":"I prefer having your accompanying for life-long time to the short-time tenderness",
"analyzer":"standard"
}
-
设置用户名、密码:
-
修改 /data/software/elasticsearch/elasticsearch-7.17.3/config/elasticsearch.yml,添加 "xpack.security.enabled: true"
-
cd /data/software/elasticsearch/elasticsearch-7.17.3/bin 执行 ./elasticsearch-certutil cert -out config/elastic-certificates.p12 -pass "",发现证书 elastic-certificates.p12 生成到了 /data/software/elasticsearch/elasticsearch-7.17.3/config 中
-
修改 /data/software/elasticsearch/elasticsearch-7.17.3/config/elasticsearch.yml,添加以下4行:
bash
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
-
重启 es,浏览器请求 http://127.0.0.1:9200/ 提示让输入用户名和密码了
-
设置密码:
cd /data/software/elasticsearch/elasticsearch-7.17.3/bin 执行 ./elasticsearch-setup-passwords interactive,选择 y,根据提示为分别为用户 elastic、apm_system、kibana_system、logstash_system、beats_system、remote_monitoring_user 设置密码