ELK教程1 - elasticsearch

目录

服务器规划

约定

下载并安装:

服务操作

配置远程访问:

访问:

创建索引:


服务器规划

IP服务
172.30.18.10elasticsearch、logstash、kibana
172.30.18.12filebeat(作为客户端收集日志,发送给172.30.18.10)
172.30.18.13filebeat(作为客户端收集日志,发送给172.30.18.10)

约定

查看用户列表:
# cat /etc/passwd
 
查看用户组列表:
# cat /etc/group
 
# 创建 filebeat用户和组
groupadd elasticsearch
useradd elasticsearch-m -s /sbin/nologin -d /home/elasticsearch -g elasticsearch
 
 
# useradd 参数
-s /sbin/nologin 设置不能登陆
-d 设置用户主目录,如果此目录不存在,则同时使用-m选项,可以创建主目录。 
-g 用户组 
-m 创建用户目录

下载并安装:

​#切换目录
cd  /home/elasticsearch
 
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.12.1-x86_64.rpm
 
yum -y localinstall elasticsearch-7.12.1-x86_64.rpm
 
rpm -qc elasticsearch
 
whereis elasticsearch

es安装路径是/usr/share/elasticsearch,日志路径是/var/log/elasticsearch

查看日志:tail -f /var/log/elasticsearch/elasticsearch.log

服务操作

# 设置服务开机启动
systemctl enable elasticsearch.service
 
# 启动服务
systemctl start elasticsearch.service
 
#查询服务状态
systemctl status elasticsearch.service
 
#重启服务
systemctl restart elasticsearch.service
 
查看服务日志
journalctl -u elasticsearch.service
 
查看服务端口
netstat -nltp | grep 9200

配置远程访问:

vi /etc/elasticsearch/elasticsearch.yml

# 绑定本机IP地址
network.host: 0.0.0.0
# 绑定HTTP端口
http.port: 9200
# 指定集群master节点
discovery.seed_hosts: ["0.0.0.0","127.0.0.1", "[::1]"]

重启:systemctl restart elasticsearch.service

访问:

curl http://localhost:9200

创建索引:

查询ES状态

curl -X GET localhost:9200/_cluster/health

创建索引

curl -X PUT "localhost:9200/machine_cap_1003?pretty"​​​​​​​

查询索引列表

curl -X GET localhost:9200/_cat/indices

删除索引

curl -X DELETE "localhost:9200/machine_cap_1003"

定期删除数据

# vim delete_es_by_day.sh
# chmod +x delete_es_by_day.sh

---------------------------------------------
#!/bin/bash
#定时删除elasticsearch索引
date=`date -d "-7 days" "+%Y.%m.%d"`
/usr/bin/curl -v --user elasticsearch:password -XDELETE "http://localhost:9200/*-$date"


---------------------------------------------
#!/bin/bash
# 两个月之前
date=`date -d "-2 months" "+%Y.%m"`
/usr/bin/curl -v --user elastic:elastic用户密码 -XDELETE "http://es机器IP:9200/*-$date"


---------------------------------------------
#定时任务
crontab -e
00 01 * * * /home/elasticsearch/script/delete_es_by_day.sh

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值