美文网首页
centos7 ELK elastic stack elast

centos7 ELK elastic stack elast

作者: 勇不言弃92 | 来源:发表于2019-04-29 11:51 被阅读0次

docker 单服务器 elasticsearch集群
docker 多服务器elasticsearch集群

服务器1接收数据分析并展示数据,2和3提供日志数据,服务器4为子节点,2和3也可配置为子节点
服务器1:
elasticsearch
kibana
logstash
服务器4:
elasticsearch

服务器2:
beat:filebeat
服务器3:
beat:filebeat


elastic.png

安装Java

yum install java*
检查版本,1.8以上
java -version

安装elasticsearch,kibana,logstash

elasticsearch,kibana,logstash这三个是安装在服务器1上的
下载地址
下面展示的是用centos7 下载的是linux-64-bit版本,下载好后解压使用命令行tar -zxvf {file}

elasticsearch

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.0.0-linux-x86_64.tar.gz

使用默认配置,直接运行,或者配置集群和节点信息等
elasticsearch.yml配置文件:
集群节点配置:
node1

cluster.name: wwzb_elastic
node.name: node1
node.master: true
node.data: true
path.data: /data/els/data
path.logs: /data/els/logs
network.host: 0.0.0.0
http.port: 9200
transport.tcp.port: 9300
discovery.seed_hosts: ["服务器1-IP:9300", "服务器4-IP:9301"]
cluster.initial_master_nodes: ["node1"]
gateway.recover_after_nodes: 2
gateway.recover_after_time: 5m
gateway.expected_nodes: 1
indices.recovery.max_bytes_per_sec: 20mb
http.cors.enabled: true
http.cors.allow-origin: "*"

node2

cluster.name: wwzb_elastic
node.name: node2
node.master: false
node.data: true
path.data: /data/els/data
path.logs: /data/els/logs
network.host: 0.0.0.0
http.port: 9201
transport.tcp.port: 9301
discovery.seed_hosts: ["服务器1-IP:9300", "服务器4-IP:9301"]
cluster.initial_master_nodes: ["node1"]
gateway.recover_after_nodes: 2
gateway.recover_after_time: 5m
gateway.expected_nodes: 1
indices.recovery.max_bytes_per_sec: 20mb
http.cors.enabled: true
http.cors.allow-origin: "*"

elasticsearch不能使用root运行,需要新建一个用户,并更改elasticsearch的归属

groupadd elastic
useradd elastic -g elastic
chown -R elastic:elastic {file}

切换用户,运行elasticsearch,运行后切换回root

su elastic
bin/elasticsearch

查看运行结果

curl http://localhost:9200/

kibana

下载后解压文件

wget https://artifacts.elastic.co/downloads/kibana/kibana-7.0.0-linux-x86_64.tar.gz

配置kibana.yml

server.port: 5601
server.host: "0.0.0.0"
elasticsearch.hosts: ["http://127.0.0.1:9200"]
```
运行kibana,在浏览器查看“http://IP:5601”
```
bin/kibana
```


####logstash
```
wget https://artifacts.elastic.co/downloads/logstash/logstash-7.0.0.tar.gz
```
在config中添加test.conf,详细配置自行按照需求增加,input-filter-output
```
input {
  beats {
    port => 5044
  }
}
output {
  elasticsearch {
    hosts => "localhost:9200"
    manage_template => false
    index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"
  }
}
```
在logstash目录下运行
```
bin/logstash -f config/logstash.conf
```



####filebeat
filebeat安装在需要收集日志的服务器上,即服务器2和3
```
https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.0.0-linux-x86_64.tar.gz
```
配置filebeat.yml
```
filebeat.inputs:
- type: log
  enabled: true
  paths:
    - /home/blog/storage/logs/*.log
    - /var/log/*.log

#output.elasticsearch:
 # hosts: ["localhost:9200"]

output.logstash:
  hosts: ["IP:5044"]
```
运行
```
sudo ./filebeat -e -c filebeat.yml
```
这时服务器2和3就开始向服务器1传输日志文件了,使用服务器1的IP地址访问5601端口可看到kibana上展示的数据,运行时可能会有报错,报错都是因为配置文件,按照提示调一下就OK了。


###通过yum命令安装
上面所需的安装包也可通过yum安装
安装在/etc/{name}下
添加yum源
vim /etc/yum.repos.d/elastic.repo
```
[elastic-7.x]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
```
安装
```
sudo yum install {name} //eg:sudo yum install kibana
```
运行
```
systemctl start {name}
systemctl status {name}
systemctl stop {name}
```

###可能用到的命令
```
lsof -i tcp:80//查看80端口状态
netstat -ntlp//列出所有端口

firewall-cmd --state //查看防火墙状态
systemctl unmask firewalld.service //
systemctl stop firewalld.service //关闭防火墙
systemctl disable firewalld.service //
systemctl start firewalld.service //打开防火墙
```



[ElasticSearch PHP 使用](https://www.jianshu.com/p/70ecd565eccb)
后面会写一篇使用[docker配置的方式](https://www.jianshu.com/p/17a903932aa9)

相关文章

网友评论

      本文标题:centos7 ELK elastic stack elast

      本文链接:https://www.haomeiwen.com/subject/nvfynqtx.html