ELK线上搭建步骤

这是我参与更文挑战的第27天,活动详情查看: 更文挑战

? 直接盘,之前测试和线上安装过一版,区别线上和测试的配置不一样。

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.7.2.tar.gz
wget https://artifacts.elastic.co/downloads/kibana/kibana-6.7.2-linux-x86_64.tar.gz
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.7.2-linux-x86_64.tar.gz
wget https://artifacts.elastic.co/downloads/logstash/logstash-6.7.2.tar.gz
复制代码

// 可到网盘下载 pan.baidu.com/s/1cQ1RP75W… 9s64

tar -xzvf elasticsearch-6.7.2.tar.gz -C  /usr/local/
tar -xzvf kibana-6.7.2-linux-x86_64.tar.gz -C  /usr/local/
tar -xzvf filebeat-6.7.2-linux-x86_64.tar.gz -C  /usr/local/
tar -xzvf logstash-6.7.2.tar.gz -C  /usr/local/
复制代码

首先安装jdk环境
#############################################################

rpm -ivh jdk-8u202-linux-x64.rpm
pid="sed -i '/export JAVA_HOME/d' /etc/profile"
eval $pid
pid="sed -i '/export CLASSPATH/d' /etc/profile"
eval $pid
cat >> /etc/profile <<EOF
export JAVA_HOME=/usr/java/jdk1.8.0_152
export CLASSPATH=%JAVA_HOME%/lib:%JAVA_HOME%/jre/lib
export PATH=\$PATH:\$JAVA_HOME/bin
EOF
source /etc/profile
java -version
复制代码

#############################################################
给用户组的用户权限

groupadd elasticsearch
useradd elasticsearch -g elasticsearch
chown -R elasticsearch.elasticsearch /usr/local/elasticsearch-6.7.2
chown -R elasticsearch.elasticsearch /usr/local/kibana-6.7.2-linux-x86_64/config
chown -R elasticsearch.elasticsearch /usr/local/filebeat-6.7.2-linux-x86_64
hostnamectl set-hostname elk-server
systemctl stop firewalld.service
systemctl disable firewalld.service
复制代码
cat >> /etc/security/limits.conf << EOF
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
EOF

cat >> /etc/sysctl.conf << EOF
vm.max_map_count=655360 
EOF

sysctl -p
复制代码
su - elasticsearch
/usr/local/elasticsearch-6.7.2/bin/elasticsearch -d   // 启动elasticsearch
vim /usr/local/elasticsearch-6.7.2/config/elasticsearch.yml   修改network:0.0.0.0
curl http://127.0.0.1:9200

vi /usr/local/logstash-6.7.2/config/logstash.yml
复制代码

需要root创建给elasticsearch用户权限
#################################################

path.data: /data/logstash/data
path.logs: /data/logstash/logs
复制代码

#################################################

vi /usr/local/logstash-6.7.2/default.conf
复制代码

#################################################

input {
  beats {
    host => "192.168.244.200"
    port => 5044
    codec => plain {
          charset => "UTF-8"
    }
  }
}

output {
  elasticsearch {
    hosts => "127.0.0.1:9200"
    manage_template => false
    index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"
    document_type => "%{[@metadata][type]}"
  }
}
复制代码

##########################################

vi /usr/local/logstash-6.7.2/config/jvm.options       # 修改jvm内存 1g
vi /usr/local/elasticsearch-6.7.2/config/jvm.options  # 修改jvm内存 1g
复制代码

// 启动logstash

nohup /usr/local/logstash-6.7.2/bin/logstash -f /usr/local/logstash-6.7.2/default.conf --config.reload.automatic > logstash.log 2>&1 &
复制代码
vi /usr/local/kibana-6.7.2-linux-x86_64/config/kibana.yml
复制代码

############################################

server.port: 5601
server.host: "192.168.2.207"  云服务器0.0.0.0
elasticsearch.url: "http://localhost:9200"
复制代码

############################################

// 启动kibana

nohup /usr/local/kibana-6.7.2-linux-x86_64/bin/kibana > kibana.log 2>&1 &
复制代码

// 通过filebeat收集日志,发送到logstash

vi /usr/local/filebeat-6.7.2-linux-x86_64/filebeat.yml
复制代码

############################################

filebeat.prospectors:
- type: log
  enabled: true
  paths:
    - /var/log/*.log
output.logstash:
  hosts: ["localhost:5044"]
复制代码

注释掉output.elasticsearch

############################################ 启动 filebeat

nohup /usr/local/filebeat-6.7.2-linux-x86_64/filebeat -e -c /usr/local/filebeat-6.7.2-linux-x86_64/filebeat.yml -d "publish" > filebeat.log 2>&1 &
复制代码

最后,多看看su – elasticsearch里面的3个日志报错。

  • 一般没出日志都是filebeat没配置好logstash,或是elsasearch、logstash状态有问题,或是配置文件错误导致
  • 一般日志找不到有可能是时间戳无法分隔的问题
  • Docker目录位置:- /var/new_lib/docker/containers//-json.log
  • 服务器时间与真实时间不一致

时间修正:root 用户

#######################

yum install -y ntpdate
yes | cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
ntpdate us.pool.ntp.org
crontab -l >/tmp/crontab.bak
echo "*/10 * * * * /usr/sbin/ntpdate us.pool.ntp.org | logger -t NTP" >> /tmp/crontab.bak
crontab /tmp/crontab.bak
复制代码

#######################

参考

真心感谢帅逼靓女们能看到这里,如果这个文章写得还不错,觉得有点东西的话

求点赞? 求关注❤️ 求分享? 对8块腹肌的我来说真的 非常有用!!!

如果本篇博客有任何错误,请批评指教,不胜感激 !❤️❤️❤️❤️

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享