Centos下搭建ElasticSearch

Centos 7下搭建ElasticSearch

JDK

首先,ES是java开发的,所以,通性,懂得,装JDK,好在linux下一条命令行就可以解决:

1
2
# 安装1.8.0的所有文件
yum install java-1.8.0-openjdk* -y

校验:

1
2
java -version
javac
1
2
3
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)

很正常,完成。

ElasticSearch

下载

下载很简单:

1
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.2.zip

然后解压缩就可以了

1
unzip elasticsearch-6.3.2.zip

启动

1
2
cd elasticsearch-6.3.2/bin
./elasticsearch

嗯,然后问题就开始了~

配置

root用户登录的系统,启es,会报错:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[2018-01-28T22:00:31,358][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] 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:125) ~[elasticsearch-6.1.2.jar:6.1.2]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-6.1.2.jar:6.1.2]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.1.2.jar:6.1.2]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.1.2.jar:6.1.2]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.1.2.jar:6.1.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-6.1.2.jar:6.1.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:85) ~[elasticsearch-6.1.2.jar:6.1.2]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:104) ~[elasticsearch-6.1.2.jar:6.1.2]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:171) ~[elasticsearch-6.1.2.jar:6.1.2]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:322) ~[elasticsearch-6.1.2.jar:6.1.2]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-6.1.2.jar:6.1.2]
... 6 more

很明显,人家不让你用root启服务

创建es用户

不让用root就创建一个es的用户:

1
2
3
4
# 创建es组
groupadd elasticsearch
# 在es组下创建es用户,并设置密码为elasticsearch
useradd elasticsearch -g elasticsearch -p elasticsearch

然后将前面下载的elasticsearch-6.3.2.zip包拷贝到es家目录下:

1
cp elasticsearch-6.3.2.zip /home/elasticsearch

解压缩:

1
unzip elasticsearch-6.3.2.zip

更改文件夹属主和属组:

1
chown -R elasticsearch:elasticsearch elasticsearch-6.1.2/

然后切换到es用户,启服务:

1
2
su - elasticsearch
./bin/elasticsearch

然后就可以看见服务基本是正常起来了:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
[2018-07-31T22:11:06,918][INFO ][o.e.n.Node               ] [] initializing ...
[2018-07-31T22:11:07,161][INFO ][o.e.e.NodeEnvironment ] [qR5cyzh] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [12.5gb], net total_space [17.6gb], types [rootfs]
[2018-07-31T22:11:07,162][INFO ][o.e.e.NodeEnvironment ] [qR5cyzh] heap size [1015.6mb], compressed ordinary object pointers [true]
[2018-07-31T22:11:07,163][INFO ][o.e.n.Node ] node name [qR5cyzh] derived from node ID [qR5cyzhRQUix7PbCNFViTw]; set [node.name] to override
[2018-07-31T22:11:07,163][INFO ][o.e.n.Node ] version[6.1.2], pid[7200], build[5b1fea5/2018-01-10T02:35:59.208Z], OS[Linux/3.10.0-514.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_141/25.141-b15]
[2018-07-31T22:11:07,163][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=/home/elasticsearch/elasticsearch-6.1.2, -Des.path.conf=/home/elasticsearch/elasticsearch-6.1.2/config]
[2018-07-31T22:11:09,295][INFO ][o.e.p.PluginsService ] [qR5cyzh] loaded module [aggs-matrix-stats]
[2018-07-31T22:11:09,295][INFO ][o.e.p.PluginsService ] [qR5cyzh] loaded module [analysis-common]
[2018-07-31T22:11:09,295][INFO ][o.e.p.PluginsService ] [qR5cyzh] loaded module [ingest-common]
[2018-07-31T22:11:09,296][INFO ][o.e.p.PluginsService ] [qR5cyzh] loaded module [lang-expression]
[2018-07-31T22:11:09,296][INFO ][o.e.p.PluginsService ] [qR5cyzh] loaded module [lang-mustache]
[2018-07-31T22:11:09,296][INFO ][o.e.p.PluginsService ] [qR5cyzh] loaded module [lang-painless]
[2018-07-31T22:11:09,296][INFO ][o.e.p.PluginsService ] [qR5cyzh] loaded module [mapper-extras]
[2018-07-31T22:11:09,296][INFO ][o.e.p.PluginsService ] [qR5cyzh] loaded module [parent-join]
[2018-07-31T22:11:09,296][INFO ][o.e.p.PluginsService ] [qR5cyzh] loaded module [percolator]
[2018-07-31T22:11:09,296][INFO ][o.e.p.PluginsService ] [qR5cyzh] loaded module [reindex]
[2018-07-31T22:11:09,296][INFO ][o.e.p.PluginsService ] [qR5cyzh] loaded module [repository-url]
[2018-07-31T22:11:09,296][INFO ][o.e.p.PluginsService ] [qR5cyzh] loaded module [transport-netty4]
[2018-07-31T22:11:09,296][INFO ][o.e.p.PluginsService ] [qR5cyzh] loaded module [tribe]
[2018-07-31T22:11:09,297][INFO ][o.e.p.PluginsService ] [qR5cyzh] no plugins loaded
[2018-07-31T22:11:13,791][INFO ][o.e.d.DiscoveryModule ] [qR5cyzh] using discovery type [zen]
[2018-07-31T22:11:14,926][INFO ][o.e.n.Node ] initialized
[2018-07-31T22:11:14,927][INFO ][o.e.n.Node ] [qR5cyzh] starting ...
[2018-07-31T22:11:15,582][INFO ][o.e.t.TransportService ] [qR5cyzh] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300}
[2018-07-31T22:11:15,598][WARN ][o.e.b.BootstrapChecks ] [qR5cyzh] max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2018-07-31T22:11:15,598][WARN ][o.e.b.BootstrapChecks ] [qR5cyzh] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2018-07-31T22:11:18,915][INFO ][o.e.c.s.MasterService ] [qR5cyzh] zen-disco-elected-as-master ([0] nodes joined), reason: new_master {qR5cyzh}{qR5cyzhRQUix7PbCNFViTw}{wRzc-CVaRmmdLNnPfT_LTA}{127.0.0.1}{127.0.0.1:9300}
[2018-07-31T22:11:18,920][INFO ][o.e.c.s.ClusterApplierService] [qR5cyzh] new_master {qR5cyzh}{qR5cyzhRQUix7PbCNFViTw}{wRzc-CVaRmmdLNnPfT_LTA}{127.0.0.1}{127.0.0.1:9300}, reason: apply cluster state (from master [master {qR5cyzh}{qR5cyzhRQUix7PbCNFViTw}{wRzc-CVaRmmdLNnPfT_LTA}{127.0.0.1}{127.0.0.1:9300} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]])
[2018-07-31T22:11:19,028][INFO ][o.e.g.GatewayService ] [qR5cyzh] recovered [0] indices into cluster_state
[2018-07-31T22:11:19,097][INFO ][o.e.h.n.Netty4HttpServerTransport] [qR5cyzh] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
[2018-07-31T22:11:19,097][INFO ][o.e.n.Node ] [qR5cyzh] started

验证:

1
curl "127.0.0.1:9200"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
"name" : "snZNWBu",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "9k1xyJl4S6uoosA_Ua0XEQ",
"version" : {
"number" : "6.3.2",
"build_flavor" : "default",
"build_type" : "zip",
"build_hash" : "053779d",
"build_date" : "2018-07-20T05:20:23.451332Z",
"build_snapshot" : false,
"lucene_version" : "7.3.1",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}

更改静态IP

本地是可以用,但是试了下,由于centos是在虚拟机里面,在外面机器,访问虚拟机ip就打不开es了,没办法,将es设置成静态IP
修改配置文件/confif/elasticsearch.yml,修改IP为静态IP:

1
2
3
4
5
6
7
8
9
10
11
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 192.168.0.91
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, consult the network module documentation.

然后重启es,发现,嗯,还是起不来,又报了俩错:

1
2
3
ERROR: [2] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

切到root下,修改对应配置文件:

1
2
3
4
5
cd /etc/security/
# 日常备份
cp limits.conf limits.conf.bak
# 修改配置
vim limits.conf

增加内容:

1
2
3
4
5
6
# elasticsearch config start
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
# elasticsearch config end

max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

也是切root改配置

1
2
3
cd /etc
cp sysctl.conf sysctl.conf.bak
vim sysctl.conf

增加内容:

1
2
3
# elasticsearch config start
vm.max_map_count=262144
# elasticsearch config end

重启系统

然后切到es用户,重启服务,完成~
可以到本地浏览器试试访问”http://IP:9200"

文章目录
  1. JDK
  2. ElasticSearch
    1. 下载
    2. 启动
  3. 配置
    1. 创建es用户
    2. 更改静态IP
    3. max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
    4. max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
|