CentOS6.X,部署elasticsearch5.6詳細(xì)步驟

標(biāo)簽(空格分隔): elasticsearch head kibana jdk Linux升級(jí)


目錄.png

安裝說(shuō)明

本次為裸機(jī)安裝單機(jī)版的elasticsearch5.6,由此會(huì)涉及到很多不可避免的,或者說(shuō)多余的部分,請(qǐng)自行忽略。操作系統(tǒng)Linux內(nèi)核版本,jdk版本,elasticsearch5.6需要 Java8。

這里說(shuō)明一下,因?yàn)楹竺鏁?huì)安裝head插件,對(duì)Linux的內(nèi)核要求在3.5以上,默認(rèn)安裝的Linux版本的內(nèi)核為2.6。參見(jiàn)截圖。jdk1.8是安裝在elasticsearch用戶下的,在root用戶下java -version就會(huì)顯示-bash: java: command not found

見(jiàn)官方文檔:Elasticsearch requires at least Java 8. Specifically as of this writing, it is recommended that you use the Oracle JDK version 1.8.0_131.

系統(tǒng)參數(shù)
系統(tǒng)參數(shù)

Linux插件安裝

root用戶下,".xz"文件解壓

說(shuō)明:安裝解壓xz,是在安裝elasticsearch的head插件的時(shí)候,需要用到node.js,同時(shí)需要Linux需要可以連接internet網(wǎng)絡(luò)

1.下載地址 https://tukaani.org/xz/
要選擇.bz2的,別選.xz的,否則還是解壓不了

image.png

2.解壓包
tar -zxvf xz-5.2.3.tar.gz
cd xz-5.2.3
./configure --prefix=/usr/local/xz
這里會(huì)遇到問(wèn)題,在configure時(shí)就是各種找不到,沒(méi)有g(shù)cc等,于是輸入以下命令
yum install update -y
yum install upgrade -y
這個(gè)過(guò)程有點(diǎn)久,等完成后,再安裝gcc
yum install gcc
這樣安裝好后
cd xz-5.0.3/
./configure
make
make install
之后就可以愉快地解壓tar.xz文件啦!基本是參見(jiàn)文檔內(nèi)容,請(qǐng)見(jiàn)諒。

3.解壓xz包
xz -d ***.tar.xz

4.解壓tar包
tar -xvf ***.tar

安裝wget

yum -y install wget

安裝vim

yum -y install vim

Linux的常用支持庫(kù)

在CentOS安裝軟件的時(shí)候,可能缺少一部分支持庫(kù),而報(bào)錯(cuò)。這里首先安裝系統(tǒng)常用的支持庫(kù)。那么在安裝的時(shí)候就會(huì)減少很多的錯(cuò)誤的出現(xiàn)。

yum install -y gcc gdb strace gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs patch e2fsprogs-devel krb5-devel libidn libidn-devel openldap-devel nss_ldap openldap-clients openldap-servers libevent-devel libevent uuid-devel uuid mysql-devel 

jdk1.8安裝

說(shuō)明:這里切換到elasticsearch用戶進(jìn)行安裝,不是一種全局jdk配置方式

1.新建用戶
useradd elasticsearch,這時(shí)默認(rèn)用戶主目錄在 /home/elasticsearch

2.su - elasticsearch,切換到elasticsearch用戶

3.ls -al,可以查看到隱藏文件,見(jiàn)圖片紅色框部分

新建用戶下的目錄.png

4.修改.bashrc文件,切記 :wq 后,執(zhí)行source .bashrc,進(jìn)行保存生效
export JAVA_HOME="/home/elasticsearch/jdk1.8.0_144"
export JRE_HOME=${JAVA_HOME}/jre
export PATH=${JAVA_HOME}/bin:$PATH
export CLASSPATH=.:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar
export JAVA_HOME JRE_HOME CLASSPATH PATH

.bashrc文件配置.png

5.這時(shí)再查看java版本,發(fā)現(xiàn)已經(jīng)為1.8了

jdk1.8.png

elasticsearch5.6安裝以及配置修改

1.下載地址
https://www.elastic.co/downloads/elasticsearch#ga-release

elasticsearch下載.png

2.解壓壓縮文件
tar -zxvf elasticsearch-5.6.3.tar.gz

3.修改elasticsearch.yml配置文件

配置文件位置.png

修改參數(shù)如下,注意該配置##順序分先后##

  • 集群名稱:cluster.name: jt_sap5
  • 節(jié)點(diǎn)名稱:node.name: single-node(集群中的各個(gè)節(jié)點(diǎn)名稱都不能相同)
  • 數(shù)據(jù)目錄:path.data: /path/to/data(若沒(méi)有特殊數(shù)據(jù)路徑,注釋掉該參數(shù),默認(rèn)使用ES_HOME/data)
  • 日志目錄:#path.logs: /path/to/logs(若沒(méi)有特殊數(shù)據(jù)路徑,注釋掉該參數(shù),默認(rèn)使用ES_HOME/logs)
  • 鎖定物理內(nèi)存設(shè)置:bootstrap.memory_lock: false(注釋掉該參數(shù),默認(rèn)使用false)
  • 系統(tǒng)過(guò)濾器調(diào)用設(shè)置:bootstrap.system_call_filter: false
  • 節(jié)點(diǎn)主機(jī)IP:network.host: 10.0.1.215
  • 節(jié)點(diǎn)端口:http.port: 9200
  • 數(shù)據(jù)傳輸端口:transport.tcp.port: 9300
  • 集群節(jié)點(diǎn)獲取類型:discovery.type: single-node(注意該配置只在單節(jié)點(diǎn)集群中使用,多節(jié)點(diǎn)集群不能使用,使用默認(rèn)類型)
  • 集群節(jié)點(diǎn)列表:discovery.zen.ping.unicast.hosts: ["host1:port1", "host2: port2"](該配置在多節(jié)點(diǎn)集群中使用,單節(jié)點(diǎn)不適用該配置。其中,host表示集群中其他節(jié)點(diǎn)的ip地址,port表示集群中其他節(jié)點(diǎn)的數(shù)據(jù)傳輸端口)
  • 集群有效節(jié)點(diǎn)最小值:discovery.zen.minimum_master_nodes: 3(該配置在多借點(diǎn)集群中使用,單節(jié)點(diǎn)不適用。其中,該配置的值不能大于總節(jié)點(diǎn)數(shù)量,建議使用 [節(jié)點(diǎn)數(shù)量/2 + 1] 來(lái)計(jì)算該配置值)
  • 是否允許跨源 REST 請(qǐng)求:http.cors.enabled: true
  • 允許跨源REST請(qǐng)求的地址:http.cors.allow-origin: ""(在開(kāi)啟允許跨源REST請(qǐng)求之后,才使用該配置,不然不能使用,其中“”標(biāo)識(shí)允許所有的跨源訪問(wèn))
  • 最大的http請(qǐng)求長(zhǎng)度:http.max_initial_line_length: 10m

備注:
1.bootstrap.system_call_filter參數(shù)配置,默認(rèn)為true,這里更改為false,放在bootstrap.memory_lock后面,同時(shí)設(shè)定bootstrap.memory_lock為false,主要可能的原因是由于CentOS6.X內(nèi)核版本為2.6,不支持bootstrap.memory_lock參數(shù)的開(kāi)啟,就會(huì)引出下面的內(nèi)核升級(jí)問(wèn)題。
2.官方文檔中提到bootstrap.memory_lock: true的諸多配置,在后文添加。
3.注意 “:”,后面需要加空格

內(nèi)核版本問(wèn)題報(bào)錯(cuò).png

4.elasticsearch啟動(dòng)錯(cuò)誤處理方法,以及必須的配置

[elasticsearch@localhost bin]$ ./elasticsearch
... ...
 
ERROR: 
[5] bootstrap checks failed
[1]: max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]
[2]: max number of threads [1024] for user [elasticsearch] is too low, increase to at least [2048]
[3]: max virtual memory areas vm.max_map_count [256000] is too low, increase to at least [262144]
[4]: system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
 
... ...

(1)針對(duì)錯(cuò)誤[1],[2],可以采取如下配置:

修改/etc/security/limits.conf配置文件:

#[root@www config]$ vim /etc/security/limits.conf

#增加5行,修改最大句柄數(shù)和單進(jìn)程的最大線程數(shù):
*  -  nofile  65536
* soft memlock   unlimited
* hard memlock   unlimited
* soft nproc 2048
* hard nproc 2048

(此處代表所有用戶都適用,可以根據(jù)自身需要設(shè)定特定用戶句柄)
如果系統(tǒng)中存在/etc/security/limits.d/90-nproc.conf,修改
soft nproc 1024為* soft nproc 10240,將所有用戶句柄最大值調(diào)整為10240。

#[root@www config]$ vim /etc/security/limits.d/90-nproc.conf
修改如下配置:

# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.

*          soft    nproc     10240
root       soft    nproc     unlimited

修改完成后,重新登錄elasticsearch賬戶,查看設(shè)置是否生效。

[elasticsearch@www config]$ ulimit -n
65536
[elasticsearch@www config]$ ulimit -u
2048

官方文檔:
Elasticsearch使用了大量的文件描述符或者文件句柄。文件描述符將要被用完時(shí)會(huì)導(dǎo)致災(zāi)難性的后果,并且非??赡芤饠?shù)據(jù)丟失。確保增加運(yùn)行Elasticsearch的用戶打開(kāi)文件描述符的數(shù)量至少為65,536或者更高。
Elasticsearch使用多個(gè)線程池來(lái)進(jìn)行不同類型的操作。當(dāng)需要時(shí)能夠創(chuàng)建新線程是很重要的。確保Elasticsearch用戶能創(chuàng)建的線程數(shù)最少為2048個(gè)。

你可以檢查每個(gè)節(jié)點(diǎn)的max_file_descriptors配置情況:

GET _nodes/stats/process?filter_path=**.max_file_descriptors

(2)針對(duì)錯(cuò)誤[3],可以采取如下方式:
修改/etc/sysctl.conf文件配置項(xiàng):

[root@www ~]# vim /etc/sysctl.conf
# 一個(gè)進(jìn)程可以擁有的VMA(虛擬內(nèi)存區(qū)域)的數(shù)量:
vm.max_map_count=262144
 
# 調(diào)用虛擬內(nèi)存的閾值數(shù):
vm.swappiness=1 

[root@www ~]# sysctl -p

(3)針對(duì)錯(cuò)誤[4][5],可以采取如下方式:

出現(xiàn)錯(cuò)誤的原因:是因?yàn)閏entos6.x操作系統(tǒng)不支持SecComp,而elasticsearch 5.x,默認(rèn)bootstrap.system_call_filter為true進(jìn)行檢測(cè),所以導(dǎo)致檢測(cè)失敗,失敗后直接導(dǎo)致ES不能啟動(dòng)。但是為了禁止內(nèi)存交換,這兩個(gè)參數(shù)最好設(shè)置為true。

在elasticsearch.yml中添加配置項(xiàng):bootstrap.system_call_filter為false:

bootstrap.memory_lock: false
bootstrap.system_call_filter: false

官方文檔:大多數(shù)操作系統(tǒng)會(huì)用盡可能多的內(nèi)存用于文件系統(tǒng)緩存和及早換出無(wú)用的應(yīng)用內(nèi)存。這可能導(dǎo)致一部分JVM內(nèi)存被交換到硬盤(pán)上。這種內(nèi)存交換非常不利于性能和節(jié)點(diǎn)的穩(wěn)定性。應(yīng)該竭盡所能來(lái)避免這種情況。它能引起垃圾回收持續(xù)長(zhǎng)達(dá)數(shù)分鐘而不是幾毫秒并且能導(dǎo)致節(jié)點(diǎn)響應(yīng)緩慢甚至與集群失去聯(lián)系。由此,最好的方式就是禁止內(nèi)存交換。

禁止內(nèi)存交換的三種方式

  • 啟用 bootstrap.memory_lock
  • 暫時(shí)禁用,Linux系統(tǒng)執(zhí)行命令sudo swapoff -a,如果要永久禁用,則需要編輯/etc/fstab文件,然后注釋掉所有包含swap的行。
  • vim /etc/sysctl.conf,正如上面提到的vm.swappiness=1,這樣子只會(huì)在正常情況下減少內(nèi)存交換,但在緊急情況中依然存在。

警告:mlockall如果嘗試分配超過(guò)了可用的內(nèi)存,可能會(huì)引起JVM 或者 shell session退出。在啟動(dòng)Elasticsearch后,你可以檢查下設(shè)置是否生效了,可以通過(guò)檢查下面請(qǐng)求響應(yīng)中的mlockall值:

`GET _nodes?filter_path=**.mlockall`
or
`GET _nodes/process?pretty`

(4)優(yōu)化JVM的Head內(nèi)存大小
說(shuō)明:該配置適用于ES服務(wù)器負(fù)載較高時(shí),通過(guò)提高JVM的Heap內(nèi)存,可以提高ES的處理速度。

# vim $ES_HOME/config/jvm.options

#這個(gè)值不能超過(guò)可用物理內(nèi)存的50%,甚至更小。
修改以下兩處配置:
-Xms4g
-Xmx4g

#如果內(nèi)存配置超過(guò)6G請(qǐng)修改如下配置。把回收期修改為G1 GC
## GC configuration
-XX:+UseConcMarkSweepGC
-XX:CMSInitiatingOccupancyFraction=75
-XX:+UseCMSInitiatingOccupancyOnly
修改后
## GC configuration
-XX:+UseG1GC
-XX:MaxGCPauseMillis=200

5.啟動(dòng)和關(guān)閉elasticsearch
以elasticsearch用戶登錄

啟動(dòng):
# cd $ES_HOME
# ./bin/elasticsearch –d –p pid
關(guān)閉:
# cd $ES_HOME
# kill -9 `pid`

瀏覽器打開(kāi):http://127.0.0.1:9200

Head插件安裝

1.安裝git
需要從github上面下載代碼,因此先要安裝git

yum -y install git

安裝完成后,就可以直接下載代碼了:

git clone git://github.com/mobz/elasticsearch-head.git

或者在windows下載
下載地址:https://github.com/mobz/elasticsearch-head,下載后上傳到Linux系統(tǒng)中。

2.安裝node
由于head插件本質(zhì)上還是一個(gè)nodejs的工程,因此需要安裝node,使用npm來(lái)安裝依賴的包。(npm可以理解為maven)
去官網(wǎng)下載nodejs,https://nodejs.org/en/download/

node官網(wǎng).png

下載下來(lái)的jar包是xz格式的,一般的linux可能不識(shí)別,但我們前面以及安裝了xz解壓工具了哦!

xz -d node*.tar.xz
tar -xvf node*.tar

解壓完node的安裝文件后,需要配置下環(huán)境變量,root用戶編輯/etc/profile,注意要修改node路徑,添加

vim /etc/profile

export NODE_HOME=/home/elasticsearch/node-v8.9.0-linux-x64
export PATH=$PATH:$NODE_HOME/bin
export NODE_PATH=$NODE_HOME/lib/node_modules

#在命令行輸入:source /etc/profile,讓配置文件生效。

在命令行輸入:node -v,查看node.js的版本。

node版本號(hào).png

3.安裝grunt
grunt是一個(gè)很方便的構(gòu)建工具,可以進(jìn)行打包壓縮、測(cè)試、執(zhí)行等等的工作,5.0里的head插件就是通過(guò)grunt啟動(dòng)的。因此需要安裝一下grunt:

npm install grunt-cli

安裝完成后檢查一下:
[root@www elasticsearch-head-master]# grunt -version
grunt-cli v1.2.0
grunt v1.0.1

4.修改head源碼

查看當(dāng)前head插件目錄下有無(wú)node_modules/grunt目錄,沒(méi)有的話,執(zhí)行命令創(chuàng)建:npm install grunt --save

(1)修改服務(wù)器監(jiān)聽(tīng)地址:增加hostname屬性,設(shè)置為*
目錄:head/Gruntfile.js

connect: {
    server: {
        options: {
            port: 9100,
            hostname: '*',
            base: '.',
            keepalive: true
        }
    }
}

(2)檢查head根目錄下是否存在base文件夾
要是沒(méi)有的話,將 _site下的base文件夾及其內(nèi)容復(fù)制到head根目錄下

(3)修改連接地址:
目錄:head/_site/app.js

修改head的連接地址:
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200";

把localhost修改成你es的服務(wù)器地址,如:
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://10.0.0.78:9200";

5.運(yùn)行head
首先啟動(dòng)elasticsearch,然后在head目錄中,執(zhí)行npm install下載依賴的包
如果速度較慢或者安裝失敗,可以使用國(guó)內(nèi)鏡像 npm install -g cnpm --registry=https://registry.npm.taobao.org

#后臺(tái)啟動(dòng)grunt server命令
nohup grunt server &exit

#如果想關(guān)閉head插件,使用[Linux](http://lib.csdn.net/base/linux)查找進(jìn)程命令:
ps aux|grep head

#結(jié)束進(jìn)程:
kill -9 'pid'

訪問(wèn)head插件:
http://10.0.0.78:9100(啟動(dòng)后會(huì)有提示:Started connect web server on http://10.0.0.78:9100)

Kibana安裝

Kibana是一個(gè)開(kāi)源的分析與可視化平臺(tái),設(shè)計(jì)出來(lái)用于和Elasticsearch一起使用的。你可以用kibana搜索、查看、交互存放在Elasticsearch索引里的數(shù)據(jù),使用各種不同的圖表、表格、地圖等kibana能夠很輕易地展示高級(jí)數(shù)據(jù)分析與可視化。
1.下載kibana-5.6.3-linux-x86_64.tar.gz
下載地址為:https://www.elastic.co/downloads/kibana

image.png

2.修改配置文件
進(jìn)入kibana解壓目錄,修改配置文件config/kibana.yml。

  • kibana服務(wù)器端口號(hào):server.port: 5601
  • kibana服務(wù)器ip地址:server.host: "10.10.10.102"
  • kibana服務(wù)器連接ES地址:elasticsearch.url: "http://10.10.10.102:9200"

3.啟動(dòng) kibana

nohup  bin/kibana &>/dev/null&

4.查看是否啟動(dòng)成功
打開(kāi)瀏覽器,訪問(wèn):http://IP:5601即可

Linux內(nèi)核2.6升級(jí)3.10

背景說(shuō)明:CentOS 7 的內(nèi)核一般都是3.10的,而CentOS 6.X 的內(nèi)核一般都是2.6,在2.6的內(nèi)核下,elasticsearch5.x下bootstrap.system_call_filter啟動(dòng)會(huì)出現(xiàn)問(wèn)題,要求為內(nèi)核3.5以上。
升級(jí)內(nèi)核的方式,網(wǎng)上有很多方法是下載內(nèi)核然后編譯,這樣需要安裝很多必備的環(huán)境和工具,比較麻煩,但是也有助于我們了解內(nèi)核的編譯,這里采取較為簡(jiǎn)單的快速的升級(jí)方式。

1.查看當(dāng)前內(nèi)核版本(升級(jí)后)

[root@www home]# more /etc/issue
Red Hat Enterprise Linux Server release 6.5 (Santiago)
Kernel \r on an \m

[root@www home]# uname -a
Linux www 3.10.107-1.el6.elrepo.x86_64 #1 SMP Tue Jun 27 10:57:54 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux

2.導(dǎo)入public key

rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

3.安裝ELRepo到CentOS
http://elrepo.org/tiki/tiki-index.php 選擇要安裝的ELRepo

ELRepo官網(wǎng).png
rpm -Uvh http://www.elrepo.org/elrepo-release-6-8.el6.elrepo.noarch.rpm

4.安裝kernel-lt(lt=long-term)

yum --enablerepo=elrepo-kernel install kernel-lt -y

或者 安裝kernel-ml(ml=mainline)

yum --enablerepo=elrepo-kernel install kernel-ml -y

5.編輯grub.conf文件,修改Grub引導(dǎo)順序

vim /etc/grub.conf

因?yàn)橐话阈掳惭b的內(nèi)核在第一個(gè)位置,所以設(shè)置default=0,表示啟動(dòng)新內(nèi)核

image.png

6.重啟
查看此時(shí)內(nèi)核版本

[root@www home]# uname -r
3.10.107-1.el6.elrepo.x86_64

[THE END]

參考文檔:

linux的tar.xz文件解壓以及xz工具安裝
centos安裝wget 及配置
Linux中必備常用支持庫(kù)的安裝(CentOS-6.5)
Elasticsearch用戶指南 二 安裝
如何在Linux下源碼安裝node.js
Elasticsearch5 及 head插件 安裝說(shuō)明
centos7下Elasticsearch5.2.2和head 插件環(huán)境搭建
Elasticsearch 5.0 —— Head插件部署指南(Head目前支持5.0了!請(qǐng)不要看本篇文章了)
CentOS6.X 升級(jí)內(nèi)核 至 3.10
Welcome to the ELRepo Project

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容