在本地主机以外启动Elasticsearch的方法是什么?
我是Qiita的新手,请多关照。
本文描述了在将Elasticsearch绑定到非localhost时的配置方法。在非localhost上启动时,启动时的检查比在localhost上严格。本文除了描述在localhost上的配置外,还描述了必要的配置方法。
环境
我的环境如下:
-
- Elasticsearch 7.3.2
- ubuntu 18.04.1
在本地主机以外进行绑定
举个例子,如果您想指定接口,可以按照以下方式进行指定。
network.host: [_<インターフェース名>_,_local_]
如果通过.tar.gz解压,elasticsearch.yml文件将位于config/文件夹中;如果通过apt等进行安装,则位于/etc/elasticsearch/ 中。
如果要使用IP地址进行指定,可以按如下方式指定。如果希望从任何接口都能够访问Elasticsearch,则可以使用0.0.0.0。但是,出于安全原因,不推荐这种方法。
network.host: 192.168.1.xx
请参考以下链接:https://www.elastic.co/zh-cn/guide/en/elasticsearch/reference/current/network.host.html
选择主节点
在Elasticsearch中,可以在多台计算机(节点)上共享数据。对应的,有一个指定主节点的选项,但如果在localhost以外的地址进行绑定时,如果未进行该设置,则会出现以下错误。
the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
如果只在一个节点上执行。
输入以下设置将会启动一个单独的节点,从而避免关于主节点的启动错误。
discovery.type: single-node
(https://www.elastic.co/guide/en/elasticsearch/reference/current/bootstrap-checks.html#single-node-discovery 参考)
如果计划安装多个节点
如果计划安装多个节点,请按以下方式进行设置。
cluster.initial_master_nodes: ["node-1"]
同时,我还会指定正在进行设置的Elasticsaerch节点的名称。
node.name: node-1
请查看以下链接获取详细信息:https://www.elastic.co/guide/en/elasticsearch/reference/7.6/discovery-settings.html
如果通过rpm或者apt进行安装,则无需设置虚拟内存。
如果不进行增加虚拟内存的设置,则会出现以下错误。
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
可以通过以下命令来增加虚拟内存设置。需要在root用户下执行。
sudo sysctl -w vm.max_map_count=262144
(参考来源:https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html)
如果您是通过rpm或apt等方式进行安装,您无需更改页面大小。
如果不将文件描述符更改为65535,则无法启动。输入以下命令即可启动。请注意,如果在使用ulimit指定后输入exit退出,ulimit的更改将被还原,导致elasticsearch无法启动。
sudo su
ulimit -n 65535
su <ユーザ名>
./elasticsearch #Elasticsearchをこのションで起動
如果不进行此设置,将会输出以下错误。
max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
请参考以下网站
重要的系统配置 – Elasticsearch 参考
https://www.elastic.co/guide/en/elasticsearch/reference/current/system-config.html