1.下载安装包
输入官网下载网址,选择Linux版本,可直接下载最新版本的elastic,也可通过右侧的View past releases选择其他版本,本案例是以elasticsearch-6.8.5版本为例。
https://www.elastic.co/cn/downloads/elasticsearch
下载非最新版本时步骤。
2.解压tar包
cd /data/app/elk/elk-6.8.5 //此目录结构为自定义,若不存在此结构可自行创建
tar zxvf elasticsearch-6.8.5.tar.gz
3.创建data和logs目录
//若目录已存在可以不执行此命令
mkdir /data/app/elk/elk-6.8.5/elasticsearch-6.8.5/data
mkdir /data/app/elk/elk-6.8.5/elasticsearch-6.8.5/logs
4.配置config目录下的elasticsearch.yml
network.host一定要改成虚拟机的IP地址,此处127.0.0.1为示例数据!!!
cd /data/app/elk/elk-6.8.5/elasticsearch-6.8.5/config
vim elasticsearch.yml
可以选择vim编辑,也可使用FTP访问文件进行编辑(建议)
cluster.name: dsports-es #集群名称
node.name: dsports-node-1 #本节点名称
path.data: /data/app/elk/elk-6.8.5/elasticsearch-6.8.5/data #数据存储目录
path.logs: /data/app/elk/elk-6.8.5/elasticsearch-6.8.5/logs #日志存储目录
network.host: 127.0.0.1 #监听127.0.0.1(本机IP)
discovery.type: single-node #单例模式
http.port: 9200 #默认端口
action.auto_create_index: true #自动创建索引
http.cors.enabled: true #配置开启跨域
http.cors.allow-origin: "*" #配置允许任何域名访问
http.cors.allow-headers: Authorization
xpack.security.enabled: true #是否开启安全验证
#xpack.security.transport.ssl.enabled: true #是否开启远程访问安全验证
5.启动命令
cd /data/app/elk/elk-6.8.5/elasticsearch-6.8.5
./bin/elasticsearch -d
-d 表示后台运行elasticsearch进程
6.查看elasticsearch是否启动成功
ps -ef | grep elastic
7.重置密码
7.1. 自动生成密码
./bin/elasticsearch-setup-passwords auto
7.2.以交互的方式设置用户名和密码:(记住你所设置的密码)
./bin/elasticsearch-setup-passwords interactive
8.验证密码
8.1. 密码验证:验证 elastic 账户
//此处的127.0.0.1必须更改成你的虚拟机IP地址
curl -u elastic 'http://127.0.0.1:9200/_xpack/security/_authenticate?pretty'
8.2. 重置 elastic 账户密码(无需执行)
//此处的127.0.0.1必须更改成你的虚拟机IP地址
curl -u elastic -XPUT 'http://127.0.0.1:9200/_xpack/security/user/elastic/_password?pretty' -H 'Content-Type: application/json' -d '{"password" : "elastic2021"}'
9.浏览器访问
//此处的127.0.0.1必须更改成你的虚拟机IP地址
http://127.0.0.1:9200/ 输入账号/密码:elastic/elastic2021
10.问题集锦
问题1:
bootstrap check failure [1] of [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解决方案:
1.修改sysctl.conf
vim /etc/sysctl.conf
2.添加参数
vm.max_map_count=262144
sysctl -p