(在安装之前,本方法必须安装jdk1.8以上版本)
一、安装elasticsearch
1、下载elasticsearch7镜像:docker pull elasticsearch:7.7.1
2、创建挂载目录:mkdir -p /data/elk/es/{config,data,logs}
3、赋予权限:chown -R 1000:1000 /data/elk/es
5、创建挂在目录:mkdir -p /data/elk/es/config
6、创建挂载用配置:
cd /data/elk/es/config
vim elasticsearch.yml
cluster.name: "my-es"
network.host: 0.0.0.0
http.port: 9200
7、运行elasticsearch:
docker run -it -d -p 9200:9200 -p 9300:9300 --name es -e ES_JAVA_OPTS="-Xms1g -Xmx1g" -e "discovery.type=single-node" --restart=always -v /data/elk/es/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /data/elk/es/data:/usr/share/elasticsearch/data -v /data/elk/es/logs:/usr/share/elasticsearch/logs elasticsearch:7.7.1
8、验证安装是否成功:curl http://localhost:9200
二、安装kibana
1、下载kibana7镜像:docker pull kibana:7.7.1
2、获取elasticsearch容器ip:docker inspect --format '{{ .NetworkSettings.IPAddress }}' es
3、创建配置文件目录:mkdir -p /data/elk/kibana
4、配置文件:
vi /data/elk/kibana/kibana.yml
server.name: kibana
server.host: "0"
elasticsearch.hosts: ["http://172.17.0.6:9200"]
xpack.monitoring.ui.container.elasticsearch.enabled: true
(注:这里的IP地址是第二步输出的IP地址)
5、运行kibana:
docker run -d --restart=always --log-driver json-file --log-opt max-size=100m --log-opt max-file=2 --name kibana -p 5601:5601 -v /data/elk/kibana/kibana.yml:/usr/share/kibana/config/kibana.yml kibana:7.7.1
6、在浏览器上运行:http://192.168.8.166:5601
7、修改elasticsearch.hosts地址
docker exec -it kibana /bin/bash
cd config
vi kibana.yml,修改后的配置如下:
server.name: kibana
server.host: "0"
elasticsearch.hosts: ["http://172.17.0.2:9200"]
xpack.monitoring.ui.container.elasticsearch.enabled: true
(注:这里的IP地址是第二步输出的IP地址,这步是自动生成的)
8、重启kibana:docker restart kibana
三、安装Logstash
1、下载Logstash7镜像:docker pull logstash:7.7.1
2、创建logstash配置目录:mkdir /data/elk/logstash/
3、配置logstash文件:vim /data/elk/logstash/logstash.yml
http.host: "0.0.0.0"
xpack.monitoring.elasticsearch.hosts: [ "http://172.17.0.2:9200" ]
xpack.monitoring.elasticsearch.username: elastic
xpack.monitoring.elasticsearch.password: hcmcm88wde55
#path.config: /data/elk/logstash/conf.d/*.conf
path.config: /data/docker/logstash/conf.d/*.conf
path.logs: /var/log/logstash
4、配置logstash.conf文件
mkdir -p /data/elk/logstash/conf.d/
vim /data/elk/logstash/conf.d/syslog.conf
input {
syslog {
type => "system-syslog"
port => 5044
}
}
output {
elasticsearch {
hosts => ["192.168.8.166:9200"] # 定义es服务器的ip
index => "system-syslog-%{+YYYY.MM}" # 定义索引
}
}
5、编辑本地rsyslog配置增加:vim /etc/rsyslog.conf
*.* @@192.168.8.166:5044
6、配置修改后重启服务:systemctl restart rsyslog
7、运行logstash:
docker run -d --restart=always --log-driver json-file --log-opt max-size=100m --log-opt max-file=2 -p 5044:5044 --name logstash -v /data/elk/logstash/logstash.yml:/usr/share/logstash/config/logstash.yml -v /data/elk/logstash/conf.d/:/data/docker/logstash/conf.d/ logstash:7.7.1
8、测试es接收logstash数据:
curl http://localhost:9200/_cat/indices?v
获取到system-syslog-相关日志,则es已能获取来自logstash的数据,kibana中也同步显示数据。