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服务java
具体参考:zabbix系列(九)zabbix3.0实现自动触发zabbix-agent端shell脚本任务node
http://blog.csdn.net/reblue520/article/details/52315154
linux
/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