docker搭建ELK集群

首先安装docker,须要centos7的机子,centos6的百度本身折腾html

#安装docker
yum install -y docker-io 
systemctl start docker

进入正题,这里搭建的是ELK7.2版本node

  1. 搭建elasticsearch
  • 修改内核参数
    vim /etc/sysctl.conf
vm.max_map_count = 655360
vm.swappiness = 1
  • 进入data 建立目录elk
    cd /data && mkdir elk
  • 进入elk,建立目录data logs
    cd elk
    mkdir data
    mkdir logs
  • 回到data 授予elk1000:1000权限(es默认权限是1000)
    cd /data
    chown 1000:1000 elk -R
  • 这里搭建的是2个节点的es,在2台机子分别建目录,而后分别执行如下命令
docker run --name ES   \
        -d --net=host \
        --restart=always \
        --privileged=true \
        --ulimit nofile=655350 \
        --ulimit memlock=-1 \
        --memory=16G \
        --memory-swap=-1 \
        --volume /data:/data \
        --volume /etc/localtime:/etc/localtime \
        -e TERM=dumb \
        -e ELASTIC_PASSWORD='changeme' \
        -e ES_JAVA_OPTS="-Xms8g -Xmx8g" \
        -e cluster.name="es" \
        -e node.name="node-1" \
        -e node.master=true \
        -e node.data=true \
        -e node.ingest=false \
        -e node.attr.rack="0402-K03" \
        -e discovery.zen.ping.unicast.hosts="ip1,ip2" \
        -e xpack.security.enabled=true  \
        -e xpack.monitoring.collection.enabled=true  \
        -e xpack.monitoring.exporters.my_local.type=local \
        -e xpack.monitoring.exporters.my_local.use_ingest=false \
        -e discovery.zen.minimum_master_nodes=1 \
        -e gateway.recover_after_nodes=1 \
        -e cluster.initial_master_nodes="node-1" \
        -e network.host=0.0.0.0 \
        -e http.port=9200 \
        -e path.data=/data/elk/data \
        -e path.logs=/data/elk/logs \
        -e bootstrap.memory_lock=true \
        -e bootstrap.system_call_filter=false \
        -e indices.fielddata.cache.size="25%" \
        elasticsearch:7.2.0

其中须要注意的几个参数,nginx

ELASTIC_PASSWORD 这个是设置你elastic这个用户对应的密码
    memory是你服务器的内存
    ES_JAVA_OPTS这个数值通常是内存的一半
    discovery.zen.ping.unicast.hosts 这个参数是你集群的ip

在第二个节点修改如下参数redis

node.name, node.master=false,去除cluster.initial_master_nodes参数
  • 完成之后就能够执行如下命令看一下日志了

docker logs ES -fdocker

  • 检测一下结果
curl --user elastic:changeme -XGET http://ip1:9200/_cat/indices

clipboard.png

看到这张图就表明你搭建成功了,number_of_nodes表明的节点数 最后一个参数表明加载了多少json

2.搭建kibanabootstrap

  • 搭建kibana比较简单,先拉一下镜像
docker pull kibana
  • 执行命令开启服务
docker run --name kibana \
        --restart=always \
        -d --net=host \
        -v /data:/data \
        -v /etc/localtime:/etc/localtime \
        --privileged \
        -e TERM=dumb \
        -e SERVER_HOST=0.0.0.0 \
        -e SERVER_PORT=5601 \
        -e SERVER_NAME=Kibana-100 \
        -e ELASTICSEARCH_HOSTS=http://localhost:9200 \
        -e ELASTICSEARCH_USERNAME=elastic \
        -e ELASTICSEARCH_PASSWORD=changeme \
        -e XPACK_MONITORING_UI_CONTAINER_ELASTICSEARCH_ENABLED=true \
        -e LOG_FILE=/data/elasticsearch/logs/kibana.log \
        kibana:7.2.0
  • kibana搭建比较简单,接下来就作个nginx设置一下就行了,给个简单的配置
server {
        listen       80;
        #listen       [::]:80 default_server;
        #server_name  ;
        #root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host  $http_host;
        proxy_set_header X-Nginx-Proxy true;
        proxy_set_header Connection "";
        proxy_pass      http://127.0.0.1:5601;

        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
}
  1. logstash安装
  • 建立目录受权
cd /data
mkdir config
cd config
mkdir pipeline
cd /data
chown 1000:1000 config
  • 在config中建立如下文件

vim log4j2.propertiesvim

logger.elasticsearchoutput.name = logstash.outputs.elasticsearch
logger.elasticsearchoutput.level = debug

vim logstash.yml
内容直接放空,wq出来就好centos

vim pipelines.yml服务器

- pipeline.id: my-logstash
  path.config: "/usr/share/logstash/config/pipeline/*.conf"
  pipeline.workers: 3

紧接着进入pipeline目录,建立要

cd pipeline
vim redis2es.conf
input {
    redis {
        data_type => "list"
        codec => "json"
        key => "xxx"
        host => "xxxxxxx"
        port => 6379
        password => "xxxxxx"
        threads => 1
        batch_count => 100
    }
}
output {
    elasticsearch {
        hosts => ["ip1:9200"]
        index => "%{srv}-%{type}-%{+yyyy.MM.dd}"
        document_type => "%{type}"
        workers => 1
        user => "elastic"
        password => "changme"
    }
    file {
        path => "/usr/share/logstash/%{srv}-%{type}-%{+yyyyMMdd}.log"
        gzip => true
        flush_interval => 10
        workers => 1
    }
}

以上xxx请自行脑补


额外扩展,推荐一个工具——dremio
简单的命令解决

docker pull dremio/dremio-oss
docker run -p 9047:9047 -p 31010:31010 -p 45678:45678 dremio/dremio-oss
相关文章
相关标签/搜索