手机版
你好,游客 登录 注册
背景:
阅读新闻

ELK日志服务器的快速搭建并收集Nginx日志

[日期:2017-03-13] 来源:Linux社区  作者:shaonian [字体:大 中 小]

二、安装nginx和logstash软件

在test1上安装好nginx服务 就是收集它的日志呢

yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel
./configure --prefix=/usr/local/nginx  --with-pcre  --with-openssl= --with-zlib=
make && make install

日志在/usr/local/nginx/logs/access.log

然后在test1上安装logstash-2.3.3-1.noarch.rpm

yum remove java-1.7.0-openjdk
rpm -ivh jdk-8u91-linux-x64.rpm
rpm -ivh logstash-2.3.3-1.noarch.rpm 
/etc/init.d/logstash start  #启动服务
/opt/logstash/bin/logstash -e "input {stdin{}} output{stdout{ codec=>"rubydebug"}}"  #检测环境  执行这个命令检测环境正常否,启动完成后 直接输入东西就会出现

之后输入 /opt/logstash/bin/logstash -e 'input {stdin{}} output{ elasticsearch { hosts => ["192.168.48.131:9200"] index => "test"}}' 

 就是输入东西到48.131的elasticsearch上 会在/path/to/data/myelk/nodes/0/indices 生成你名称test索引文件目录 可以多输入几个到48.131的目录看看有没有文件有就证明正常。

之后在/etc/logstash/conf.d 建立以.conf结尾的配置文件,我收集nginx就叫nginx.conf了内容如下;

###########################################################################################

input {

  file {

    type => "accesslog"

    path => "/usr/local/nginx/logs/access.log"  #日志的位置

    start_position => "beginning"  #日志收集文件,默认end

  }

}

 

output {

  if [type] == "accesslog" {

    elasticsearch  {

        hosts => ["192.168.0.87"]  ###elasticearch的地址

        index => "nginx-access-%{+YYYY.MM.dd}" #生成的索引和刚才的test一样会在那里生成后面的是日期变量。

                    }

      }

      }

##########################################################################################

一定要仔细,之后运行/etc/init.d/logstash configtest检测配置是否正常。

查看进程是否启动

之后在elasticearch查看有没有索引生成。多访问下nginx服务

如果没有就修改这个文件

vi /etc/init.d/logstash

######################################################################################################

LS_USER=root    ###把这里换成root或者把访问的日志加个权限可以让logstash可以读取它 重启服务就会生成索引了

LS_GROUP=root

LS_HOME=/var/lib/logstash

LS_HEAP_SIZE="1g"

LS_LOG_DIR=/var/log/logstash

LS_LOG_FILE="${LS_LOG_DIR}/$name.log"

LS_CONF_DIR=/etc/logstash/conf.d

LS_OPEN_FILES=16384

LS_NICE=19

KILL_ON_STOP_TIMEOUT=${KILL_ON_STOP_TIMEOUT-0} #default value is zero to this variable but could be updated by user request

LS_OPTS=""

#######################################################################################################

看logstash的日志有下面的信息就成功了

更多详情见请继续阅读下一页的精彩内容: http://www.linuxidc.com/Linux/2017-03/141729p3.htm

linux
相关资讯       Nginx日志  ELK日志服务器 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款