ELK自动部署脚本-创新互联

ELK自动安装脚本

专注于为中小企业提供成都做网站、网站设计服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业北川羌族免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了上千企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

一、简介

ELK由Elasticsearch、Logstash和Kibana三部分组件组成;

Elasticsearch是个开源分布式搜索引擎,它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等。

Logstash是一个完全开源的工具,它可以对你的日志进行收集、分析,并将其存储供以后使用

kibana 是一个开源和免费的工具,它可以为 Logstash 和 ElasticSearch 提供的日志分析友好的 Web 界面,可以帮助您汇总、分析和搜索重要数据日志。

二、核心组件

Logstash: logstash server端用来搜集日志;

Elasticsearch: 存储各类日志;

Kibana: web化接口用作查寻和可视化日志;

Filebeat是一个日志文件托运工具,在你的服务器上安装客户端后,filebeat会监控日志目录或者指定的日志文件,追踪读取这些文件(追踪文件的变化,不停的读),并且转发这些信息到elasticsearch或者logstarsh中存放。

三、安装脚本

注意:vim /etc/hosts 添加ip及主机名; 注意:服务器的内存如果服务器内存低的话会导致elasticsearch启动不了;

自定义shell脚本名称 vim Autoinstall_ELK_V1.3.sh 复制粘贴一下内容执行。

#!/bin/bash #mail:lishilong@co-mall.com #data:2019/1/9 #AutoInstall ELK scripts #Software:elasticsearch-5.4.1/logstash-5.4.1/filebeat-5.4.1/kibana-5.4.1 clear echo "#############################################################################" echo "#            Auto Install ELK.                 ##"     echo "#            Press Ctrl+C to cancel                  ##"     echo "#            Any key to continue               ##"    echo "# Softwae:elasticsearch-5.4.1/logstash-5.4.1/filebeat-5.4.1/kibana-5.4.1  ##" echo "#############################################################################" read -n 1 software_dir="/usr/local/software" elasticsearch_url="https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.4.1.tar.gz" kibana_url="https://artifacts.elastic.co/downloads/kibana/kibana-5.4.1-linux-x86_64.tar.gz" logstash_url="https://artifacts.elastic.co/downloads/logstash/logstash-5.4.1.tar.gz" filebeat_url="https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-5.4.1-linux-x86_64.tar.gz" sys_version=`cat /etc/redhat-release |awk '{print $4}'|cut -d. -f1` IP=`ip addr|grep "inet "|grep -v 127.0.0.1|awk '{print $2}'|cut -d/ -f1` jvm_conf="/usr/local/elasticsearch/config/jvm.options" sys_mem=`free -m|grep Mem:|awk '{print $2}'|awk '{sum+=$1} END {print sum/1024}'|cut -d. -f1` #wget software wget_fun() { if [ ! -d ${software_dir} ];then     mkdir -p ${software_dir} && cd ${software_dir} else     cd ${software_dir} fi for software in $elasticsearch_url $kibana_url $logstash_url $filebeat_url do     wget -c $software done clear } #initial system:install java wget;set hostname;disable firewalld init_sys() { [ -f /etc/init.d/functions ] && . /etc/init.d/functions [ "${sys_version}" != "7" ] && echo "Error:This Scripts Support Centos7.xx" && exit 1 [ $(id -u) != "0" ] && echo "Error: You must be root to run this script" && exit 1 sed -i "s/SELINUX=enforcing/SELINUX=disabled/"  /etc/selinux/config setenforce 0 yum install -y java-1.8.0-openjdk wget hostnamectl set-hostname elk-server           systemctl stop firewalld cat >>/etc/security/limits.conf<>/etc/sysctl.conf && sysctl -p if [ ${sys_mem} -eq 0 ];then     sed -i "s#`grep "^-Xmx" ${jvm_conf}`#"-Xmx512m"#g" ${jvm_conf}     sed -i "s#`grep "^-Xms" ${jvm_conf}`#"-Xms512m"#g" ${jvm_conf} else     sed -i "s#`grep "^-Xmx" ${jvm_conf}`#"-Xmx${sys_mem}g"#g" ${jvm_conf}     sed -i "s#`grep "^-Xms" ${jvm_conf}`#"-Xms${sys_mem}g"#g" ${jvm_conf} fi cat >>/usr/local/elasticsearch/config/elasticsearch.yml</usr/local/logstash/config/01-syslog.conf< "5044"         }     } output {     elasticsearch {         hosts => "127.0.0.1:9200"     }     stdout { codec => rubydebug } } EOF nohup /usr/local/logstash/bin/logstash -f /usr/local/logstash/config/01-syslog.conf & >/dev/null } #install filebeat install_filebeat() { cd $software_dir tar -zxf filebeat-5.4.1-linux-x86_64.tar.gz mv filebeat-5.4.1-linux-x86_64 /usr/local/filebeat cat >/usr/local/filebeat/filebeat.yml</dev/null } #install kibana install_kibana() { cd $software_dir tar -zxf kibana-5.4.1-linux-x86_64.tar.gz mv kibana-5.4.1-linux-x86_64 /usr/local/kibana cat >> /usr/local/kibana/config/kibana.yml </dev/null } check() { port=$1 program=$2 check_port=`netstat -lntup|grep ${port}|wc -l` check_program=`ps -ef|grep ${program}|grep -v grep|wc -l` if [ $check_port -gt 0 ] && [ $check_program -gt 0 ];then         action "${program} run is ok!" /bin/true else         action "${program} run is error!" /bin/false fi } main() { init_sys wget_fun install_elasticsearch install_filebeat install_logstash install_kibana echo -e "\033[32m Checking Elasticsearch...\033[0m" sleep 20 check :9200 "elasticsearch" echo -e "\033[32m Checking Logstash...\033[0m" sleep 2 check ":9600" "logstash" echo -e "\033[32m Checking Kibana...\033[0m" sleep 2 check ":5601" "kibana" action "ELK install is success!" /bin/true echo "url:http://$IP:5601" } main

四、脚本安装

ELK自动部署脚本

安装完成访问:http://IP:5601即可访问;

五、配置

通过web界面访问,创建index patterns;

六、查看日志与dashboard

ELK自动部署脚本 ELK自动部署脚本

配置完成!当你发现你的才华与目标相差甚远的时候,不如安心的好好学习!

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网站题目:ELK自动部署脚本-创新互联
本文链接:http://myzitong.com/article/dipcig.html