1. 环境如下:
[root@es ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@es ~]# uname -a
Linux es 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
2. elasticsearch 会优先使用内置的 jdk,如果你本地配置了 jdk,那么 elasticsearch 就会优先使用本地配置的 jdk 去启动。本地配置官方推荐 jdk 11。
# 如果使用的自己配置的 1.8 版本 jdk,启动 elasticsearch 时会报如下警告,但不影响正常使用。
future versions of Elasticsearch will require Java 11; your Java version from [/var/www/java/jdk1.8/jre] does not meet this requirement
3. 下载 elasticsearch 和其分词器的压缩包,注意版本保持一致。
[root@es ~]# cd /usr/local/src/
[root@es src]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.4.2-linux-x86_64.tar.gz
[root@es src]# tar xf elasticsearch-7.4.2-linux-x86_64.tar.gz -C ../
[root@es src]# cd ../
[root@es local]# ln -s /usr/local/elasticsearch-7.4.2/ /usr/local/elasticsearch
[root@es local]# echo 'export PATH=/usr/local/elasticsearch/bin:$PATH' >>/etc/profile
[root@es local]# source /etc/profile
[root@es local]# mkdir -p elasticsearch/plugins/ik
[root@es local]# cd elasticsearch/plugins/ik
[root@es ik]# wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.4.2/elasticsearch-analysis-ik-7.4.2.zip
[root@es ik]# unzip elasticsearch-analysis-ik-7.4.2.zip
[root@es ik]# \rm elasticsearch-analysis-ik-7.4.2.zip
4. elasticsearch 默认禁止使用 root 启动。创建普通账户 es 并授权。
[root@es ik]# cd /usr/local/
[root@es local]# useradd es
[root@es local]# passwd es
[root@es local]# chown -R es elasticsearch*
5. 切换为 es 普通用户修改配置并启动 elasticsearch。
[root@es local]# su - es
[es@es ~]$ cd /usr/local/elasticsearch/config/
[es@es config]$ cp elasticsearch.yml{,.bak}
[es@es config]$ vim elasticsearch.yml
network.host: 0.0.0.0
[es@es config]$ elasticsearch
ERROR: [3] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[3]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
-------------------------------------------------解决报错-------------------------------------------------
- 切换为root用户
# 解决第一个报错:
[root@es ~]# vim /etc/security/limits.conf # 追加如下内容,使之生效需要断开一下终端
* soft nofile 65536
* hard nofile 65536
# 解决第二个报错:
[root@es ~]# vim /etc/sysctl.conf # 追加如下内容
vm.max_map_count=655360
[root@es ~]# sysctl -p # 使配置生效
# 解决第三个报错:
[root@es ~]# vim /usr/local/elasticsearch/config/elasticsearch.yml
cluster.initial_master_nodes: ["node-1"] # 取消本行注释并修改只保留一个节点。
- 如果是 CentOS 6.x 可能会多报如下两个错误:
[4]:max number of threads [1024] for user [es] is too low, increase to at least [4096]
[5]:system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
# 解决第四个报错:
[root@es ~]# /etc/security/limits.d/90-nproc.conf
* soft nproc 4096 # 将本行的 1024 修改为 4096,断开重连终端生效。
# 解决第五个报错:
[root@es ~]# vim /usr/local/elasticsearch/config/elasticsearch.yml
bootstrap.memory_lock: false # 取消本行注释,并修改为 false
bootstrap.system_call_filter: false # 添加本行内容
# 出现此报错因为 CentOS 6.x 不支持 SECCOMP,而 elasticsearch 默认相关配置默认是为true,所以导致启动失败。具体见Gitlab:https://github.com/elastic/elasticsearch/issues/22899
-------------------------------------------------解决完毕-------------------------------------------------
6. 重新启动 elasticsearch。
[root@es ~]# su - es
[es@es ~]$ elasticsearch
# 查看是可以启动成功的,此时前台启动是方便查看启动日志,现在没问题就可以Ctrl+c中止掉,以daemon方式启动
[es@es ~]$ elasticsearch -d
7. 验证安装的插件和 elasticsearch 服务。
[root@es local]# curl http://localhost:9200/_cat/plugins
es analysis-ik 7.4.2
[root@es local]# curl http://localhost:9200
{
"name" : "es",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "neAuqAOpSbSV8F2_bhGtCw",
"version" : {
"number" : "7.4.2",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "2f90bbf7b93631e52bafb59b3b049cb44ec25e96",
"build_date" : "2019-10-28T20:40:44.881551Z",
"build_snapshot" : false,
"lucene_version" : "8.2.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
写作不易,转载请注明出处,谢谢~~