分享

Elk实时日志分析平台5.0版本源码安装配置

 株野 2017-06-08

ELK5.0版本源码安装过程,水平有限,凑合着看!!最后附上安装包


一、配置Java环境变量

  1. # mkdir /usr/local/java/ –p  
  2. # cd /usr/local/java/  
  3. # tar zxvf /data/elk5.0/jdk-8u111-linux-x64.tar.gz  
  4.    
  5. # cat >>/etc/profile<<EOF  
  6.    
  7. export JAVA_HOME=/usr/local/java/jdk1.8.0_111  
  8. export PATH=$PATH:$JAVA_HOME/bin  
  9. exportCLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar  
  10. EOF  
  11.    
  12. # source /etc/profile  
  13. # java -version  
  14. java version "1.8.0_111"  
  15. Java(TM) SE Runtime Environment (build 1.8.0_111-b14)  
  16. Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixedmode)  


 

二、安装elasticsearch

  1. # mkdir  /data/PRG/-p  
  2. # cd /data/PRG/  
  3. # tar zxvf /data/elk5.0/elasticsearch-5.0.0.tar.gz  
  4. # mv elasticsearch-5.0.0 elasticsearch  
  5. # useradd elasticsearch -s /sbin/nologin  
  6. # chown elasticsearch. elasticsearch /data/PRG/elasticsearch/  


添加启动脚本

vi /etc/init.d/elasticsearch

 

  1. #!/bin/sh  
  2. #  
  3. # elasticsearch <summary>  
  4. #  
  5. # chkconfig:   2345 80 20  
  6. # description: Starts and stops a single elasticsearch instance on this system  
  7. #  
  8.   
  9.   
  10. ### BEGIN INIT INFO  
  11. # Provides: Elasticsearch  
  12. # Required-Start: $network $named  
  13. # Required-Stop: $network $named  
  14. # Default-Start: 2 3 4 5  
  15. # Default-Stop: 0 1 6  
  16. # Short-Description: This service manages the elasticsearch daemon  
  17. # Description: Elasticsearch is a very scalable, schema-free and high-performance search solution supporting multi-tenancy and near realtime search.  
  18. ### END INIT INFO  
  19.   
  20.   
  21. #  
  22. # init.d / servicectl compatibility (openSUSE)  
  23. #  
  24. if [ -f /etc/rc.status ]; then  
  25.     . /etc/rc.status  
  26.     rc_reset  
  27. fi  
  28.   
  29.   
  30. #  
  31. # Source function library.  
  32. #  
  33. if [ -f /etc/rc.d/init.d/functions ]; then  
  34.     . /etc/rc.d/init.d/functions  
  35. fi  
  36.   
  37.   
  38.   
  39.   
  40.   
  41.   
  42. # Sets the default values for elasticsearch variables used in this script  
  43. export JAVA_HOME=/usr/local/java/jdk1.8.0_111  
  44. ES_USER="elasticsearch"  
  45. ES_GROUP="elasticsearch"  
  46. name=elasticsearch  
  47. ES_HOME="/data/PRG/elasticsearch"  
  48. MAX_OPEN_FILES=65536  
  49. MAX_MAP_COUNT=262144  
  50. LOG_DIR="$ES_HOME/log/"  
  51. DATA_DIR="$ES_HOME/lib/"  
  52. CONF_DIR="$ES_HOME/config"  
  53. mkdir -p $LOG_DIR  
  54. chown -R elasticsearch.elasticsearch $ES_HOME  
  55.   
  56.   
  57. PID_DIR="$ES_HOME/log"  
  58.   
  59.   
  60. # Source the default env file  
  61. ES_ENV_FILE="/etc/sysconfig/elasticsearch"  
  62. if [ -f "$ES_ENV_FILE" ]; then  
  63.     . "$ES_ENV_FILE"  
  64. fi  
  65.   
  66.   
  67. # CONF_FILE setting was removed  
  68. if [ ! -z "$CONF_FILE" ]; then  
  69.     echo "CONF_FILE setting is no longer supported. elasticsearch.yml must be placed in the config directory and cannot be renamed."  
  70.     exit 1  
  71. fi  
  72.   
  73.   
  74. exec="$ES_HOME/bin/elasticsearch"  
  75. prog="elasticsearch"  
  76. pidfile="$PID_DIR/${prog}.pid"  
  77.   
  78.   
  79. export ES_HEAP_SIZE  
  80. export ES_HEAP_NEWSIZE  
  81. export ES_DIRECT_SIZE  
  82. export ES_JAVA_OPTS  
  83. export ES_GC_LOG_FILE  
  84. export ES_STARTUP_SLEEP_TIME  
  85. export JAVA_HOME  
  86. export ES_INCLUDE  
  87. ulimit -n $MAX_OPEN_FILES  
  88. lockfile=$ES_HOME/log/$prog  
  89.   
  90.   
  91. # backwards compatibility for old config sysconfig files, pre 0.90.1  
  92. if [ -n $USER ] && [ -z $ES_USER ] ; then  
  93.    ES_USER=$USER  
  94. fi  
  95.   
  96.   
  97. checkJava() {  
  98.     if [ -x "$JAVA_HOME/bin/java" ]; then  
  99.         JAVA="$JAVA_HOME/bin/java"  
  100.     else  
  101.         JAVA=`which java`  
  102.     fi  
  103.   
  104.   
  105.     if [ ! -x "$JAVA" ]; then  
  106.         echo "Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME"  
  107.         exit 1  
  108.     fi  
  109. }  
  110.   
  111.   
  112. start() {  
  113.     checkJava  
  114.     [ -x $exec ] || exit 5  
  115.     if [ -n "$MAX_LOCKED_MEMORY" -a -z "$ES_HEAP_SIZE" ]; then  
  116.         echo "MAX_LOCKED_MEMORY is set - ES_HEAP_SIZE must also be set"  
  117.         return 7  
  118.     fi  
  119.     if [ -n "$MAX_OPEN_FILES" ]; then  
  120.         ulimit -n $MAX_OPEN_FILES  
  121.     fi  
  122.     if [ -n "$MAX_LOCKED_MEMORY" ]; then  
  123.         ulimit -l $MAX_LOCKED_MEMORY  
  124.     fi  
  125.     if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count ]; then  
  126.         sysctl -q -w vm.max_map_count=$MAX_MAP_COUNT  
  127.     fi  
  128.     export ES_GC_LOG_FILE  
  129.   
  130.   
  131.     # Ensure that the PID_DIR exists (it is cleaned at OS startup time)  
  132.     if [ -n "$PID_DIR" ] && [ ! -e "$PID_DIR" ]; then  
  133.         mkdir -p "$PID_DIR" && chown "$ES_USER":"$ES_GROUP" "$PID_DIR"  
  134.     fi  
  135.     if [ -n "$pidfile" ] && [ ! -e "$pidfile" ]; then  
  136.         touch "$pidfile" && chown "$ES_USER":"$ES_GROUP" "$pidfile"  
  137.     fi  
  138.   
  139.   
  140.     cd $ES_HOME  
  141.     echo -n $"Starting $prog: "  
  142.     # if not running, start it up here, usually something like "daemon $exec"  
  143.     daemon --user $ES_USER  --pidfile $pidfile $exec -p $pidfile -d  
  144.   
  145.   
  146.     #daemon --user $ES_USER --pidfile $pidfile $exec -p $pidfile -d -Des.default.path.home=$ES_HOME -Des.default.path.logs=$LOG_DIR -Des.default.path.data=$DATA_DIR -Des.default.path.conf=$CONF_DIR  
  147.     retval=$?  
  148.     echo  
  149.     [ $retval -eq 0 ] && touch $lockfile  
  150.     return $retval  
  151. }  
  152.   
  153.   
  154. stop() {  
  155.     echo -n $"Stopping $prog: "  
  156.     # stop it here, often "killproc $prog"  
  157.     killproc -p $pidfile -d 86400 $prog  
  158.     retval=$?  
  159.     echo  
  160.     [ $retval -eq 0 ] && rm -f $lockfile  
  161.     return $retval  
  162. }  
  163.   
  164.   
  165. restart() {  
  166.     stop  
  167.     start  
  168. }  
  169.   
  170.   
  171. reload() {  
  172.     restart  
  173. }  
  174.   
  175.   
  176. force_reload() {  
  177.     restart  
  178. }  
  179.   
  180.   
  181. rh_status() {  
  182.     # run checks to determine if the service is running or use generic status  
  183.     status -p $pidfile $prog  
  184. }  
  185.   
  186.   
  187. rh_status_q() {  
  188.     rh_status >/dev/null 2>&1  
  189. }  
  190.   
  191.   
  192.   
  193.   
  194. case "$1" in  
  195.     start)  
  196.         rh_status_q && exit 0  
  197.         $1  
  198.         ;;  
  199.     stop)  
  200.         rh_status_q || exit 0  
  201.         $1  
  202.         ;;  
  203.     restart)  
  204.         $1  
  205.         ;;  
  206.     reload)  
  207.         rh_status_q || exit 7  
  208.         $1  
  209.         ;;  
  210.     force-reload)  
  211.         force_reload  
  212.         ;;  
  213.     status)  
  214.         rh_status  
  215.         ;;  
  216.     condrestart|try-restart)  
  217.         rh_status_q || exit 0  
  218.         restart  
  219.         ;;  
  220.     *)  
  221.         echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"  
  222.         exit 2  
  223. esac  
  224. exit $?  

  1. # chmod +x /etc/init.d/elasticsearch  
  2.    
  3. # /etc/init.d/elasticsearch start  
  4.    
  5. # /etc/init.d/elasticsearch status  
  6. elasticsearch (pid 20895) is running...  
  7. # netstat -ntlp |grep 9[2-3]00  
  8. tcp        0     0 :::9300                    :::*                        LISTEN      20895/java           
  9. tcp        0      0 :::9200                     :::*                        LISTEN      20895/java  




三、配置elasticsearch 

内存低于2G,需要修改jvm配置

  1. # vim /data/PRG/elasticsearch/config/jvm.options  
  2. -Xms512m  
  3. -Xmx512m  

 

  1. # cat /data/PRG/elasticsearch/config/elasticsearch.yml|grep -v '#'  
  2. network.host: 0.0.0.0           ###开启监听地址,  
  3. action.auto_create_index:.security,.monitoring*,.watches,.triggered_watches,.watcher-history*  
  4. ####以下模块视情况是否开启  
  5. xpack.security.enabled: true          ####开启用户认证  
  6. xpack.monitoring.enabled: true  
  7. xpack.graph.enabled: true  
  8. xpack.watcher.enabled: true  
  9. xpack.security.authc.realms:     ####用户认证模式,ldap、file、pki、ActiveDirectory等  
  10.     file1:  
  11.       type: file  
  12.       order: 0  


四、安装logstash

  1. # cd /data/PRG/  
  2. # tar zxvf /data/elk5.0/logstash-5.0.0.tar.gz  
  3. # mv logstash-5.0.0 logstash  
  4. # useradd logstash -s /sbin/nologin  
  5. # chown logstash. logstash /data/PRG/logstash  


         添加启动脚本

vim /etc/init.d/logstash

  1. #!/bin/sh  
  2. # Init script for logstash  
  3. # Maintained by Elasticsearch  
  4. # Generated by pleaserun.  
  5. # Implemented based on LSB Core 3.1:  
  6. #   * Sections: 20.2, 20.3  
  7. #  
  8. ### BEGIN INIT INFO  
  9. # Provides:          logstash  
  10. # Required-Start:    $remote_fs $syslog  
  11. # Required-Stop:     $remote_fs $syslog  
  12. # Default-Start:     2 3 4 5  
  13. # Default-Stop:      0 1 6  
  14. # Short-Description:  
  15. # Description:        Starts Logstash as a daemon.  
  16. ### END INIT INFO  
  17.   
  18. PATH=/sbin:/usr/sbin:/bin:/usr/bin:/data/PRG/logstash/bin  
  19. export PATH  
  20.   
  21. if [ `id -u` -ne 0 ]; then  
  22.    echo "You need root privileges to run this script"  
  23.    exit 1  
  24. fi  
  25.   
  26. name=logstash  
  27.   
  28. LS_USER=logstash  
  29. LS_GROUP=logstash  
  30. LS_HOME=/data/PRG/logstash  
  31. LS_HEAP_SIZE="1g"  
  32. LS_LOG_DIR=/data/PRG/logstash/logs  
  33. LS_LOG_FILE="${LS_LOG_DIR}/$name.log"  
  34. pidfile="${LS_LOG_DIR}/$name.pid"  
  35. LS_CONF_DIR=/data/PRG/logstash/conf.d  
  36. LS_OPEN_FILES=16384  
  37. LS_NICE=19  
  38. KILL_ON_STOP_TIMEOUT=${KILL_ON_STOP_TIMEOUT-0} #default value is zero to this variable but could be updated by user request  
  39. LS_OPTS=""  
  40.   
  41.   
  42. [ -r /etc/default/$name ] && . /etc/default/$name  
  43. [ -r /etc/sysconfig/$name ] && . /etc/sysconfig/$name  
  44.   
  45. program=$LS_HOME/bin/logstash  
  46. args=" -f ${LS_CONF_DIR} -l ${LS_LOG_FILE} ${LS_OPTS}"  
  47.   
  48. quiet() {  
  49.   "$@" > /dev/null 2>&1  
  50.   return $?  
  51. }  
  52.   
  53. start() {  
  54.   
  55.   LS_JAVA_OPTS="${LS_JAVA_OPTS} -Djava.io.tmpdir=${LS_HOME}"  
  56.   HOME=${LS_HOME}  
  57.   export PATH HOME LS_HEAP_SIZE LS_JAVA_OPTS LS_USE_GC_LOGGING LS_GC_LOG_FILE  
  58.   
  59.   # chown doesn't grab the suplimental groups when setting the user:group - so we have to do it for it.  
  60.   # Boy, I hope we're root here.  
  61.   SGROUPS=$(id -Gn "$LS_USER" | tr " " "," | sed 's/,$//'; echo '')  
  62.   
  63.   if [ ! -z $SGROUPS ]  
  64.   then  
  65.         EXTRA_GROUPS="--groups $SGROUPS"  
  66.   fi  
  67.   
  68.   # set ulimit as (root, presumably) first, before we drop privileges  
  69.   ulimit -n ${LS_OPEN_FILES}  
  70.   
  71.   # Run the program!  
  72.   nice -n ${LS_NICE} chroot --userspec $LS_USER:$LS_GROUP $EXTRA_GROUPS / sh -c "  
  73.     cd $LS_HOME  
  74.     ulimit -n ${LS_OPEN_FILES}  
  75.     $program $args > ${LS_LOG_DIR}/$name.stdout" 2> "${LS_LOG_DIR}/$name.err" &  
  76.   
  77.   # Generate the pidfile from here. If we instead made the forked process  
  78.   # generate it there will be a race condition between the pidfile writing  
  79.   # and a process possibly asking for status.  
  80.   echo $! > $pidfile  
  81.   
  82.   echo "$name started."  
  83.   return 0  
  84. }  
  85.   
  86. stop() {  
  87.   # Try a few times to kill TERM the program  
  88.   if status ; then  
  89.     pid=`cat "$pidfile"`  
  90.     echo "Killing $name (pid $pid) with SIGTERM"  
  91.     ps -ef |grep $pid |grep -v 'grep' |awk '{print $2}' | xargs kill -9  
  92.     # Wait for it to exit.  
  93.     for i in 1 2 3 4 5 6 7 8 9 ; do  
  94.       echo "Waiting $name (pid $pid) to die..."  
  95.       status || break  
  96.       sleep 1  
  97.     done  
  98.     if status ; then  
  99.       if [ $KILL_ON_STOP_TIMEOUT -eq 1 ] ; then  
  100.         echo "Timeout reached. Killing $name (pid $pid) with SIGKILL. This may result in data loss."  
  101.         kill -KILL $pid  
  102.         echo "$name killed with SIGKILL."  
  103.       else  
  104.         echo "$name stop failed; still running."  
  105.         return 1 # stop timed out and not forced  
  106.       fi  
  107.     else  
  108.       echo "$name stopped."  
  109.     fi  
  110.   fi  
  111. }  
  112.   
  113. status() {  
  114.   if [ -f "$pidfile" ] ; then  
  115.     pid=`cat "$pidfile"`  
  116.     if kill -0 $pid > /dev/null 2> /dev/null ; then  
  117.       # process by this pid is running.  
  118.       # It may not be our pid, but that's what you get with just pidfiles.  
  119.       # TODO(sissel): Check if this process seems to be the same as the one we  
  120.       # expect. It'd be nice to use flock here, but flock uses fork, not exec,  
  121.       # so it makes it quite awkward to use in this case.  
  122.       return 0  
  123.     else  
  124.       return 2 # program is dead but pid file exists  
  125.     fi  
  126.   else  
  127.     return 3 # program is not running  
  128.   fi  
  129. }  
  130.   
  131. configtest() {  
  132.   # Check if a config file exists  
  133.   if [ ! "$(ls -A ${LS_CONF_DIR}/* 2> /dev/null)" ]; then  
  134.     echo "There aren't any configuration files in ${LS_CONF_DIR}"  
  135.     return 1  
  136.   fi  
  137.   
  138.   HOME=${LS_HOME}  
  139.   export PATH HOME  
  140.   
  141.   test_args="-t -f ${LS_CONF_DIR} ${LS_OPTS} "  
  142.   $program ${test_args}  
  143.   [ $? -eq 0 ] && return 0  
  144.   # Program not configured  
  145.   return 6  
  146. }  
  147.   
  148. case "$1" in  
  149.   start)  
  150.     status  
  151.     code=$?  
  152.     if [ $code -eq 0 ]; then  
  153.       echo "$name is already running"  
  154.     else  
  155.       start  
  156.       code=$?  
  157.     fi  
  158.     exit $code  
  159.     ;;  
  160.   stop) stop ;;  
  161.   force-stop) force_stop ;;  
  162.   status)  
  163.     status  
  164.     code=$?  
  165.     if [ $code -eq 0 ] ; then  
  166.       echo "$name is running"  
  167.     else  
  168.       echo "$name is not running"  
  169.     fi  
  170.     exit $code  
  171.     ;;  
  172.   reload) reload ;;  
  173.   restart)  
  174.     stop && start  
  175.     ;;  
  176.   check)  
  177.     configtest  
  178.     exit $?  
  179.     ;;  
  180.   *)  
  181.     echo "Usage: $SCRIPTNAME {start|stop|status|restart|check}" >&2  
  182.     exit 3  
  183.   ;;  
  184. esac  
  185.   
  186. exit $?  


  1. # chmod +x /etc/init.d/logstash  
  2. # /etc/init.d/logstash start  
  3. # /etc/init.d/logstash status    
  4. logstash is running  
  5.    
  6. # netstat -ntlp|grep 9600  
  7. tcp        0      0 :::9600                     :::*                        LISTEN      10141/java     


 

五、配置logstash

# cat /data/PRG/logstash/config/logstash.yml  |grep -v '#'

http.host: "0.0.0.0"       ###开启监听地址

 

ngin日志收集

  1. # cat /data/PRG/logstash/conf.d/filter.conf  
  2. input {  
  3.   beats {  
  4.     port => 10200  
  5.   }  
  6. }  
  7.    
  8. filter {  
  9.     grok {       
  10.             match=> {  
  11.                message => "%{IPORHOST:remote_addr} , 
    , %{IPORHOST:http_host} , \"%{WORD:http_verb}(?:%{PATH:baseurl}\?%{NOTSPACE:params}|%{DATA:raw_http_request})\" , %{NUMBER:http_status_code}, %{NUMBER:bytes_read} , %{QS:referrer} , %{QS:agent} ,\"%{IPORHOST:client_ip}, %{IPORHOST:proxy_server}\" , - , - , - ,%{IPORHOST:server_ip} , %{BASE10NUM:request_duration}"  
  12.             }  
  13.    
  14.             match=> {  
  15.                message => "%{IPORHOST:remote_addr} , 
    , %{IPORHOST:http_host} , \"%{WORD:http_verb}(?:%{PATH:baseurl}\?%{NOTSPACE:params}|%{DATA:raw_http_request})\" , %{NUMBER:http_status_code}, %{NUMBER:bytes_read} , %{QUOTEDSTRING:referrer} , %{QS:agent} ,\"%{IPORHOST:client_ip}, %{IPORHOST:proxy_server}\" ,%{IPORHOST}:%{INT} , %{INT} , %{BASE10NUM} , %{IPORHOST} ,%{BASE10NUM:request_duration}"  
  16.             }  
  17.     }  
  18.    
  19. }  
  20. output {  
  21.  elasticsearch {  
  22.    hosts =>["192.168.62.200:9200"]  
  23.    index =>"operation-%{+YYYY.MM.dd}"  
  24.    document_type=> "nginx2"  
  25.    user => 'admin'              #### elasticsearch的用户名,用X-PACK插件创建  
  26.    password =>'kbsonlong'       #### elasticsearch的用户名  
  27.   }  
  28.  stdout { codec =>rubydebug }  
  29. }  


 

 

 

六、安装kibana

  1. # cd /data/PRG/  
  2. # tar zxvf /data/elk5.0/kibana-5.0.0-linux-x86_64.tar.gz  
  3. # mv kibana-5.0.0-linux-x86_64 kibana  
  4. # useradd kibana –s /sbin/nologin  
  5. # chown kibana. kibana /data/PRG/kibana  

添加启动脚本

# vim /etc/init.d/kibana

 

  1. #!/bin/sh  
  2. # Init script for kibana  
  3. # Maintained by   
  4. # Generated by pleaserun.  
  5. # Implemented based on LSB Core 3.1:  
  6. #   * Sections: 20.2, 20.3  
  7. #  
  8. ### BEGIN INIT INFO  
  9. # Provides:          kibana  
  10. # Required-Start:    $remote_fs $syslog  
  11. # Required-Stop:     $remote_fs $syslog  
  12. # Default-Start:     2 3 4 5  
  13. # Default-Stop:      0 1 6  
  14. # Short-Description:   
  15. # Description:       Kibana  
  16. ### END INIT INFO  
  17.   
  18. PATH=/sbin:/usr/sbin:/bin:/usr/bin  
  19. export PATH  
  20.   
  21. KIBANA_HOME=/data/PRG/kibana  
  22. name=kibana  
  23. program=$KIBANA_HOME/bin/kibana  
  24. args=''  
  25. pidfile="$KIBANA_HOME/logs/$name.pid"  
  26. LOG_HOME="$KIBANA_HOME/logs"  
  27.   
  28. [ -r /etc/default/$name ] && . /etc/default/$name  
  29. [ -r /etc/sysconfig/$name ] && . /etc/sysconfig/$name  
  30.   
  31. [ -z "$nice" ] && nice=0  
  32.   
  33. trace() {  
  34.   logger -t "/etc/init.d/kibana" "$@"  
  35. }  
  36.   
  37. emit() {  
  38.   trace "$@"  
  39.   echo "$@"  
  40. }  
  41.   
  42. start() {  
  43.   
  44.   # Ensure the log directory is setup correctly.  
  45.   [ ! -d "$LOG_HOME" ] && mkdir "$LOG_HOME"  
  46.   chmod 755 "$LOG_HOME"  
  47.   
  48.   
  49.   # Setup any environmental stuff beforehand  
  50.     
  51.   
  52.   # Run the program!  
  53.     
  54.   #chroot --userspec "$user":"$group" "$chroot" sh -c "  
  55.       
  56.   $program $args >> $LOG_HOME/kibana.stdout 2>> $LOG_HOME/kibana.stderr &  
  57.   
  58.   # Generate the pidfile from here. If we instead made the forked process  
  59.   # generate it there will be a race condition between the pidfile writing  
  60.   # and a process possibly asking for status.  
  61.   echo $! > $pidfile  
  62.   
  63.   emit "$name started"  
  64.   return 0  
  65. }  
  66.   
  67. stop() {  
  68.   # Try a few times to kill TERM the program  
  69.   if status ; then  
  70.     pid=$(cat "$pidfile")  
  71.     echo "Killing $name (pid $pid) with SIGTERM"  
  72.     ps -ef |grep $pid |grep -v 'grep' |awk '{print $2}' | xargs kill -9  
  73.     # Wait for it to exit.  
  74.     for i in 1 2 3 4 5 ; do  
  75.       trace "Waiting $name (pid $pid) to die..."  
  76.       status || break  
  77.       sleep 1  
  78.     done  
  79.     if status ; then  
  80.       if [ "$KILL_ON_STOP_TIMEOUT" -eq 1 ] ; then  
  81.         trace "Timeout reached. Killing $name (pid $pid) with SIGKILL.  This may result in data loss."  
  82.         kill -KILL $pid  
  83.         emit "$name killed with SIGKILL."  
  84.       else  
  85.         emit "$name stop failed; still running."  
  86.       fi  
  87.     else  
  88.       emit "$name stopped."  
  89.     fi  
  90.   fi  
  91. }  
  92.   
  93. status() {  
  94.   if [ -f "$pidfile" ] ; then  
  95.     pid=$(cat "$pidfile")  
  96.     if ps -p $pid > /dev/null 2> /dev/null ; then  
  97.       # process by this pid is running.  
  98.       # It may not be our pid, but that's what you get with just pidfiles.  
  99.       # TODO(sissel): Check if this process seems to be the same as the one we  
  100.       # expect. It'd be nice to use flock here, but flock uses fork, not exec,  
  101.       # so it makes it quite awkward to use in this case.  
  102.       return 0  
  103.     else  
  104.       return 2 # program is dead but pid file exists  
  105.     fi  
  106.   else  
  107.     return 3 # program is not running  
  108.   fi  
  109. }  
  110.   
  111.   
  112.   
  113.   
  114. case "$1" in  
  115.   force-start|start|stop|status|restart)  
  116.     trace "Attempting '$1' on kibana"  
  117.     ;;  
  118. esac  
  119.   
  120. case "$1" in  
  121.   force-start)  
  122.     PRESTART=no  
  123.     exec "$0" start  
  124.     ;;  
  125.   start)  
  126.     status  
  127.     code=$?  
  128.     if [ $code -eq 0 ]; then  
  129.       emit "$name is already running"  
  130.       exit $code  
  131.     else  
  132.       start  
  133.       exit $?  
  134.     fi  
  135.     ;;  
  136.   stop) stop ;;  
  137.   status)  
  138.     status  
  139.     code=$?  
  140.     if [ $code -eq 0 ] ; then  
  141.       emit "$name is running"  
  142.     else  
  143.       emit "$name is not running"  
  144.     fi  
  145.     exit $code  
  146.     ;;  
  147.   restart)  
  148.       
  149.     stop && start  
  150.     ;;  
  151.   *)  
  152.     echo "Usage: $SCRIPTNAME {start|force-start|stop|force-start|force-stop|status|restart}" >&2  
  153.     exit 3  
  154.   ;;  
  155. esac  
  156.   
  157. exit $?  

  1. # chmod +x /etc/init.d/kibana  
  2. # /etc/init.d/kibana start  
  3. # /etc/init.d/kibana status  
  4. # netstat -ntlp |grep 5601  
  5. tcp        0      0 0.0.0.0:5601                0.0.0.0:*                   LISTEN      13052/node   
  6.    


七、配置kibana

  1. # cat /data/PRG/kibana/config/kibana.yml |grep -v '#'                                       
  2. server.host: "0.0.0.0"  
  3.    
  4. ####以下模块视情况是否开启  
  5. xpack.security.enabled: true  
  6. xpack.monitoring.enabled: true  
  7. xpack.graph.enabled: true  
  8. xpack.reporting.enabled: true  


 

 

八、x-pack插件安装

 

# /data/PRG/kibana/bin/kibana-plugin install file:///root/x-pack-5.0.0.zip

 

# /data/PRG/elasticsearch/bin/elasticsearch-plugin install file:///root/x-pack-5.0.0.zip

 

离线安装x-pack要修改用户脚本,默认创建用户配置文件在/etc/elasticsearch/x-pack目录

# vim /data/PRG/elasticsearch/bin/x-pack/users

否则在创建用户的时候提示/etc/elasticsearch/x-pack/users…tmp不存在

# mkdir /etc/elasticsearch/x-pack/

# chown elasticsearch. elasticsearch /etc/elasticsearch/x-pack/-R

 

九、           x-pack管理用户

1、          添加用户

 

  1. # cd /data/PRG/elasticsearch   
  2. # bin/x-pack/users useradd admin -p kbsonlong -rsuperuser   


 

2、          查看用户

  1. # /data/PRG/elasticsearch/bin/x-pack/users list  
  2. admin          :superuser  
  3. test           : -                ###创建用户时没有添加-r参数,所以没有用户角色  


3、          测试用户登录

  1. # curl http://localhost:9200/_xpack/ --useradmin:kbsonlong   
  2. {"build":{"hash":"7763f8e","date":"2016-10-26T04:51:59.202Z"},"license":{"uid":"06a82587-66ac-4d4a-90c4-857d9ca7f3bc","type":"trial","mode":"trial","status":"active","expiry_date_in_millis":1483753731066},"features":{"graph":{"description":"GraphData Exploration for the ElasticStack","available":true,"enabled":true},"monitoring":{"description":"Monitoringfor the ElasticStack","available":true,"enabled":true},"security":{"description":"Securityfor the ElasticStack","available":true,"enabled":true},"watcher":{"description":"Alerting,Notification and Automation for the ElasticStack","available":true,"enabled":true}},"tagline":"Youknow, for X"}  


 

4、          删除用户

  1. # /data/PRG/elasticsearch/bin/x-pack/users userdel test  
  2.    
  3. # /data/PRG/elasticsearch/bin/x-pack/users list  
  4. admin          :superuser  


十、安装filebeat

  1. # cd /data/PRG  
  2. # tar zxvf / data/elk5.0/filebeat-5.0.0-linux-x86_64.tar.gz  
  3. # mv filebeat-5.0.0-linux-x86_64  filebeat  


配置启动脚本

# vim /etc/init.d/filebeat

 

  1. #!/bin/bash  
  2. #  
  3. # filebeat          filebeat shipper  
  4. #  
  5. # chkconfig: 2345 98 02  
  6. #  
  7.   
  8. ### BEGIN INIT INFO  
  9. # Provides:          filebeat  
  10. # Required-Start:    $local_fs $network $syslog  
  11. # Required-Stop:     $local_fs $network $syslog  
  12. # Default-Start:     2 3 4 5  
  13. # Default-Stop:      0 1 6  
  14. # Short-Description: Sends log files to Logstash or directly to Elasticsearch.  
  15. # Description:       filebeat is a shipper part of the Elastic Beats   
  16. #                    family. Please see: https://www./products/beats  
  17. ### END INIT INFO  
  18.   
  19.   
  20.   
  21. PATH=/usr/bin:/sbin:/bin:/usr/sbin  
  22. export PATH  
  23.   
  24. [ -f /etc/sysconfig/filebeat ] && . /etc/sysconfig/filebeat  
  25. pidfile=${PIDFILE-/data/PRG/filebeat/filebeat.pid}  
  26. agent=${PB_AGENT-/data/PRG/filebeat/filebeat}  
  27. args="-c /data/PRG/filebeat/filebeat.yml"  
  28. test_args="-e -configtest"  
  29. wrapper="filebeat-god"  
  30. wrapperopts="-r / -n -p $pidfile"  
  31. RETVAL=0  
  32.   
  33. # Source function library.  
  34. . /etc/rc.d/init.d/functions  
  35.   
  36. # Determine if we can use the -p option to daemon, killproc, and status.  
  37. # RHEL < 5 can't.  
  38. if status | grep -q -- '-p' 2>/dev/null; then  
  39.     daemonopts="--pidfile $pidfile"  
  40.     pidopts="-p $pidfile"  
  41. fi  
  42.   
  43. test() {  
  44.     $agent $args $test_args  
  45. }  
  46.   
  47. start() {  
  48.     echo -n $"Starting filebeat: "  
  49.     test  
  50.     if [ $? -ne 0 ]; then  
  51.         echo  
  52.         exit 1  
  53.     fi  
  54.     daemon $daemonopts $wrapper $wrapperopts -- $agent $args  
  55.     RETVAL=$?  
  56.     echo  
  57.     return $RETVAL  
  58. }  
  59.   
  60. stop() {  
  61.     echo -n $"Stopping filebeat: "  
  62.     killproc $pidopts $wrapper  
  63.     RETVAL=$?  
  64.     echo  
  65.     [ $RETVAL = 0 ] && rm -f ${pidfile}  
  66. }  
  67.   
  68. restart() {  
  69.     test  
  70.     if [ $? -ne 0 ]; then  
  71.         return 1  
  72.     fi  
  73.     stop  
  74.     start  
  75. }  
  76.   
  77. rh_status() {  
  78.     status $pidopts $wrapper  
  79.     RETVAL=$?  
  80.     return $RETVAL  
  81. }  
  82.   
  83. rh_status_q() {  
  84.     rh_status >/dev/null 2>&1  
  85. }  
  86.   
  87. case "$1" in  
  88.     start)  
  89.         start  
  90.     ;;  
  91.     stop)  
  92.         stop  
  93.     ;;  
  94.     restart)  
  95.         restart  
  96.     ;;  
  97.     condrestart|try-restart)  
  98.         rh_status_q || exit 0  
  99.         restart  
  100.     ;;  
  101.     status)  
  102.         rh_status  
  103.     ;;  
  104.     *)  
  105.         echo $"Usage: $0 {start|stop|status|restart|condrestart}"  
  106.         exit 1  
  107. esac  
  108.   
  109. exit $RETVAL  

配置filebeat

  1. # cat filebeat/filebeat.yml |grep -v '#'  
  2. filebeat.prospectors:  
  3. - input_type: log  
  4.    
  5.  paths:  
  6.     -/tmp/nginx.log  
  7. output.logstash:  
  8.  enabled: true  
  9.  hosts: ["localhost:10200"]  


 

启动filebeat

  1. # /etc/init.d/filebeat5 start  
  2. Starting filebeat: 2016/12/0807:18:37.177631 beat.go:264: INFO Home path: [/data/PRG/filebeat] Config path:[/data/PRG/filebeat] Data path: [/data/PRG/filebeat/data] Logs path:[/data/PRG/filebeat/logs]  
  3. 2016/12/08 07:18:37.177681 beat.go:174:INFO Setup Beat: filebeat; Version: 5.0.0  
  4. 2016/12/08 07:18:37.177760 logstash.go:90:INFO Max Retries set to: 3  
  5. 2016/12/08 07:18:37.177828 outputs.go:106:INFO Activated logstash as output plugin.  
  6. 2016/12/08 07:18:37.177912 publish.go:291:INFO Publisher name: operation  
  7. 2016/12/08 07:18:37.178158 async.go:63:INFO Flush Interval set to: 1s  
  8. 2016/12/08 07:18:37.178170 async.go:64:INFO Max Bulk Size set to: 2048  
  9. Config OK  
  10.                                                           [  OK  ]  
  11.    
  12. # /etc/init.d/filebeat5 status  
  13. filebeat-god (pid  7365) is running...  
  14.    
  15. # ps -ef |grep filebeat  
  16. root     7405     1  0 15:18 pts/1    00:00:00 filebeat-god -r / -n -p/data/PRG/filebeat/filebeat.pid -- /data/PRG/filebeat/filebeat -c/data/PRG/filebeat/filebeat.yml  
  17. root     7406  7405  0 15:18 pts/1    00:00:00 /data/PRG/filebeat/filebeat -c/data/PRG/filebeat/filebeat.yml  



附上安装源码包,包括x-pack、beat等

百度云盘http://pan.baidu.com/s/1skT4zCx

相关文章推荐

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多