我们去官网https://www.elastic.co/cn/elasticsearch/下载最新版本的软件包并解压软件包。
然后启动运行elasticsearch
./bin/elasticsearch
首先会报一个错误:
[ERROR][o.e.b.Bootstrap] [01] Exception java.lang.RuntimeException: can not run elasticsearch as root
这是因为我们不能以root用户进行运行导致的。我们只需新增一个用户赋予新用户启动elasticsearch的权限即可。
useradd esuser passwd esuser //先移动elasticsearch到usr/local/elasticsearch下 mv elasticsearch usr/local/elasticsearch //然后进行赋权 chown -R esuser:esuser usr/local/elasticsearch //之后切换到新建用户进行启动即可 su esuser ./usr/local/elasticsearch/bin/elasticsearch
启动报错,内容如下:
ERROR: [3] bootstrap checks failed. You must address the points described in the following [3] lines before starting Elasticsearch. bootstrap check failure [1] of [3]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535] bootstrap check failure [2] of [3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] bootstrap check failure [3] of [3]: 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 ERROR: Elasticsearch did not exit normally - check the logs at /opt/elasticsearch/logs/elasticsearch.log
大致是说我们3个配置没有做,也对,刚下载解压后直接运行,肯定会有很多问题:
- bootstrap check failure 1 of [3]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
这个是说ElasticSearch进程的最大文件描述大小需要65535,而当前是4096,解决办法是修改 /etc/security/limits.conf 文件,在末尾加上(存在则修改,数值不能比要求的小):
* soft nofile 65535 * hard nofile 65535 * soft nproc 65535 * hard nproc 65535
如果limits.conf文件无法修改,可尝试修改文件权限之后再次修改,如还是不行,则可进行临时修改。命令如下:
ulimit -n 65535 //临时修改最大打开文件数 ulimit -Hn 4096 //临时修改最大进程数
- bootstrap check failure [2] of [3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
这是说最大虚拟内存太小(vm.max_map_count配置),至少需要262144,当前为65530,解决办法是修改 /etc/sysctl.conf 文件,在末尾加上(存在则修改,数值不能比要求的小):
vm.max_map_count=262144 //随后执行以下命令,立即生效 /sbin/sysctl -p
- bootstrap check failure [3] of [3]: 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
这是说我们没有对ElasticSearch发现进行配置,至少需要配置discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes中的一个:
- discovery.seed_hosts:集群节点列表,每个值应采用host:port或host的形式(其中port默认为设置transport.profiles.default.port,如果未设置则返回transport.port)
- discovery.seed_providers:集群节点列表的提供者,作用就是获取discovery.seed_hosts,比如使用文件指定节点列表
- cluster.initial_master_nodes:初始化时master节点的选举列表,一般使用node.name(节点名称)配置指定,配置旨在第一次启动有效,启动之后会保存,下次启动会读取保存的数据
比如这里我全部的配置如下(config/elasticsearch.yml),更多配置参考官网:https://www.elastic.co/guide/en/elasticsearch/reference/current/settings.html
# 启动地址,如果不配置,只能本地访问 network.host: 0.0.0.0 # 节点名称 node.name: node-name # 节点列表 discovery.seed_hosts: ["你的子服务器ip"] # 初始化时master节点的选举列表 cluster.initial_master_nodes: [ "node-name" ] # 集群名称 cluster.name: cluster-name # 对外提供服务的端口 http.port: 9200 # 内部服务端口 transport.port: 9300 # 跨域支持 http.cors.enabled: true # 跨域访问允许的域名地址(正则) http.cors.allow-origin: /.*/ #设置索引数据的存储路径 path.data: /usr/local/elasticsearch/data #设置日志的存储路径 path.logs: /usr/local/elasticsearch/logs #设置集群中master节点的初始列表,可以通过这些节点来自动发现新加入集群的节点 discovery.zen.ping.unicast.hosts: ["127.0.0.1","你的ip:9200"]注:如果还报上面1、2的异常,那可能需要重启一下系统了。
接着启动,结果提示jdk版本不对,原来我自己配置了环境变量JAVA_HOME,而ElasticSearch就是用了这个环境变量对应的java来运行,即发现jdk版本不对,另外还warning,JAVA_HOME环境变量已经弃用了,使用ES_JAVA_HOME代替:
warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME Future versions of Elasticsearch will require Java 11; your Java version from [/opt/jdk1.8.0_202/jre] does not meet this requirement. Consider switching to a distribution of Elasticsearch with a bundled JDK. If you are already using a distribution with a bundled JDK, ensure the JAVA_HOME environment variable is not set.
因为ElasticSearch包中包含了JDK,所以我们可以直接使用,有两种使用办法:
1、添加环境变量ES_JAVA_HOME指向ElasticSearch包中包含了JDK目录
2、修改bin/elasticsearch-env中代码,我们注释掉JAVA_HOME部分的判断:
一切配置完成之后,重启服务器并启动elasticsearch。访问你的elasticsearch地址,如http://192.168.0.1:9200,如果出现以下json串就表示安装成功啦!
{ "name": "node-1", "cluster_name": "linlianlai", "cluster_uuid": "YBKSt_D3SGywU7YyJ3Xeog", "version": { "number": "7.16.0", "build_flavor": "default", "build_type": "tar", "build_hash": "6fc81662312141fe7691d7c1c91b8658ac17aa0d", "build_date": "2021-12-02T15:46:35.697268109Z", "build_snapshot": false, "lucene_version": "8.10.1", "minimum_wire_compatibility_version": "6.8.0", "minimum_index_compatibility_version": "6.0.0-beta1" }, "tagline": "You Know, for Search" }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)