-
Notifications
You must be signed in to change notification settings - Fork 0
/
tuto
160 lines (131 loc) · 3.97 KB
/
tuto
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/sh
ES_URL="https://artifacts.elastic.co/downloads/elasticsearch"
LS_URL="https://artifacts.elastic.co/downloads/logstash"
KB_URL="https://artifacts.elastic.co/downloads/kibana"
FB_URL="https://artifacts.elastic.co/downloads/beats/filebeat"
VER="6.7.0"
ES="elasticsearch-${VER}.tar.gz"
LS="logstash-${VER}.tar.gz"
KB="kibana-${VER}-linux-x86_64.tar.gz"
FB="filebeat-${VER}-linux-x86_64.tar.gz"
ES_PKGS=${ES_URL}/${ES}
LS_PKGS=${LS_URL}/${LS}
KB_PKGS=${KB_URL}/${KB}
FB_PKGS=${FB_URL}/${FB}
ES_DIR="elasticsearch"
LS_DIR="logstash"
KB_DIR="kibana"
FB_DIR="filebeat"
HEAD_DIR="elasticsearch-head"
PKGS_DIR="packages"
CONF_DIR="conf"
SYS_DIR="/etc/systemd/system"
ES_CONF="elasticsearch.yml"
KB_CONF="kibana.yml"
FB_CONF="filebeat.yml"
LS_SVC="logstash.service"
KB_SVC="kibana.service"
FB_SVC="filebeat.service"
USER=$(whoami)
PWD=$(pwd)
if [ $USER == "root" ]; then
echo "root is not permitted"
exit -1
fi
if [ $PWD != "/home/ec2-user/elastic-stack-tutorial" ]; then
pwd
echo "/home/ec2-user/elastic-stack-tutorial path is permitted only"
exit -1
fi
function install_elk_packages
{
git pull
# sudo apt-get install openjdk-8-jdk
# sudo sh -c "echo 'export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64' >> /etc/profile"
# sudo sh -c "echo 'export PATH=\$JAVA_HOME/bin:\$PATH' >> /etc/profile"
# sudo sh -c "ehco 'export Class_PATH=\$JAVA_HOME/lib:\$CLASS_PATH' >> /etc/profile"
sudo apt-get install bzip2 # epel-release
sudo apt-get install build-essential libssl-dev
#curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh -o install_nvm.sh
#bash install_nvm.sh
#source ~/.profile
#nvm install 10.15.1
##sudo curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
##sudo apt -y install nodejs
#sudo apt-get install npm
mkdir ${PKGS_DIR}
cd ${PKGS_DIR}
wget ${ES_PKGS}
wget ${LS_PKGS}
wget ${KB_PKGS}
wget ${FB_PKGS}
tar -xfz ${ES}
tar -xfz ${LS}
tar -xfz ${KB}
tar -xfz ${FB}
ln -s ./elasticsearch-${VER} elasticsearch
ln -s ./logstash-${VER} logstash
ln -s ./kibana-${VER}-linux-x86_64 kibana
ln -s ./filebeat-${VER}-linux-x86_64 filebeat
## sudo git clone https://github.com/mobz/elasticsearch-head.git
## cd ${HEAD_DIR}
## sudo apt-get -y update openssl
## sudo npm install
sudo sh -c "echo 'ec2-user soft nofile 65536' >> /etc/security/limits.conf"
sudo sh -c "echo 'ec2-user hard nofile 65536' >> /etc/security/limits.conf"
sudo sh -c "echo 'vm.max_map_count = 262144' >> /etc/sysctl.conf"
sudo sysctl -p
sudo su ec2-user
}
function es_start
{
cp ${CONF_DIR}/${ES_CONF} ${PKGS_DIR}/${ES_DIR}/config/elasticsearch.yml
${PKGS_DIR}/${ES_DIR}/bin/elasticsearch -d
#cd ${PKGS_DIR}/${HEAD_DIR}
##nohup npm run start &
#cd ../..
}
function kb_start
{
cp ${CONF_DIR}/${KB_CONF} ${PKGS_DIR}/${KB_DIR}/config/${KB_CONF}
sudo cp ${CONF_DIR}/${KB_SVC} ${SYS_DIR}/${KB_SVC}
daemon_reload
sudo systemctl start ${KB_SVC}
}
function fb_start
{
cp ${CONF_DIR}/${FB_CONF} ${PKGS_DIR}/${FB_DIR}/${FB_CONF}
sudo cp ${CONF_DIR}/${FB_SVC} ${SYS_DIR}/${FB_SVC}
daemon_reload
sudo systemctl start ${FB_SVC}
}
function no_filter
{
${PKGS_DIR}/${LS_DIR}/bin/logstash -e 'input { stdin {} } output { stdout {} }'
}
function simple_filter
{
${PKGS_DIR}/${LS_DIR}/bin/logstash -f logstash_conf/simple.conf
}
function daemon_reload
{
sudo systemctl daemon-reload
}
if [ -z $1 ]; then
echo "##################### Menu ##############"
echo " $ ./tuto [Command]"
echo "#####################%%%%%%##############"
echo " 1 : install elk packages"
echo " 2 : start es, kibana, filebeat"
echo " 3 : standard input/output, no filters"
echo " 4 : standard input/output, simple filter"
echo "#########################################";
exit 1;
fi
case "$1" in
"1" ) install_elk_packages;;
"2" ) es_start; kb_start; fb_start;;
"3" ) no_filter;;
"4" ) simple_filter;;
*) echo "Incorrect Command" ;;
esac