elasticsearch安装——linux集群方式

来源:互联网 发布:java socket例子 编辑:程序博客网 时间:2024/06/03 05:18

elasticsearch安装——linux集群方式

安装elasticsearch在Linux下的方法如下。如果想要在windows上运行的话,请参考文章:
http://blog.csdn.net/wild46cat/article/details/62040347

好,下面上货。
1、下载elasticsearch
https://www.elastic.co/downloads/elasticsearch

2、解压到指定文件夹

3、修改配置文件 /config/elasticsearch.yml
--集群名称
cluster.name: xy-application
--数据存放路径
path.data: /var/elaticsearch/data
--日志存放路径
path.logs: /var/elaticsearch/logs
---当前节点名称
node.name: cdh4
--设置ip地址
network.host: cdh4
--设置端口号
http.port: 9200

4、需要设置java至少为1.8(因为现在机器上的java是1.7 的,而且不想换成1.8,但是es需要1.8,所以需要单独为es配置一个java版本)就是下载一个Java1.8版本的,然后在/bin/elasticsearch文件中进行修改即可。
if [ -x "$ELASTICSEARCH_HOME/jdk1.8.0_141/bin/java" ]; then    JAVA="$ELASTICSEARCH_HOME/jdk1.8.0_141/bin/java"else    JAVA=`which java`fi

5、运行后出现异常
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as rootat org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:127) ~[elasticsearch-5.5.0.jar:5.5.0]at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:114) ~[elasticsearch-5.5.0.jar:5.5.0]at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:67) ~[elasticsearch-5.5.0.jar:5.5.0]at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) ~[elasticsearch-5.5.0.jar:5.5.0]at org.elasticsearch.cli.Command.main(Command.java:88) ~[elasticsearch-5.5.0.jar:5.5.0]at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) ~[elasticsearch-5.5.0.jar:5.5.0]at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) ~[elasticsearch-5.5.0.jar:5.5.0]Caused by: java.lang.RuntimeException: can not run elasticsearch as rootat org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:106) ~[elasticsearch-5.5.0.jar:5.5.0]at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:194) ~[elasticsearch-5.5.0.jar:5.5.0]at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:351) ~[elasticsearch-5.5.0.jar:5.5.0]at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:123) ~[elasticsearch-5.5.0.jar:5.5.0]

解决方法:
添加用户
adduser  elasticsearch
passwd elasticsearch

修改elasticsearch的所属用户和所属组 
chown -R elasticsearch:root /elasticsearch5.5.0/
chown -R elasticsearch:root /var/elaticsearch/


6、运行后出现下列错误
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536][2]: memory locking requested for elasticsearch process but memory is not locked[3]: max number of threads [1024] for user [elasticsearch] is too low, increase to at least [2048][4]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144][5]: system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk

解决方法:
[1]
/etc/security/limits.config文件末尾添加
这里的elasticsearch代表的是用户名

* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096

[2]
在/config/elasticsearch.yml中不能有
#bootstrap.memory_lock: true

[3]
切换到root用户,进入limits.d目录下修改配置文件。
vim /etc/security/limits.d/90-nproc.conf 
修改如下内容:
* soft nproc 1024
#修改为
* soft nproc 2048

[4]
vim /etc/sysctl.conf 
添加如下内容
vm.max_map_count=262144
然后执行命令
sysctl -p

[5]
添加confi/elasticsearch.yml设置
bootstrap.memory_lock: false 
bootstrap.system_call_filter: false

7、再次运行:

2017-07-22T15:55:37,018][INFO ][o.e.n.Node               ] [cdh4] initializing ...[2017-07-22T15:55:37,370][INFO ][o.e.e.NodeEnvironment    ] [cdh4] using [1] data paths, mounts [[/ (/dev/mapper/vg_cdh4-lv_root)]], net usable_space [30gb], net total_space [49gb], spins? [possibly], types [ext4][2017-07-22T15:55:37,372][INFO ][o.e.e.NodeEnvironment    ] [cdh4] heap size [503.6mb], compressed ordinary object pointers [true][2017-07-22T15:55:37,374][INFO ][o.e.n.Node               ] [cdh4] node name [cdh4], node ID [Udy2p33YRT2pnWGiQLxo2A][2017-07-22T15:55:37,377][INFO ][o.e.n.Node               ] [cdh4] version[5.5.0], pid[933], build[260387d/2017-06-30T23:16:05.735Z], OS[Linux/2.6.32-642.el6.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_141/25.141-b15][2017-07-22T15:55:37,380][INFO ][o.e.n.Node               ] [cdh4] JVM arguments [-Xms512m, -Xmx512m, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+DisableExplicitGC, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -Djdk.io.permissionsUseCanonicalPath=true, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Dlog4j.skipJansi=true, -XX:+HeapDumpOnOutOfMemoryError, -Des.path.home=/elasticsearch-5.5.0][2017-07-22T15:55:42,159][INFO ][o.e.p.PluginsService     ] [cdh4] loaded module [aggs-matrix-stats][2017-07-22T15:55:42,159][INFO ][o.e.p.PluginsService     ] [cdh4] loaded module [ingest-common][2017-07-22T15:55:42,159][INFO ][o.e.p.PluginsService     ] [cdh4] loaded module [lang-expression][2017-07-22T15:55:42,159][INFO ][o.e.p.PluginsService     ] [cdh4] loaded module [lang-groovy][2017-07-22T15:55:42,159][INFO ][o.e.p.PluginsService     ] [cdh4] loaded module [lang-mustache][2017-07-22T15:55:42,160][INFO ][o.e.p.PluginsService     ] [cdh4] loaded module [lang-painless][2017-07-22T15:55:42,161][INFO ][o.e.p.PluginsService     ] [cdh4] loaded module [parent-join][2017-07-22T15:55:42,161][INFO ][o.e.p.PluginsService     ] [cdh4] loaded module [percolator][2017-07-22T15:55:42,161][INFO ][o.e.p.PluginsService     ] [cdh4] loaded module [reindex][2017-07-22T15:55:42,162][INFO ][o.e.p.PluginsService     ] [cdh4] loaded module [transport-netty3][2017-07-22T15:55:42,162][INFO ][o.e.p.PluginsService     ] [cdh4] loaded module [transport-netty4][2017-07-22T15:55:42,165][INFO ][o.e.p.PluginsService     ] [cdh4] no plugins loaded[2017-07-22T15:55:51,664][INFO ][o.e.d.DiscoveryModule    ] [cdh4] using discovery type [zen][2017-07-22T15:55:54,461][INFO ][o.e.n.Node               ] [cdh4] initialized[2017-07-22T15:55:54,470][INFO ][o.e.n.Node               ] [cdh4] starting ...[2017-07-22T15:55:55,364][INFO ][o.e.t.TransportService   ] [cdh4] publish_address {192.168.0.84:9300}, bound_addresses {192.168.0.84:9300}[2017-07-22T15:55:55,445][INFO ][o.e.b.BootstrapChecks    ] [cdh4] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks[2017-07-22T15:55:58,768][INFO ][o.e.c.s.ClusterService   ] [cdh4] new_master {cdh4}{Udy2p33YRT2pnWGiQLxo2A}{gNzLgpezT3S0klHQ-6rYRQ}{cdh4}{192.168.0.84:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)[2017-07-22T15:55:58,886][INFO ][o.e.h.n.Netty4HttpServerTransport] [cdh4] publish_address {192.168.0.84:9200}, bound_addresses {192.168.0.84:9200}[2017-07-22T15:55:58,886][INFO ][o.e.n.Node               ] [cdh4] started[2017-07-22T15:55:58,922][INFO ][o.e.g.GatewayService     ] [cdh4] recovered [0] indices into cluster_state

8、访问cdh4:9200


同时再看一下当前的节点的情况



这样就完成了单点的搭建。

9、然后是搭建集群,需要在其他的机器上进行同样的设置(集群名称)。

10、如果想要修改成集群模式,那么需要修改/conf/elasticsearch.yml
discovery.zen.ping.unicast.hosts: ["cdh4", "cdh5","cdh6"]

11、然后启动另一台机器的es。
访问cdh4:9200/_cat/nodes?v