ES之一:Elasticsearch5.2.2安装

首先到官网下载最新的5.2.2的安装包,下载地址:https://www.elastic.co/products/elasticsearch
解压
tar -zxvf elasticsearch-5.2.2.tar.gz
修改jdk版本
注意,elasticsearch需要使用jdk8,但是由于我对Linux还跑着其他的程序,所以要在.sh启动shell脚本中指定JDK的版本
修改elasticsearch-5.2.2/bin/elasticsearch文件,在设置Java变量前添加jdk1.8:

export JAVA_HOME=/home/sfapp/jdk1.8/jdk1.8.0_25
export PATH=$JAVA_HOME/bin:$PATH


if [ -x "$JAVA_HOME/bin/java" ]; then
JAVA="/home/sfapp/jdk1.8/jdk1.8.0_25/bin/java"
else
JAVA='which java'
fi

修改配置文件,conf/elasticsearch.yml

# 换个集群的名字,免得跟别人的集群混在一起
cluster.name: es-5.2.2-test

# 换个节点名字
node.name: node-101
...
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#修改一下ES的监听地址,这样别的机器也可以访问
network.host: 10.202.11.117
#
# Set a custom port for HTTP:
#默认的就好
http.port: 9200

bootstrap.system_call_filter: false
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
...
# 增加新的参数,这样head插件可以访问es
http.cors.enabled: true
http.cors.allow-origin: "*"
注意,设置参数的时候:后面要有空格!

 

安装部署head

 

5.1中,elasticsearch-head

  • 不能放在elasticsearch的 pluginsmodules 目录下

  • 不能使用 elasticsearch-plugin install

直接启动elasticsearch即可

安装 elasticsearch-head

  1. 修改 elasticsearch/config/elasticsearch.yml

  2. 添加

    http.cors.enabled: true
    http.cors.allow-origin: "*"
  3. 下载 elasticsearch-head 或者 git clone 到随便一个文件夹

  4. 安装nodejs

  5. cd /path/to/elasticsearch-head

  6. npm install -g grunt-cli

  7. npm install

  8. grunt server

  9. http://localhost:9100/

第一步,安装git

需要从github上面下载代码,因此先要安装Git

yum -y install git

安装完成后,就可以直接下载代码了:

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

下载后,修改下777权限(简单粗暴),因为是独立启动head的,所以随便放一个位置就行了,参考:

/usr/elk/head/*****
第二步,安装node

由于head插件本质上还是一个nodejs的工程,因此需要安装node,使用npm来安装依赖的包。(npm可以理解为maven)

去官网下载nodejs,https://nodejs.org/en/download/

下载下来的jar包是xz格式的,一般的Linux可能不识别,还需要安装xz.

yum -y install xz

然后解压nodejs的安装包:

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

解压完node的安装文件后,需要配置下环境变量,编辑/etc/profile,添加

# set node environment
export NODE_HOME=/usr/elk/node-v6.9.1-linux-x64
export PATH=$PATH:$NODE_HOME/bin

别忘记立即执行以下

source /etc/profile

这个时候可以测试一下node是否生效:

[root@localnode1 node-v6.9.1-linux-x64]# echo $NODE_HOME
/usr/elk/node-v6.9.1-linux-x64
[root@localnode1 node-v6.9.1-linux-x64]# node -v v6.9.1 [root@localnode1 node-v6.9.1-linux-x64]# npm -v 3.10.8

第三步,安装grunt

grunt是一个很方便的构建工具,可以进行打包压缩、测试、执行等等的工作,5.0里的head插件就是通过grunt启动的。因此需要安装一下grunt:

sudo ln -s /usr/local/bin/npm /usr/bin/npm  
sudo ln -s /usr/local/bin/node /usr/bin/node  
#建立软连接,否则root找不到npm
npm init
#生成package.json否则报错
sudo npm install -g grunt-cli

安装完成后检查一下:

[root@localnode1 elasticsearch-head]# grunt -version
grunt-cli v1.2.0 grunt v0.4.5

第四步,修改head源码

由于head的代码还是2.6版本的,直接执行有很多限制,比如无法跨机器访问。因此需要用户修改两个地方:

修改服务器监听地址

目录:head/Gruntfile.js

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

增加hostname属性,设置为*

修改连接地址:

目录:head/_site/app.js

修改head的连接地址:

this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200";

把localhost修改成你es的服务器地址,如:

this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://10.10.10.10:9200";

第五步,运行head

首先开启5.0 ES。

然后在head目录中,执行npm install 下载以来的包:

npm install 

最后,启动nodejs

grunt server

访问:target:9100

这个时候,访问http://xxx:9100就可以访问head插件了.

启动服务

./elasticsearch &

遇到的异常解决

此时启动服务会发现报错:max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
于是我临时提高了vm.max_map_count的大小
此操作需要root权限
[root@localhost ~]# sysctl -w vm.max_map_count=262144
或者永久性修改
[root@localhost ~]# cat /etc/sysctl.conf | grep -v "vm.max_map_count" > /tmp/system_sysctl.conf
[root@localhost ~]# echo "vm.max_map_count=262144" >> /tmp/system_sysctl.conf
[root@localhost ~]# mv /tmp/system_sysctl.conf /etc/sysctl.conf
mv:是否覆盖"/etc/sysctl.conf"? y
[root@localhost ~]# cat /etc/sysctl.conf
# System default settings live in /usr/lib/sysctl.d/00-system.conf.
# To override those settings, enter new settings here, or in an /etc/sysctl.d/<name>.conf file
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
vm.max_map_count=262144
[root@localhost ~]# sysctl -p
vm.max_map_count = 262144

 

错误:

RROR: bootstrap checks failed
max file descriptors [65535] for elasticsearch process likely too low, increase to at least [65536]
memory locking requested for elasticsearch process but memory is not locked
max number of threads [1024] for user [jason] likely too low, increase to at least [2048]
max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk

需要针对这些参数进行设置:

vim /etc/security/limits.conf
...
elasticsearch hard nofile 65536  # 针对 max file descriptors
elasticsearch soft nproc 2048    # 针对 max number of threads
 
> vim /etc/sysctl.conf
...
vm.max_map_count=262144          # 针对 max virtual memory areas
 
> vim /etc/elasticsearch/elasticsearch.yml
 
...
bootstrap.system_call_filter: false   # 针对 system call filters failed to install, 参见 https://www.elastic.co/guide/en/elasticsearch/reference/current/system-call-filter-check.html

 


服务启动以后,在浏览器中访问http://10.104.29.13:9200/结果如下:

{
name: "Dsx3Ih1",
cluster_name: "elasticsearch",
cluster_uuid: "ro0IVlJITm-Kq-8ZfPwEtQ",
version: {
number: "5.1.2",
build_hash: "c8c4c16",
build_date: "2017-01-11T20:18:39.146Z",
build_snapshot: false,
lucene_version: "6.3.0"
},
tagline: "You Know, for Search"
}

 

安装head插件

真搞不懂,elasticsearch升级以后不能一行命令安装head插件,老版本的是可以的。

安装倒也简单,只需要一下三个命令:

clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

在elasticsearch-head目录下node_modules/grunt下如果没有grunt二进制程序,需要执行

cd elasticsearch-head
npm install grunt --save
  • 1
  • 2
  • 1
  • 2

然后修改配置:

修改elasticsearch-headGruntfile.js文件,添加hostname字段

connect: {
    server: { options: { hostname: '10.104.29.13', port: 9100, base: '.', keepalive: true } } }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

修改Elasticsearch配置文件

编辑elasticsearch-5.1.2/config/elasticsearch.yml,加入以下内容:

http.cors.enabled: true
http.cors.allow-origin: "*"
  • 1
  • 2
  • 1
  • 2

进入elasticsearch-head/node_modules/grunt/bin目录,执行./grunt server命令启动head插件服务。 
浏览器中访问http://10.104.29.13:9100/即可

 

 

sudo chkconfig --add elasticsearch   # configure Elasticsearch to start automatically when the system boots up
sudo -i service elasticsearch start
sudo -i service elasticsearch stop

日志: /var/log/elasticsearch/

后台启动head(head插件是个nodejs应用)服务: 
nohup bin/grunt server &

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值