ES搭建
# ES搭建
提示
ELK 基于 Elasticsearch、Logstash、Kibana,为避免版本不一致引起冲突,规定版本为7.9.3。
# 下载
cd usr/local
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.3-linux-x86_64.tar.gz
# 解压
tar -zxvf elasticsearch-7.9.3-linux-x86_64.tar.gz
# 可以先执行安装包重命名,方便后续操作
mv elasticsearch-7.9.3-linux-x86_64 elasticsearch
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 新增用户属组
# 出于安全考虑,默认不能用root账号启动,需要添加用户,并且添加用户的组,否则无法启动
useradd elk
groupadd elk
cd /usr/local
# 更改用户和组的权限
chown -R elks:elk elasticsearch
1
2
3
4
5
6
7
2
3
4
5
6
7
# 配置调整
vim /usr/local/elasticsearch/config/elasticsearch.yml
#设置ip地址,任意网络均可访问
network.host: 0.0.0.0
# 取消注释,并保留一个节点
node.name: node-1
cluster.initial_master_nodes: ["node-1"]
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: "*"
path.data: /usr/local/elasticsearch/data
path.logs: /usr/local/elasticsearch/logs
vim /usr/local/elasticsearch/config/jvm.options
#根据自己机器情况修改
-Xms4g
-Xmx4g
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
启动时会报错 "max virtual memory areas vm.maxmapcount [65530] is too low"
# 到宿主机上打开文件
vim /etc/sysctl.conf
# 增加这样一条配置,一个进程在VMAs(虚拟内存区域)创建内存映射最大数量
vm.max_map_count=655360
# 让配置生效
sysctl -p
1
2
3
4
5
6
2
3
4
5
6
# 启动
su - elk
# 进入bin目录
cd /usr/local/elasticsearch/bin
# 后台启动
./elasticsearch -d
# 启动成功后,访问下面的URL: http://ip:9200
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# 自启动配置
# 切回到root用户
su root
vim /etc/systemd/system/elasticsearch.service #该文件不存在,会打开一个空白页面新建
# 服务添加
[Unit]
Description=elasticsearch
[Service]
Type=forking
# 指定用户
User=elk
LimitNOFILE=65536
LimitNPROC=65536
ExecStart=/usr/local/elasticsearch/bin/elasticsearch -d
[Install]
WantedBy=multi-user.target
systemctl daemon-reload # 重新加载
systemctl start elasticsearch.service # 启动服务
systemctl enable elasticsearch.service # 加入开机自启
systemctl status elasticsearch.service # 查看服务状态
systemctl restart elasticsearch.service # 重启服务
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
上次更新: 2025/03/09, 15:45:50