CentOS 7 安装ES-Elasticsearch 6.4.3-能解决你安装的90%的问题

一、环境要求

CentOS 7 安装ES-Elasticsearch 6.4.3-能解决你安装的90%的问题_第1张图片

1. 系统版本

CentOS版本:7.6

[root@VM_0_13_centos ~]# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 

2.运行环境

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)

二、安装步骤

1.创建一个普通用户,es默认不能使用root用户进行启动

这里创建一个用户"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.

2.创建elasticsearch 的存放位置文件夹,将拥有者改为用户es

这里将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 ..

3. wget下载6.4.3版本安装包

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.3.tar.gz

4.解压elasticsearch-6.4.3.tar.gz

[root@VM_0_13_centos local]# tar -xzvf elasticsearch-6.4.3.tar.gz

5. 启动

启动报错内存不足:

[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

6. 再次启动

无法以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

7.再次启动

[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 即说明成功启动了

8.使用curl命令确认启动成功

[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"
}

但是当前只能本机访问,想要其他主机访问还需要做以下配置

三、其他配置

1.现在只能访问ElasticSearch的本地服务,外网访问需要修改配置文件config/elasticsearch.yml

network.host: 192.168.0.1   ->  network.host: 0.0.0.0

2.默认http端口号,config/elasticsearch.yml

http.port: 9200    -> http.port: 9201

3.文件句柄太少,至少要65536

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

4.虚拟内存太少,至少262144

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

5.设置后台启动,进入到bin目录下,启动后面加参数-d

[es@localhost bin]$ ./elasticsearch -d

6.查询es进程

ps -ef|grep elastic

7.关闭进程

kill -9 5040

8.如果启动报错:then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N ,这是某些软件包启动的时候默认启用 -XX:+AssumeMP导致

解决方案:[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,然后就解决了

查看CPU个数

[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.关于用户权限的问题

你可能感兴趣的:(项目环境)