Elasticsearch下载地址:
https://www.elastic.co/cn/downloads/past-releases#elasticsearch
解压elasticsearch-6.4.3.tar.gz到/usr/local/elastic-plugin目录:
tar -zxvf elasticsearch-6.4.3.tar.gz
进入解压后的elasticsearch目录:/usr/local/elastic-plugin/elasticsearch-6.4.3
(1)新建data目录:
mkdir data
(2)修改config/elasticsearch.yml:
vim config/elasticsearch.yml
在Memory下面添加
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
在最后添加下列内容
cluster.name: smt-xpaik-elastic #集群名称
#数据和日志的存储目录
path.data: /usr/local/elastic-plugin/elasticsearch-6.4.3/data
path.logs: /usr/local/elastic-plugin/elasticsearch-6.4.3/logs
#设置绑定的ip,设置为0.0.0.0以后就可以让任何计算机节点访问到了
network.host: 0.0.0.0
http.port: 9200 #端口
#qcl自己加的
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
修改完毕后,:wq 保存退出vim
准备启动es
进入/bin目录执行命令:
前台启动:./elasticsearch
后台启动:./elasticsearch -d
问题:
[root@VM_97_229_centos elasticsearch-6.4.3]# ./bin/elasticsearch
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000d4cc0000, 724828160, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 724828160 bytes for committing reserved memory.
# An error report file with more information is saved as:
# logs/hs_err_pid8507.log
[root@VM_97_229_centos elasticsearch-6.4.3]#
[root@VM_0_2_centos bin]#
解决:
看来是我这1G的内存太小了啊,elasticsearch使用java的jvm默认是使用1G的内存的,这里我们修改一下内存,直接把内存改到200m
cd 到es目录修改 ./config/jvm.options:
vim ./config/jvm.options
修改该内容:
-Xms200m
-Xmx200m
:wq 保存并退出vim,再次启动es
再次启动出现如下错误:
[2019-06-21T16:20:03,039][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [node-1] 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:163) ~[elasticsearch-7.1.1.jar:7.1.1]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-7.1.1.jar:7.1.1]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.1.1.jar:7.1.1]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-7.1.1.jar:7.1.1]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.1.1.jar:7.1.1]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) ~[elasticsearch-7.1.1.jar:7.1.1]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.1.1.jar:7.1.1]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:102) ~[elasticsearch-7.1.1.jar:7.1.1]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:169) ~[elasticsearch-7.1.1.jar:7.1.1]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:325) ~[elasticsearch-7.1.1.jar:7.1.1]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-7.1.1.jar:7.1.1]
... 6 more
[root@VM_0_2_centos elasticsearch-7.1.1]#
这是不能使用root用户操作,添加一个其他的用户再试试:
用户名和密码都是admin
[root@VM_0_2_centos elasticsearch-7.1.1]# adduser admin
[root@VM_0_2_centos elasticsearch-7.1.1]# passwd admin
Changing password for user admin.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
改一下admin目录所属用户:
[root@VM_0_2_centos elasticsearch-7.1.1]# chown admin /usr/local/elastic-plugin/elasticsearch-6.4.3/ -R
vim 编辑 /etc/security/limits.conf,在末尾加上:
admin soft nofile 65536
admin hard nofile 65536
admin soft nproc 4096
admin hard nproc 4096
vim 编辑 vim /etc/security/limits.d/20-nproc.conf,将* 改为用户名(admin):
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.
admin soft nproc 4096
root soft nproc unlimited
vim 编辑 /etc/sysctl.conf,在末尾加上:
vm.max_map_count = 655360
执行:
[root@VM_0_2_centos ~]# sysctl -p
kernel.printk = 5
vm.max_map_count = 655360
[root@VM_0_2_centos ~]#
登录刚才新建的admin用户,并启动elasticsearch,OK
[root@VM_0_2_centos elasticsearch-7.1.1]# su admin
[es@VM_0_2_centos elasticsearch-7.1.1]$ ./bin/elasticsearch
记得服务器开放安全组端口9200
后台启动:
[es@VM_0_2_centos elasticsearch-7.1.1]$ ./bin/elasticsearch -d
[es@VM_0_2_centos elasticsearch-7.1.1]$
查看进程:
[es@VM_0_2_centos elasticsearch-7.1.1]$ ./bin/elasticsearch -d
[es@VM_0_2_centos elasticsearch-7.1.1]$ ps -ef|grep elasticsearch
es 18652 1 19 17:48 pts/2 00:00:00 /usr/local/java/jdk1.8.0_211/bin/java -Xms200m -Xmx200m -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -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-182563007296674551 -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 -Dio.netty.allocator.type=unpooled -Des.path.home=/usr/local/elasticsearch-7.1.1 -Des.path.conf=/usr/local/elasticsearch-7.1.1/config -Des.distribution.flavor=default -Des.distribution.type=tar -Des.bundled_jdk=true -cp /usr/local/elasticsearch-7.1.1/lib/* org.elasticsearch.bootstrap.Elasticsearch -d
es 18728 8399 0 17:48 pts/2 00:00:00 grep --color=auto elasticsearch
[es@VM_0_2_centos elasticsearch-7.1.1]$
参考地址:https://blog.csdn.net/luo1544943710/article/details/93196147
问题:Java程序调用报错 :index read-only / allow delete
解决:
https://blog.51cto.com/michaelkang/2164181
curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}'
问题:Java程序调用报错 :all shards failed Caused by: org.elasticsearch.search.query.QueryPhaseExecutionException: Result window is too large, from + size must be less than or equal to: [10000] but was [11460]. See the scroll api for a more efficient way to request large data sets. This limit can be set by changing the [index.max_result_window] index level setting.
解决:
https://www.jianshu.com/p/aac37a48b775
https://www.jianshu.com/p/f10adc0819e9
es设置index.max_result_window(就是from+size,默认大小10000),可通过如下方式修改:
curl -XPUT 192.168.40.31:9200/_all/_settings -d '{ "index.max_result_window" :"1000000"}'