// 查看各版本支持的JDK
//官方参考安装文档
Installing Elasticsearch | Elasticsearch Guide [8.0] | Elastic
//安装包下载
Past Releases of Elastic Stack Software | Elastic
这里我的是CentOS7.5,可以用命令查看系统版本
cat /etc/redhat-release
我下载的不是最新的elasticsearch-7.17.1-linux-x86_64.tar.gz。
上传到Centos指定目录,比如/home/software/
解压
tar -zxvf elasticsearch-7.17.tar.gz
cd到 bin目录下执行
./elasticsearch
[root@VM_0_2_centos bin]# ./elasticsearch
warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME
Future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/jdk/jdk1.8/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.
warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME
Future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/jdk/jdk1.8/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.
[2022-03-04T16:56:30,513][ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [VM_0_2_centos] 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:170) ~[elasticsearch-7.17.1.jar:7.17.1]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:157) ~[elasticsearch-7.17.1.jar:7.17.1]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:77) ~[elasticsearch-7.17.1.jar:7.17.1]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:112) ~[elasticsearch-cli-7.17.1.jar:7.17.1]
at org.elasticsearch.cli.Command.main(Command.java:77) ~[elasticsearch-cli-7.17.1.jar:7.17.1]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:122) ~[elasticsearch-7.17.1.jar:7.17.1]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:80) ~[elasticsearch-7.17.1.jar:7.17.1]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:107) ~[elasticsearch-7.17.1.jar:7.17.1]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:183) ~[elasticsearch-7.17.1.jar:7.17.1]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:434) ~[elasticsearch-7.17.1.jar:7.17.1]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:166) ~[elasticsearch-7.17.1.jar:7.17.1]
... 6 more
uncaught exception in thread [main]
java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:107)
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:183)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:434)
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:166)
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:157)
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:77)
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:112)
at org.elasticsearch.cli.Command.main(Command.java:77)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:122)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:80)
For complete error details, refer to the log at /home/software/elasticsearch-7.17.1/logs/elasticsearch.log
2022-03-04 08:56:30,849356 UTC [30437] INFO Main.cc@111 Parent process died - ML controller exiting
结果是报错can not run elasticsearch as root。
然后是一套创建,参考:
//新建用户组,组名叫elastic
1、 groupadd -g 700 elastic
//新建用户,用户名叫elastic
2、useradd -u 701 -g 700 elastic
//设置用户密码
3、passwd elastic
//将用户添加到用户组里面,第一个elastic表示用户名,第二个elastic表示组名。
4、gpasswd -a elastic elastic
//赋予权限
5. chown -R elastic:elastic /home/software/elasticsearch-7.17.1/
// 切换用户
6、su elastic
再次执行./elasticsearch,启动成功。
然而外部访问9200端口还是失败
需要改参数
1./home/software/elasticsearch-7.17.1/config/elasticsearch.yml
cluster.initial_master_nodes: ["node-1"]
http.port: 9200
network.host: 0.0.0.0
2.在/etc/sysctl.conf 添加:
vm.max_map_count=262144
重启,外部访问9200端口就可以返回如下JSON数据
{
"name": "VM_0_2_centos",
"cluster_name": "elasticsearch",
"cluster_uuid": "tOJOc_tVQJapivGA1HU17g",
"version": {
"number": "7.17.1",
"build_flavor": "default",
"build_type": "tar",
"build_hash": "e5acb99f822233d62d6444ce45a4543dc1c8059a",
"build_date": "2022-02-23T22:20:54.153567231Z",
"build_snapshot": false,
"lucene_version": "8.11.1",
"minimum_wire_compatibility_version": "6.8.0",
"minimum_index_compatibility_version": "6.0.0-beta1"
},
"tagline": "You Know, for Search"
}
这里还有个ElasticSearch的web管理工具Cerebro可以试试。
Elasticsearch Web管理工具 - 废物大师兄 - 博客园