CentOS 7 安裝ES-Elasticsearch 6.4.3-能解決你安裝的90%的問題

一、環境要求

image

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.關於用戶權限的問題

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章