Ubuntu安装ElasticSearch 7.14

  1. cd /etc
  2. 下载和解压elasticsearch , 最新版本可去到 https://www.elastic.co/guide/en/elasticsearch/reference/current/targz.html
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.14.0-linux-x86_64.tar.gz

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.14.0-linux-x86_64.tar.gz.sha512

shasum -a 512 -c elasticsearch-7.14.0-linux-x86_64.tar.gz.sha512 

tar -xzf elasticsearch-7.14.0-linux-x86_64.tar.gz

cd elasticsearch-7.14.0/

3. 更改Elasticsearch config

nano config/elasticsearch.yml

4. 加入这些进yml文件内

network.host: 0.0.0.0
http.port: 9001 【设定你要的port】
node.master: true
xpack.security.enabled: true
discovery.type: single-node

http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type

5. 因为无法使用root运行elasticsearch所以需要创建子账号

adduser elasticsearch
passwd elasticsearch【密码最好和username一样,容易记】
chown -R elasticsearch /etc/elasticsearch-7.14.0

6. 创建好子账号了,就切换到子账号并且运行elasticsearch

su elasticsearch

【-d 使用后台启动方式】
/etc/elasticsearch-7.14.0/bin/elasticsearch -d

7. 允许了elasticsearch之后,需要设定ES密码

/etc/elasticsearch-7.14.0/bin/elasticsearch-setup-passwords interactive

ES设定密码官方参考文档

https://www.elastic.co/guide/en/elasticsearch/reference/7.14/security-minimal-setup.html

【ElasticSearch 设定SSL】

  1. 在config/elasticsearch.yml 内加这些 ,seed_hosts可以设定你要的domain
【如果要开启SSL】
discovery.seed_hosts: ["test.pangzai.win"]
xpack.security.http.ssl.enabled: true
xpack.security.http.ssl.keystore.path: /etc/elasticsearch-7.14.0/config/cert.pfx

xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.keystore.path: /etc/elasticsearch-7.14.0/config/cert.pfx

2. 通常我们弄SSL证书都会有2个或3个文件,不知为何我一直设定就是无法正常运行,所以ssl证书转换成符合pkcs12格式,导出cert.pfx
– 3个证书 cert.crt & cert.key & ca.crt
– 2个证书的话至少cert.crt和ca.crt 合成一个证书了

openssl pkcs12 -export -out cert.pfx -inkey cert.key -in cert.crt -certfile ca.crt

3. 最后导出了cert.pfx 放在ES的目录内,否则无法正常运行

4. 停掉正在运行的elasticsearch并且重启, 就完成了

/etc/elasticsearch-7.14.0/bin/elasticsearch stop
/etc/elasticsearch-7.14.0/bin/elasticsearch -d

Loading

Facebook评论