当前位置: 首页 > 科技观察

如何在UbuntuServer20.04上部署Elasticsearch集群?_0

时间:2023-03-19 18:21:17 科技观察

【.com速译】Elasticsearch是一个非常强大的搜索分析引擎,具有很强的扩展性。有了这个工具,您就有了可视化大量数据的基础。但是当您开始扩展Elasticsearch以满足大数据的需求时,您需要使用不止一台服务器。在扩展以满足企业需求时,单个服务器可能会遇到大量数据。所以你会怎么做?您可以部署一个Elasticsearch服务器集群。我会告诉你如何做到这一点。部署后,您就具备了开始构建能够处理大量数据的令人难以置信的数据可视化工具的必要技能。你需要什么?我将在UbuntuServer20.04的两个实例上对此进行演示,但您可以根据需要将其部署到尽可能大的集群。除了两个UbuntuServer实例之外,还需要一个具有sudo权限的用户。就是这样。不妨部署它。如何安装Java?您至少需要在每台服务器上安装Java8,因此我们将使用以下命令安装默认的JRE:sudoapt-getinstalldefault-jre-y在两台测试机器上都安装好之后,安装Elasticsearch就完成了。如何安装Elasticsearch?这需要在两台机器上完成。首先安装ElasticsearchGPG密钥:wget-qO-https://artifacts.elastic.co/GPG-KEY-elasticsearch|sudoapt-keyadd-接下来,安装apt-transport-https:sudoapt-getinstallapt-transport-https添加必要的存储库,命令:echo"debhttps://artifacts.elastic.co/packages/6.x/aptstablemain"|sudotree-a/etc/apt/sources.list.d/elastic-6.x.list最后,更新apt并安装Elasticsearch:sudoapt-getupdatesudoapt-getinstallelasticsearch-y运行并启用Elasticsearch:sudosystemctlstartelasticsearchsudosystemctlenableelasticsearch如何配置Elasticsearch?您将在两台服务器上执行此操作,请务必更改配置以适合每台机器。我们称第一台机器为controller-1,第二台机器为node-1。使用以下命令打开配置文件:sudonano/etc/elasticsearch/elasticsearch.yml在此文件中,您需要编辑以下行。其中一些行将被注释掉,因此您需要先删除前导#字符。要编辑的行是(粗体应根据需要进行编辑):cluster.name:elkclusternode.name:"controller-1"network.host:192.168.1.80http.port:9200discovery.zen。ping.unicast.hosts:["192.168.1.80","192.168.1.81"]本例中控制器使用192.168.1.80,节点使用192.168.1.81。保存并关闭文件。在两台机器上重启Elasticsearch:sudosystemctlrestartelasticsearch如何测试集群?您需要给Elasticsearch几分钟的时间来启动。您可以使用以下命令对其进行测试:curl-XGET'http://192.168.1.80:9200/_cluster/state?pretty'确保根据您的控制器或节点编辑上述IP地址。如果您正在测试控制器,请使用控制器IP;如果测试节点,请使用节点IP。当Elasticsearch最终运行时,您应该会看到一些输出结果,包括以下内容:{"cluster_name":"monkeypantz","cluster_uuid":"rGzNNmm_Rteel0Xg3xqw9w","version":6,"state_uuid":"WVx5O6Q7SfOqZf_wxaPOKQ","master_node":"2NI9_pDYS1WvJYQz-XY3KQ","blocks":{},"nodes":{"yV2TBoxVTvKbh7E1ZngpbA":{"name":"node-1","ephemeral_id":"pkb3vapLTd2yFLrXO64ENA","transport_address":"192.168.1.81:9300","attributes":{"ml.machine_memory":"3137888256","ml.max_open_jobs":"20","xpack.installed":"true","ml.enabled":"true"一旦控制器和节点启动并运行,使用以下命令测试集群:curl-XGET'192.168.1.80:9200/_cluster/health?pretty'确保编辑IP地址以匹配您所在的机器从IP地址匹配运行命令。输出应包括以下内容:{"cluster_name":"monkeypantz","status":"green","timed_out":false,"number_of_nodes":2,"number_of_data_nodes":2,"active_primary_shards":0,"active_shards":0,"relocating_shards":0,"initializing_shards":0,"unassigned_shards":0,"delayed_unassigned_shards":0,"number_of_pending_tasks":0,"number_of_in_flight_fetch":0,"task_max_waiting_in_queue_millis":0,"active_shards_number0_perber}要注意的重要行是:“status”:“green”,“timed_out”:false,“number_of_nodes”:2,“number_of_data_nodes”:2,您还可以从控制器使用以下命令(在控制器上运行)查看节点:curl-XGET'192.168.1.81:9200/_nodes/?pretty请务必将上面的IP地址替换为Elasticsearch节点的IP地址,也可以将浏览器指向http://SERVER:9200(其中服务器是您的控制器的IP地址),您应该会看到类似于图A的输出。图A.Elasticsearch集群启动并运行恭喜,您现在拥有了一个功能正常的Elasticsearch集群已准备好供您的开发人员可视化数据。原标题:如何在UbuntuServer20.04上部署Elasticsearch集群,作者:JackWallen