使用CentOS8 + ElasticSearch + Kibana + Logstash + Elastiflow来构建NetFlow收集器环境
概述
环境和版本
CentOS 8
弹性搜索 7.5.2
基本 7.5.2
日志聚合 7.5.2
弹性流 3.4.0
已安装组
以下是已安装的组:
# yum grouplist
CentOS-8 - AppStream 6.8 kB/s | 4.3 kB 00:00
CentOS-8 - Base 5.4 kB/s | 3.8 kB 00:00
CentOS-8 - Extras 4.3 kB/s | 1.5 kB 00:00
利用可能な環境グループ:
サーバー (GUI 使用)
最小限のインストール
ワークステーション
仮想化ホスト
カスタムオペレーティングシステム
インストール済みの環境グループ:
サーバー
インストール済みのグループ:
コンテナー管理
ヘッドレス管理
利用可能なグループ:
.NET Core 開発
RPM 開発ツール
開発ツール
グラフィカル管理ツール
レガシーな UNIX 互換性
ネットワークサーバー
科学的サポート
セキュリティーツール
スマートカードサポート
システムツール
执行yum update
执行yum update和yum clean all。
# yum update
メタデータの期限切れの最終確認: 0:44:37 時間前の 2020年02月04日 13時35分33秒 に実施しました。
依存関係が解決しました。
(中略)
完了しました!
# yum clean all
22 ファイルが削除されました
操作系统版本
yum更新后的操作系统版本如下。
# cat /etc/redhat-release
CentOS Linux release 8.1.1911 (Core)
SELinux (Security-Enhanced Linux) – 安全增强型Linux
将SELinux设置为permissive模式。
※为了使设置永久生效,需要重新启动。
# vi /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
#SELINUX=enforcing # ← コメントアウト
SELINUX=permissive # ← 追記
# SELINUXTYPE= can take one of these three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
# shutdown -r now
(再起動)
# getenforce
Permissive
添加防火墙策略
使用firewall-cmd命令开放所需的端口。
ElasticSearchの為の設定
# firewall-cmd --add-port=9200/tcp --zone=public
# firewall-cmd --add-port=9200/tcp --zone=public --permanent
Kibanaの為の設定
# firewall-cmd --add-port=5601/tcp --zone=public
# firewall-cmd --add-port=5601/tcp --zone=public --permanent
Logstashの為の設定
# firewall-cmd --add-port=2055/tcp --zone=public
# firewall-cmd --add-port=2055/tcp --zone=public --permanent
安装OpenJDK
安装OpenJDK。
# yum install java-1.8.0-openjdk-devel
インストール:
java-1.8.0-openjdk-devel x86_64 1:1.8.0.232.b09-2.el8_1 AppStream 9.8 M
依存関係のインストール:
(中略)
java-1.8.0-openjdk x86_64 1:1.8.0.232.b09-2.el8_1 AppStream 317 k
java-1.8.0-openjdk-headless x86_64 1:1.8.0.232.b09-2.el8_1 AppStream 33 M
(以降略)
これでよろしいですか? [y/N]: y
(中略)
完了しました!
导入GPG密钥
根据本机手册,安装GPG KEY。
# rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
创建各种存储库文件
根据本地手册,创建ElasticSearch、Kibana和Logstash的存储库文件,并进行安装。
[elasticsearch]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=1
type=rpm-md
[kibana-7.x]
name=Kibana repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
[logstash-7.x]
name=Elastic repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
yum install --enablerepo=elasticsearch elasticsearch
yum install --enablerepo=kibana kibana
yum install --enablerepo=logstash logstash
修改各种设置
只有在更改了集群配置之后,ElasticSearch才能启动,因此需要修改/etc/elasticsearch/elasticsearch.yml文件如下。
# --------------------------------- Discovery ----------------------------------
(中略)
#discovery.seed_hosts: ["host1", "host2"]
discovery.type: single-node # ← 追記
我将从Kibana的设置中更改监听IP地址。另外,我还会更改设置,以便默认情况下支持日语化。
#server.host: "localhost"
server.host: "0.0.0.0" # ← 追記
#i18n.locale: "en"
i18n.locale: "ja-JP" # ← 追記
服务注册,自动启动和启动设置
我将注册、自动启动和配置ElasticSearch、Kibana和Logstash的服务。
# systemctl daemon-reload
# systemctl enable elasticsearch.service
# systemctl start elasticsearch.service
# systemctl status elasticsearch.service
# systemctl daemon-reload
# systemctl enable kibana.service
# systemctl start kibana.service
# systemctl status kibana.service
# systemctl daemon-reload
# systemctl enable logstash.service
# systemctl start logstash.service
# systemctl status logstash.service
执行systemctl status服务名称,确认其正常启动。
安装ElastiFlow
参考此网站安装ElastiFlow。
# /usr/share/logstash/bin/logstash-plugin install logstash-codec-sflow
# /usr/share/logstash/bin/logstash-plugin update
# yum install git
# git clone https://github.com/robcowart/elastiflow.git
# cp -r ./elastiflow/logstash/elastiflow/ /etc/logstash/
# cd /etc/logstash/elastiflow/conf.d
禁用未使用的功能。
# mv 10_input_ipfix_ipv4.logstash.conf 10_input_ipfix_ipv4.logstash.conf.disabled
# mv 10_input_sflow_ipv4.logstash.conf 10_input_sflow_ipv4.logstash.conf.disabled
# mv 20_filter_30_ipfix.logstash.conf 20_filter_30_ipfix.logstash.conf.disabled
# mv 20_filter_40_sflow.logstash.conf 20_filter_40_sflow.logstash.conf.disabled
复制参数设置文件。
# cp -r ./elastiflow/sysctl.d/* /etc/sysctl.d/
# cp -r ./elastiflow/logstash.service.d/ /etc/systemd/system/
注册输出流设备。
#"192.0.2.1": "cisco_nbar2" # ← コメントアウト
#"192.0.2.2": "fortinet" # ← コメントアウト
"192.168.1.1": "gateway1" # ← 追記
我将在Logstash中编写Elastiflow的配置。
- pipeline.id: main
# path.config: "/etc/logstash/conf.d/*.conf" # ← コメントアウト
path.config: "/etc/logstash/elastiflow/conf.d/*.conf" # ← 追記
重新启动Logstash。
# systemctl daemon-reload
# systemctl restart logstash
检查Logstash日志,确认是否显示了以下表明启动的日志。
[2020-02-04T16:37:17,295][INFO ][logstash.runner ] Starting Logstash {"logstash.version"=>"7.5.2"}