1、进入到官网
https://www.elastic.co/cn/downloads/elasticsearch
2、右键复制地址
3、进入到linux文件夹下输入以下命令
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.14.0-linux-x86_64.tar.gz
tar -zxvf elasticsearch-7.14.0-linux-x86_64.tar.gz
4、将elasticsearch-7.14.0改名为elasticsearch并放到/usr/local
mv elasticsearch-7.14.0 /usr/local/elasticsearch
5、进入到config下vim elasticsearch.yml
具体设置参数,自己调
#配置es的集群名称,默认是elasticsearch,es会自动发现在同一网段下的es,如果在同一网段下有多个集群,就可以用这个属性来区分不同的集群。
cluster.name: my-es
#节点名称
node.name: node-1
#设置索引数据的存储路径
path.data: /usr/local/elasticsearch/data
#设置日志的存储路径
path.logs: /usr/local/elasticsearch/logs
#设置当前的ip地址,通过指定相同网段的其他节点会加入该集群中
network.host: 0.0.0.0
#设置对外服务的http端口
http.port: 9200
#设置集群中master节点的初始列表,可以通过这些节点来自动发现新加入集群的节点,10.10.10.34本地局域网
discovery.zen.ping.unicast.hosts: ["127.0.0.1","10.10.10.34:9200"]
#当您第一次启动全新的Elasticsearch集群时,会出现一个集群引导步骤,该步骤确定在第一次选举中计票的主要合格节点集。 在开发模式下,如果未配置发现设置,则此步骤由节点本身自动执行。 由于此自动引导本质上是不安全的,因此当您在生产模式下启动全新集群时,必须明确列出符合条件的节点的名称或IP地址,这些节点的投
cluster.initial_master_nodes:["node-1","node-2"]
记得都要配置噢
6、在/usr/local/elasticsearch/下mkdir data 和 logs
7、启动运行
进入bin,运行
./elasticsearch
报错
][ERROR][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.14.0.jar:7.14.0]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-7.14.0.jar:7.14.0]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:75) ~[elasticsearch-7.14.0.jar:7.14.0]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:116) ~[elasticsearch-cli-7.14.0.jar:7.14.0]
at org.elasticsearch.cli.Command.main(Command.java:79) ~[elasticsearch-cli-7.14.0.jar:7.14.0]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) ~[elasticsearch-7.14.0.jar:7.14.0]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:81) ~[elasticsearch-7.14.0.jar:7.14.0]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:103) ~[elasticsearch-7.14.0.jar:7.14.0]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170) ~[elasticsearch-7.14.0.jar:7.14.0]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:399) ~[elasticsearch-7.14.0.jar:7.14.0]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-7.14.0.jar:7.14.0]
... 6 more
uncaught exception in thread [main]
java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:103)
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:399)
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159)
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150)
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:75)
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:116)
at org.elasticsearch.cli.Command.main(Command.java:79)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:81)
For complete error details, refer to the log at /usr/local/elasticsearch/logs/my-luobi.log
2021-08-31 07:44:23,893728 UTC [23055] INFO Main.cc@106 Parent process died - ML controller exiting
java.lang.RuntimeException: can not run elasticsearch as root 因为安全问题elasticsearch 不让用root用户直接运行,所以要创建新用户。
具体操作如下:
useradd testuser
passwd testuser
再输入两次密码(自定义)
为用户赋权限
chown -R testuser:testuser /usr/local/elasticsearch
然后使用es用户启动 :su testuser
cd /usr/local/elasticsearch
启动es命令:bin/elasticsearch
还要再进行一次
为用户赋权限
chown -R testuser:testuser /usr/local/elasticsearch
然后使用es用户启动 :su testuser
cd /usr/local/elasticsearch
启动es命令:bin/elasticsearch
如果还报错
a、原因:无法创建本地文件问题,用户最大可创建文件数太小,解决方案:切换到root用户,编辑limits.conf配置文件, 添加类似如下内容:
vi /etc/security/limits.conf
然后添加如下内容: 注意*不要去掉了
* soft nofile 65536
* hard nofile 131072
注:* 代表Linux所有用户名称(比如 hadoop)
需要保存、退出、重新登录才可生效。
b、原因:最大虚拟内存太小,解决办法切换到root用户修改配置sysctl.conf:
vi /etc/sysctl.conf
添加下面配置:
vm.max_map_count=655360
最后记得执行:
sysctl -p
然后,重新启动elasticsearch,即可启动成功。
后台启动命令如下
/elasticsearch -d