Centos7.0 安装ELK(5.5.1版本)

前端之家收集整理的这篇文章主要介绍了Centos7.0 安装ELK(5.5.1版本)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

安装环境:

操作系统:centos7.0

elasticsearch:5.5.1

kibana:5.5.1

logstash:5.5.1

JDK:jdk1.8.0_101

下载地址:https://www.elastic.co/downloads

JDK的安装此处就不做说明,自行百度

首先文件下载存放至/data/ELK,目录看个人习惯存放。

文件列表:

elasticsearch-5.5.1.tar.gz

kibana-5.5.1-linux-x86_64.tar.gz

logstash-5.5.1.tar.gz

安装elasticsearch

创建elasticsearch组与用户及设置密码:

[root@bigdata2 bin]# groupadd elsearchgroup //创建elasticserch组
[root@bigdata2 bin]# useradd -g elsearchgroup elsearchuser //创建elasticserch用户
[root@bigdata2 bin]# passwd elsearchuser //设置elasticserch用户的密码
Changing password for user elsearchuser.
New password:
BAD PASSWORD: The password contains the user name in some form
Retype new password:
passwd: all authentication tokens updated successfully.
[root@bigdata2 ELK]# cd /data/ELK/
[root@bigdata2 ELK]# chown -R elsearchuser:elsearchgroup elasticsearch //将文件夹拥有者赋给elsearchuser
[root@bigdata2 ELK]# su elsearchuser //切换到elsearchuser用户
[elsearchuser@bigdata2 ELK]$ chmod -R +x elasticsearch //授予该文件及遍历子文件夹可执行权限

修改配置文件

[elsearchuser@bigdata2 ELK]$vi /data/ELK/elasticsearch/conf/elasticsearch.yml

将network.host 改为本机地址或者0.0.0.0即可。

启动服务器

[elsearchuser@bigdata2 ELK]$/data/ELK/elasticsearch/bin/elasticsearch -d #-d 为后台运行

安装logstash

[root@bigdata2 ELK]# tar -zxvf logstash-5.5.1.tar.gz
[root@bigdata2 ELK]# mv logstash-5.5.1 logstash
[root@bigdata2 ELK]# cd logstash/bin
[root@bigdata2 ELK]# touchlogstash.sh
插入以下shell脚本内容

  1. #!/bin/sh
  2. # -*- coding: utf-8 -*-
  3. #
  4. #
  5. # Authors:huwj
  6. # Purpose: control ./logstash.sh start|stop|force-stop|status|restart
  7. #
  8. #
  9. # customer env
  10. name=logstash
  11. pidfile="/var/run/${name}.pid"
  12. LS_HOME=/data/ELK/logstash
  13. export PATH=/sbin:/usr/sbin:/bin:/usr/bin:${LS_HOME}/bin
  14. # must use root
  15. if [ `id -u` -ne 0 ]; then
  16. echo "You need root privileges to run this script"
  17. exit 1
  18. fi
  19. # optimizations
  20. LS_HEAP_SIZE="1024m"
  21. LS_OPEN_FILES=102400
  22. # logstash comm
  23. # LS_OPTS="--debug"
  24. LS_OPTS="--quiet"
  25. LS_LOG_DIR=${LS_HOME}/logs
  26. LS_CONF_DIR="${LS_HOME}/etc/logstash.d"
  27. [ ! -d ${LS_HOME} ] && mkdir -p ${LS_HOME}
  28. [ ! -d ${LS_LOG_DIR} ] && mkdir -p ${LS_LOG_DIR}
  29. [ ! -d ${LS_CONF_DIR} ] && mkdir -p ${LS_CONF_DIR}
  30. program=${LS_HOME}/bin/${name}
  31. args="-f ${LS_CONF_DIR} -l ${LS_LOG_DIR} ${LS_OPTS}"
  32. start() {
  33. LS_JAVA_OPTS="${LS_JAVA_OPTS} -Djava.io.tmpdir=${LS_HOME}"
  34. HOME=${LS_HOME}
  35. export PATH HOME LS_HEAP_SIZE LS_JAVA_OPTS LS_USE_GC_LOGGING
  36. ulimit -n ${LS_OPEN_FILES}
  37. # Run the program!
  38. bash -c "
  39. cd $LS_HOME
  40. ulimit -n ${LS_OPEN_FILES}
  41. exec \"$program\" $args
  42. " 2> "${LS_LOG_DIR}/${name}-error.log" &>/dev/null &
  43. echo $! > $pidfile
  44. echo "${name} started."
  45. return 0
  46. }
  47. stop() {
  48. if status ; then
  49. pid=`cat "$pidfile"`
  50. echo "Killing ${name} (pid $pid) with SIGTERM"
  51. kill -TERM $pid
  52. for i in 1 2 3 4 5 ; do
  53. echo "Waiting ${name} (pid $pid) to die..."
  54. status || break
  55. sleep 1
  56. done
  57. if status ; then
  58. echo "${name} stop Failed; still running."
  59. else
  60. echo "${name} stopped."
  61. fi
  62. fi
  63. }
  64. status() {
  65. if [ -f "$pidfile" ] ; then
  66. pid=`cat "$pidfile"`
  67. if kill -0 $pid > /dev/null 2> /dev/null ; then
  68. return 0
  69. else
  70. return 2
  71. fi
  72. else
  73. return 3
  74. fi
  75. }
  76. force_stop() {
  77. if status ; then
  78. stop
  79. status && kill -KILL `cat "$pidfile"`
  80. fi
  81. }
  82. case "$1" in
  83. start)
  84. status
  85. code=$?
  86. if [ $code -eq 0 ]; then
  87. echo "${name} is already running"
  88. else
  89. start
  90. code=$?
  91. fi
  92. exit $code
  93. ;;
  94. stop) stop ;;
  95. force-stop) force_stop ;;
  96. status)
  97. status
  98. code=$?
  99. if [ $code -eq 0 ] ; then
  100. echo "${name} is running"
  101. else
  102. echo "${name} is not running"
  103. fi
  104. exit $code
  105. ;;
  106. restart)
  107. stop && start
  108. ;;
  109. *)
  110. echo "Usage: ${SCRIPTNAME} {start|stop|force-stop|status|restart}" >&2
  111. exit 3
  112. ;;
  113. esac
  114. exit $?


退出保存:wq
[root@bigdata2 ELK]# chmod +x logstash.sh //授予可执行权限
[root@bigdata2 ELK]# ./logstash.sh start //启动服务

安装kibana

[root@bigdata2 ELK]# tar -zxvf kibana-5.5.1.tar.gz
[root@bigdata2 ELK]# mv kibana-5.5.1 kibana
[root@bigdata2 ELK]# cd kibana/config
[root@bigdata2 kibana]# vi kibana.yml
修改以下配置
server.host 为0.0.0.0
elasticsearch.url: "http://192.168.40.249:9200" //本机可以直接填写localhost
[root@bigdata2 kibana]# cd ../bin
[root@bigdata2 bin]#nohup kibana & //后台运行

服务启动完成后,在浏览器中访问地址: http://192.168.40.249:5601


添加索引的正则,如上图,我的日志索引是lymtest,我就输入正则为 lymtest*,保存,添加成功


然后选择Discover模块,就可以查询采集的日志信息


到此,ELK 5.5.1就完成了搭建。

猜你在找的CentOS相关文章