forked from 9652040795/aws-policies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogstash.sh
105 lines (68 loc) · 2.06 KB
/
logstash.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
# OS: RHEL-7/8 Centos-7/8
ELASTIC_SEARCH_URL="vpc-abc-oeydc53oi53pes74763ztbukge.us-east-1.es.amazonaws.com:443"
# Java Requirement
# Install Java v8 (if it is lesser than v8)
yum -y install java-1.8.0-openjdk
yum -y remove java-1.7.0-openjdk
java -version
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
# Create Repo
# Create a file called logstash.repo in the /etc/yum.repos.d/
echo '[logstash-6.x]
name=Elastic repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
' | sudo tee /etc/yum.repos.d/elasticsearch.repo
# Install from RPM
yum -y install logstash
# Install the Amazon ES Logstash Output Plugin
/usr/share/logstash/bin/logstash-plugin update
/usr/share/logstash/bin/logstash-plugin install logstash-output-amazon_es
# Let’s create the input configuration:
cat << EOF > /etc/logstash/conf.d/10-input.conf
input {
file {
path => "/var/log/nginx/access.log"
start_position => "beginning"
}
}
EOF
# Our filter configuration: /etc/logstash/conf.d/20-filter.conf
cat << EOF > /etc/logstash/conf.d/20-filter.conf
ilter {
grok {
match => { "message" => "%{HTTPD_COMMONLOG}" }
}
mutate {
add_field => {
"custom_field1" => "hello from: %{host}"
}
}
}
EOF
# And lastly, our output configuration: /etc/logstash/conf.d/30-outputs.conf
#vNOTE- HERE YOU WILL PUT THE ELASTICSEARCH ENDPOINT
cat << EOF > /etc/logstash/conf.d/30-outputs.conf
output {
amazon_es {
hosts => ["$ELASTIC_SEARCH_URL"]
index => "new-logstash-%{+YYYY.MM.dd}"
region => "eu-west-1"
aws_access_key_id => ''
aws_secret_access_key => ''
}
}
EOF
# Start LogStash
systemctl start logstash
# Status LogStash
systemctl status logstash
# END
# https://blog.ruanbekker.com/blog/2019/06/04/setup-a-logstash-server-for-amazon-elasticsearch-service-and-auth-with-iam/
# https://www.youtube.com/watch?v=YasrCKykAKo
# https://github.com/miztiik/elk-stack/tree/master/Logstash