Elasticstack,俗称ELKstack,是包括Elasticsearch、Logstash和Kibana在内的一套开源产品。ElasticStack由ElasticCorporation开发和维护。使用Elasticstack,可以将系统日志发送到Logstash,这是一个数据收集引擎,可以从可能的任何来源接受日志或数据,规范化日志,并将日志转发到Elasticsearch进行分析、索引、搜索和存储,表示为使用Kibana可视化数据,使用Kibana我们还可以创建基于用户查询的交互式图表。在本文中,我们将演示如何在RHEL8/CentOS8服务器上设置多节点弹性堆栈集群。以下是我的ElasticStack集群的详细信息:Elasticsearch:三台服务器,最小安装RHEL8/CentOS8IP和主机名–192.168.56.40(elasticsearch1.linuxtechi.local)、192.168.56.50(elasticsearch2.linuxtechi.local)、192.168。56.60(elasticsearch3.linuxtechi.local`)Logstash:两台服务器,最小RHEL8/CentOS8IP和主机–192.168.56.20(logstash1.linuxtechi.local),192.168.56.30(logstash2.linuxtechi.local)Kibana:一台服务器,最小安装RHEL8/CentOS8IP和主机名–192.168.56.10(kibana.linuxtechi.local)Filebeat:一台服务器,最小安装CentOS7IP和主机名–192.168.56.70(web-server)让我们从设置Elasticsearch集群开始,如前所述,设置一个3节点Elasticsearch集群,设置Elasticsearch集群的节点,登录到每个节点,设置主机名并配置yum/dnf存储库。使用命令hostnamectl在每个节点上设置主机名:[root@linuxtechi~]#hostnamectlset-hostname"elasticsearch1.linuxtechi.local"[root@linuxtechi~]#execbash[root@linuxtechi~]#[root@linuxtechi~]#[root@linuxtechi~]]#hostnamectlset-hostname"elasticsearch2.linuxtechi.local"[root@linuxtechi~]#execbash[root@linuxtechi~]#[root@linuxtechi~]#hostnamectlset-hostname"elasticsearch3.linuxtechi.local[root@linuxtechi~]#execbash[root@linuxtechi~]#对于CentOS8系统,我们不需要配置任何操作系统包仓库,对于RHEL8服务器,如果你有有效的订阅,然后订阅RedHat以获得软件包存储库OK。如果要为OS包配置本地yum/dnf存储库,请参考以下网址:如何使用DVD或ISO文件在RHEL8服务器上设置本地Yum/DNF存储库在所有服务器上配置Elasticsearch包存储库nodesat/在etc/yum.repo.d/文件夹中创建一个elastic.repo文件,内容如下:~]#vi/etc/yum.repos.d/elastic.repo[elasticsearch-7.x]name=7.x包的Elasticsearch存储库baseurl=https://artifacts.elastic.co/packages/7.x/yumgpgcheck=1gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearchenabled=1autorefresh=1type=rpm-md保存文件并退出。在所有三个节点上使用rpm命令导入Elastic公共签名密钥。~]#rpm--importhttps://artifacts.elastic.co/GPG-KEY-elasticsearch在所有三个节点的/etc/hosts文件中添加以下行:192.168.56.40elasticsearch1.linuxtechi.local192.168.56.50elasticsearch2.linuxtechi.local192.168.56.60elasticsearch3.linuxtechi.local使用yum/dnf命令在所有三个节点上安装Java:[root@linuxtechi~]#dnfinstalljava-openjdk-y[root@linuxtechi~]#dnfinstalljava-openjdk-y[root@linuxtechi~]#dnfinstalljava-openjdk-y使用yum/dnf命令在所有三个节点上安装Elasticsearch:[root@linuxtechi~]#dnfinstallelasticsearch-y[root@linuxtechi~]#dnfinstallelasticsearch-y[root@linuxtechi~]#dnfinstallelasticsearch-y注意:如果每个Elasticsearch节点都启用并运行了OS防火墙,使用firewall-cmd命令允许打开以下端口:~]#firewall-cmd--permanent--add-port=9300/tcp~]#firewall-cmd--permanent--add-port=9200/tcp~]#firewall-cmd--reload在所有节点上配置ElasticsearchE编辑文件/etc/elasticsearch/elasticsearch.yml并添加以下内容:~]#vim/etc/elasticsearch/elasticsearch.ymlcluster.name:opn-clusternode.name:elasticsearch1.linuxtechi.localnetwork.host:192.168.56.40http.port:9200discovery.seed_hosts:[“elasticsearch1.linuxtechi.local”,“elasticsearch2.linuxtechi.local”,“elasticsearch3.linuxtechi.local”]集群。initial_master_nodes:["elasticsearch1.linuxtechi.local","elasticsearch2.linuxtechi.local","elasticsearch3.linuxtechi.local"]注意:在每个节点上,node.name填写正确的主机名,network.host填写IP地址正确,其他参数不变现在使用systemctl命令在所有三个节点上启动并启用Elasticsearch服务:~]#systemctldaemon-reload~]#systemctlenableelasticsearch.service~]#systemctlstartelasticsearch.service使用以下ss命令验证elasticsearch节点开始监听9200端口:[root@linuxtechi~]#ss-tunlp|grep9200tcpLISTEN0128[::ffff:192.168.56.40]:9200*:*users:(("java",pid=2734,fd=256))[root@linuxtechi~]#使用如下curl命令验证Elasticsearch集群状态:[root@linuxtechi~]#curlhttp://elasticsearch1.linuxtechi.local:9200[root@linuxtechi~]#curl-XGEThttp://elasticsearch2.linuxtechi.local:9200的输出/_cluster/health?pretty命令如下:Elasticsearch-cluster-status-rhel8上面的输出说明我们已经成功创建了一个3节点的Elasticsearch集群,集群的状态也是绿色的。注意:如果要修改JVM堆大小,则可以编辑文件/etc/elasticsearch/jvm.options并根据您的环境更改以下参数:-Xms1g-Xmx1g现在让我们转到Logstash节点。要安装和配置Logstash,请在两个Logstash节点上执行以下步骤。登录两个节点,使用hostnamectl命令设置主机名:[root@linuxtechi~]#hostnamectlset-hostname"logstash1.linuxtechi.local"[root@linuxtechi~]#execbash[root@linuxtechi~]#[root@linuxtechi~]#[root@linuxtechi~]#hostnamectlset-hostname"logstash2.linuxtechi.local"[root@linuxtechi~]#execbash[root@linuxtechi~]#在/etc/两个logstash节点的hosts文件:~]#vi/etc/hosts192.168.56.40elasticsearch1.linuxtechi.local192.168.56.50elasticsearch2.linuxtechi.local192.168.56.60elasticsearch3.linuxtechi.local保存文件并退出。在两个节点上配置Logstash存储库,在/ete/yum.repo.d/文件夹下创建文件logstash.repo,内容如下:~]#vi/etc/yum.repos.d/logstash.repo[elasticsearch-7.x]name=7.x包的Elasticsearch存储库baseurl=https://artifacts.elastic.co/packages/7.x/yumgpgcheck=1gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearchenabled=1autorefresh=1type=rpm-md保存退出文件,运行rpm命令导入签名密钥:~]#rpm--importhttps://artifacts.elastic.co/GPG-KEY-elasticsearch使用yum/dnf命令在两个节点上安装JavaOpenJDK:~]#dnfinstalljava-openjdk-y从两个节点运行yum/dnf命令以安装logstash:[root@linuxtechi~]#dnfinstalllogstash-y[root@linuxtechi~]#dnfinstalllogstash-y现在配置logstash,在两个logstash节点上执行以下步骤,创建一个logstash配置文件,首先我们将logstash示例文件复制到/etc/logstash/conf.d/下:#cd/etc/logstash/#cplogstash-sample.confconf.d/logstash.conf编辑配置文件并更新以下内容:#viconf.d/logstash.confinput{beats{port=>5044}}output{elasticsearch{hosts=>["http://elasticsearch1.linuxtechi.local:9200","http://elasticsearch2.linuxtechi.local:9200","http://elasticsearch3.linuxtechi.local:9200"]index=>"%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"#user=>"elastic"#password=>"changeme"}}在输出部分下,在hosts参数中指定所有三个Elasticsearch节点的FQDN,其他参数保持不变使用firewall-cmd命令在操作系统防火墙中允许logstash端口“5044”:~#firewall-cmd--permanent--add-port=5044/tcp~#firewall-cmd--reload现在,在每个节点上运行以下命令systemctl命令启动并启用Logstash服务:~]#systemctlstartlogstash~]#systemctleanblelogstash使用ss命令验证logstash服务是否监听5044端口:[root@linuxtechi~]#ss-tunlp|grep5044tcpLISTEN0128*:5044*:*users:(("java",pid=2416,fd=96))[root@linuxtechi~]#以上输出说明logstash已经安装配置成功,我们继续到Kibana安装。安装配置Kibana登录Kibana节点,使用hostnamectl命令设置主机名:[root@linuxtechi~]#hostnamectlset-hostname"kibana.linuxtechi.local"[root@linuxtechi~]#execbash[root@linuxtechi~]#编辑/etc/hosts文件并添加以下行:192.168.56.40elasticsearch1.linuxtechi.local192.168.56.50elasticsearch2.linuxtechi.local192.168.56.60elasticsearch3.linuxtechi.local设置Kibana存储库以下命令:[root@linuxtechi~]#vi/etc/yum.repos.d/kibana.repo[elasticsearch-7.x]name=Elasticsearchrepositoryfor7.xpackagesbaseurl=https://artifacts.elastic.co/packages/7.x/yumgpgcheck=1gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearchenabled=1autorefresh=1type=rpm-md[root@linuxtechi~]#rpm--importhttps://artifacts.elastic.co/GPG-KEY-elasticsearch执行yum/dnf命令安装kibana:[root@linuxtechi~]#yuminstallkibana-y通过编辑/etc/kibana/kibana.yml文件配置Kibana:[root@Linux科技~]#vim/etc/kibana/kibana.yml…………server.host:“kibana.linuxtechi.local"server.name:"kibana.linuxtechi.local"elasticsearch.hosts:["http://elasticsearch1.linuxtechi.local:9200","http://elasticsearch2.linuxtechi.local:9200","http://elasticsearch3.linuxtechi.local:9200"]…………启用并启动kibana服务:[root@linuxtechi~]#systemctlstartkibana[root@linuxtechi~]#systemctlenablekibanaAllowKibanaportonthesystemfirewall”5601":[root@linuxtechi~]#firewall-cmd--permanent--add-port=5601/tcpsuccess[root@linuxtechi~]#firewall-cmd--reloadsuccess[root@linuxtechi~]#使用以下网址访问KibanaInterface:http://kibana.linuxtechi.local:5601Kibana-Dashboard-rhel8从面板中我们可以查看ElasticStack集群的状态Stack-Monitoring-Overview-RHEL8这证明我们已经在RHEL8上安装成功/CentOS8并搭建多节点ElasticStack集群。现在让我们通过filebeat从其他Linux服务器发送一些日志到logstash节点。就我而言,我有一台CentOS7服务器。我会把这个服务器的所有重要日志通过filebeatPush到logstash。登录CentOS7服务器,使用yum/rpm命令安装filebeat包:[root@linuxtechi~]#rpm-ivhhttps://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.3。1-x86_64.rpm正在检索https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.3.1-x86_64.rpmPreparing...##################################[100%]正在更新/安装...1:filebeat-7.3.1-1###################################[100%][root@linuxtechi~]#编辑/etc/hosts文件,添加如下内容:192.168.56.20logstash1.linuxtechi.local192.168.56.30logstash2.linuxtechi。local现在配置filebeat,使其可以使用负载均衡技术将日志发送到logstash节点,编辑文件/etc/filebeat/filebeat.yml,添加如下参数:在filebeat.inputs:部分将enabled:false改为enabled:true,并在paths参数下指定我们可以发送到logstash的日志文件的位置;注释掉output.elasticsearch和host参数;删除output.logstash:和hosts:的注释,在hosts参数中添加两个logstash节点,并设置loadbalance:true。[root@linuxtechi~]#vi/etc/filebeat/filebeat.ymlfilebeat.inputs:-type:logenabled:truepaths:-/var/log/messages-/var/log/dmesg-/var/log/maillog-/var/log/boot.log#output.elasticsearch:#hosts:["localhost:9200"]output.logstash:hosts:["logstash1.linuxtechi.local:5044","logstash2.linuxtechi.local:5044"]loadbalance:true使用以下2个systemctl命令启动并启用filebeat服务:[root@linuxtechi~]#systemctlstartfilebeat[root@linuxtechi~]#systemctlenablefilebeat现在转到KibanaUI并验证新索引是否可见.从左侧栏中选择管理选项,然后单击Elasticsearch下的索引管理:Elasticsearch-index-management-Kibana正如我们在上面看到的,索引现在是可见的,现在让我们创建索引模型。点击Kibana部分的“IndexPatterns”,会提示我们创建一个新模型,点击“CreateIndexPattern”,指定模式名称为“filebeat”:Define-Index-Pattern-Kibana-RHEL8点击Next。选择“Timestamp”作为索引模式的时间过滤器,然后点击“创建索引模式”:Time-Filter-Index-Pattern-Kibana-RHEL8filebeat-index-pattern-overview-Kibana现在点击查看实时filebeat索引模式:Discover-Kibana-REHL8这说明Filebeatagent已经配置成功,我们可以在Kibanadashboard上看到实时日志。这就是本文的全部内容,请不要犹豫,分享您对这些帮助您在RHEL8/CentOS8系统上设置ElasticStack集群的步骤的反馈和意见。
