手把手教你,在CentOS上安装ELK,进行服务器日志收集( 三 )


/usr/share/logstash/bin/logstash-f /etc/logstash/conf.d/logstash.conf --config.test_and_exit**如果报错:WARNING: Could not find logstash.yml which is typically located in $LS_HOME/config or /etc/logstash. You can specify the path using –path.settings. **
解决办法:
cd /usr/share/logstashln -s /etc/logstash ./config3.2.8、logstash指定配置进行运行指定logstash.conf配置文件,以后台的方式运用,执行这段命令之后,需要回车一下
nohup /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/logstash.conf &检查logstash是否启动
ps -ef|grep logstash显示如下信息,说明启动了
 

手把手教你,在CentOS上安装ELK,进行服务器日志收集

文章插图
 
3.3、kibana安装3.3.1、安装kibanarpm -ivh kibana-6.1.0-x86_64.rpm搜索rpm包
rpm -ql kibana默认是装在/usr/share/kibana/下 。
3.3.2、修改kibana.yml修改kibana的配置文件
vim /etc/kibana/kibana.yml内容如下:
#kibana页面映射在5601端口server.port: 5601#允许所有ip访问5601端口server.host: "0.0.0.0"#elasticsearch所在的ip及监听的地址elasticsearch.url: "http://localhost:9200"3.3.3、启动kibana启动
systemctl start kibana查看状态
systemctl status kibana设置开机启动
systemctl enable kibana3.4、配置nginx 访问3.4.1、安装nginx和http用户认证工具yum -y install epel-releaseyum -y install nginx httpd-tools3.4.2、修改nginx配置cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bakvim /etc/nginx/nginx.conf将location配置部分,注释掉
手把手教你,在CentOS上安装ELK,进行服务器日志收集

文章插图
 
创建kibana.conf文件
vim /etc/nginx/conf.d/kibana.conf内容如下:
server {listen 8000; #修改端口为8000server_name kibana;#auth_basic "Restricted Access";#auth_basic_user_file /etc/nginx/kibana-user;location / {proxy_pass http://127.0.0.1:5601; #代理转发到kibanaproxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection 'upgrade';proxy_set_header Host $host;proxy_cache_bypass $http_upgrade;}}重新加载配置文件
systemctl reload nginx到这一步,elk基本配置完了,输入如下命令,启动服务
# 启动ELK和nginxsystemctl restart elasticsearch logstash kibana nginx#查看ELK和nginx启动状态systemctl status elasticsearch logstash kibana nginx在浏览器输入ip:8000, 就可以访问了kibana
04、linux节点服务器安装配置filebeat4.1、安装filebeatyum localinstall -y filebeat-6.2.4-x86_64.rpm4.2、启动kibana启动
systemctl start filebeat查看状态
systemctl status filebeat设置开机启动
systemctl enable filebeat4.3、修改配置Filebeat编辑filebeat.yml文件
vim /etc/filebeat/filebeat.yml#============= Filebeat prospectors ===============filebeat.prospectors:- input_type: logenabled: true #更改为true以启用此prospectors配置 。paths:#支持配置多个文件收集目录#- /var/log/*.log- /var/log/messages#==================== Outputs =====================#------------- Elasticsearch output ---------------#output.elasticsearch:# Array of hosts to connect to.#hosts: ["localhost:9200"]#---------------- Logstash output -----------------output.logstash:# The Logstash hostshosts: ["localhost:5044"]注意:注释掉Elasticsearch output下面的部分,将Filebeat收集到的日志输出到 Logstash output
最后重启服务
systemctl restart filebeat4.4、登录kibana,创建索引,并且搜集数据 
手把手教你,在CentOS上安装ELK,进行服务器日志收集

文章插图
 
 
手把手教你,在CentOS上安装ELK,进行服务器日志收集

文章插图
 
 
手把手教你,在CentOS上安装ELK,进行服务器日志收集

文章插图
 
 
ELK+ Filebeat的安装,到此,就基本结束了,以上只是简单的部署完了 。
但是,还满足不了需求,比如,一台服务器,有多个日志文件路径,改怎么配置,接下来,我们来分类创建索引!
05、Filebeat收集多个Tomcat目录下的日志5.1、修改filebeat.yml配置文件vim /etc/filebeat/filebeat.yml配置多个paths收集路径,并且使用fields标签配置自定义标签log_topics,以方便做索引判断,如下:
filebeat.prospectors:- type: logenabled: truepaths:- /usr/tomcat7-ysynet/logs/default/common_monitor.logmultiline.pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2},[0-9]{3}'multiline.negate: truemultiline.match: afterfields:log_topics: spd-ysynet- type: logenabled: truepaths:- /usr/tomcat7-ysynet-sync/logs/default/common_monitor.logmultiline.pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2},[0-9]{3}'multiline.negate: truemultiline.match: afterfields:log_topics: spd-ysynet-sync- type: logenabled: truepaths:- /usr/tomcat7-hscm/logs/default/common_monitor.logmultiline.pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2},[0-9]{3}'multiline.negate: truemultiline.match: afterfields:log_topics: spd-hscm- type: logenabled: truepaths:- /usr/tomcat7-hscm-sync/logs/default/common_monitor.logmultiline.pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2},[0-9]{3}'multiline.negate: truemultiline.match: afterfields:log_topics: spd-hscm-sync


推荐阅读