1. 环境与版本
- 服务器环境:Ubuntu 16.04
- JDK8,ES最低要求版本是jdk8
- Elasticsearch-6.2.4
安装Elasticsearch前先安装JDK8
2. 下载Elasticsearch-6.2.4
- 进入下载目录
cd /var/webdata/
- 下载
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.4.zip
- 解压
unzip elasticsearch-6.2.4.zip
- 进入elasticsearch目录,启动程序
cd elasticsearch-6.2.4
./bin/elasticsearch
如果你当前为root账号启动会报错,这是出于系统安全考虑,ElasticSearch不允许以root账号启动。
3. 创建账号
- 新建组
groupadd webdata
- 新建用户
useradd webdata -g webdata -p webdatapass
- 更改ElasticSearch文件夹及内部文件的所属用户及组webdata:webdata
cd /var/
chown -R webdata:webdata webdatapass
4. 运行ElasticSearch
- 切换为非root账号并进入目录
su webdata
cd /var/webdata
./bin/elasticsearch
- 运行
./bin/elasticsearch
此运行方式通过Ctrl-C即可停止,非后台运行
- 后台运行方式
./bin/elasticsearch -d
- 通过curl查看启动结果
{
"name" : "hGnygOr",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "rGteQVtDRaO2iauwdQu4ug",
"version" : {
"number" : "6.2.4",
"build_hash" : "ccec39f",
"build_date" : "2018-04-12T20:37:28.497551Z",
"build_snapshot" : false,
"lucene_version" : "7.2.1",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
- 虽然启动成功,但只能本机可以访问。如果想要外部机器通过192.168.3.163:9200机器也能访问,需要修改配置
vi elasticsearch-6.2.4/config/elasticsearch.yml
找到这一行
#network.host: 192.168.0.1
修改为:
network.host: 0.0.0.0
然后重启ElasticSearch,即可通过浏览器访问。
- 启动日志
[2018-05-10T13:23:34,133][INFO ][o.e.n.Node ] [] initializing ...
[2018-05-10T13:23:34,324][INFO ][o.e.e.NodeEnvironment ] [hGnygOr] using [1] data paths, mounts [[/ (/dev/sda1)]], net usable_space [1.8tb], net total_space [1.9tb], types [ext4]
[2018-05-10T13:23:34,325][INFO ][o.e.e.NodeEnvironment ] [hGnygOr] heap size [989.8mb], compressed ordinary object pointers [true]
[2018-05-10T13:23:34,327][INFO ][o.e.n.Node ] node name [hGnygOr] derived from node ID [hGnygOrlRGuwNWiKjj4ldQ]; set [node.name] to override
[2018-05-10T13:23:34,334][INFO ][o.e.n.Node ] version[6.2.4], pid[7080], build[ccec39f/2018-04-12T20:37:28.497551Z], OS[Linux/4.4.0-124-generic/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_77/25.77-b03]
[2018-05-10T13:23:34,334][INFO ][o.e.n.Node ] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -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.3i6VR95K, -XX:+HeapDumpOnOutOfMemoryError, -XX:+PrintGCDetails, -XX:+PrintGCDateStamps, -XX:+PrintTenuringDistribution, -XX:+PrintGCApplicationStoppedTime, -Xloggc:logs/gc.log, -XX:+UseGCLogFileRotation, -XX:NumberOfGCLogFiles=32, -XX:GCLogFileSize=64m, -Des.path.home=/var/myapp/elasticsearch-6.2.4, -Des.path.conf=/var/myapp/elasticsearch-6.2.4/config]
[2018-05-10T13:23:35,086][INFO ][o.e.p.PluginsService ] [hGnygOr] loaded module [aggs-matrix-stats]
[2018-05-10T13:23:35,086][INFO ][o.e.p.PluginsService ] [hGnygOr] loaded module [analysis-common]
[2018-05-10T13:23:35,086][INFO ][o.e.p.PluginsService ] [hGnygOr] loaded module [ingest-common]
[2018-05-10T13:23:35,087][INFO ][o.e.p.PluginsService ] [hGnygOr] loaded module [lang-expression]
[2018-05-10T13:23:35,087][INFO ][o.e.p.PluginsService ] [hGnygOr] loaded module [lang-mustache]
[2018-05-10T13:23:35,087][INFO ][o.e.p.PluginsService ] [hGnygOr] loaded module [lang-painless]
[2018-05-10T13:23:35,087][INFO ][o.e.p.PluginsService ] [hGnygOr] loaded module [mapper-extras]
[2018-05-10T13:23:35,087][INFO ][o.e.p.PluginsService ] [hGnygOr] loaded module [parent-join]
[2018-05-10T13:23:35,087][INFO ][o.e.p.PluginsService ] [hGnygOr] loaded module [percolator]
[2018-05-10T13:23:35,087][INFO ][o.e.p.PluginsService ] [hGnygOr] loaded module [rank-eval]
[2018-05-10T13:23:35,088][INFO ][o.e.p.PluginsService ] [hGnygOr] loaded module [reindex]
[2018-05-10T13:23:35,088][INFO ][o.e.p.PluginsService ] [hGnygOr] loaded module [repository-url]
[2018-05-10T13:23:35,088][INFO ][o.e.p.PluginsService ] [hGnygOr] loaded module [transport-netty4]
[2018-05-10T13:23:35,088][INFO ][o.e.p.PluginsService ] [hGnygOr] loaded module [tribe]
[2018-05-10T13:23:35,088][INFO ][o.e.p.PluginsService ] [hGnygOr] no plugins loaded
[2018-05-10T13:23:37,432][INFO ][o.e.d.DiscoveryModule ] [hGnygOr] using discovery type [zen]
[2018-05-10T13:23:37,872][INFO ][o.e.n.Node ] initialized
[2018-05-10T13:23:37,872][INFO ][o.e.n.Node ] [hGnygOr] starting ...
[2018-05-10T13:23:37,994][INFO ][o.e.t.TransportService ] [hGnygOr] publish_address {192.168.3.164:9300}, bound_addresses {[::]:9300}
[2018-05-10T13:23:38,003][INFO ][o.e.b.BootstrapChecks ] [hGnygOr] bound or publishing to a non-loopback address, enforcing bootstrap checks
[2018-05-10T13:23:41,082][INFO ][o.e.c.s.MasterService ] [hGnygOr] zen-disco-elected-as-master ([0] nodes joined), reason: new_master {hGnygOr}{hGnygOrlRGuwNWiKjj4ldQ}{Cgs1fRXYQNCrY8ad-5tYIw}{192.168.3.164}{192.168.3.164:9300}
[2018-05-10T13:23:41,089][INFO ][o.e.c.s.ClusterApplierService] [hGnygOr] new_master {hGnygOr}{hGnygOrlRGuwNWiKjj4ldQ}{Cgs1fRXYQNCrY8ad-5tYIw}{192.168.3.164}{192.168.3.164:9300}, reason: apply cluster state (from master [master {hGnygOr}{hGnygOrlRGuwNWiKjj4ldQ}{Cgs1fRXYQNCrY8ad-5tYIw}{192.168.3.164}{192.168.3.164:9300} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]])
[2018-05-10T13:23:41,114][INFO ][o.e.h.n.Netty4HttpServerTransport] [hGnygOr] publish_address {192.168.3.164:9200}, bound_addresses {[::]:9200}
[2018-05-10T13:23:41,114][INFO ][o.e.n.Node ] [hGnygOr] started
[2018-05-10T13:23:41,210][INFO ][o.e.g.GatewayService ] [hGnygOr] recovered [0] indices into cluster_state
5. 如果启动失败,报以下错误:
[2018-05-10T08:09:13,160][INFO ][o.e.n.Node ] initialized
[2018-05-10T08:09:13,160][INFO ][o.e.n.Node ] [hGnygOr] starting ...
[2018-05-10T08:09:13,279][INFO ][o.e.t.TransportService ] [hGnygOr] publish_address {192.168.3.164:9300}, bound_addresses {[::]:9300}
[2018-05-10T08:09:13,288][INFO ][o.e.b.BootstrapChecks ] [hGnygOr] bound or publishing to a non-loopback address, enforcing bootstrap checks
ERROR: [1] bootstrap checks failed
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2018-05-10T08:09:13,296][INFO ][o.e.n.Node ] [hGnygOr] stopping ...
[2018-05-10T08:09:13,481][INFO ][o.e.n.Node ] [hGnygOr] stopped
[2018-05-10T08:09:13,481][INFO ][o.e.n.Node ] [hGnygOr] closing ...
[2018-05-10T08:09:13,494][INFO ][o.e.n.Node ] [hGnygOr] closed
- 解决办法
切换为root账号,编辑sysctl.conf
文件
vim /etc/sysctl.conf
增加一行:
vm.max_map_count=655360
保存后,执行命令立即生效
sysctl -p
再切换为webdata
账号启动ES即可。
参考资料
https://my.oschina.net/topeagle/blog/591451?fromerr=mzOr2qzZ
https://blog.csdn.net/gebitan505/article/details/54709515
https://blog.csdn.net/chengyuqiang/article/details/78837712
网友评论