Linux日志服务器_ELK搭建

Linux日志服务器_ELK搭建

1.实验环境及准备

(1)两台liunx虚拟机,内存至少为4G;
(2)第一台虚拟机IP为192.168.110.11,第二台虚拟机IP为192.168.110.12,可以ping通网络,彼此之间可以ping通
(3)有相应的安装包
(4)虚拟机版本为liunx centos 7.3

2.部署elasticsearch群集

1.第1台虚拟机配置群集结点

[root@localhost ~]# vim /etc/hostname
elk-n1.sevenwin.org
[root@localhost ~]# vim /etc/hosts
192.168.110.11 elk-n1 elk-n1.sevenwin.org
192.168.110.12 elk-n2 elk-n1.sevenwin.org
[root@localhost ~]# vim /etc/selinux/config      //关闭SELINUX,等同setenforce=0
SELINUX=permissive    
[root@localhost ~]# vim /etc/security/limits.conf
*       soft    nofile  65536    //加到最后一行前
*       hard    nofile  131072
*       soft    nproc   4096
*       hard    nproc   8192
*       soft    memlock unlimited
*       hard    memlock unlimited
[root@localhost ~]# cp '/tmp/VMwareDnD/22777c89/jdk-8u161-linux-x64.tar.gz' ./
[root@localhost ~]# tar zxvf jdk-8u161-linux-x64.tar.gz 
[root@localhost ~]# mv jdk1.8.0_161/ /usr/local/jdk1.8.0
[root@localhost ~]# vim /etc/profile
export JAVA_HOME=/usr/local/jdk1.8.0
export CLASSPATH=./:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH

在这里插入图片描述

[root@localhost ~]# source /etc/profile
[root@localhost ~]# java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
[root@localhost ~]# reboot
[root@elk-n1 ~]# rpm -ivh elasticsearch-7.6.0-x86_64.rpm
[root@elk-n1 ~]# mkdir -p /var/es-data
[root@elk-n1 ~]# chown -R elasticsearch:elasticsearch /var/es-data/
[root@elk-n1~]# chown -R elasticsearch:elasticsearch /var/log/elasticsearch/
[root@elk-n1 ~]# vim /etc/elasticsearch/elasticsearch.yml
cluster.name: my-elk
node.name: elk-n1
node.master: true
node.data: true
path.data: /var/es-data
path.logs: /var/log/elasticsearch
bootstrap.memory_lock: true
network.host: 0.0.0.0
http.port: 9200
cluster.initial_master_nodes: ["elk-n1"]
discovery.zen.ping.unicast.hosts: ["elk-n1", "elk-n2"]
http.cors.enabled: true
http.cors.allow-origin: "*"

在这里插入图片描述

[root@elk-n1 ~]# systemctl stop firewalld.service 
[root@elk-n1 ~]# setenforce 0
[root@elk-n1 ~]# vim /usr/lib/systemd/system/elasticsearch.service
LimitMEMLOCK=infinity
# Disable timeout logic and wait until process is stopped

在这里插入图片描述

[root@elk-n1 ~]# systemctl daemon-reload 
[root@elk-n1 ~]# systemctl start elasticsearch.service

在firefox中输入回环地址查询


2.第二台虚拟机配置群集结点

[root@localhost ~]# vim /etc/hostname
elk-n2.sevenwin.org
[root@localhost ~]# vim /etc/hosts
192.168.110.11 elk-n1 elk-n1.sevenwin.org
192.168.110.12 elk-n2 elk-n1.sevenwin.org
[root@localhost ~]# vim /etc/selinux/config      //关闭SELINUX,
SELINUX=permissive    
setenforce=0
[root@localhost ~]# vim /etc/security/limits.conf
*       soft    nofile  65536    //加到最后一行前
*       hard    nofile  131072
*       soft    nproc   4096
*       hard    nproc   8192
*       soft    memlock unlimited
*       hard    memlock unlimited
[root@localhost ~]# tar zxvf jdk-8u161-linux-x64.tar.gz 
[root@localhost ~]# mv jdk1.8.0_161/ /usr/local/jdk1.8.0
[root@localhost ~]# vim /etc/profile
export JAVA_HOME=/usr/local/jdk1.8.0
export CLASSPATH=./:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH
[root@localhost ~]# source /etc/profile
[root@localhost ~]# java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode) 
[root@localhost ~]# reboot
[root@elk-n2 ~]# rpm -ivh elasticsearch-7.6.0-x86_64.rpm
[root@elk-n2 ~]# mkdir -p /var/es-data
[root@elk-n2 ~]# chown -R elasticsearch:elasticsearch /var/es-data/
[root@elk-n2 ~]# chown -R elasticsearch:elasticsearch /var/log/elasticsearch/
[root@elk-n2 ~]# vim /etc/elasticsearch/elasticsearch.yml
cluster.name: my-elk
node.name: elk-n2
node.master: true
node.data: true
path.data: /var/es-data
path.logs: /var/log/elasticsearch
bootstrap.memory_lock: true
network.host: 0.0.0.0
http.port: 9200
cluster.initial_master_nodes: ["elk-n1"]
discovery.zen.ping.unicast.hosts: ["elk-n1", "elk-n2"]
http.cors.enabled: true
http.cors.allow-origin: "*
[root@elk-n2 ~]# systemctl stop firewalld.service
[root@elk-n2 ~]# setenforce 0
[root@elk-n2 ~]# vim /usr/lib/systemd/system/elasticsearch.service
LimitMEMLOCK=infinity
# Disable timeout logic and wait until process is stopped
[root@elk-n2 ~]# systemctl daemon-reload
[root@elk-n2 ~]# systemctl start elasticsearch.service

与第一台机器的uuid号需一致
在这里插入图片描述
3.在第一台虚拟机安装Head插件

[root@elk-n1 ~]# yum -y install epel-relese
[root@elk-n1 ~]# tar jxvf phantomjs-2.1.1-linux-x86_64.tar.bz2
[root@elk-n1 ~]# mv phantomjs-2.1.1-linux-x86_64 /usr/local/phantomjs
[root@elk-n1 ~]# ln -s /usr/local/phantomjs/bin/phantomjs /usr/bin
[root@elk-n1 ~]# phantomjs --version
2.1.1
[root@elk-n1 ~]# tar zxvf node-v13.8.0-linux-x64.tar.gz
[root@elk-n1 ~]# mv node-v13.8.0-linux-x64/ /usr/local/node13.8
[root@elk-n1 ~]# vim /etc/profile
export NODE_HOME=/usr/local/node13.8
export PATH=$PATH:$NODE_HOME/bin

在这里插入图片描述

[root@elk-n1 ~]# source /etc/profile
[root@elk-n1 ~]# yum -y install git
[root@elk-n1 ~]# git clone https://github.com/mobz/elasticsearch-head.git
[root@elk-n1 ~]# mv elasticsearch-head/ /opt
[root@elk-n1 ~]# cd /opt/elasticsearch-head/
[root@elk-n1 elasticsearch-head]# npm install -g grunt --registry=https://registry.npm.taobao.org
[root@elk-n1 elasticsearch-head]# npm config set registry=https://registry.npm.taobao.org
[root@elk-n1 elasticsearch-head]# npm install  //时间较长
[root@elk-n1 elasticsearch-head]# vim Gruntfile.js 

在这里插入图片描述

[root@elk-n1 elasticsearch-head]# vim _site/app.js

在这里插入图片描述

[root@elk-n1 elasticsearch-head]# ./node_modules/grunt/bin/grunt server &                       //或者npm run start &

在这里插入图片描述

3.在第一台虚拟机安装配置logstash

[root@elk-n1 ~]# rpm -ivh logstash-7.6.0.rpm 
[root@elk-n1 ~]# ln -s /etc/logstash/ /usr/share/logstash/config
[root@elk-n1 ~]# vim /etc/logstash/logstash.yml 
path.config: /etc/logstash/conf.d/*.conf
[root@elk-n1 ~]# /usr/share/logstash/bin/logstash -t 'input{stdin{}}output{stdout{codec=>rubydebug}}' //检测
[root@elk-n1 ~]# chmod a+r /var/log/messages
[root@elk-n1 ~]# vim /etc/logstash/conf.d/system.conf

输入图中内容

[root@elk-n1 ~]# systemctl enable logstash.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/logstash.service to /etc/systemd/system/logstash.service.
[root@elk-n1 ~]# systemctl enable logstash.service 
[root@elk-n1 ~]# systemctl start logstash.service   //如果没有出来系统配置文件使用下面的命令指定激活配置文件
[root@elk-n1 ~]# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/system.conf

在这里插入图片描述

4.在第一台虚拟机安装kibana

[root@elk-n1 ~]# rpm -ivh kibana-7.6.0-x86_64.rpm
[root@elk-n1 ~]# vim /etc/kibana/kibana.yml
server.port: 5601    //第2行 
server.host: "0.0.0.0"   //第7行
elasticsearch.hosts: ["http://127.0.0.1:9200"]   //第28行
kibana.index: ".kibana"  //第37行
[root@elk-n1 ~]# systemctl enable kibana
Created symlink from /etc/systemd/system/multi-user.target.wants/kibana.service to /etc/systemd/system/kibana.service.
[root@elk-n1 ~]# systemctl start kibana

4.在第一台虚拟机安装filebeat

[root@elk-n1 ~]# rpm -ivh filebeat-7.6.0-x86_64.rpm
[root@elk-n1 ~]# vim /etc/filebeat/filebeat.yml
output.elasticsearch:
  # Array of hosts to connect to.
  hosts: ["127.0.0.1:9200"]     第150行
 
setup.kibana:
 host: "127.0.0.1:5601"       第123行

[root@elk-n1 ~]# filebeat modules enable elasticsearch
[root@elk-n1 ~]# filebeat setup   //时间长
[root@elk-n1 ~]# systemctl start filebeat.service

在这里插入图片描述
在这里插入图片描述

5.在第二台虚拟机安装配置apache与logstash

[root@elk-n2 ~]# yum -y install httpd
[root@elk-n2 ~]# systemctl enable httpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@elk-n2 ~]# systemctl start httpd.service
[root@elk-n2 ~]# rpm -ivh logstash-7.6.0.rpm 
[root@elk-n2 ~]# ln -s /etc/logstash/ /usr/share/logstash/config
[root@elk-n2 ~]# vim /etc/logstash/logstash.yml
path.config: /etc/logstash/conf.d/*.conf
[root@elk-n2 ~]# vim /etc/logstash/conf.d/apache_access.conf

在这里插入图片描述

[root@elk-n2 ~]# vim /etc/logstash/conf.d/apache_error.conf

在这里插入图片描述

[root@elk-n2 ~]# chmod a+r /var/log/httpd/ -R
[root@elk-n2 ~]# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/apache_access.conf 
[root@elk-n2 ~]# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/apache_error.conf 
[root@elk-n2 ~]# systemctl enable logstash.service
[root@elk-n2 ~]# systemctl start logstash.service

在这里插入图片描述

6.在第一台虚拟机查看kibana

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值