一、复制5份es,版本要相同,且各个节点上jdk版本也要相同,不然会报数据同步格式不一致 invalid internal transport message format。node
二、配置elasticsearch.yml,主要修改如下方面:nginx
cluster.name: my-application #集群名,各个节点要一致git
node.name: node-01 #节点名github
path.data: /data1/elk/elasticsearch/data #数据存储位置bootstrap
path.logs: /data1/elk/elasticsearch/logs #日志vim
bootstrap.system_call_filter: false #关闭锁内存安全
network.host: 192.168.0.1 #各个节点IP,每一个节点写本身的ipapp
http.port: 9200 #端口curl
discovery.zen.ping.unicast.hosts: ["192.168.0.1", "192.168.0.2","192.168.0.3","192.168.0.4","192.168.0.5"] #集群ip列表elasticsearch
discovery.zen.minimum_master_nodes: 3 #集群master节点数,建议为(集群节点总数/2)+1
三、配置好直接启动便可,随意先启动哪一台,先启动即为master。9300是tcp通信端口,集群间和TCPClient都走的它,因此各个主机间9300必定要能互通。
四、验证集群 ,es 9200是http协议的RESTful接口,可用此端口查看集群状态
curl -XGET 'http://192.168.0.1:9200/_cat/nodes?pretty'
其中
结果以下表示集群已搭建成功:
五、es启动脚本
vim /etc/init.d/es
#!/bin/sh
#chkconfig: 2345 80 05
#description: elasticsearch
export JAVA_HOME=/usr/local/jdk1.8.0_92
export JAVA_BIN=/usr/local/jdk1.8.0_92/bin
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH
case "$1" in
start)
su dev<<!
cd /data1/elk/elasticsearch
./bin/elasticsearch -d
!
echo "elasticsearch startup"
;;
stop)
es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
kill -9 $es_pid
echo "elasticsearch stopped"
;;
restart)
es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
kill -9 $es_pid
echo "elasticsearch stopped"
su dev<<!
cd /data1/elk/elasticsearch
./bin/elasticsearch -d
!
echo "elasticsearch startup"
;;
*)
echo "start|stop|restart"
;;
esac
exit $?
六、集群管理-cerebro
下载cerebro
解压并配置application.conf wget https://github.com/lmenezes/cerebro/releases/download/v0.7.2/cerebro-0.7.2.zip
启动后,访问http://127.0.0.1:9000 便可
由于cerebo目前没有什么登陆验证(最起码写这篇博客时,我还不知道,若是大家知道更方便的登陆验证,请留言告诉我,谢谢~),用户直接访问域名便可,不是很安全,因此用nginx配置下登陆验证。
一、在location /下添加auth_basic_user_file /usr/local/.passwd;
二、登录http://tool.oschina.net/htpasswd 输入用户名和密码,在线生成加密密码
三、将生成的密码写入/usr/local/.passwd文件中
echo "wuyun:$apr1$TrU5vUSC$RBuz3xG67Mr2pnAV596N5." >/usr/local/.passwd
nginx配置以下:
此时重启nginx,再登陆访问域名时就须要输入帐号密码了。不输入密码会报401 Authorization Required错误
另若是logstash启动多个配置需先创建单独存在配置文件目录,
而后启动
nohup ./logstash -f ../conf &