【elasticsearch】初识es搜索引擎,单节点安装

时间:2021-08-15 17:32:17

es权威指南1:

https://es.xiaoleilu.com/index.html

es权威指南2:
https://elasticsearch.cn/book/elasticsearch_definitive_guide_2.x/

部署es环境:

centos6.9、jdk1.8 、elasticsearch-5.5.1.rpm

部署步骤:

官网下载最新版本的es:
https://www.elastic.co/downloads/elasticsearch

jdk 安装

参考博文:http://blog.csdn.net/vchen_hao/article/details/76613788

rpm 安装方式

[root@localhost ~]# rpm -ivh elasticsearch-5.5.1.rpm 

安装结果:

[root@localhost ~]# rpm -ivh elasticsearch-5.5.1.rpm 
warning: elasticsearch-5.5.1.rpm: Header V4 RSA/SHA512 Signature, key ID d88e42b4: NOKEY
Preparing... ########################################### [100%]
Creating elasticsearch group... OK
Creating elasticsearch user... OK
1:elasticsearch ########################################### [100%]
### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using chkconfig
sudo chkconfig --add elasticsearch
###
You can start elasticsearch service by executing
sudo service elasticsearch start

启动、停止、状态

service elasticsearch start/stop/status

zip压缩包安装方式

解压运行报错:

[root@localhost elasticsearch-5.5.1]# bin/elasticsearch
[2017-08-03T03:27:36,185][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] 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:127) ~[elasticsearch-5.5.1.jar:5.5.1]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:114) ~[elasticsearch-5.5.1.jar:5.5.1]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:67) ~[elasticsearch-5.5.1.jar:5.5.1]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) ~[elasticsearch-5.5.1.jar:5.5.1]
at org.elasticsearch.cli.Command.main(Command.java:88) ~[elasticsearch-5.5.1.jar:5.5.1]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) ~[elasticsearch-5.5.1.jar:5.5.1]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) ~[elasticsearch-5.5.1.jar:5.5.1]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:106) ~[elasticsearch-5.5.1.jar:5.5.1]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:194) ~[elasticsearch-5.5.1.jar:5.5.1]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:351) ~[elasticsearch-5.5.1.jar:5.5.1]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:123) ~[elasticsearch-5.5.1.jar:5.5.1]
... 6 more

解决方案:

因为安全问题elasticsearch 不让用root用户直接运行,所以要创建新用户
建议创建一个单独的用户用来运行ElasticSearch
创建elsearch用户组及elsearch用户
groupadd elsearch
useradd elsearch -g elsearch -p elasticsearch

chown -R elsearch:elsearch ./elasticsearch-5.5.1 用户目录权限

如果你想把 Elasticsearch 作为一个守护进程在后台运行,那么可以在后面添加参数 -d 。

测试 Elasticsearch 是否启动成功,可以打开另一个终端,执行以下操作:

curl 'http://localhost:9200/?pretty'

你应该得到和下面类似的响应(response):

[root@localhost ~]# curl 'http://localhost:9200/?pretty'
{
"name" : "SoKheeE",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "M5lU32CWQHiDEVu6XUhjeg",
"version" : {
"number" : "5.5.1",
"build_hash" : "19c13d0",
"build_date" : "2017-07-18T20:44:24.823Z",
"build_snapshot" : false,
"lucene_version" : "6.6.0"
},
"tagline" : "You Know, for Search"
}