CentOS版本:7.6
[root@VM_0_13_centos ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
es是基于Java开发,提前装好Java环境,Java环境的安装就不多说明了,没装的Google一下,
[root@VM_0_13_centos ~]# java -version
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) Client VM (build 25.201-b09, mixed mode)
这里创建一个用户"es",并设置密码
[root@VM_0_13_centos ~]# adduser es
# 设置密码
[root@VM_0_13_centos home]# passwd es
Changing password for user es.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
这里将elasticsearch放在/usr/local目录下
[root@VM_0_13_centos ~]# mkdir /usr/local/elasticsearch
[root@VM_0_13_centos ~]# cd /usr/local
[root@VM_0_13_centos local]# chown -R es elasticsearch/
[root@VM_0_13_centos local]# ls -al elasticsearch/
total 8
drwxr-xr-x 2 es root 4096 Jun 26 12:27 .
drwxr-xr-x. 17 root root 4096 Jun 26 12:27 ..
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.3.tar.gz
[root@VM_0_13_centos local]# tar -xzvf elasticsearch-6.4.3.tar.gz
启动报错内存不足:
[root@VM_0_13_centos local]# cd elasticsearch-6.4.3/bin/
[root@VM_0_13_centos bin]# ./elasticsearch
Java HotSpot(TM) Client VM warning: INFO: os::commit_memory(0xb8400000, 1006632960, 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 1006632960 bytes for committing reserved memory.
# An error report file with more information is saved as:
# logs/hs_err_pid6411.log
解决,调小启动内存
[root@VM_0_13_centos elasticsearch-6.4.3]# vi ./config/jvm.options
22 #-Xms1g
23 #-Xmx1g
24 -Xms300m
25 -Xmx300m
无法以root全新启动
[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-5.2.2.jar:5.2.2]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-5.2.2.jar:5.2.2]
at org.elasticsearch.cli.SettingCommand.execute(SettingCommand.java:54) ~[elasticsearch-5.2.2.jar:5.2.2]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) ~[elasticsearch-5.2.2.jar:5.2.2]
at org.elasticsearch.cli.Command.main(Command.java:88) ~[elasticsearch-5.2.2.jar:5.2.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:89) ~[elasticsearch-5.2.2.jar:5.2.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:82) ~[elasticsearch-5.2.2.jar:5.2.2]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:105) ~[elasticsearch-5.2.2.jar:5.2.2]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:203) ~[elasticsearch-5.2.2.jar:5.2.2]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:333) ~[elasticsearch-5.2.2.jar:5.2.2]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-5.2.2.jar:5.2.2]
... 6 more
解决:切换至之前创建的es用户
[root@localhost local]# su es
[2020-06-26T08:07:22,821][INFO ][o.e.n.Node ] [9SxkwdN] **starting** ...
[2020-06-26T08:07:23,249][INFO ][o.e.t.TransportService ] [9SxkwdN] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300}
[2020-06-26T08:07:23,282][WARN ][o.e.b.BootstrapChecks ] [9SxkwdN] max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2020-06-26T08:07:23,282][WARN ][o.e.b.BootstrapChecks ] [9SxkwdN] max number of threads [3802] for user [es] is too low, increase to at least [4096]
[2020-06-26T08:07:23,282][WARN ][o.e.b.BootstrapChecks ] [9SxkwdN] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2020-06-26T08:07:26,486][INFO ][o.e.c.s.MasterService ] [9SxkwdN] zen-disco-elected-as-master ([0] nodes joined)[ack.installed=true, ml.max_open_jobs=20, ml.enabled=true}
[2020-06-26T08:07:26,492][INFO ][o.e.c.s.ClusterApplierService] [9SxkwdN] new_master {9SxkwdN}{9SxkwdNHTR6EWEeP_t1Wpw}, reason: apply cluster state (from master [master {9SxkwdN}{9SxkwdNHTR6EWEeP_t1Wpw}{5Tj0IuqBSWespFPpOeiNxA}{127.0.0en-disco-elected-as-master ([0] nodes joined)[, ]]])
[2020-06-26T08:07:26,579][WARN ][o.e.x.s.a.s.m.NativeRoleMappingStore] [9SxkwdN] Failed to clear cache for realms [[]
[2020-06-26T08:07:26,656][INFO ][o.e.x.s.t.n.SecurityNetty4HttpServerTransport] [9SxkwdN] publish_address {127.0.0.1:
[2020-06-26T08:07:26,656][INFO ][o.e.n.Node ] [9SxkwdN] **started**
看到started 即说明成功启动了
[root@localhost ~]# curl localhost:9200
{
"name" : "9SxkwdN",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "Lkj7f05WR0GN1VqTofBxRQ",
"version" : {
"number" : "6.4.3",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "fe40335",
"build_date" : "2018-10-30T23:17:19.084789Z",
"build_snapshot" : false,
"lucene_version" : "7.4.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
但是当前只能本机访问,想要其他主机访问还需要做以下配置
network.host: 192.168.0.1 -> network.host: 0.0.0.0
http.port: 9200 -> http.port: 9201
max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]
解决办法:更改文件句柄数,修改/etc/security/limits.conf,加入以下内容【前面星号也需要】
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解决办法:增加虚拟内存,修改/etc/sysctl.conf ,加入以下内容
vm.max_map_count=655360
修改完成后,并没有立即生效,需要执行以下命令使其生效
[root@localhost config]# sysctl -p
vm.max_map_count = 655360
[es@localhost bin]$ ./elasticsearch -d
ps -ef|grep elastic
kill -9 5040
解决方案:[root@localhost config]# vi /usr/local/elasticsearch/elasticsearch-6.4.3/config/jvm.options添加
#Warning: configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
-XX:+AssumeMP
因为我是用虚拟机装的,配置了上面的JVM参数配置之后还是出现同样的问题,一番搜索之后看见有网友遇到同样的问题,解决办法是增加虚拟机的CPU核心数量,我就简单改成2,然后就解决了
[es@localhost bin]$ cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l
2
[es@localhost bin]$ cat /proc/cpuinfo| grep "processor"| wc -l
2
[es@localhost bin]$ ./elasticsearch -d
[es@localhost bin]$
排查es日志,发现还是文件句柄个数和虚拟内存太少,也就是我我杠改的配置没有起作用,
ulimit -a
查看之后发现确实没有变化,于是我又分别在root用户和es用户分别改了一遍,发现还是没有解决问题,只好寄出我的究极大法了:重启
[root@localhost config]# reboot
启动成功
[es@bogon bin]$ ps -ef|grep elastic
es 10540 1 21 09:54 pts/0 00:00:22 /usr/bin/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+AlwaysPreTouch -Xss1m -XX:+AssumeMP -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.YmSmkm89 -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/elasticsearch/elasticsearch-6.4.3 -Des.path.conf=/usr/local/elasticsearch/elasticsearch-6.4.3/config -Des.distribution.flavor=default -Des.distribution.type=tar -cp /usr/local/elasticsearch/elasticsearch-6.4.3/lib/* org.elasticsearch.bootstrap.Elasticsearch -d
es 10571 10540 0 09:54 pts/0 00:00:00 /usr/local/elasticsearch/elasticsearch-6.4.3/modules/x-pack-ml/platform/linux-x86_64/bin/controller
es 10617 10449 0 09:56 pts/0 00:00:00 grep --color=auto elastic
其他主机访问,如果es端口已经配置0.0.0.0了,记得关闭防火墙
systemctl stop firewalld.service.
,否则也可能访问不了
{
"name" : "9SxkwdN",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "Lkj7f05WR0GN1VqTofBxRQ",
"version" : {
"number" : "6.4.3",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "fe40335",
"build_date" : "2018-10-30T23:17:19.084789Z",
"build_snapshot" : false,
"lucene_version" : "7.4.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
1.Linux下修改当前用户的最大线程数和 open files
2.CentOS7.4安装Elasticsearch 6.4.3
3.el 安装问题集合
4.关于用户权限的问题