vim /etc/security/limits.conf
#末尾插入
# allow user 'elasticsearch' mlockall
elasticsearch soft memlock unlimited
elasticsearch hard memlock unlimited
* soft nofile 65535
* hard nofile 65535
重启生效
systemctl restart elasticsearch.service
部署Logstash 1.安装Logstashrpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
vim /etc/yum.repos.d/ogstash.repo #配置yum源
[logstash-2.1]
name=Logstash repository for 2.1.x packages
baseurl=http://packages.elastic.co/logstash/2.1/centos
gpgcheck=1
gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch
enable=1
yum install logstash -y
2.创建链接,识别logstash命令ln -s /opt/logstash/bin/logstash /usr/bin/
3.配置Logstash收集Logstash使用input和output定义收集日志时的输入和输出。
input常用的输入源有:
file、syslog、redis、log4j、apache log或nginx log,或者其他一些自定义的log格式。
output常用的输出有:
elasticsearch比较常用,fle:写入文件,redis: 写入队列,hdfs: 写入HDFS,需插件支持,zabbix: zabbix监控,mongodb: 写入mongodb库,除此之外编码插件codes也比较常用,经常用来处理json数据或者多行数据源。
(1)定义输入和输出流,类似管道
logstash -e 'input { stdin{} } output { stdout{} }'
(2)详细格式显示
logstash -e 'input { stdin{} } output { stdout{ codec => rubydebug } }'
(3)写入到elasticsearch中
logstash -e 'input { stdin{} } output { elasticsearch { hosts => ["192.168.26.144:9200"] } }'
(4)写入ES和同时生成文本
logstash -e 'input { stdin{} } output { elasticsearch { hosts => ["192.168.26.144:9200"] } stdout { codec => rubydebug } }'
(5)编写配置文件将事件生成到ES
vim /etc/logstash/conf.d/01-logstash.conf
input { stdin { } }
output {
elasticsearch { hosts => ["localhost:9200"] }
stdout { codec => rubydebug }
}logstash -f /etc/logstash/conf.d/01-logstash.conf #配置文件生效
5.使用logstash收集日志(系统日志、java异常日志、事件优化处理)
编写配置文件将日志生成到ES中
vim /root/file.conf
input {
file {
path => "/var/log/messages" #系统日志
type => "system"
start_position => "beginning"
}
file {
path => "/var/log/elasticsearch/yun.log" #java异常日志
type => "es-error"
start_position => "beginning"
codec => multiline { #多行优化处理
pattern => "^\["
negate => true
what => "previous"
}
}
}
output {