ElasticSearch本地搭建

avatar 2020年1月7日18:18:29 评论 2,702 次浏览

因为ElasticSearch是java开发的,所以在安装之前需要先安装java,可以参考前面的java安装方法。下面主要是对于ElasticSearch的单实例安装方法介绍。

下载到本地

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.3.0.tar.gz
https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.1.tar.gz
tar -zxf elasticsearch-5.3.0.tar.gz 
mv elasticsearch-5.3.0 /usr/local/elasticsearch

配置

cd /usr/local/elasticsearch/config

调整内存

vim jvm.options 
.......
-Xms2g
-Xmx2g
改成
-Xms512m
-Xmx512m
......

修改数据日志和端口

vim elasticsearch.yml 
 .............

#
path.data: /usr/local/elasticsearch/data        #数据路径
# 
# Path to log files:
#
path.logs: /usr/local/elasticsearch/logs        #日志路径
................
network.host: 0.0.0.0      #允许任何IP访问
#
# Set a custom port for HTTP:
#
http.port: 9200

#cd ..
#mkdir logs data

创建用户

ElasticSearch不允许root权限来运行,所以需要创建一个非root用户,以非root用户启动es

#groupadd elk       #创建用户组elk
#useradd elk -g elk -p 111111      # 创建新用户elk,-g elk 设置其用户组为 elk,-p 111 设置其密码6个1
# cd /usr/local
# chown -R elk:elk elasticsearch
# cd elasticsearch/bin

启动elasticsearch

#./elasticsearch        #启动打印日志
#./elasticsearch -d     #后台启动

验证安装成功:

使用浏览器访问:http://10.211.55.32:9200/,查看一下安装是否成功。

{
  "name" : "iknMFrM",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "rfPgAJQDTEKPPsZDgEBKjA",
  "version" : {
    "number" : "5.3.0",
    "build_hash" : "3adb13b",
    "build_date" : "2017-03-23T03:31:50.652Z",
    "build_snapshot" : false,
    "lucene_version" : "6.4.1"
  },
  "tagline" : "You Know, for Search"
}

启动报错:

#./elasticsearch
[2019-08-29T20:02:07,957][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.3.0.jar:5.3.0]
        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:114) ~[elasticsearch-5.3.0.jar:5.3.0]
        at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:58) ~[elasticsearch-5.3.0.jar:5.3.0]
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) ~[elasticsearch-5.3.0.jar:5.3.0]
        at org.elasticsearch.cli.Command.main(Command.java:88) ~[elasticsearch-5.3.0.jar:5.3.0]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) ~[elasticsearch-5.3.0.jar:5.3.0]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) ~[elasticsearch-5.3.0.jar:5.3.0]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
        at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:106) ~[elasticsearch-5.3.0.jar:5.3.0]
        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:204) ~[elasticsearch-5.3.0.jar:5.3.0]
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:360) ~[elasticsearch-5.3.0.jar:5.3.0]
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:123) ~[elasticsearch-5.3.0.jar:5.3.0]
        ... 6 more

解决方法:

因为ElasticSearch不允许root权限来运行,所以需要创建一个非root用户,以非root用户启动es

启动报错:

[2019-08-29T20:16:17,312][INFO ][o.e.b.BootstrapChecks    ] [iknMFrM] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
ERROR: bootstrap checks failed
max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

临时提高了vm.max_map_count的大小,此操作需要root权限:

sudo  sysctl -w vm.max_map_count=262144
sysctl -a|grep vm.max_map_count

永久修改vm.max_map_count: 解决:切换到root用户修改配置sysctl.conf

vi /etc/sysctl.conf

添加下面配置:

vm.max_map_count=655360

并执行命令:

sysctl -p

然后,重新启动elasticsearch,即可启动成功。

启动报错:

[2019-08-29T20:16:17,312][INFO ][o.e.b.BootstrapCheck     ] [SfD5sIh] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
ERROR: bootstrap checks failed
initial heap size [536870912] not equal to maximum heap size [1073741824]; this can cause resize pauses and prevents mlockall from locking the entire heap

解决方法:

vi config/jvm.options

###-Xms 和 -Xmx需要配置的相等,不然无法启动成功。
-Xms1024m
-Xmx1024m

至此,elasticsearch单机安装已经完成。

avatar

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: