首页 技术 正文
技术 2022年11月18日
0 收藏 585 点赞 4,223 浏览 5689 个字

elasticsearch5.0集群+kibana5.0+head插件插件的安装

es集群的规划:

两台16核64G内存的服务器:

yunva_etl_es1  ip:1.1.1.1 u04es01.chinasoft.com

yunva_etl_es2  ip:2.2.2.2

操作系统:centos7.2 x86_64

1.安装jdk1.8和elasticsearch5.0.1

rpm -ivh jdk-8u111-linux-x64.rpm

rpm -ivh elasticsearch-5.0.1.rpm

对es的配置进行优化

vim /etc/sysctl.conf

# 增加下面的内容

fs.file-max = 1000000

vm.max_map_count=262144

使配置生效

sysctl -p

vi /etc/security/limits.conf

# 修改

* soft nofile 655350

* hard nofile 655350

内存调整配置文件(建议配置为物理内存的一半或者更多):

vim /etc/elasticsearch/jvm.options

-Xms32g

-Xmx32g

2.集群的配置

修改elasticsearch的参数

vim /etc/elasticsearch/elasticsearch.yml

yunva_etl_es1配置

cluster.name: yunva_es_cluster

# 集群的关键配置

discovery.zen.ping.unicast.hosts: [“yunva_etl_es1”, “yunva_etl_es2”]

node.name: yunva_etl_es1

node.master: true

# 关闭自动索引

action.auto_create_index: false

node.data: true

path.data: /data/es/data

path.logs: /data/es/logs

bootstrap.memory_lock: false

network.host: 0.0.0.0

http.port: 9200

# 增加新的参数,这样head插件可以访问es

http.cors.enabled: true

http.cors.allow-origin: “*”

yunva_etl_es2的配置

# cat /etc/elasticsearch/elasticsearch.yml

cluster.name: yunva_es_cluster

# 集群的关键配置

discovery.zen.ping.unicast.hosts: [“yunva_etl_es1”, “yunva_etl_es2”]

node.name: yunva_etl_es2

node.master: true

# 关闭自动索引

action.auto_create_index: false

path.data: /data/es/data

path.logs: /data/es/logs

bootstrap.memory_lock: false

network.host: 0.0.0.0

http.port: 9200

# 增加新的参数,这样head插件可以访问es

http.cors.enabled: true

http.cors.allow-origin: “*”

创建日志和数据存放目录

mkdir -p /data/es/data

mkdir /data/es/logs

chown -R elasticsearch.elasticsearch /data/es

服务启动:

systemctl start elasticsearch.service

3.head插件的安装

使用ES的基本都会使用过head,但是版本升级到5.0后,head插件就不好使了,因为这个head插件现在成了一个独立的组件

在5.0版本中不支持直接安装head插件,需要启动一个服务

安装依赖包:

yum install gcc openssl-devel gcc-c++ compat-gcc-34 compat-gcc-34-c++ bzip2

第一步,安装git需要从github上面下载代码,因此先要安装git

yum -y install git

第二步,安装node(head安装依赖npm 需要node4.2.2以上版本)

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

wget https://nodejs.org/dist/v4.2.2/node-v4.2.2-linux-x64.tar.gz

tar -zxvf node-v4.2.2-linux-x64.tar.gz -C /usr/local/

cd /usr/local

ln -sv node-v4.2.2-linux-x64/ node

ln -sv /usr/local/node/bin/* /usr/sbin/

cd /usr/local/node-v4.2.2-linux-x64/

npm install grunt-cli

# ln -sv /usr/local/node-v4.2.2-linux-x64/node_modules/grunt-cli/bin/grunt /usr/sbin/

第三步,安装并修改head源码

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

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

修改服务器监听地址

目录:cd elasticsearch-head/

vim Gruntfile.js

connect: {

    server: {

        options: {

            port: 9100,

            hostname: ‘*’,

            base: ‘.’,

            keepalive: true

        }

    }

}

增加hostname属性,设置为*

修改连接地址:

目录:elasticsearch-head/_site/app.js

修改head的连接地址:

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

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

# 经过测试需要配置为服务器的外网IP地址

this.base_uri = this.config.base_uri || this.prefs.get(“app-base_uri”) || “http://1.1.1.1:9200”;

第四步,运行head 首先开启ES

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

npm install 

最后,启动nodejs

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

npm install grunt

# 然后启动nodejs

grunt server

集群健康检测:

http://1.1.1.1:9200/_cluster/health?pretty

{

  “cluster_name” : “yunva_es_cluster”,

  “status” : “green”,

  “timed_out” : false,

  “number_of_nodes” : 2,

  “number_of_data_nodes” : 2,

  “active_primary_shards” : 0,

  “active_shards” : 0,

  “relocating_shards” : 0,

  “initializing_shards” : 0,

  “unassigned_shards” : 0,

  “delayed_unassigned_shards” : 0,

  “number_of_pending_tasks” : 0,

  “number_of_in_flight_fetch” : 0,

  “task_max_waiting_in_queue_millis” : 0,

  “active_shards_percent_as_number” : 100.0

}

4.安装kibana

rpm -ivh kibana-5.0.1-x86_64.rpm

编辑配置文件

vim /etc/kibana/kibana.yml

修改这两项,其他默认不用动

server.host: “0.0.0.0”

elasticsearch.url: “http://localhost:9200”

启动命令:

systemctl start kibana

systemctl enable kibana

kibana访问地址:

http://1.1.1.1

为了安全将kibana 5601和head插件的9100端口通过nginx的密码验证方式访问:

server {  

  listen       80;  

  server_name 1.1.1.1 u04kaf01.chinasoft.com;  

  location / {  

     auth_basic “secret”;  

     auth_basic_user_file /data/nginx/db/passwd.db;  

     proxy_pass http://localhost:5601;

     proxy_set_header Host $host:5601;  

     proxy_set_header X-Real-IP $remote_addr;  

     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  

     proxy_set_header Via “nginx”;  

  }  

  

  location /head/{

     auth_basic “secret”;

     auth_basic_user_file /data/nginx/db/passwd.db;

     proxy_pass http://u04es01.chinasoft.com:9100/;

     proxy_set_header Host $host:9100;

     proxy_set_header X-Real-IP $remote_addr;

     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

     proxy_set_header Via “nginx”;

  }

  access_log off;

}

———————————————————————

配置zabbix检测若9200端口或者5601端口挂掉则自动拉起elasticsearch和kibana服务

具体参考:zabbix系列(九)zabbix3.0实现自动触发zabbix-agent端shell脚本任务

http://blog.csdn.net/reblue520/article/details/52315154

/usr/local/zabbix-agent/scripts/start_es.sh

#!/bin/bash

# if elasticsearch exists kill it

source /etc/profile

count_es=`ps -ef|grep elasticsearch|grep -v grep|wc -l`

if [ $count_es -gt 1 ];then

    ps -ef|grep elasticsearch|grep -v grep|/bin/kill `awk ‘{print $2}’`

fi

# start it

su yunva -c “cd /data/elasticsearch-5.0.1/bin && /bin/bash elasticsearch &”

执行:

sudo /bin/bash /usr/local/zabbix-agent/scripts/start_es.sh

报错:

which: no java in (/sbin:/bin:/usr/sbin:/usr/bin)

Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME

解决办法:

在脚本中添加

source /etc/profile

———————————————————————

以root用户运行elasticsearch

报错:

can not run elasticsearch as root

网上的方法,针对elasticsearch5.1不起作用

解决方法1:

在执行elasticSearch时加上参数-Des.insecure.allow.root=true,完整命令如下

./elasticsearch -Des.insecure.allow.root=true  

解决办法2:

用vi打开elasicsearch执行文件,在变量ES_JAVA_OPTS使用前添加以下命令

ES_JAVA_OPTS=”-Des.insecure.allow.root=true”  

解决办法:

su yunva -c “cd /data/elasticsearch-5.0.1/bin && /bin/bash elasticsearch &”

自动拉起kibana服务的脚本:

cat /usr/local/zabbix/scripts/restart_kibana.sh

#!/bin/bash

# if kibana exists kill it

count_kibana=`ps -ef|grep kibana|grep -v grep|wc -ll`

if [ $count_kibana -eq 1 ];then

    ps -ef|grep kibana|grep -v grep|/bin/kill `awk ‘{print $2}’`

fi

# start it

/etc/init.d/kibana start

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,084
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,559
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,408
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,181
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,818
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,901