filebeat+ELK+kafka集群搭建(五:Elastic
四、安装:Elasticsearch:
1. 安装java(在我的架构是安装过的)
Elasticsearch至少需要Java 8.版本的java,建议使用Oracle JDK 1.8.0_131版(官网建议)。如果没符合标准,请自行升级。本文只描述新安装java
[root@es-1 ~]# yum install -y java-1.8.0
[root@es-1 ~]# java -version
openjdk version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-b10)
OpenJDK 64-Bit Server VM (build 25.171-b10, mixed mode)
2.导入Elasticsearch PGP密钥
[root@es-1 ~]# rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
3.建立rpm包的repo
[root@es-1 ~]# vim /etc/yum.repos.d/elasticsearch.repo
[elasticsearch-5.x]
name=Elasticsearch repository for 5.x packages
baseurl=https://artifacts.elastic.co/packages/5.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
4.安装elasticsearch
[root@es-1 ~]# yum -y install elasticsearch
5.编辑配置文件(省略号代表有其他内容,但是不用修改)
[root@es-1 ~]# vim /etc/elasticsearch/elasticsearch.yml
# ---------------------------------- Cluster -----------------------------------
…………
#cluster.name: my-application
cluster.name: ELK #起名三个节点要一致
…………
# ------------------------------------ Node ------------------------------------
…………
#node.name: node-1
node.name: es-1 #节点名:三个节点不一致
…………
# ---------------------------------- Network -----------------------------------
……
#network.host: 192.168.0.1
network.host: 192.168.205.155 #当前IP地址
#
# Set a custom port for HTTP:
#http.port: 9200 #端口号:默认9200
……
# --------------------------------- Discovery ----------------------------------
…………
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
discovery.zen.ping.unicast.hosts: ["192.168.205.155","192.168.205.156","192.168.205.157"]
#集群节点IP地址
…………
6.启动、添加开机自启
[root@es-1 ~]# systemctl daemon-reload #重载所有修改过的配置文件(刷新配置)
[root@es-1 ~]# systemctl start elasticsearch #开启服务
[root@es-1 ~]# systemctl enable elasticsearch #设置开机自启动
[root@es-1 ~]# systemctl status elasticsearch #检查状态
● elasticsearch.service – Elasticsearch
Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled; vendor preset: disabled)
Active: active (running) since 四 2018-05-24 10:20:04 CST; 3h 12min ago
7.查看端口状态
[root@es-1 ~]# netstat -ntlt
tcp6 0 0 192.168.205.155:9200 :::* LISTEN
tcp6 0 0 192.168.205.155:9300 :::* LISTEN
#9200是默认端口
#9300是集群通信端口
8.其他节点配置
es-2和es-3的安装和es-1步骤相同。不同之处为配置文件node.name:、network.host:
9.相关命令
•检查Elasticsearch是否运行
[root@es-1 ~]# curl -X GET "192.168.205.155:9200/"
{
"name" : "es-1",
"cluster_name" : "ELK",
"cluster_uuid" : "JBdisD6qT_aEbCbz5eZo8Q",
"version" : {
"number" : "5.6.9",
"build_hash" : "877a590",
"build_date" : "2018-04-12T16:25:14.838Z",
"build_snapshot" : false,
"lucene_version" : "6.6.1"
},
"tagline" : "You Know, for Search"
}
•查询集群状态
[root@es-1 ~]# curl -XGET 'http://192.168.205.155:9200/_cat/nodes' #任选一台机器执行
192.168.205.157 19 45 0 0.00 0.01 0.05 mdi - es-3
192.168.205.156 20 43 0 0.00 0.01 0.05 mdi - es-2
192.168.205.155 26 74 0 0.30 0.18 0.09 mdi * es-1 #带*号的是自动选举出来的master
[root@es-1 ~]# curl -XGET 'http://192.168.205.155:9200/_cat/nodes?v'
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
192.168.205.157 20 45 0 0.00 0.01 0.05 mdi - es-3
192.168.205.156 20 43 0 0.00 0.01 0.05 mdi - es-2
192.168.205.155 26 74 0 0.05 0.12 0.08 mdi * es-1
[root@es-1 ~]# curl -XGET 'http://192.168.205.155:9200/_cluster/state/nodes?pretty'
{
"cluster_name" : "ELK", #名字
"nodes" : {
"fkzXpqmxTkCFdYOUqkWw4g" : { #ID值
"name" : "es-3", #node名字
"ephemeral_id" : "c0tVVqFvRUq9vBY0FAGW2Q", #id
"transport_address" : "192.168.205.157:9300", #集群通讯地址
"attributes" : { }
},
"4ZbLhzt6Q5GK4kyICnYWHg" : { #ID值
"name" : "es-2", #node名字
"ephemeral_id" : "E28qTcY_QxWHuZkENO9-gQ", #id
"transport_address" : "192.168.205.156:9300", #集群通讯地址
"attributes" : { }
},
"SVXe8qm9RACCRl1Zb1qs8w" : { #ID值
"name" : "es-1", #node名字
"ephemeral_id" : "w19b7MK_RO221SrwarV8Cg", #id
"transport_address" : "192.168.205.155:9300", #集群通讯地址
"attributes" : { }
}
}
}
•查询集群中的master
[root@es-1 ~]# curl -XGET 'http://192.168.205.156:9200/_cluster/state/master_node?pretty'
{
"cluster_name" : "ELK",
"master_node" : "SVXe8qm9RACCRl1Zb1qs8w"
}
[root@es-1 ~]# curl -XGET 'http://192.168.205.155:9200/_cat/master?v'
id host ip node
SVXe8qm9RACCRl1Zb1qs8w 192.168.205.155 192.168.205.155 es-1
•查询集群的健康状态
[root@es-1 ~]# curl -XGET 'http://192.168.205.155:9200/_cat/health?v'
epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1527142257 14:10:57 ELK green 3 3 0 0 0 0 0 0 - 100.0%
###Status下边是状态显示
[root@es-1 ~]# curl -XGET 'http://192.168.205.155:9200/_cluster/health?pretty'
{
"cluster_name" : "ELK",
"status" : "green", ##代表正常
"timed_out" : false,
"number_of_nodes" : 3,
"number_of_data_nodes" : 3,
"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
}
10.相关文件路径
/etc/elasticsearch/elasticsearch.yml ---主配置文件
/etc/elasticsearch/jvm.options ---jvm参数配置文件
/etc/elasticsearch/log4j2.properties ----日志配置文件
/etc/sysconfig/elasticsearch ---系统配置文件
/usr/share/elasticsearch/bin ---二进制脚本文件
/var/lib/elasticsearch ---在节点上分配的每个索引/分片的数据文件的位置。
/var/log/elasticsearch ---日志文件位置
/usr/share/elasticsearch/plugins ---插件目录
/etc/elasticsearch/scripts ---脚本文件位置
至此elasticsearch集群布置结束
上一篇:filebeat+ELK+kafka集群搭建(四:logstash部署)
下一篇:filebeat+ELK+kafka集群搭建(六:kibana部署)