elasticsearch github 地址为GitHub - elastic/elasticsearch: Free and Open, Distributed, RESTful Search Engine
下载elasticsearch https://www.elastic.co/cn/downloads/past-releases#elasticsearch
注意elasticsearch版本对应的jdk版本。我使用的jdk版本为1.8.0,下载的elasticsearch版本为6.8.8
每一个elasticsearch压缩包中都含有自带的jdk,如果您希望使用最新的elasticsearch版本,最好将java_home设置为elasticsearch自带的jdk目录。一般目录在elasticserach_home/jdk/下
解压elasticsearch
root@ubuntu:/usr/local/elastic# tar -xf elasticsearch-6.8.8.tar.gz
如果您的机器内存有限,启动之前最好先修改 confi目录下jvm.options启动内存
root@ubuntu:/usr/local/elastic/elasticsearch-6.8.8/config# vim jvm.options
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
-Xms512m
-Xmx512m
启动elasticsearch 注意不能使用root用户启动
先将elasticsearch文件目录权限赋予启动用户
root@ubuntu:/usr/local/elastic# chown -R wl:wl /usr/local/elastic/
root@ubuntu:/usr/local/elastic# ll
total 461724
drwxr-xr-x 4 wl wl 4096 Mar 13 20:31 ./
drwxr-xr-x 26 root root 4096 Mar 13 19:46 ../
drwxr-xr-x 8 wl wl 4096 Mar 19 2020 elasticsearch-6.8.8/
-rwxrw-rw- 1 wl wl 149927766 Mar 13 20:07 elasticsearch-6.8.8.tar.gz*
drwxr-xr-x 9 wl wl 4096 Mar 6 13:58 elasticsearch-7.11.2/
-rwxrw-rw- 1 wl wl 322857683 Mar 13 19:33 elasticsearch-7.11.2-linux-x86_64.tar.gz*
root@ubuntu:/usr/local/elastic#
启动elasticsearch
wl@ubuntu:/usr/local/elastic/elasticsearch-6.8.8$ bin/elasticsearch
或后台启动
wl@ubuntu:/usr/local/elastic/elasticsearch-6.8.8$ bin/elasticsearch -d
Run curl -X GET http://localhost:9200/
to verify Elasticsearch is running. 如果您没有安装curl可以直接在浏览器输入 http://localhost:9200/
curl安装参考:curl安装
root@ubuntu:/usr/local/elastic# curl -X GET http://localhost:9200/
{
"name" : "hui1XcR",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "KLSs_y_2QB2wJTmC48b4dQ",
"version" : {
"number" : "6.8.8",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "2f4c224",
"build_date" : "2020-03-18T23:22:18.622755Z",
"build_snapshot" : false,
"lucene_version" : "7.7.2",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
root@ubuntu:/usr/local/elastic#
现在elasticsearch安装完毕。默认配置下,elasticsearch只能本机访问,如果您想别的机器也能访问您的elasticsearch,需要修该以下配置
elasticsearch.yml 增加配置 network.host: 0.0.0.0(注意yaml配置文件格式,冒号后面有个空格)
root@ubuntu:/usr/local/elastic/elasticsearch-6.8.8/config# vim elasticsearch.yml
#network.host: 192.168.0.1
network.host: 0.0.0.0
#
修改 /etc/security/limits.conf 文件 如果您在修改上面配置后报错:max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
wl soft nproc 4097
wl hard nproc 4097
wl soft nfile 65536
wl hard nfile 65536
修改后需要用户退出登陆后再次登陆 即执行su wl (上面wl为我的启动elasticservice的用户名称)
使用 ulimit -a 或者 ulimit -Hu 和 ulimit -Hn命令查看
wl@ubuntu:~$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 15651
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 65536
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 4097
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
wl@ubuntu:~$
如果您在配置了/etc/security/limits.conf文件并重新登陆之后却没有修改成功,您需要修改您的sshd_config文件 加入下面两个配置
参考
https://manpages.ubuntu.com/manpages/hirsute/en/man5/limits.conf.5.html
https://www.cnblogs.com/zjsylg/p/10470469.html
UsePAM yes
UseLogin yes
注意sshd_config文件的位置。一般默认在/etc/ssh/ 目录下,不过我的目录为/usr/local/etc/。参考我的openssh安装 openssh的安装
wl@ubuntu:/usr/local/etc$ ls
moduli ssh_config sshd_config ssh_host_dsa_key ssh_host_dsa_key.pub ssh_host_ecdsa_key ssh_host_ecdsa_key.pub ssh_host_ed25519_key ssh_host_ed25519_key.pub ssh_host_rsa_key ssh_host_rsa_key.pub
wl@ubuntu:/usr/local/etc$
修改 /etc/sysctl.conf 如果您在修改上面配置后报错:max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
root@ubuntu:/home/wl# vim /etc/sysctl.conf
#
vm.max_map_count=262144
执行 sysctl -p 使配置生效
root@ubuntu:/home/wl# sysctl -p
vm.max_map_count = 262144
重新启动elasticsearch
wl@ubuntu:/usr/local/elastic/elasticsearch-6.8.8$ bin/elasticsearch
[2021-03-13T23:27:53,881][INFO ][o.e.e.NodeEnvironment ] [hui1XcR] using [1] data paths, mounts [[/ (/dev/sda1)]], net usable_space [25.4gb], net total_space [38.2gb], types [ext4]
[2021-03-13T23:27:53,891][INFO ][o.e.e.NodeEnvironment ] [hui1XcR] heap size [503.6mb], compressed ordinary object pointers [true]
[2021-03-13T23:27:53,894][INFO ][o.e.n.Node ] [hui1XcR] node name derived from node ID [hui1XcRuTFify9PvyVUQng]; set [node.name] to override
[2021-03-13T23:27:53,896][INFO ][o.e.n.Node ] [hui1XcR] version[6.8.8], pid[2127], build[default/tar/2f4c224/2020-03-18T23:22:18.622755Z], OS[Linux/4.4.0-31-generic/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_121/25.121-b13]
[2021-03-13T23:27:53,897][INFO ][o.e.n.Node ] [hui1XcR] JVM arguments [-Xms512m, -Xmx512m, -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-6323344320266411338, -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/local/elastic/elasticsearch-6.8.8, -Des.path.conf=/usr/local/elastic/elasticsearch-6.8.8/config, -Des.distribution.flavor=default, -Des.distribution.type=tar]
[2021-03-13T23:27:57,051][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [aggs-matrix-stats]
[2021-03-13T23:27:57,052][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [analysis-common]
[2021-03-13T23:27:57,052][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [ingest-common]
[2021-03-13T23:27:57,053][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [ingest-geoip]
[2021-03-13T23:27:57,053][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [ingest-user-agent]
[2021-03-13T23:27:57,054][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [lang-expression]
[2021-03-13T23:27:57,054][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [lang-mustache]
[2021-03-13T23:27:57,054][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [lang-painless]
[2021-03-13T23:27:57,054][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [mapper-extras]
[2021-03-13T23:27:57,055][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [parent-join]
[2021-03-13T23:27:57,055][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [percolator]
[2021-03-13T23:27:57,055][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [rank-eval]
[2021-03-13T23:27:57,056][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [reindex]
[2021-03-13T23:27:57,056][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [repository-url]
[2021-03-13T23:27:57,057][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [transport-netty4]
[2021-03-13T23:27:57,057][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [tribe]
[2021-03-13T23:27:57,057][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [x-pack-ccr]
[2021-03-13T23:27:57,058][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [x-pack-core]
[2021-03-13T23:27:57,058][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [x-pack-deprecation]
[2021-03-13T23:27:57,058][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [x-pack-graph]
[2021-03-13T23:27:57,059][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [x-pack-ilm]
[2021-03-13T23:27:57,059][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [x-pack-logstash]
[2021-03-13T23:27:57,060][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [x-pack-ml]
[2021-03-13T23:27:57,060][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [x-pack-monitoring]
[2021-03-13T23:27:57,061][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [x-pack-rollup]
[2021-03-13T23:27:57,065][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [x-pack-security]
[2021-03-13T23:27:57,065][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [x-pack-sql]
[2021-03-13T23:27:57,066][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [x-pack-upgrade]
[2021-03-13T23:27:57,066][INFO ][o.e.p.PluginsService ] [hui1XcR] loaded module [x-pack-watcher]
[2021-03-13T23:27:57,067][INFO ][o.e.p.PluginsService ] [hui1XcR] no plugins loaded
[2021-03-13T23:28:03,046][INFO ][o.e.x.s.a.s.FileRolesStore] [hui1XcR] parsed [0] roles from file [/usr/local/elastic/elasticsearch-6.8.8/config/roles.yml]
[2021-03-13T23:28:04,014][INFO ][o.e.x.m.p.l.CppLogMessageHandler] [hui1XcR] [controller/2182] [Main.cc@109] controller (64 bit): Version 6.8.8 (Build 398321ce7838fd) Copyright (c) 2020 Elasticsearch BV
[2021-03-13T23:28:04,793][DEBUG][o.e.a.ActionModule ] [hui1XcR] Using REST wrapper from plugin org.elasticsearch.xpack.security.Security
[2021-03-13T23:28:05,158][INFO ][o.e.d.DiscoveryModule ] [hui1XcR] using discovery type [zen] and host providers [settings]
[2021-03-13T23:28:06,460][INFO ][o.e.n.Node ] [hui1XcR] initialized
[2021-03-13T23:28:06,465][INFO ][o.e.n.Node ] [hui1XcR] starting ...
[2021-03-13T23:28:06,761][INFO ][o.e.t.TransportService ] [hui1XcR] publish_address {192.168.92.128:9300}, bound_addresses {[::]:9300}
[2021-03-13T23:28:06,800][INFO ][o.e.b.BootstrapChecks ] [hui1XcR] bound or publishing to a non-loopback address, enforcing bootstrap checks
[2021-03-13T23:28:09,901][INFO ][o.e.c.s.MasterService ] [hui1XcR] zen-disco-elected-as-master ([0] nodes joined), reason: new_master {hui1XcR}{hui1XcRuTFify9PvyVUQng}{5ofZJEd4Sg25GxijN29Mmw}{192.168.92.128}{192.168.92.128:9300}{ml.machine_memory=4125745152, xpack.installed=true, ml.max_open_jobs=20, ml.enabled=true}
[2021-03-13T23:28:09,909][INFO ][o.e.c.s.ClusterApplierService] [hui1XcR] new_master {hui1XcR}{hui1XcRuTFify9PvyVUQng}{5ofZJEd4Sg25GxijN29Mmw}{192.168.92.128}{192.168.92.128:9300}{ml.machine_memory=4125745152, xpack.installed=true, ml.max_open_jobs=20, ml.enabled=true}, reason: apply cluster state (from master [master {hui1XcR}{hui1XcRuTFify9PvyVUQng}{5ofZJEd4Sg25GxijN29Mmw}{192.168.92.128}{192.168.92.128:9300}{ml.machine_memory=4125745152, xpack.installed=true, ml.max_open_jobs=20, ml.enabled=true} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]])
[2021-03-13T23:28:10,019][INFO ][o.e.h.n.Netty4HttpServerTransport] [hui1XcR] publish_address {192.168.92.128:9200}, bound_addresses {[::]:9200}
[2021-03-13T23:28:10,020][INFO ][o.e.n.Node ] [hui1XcR] started
[2021-03-13T23:28:10,290][WARN ][o.e.x.s.a.s.m.NativeRoleMappingStore] [hui1XcR] Failed to clear cache for realms [[]]
[2021-03-13T23:28:10,397][INFO ][o.e.l.LicenseService ] [hui1XcR] license [fd12b973-1cd9-477b-b535-10de34e41128] mode [basic] - valid
[2021-03-13T23:28:10,415][INFO ][o.e.g.GatewayService ] [hui1XcR] recovered [0] indices into cluster_state
启动成功
可以通过非localhost访问了