Elasticsearch安装配置启动,kibana、head插件安装,中文分词ik、拼音分词安装

Elasticsearch安装

1、下载ES

  • wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.2.tar.gz
  • 或者在windows下载好,放到服务器上
  • tar -xvf elasticsearch-5.5.2.tar.gz
  • 注意版本:5.5.2
  • 注意:需要jdk1.8+

2、修改配置

修改conifig/elasticsearch.yml(主节点)

cluster.name: website-application
node.name: node-1-master-175-9200
node.master: true
#node.attr.rack: r1
node.data: true
path.data: /usr/local/elasticsearch/elasticsearch-5.5.2/data
path.logs: /usr/local/elasticsearch/elasticsearch-5.5.2/logs
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
network.host: 192.168.1.175
http.port: 9200
transport.tcp.port: 9300

#设置集群中master节点的初始列表,可以通过这些节点来自动发现新加入集群的节点。
discovery.zen.ping.unicast.hosts: ["192.168.1.175:9300"]
# 为了避免脑裂,集群节点数最少为 (有master资格节点数/2) + 1
discovery.zen.minimum_master_nodes: 1
#discovery.zen.ping_timeout: 120s
#gateway.recover_after_nodes: 2
#gateway.recover_after_time: 5m
#gateway.expected_nodes: 1
#script.engine.groovy.inline.search: on
#script.engine.groovy.inline.aggs: on
#indices.recovery.max_bytes_per_sec: 20mb
node.max_local_storage_nodes: 3
action.destructive_requires_name: false
# 增加新的参数,这样head插件可以访问es,解决跨域访问问题
http.cors.enabled: true
http.cors.allow-origin: "*"

从节点

cluster.name: website-application
node.name: node-2-176-9200
node.master: false
#node.attr.rack: r1
node.data: true
path.data: /usr/local/elasticsearch/elasticsearch-5.5.2/data
path.logs: /usr/local/elasticsearch/elasticsearch-5.5.2/logs
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
network.host: 0.0.0.0
http.port: 9200
transport.tcp.port: 9300

#设置集群中master节点的初始列表,可以通过这些节点来自动发现新加入集群的节点。
discovery.zen.ping.unicast.hosts: ["192.168.1.175:9300"]
# 为了避免脑裂,集群节点数最少为 半数+1
discovery.zen.minimum_master_nodes: 1
#discovery.zen.ping_timeout: 120s
#gateway.recover_after_nodes: 2
#gateway.recover_after_time: 5m
#gateway.expected_nodes: 1
#script.engine.groovy.inline.search: on
#script.engine.groovy.inline.aggs: on
#indices.recovery.max_bytes_per_sec: 20mb
node.max_local_storage_nodes: 3
action.destructive_requires_name: false
# 增加新的参数,这样head插件可以访问es,解决跨域访问问题
http.cors.enabled: true
http.cors.allow-origin: "*"

3、新建用户es,分配文件权限

es启动需要在非root账号下,所以需要新建一个用户。新建用户后,需要分配文件权限,否则会报错:

groupadd es
useradd es -g es -p es
chown -R es:es  /usr/local/elasticsearch
chmod 775 /usr/local/elasticsearch

可能的报错:

java.nio.file.AccessDeniedException: 或
bash: ./elasticsearch: Permission denied

4、 启动,报错处理

启动命令 ./bin/elasticsearch
查看日志和报错:

ERROR: [2] bootstrap checks failed
[1]: max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

原因
每个进程最大打开文件数大小太小,用户拥有的内存权限太小,查看命令如下:
ulimit -Hn
ulimit -Sn

解决
切换到root账户下:
vi /etc/security/limits.conf添加或修改以下配置(用户退出后重新登录生效):

* hard nofile 65536
* soft nofile 65536

注意:65535不行,必须是65536
然后修改内存分配:
sudo sysctl -w vm.max_map_count=262144

5、重启脚本


#!/bin/sh

NAME=elasticsearch
echo $NAME
ID=`ps -ef | grep "$NAME" | grep -v "$0" | grep -v "grep" | awk '{print $2}'`
echo $ID
echo "---------------"
for id in $ID
do
kill -9 $id
echo "killed $id"
done
/usr/local/elasticsearch/elasticsearch-5.5.2/bin/elasticsearch -d
tail -300f /usr/local/elasticsearch/elasticsearch-5.5.2/logs/website-application.log
echo "---------------"

head安装

1、下载解压

  • wget https://github.com/mobz/elasticsearch-head/archive/master.zip
  • 或者windows下载好放到服务器上
  • 需要nodejs环境

2、安装nodejs

下载解压:
wget https://nodejs.org/dist/v6.9.2/node-v6.9.2-linux-x64.tar.xz
xz -d node-v6.9.2-linux-x64.tar.xz
tar -xvf node-v6.9.2-linux-x64.tar
修改:
vi /etc/profile
增加配置:
export NODE_HOME=/usr/local/elasticsearch/node-v6.9.2-linux-x64
export PATH=$NODE_HOME/bin:$PATH
使之生效:
source /etc/profile
查看版本:
node -v
npm -v

3、继续安装

cd /usr/local/elasticsearch/elasticsearch-head-maste
npm install [email protected] --ignore-scripts

可以在elasticsearch-head下使用npm run start启动,可能会报警告:

[root@redis1 elasticsearch-head-master]# npm run start

> [email protected] start /usr/local/elasticsearch/elasticsearch-head-master
> grunt server

>> Local Npm module "grunt-contrib-jasmine" not found. Is it installed?

使用命令安装缺失的插件:
npm install grunt-contrib-clean grunt-contrib-concat grunt-contrib-watch grunt-contrib-connect grunt-contrib-copy grunt-contrib-jasmine

使用grunt server命令启动报错处理:

[root@redis1 elasticsearch-head-master]# grunt server
-bash: grunt: 未找到命令

安装grunt快捷命令:   
npm install -g grunt-cli

此后可以在elasticsearch-head下使用grunt server 命令启动

4、修改配置

  • 修改Gruntfile.js hostname属性,添加主机ip
  • 如果elasticsearch未针对head修改配置,需修改elasticsearch配置文件
    conifig/elasticsearch.yml:
# 增加新的参数,这样head插件可以访问es,解决跨域访问问题
http.cors.enabled: true
http.cors.allow-origin: "*"
# http.cors.allow-headers: "Authorization"
  • 重启es后生效

中文分词安装

  • 去elasticsearch路径下使用命令安装
  • ./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.5.2/elasticsearch-analysis-ik-5.5.2.zip
  • 注意版本一致
  • 重启es后生效

拼音分词安装

  • wget https://github.com/medcl/elasticsearch-analysis-pinyin/releases/download/v5.5.2/elasticsearch-analysis-pinyin-5.5.2.zip
  • 或者本地下载好放到服务器
  • 在elasticsearch下plugins文件夹建立pinyin文件夹,unzip解压,放入此文件夹
  • 注意版本一致
wget https://github.com/medcl/elasticsearch-analysis-pinyin/releases/download/v5.5.2/elasticsearch-analysis-pinyin-5.5.2.zip
unzip elasticsearch-analysis-pinyin-5.5.2.zip
mv elasticsearch ./elasticsearch-5.5.2/plugins/pinyin
  • 重启es后生效

kibana安装

  • wget https://artifacts.elastic.co/downloads/kibana/kibana-5.5.2-linux-x86_64.tar.gz
  • 或者本地下载好放到服务器上
  • tar -xvf kibana-5.5.2-linux-x86_64.tar.gz
  • 注意版本与elasticsearch一致;
  • 修改配置文件config/kibana.yml;
server.port: 5601

server.host: "0.0.0.0"

elasticsearch.url: "http://192.168.2.41:9200"

kibana.index: ".kibana"

启动:./bin/kibana
后台启动:nohup ./bin/kibana &

猜你喜欢

转载自blog.csdn.net/qq_45430163/article/details/114382119