docker install logstash service

1. Create a directory
mkdir logstash #Main directory
cd logstash
mkdir dockerfile #Dockerfile build mirror directory
mkdir shell #Service build startup related scripts
mkdir volumes #Mount service configuration, logs, data
insert image description here
2. Write Dockerfile
cd dockerfile
logstash installation is relatively simple, mainly Some configuration files need to be configured; directly based on existing images, Dockerfile basically has no content
vim Dockerfile
adds content

FROM logstash:7.4.2


USER logstash

ENTRYPOINT ["logstash","-f"]

CMD ["/usr/share/logstash/logstash.conf"]

3. Write the build script

cd ../shell
vim build

add content


#!/bin/bash
DOCKER_PATH=$PWD/../
sudo docker build -f $DOCKER_PATH/dockerfile/Dockerfile  -t logstash:7.4.2 $DOCKER_PATH/dockerfile/

Give execution permission
chmod 755 build
build
image./build
insert image description here

View the mirrored
docker images
insert image description here
3. Modify the configuration file
Enter the volumes directory
Create the config directory to mount the configuration file
mkdir config
Write the configuration file logstash.conf
cd config
vim logstash.conf
The content is as follows

# Sample Logstash configuration for creating a simple
# Beats -> Logstash -> Elasticsearch pipeline.

input {
#  beats {
#    port => 5044
#  }
tcp {
	 # elastcisearch 服务所在 ip 地址(docker内注释这行)
	 host => "127.0.0.1"
	 # logstash的端口,默认为 5044。
	 port => 5044
	 codec => json_lines
	}
}

output {
  elasticsearch {
    hosts => ["http://127.0.0.1:9200"]
    index =>  "logstash-console-%{+YYYY.MM.dd}"
    #user => "elastic"
    #password => "changeme"
  }
}

Write the configuration file logstash.yml
vim logstash.yml
to modify the content

# 127.0.0.1 为 logstash 服务所在 ip
http.host: "127.0.0.1"(docker需要填0.0.0.0否则外部无法访问)
http.port: 9600

4. Write a script to create a container. The content of
vim run
is

#!/bin/bash
DOCKER_PATH=$PWD/../
port=9600
imageName=logstash
version=7.4.2
sudo docker run -itd  -p ${port}:9600 -p 5044:5044  --name logstash  -v /etc/localtime:/etc/localtime -v $DOCKER_PATH/volumes/config/jvm.options:/usr/share/logstash/config/jvm.options -v $DOCKER_PATH/volumes/config/logstash.conf:/usr/share/logstash/config/logstash.conf -v $DOCKER_PATH/volumes/config/logstash.yml:/usr/share/logstash/config/logstash.yml -v $DOCKER_PATH/volumes/data/:/usr/share/logstash/data/ --restart=always ${imageName}:${version}

Give execution permission
chmod 755 run
to create a container and start
it./run
insert image description here
to view the container
docker ps
insert image description here
5. Verify whether it is successful
Enter the host ip in the browser: 9600
insert image description here

Guess you like

Origin blog.csdn.net/weixin_44835704/article/details/119974169