Centos7下快速部署EFK服务具体方法

EFK是一套分布式日志服务解决方案,由各个组件构成。EFK分别是指:elasticsearch、filebeat、kibana。不过在真实的生产环境中,搭建日志服务可能还需要logstash来进行规制解析,使用kafka进行削峰填谷作为缓冲,本篇文章将为大家分享一下Centos7下快速部署EFK服务具体方法。

架构

EFK采用集中式的日志管理架构

elasticsearch:一个开源分布式搜索引擎,提供搜集、分析、存储数据三大功能。它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等。

kibana:可以为Logstash 、Beats和ElasticSearch提供友好的日志分析Web 界面,可以帮助汇总、分析和搜索重要数据日志。

filebeat:轻量级日志采集器。需要在每个应用服务器配置filebeat,来采集日志,并输出到elasticsearch。

基于Centos7系统一键部署EFK服务基于Centos7系统一键部署EFK服务

一键部署KIBANA脚本

function install_es7_el7()  
{
   echo ""
 echo -e "\033[33m****************************************************安装ElasticSearch 7.6.2*****************************************************\033[0m"  
 #action "********初始化JAVA环境********" /bin/true
 #install_jdk

 #下载包
   if [ -f /opt/elasticsearch-7.6.2-x86_64.rpm ] && [ -f /opt/elasticsearch-analysis-ik-7.6.2.zip ] ;then
       echo "*****存在ElasticSearch 7.6.2安装包,无需下载*****"
   else
     ping -c 4 artifacts.elastic.co >/dev/null 2>&1
     if [ $? -eq 0 ];then
       wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.6.2-x86_64.rpm -O /opt/elasticsearch-7.6.2-x86_64.rpm
       wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.6.2/elasticsearch-analysis-ik-7.6.2.zip  -O /opt/elasticsearch-analysis-ik-7.6.2.zip    
     else
       echo "please download ES7 package manual !"
       exit $?
     fi  
 fi

 #安装es7.6  
 action "********安装ElasticSearch 7.6.2服务********" /bin/true
 chmod u+x /opt/elasticsearch-7.6.2-x86_64.rpm && rpm -ivh /opt/elasticsearch-7.6.2-x86_64.rpm
 
 #建目录及授权
 mkdir -p $ES_HOME/data &&  mkdir -p $ES_HOME/log
 chown -R elasticsearch:elasticsearch $ES_HOME && chmod -R 755 $ES_HOME
 
 #修改ES配置文件
 cp /etc/elasticsearch/elasticsearch.yml /etc/elasticsearch/elasticsearch.yml_bak &>/dev/null  
cat > /etc/elasticsearch/elasticsearch.yml # 设定本机节点名 node.name: es_node # 设定集群主节点清单 cluster.initial_master_nodes: ["es_node"] path.data: ${ES_HOME}/data path.logs: ${ES_HOME}/log bootstrap.memory_lock: false bootstrap.system_call_filter: false # 允许从其它机器访问 network.host: 0.0.0.0 http.port: ${ES_PORT} discovery.zen.ping.unicast.hosts: ["${ES_IP}:${ES_PORT}"] EOF #安装分词器:ik-analyzer插件 #默认情况下,ES使用内置的标准分词器,对文本进行解析。但是对于中文,其会拆解为一个一个的汉字,最终失去了分词的意义,所以安装分词器:ik-analyzer插件 action "********安装ik-analyzer插件********" /bin/true mkdir -p /usr/share/elasticsearch/plugins/ik unzip /opt/elasticsearch-analysis-ik-7.6.2.zip -d /usr/share/elasticsearch/plugins/ik/ &>/dev/null  
 chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/plugins/ &&  chmod -R 755  /usr/share/elasticsearch/plugins/
 sleep 2
#在filebeat配置文件中为索引模板添加默认分词器属性。未来新创建的索引均引用此属性:#setup.template.settings:#  index.analysis.analyzer.default.type: "ik_max_word"#  index.analysis.analyzer.default_search.type: "ik_max_word"#setup.template.overwrite: true#在Linux终端中执行如下命令,为现有所有索引,设置默认分词器属性:#curl -X POST "172.16.20.143:9200/_all/_close"#curl -X PUT  -H'Content-Type: application/json' 'http://172.16.20.143:9200/_all/_settings?preserve_existing=true' -d '{#  "index.analysis.analyzer.default.type" : "ik_max_word",#  "index.analysis.analyzer.default_search.type" : "ik_max_word"#}'#curl -X POST "172.16.20.143:9200/_all/_open"


 #启动ES并初始化数据
 action "********启动es并初始化数据********" /bin/true
 systemctl daemon-reload && systemctl enable elasticsearch.service  
 systemctl restart elasticsearch.service
 es_version=`curl -XGET ${ES_IP}:${ES_PORT}`
 echo -e "\033[33m**************************************************完成ElasticSearch 7.6.2安装***************************************************\033[0m"
cat > /tmp/es7.log  ${ES_IP}
ES服务器端口:${ES_PORT}
ES数据目录: ${ES_HOME}/data
ES日志目录: ${ES_HOME}/log
ES详细信息: ${es_version}
EOF
 cat /tmp/es7.log
 echo -e "\e[1;31m 以上信息10秒后消失,保存在/tmp/es7.log文件下 \e[0m"
 echo -e "\033[33m************************************************************************************************************************\033[0m"
 echo ""
 sleep 10
}

基于Centos7系统一键部署EFK服务基于Centos7系统一键部署EFK服务

一键部署Elasticsearch脚本

function install_es7_el7()  
{
   echo ""
 echo -e "\033[33m****************************************************安装ElasticSearch 7.6.2*****************************************************\033[0m"  
 #action "********初始化JAVA环境********" /bin/true
 #install_jdk

 #下载包
   if [ -f /opt/elasticsearch-7.6.2-x86_64.rpm ] && [ -f /opt/elasticsearch-analysis-ik-7.6.2.zip ] ;then
       echo "*****存在ElasticSearch 7.6.2安装包,无需下载*****"
   else
     ping -c 4 artifacts.elastic.co >/dev/null 2>&1
     if [ $? -eq 0 ];then
       wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.6.2-x86_64.rpm -O /opt/elasticsearch-7.6.2-x86_64.rpm
       wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.6.2/elasticsearch-analysis-ik-7.6.2.zip  -O /opt/elasticsearch-analysis-ik-7.6.2.zip    
     else
       echo "please download ES7 package manual !"
       exit $?
     fi  
 fi

 #安装es7.6  
 action "********安装ElasticSearch 7.6.2服务********" /bin/true
 chmod u+x /opt/elasticsearch-7.6.2-x86_64.rpm && rpm -ivh /opt/elasticsearch-7.6.2-x86_64.rpm
 
 #建目录及授权
 mkdir -p $ES_HOME/data &&  mkdir -p $ES_HOME/log
 chown -R elasticsearch:elasticsearch $ES_HOME && chmod -R 755 $ES_HOME
 
 #修改ES配置文件
 cp /etc/elasticsearch/elasticsearch.yml /etc/elasticsearch/elasticsearch.yml_bak &>/dev/null  
cat > /etc/elasticsearch/elasticsearch.yml # 设定本机节点名 node.name: es_node # 设定集群主节点清单 cluster.initial_master_nodes: ["es_node"] path.data: ${ES_HOME}/data path.logs: ${ES_HOME}/log bootstrap.memory_lock: false bootstrap.system_call_filter: false # 允许从其它机器访问 network.host: 0.0.0.0 http.port: ${ES_PORT} discovery.zen.ping.unicast.hosts: ["${ES_IP}:${ES_PORT}"] EOF #安装分词器:ik-analyzer插件 #默认情况下,ES使用内置的标准分词器,对文本进行解析。但是对于中文,其会拆解为一个一个的汉字,最终失去了分词的意义,所以安装分词器:ik-analyzer插件 action "********安装ik-analyzer插件********" /bin/true mkdir -p /usr/share/elasticsearch/plugins/ik unzip /opt/elasticsearch-analysis-ik-7.6.2.zip -d /usr/share/elasticsearch/plugins/ik/ &>/dev/null  
 chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/plugins/ &&  chmod -R 755  /usr/share/elasticsearch/plugins/
 sleep 2
#在filebeat配置文件中为索引模板添加默认分词器属性。未来新创建的索引均引用此属性:#setup.template.settings:#  index.analysis.analyzer.default.type: "ik_max_word"#  index.analysis.analyzer.default_search.type: "ik_max_word"#setup.template.overwrite: true#在Linux终端中执行如下命令,为现有所有索引,设置默认分词器属性:#curl -X POST "172.16.20.143:9200/_all/_close"#curl -X PUT  -H'Content-Type: application/json' 'http://172.16.20.143:9200/_all/_settings?preserve_existing=true' -d '{#  "index.analysis.analyzer.default.type" : "ik_max_word",#  "index.analysis.analyzer.default_search.type" : "ik_max_word"#}'#curl -X POST "172.16.20.143:9200/_all/_open"


 #启动ES并初始化数据
 action "********启动es并初始化数据********" /bin/true
 systemctl daemon-reload && systemctl enable elasticsearch.service  
 systemctl restart elasticsearch.service
 es_version=`curl -XGET ${ES_IP}:${ES_PORT}`
 echo -e "\033[33m**************************************************完成ElasticSearch 7.6.2安装***************************************************\033[0m"
cat > /tmp/es7.log  ${ES_IP}
ES服务器端口:${ES_PORT}
ES数据目录: ${ES_HOME}/data
ES日志目录: ${ES_HOME}/log
ES详细信息: ${es_version}
EOF
 cat /tmp/es7.log
 echo -e "\e[1;31m 以上信息10秒后消失,保存在/tmp/es7.log文件下 \e[0m"
 echo -e "\033[33m************************************************************************************************************************\033[0m"
 echo ""
 sleep 10
}

基于Centos7系统一键部署EFK服务基于Centos7系统一键部署EFK服务

一键部署filebeat脚本

function install_filebeat7_el7()  
{
   echo ""
 echo -e "\033[33m****************************************************安装Filebeat 7.6.2*****************************************************\033[0m"  

 #下载包
   if [ -f /opt/filebeat-7.6.2-x86_64.rpm ] ;then
       echo "*****存在Filebeat 7.6.2安装包,无需下载*****"
   else
     ping -c 4 artifacts.elastic.co >/dev/null 2>&1
     if [ $? -eq 0 ];then
       wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.6.2-x86_64.rpm -O /opt/filebeat-7.6.2-x86_64.rpm
     else
       echo "please download Filebeat7.6 package manual !"
       exit $?
     fi  
 fi

 #安装filebeat7.6  
 action "********安装filebeat 7.6.2服务********" /bin/true
 chmod u+x /opt/filebeat-7.6.2-x86_64.rpm && rpm -ivh /opt/filebeat-7.6.2-x86_64.rpm
 
 #修改kibana配置文件
 cp /etc/filebeat/filebeat.yml /etc/filebeat/filebeat.yml_bak  
cat > /etc/filebeat/filebeat.yml type: log enabled: true paths: - /lcp_logs/*.log filebeat.config.modules: path: /etc/filebeat/modules.d/*.yml reload.enabled: false setup.template.settings: #number_of_shards 是数据分片数,默认为5,有时候设置为3 index.number_of_shards: 3 index.analysis.analyzer.default.type: "ik_max_word" index.analysis.analyzer.default_search.type: "ik_max_word" setup.template.overwrite: true setup.kibana: host: "${KIBANA_IP}:${KIBANA_PORT}" output.elasticsearch: hosts: ["${ES_IP}:${ES_PORT}"] ilm.enabled: true ilm.rollover_alias: "fsl_uat.prod1" ilm.pattern: "{now/d}-000001" processors: - add_host_metadata: ~ - add_cloud_metadata: ~ EOF #启动filebeat并初始化数据 action "********启动filebeat并初始化数据********" /bin/true systemctl daemon-reload && systemctl enable filebeat.service systemctl restart filebeat.service #nohup ./filebeat -e -c filebeat.yml >/dev/null 2>&1 &
 
 echo -e "\033[33m**************************************************完成Filebeat 7.6.2安装***************************************************\033[0m"
cat > /tmp/filebeat7.log ${KIBANA_IP}:${KIBANA_PORT}
filebeat配置elasticsearch: ${ES_IP}:${ES_PORT}
EOF
 cat /tmp/filebeat7.log
 echo -e "\e[1;31m 以上信息10秒后消失,保存在/tmp/filebeat7.log文件下 \e[0m"
 echo -e "\033[33m************************************************************************************************************************\033[0m"
 echo ""
 sleep 10
}

基于Centos7系统一键部署EFK服务基于Centos7系统一键部署EFK服务

文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/208061.html<

(1)
运维的头像运维
上一篇2025-04-08 20:11
下一篇 2025-04-08 20:12

相关推荐

  • 个人主题怎么制作?

    制作个人主题是一个将个人风格、兴趣或专业领域转化为视觉化或结构化内容的过程,无论是用于个人博客、作品集、社交媒体账号还是品牌形象,核心都是围绕“个人特色”展开,以下从定位、内容规划、视觉设计、技术实现四个维度,详细拆解制作个人主题的完整流程,明确主题定位:找到个人特色的核心主题定位是所有工作的起点,需要先回答……

    2025-11-20
    0
  • 社群营销管理关键是什么?

    社群营销的核心在于通过建立有温度、有价值、有归属感的社群,实现用户留存、转化和品牌传播,其管理需贯穿“目标定位-内容运营-用户互动-数据驱动-风险控制”全流程,以下从五个维度展开详细说明:明确社群定位与目标社群管理的首要任务是精准定位,需明确社群的核心价值(如行业交流、产品使用指导、兴趣分享等)、目标用户画像……

    2025-11-20
    0
  • 香港公司网站备案需要什么材料?

    香港公司进行网站备案是一个涉及多部门协调、流程相对严谨的过程,尤其需兼顾中国内地与香港两地的监管要求,由于香港公司注册地与中国内地不同,其网站若主要服务内地用户或使用内地服务器,需根据服务器位置、网站内容性质等,选择对应的备案路径(如工信部ICP备案或公安备案),以下从备案主体资格、流程步骤、材料准备、注意事项……

    2025-11-20
    0
  • 如何企业上云推广

    企业上云已成为数字化转型的核心战略,但推广过程中需结合行业特性、企业痛点与市场需求,构建系统性、多维度的推广体系,以下从市场定位、策略设计、执行落地及效果优化四个维度,详细拆解企业上云推广的实践路径,精准定位:明确目标企业与核心价值企业上云并非“一刀切”的方案,需先锁定目标客户群体,提炼差异化价值主张,客户分层……

    2025-11-20
    0
  • PS设计搜索框的实用技巧有哪些?

    在PS中设计一个美观且功能性的搜索框需要结合创意构思、视觉设计和用户体验考量,以下从设计思路、制作步骤、细节优化及交互预览等方面详细说明,帮助打造符合需求的搜索框,设计前的规划明确使用场景:根据网站或APP的整体风格确定搜索框的调性,例如极简风适合细线条和纯色,科技感适合渐变和发光效果,电商类则可能需要突出搜索……

    2025-11-20
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注