从8.0版本开始,需要为 Logstash 配置身份验证凭据才能建立通信。关于认证这块,搜了很多文章,都是配置X-pack,但是配置X-pack就不会配置conf文件,所以拥抱新版本,配置CA
可以优先阅读 Beats:Elastic Beats 介绍 及和 Logstash 的比较 以及后续的入门教程
目前来说,ELK的架构是最基础的,但是无论是开发、测试以及发布到生产,很少有直接使用的,架构图表达的很清楚。测试环境基本是 B => L => E => K,生产环境考虑容错,B => (中间件) => L => E => K,可参考 Beats => Redis => Logstash => Elasticsearch 或 Kafka => Logstash => Elasticsearch,在官网最下面,可以看到Beats的推荐位
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
cd ~
vi elasticsearch-start.sh
i
内容
sudo -u esuser '/usr/local/src/elasticsearch-8.5.0/bin/elasticsearch' -d
Esc
:wq
chmod -R 777 elasticsearch-start.sh
运行
./elasticsearch-start.sh
cd ~
vi kibana-start.sh
i
内容
sudo -u esuser '/usr/local/src/kibana-8.5.0/bin/kibana' &
Esc
:wq
chmod -R 777 kibana-start.sh
运行
./kibana-start.sh
cd ~
vi logstash-start.sh
i
内容
sudo -u esuser '/usr/local/src/logstash-8.5.0/bin/logstash' -f /usr/local/src/logstash-8.5.0/logstash.conf &
Esc
:wq
chmod -R 777 logstash-start.sh
cd /usr/local/src/logstash-8.5.0/
vi logstash.conf
i
内容
input {
file {
path => "/platform/first/first-info*.log"
type => "first_info"
}
file {
path => "/platform/first/first-error*.log"
type => "first_error"
}
}
output {
stdout {}
elasticsearch {
hosts => ["https://192.168.109.160:9200"]
index => "platform_%{+YYYY-MM-dd}"
user => "elastic"
password => "nnTB9IxTtjyndWjKNC+q"
ssl => true
cacert => "/usr/local/src/elasticsearch-8.5.0/config/certs/http_ca.crt"
}
}
关于隐藏账号和密码,请参考 Logstash 入门教程 (二)
Esc
:wq
chmod -R 777 logstash.conf
cd /
mkdir platform
cd platform
mkdir first
cd ..
chmod -R 777 platform/
cd ~
./logstash-start.sh
我自己准备的架构设计是以平台为单位,平台下分各种各样的服务,一个平台建一个视图数据,下面的服务数据查看通过type来筛选
格式 2022-10-01 00:00:00 [main] INFO 自定义内容
cd /platform/first/
su esuser
touch first-info.1.log
echo "2022-10-01 00:00:00 [main] INFO AAAAA" >> first-info.1.log
echo "2022-10-01 00:00:00 [main] INFO HHHHH" >> first-info.1.log
echo "2022-10-01 00:00:00 [main] INFO KKKKK" >> first-info.1.log
echo "2022-10-01 00:00:00 [main] INFO CCCCC" >> first-info.1.log
echo "2022-10-01 00:00:00 [main] INFO FFFFF" >> first-info.1.log
格式 2022-10-01 23:59:59 [timeoutChecker_2_1] ERROR 自定义内容
touch first-error.1.log
echo "2022-10-01 23:59:59 [timeoutChecker_2_1] ERROR BBBBB" >> first-error.1.log
echo "2022-10-01 23:59:59 [timeoutChecker_2_1] ERROR LLLLL" >> first-error.1.log
echo "2022-10-01 23:59:59 [timeoutChecker_2_1] ERROR OOOOO" >> first-error.1.log
echo "2022-10-01 23:59:59 [timeoutChecker_2_1] ERROR IIIII" >> first-error.1.log
echo "2022-10-01 23:59:59 [timeoutChecker_2_1] ERROR ZZZZZ" >> first-error.1.log
cat first-info.1.log
cat first-error.1.log
如果只想看某个服务的info或者error,点击type进行筛选
cd /usr/local/src/logstash-8.5.0/
vi logstash.conf
i
input内容,增加了second服务
input {
file {
path => "/platform/first/first-info*.log"
type => "first_info"
}
file {
path => "/platform/first/first-error*.log"
type => "first_error"
}
file {
path => "/platform/second/second-info*.log"
type => "second_info"
}
file {
path => "/platform/second/second-error*.log"
type => "second_error"
}
}
Esc
:wq
之后logstash的控制台会打印新的配置信息
su esuser
cd /platform/
mkdir second
cd second
touch second-info.1.log
echo "2022-10-02 00:00:00 [main] INFO AAAAA2" >> second-info.1.log
echo "2022-10-02 00:00:00 [main] INFO HHHHH2" >> second-info.1.log
echo "2022-10-02 00:00:00 [main] INFO KKKKK2" >> second-info.1.log
echo "2022-10-02 00:00:00 [main] INFO CCCCC2" >> second-info.1.log
echo "2022-10-02 00:00:00 [main] INFO FFFFF2" >> second-info.1.log
touch second-error.1.log
echo "2022-10-02 23:59:59 [timeoutChecker_2_1] ERROR BBBBB2" >> second-error.1.log
echo "2022-10-02 23:59:59 [timeoutChecker_2_1] ERROR LLLLL2" >> second-error.1.log
echo "2022-10-02 23:59:59 [timeoutChecker_2_1] ERROR OOOOO2" >> second-error.1.log
echo "2022-10-02 23:59:59 [timeoutChecker_2_1] ERROR IIIII2" >> second-error.1.log
echo "2022-10-02 23:59:59 [timeoutChecker_2_1] ERROR ZZZZZ2" >> second-error.1.log
cat second-info.1.log
cat second-error.1.log
亦可以看到type已经变成了4个
亦可以使用KQL(Kibana Query Language)进行查询,更详细的语法看文档