Elasticsearch 6.X安装
1、获取安装包,并解压
tar -zxvf elasticsearch-6.1.1.tar.gz
ln -s elasticsearch-6.1.1 elasticsearch
2、配置,进入config目录
1)配置elasticsearch.yml
创建data目录:索引数据的存储路径
创建logs目录:日志文件的存储路径
配置信息如下:
cluster.name: my-application #集群的名称
node.name: master #节点名称,其余两个节点分别为slave1和slave2
path.data: /usr/local/src/elasticsearch/elasticsearch/data #索引数据的存储路径
path.logs: /usr/local/src/elasticsearch/elasticsearch/logs #日志文件的存储路径
bootstrap.memory_lock: true #设置为true来锁住内存。因为内存交换到磁盘对服务器性能来说是致命的,当jvm开始swapping时es的效率会降低,所以要保证它不swap
network.host: 172.16.209.10 #绑定的ip地址 ,其他节点也应该为对应的IP地址
http.port: 9200 #设置对外服务的http端口,默认为9200
discovery.zen.ping.unicast.hosts: ["172.16.209.10", "172.16.209.11", "172.16.209.12"] #集群IP地址
discovery.zen.minimum_master_nodes: 2 #为了避免脑裂,集群节点数最少为半数+1
2)配置 jvm.options文件
# Xms represents the initial size of total heap space ,即初始时,java堆空间大小
# Xmx represents the maximum size of total heap space ,最大堆空间大小
-Xms64m
-Xmx256m
3) log4j2.properties日志格式配置文件,暂时不用改
3、将安装包发送给slave1和slave2
scp -r elasticsearch/ root@slave1:/usr/local/src
scp -r elasticsearch/ root@slave2:/usr/local/src
并修改elasticsearch.yml 配置文件中的node.name 和 network.host属性
4、配置elasticsearch环境变量
配置三台集群的环境变量,vi /etc/profile
增加:
export ES_HOME=/usr/local/src/elasticsearch/elasticsearch
export PATH=$PATH:$ES_HOME/bin:
然后执行:
source /etc/profile 生效
5、启动elasticsearch
输入./elasticsearch 启动,但是报错
[root@master bin]# ./elasticsearch
[2018-12-08T22:46:45,929][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [master] 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:125) ~[elasticsearch-6.1.1.jar:6.1.1]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-6.1.1.jar:6.1.1]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.1.1.jar:6.1.1]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.1.1.jar:6.1.1]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.1.1.jar:6.1.1]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-6.1.1.jar:6.1.1]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:85) ~[elasticsearch-6.1.1.jar:6.1.1]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:104) ~[elasticsearch-6.1.1.jar:6.1.1]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:171) ~[elasticsearch-6.1.1.jar:6.1.1]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:322) ~[elasticsearch-6.1.1.jar:6.1.1]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-6.1.1.jar:6.1.1]
... 6 more
解决办法:
chown -R XXX elasticsearch 用自己的用户启动ES
之后还是有报错:
[2018-12-08T23:00:47,128][INFO ][o.e.b.BootstrapChecks ] [slave1] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
ERROR: [5] bootstrap checks failed
[1]: initial heap size [67108864] not equal to maximum heap size [268435456]; this can cause resize pauses and prevents mlockall from locking the entire heap
[2]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[3]: memory locking requested for elasticsearch process but memory is not locked
[4]: max number of threads [3802] for user [lihao] is too low, increase to at least [4096]
[5]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解决办法:
[1]、修改jvm.options 配置文件,内存改为一致即可
[2]、vi /etc/security/limits.conf,增加
* soft nofile 65536
* hard nofile 131072
其中* 表示所有用户,如果单独指定用户,*这里用户名取代即可
[3]、vi /etc/security/limits.conf
* soft memlock unlimited
* hard memlock unlimited
[4]、ulimit -a 查看:
然后:cd /etc/security/limits.d/目录,查看:
编辑20-nproc.conf,增加红框中内容:
重启系统。
然后用ulimit -a命令查看 ,修改成功:
[5]、编辑vi /etc/sysctl.conf文件:增加
vm.max_map_count=655360
然后:sysctl -p
6、进入bin目录,然后输入命令elasticsearch,启动成功:
验证:curl master:9200