大多数Linux发行版默认的日志守护进程为rsyslog
开发语言的warning(警告级别)可以不用查
系统及服务的warning(警告级别)必须查
ELK
E:搜索引擎,存放数据
L:安装于服务器中,将各个服务器中的日志存于E中
K:用于显示
用处
收集文件,收集正则方式,收集json
全文索引
实时分析
处理PB级结构化或非结构化数据
ELK配置(本机IP:192.168.199.103)
elasticsearch-5.6.8配置(ES)
配置
jdk,jdk环境变量确保安装java1.8以上版本
解压java-jdk
1
tar zxvf jdk-8u171-linux-x64.tar.gz /data/server/
设置环境变量
1
2
3
4
5vim /etc/profile
export JAVA_HOME=/data/server/jdk1.8.0_171
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/jre/lib/rt.jar
export PATH=$PATH:$JAVA_HOME/bin使
/etc/profile生效1
source /etc/profile
解压
elasticsearch-5.6.8.tar.gz包并执行安装1
2
3mv elasticsearch-5.6.8/ /data/server
cd /data/server/elasticsearch-5.6.8/bin/
./elasticsearch错误一:不能以
root用户执行1
2useradd elas
chown -R elas.elas elasticsearch-5.6.8/错误二:文件描述符
1
2echo fs.file-max=65536 >> /etc/sysctl.conf
sysctl -p错误三:虚拟内存数
1
2echo vm.max_map_count=655360 >> /etc/sysctl.conf
sysctl -p错误四:
JVM heap size1
2vim /data/server/elasticsearch-5.6.8/config/jvm.options
更改 -Xms2g与-Xmx2g
验证安装
1
curl http://127.0.0.1:9200
logstash-5.6.10配置
解压
logstash-5.6.10.tar.gz包1
mv logstash-5.6.10/ /data/server/
修改
elasticsearch配置文件1
2
3
4
5
6vim /data/server/elasticsearch-5.6.8/config/elastic search.yml
cluster.name: my-application
node.name: node-1
network.host: 192.168.199.103
http.port: 9200验证:浏览器访问
http://192.168.199.103:9200配置远程日志服务器
1
2
3vim /etc/rsyslog.conf
*.* @192.168.199.103:5000编写
logstash配置文件.conf1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22cd /data/logger/
vim logstash.conf
input {
tcp {
port => 5000
type => syslog #可选
}
udp {
port => 5000
type => syslog
}
}
output {
elasticsearch {
hosts => ["192.168.199.103:9200"]
index => "ad" #索引,用于kibana建立实例时使用
}
stdout {
codec => rubydebug
}
}启动
ES1
2cd /data/server/elasticsearch-5.6.8/bin/
./elasticsearch启动
logstash1
2cd /data/server/logstash-5.6.10/bin/
./logstash -f /data/logger/logstash.conf验证
1
2logger -i -s "asdasd" #产生日志
logstash 中产生日志记录
kibana-5.6.8配置(版本与ES相同)
- 解包
1
2
3tar xvf kibana-5.6.8-linux-x86_64.tar.gz
mv kibana-5.6.8-linux-x86_64 /data/server/
cd /data/server/kibana-5.6.8-linux-x86_64
- 更改配置文件
1
2
3
4
5
6
7
8vim config/kibana.yml
server.port: 5601
server.host: "192.168.199.103"
elasticsearch.url: "http://192.168.199.177:9200"
kibana.index: ".kibana"
elasticsearch.username: "elastic"
elasticsearch.password: "changeme"
启动
首先启动
ES,logstash然后启动
kibana1
2cd /data/server/kibana-5.6.8-linux-x86_64/bin
./kibana验证安装
访问
http://192.168.199.103:5601
安装x-pack插件
下载
版本与
ES和kibana相同安装
安装
ES部分1
2cd /data/server/elasticsearch-5.6.8/bin
./elasticsearch-plugin install file:////usr/local/src/x-pack-5.6.10.zip安装
kibana部分1
2cd /data/server/kibana-5.6.8-linux-x86_64/bin
./kibana-plugin install file:////usr/local/src/x-pack-5.6.10.zip修改
logstash.conf添加
x-pack身份验证1
2
3
4
5
6
7
8
9
10output {
elasticsearch {
hosts => ["192.168.199.103:9200"]
user => elastic
password => changeme
}
stdout {
codec => rubydebug
}
}验证安装
访问
http://192.168.199.103:5601默认用户名:
elastic默认密码:changeme
导入日志文件
创建
logstash_file.conf1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24cd /data/logger
vim logstash_file.conf
input {
file {
path => ["/data/server/nginx/logs/acc.log"]
type => "nginx_log"
start_position => "beginning"
}
}
output {
if [type] == "nginx_log" {
elasticsearch {
hosts => ["192.168.199.103:9200"]
index => "access-%{+YYYY.MM.dd}"
user => elastic
password => changeme
}
}
stdout {
codec => rubydebug
}
}启动ES,logstash,kibana,调整时间,查看导入日志
ELRK
启动
redis1
2cd /data/server/redis/bin
./redis-server创建
logstash_redis.conf1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17cd /data/logger
vim logstash_redis.conf
input {
file {
path => "/data/server/nginx/logs/acc.log"
type => "nginx_log"
}
}
output {
redis {
host => "192.168.199.103"
port => "6379"
data_type => "list"
key => "nginx:redis"
}
}创建
logstash_redis1.conf1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23cd /data/logger
vim logstash_redis1.conf
input {
redis {
host => "192.168.199.103"
port => "6379"
data_type => "list"
type => "redis_input"
key => "nginx:redis"
}
}
output {
elasticsearch {
hosts => ["192.168.199.103:9200"]
index => "nginxlog-%{+YYYY.MM.dd}"
user => elastic
password => changeme
}
stdout {
codec => rubydebug
}
}启动
ES,两个logstash,kibana,调整时间,查看导入日志