部署准备

  1. wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.3.2-linux-x86_64.tar.gz
  2. wget https://artifacts.elastic.co/downloads/logstash/logstash-7.3.2.tar.gz
  3. wget https://artifacts.elastic.co/downloads/kibana/kibana-7.3.2-linux-x86_64.tar.gz
  4. wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.3.2-linux-x86_64.tar.gz
  5. # mkdir /home/elk
  6. # ll /home/elk
  7. -rw-r--r--. 1 root root 285050383 十一 23 2019 elasticsearch-7.3.2-linux-x86_64.tar.gz
  8. -rw-r--r--. 1 root root 25274202 十一 23 2019 filebeat-7.3.2-linux-x86_64.tar.gz
  9. -rw-r--r--. 1 root root 236654252 十一 23 2019 kibana-7.3.2-linux-x86_64.tar.gz
  10. -rw-r--r--. 1 root root 171783584 十一 23 2019 logstash-7.3.2.tar.gz

elastic

  1. # tar -zxvf elasticsearch-7.3.2-linux-x86_64.tar.gz
  2. 修改配置文件
  3. [root@dev-app-60 elasticsearch-7.3.2]# vim config/elasticsearch.yml
  4. ——————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  5. #ES监听地址任意IP都可访问,也可以是自己服务器的IP
  6. network.host: 0.0.0.0
  7. http.port: 9200
  8. ——————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  9. 优化类配置
  10. vi /etc/sysctl.conf
  11. fs.file-max=65536
  12. vm.max_map_count=262144
  13. # sysctl -p
  14. vi /etc/security/limits.conf
  15. * soft nofile 65536
  16. * hard nofile 65536
  17. * soft nproc 65536
  18. * hard nproc 65536
  19. #############################################添加用户和组#############################################################
  20. 添加组
  21. groupadd elkgroup
  22. elkgroup下添加elkuser用户,并设密码
  23. useradd elkuser -g elkgroup -p elkuser
  24. 文件目录权限修改
  25. [root@dev-app-60 elk]# chown elkuser. /home/elk -R
  26. # ll
  27. total 0
  28. drwxr-xr-x. 10 elkuser elkgroup 183 三月 10 18:05 elasticsearch-7.3.2
  29. drwxr-xr-x. 5 elkuser elkgroup 212 三月 11 09:21 filebeat-7.3.2-linux-x86_64
  30. drwxr-xr-x. 14 elkuser elkgroup 271 三月 11 09:21 kibana-7.3.2-linux-x86_64
  31. drwxr-xr-x. 12 elkuser elkgroup 255 三月 10 18:08 logstash-7.3.2
  32. 定位到elasticsearch安装目录下为elkuser用户设置访问权限
  33. # chown -R elkuser /home/elk/elasticsearch-7.3.2
  34. 启动
  35. # su elkuser
  36. $ cd /home/elk/elasticsearch-7.3.2
  37. nohup ./bin/elasticsearch &
  38. 检测是否启动
  39. # netstat -tanp|grep 9200
  40. tcp6 0 0 :::9200 :::* LISTEN 9090/java
  41. $ curl 127.0.0.1:9200
  42. {
  43. "name" : "dev-app-60",
  44. "cluster_name" : "elasticsearch",
  45. "cluster_uuid" : "_na_",
  46. "version" : {
  47. "number" : "7.3.2",
  48. "build_flavor" : "default",
  49. "build_type" : "tar",
  50. "build_hash" : "1c1faf1",
  51. "build_date" : "2019-09-06T14:40:30.409026Z",
  52. "build_snapshot" : false,
  53. "lucene_version" : "8.1.0",
  54. "minimum_wire_compatibility_version" : "6.8.0",
  55. "minimum_index_compatibility_version" : "6.0.0-beta1"
  56. },
  57. "tagline" : "You Know, for Search"
  58. }
  59. elastic添加密码
  60. [elkuser@dev-app-60 elasticsearch-7.3.2]$ vim config/elasticsearch.yml
  61. http.cors.enabled: true
  62. http.cors.allow-origin: "*"
  63. http.cors.allow-headers: Authorization
  64. xpack.security.enabled: true
  65. xpack.security.transport.ssl.enabled: true
  66. xpack.security.authc.accept_default_password: true
  67. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  68. 指定密码比较复杂的时候,可以随机 密码
  69. [elkuser@dev-app-60 elasticsearch-7.3.2]$ ./bin/elasticsearch-setup-passwords auto
  70. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  71. 执行设置用户名和密码的命令,这里需要为4个用户分别设置密码,elastic,apm_system, kibana, logstash_system,betas_system,remote_monitoring_user
  72. [elkuser@dev-app-60 elasticsearch-7.3.2]$ ./bin/elasticsearch-setup-passwords interactive
  73. ./bin/elasticsearch-setup-passwords interactive
  74. future versions of Elasticsearch will require Java 11; your Java version from [/home/jdk/jre] does not meet this requirement
  75. Failed to determine the health of the cluster running at http://10.2.204.60:9200
  76. Unexpected response code [503] from calling GET http://10.2.204.60:9200/_cluster/health?pretty
  77. Cause: master_not_discovered_exception
  78. It is recommended that you resolve the issues with your cluster before running elasticsearch-setup-passwords.
  79. It is very likely that the password changes will fail when run against an unhealthy cluster.
  80. Do you want to continue with the password setup process [y/N]y
  81. Initiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user.
  82. You will be prompted to enter passwords as the process progresses.
  83. Please confirm that you would like to continue [y/N]y
  84. Enter password for [elastic]:
  85. Reenter password for [elastic]:
  86. Enter password for [apm_system]:
  87. Reenter password for [apm_system]:
  88. Enter password for [kibana]:
  89. Reenter password for [kibana]:
  90. Enter password for [logstash_system]:
  91. Reenter password for [logstash_system]:
  92. Enter password for [beats_system]:
  93. Reenter password for [beats_system]:
  94. Enter password for [remote_monitoring_user]:
  95. Reenter password for [remote_monitoring_user]:
  96. Changed password for user [apm_system]
  97. Changed password for user [kibana]
  98. Changed password for user [logstash_system]
  99. Changed password for user [beats_system]
  100. Changed password for user [remote_monitoring_user]
  101. Changed password for user [elastic]

logstash

  1. #测试
  2. curl -H "Content-Type:application/json" -XPOST -u elastic 'http://127.0.0.1:9200/_xpack/security/user/elastic/_password' -d '{ "password" : "123456" }'
  3. # cd /home/elk
  4. # tar -zxvf logstash-7.3.2.tar.gz
  5. # cd logstash-7.3.2/
  6. 配置文件
  7. vim pipelines.yml
  8. path.config: "/home/elk/logstash-7.3.2/config/conf.d/*.conf"
  9. [root@dev-app-60 config]# mkdir conf.d
  10. [root@dev-app-60 config]# cd conf.d/
  11. #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
  12. 配置文件
  13. [elkuser@dev-app-60 logstash-7.3.2]$ cat config/conf.d/app.conf
  14. input {
  15. beats {
  16. port => 5044
  17. }
  18. }
  19. filter {
  20. if "dev-app-allocation" in [tags] {
  21. grok {
  22. match => { "message" => "\[%{TIMESTAMP_ISO8601:log_timestamp}\]%{GREEDYDATA:log_info}" }
  23. remove_field => ["log_info","agent","ecs.version","log.flags","log.offset"]
  24. }
  25. mutate {
  26. gsub => [ "log_info", "\\n", "\n\r" ]
  27. }
  28. date {
  29. match => [ "log_timestamp" , "yyyy-MM-dd HH:mm:ss,SSS" ]
  30. }
  31. }
  32. output {
  33. if "dev-app" in [tags] {
  34. elasticsearch {
  35. hosts => ["http://10.2.204.60:9200"]
  36. index => "dev-app%{+YYYY.MM.dd}"
  37. user => "elastic"
  38. password => "elastic密码"
  39. }
  40. }
  41. #stdout { codec => rubydebug }
  42. }
  43. }
  44. #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
  45. 启动
  46. [elkuser@dev-app-60 logstash-7.3.2]$ nohup ./bin/logstash &

logstash限制内存

  1. [elkuser@dev-app-60 config]$ cat /home/elk/logstash-7.3.2/config/jvm.options

排错记录

  1. [elkuser@dev-app-60 elasticsearch-7.3.2]$ ./bin/elasticsearch-setup-passwords interactive
  2. ERROR: Failed to set password for user [apm_system].
  3. 注释:
  4. discovery.seed_hosts
  5. cluster.initial_master_nodes
  6. 添加
  7. discovery.type: single-node
  8. 重启elastic
  9. [elkuser@dev-app-60 logstash-7.3.2]$ ./bin/logstash -e'input {stdin {}} output {stdout {}}'
  10. Thread.exclusive is deprecated, use Thread::Mutex
  11. Sending Logstash logs to /home/elk/logstash-7.3.2/logs which is now configured via log4j2.properties
  12. [2021-03-11T11:57:21,225][WARN ][logstash.config.source.multilocal] Ignoring the 'pipelines.yml' file because modules or command line options are specified
  13. [2021-03-11T11:57:21,240][INFO ][logstash.runner ] Starting Logstash {"logstash.version"=>"7.3.2"}
  14. [2021-03-11T11:57:21,267][INFO ][logstash.agent ] No persistent UUID file found. Generating new UUID {:uuid=>"6426ad87-6c81-4c91-823e-1b44e06139a8", :path=>"/home/elk/logstash-7.3.2/data/uuid"}
  15. [2021-03-11T11:57:22,581][INFO ][org.reflections.Reflections] Reflections took 110 ms to scan 1 urls, producing 19 keys and 39 values
  16. [2021-03-11T11:57:23,968][WARN ][org.logstash.instrument.metrics.gauge.LazyDelegatingGauge] A gauge metric of an unknown type (org.jruby.RubyArray) has been create for key: cluster_uuids. This may result in invalid serialization. It is recommended to log an issue to the responsible developer/development team.
  17. [2021-03-11T11:57:23,972][INFO ][logstash.javapipeline ] Starting pipeline {:pipeline_id=>"main", "pipeline.workers"=>8, "pipeline.batch.size"=>125, "pipeline.batch.delay"=>50, "pipeline.max_inflight"=>1000, :thread=>"#<Thread:0x287ba869 run>"}
  18. [2021-03-11T11:57:24,028][INFO ][logstash.javapipeline ] Pipeline started {"pipeline.id"=>"main"}
  19. The stdin plugin is now waiting for input:
  20. [2021-03-11T11:57:24,161][INFO ][logstash.agent ] Pipelines running {:count=>1, :running_pipelines=>[:main], :non_running_pipelines=>[]}
  21. [2021-03-11T11:57:24,401][INFO ][logstash.agent ] Successfully started Logstash API endpoint {:port=>9600}########出现此处则输入要输出的内容
  22. xlxtest
  23. /home/elk/logstash-7.3.2/vendor/bundle/jruby/2.5.0/gems/awesome_print-1.7.0/lib/awesome_print/formatters/base_formatter.rb:31: warning: constant ::Fixnum is deprecated
  24. {
  25. "@timestamp" => 2021-03-11T03:57:45.394Z,
  26. "host" => "dev-app-60",
  27. "message" => "xlxtest",
  28. "@version" => "1"
  29. }
  30. {
  31. "@timestamp" => 2021-03-11T03:57:48.869Z,
  32. "host" => "dev-app-60",
  33. "message" => "",
  34. "@version" => "1"
  35. }
  36. 根据配置文件调试

filebeat

  1. # tar -zxvf filebeat-7.3.2-linux-x86_64.tar.gz
  2. [root@dev-app-60 elk]# cd logstash-7.3.2/config/
  3. [root@dev-app-60 config]# su elkuser
  4. [elkuser@dev-app-60 filebeat-7.3.2-linux-x86_64]$ cp filebeat.yml filebeat.yml_bak.0311
  5. [elkuser@dev-app-60 filebeat-7.3.2-linux-x86_64]$ vim filebeat.yml
  6. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7. [elkuser@dev-app-60 filebeat-7.3.2-linux-x86_64]$ cat filebeat.yml
  8. filebeat.inputs:
  9. - type: log
  10. enabled: true
  11. paths:
  12. - /home/output/logs/allocation/*.log
  13. tags: ["dev-app"]
  14. multiline.pattern: '^\[\d{4}-\d{1,2}-\d{1,2}\s\d{1,2}:\d{1,2}:\d{1,2}'
  15. multiline.negate: true
  16. multiline.match: after
  17. #============================= Filebeat modules ===============================
  18. filebeat.config.modules:
  19. # Glob pattern for configuration loading
  20. path: ${path.config}/modules.d/*.yml
  21. # Set to true to enable config reloading
  22. reload.enabled: false
  23. # Period on which files under path should be checked for changes
  24. #reload.period: 10s
  25. #==================== Elasticsearch template setting ==========================
  26. setup.template.settings:
  27. index.number_of_shards: 1
  28. #index.codec: best_compression
  29. #_source.enabled: false
  30. #================================ Outputs =====================================
  31. #----------------------------- Logstash output --------------------------------
  32. output.logstash:
  33. # The Logstash hosts
  34. hosts: ["10.2.204.60:5044"] # 需要在 logstash 配置文件中配置
  35. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  36. 启动
  37. # su elkuser
  38. [elkuser@dev-app-60 filebeat-7.3.2-linux-x86_64]$ nohup /home/elk/filebeat-7.3.2-linux-x86_64/filebeat &

kibana

  1. # cd /home/elk/kibana-7.3.2-linux-x86_64/config
  2. [elkuser@dev-app-60 config]$ cat kibana.yml|grep -v "#"|grep -v ^$
  3. server.host: "0.0.0.0"
  4. elasticsearch.username: "elastic"
  5. elasticsearch.password: "elastic密码"
  6. 启动
  7. [elkuser@dev-app-60 elk]$ nohup /home/elk/kibana-7.3.2-linux-x86_64/bin/kibana &

kibana查询通配符

  1. 通配符
  2. ? 匹配单个字符
  3. * 匹配0到多个字符
  4. 示例:kiba?a, el*search
  5. ? * 不能用作第一个字符,例如:?text *text

kibana-转义特殊字符

  1. 转义特殊字符
  2. + - = && || > < ! ( ) { } [ ] ^ " ~ * ? : \ /
  3. 以上字符当作值搜索的时候需要用\转义
  4. 1\+ 用来查询1+

kibana—web界面

  1. http://10.2.204.60:5601/login?next=%2F#?_g=()
  2. elastic/elastic密码