Elasticsearch下載地址:
https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.1.1-linux-x86_64.tar.gz
解壓elasticsearch-7.1.1-linux-x86_64.tar.gz到/usr/local/目錄:
tar -avxf elasticsearch-7.1.1-linux-x86_64.tar.gz -C /usr/local/
進入解壓后的elasticsearch目錄:
(1)新建data目錄:
mkdir data
(2)修改config/elasticsearch.yml:
vim config/elasticsearch.yml
取消下列項注釋並修改:
cluster.name: my-application #集群名稱 node.name: node-1 #節點名稱 #數據和日志的存儲目錄 path.data: /usr/local/elasticsearch-7.1.1/data path.logs: /usr/local/elasticsearch-7.1.1/logs #設置綁定的ip,設置為0.0.0.0以后就可以讓任何計算機節點訪問到了 network.host: 0.0.0.0 http.port: 9200 #端口 #設置在集群中的所有節點名稱,這個節點名稱就是之前所修改的,當然你也可以采用默認的也行,目前是單機,放入一個節點即可 cluster.initial_master_nodes: ["node-1"]
修改完畢后,:wq 保存退出vim
准備啟動es
進入/bin目錄執行命令:
./elasticsearch
我這里出現如下錯誤:
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c5330000, 986513408, 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 986513408 bytes for committing reserved memory. # An error report file with more information is saved as: # logs/hs_err_pid22863.log
[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用戶操作,添加一個其他的用戶再試試:
[root@VM_0_2_centos elasticsearch-7.1.1]# adduser es
[root@VM_0_2_centos elasticsearch-7.1.1]# passwd es
Changing password for user es.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
改一下es目錄所屬用戶:
[root@VM_0_2_centos elasticsearch-7.1.1]# chown es /usr/local/elasticsearch-7.1.1/ -R
vim 編輯 /etc/security/limits.conf,在末尾加上:
es soft nofile 65536 es hard nofile 65536 es soft nproc 4096 es hard nproc 4096
vim 編輯 vim /etc/security/limits.d/20-nproc.conf,將* 改為用戶名(es):
# Default limit for number of user's processes to prevent # accidental fork bombs. # See rhbz #432903 for reasoning. es 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 ~]#
登錄剛才新建的es用戶,並啟動elasticsearch,OK
[root@VM_0_2_centos elasticsearch-7.1.1]# su es
[es@VM_0_2_centos elasticsearch-7.1.1]$ ./bin/elasticsearch
后台啟動:
[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
