0. 事前准备工作
0.1 防火墙
- 若是使用公网IP的话可以考虑关闭防火墙,或者放行相应端口
- 使用内网IP的话可以不用管防火墙
0.2 关闭SElinux
# setenforce 0
文件:/etc/selinux/config
SELINUX=disabled
0.3 内核优化
文件:/etc/security/limits.conf,在最后加入如下内容:
* soft nofile 65537
* hard nofile 65537
* soft nproc 65537
* hard nproc 65537
文件:/etc/security/limits.d/20-nproc.conf,修改如下内容:
* soft nproc 4096
文件:/etc/sysctl.conf,修改好后使用sysctl -p
生效
vm.max_map_count = 262144
net.core.somaxconn = 65535
net.ipv4.ip_forward = 1
0.4 软件准备
软件存放路径:/usr/local/src
- elasticsearch-7.3.0-x86_64.rpm
- filebeat-7.3.0-x86_64.rpm
- kibana-7.3.0-x86_64.rpm
- logstash-7.3.0.rpm
- openjdk-12_linux-x64_bin.tar.gz
0.5 规划
主机1:192.168.10.170,安装有nginx,filebeat,kibana
主机2:192.168.10.102,安装有logstash,elasticsearch,kibana,java
后期考虑:
- 使用多台主机搭建elasticsearch集群
- 使用elasticsearch-head监控elasticsearchz状态,设置密码
- 访问kibana使用nginx代理进行访问,kibana配置文件监听本机ip,kibana设置访问密码
- filenbeat与logstash进行ssl安全通信
- Heartbeat检测
- elasticsearch-certutil安全,设置密码
0.6 日志路径流程
nginx程序产生日志,filebeat配置文件中获取该日志,并把日志输出给logstash,logstash把日志输出给elasticsearch,使用kibana构建索引展示出来。
1. 配置java环境
# cd /usr/local/src
# tar -zxv -f openjdk-12_linux-x64_bin.tar.gz -C /usr/local/
# vim /etc/profile
export JAVA_HOME=/usr/local/jdk-12
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
# source /etc/profile
# ln -s /usr/local/jdk-12/bin/java /usr/bin/java
# java -version
openjdk version "12" 2019-03-19
OpenJDK Runtime Environment (build 12+33)
OpenJDK 64-Bit Server VM (build 12+33, mixed mode, sharing)
2. Elasticsearch
2.1 安装
# rpm -Uvh elasticsearch-7.3.0-x86_64.rpm
# systemctl daemon-reload
# systemctl enable elasticsearch.service
# systemctl start elasticsearch.service
2.2 测试
# 测试
# curl -X GET http://localhost:9200
3. Kibana
3.1 安装
# rpm -Uvh kibana-7.3.0-x86_64.rpm
# systemctl daemon-reload
# systemctl enable kibana.service
# systemctl start kibana.service
3.2 配置文件修改
# 默认配置文件路径
# /etc/kibana/kibana.yml
server.host: "192.168.10.102" # 能够访问kibana的ip,此处设置公网IP直接本机访问
elasticsearch.hosts: ["http://localhost:9200"] # 关联的elasticsearch,多个的话中间用逗号隔开
i18n.locale: "zh-CN" # web界面使用中文
3.3 测试
# 测试
打开浏览器,输入地址:http://192.168.10.102:5601 进行访问
4. Logstash
4.1 安装
# rpm -Uvh logstash-7.3.0.rpm
# systemctl daemon-reload
# systemctl enable logstash.service
# systemctl start logstash.service
4.2. 配置filebeat日志输出到logstash
注意:这一步不能直接修改logstash-sample.conf使用,需要在conf.d目录下创建conf文件使用,具体可以查看logstash日志文件
# /etc/logstash/logstash-sample.conf /etc/logstash/conf.d/nginx.conf
# vim /etc/logstash/conf.d/nginx.conf
input {
beats {
port => 5044
}
}
output {
elasticsearch {
hosts => ["http://localhost:9200"]
index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"
#user => "elastic"
#password => "changeme"
}
}
5. filebeat
5.1 安装
# rpm -Uvh filebeat-7.3.0-x86_64.rpm
# systemctl daemon-reload
# systemctl enable filebeat.service
# systemctl start filebeat.service
5.2 配置文件
# vim /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /usr/local/openresty/nginx/logs/*.log
#output.elasticsearch:
# hosts: ["localhost:9200"]
output.logstash:
hosts: ["192.168.10.102:5044"]
6. nginx
忽略
7. 补充
7.1 通过nginx访问kibana
# /etc/kibana/kibana.yml
server.port: 5601
server.host: "127.0.0.1"
server.basePath: "/kibana"
# nginx.conf
location /kibana/ {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:5601;
rewrite ^/kibana/(.*)$ /$1 break;
}
重启nginx和kibana,然后就能使用http://ip/kibana进行访问了
延伸:
可以给nginx访问配置密码,进一步加强安全