由于logstash 太过臃肿,CPU和内存使用过大,我们需要一个性能好,资源消耗低的替代品。fluentd就是我们想要的。测试表明,在相同负载情况下,fluentd的性能数倍于logstash。
由于CentOS7 自带ruby版本过低,本文使用ruby 2.4.1 安装fluentd .
1、卸载自带的ruby
1
|
yum remove ruby -y |
2、安装ruby2.4.1
1
|
yum install http: //120 .24.7.75:8000 /centos/7/x86_64/ruby2 .4-2.4.1-1.el7.centos.x86_64.rpm
|
3、调整gem源
1
2
3
|
gem sources #列出默认源
gem sources --remove https: //rubygems .org/ #移除默认源
gem sources -a https: //mirrors .ustc.edu.cn /rubygems/ #添加科大源
|
4、安装编译环境和软件包依赖
1
|
yum install gcc gcc-c++ make automake autoconf libtool openssl-devel jemalloc-devel gmp-devel -y
|
5、安装fluentd
1
|
gem install fluentd
|
6、安装fluent插件
1
2
|
gem install fluent-plugin-kafka
gem install fluent-plugin-elasticsearch
|
7、初始化fluentd
1
|
fluentd --setup /etc/fluentd
|
前台debug 测试,用于检查配置文件
1
|
fluentd -c /etc/fluentd/fluentd/fluent .conf -vv
|
8、创建启动脚本/usr/lib/systemd/system/fluentd.service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
[Unit] Description=Fluentd Documentation=http://www.fluentd.org/ After=network.target [Service] Type=simple ExecStart=/usr/bin/fluentd -c /etc/fluentd/fluent.conf Restart=on-failure User=fluentd Group=fluentd [Install] WantedBy=multi-user.target |
9、启动fluentd
1
2
3
|
systemctl daemon-reload
systemctl enable fluentd
systemctl start fluentd
|
fluentd 是cruby写的,受限于GIL,无法利用多核CPU,已知每个CPU可处理5000个并发,
如果性能不能满足需求,可以进程多开。
本文转自 紫色葡萄 51CTO博客,原文链接:http://blog.51cto.com/purplegrape/1956249,如需转载请自行联系原作者