Linux centos7 以tar包方式安装elasticsearch 7.8
1. 官网下载 elasticsearch
https://www.elastic.co/cn/downloads/elasticsearch
我下载的是最新稳定版本7.0.0
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.0.0-linux-x86_64.tar.gz
2. 解压文件, 拷贝到安装目录
tar -xzvf elasticsearch 解压缩,并将解压缩的文件剪切到/usr/local/目录下
3. 进入config文件夹下编辑elasticsearch.yml
集群模式下,放开cluster.name注释,单机模式下,放开node.name
数据存储和日志存储路径放开注释
网络设置 设置ip限制,端口设置,跨越设置i
4. 配置完成后进入bin目录执行启动脚本elasticsearch
前台启动 ./elasticsearch
后台启动 ./elasticsearch -d
5. 启动过程中遇到的坑
1) root启动时,elasticsearch不能以root用户启动
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
处理方法,创建非root用户,使用非root用户启动
a) adduser es 创建用户es
b) passwd es 设置es密码,
c) 设置文件权限 chown -R es /opt/supp_app/elasticsearch-6.4.0
d) visudo.设置用户对命令的执行权限 配置同root
2) JDK版本要求最低版本1.8,在elasticsearch中设置JAVA_HOME CATALINA_HOME和PATH等信息
3) elasticsearch.yml配置有问题,保证配置的文件的key后面直接跟着冒号,冒号后空格一位,再输入对应的value
4) elasticsearch用户拥有的可创建文件描述的权限太低,至少需要65536,
处理办法: #切换到root用户修改
vim /etc/security/limits.conf # 在最后面追加下面内容
*** hard nofile 65536
*** soft nofile 65536 #*** 是启动ES的用户
5) max_map_count文件包含限制一个进程可以拥有的VMA(虚拟内存区域)的数量
处理办法: #切换到root用户修改
vim /etc/sysctl.conf # 在最后面追加下面内容
vm.max_map_count=262144
执行 sysctl -p
集群启动时,设置master节点列表(用逗号分隔,目前单机所以只配置了一个),master节点后续会解释

配置ES启动JVM参数(谨慎操作,本人买不起内存所以配置一下)

记得保存配置
五、 启动ES
- 启动bin目录下的elasticsearch报错(这是ES的一种安全措施,不让用root用户)
[root@localhost bin]# ./elasticsearchfuture versions of Elasticsearch will require Java 11; your Java version from [/usr/local/java/jdk1.8.0_201/jre] does not meet this requirement[2019-07-11T22:47:02,963][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [node-1] uncaught exception in thread [main]org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:163) ~[elasticsearch-7.2.0.jar:7.2.0] at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-7.2.0.jar:7.2.0] at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.2.0.jar:7.2.0] at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-7.2.0.jar:7.2.0] at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.2.0.jar:7.2.0] at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) ~[elasticsearch-7.2.0.jar:7.2.0] at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.2.0.jar:7.2.0]Caused by: java.lang.RuntimeException: can not run elasticsearch as root at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:105) ~[elasticsearch-7.2.0.jar:7.2.0] at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:172) ~[elasticsearch-7.2.0.jar:7.2.0] at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:349) ~[elasticsearch-7.2.0.jar:7.2.0] at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-7.2.0.jar:7.2.0] ... 6 more
- 创建用户并赋予es安装目录权限
创建一个esroot用户并设置初始密码useradd -c 'ES user' -d /home/esroot esrootpasswd esroot将es安装目录属主权限改为esroot用户chown -R esroot <es安装目录>切换用户到esrootsu esroot
- 使用esroot用户重启es(咦,又来错,没关系继续)
ERROR: [2] bootstrap checks failed[1]: initial heap size [268435456] not equal to maximum heap size [524288000]; this can cause resize pauses and prevents mlockall from locking the entire heap[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
- 错误解释:
错误1:本文章中第四点第6条中,我的JVM配置的Xms、Xmx不一致,设置为一致即可;
错误2:官方原话如下(意思就是说要设置系统参数vm.max_map_count=262144):
地址为:https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html#docker-cli-run-prod-mode
The vm.max_map_count kernel setting needs to be set to at least 262144 for production use. Depending on your platform:
- Linux
The vm.max_map_count setting should be set permanently in /etc/sysctl.conf:
To apply the setting on a live system type: sysctl -w vm.max_map_count=262144$ grep vm.max_map_count /etc/sysctl.conf
vm.max_map_count=262144
- 切换到root用户下,解决三中的错误二
查看vm.max_map_count属性值,如果没有添加则在/etc/sysctl.conf文件添加vm.max_map_count = 262144grep vm.max_map_count /etc/sysctl.conf或者执行添加临时变量sysctl -w vm.max_map_count=262144
六、 再次启动ES,然后测试一下,访问http://localhost:9200/
[root@localhost ~]# ./elasticsearch[root@localhost ~]# curl http://localhost:9200/{ "name" : "node-1", "cluster_name" : "my-application", "cluster_uuid" : "QqRQ8cMCTAexMVKTTY4PpA", "version" : { "number" : "7.2.0", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "508c38a", "build_date" : "2019-06-20T15:54:18.811730Z", "build_snapshot" : false, "lucene_version" : "8.0.0", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search"}
后台启动方式加-d,如:./elasticsearch -d
vi /etc/rc.local
/usr/bin/su es -c "/workspace/elasticsearch-7.8.0/bin/elasticsearch -d"
七、 祝学习愉快!
作者:单名一个冲
链接:https://www.jianshu.com/p/2071ddf57996
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· NetPad:一个.NET开源、跨平台的C#编辑器