打赏

星辰大海ゞ

That which does not kill us makes us stronger!

导航

Logstash配置以服务方式运行

Logstash官网最新版下载地址以及YUM源:https://www.elastic.co/cn/downloads/logstash

 

Logstash最常见的运行方式即命令行运行 ./bin/logstash -f logstash.conf 然后通过ctrl+c结束,这种方式的优点在于运行方便,但是缺点也很明显,不便于管理,同时如果遇到服务器重启,则维护成本会更高一些,如果在生产环境运行logstash建议还是使用服务的方式运行

1、修改config目录下的 startup.optins

JAVA_HOME=/usr/local/java/jdk1.8.0_171
LS_HOME=/usr/local/logstash-6.2.4
LS_OPTS="--path.settings ${LS_SETTINGS_DIR} --path.config /usr/local/logstash-6.2.4/logstash.d"
#我们把logstash的配置文件*.conf都放在/usr/local/logstash-6.2.4/logstash.d目录下面
LS_USER=root
LS_GROUP=root

2、创建服务

以root身份执行logstash命令创建服务

# /usr/local/logstash-6.2.4/bin/system-install

执行完后,会生成一个环境变量文件 /etc/default/logstash

另一个生成的则是主要的服务文件 /etc/systemd/system/logstash.service :

[Unit]
Description=logstash

[Service]
Type=simple
User=root
Group=root
# Load env vars from /etc/default/ and /etc/sysconfig/ if they exist.
# Prefixing the path with '-' makes it try to load, but if the file doesn't
# exist, it continues onward.
EnvironmentFile=-/etc/default/logstash
EnvironmentFile=-/etc/sysconfig/logstash
ExecStart=/usr/local/logstash-6.2.4/bin/logstash "--path.settings" "/usr/local/logstash-6.2.4/config" "--path.config" "/usr/local/logstash-6.2.4/logstash.d"
Restart=always
WorkingDirectory=/
Nice=19
LimitNOFILE=16384

[Install]
WantedBy=multi-user.target

# systemctl start logstash

# systemctl enable logstash

3、日志查看

默认情况下日志会保存在以下两个位置

  • /var/log/messages
  • /usr/local/logstash/logs

 


 

/logstash/config/logstash.yml:主要用于控制logstash运行时的状态
/logstash/config/startup.options:logstash 运行相关参数

配置参数说明:

logstash.yml
参数    用途    默认值
node.name  节点名称    主机名称
path.data  /数据存储路径    LOGSTASH_HOME/data/
pipeline.workers  输出通道的工作workers数据量(提升输出效率)    cpu核数
pipeline.output.workers  每个输出插件的工作wokers数量    1
pipeline.batch.size  每次input数量    125
path.config  过滤配置文件目录    
config.reload.automatic   自动重新加载被修改配置    false or true
config.reload.interval  配置文件检查时间    
path.logs   日志输出路径    
http.host   绑定主机地址,用户指标收集    “127.0.0.1”
http.port   绑定端口    5000-9700
log.level   日志输出级别,如果config.debug开启,这里一定要是debug日志    info
log.format  日志格式    * plain*
path.plugins  自定义插件目录

startup.options参数:

JAVACMD=/usr/bin/java   本地jdk
LS_HOME=/opt/logstash   logstash所在目录
LS_SETTINGS_DIR="${LS_HOME}/config"           默认logstash配置文件目录
LS_OPTS="–path.settings ${LS_SETTINGS_DIR}"  logstash启动命令参数 指定配置文件目录
LS_JAVA_OPTS=""  指定jdk目录
LS_PIDFILE=/var/run/logstash.pid logstash.pid所在目录
LS_USER=logstash    logstash启动用户
LS_GROUP=logstash logstash启动组
LS_GC_LOG_FILE=/var/log/logstash/gc.log logstash jvm gc日志路径
LS_OPEN_FILES=65534 logstash最多打开监控文件数量


示例logstash配置文件:

input {
    file {
      path => "/usr/local/nginx/logs/ad-access.log"
      type => "nginx--ad"
      start_position => "beginning"
    }
    beats {
      port => "5044"
    }
}

filter {
    grok {
      match => { "message" => "%{MYNGINX}" }
    }
    mutate {
      convert => [ "elapsed", "float" ]
      convert => [ "serverelapsed", "float" ]
    }
}

output {
    if [type] == "nginx--ad" {
      elasticsearch {
      hosts=> ["172.17.213.61:9200"]
      index=> "nginx-ad.%{+YYYY-MM}"
      }
    }
    else {
      elasticsearch {
        hosts => ["172.17.213.60:9200", "172.17.213.61:9200"]
        index => "adsdk.%{+YYYY-MM-DD}"
        manage_template => false
        template_overwrite => true
        template_name => "adsdk-template"
        template => "/usr/local/logstash-6.2.4/adsdk.template"
        document_type => "adsdk"
      }
    }
}

 

posted on 2019-09-18 18:26  星辰大海ゞ  阅读(3731)  评论(0编辑  收藏  举报