公司目前用的ElasticSearch 5.x
这里转载一篇ElasticSearch 6.x版本的安装及配置教程,方便日后查阅。
原文地址:ElasticSearch 6.x 学习笔记:1.下载安装与配置,转载烦请注明原文地址。
1. 安装配置JDK 8
(1)下载并解压缩
[root@node1 ~]# tar -zxvf jdk-8u112-linux-x64.tar.gz -C /opt
(2)编辑环境变量
vi /etc/profile.d/custom.sh
[root@node1 ~]# vi /etc/profile.d/custom.sh
[root@node1 ~]# cat /etc/profile.d/custom.sh
#!/bin/bash
#java path
export JAVA_HOME=/opt/jdk1.8.0_112
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib
(3)生效
[root@node1 ~]# source /etc/profile.d/custom.sh
(4)查看JDK版本
[root@node1 ~]# java -version
java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)
[root@node1 ~]#
2. 创建用户
从5.0开始,ElasticSearch 安全级别提高了,不允许采用root帐号启动,所以我们要添加一个用户。
(1)创建bigdata 用户组
[root@node1 ~]# groupadd bigdata
(2)创建用户es
[root@node1 ~]# useradd es
[root@node1 ~]# passwd es
Changing password for user es.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@node1 ~]#
(3)将es用户添加到bigdata组
[root@node1 ~]# usermod -G bigdata es
(4)设置sudo权限
[root@node1 ~]# visudo
找到root ALL=(ALL) ALL
一行,添加es用户,如下。
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
es ALL=(ALL) ALL
(5)切换用户
[root@node1 ~]# su es
[es@node1 root]$ cd
[es@node1 ~]$
3. ElasticSearch 6.x 软件包下载
(1)ElasticSearch官网
https://www.elastic.co/cn/downloads
(2)下载ElasticSearch
https://www.elastic.co/downloads/elasticsearch
[es@node1 ~]$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.1.1.tar.gz
--2018-01-06 08:24:06-- https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.1.1.tar.gz
Resolving artifacts.elastic.co (artifacts.elastic.co)... 54.225.188.6, 54.243.108.41, 184.72.218.26, ...
Connecting to artifacts.elastic.co (artifacts.elastic.co)|54.225.188.6|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 28462503 (27M) [application/x-gzip]
Saving to: ‘elasticsearch-6.1.1.tar.gz.1’
100%[===================================================================================================================================================>] 28,462,503 232KB/s in 3m 33s
2018-01-06 08:27:42 (130 KB/s) - ‘elasticsearch-6.1.1.tar.gz.1’ saved [28462503/28462503]
[es@node1 ~]$
(3)解压缩
tar -zxvf elasticsearch-6.1.1.tar.gz
[es@node1 ~]$ tar -zxvf elasticsearch-6.1.1.tar.gz
[es@node1 ~]$ sudo mv elasticsearch-6.1.1 /opt
(4)修改目录权限
更改elasticsearch-6.1.1文件夹以及内部文件的所属用户为es, 用户组组为bigdata,-R表示逐级(N层目录)
[es@node1 ~]$ sudo chown -R es:bigdata /opt/elasticsearch-6.1.1
[es@node1 ~]$ ll /opt/elasticsearch-6.1.1
total 220
drwxr-xr-x 2 es bigdata 4096 Jan 6 08:35 bin
drwxr-xr-x 2 es bigdata 75 Dec 17 15:24 config
drwxr-xr-x 2 es bigdata 4096 Dec 17 15:24 lib
-rw-r--r-- 1 es bigdata 11358 Dec 17 15:22 LICENSE.txt
drwxr-xr-x 15 es bigdata 272 Dec 17 15:24 modules
-rw-r--r-- 1 es bigdata 191887 Dec 17 15:24 NOTICE.txt
drwxr-xr-x 2 es bigdata 6 Dec 17 15:24 plugins
-rw-r--r-- 1 es bigdata 9326 Dec 17 15:22 README.textile
[es@node1 ~]$
4. ElasticSearch 配置
(1)修改elasticsearch.yml
[es@node1 elasticsearch-6.1.1]$ vi config/elasticsearch.yml
修改network.host和http.port
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 192.168.80.131
#
# Set a custom port for HTTP:
#
http.port: 9200
保存退出。
(2)修改/etc/sysctl.conf
切换到root用户,
[root@node1 elasticsearch-6.1.1]# vi /etc/sysctl.conf
添加内容如下:
vm.max_map_count=262144
用命令sysctl -p 生效
[root@node1 ~]# sysctl -p
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
vm.max_map_count = 262144
[root@node1 ~]#
(3)修改文件/etc/security/limits.conf
[root@node1 logs]# vi /etc/security/limits.conf
添加如下内容
* hard nofile 65536
* soft nofile 65536
* soft nproc 2048
* hard nproc 4096
# End of file
5.ElasticSearch启动与停止
(1)直接启动
[es@node1 elasticsearch-6.1.1]$ bin/elasticsearch
[2018-01-06T08:53:21,796][INFO ][o.e.n.Node ] [] initializing ...
[2018-01-06T08:53:21,941][INFO ][o.e.e.NodeEnvironment ] [cNWkQjt] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [13.8gb], net total_space [21.9gb], types [rootfs]
[2018-01-06T08:53:21,941][INFO ][o.e.e.NodeEnvironment ] [cNWkQjt] heap size [1007.3mb], compressed ordinary object pointers [true]
[2018-01-06T08:53:21,945][INFO ][o.e.n.Node ] node name [cNWkQjt] derived from node ID [cNWkQjt9SzKFNtyx8IIu-A]; set [node.name] to override
[2018-01-06T08:53:21,945][INFO ][o.e.n.Node ] version[6.1.1], pid[2752], build[bd92e7f/2017-12-17T20:23:25.338Z], OS[Linux/3.10.0-514.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_112/25.112-b15]
[2018-01-06T08:53:21,946][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, -XX:+HeapDumpOnOutOfMemoryError, -Des.path.home=/opt/elasticsearch-6.1.1, -Des.path.conf=/opt/elasticsearch-6.1.1/config]
[2018-01-06T08:53:23,614][INFO ][o.e.p.PluginsService ] [cNWkQjt] loaded module [aggs-matrix-stats]
[2018-01-06T08:53:23,615][INFO ][o.e.p.PluginsService ] [cNWkQjt] loaded module [analysis-common]
[2018-01-06T08:53:23,615][INFO ][o.e.p.PluginsService ] [cNWkQjt] loaded module [ingest-common]
[2018-01-06T08:53:23,615][INFO ][o.e.p.PluginsService ] [cNWkQjt] loaded module [lang-expression]
[2018-01-06T08:53:23,615][INFO ][o.e.p.PluginsService ] [cNWkQjt] loaded module [lang-mustache]
[2018-01-06T08:53:23,615][INFO ][o.e.p.PluginsService ] [cNWkQjt] loaded module [lang-painless]
[2018-01-06T08:53:23,616][INFO ][o.e.p.PluginsService ] [cNWkQjt] loaded module [mapper-extras]
[2018-01-06T08:53:23,616][INFO ][o.e.p.PluginsService ] [cNWkQjt] loaded module [parent-join]
[2018-01-06T08:53:23,616][INFO ][o.e.p.PluginsService ] [cNWkQjt] loaded module [percolator]
[2018-01-06T08:53:23,616][INFO ][o.e.p.PluginsService ] [cNWkQjt] loaded module [reindex]
[2018-01-06T08:53:23,616][INFO ][o.e.p.PluginsService ] [cNWkQjt] loaded module [repository-url]
[2018-01-06T08:53:23,617][INFO ][o.e.p.PluginsService ] [cNWkQjt] loaded module [transport-netty4]
[2018-01-06T08:53:23,617][INFO ][o.e.p.PluginsService ] [cNWkQjt] loaded module [tribe]
[2018-01-06T08:53:23,618][INFO ][o.e.p.PluginsService ] [cNWkQjt] no plugins loaded
[2018-01-06T08:53:26,588][INFO ][o.e.d.DiscoveryModule ] [cNWkQjt] using discovery type [zen]
[2018-01-06T08:53:27,618][INFO ][o.e.n.Node ] initialized
[2018-01-06T08:53:27,619][INFO ][o.e.n.Node ] [cNWkQjt] starting ...
[2018-01-06T08:53:27,836][INFO ][o.e.t.TransportService ] [cNWkQjt] publish_address {192.168.80.131:9300}, bound_addresses {192.168.80.131:9300}
[2018-01-06T08:53:27,860][INFO ][o.e.b.BootstrapChecks ] [cNWkQjt] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
[2018-01-06T08:53:30,984][INFO ][o.e.c.s.MasterService ] [cNWkQjt] zen-disco-elected-as-master ([0] nodes joined), reason: new_master {cNWkQjt}{cNWkQjt9SzKFNtyx8IIu-A}{eRRknS3vQ52ffJA8I2u9iQ}{192.168.80.131}{192.168.80.131:9300}
[2018-01-06T08:53:30,992][INFO ][o.e.c.s.ClusterApplierService] [cNWkQjt] new_master {cNWkQjt}{cNWkQjt9SzKFNtyx8IIu-A}{eRRknS3vQ52ffJA8I2u9iQ}{192.168.80.131}{192.168.80.131:9300}, reason: apply cluster state (from master [master {cNWkQjt}{cNWkQjt9SzKFNtyx8IIu-A}{eRRknS3vQ52ffJA8I2u9iQ}{192.168.80.131}{192.168.80.131:9300} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]])
[2018-01-06T08:53:31,073][INFO ][o.e.h.n.Netty4HttpServerTransport] [cNWkQjt] publish_address {192.168.80.131:9200}, bound_addresses {192.168.80.131:9200}
[2018-01-06T08:53:31,073][INFO ][o.e.n.Node ] [cNWkQjt] started
[2018-01-06T08:53:31,094][INFO ][o.e.g.GatewayService ] [cNWkQjt] recovered [0] indices into cluster_state
(2)停止
ctrl+c停止。
^C[2018-01-06T08:55:24,513][INFO ][o.e.n.Node ] [cNWkQjt] stopping ...
[2018-01-06T08:55:24,568][INFO ][o.e.n.Node ] [cNWkQjt] stopped
[2018-01-06T08:55:24,569][INFO ][o.e.n.Node ] [cNWkQjt] closing ...
[2018-01-06T08:55:24,585][INFO ][o.e.n.Node ] [cNWkQjt] closed
[es@node1 elasticsearch-6.1.1]$
(3)后台运行
可以通过参数-d后台运行
[es@node1 elasticsearch-6.1.1]$ bin/elasticsearch -d
(4)查询进程
[es@node1 elasticsearch-6.1.1]$ jps
3120 Elasticsearch
3135 Jps
[es@node1 elasticsearch-6.1.1]$
6. 验证
(1)使用curl验证
[es@node1 elasticsearch-6.1.1]$ curl http://192.168.80.131:9200
{
"name" : "cNWkQjt",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "Kd_e-tqxSx20dl_HjAt1ZQ",
"version" : {
"number" : "6.1.1",
"build_hash" : "bd92e7f",
"build_date" : "2017-12-17T20:23:25.338Z",
"build_snapshot" : false,
"lucene_version" : "7.1.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
[es@node1 elasticsearch-6.1.1]$
(2)浏览器验证
http://node1:9200/
如果在Windows平台通过浏览器打开,需要配置hosts。编辑C:\Windows\System32\drivers\etc\hosts
添加
192.168.80.131 node1
6.问题解决
(1)jps看不到Java进程
[es@node1 elasticsearch-6.1.1]$ bin/elasticsearch -d
[es@node1 elasticsearch-6.1.1]$ jps
[es@node1 elasticsearch-6.1.1]$ jps
[es@node1 elasticsearch-6.1.1]$ ps -aux|grep elasticsearch
es 2930 125 65.2 3627480 1218920 pts/0 Sl 09:33 0:15 /opt/jdk1.8.0_112/bin/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+AlwaysPreTouch -server -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 -XX:+HeapDumpOnOutOfMemoryError -Des.path.home=/opt/elasticsearch-6.1.1 -Des.path.conf=/opt/elasticsearch-6.1.1/config -cp /opt/elasticsearch-6.1.1/lib/* org.elasticsearch.bootstrap.Elasticsearch -d
es 2998 0.0 0.0 112660 968 pts/0 S+ 09:33 0:00 grep --color=auto elasticsearch
[es@node1 elasticsearch-6.1.1]$
查找原因
[es@node1 ~]$ ll /tmp
total 0
drwxr-xr-x 2 1000 1000 6 Jan 5 10:28 hsperfdata_es
drwxr-xr-x 2 root root 6 Jan 6 08:56 hsperfdata_root
drwxrwxr-x 2 1000 1000 6 Jan 5 10:21 jna-3246
drwxrwxr-x 3 1000 1000 32 Jan 5 09:40 npm-2339-f258bfea
drwxr-xr-x 3 root root 37 Jan 5 09:46 npm-2381-44b2a32e
drwxrwxr-x 3 es es 37 Jan 6 02:21 npm-2404-e0646f46
drwxrwxr-x 2 es es 6 Jan 6 02:24 npm-2416-56232d2b
drwxr-xr-x 3 root root 37 Jan 6 02:25 npm-2427-ac7dea5c
drwxrwxr-x 3 1000 1000 32 Jan 5 09:54 npm-2466-3358fd28
drwxrwxr-x 3 1000 1000 37 Jan 5 10:09 npm-2590-5ae8499b
drwxrwxrwx 5 1000 1000 202 Jan 6 02:27 phantomjs
drwx------ 3 root root 17 Jan 6 09:12 systemd-private-3333a83cac6947c59f5bb80f042de342-vmtoolsd.service-nRUgwa
[es@node1 ~]$
原因是当前es用户没有/tmp/hsperfdata_es目录的写权限。
解决办法:
[root@node1 ~]# chown -R es:es /tmp/hsperfdata_es