1.创建elasticsearch用户组
[root@VM_0_3_centos ~]# groupadd elasticsearch
2.创建用户 es 并设置密码为es
[root@VM_0_3_centos ~]# useradd es
[root@VM_0_3_centos ~]# passwd es
3.用户es 添加到 elasticsearch 用户组
[root@VM_0_3_centos ~]# usermod -G elasticsearch es
4. 设置sudo权限
[root@VM_0_3_centos ~]# visudo
在root ALL=(ALL) ALL 下添加
es ALL=(ALL) ALL
5.下载安装包https://www.elastic.co/cn/downloads/elasticsearch并上传/usr/dsa/目录下,并解压 tar.gz
[root@VM_0_3_centos dsa]# tar -xvf elasticsearch-6.3.2.tar.gz
6.解压成功后,切换用户
[root@VM_0_3_centos dsa]# su es
7.更改elasticsearch-6.3.2 文件夹以及内部文件的所属用户为es, 用户组组为elasticsearch
[es@VM_0_3_centos dsa]$ sudo chown -R es:elasticsearch elasticsearch-6.3.2
8.修改ElasticSearch.yml 配置
[es@VM_0_3_centos dsa]$ vim elasticsearch-6.3.2/config/elasticsearch.yml
修改内容(没有就添加)
cluster.name: my-es
node.name: node-1
network.host: 0.0.0.0
http.port: 9200
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
9.切换root用户修改/etc/sysctl.conf
[root@VM_0_3_centos dsa]# vim /etc/sysctl.conf
在最后一行添加 vm.max_map_count=262144
保存退出后,使用sysctl -p 刷新生效
[root@VM_0_3_centos dsa]# sysctl -p
kernel.printk = 5
vm.max_map_count = 262144
10.修改文件/etc/security/limits.conf
[root@VM_0_3_centos dsa]# vim /etc/security/limits.conf
添加如下内容:
* hard nofile 65536
* soft nofile 65536
* soft nproc 2048
* hard nproc 4096
11.切换cd /etc/security/limits.d/ 找到 -nproc.conf 文件修改配置文件
[root@VM_0_3_centos dsa]# vi /etc/security/limits.d/20-nproc.conf
修改如下内容:
* soft nproc 1024
#修改为
* soft nproc 4096
12.启动elasticsearch
[es@VM_0_3_centos dsa]$ cd elasticsearch-6.3.2/bin/
[es@VM_0_3_centos bin]$ ./elasticsearch
13.在浏览器输入localhost:9200 验证是否启动成功
在浏览器上输出如下信息代表成功哦
{
"name" : "node-1",
"cluster_name" : "my-es",
"cluster_uuid" : "NBwUIqhUS8uThieUYnspAg",
"version" : {
"number" : "6.3.2",
"build_flavor" : "oss",
"build_type" : "tar",
"build_hash" : "053779d",
"build_date" : "2018-07-20T05:20:23.451332Z",
"build_snapshot" : false,
"lucene_version" : "7.3.1",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
14.es启动常遇见的错误信息及解决方法
异常信息1:expecting token of type [START_OBJECT] but found [VALUE_STRING]];
错误原因:elasticsearch.yml 文件内部错误
解决办法:仔细检查yml文件中的配置项书写格式: (空格)name:(空格)value
---------------------------------------------------------------------------------
异常信息2:java.lang.UnsupportedOperationException: seccomp unavailable: CONFIG_SECCOMP not compiled into kernel, CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER are needed
错误原因:Centos6不支持SecComp,而ES默认bootstrap.system_call_filter为true进行检测,所以导致检测失败,失败后直接导致ES不能启动
解决办法:修改elasticsearch.yml 添加一下内容 :
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
异常信息3:BindTransportException[Failed to bind to [9300-9400]
解决办法 打开配置文件elasticsearch.yml 将 network.host: 192.168.0.1 修改为本机IP 0.0.0.0
--------------------------------------------------------------------------------------------
异常信息4:max number of threads [1024] for user [lish] likely too low, increase to at least [2048]
解决办法:切换到root用户,进入limits.d目录下找到 -nproc.conf文件并 修改配置文件。
vi /etc/security/limits.d/20-nproc.conf
修改如下内容:
* soft nproc 1024
#修改为
* soft nproc 2048
异常信息5 在启动的过程中 进程被杀
[es@VM_0_3_centos bin]$ ./elasticsearch
[2019-07-10T09:31:28,776][INFO ][o.e.n.Node ] [node-1] initializing ...
[2019-07-10T09:31:28,959][INFO ][o.e.e.NodeEnvironment ] [node-1] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [38.9gb], net total_space [49gb], types [rootfs]
[2019-07-10T09:31:28,959][INFO ][o.e.e.NodeEnvironment ] [node-1] heap size [1015.6mb], compressed ordinary object pointers [true]
[2019-07-10T09:31:28,963][INFO ][o.e.n.Node ] [node-1] node name [node-1], node ID [_i1T3Ze9Q8mePcZkAUO6Bg]
[2019-07-10T09:31:28,963][INFO ][o.e.n.Node ] [node-1] version[6.3.2], pid[592], build[oss/tar/053779d/2018-07-20T05:20:23.451332Z], OS[Linux/3.10.0-514.26.2.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_131/25.131-b11]
[2019-07-10T09:31:28,963][INFO ][o.e.n.Node ] [node-1] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.io.tmpdir=/tmp/elasticsearch.9XZNDohq, -XX:+HeapDumpOnOutOfMemoryError, -XX:HeapDumpPath=data, -XX:ErrorFile=logs/hs_err_pid%p.log, -XX:+PrintGCDetails, -XX:+PrintGCDateStamps, -XX:+PrintTenuringDistribution, -XX:+PrintGCApplicationStoppedTime, -Xloggc:logs/gc.log, -XX:+UseGCLogFileRotation, -XX:NumberOfGCLogFiles=32, -XX:GCLogFileSize=64m, -Des.path.home=/usr/dsa/elasticsearch-6.3.2, -Des.path.conf=/usr/dsa/elasticsearch-6.3.2/config, -Des.distribution.flavor=oss, -Des.distribution.type=tar]
Killed
-------------------------------------
解决办法 修改ES中config目录下的jvm.options文件
vim jvm.options 将
-Xms1g
-Xmx1g
改为
-Xms512m
-Xmx512m
就启动成功了