设为首页 收藏本站
查看: 1048|回复: 0

[经验分享] elk+redis centos6.6安装与配置

[复制链接]

尚未签到

发表于 2018-4-28 08:42:30 | 显示全部楼层 |阅读模式
本人安装配置ELK走了不少弯路,初学者按以下步骤安装及可使用; 建议安装配置之前先对阅读相关架构原理。

logstash,elasticsearch,kibana
怎么进行nginx的日志分析呢?首先,架构方面,nginx是有日志文件的,它的每个请求的状态等都有日志文件进行记录。其次,需要有个队
列,redis的list结构正好可以作为队列使用。然后分析使用elasticsearch就可以进行分析和查询了。

我们需要的是一个分布式的,日志收集和分析系统。logstash有agent和indexer两个角色。对于agent角色,放在单独的web机
器上面,然后这个agent不断地读取nginx的日志文件,每当它读到新的日志信息以后,就将日志传送到网络上的一台redis队列上。对于队列上的这
些未处理的日志,有不同的几台logstash
indexer进行接收和分析。分析之后存储到elasticsearch进行搜索分析。再由统一的kibana进行日志web界面的展示。

  

相关环境:Centos_x64_6.6  redis2.8.23  Elasticsearch 2.0.0, Logstash 2.0.0,  Kibana4.2.0

软件下载地址:

redis: http://redis.io/download
Elasticsearch: wget https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/rpm/elasticsearch/2.0.0/elasticsearch-2.0.0.rpm
Logstash: wget https://download.elastic.co/logstash/logstash/packages/centos/logstash-2.0.0-1.noarch.rpmKibana: wget  https://download.elastic.co/kibana/kibana/kibana-4.2.0-linux-x64.tar.gz
Kibana: wget https://download.elastic.co/kibana/kibana/kibana-4.2.0-linux-x64.tar.gz
jdk:  wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u65-b17/jdk-8u65-linux-x64.rpmyum localinstall jdk-8u65-linux-x64.rpm  

Install Java 8
[root@localhost src]# rpm -ivh jdk-8u65-linux-x64.rpm
Preparing...                ########################################### [100%]
   1:jdk1.8.0_65            ########################################### [100%]
Unpacking JAR files...
        tools.jar...
        plugin.jar...
        javaws.jar...
        deploy.jar...
        rt.jar...
        jsse.jar...
        charsets.jar...
        localedata.jar...
        jfxrt.jar...
[root@localhost src]# ln -s  /usr/java/jdk1.8.0_65/jre/bin/java /usr/bin/javaInstall redis
先安装依赖tcl
[root@localhost src]# yum install tcl
安装redis
[root@localhost src]#tar zxvf redis-2.8.23.tar.gz
[root@localhost src]# cd redis-2.8.23
[root@localhost redis-2.8.23]#
[root@localhost redis-2.8.23]# make
[root@localhost redis-2.8.23]# make install
redis安装后配置[root@localhost redis-2.8.23]# cd utils/
[root@localhost utils]# ./install_server.shWelcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port           : 6379
Config file    : /etc/redis/6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!Install Elasticsearch
[root@localhost src]#rpm -ivh elasticsearch-2.0.0.rpm
warning: elasticsearch-2.0.0.rpm: Header V4 RSA/SHA1 Signature, key ID d88e42b4: NOKEY
Preparing...                ########################################### [100%]
Creating elasticsearch group... OK
Creating elasticsearch user... OK
   1:elasticsearch          ########################################### [100%]
### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using chkconfig
sudo chkconfig --add elasticsearch
### You can start elasticsearch service by executing
sudo service elasticsearch start
[root@localhost src]# /etc/init.d/elasticsearch start
  正在启动 elasticsearch:                                   [确定]
[root@localhost src]# chkconfig elasticsearch onInstall Kibana
[root@localhost opt]#groupadd -g 1005 kibana
[root@localhost opt]#useradd -u 1005 -g 1005 kibana
[root@localhost opt]# tar zxvf kibana-4.2.0-linux-x64.tar.gz  -C /opt/
[root@localhost ~]# cd /opt[root@localhost opt]# mv kibana-4.2.0-linux-x64/ kibana
[root@localhost opt]#chown -R kibana: /opt/kibana
[root@localhost opt]#cd /etc/init.d &&  curl -o kibana https://gist.githubusercontent.com/thisismitch/8b15ac909aed214ad04a/raw/fc5025c3fc499ad8262aff34ba7fde8c87ead7c0/kibana-4.x-init
[root@localhost opt]#cd /etc/init.d &&  curl -o kibana https://gist.githubusercontent.com/thisismitch/8b15ac909aed214ad04a/raw/fc5025c3fc499ad8262aff34ba7fde8c87ead7c0/kibana-4.x-initcd /etc/default &&  curl -o kibana https://gist.githubusercontent.com/thisismitch/8b15ac909aed214ad04a/raw/fc5025c3fc499ad8262aff34ba7fde8c87ead7c0/kibana-4.x-default
[root@localhost opt]#service kibana start
[root@localhost opt]#chkconfig kibana on
如果启动不成功请手动启动 nohup  /opt/kibana/bin/kibana -l /var/log/kibana.log &
检查5601端口是否启动 netstat -ntlup |grep ":5601"Install Logstash
[root@localhost src]rpm -ivh logstash-2.0.0-1.noarch.rpm
Preparing...                ########################################### [100%]
   1:logstash               ########################################### [100%]
server端配置
[root@localhost conf.d]# cat /etc/logstash/conf.d/index.conf
input {
  redis {
        host => "127.0.0.1"
        port => 6379
        data_type => "list"
        key => "logstash:redis"
        type => "redis-input"
}
}
filter {
    grok {   
        match => [ "message", "%{WORD:http_host} %{URIHOST:api_domain} %{IP:inner_ip} %{IP:lvs_ip} \[%{HTTPDATE:timestamp}\] \"%{WORD:http_verb} %{URIPATH:baseurl}(?:\?%{NOTSPACE:request}|) HTTP/%{NUMBER:http_version}\" (?:-|%{NOTSPACE:request}) %{NUMBER:http_status_code} (?:%{NUMBER:bytes_read}|-) %{QS:referrer} %{QS:agent} %{NUMBER:time_duration:float} (?:%{NUMBER:time_backend_response:float}|-)"]
    kv {
        prefix => "request."
        field_split => "&"
        source => "request"
    }
    urldecode {
        all_fields => true
    }
    date { type => "log-date"
        match => ["timestamp" , "dd/MMM/YYYY:HH:mm:ss Z"]
    }
}
output {
  elasticsearch { hosts => ["localhost:9200"] }
}
本机日志配置
[root@localhost conf.d]# cat /etc/logstash/conf.d/agent.conf
input {
  file { path => "日志路径" }  #logstash用户需要对文件有读权限
}
output {
     redis {
          host => "127.0.0.1"  #redis IP地址
          data_type => "list"
          key => "logstash:redis"
        }
}[root@localhost src]# /etc/init.d/logstash start[root@localhost src]# chkconfig logstash on  

客房端安装配置

  

在nginx.conf 中设置日志格式:logstash

log_format logstash '$http_host $server_addr $remote_addr [$time_local] "$request" '
                    '$request_body $status $body_bytes_sent "$http_referer" "$http_user_agent" '
                    '$request_time $upstream_response_time';[root@localhost src]rpm -ivh logstash-2.0.0-1.noarch.rpm
Preparing...                ########################################### [100%]
   1:logstash               ########################################### [100%] [root@localhost conf.d]# cat /etc/logstash/conf.d/agent.conf
input {
  file { path => "日志路径" }  #logstash用户需要对文件有读权限
}
output {
     redis {
          host => "x.x.x.x"  #redis IP地址
          data_type => "list"
          key => "logstash:redis"
        }
}  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-452940-1-1.html 上篇帖子: CentOS 6.7 FTP安装配置之vsftp 下篇帖子: Centos6.5 安装Python 3.5+ipython
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表