-
Notifications
You must be signed in to change notification settings - Fork 0
/
logserver_install.sh
executable file
·137 lines (99 loc) · 5.24 KB
/
logserver_install.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
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
#!/bin/sh
echo "***** CIF (Cyber Intelligence Framework) *****"
echo "***** *****"
echo "***** Author: Gijs Rijnders *****"
echo "***** *****"
echo "***** Log server installation script *****"
echo "***** This script will install the Logstash, *****"
echo "***** ElasticSearch and Kibana components. *****"
echo ""
# Check if the script is ran with root permissions
if [[ $UID != 0 ]]; then
echo "Please run this script with sudo:"
echo "sudo $0 $*"
exit 1
fi
# Install Java 8
echo "***** Installing Java 8... *****"
cd /opt
# Download Java 8u60 (Update these lines if a newer Java version/update is released!)
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u60-b27/jdk-8u60-linux-x64.tar.gz"
tar xzf jdk-8u60-linux-x64.tar.gz
rm -f jdk-8u60-linux-x64.tar.gz
cd /opt/jdk1.8.0_60/
# Install Java as alternative. It may have to be selected as primary manually
alternatives --install /usr/bin/java java /opt/jdk1.8.0_60/bin/java 2
alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_60/bin/jar 2
alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_60/bin/javac 2
alternatives --set jar /opt/jdk1.8.0_60/bin/jar
alternatives --set javac /opt/jdk1.8.0_60/bin/javac
# Check if the Java environment variables are already set
if [ $(grep -c 'jdk1.8' /etc/environment) -ne 0 ]
then
echo "***** The environment variables are already set! *****"
else
# Set Java environment variables accordingly
echo "JAVA_HOME=/opt/jdk1.8.0_60" >> /etc/environment
echo "JRE_HOME=/opt/jdk1.8.0_60/jre" >> /etc/environment
echo "PATH=$PATH:/opt/jdk1.8.0_60/bin:/opt/jdk1.8.0_60/jre/bin" >> /etc/environment
fi
echo "***** Installing ElasticSearch... *****"
# Add the ElasticSearch repository and install the packages
sudo rpm --import http://packages.elasticsearch.org/GPG-KEY-elasticsearch
# Check if the repository descriptor exists
if [ -f "/etc/yum.repos.d/elasticsearch.repo" ]
then
rm -f /etc/yum.repos.d/elasticsearch.repo
fi
# (Re)create the repository descriptor
touch /etc/yum.repos.d/elasticsearch.repo
printf '%s\n%s\n%s\n%s\n%s\n%s' '[elasticsearch-1.7]' 'name=Elasticsearch repository for 1.7.x packages' 'baseurl=http://packages.elasticsearch.org/elasticsearch/1.7/centos' 'gpgcheck=1' 'gpgkey=http://packages.elasticsearch.org/GPG-KEY-elasticsearch' 'enabled=1' >> /etc/yum.repos.d/elasticsearch.repo
yum -y install elasticsearch
# Enable and start ElasticSearch using SystemCtl
systemctl start elasticsearch
systemctl enable elasticsearch
echo "***** Installing Kibana... *****"
# Check whether Kibana4 is already installed (in case of an error in a previous execution of this script)
if [ $(systemctl status kibana4 | grep -c not-found) = 1 ]
then
# Download and unpack Kibana4
cd ~; wget https://download.elasticsearch.org/kibana/kibana/kibana-4.1.2-linux-x64.tar.gz
tar xf kibana-*.tar.gz
rm -f kibana-*.tar.gz
mkdir -p /opt/kibana
cp -R ~/kibana-4*/* /opt/kibana/
touch /etc/systemd/system/kibana4.service
# Enable and start Kibana4 as a service
printf '%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n\n%s\n%s\n%s' '[Service]' 'ExecStart=/opt/kibana/bin/kibana' 'Restart=always' 'StandardOutput=syslog' 'StandardError=syslog' 'SyslogIdentifier=kibana4' 'User=root' 'Group=root' 'Environment=NODE_ENV=production' '[Install]' 'WantedBy=multi-user.target' >> /etc/systemd/system/kibana4.service
systemctl start kibana4
systemctl enable kibana4
else
echo "***** Kibana4 is already installed, nothing to do! *****"
fi
echo "***** Installing Logstash... *****"
# Add the Logstash repository and install the packages
# Check if the Logstash repository descriptor exists
if [ -f "/etc/yum.repos.d/logstash.repo" ]
then
rm -f /etc/yum.repos.d/logstash.repo
fi
# (Re)create the repository descriptor
touch /etc/yum.repos.d/logstash.repo
printf '%s\n%s\n%s\n%s\n%s\n%s' '[logstash-1.5]' 'name=logstash repository for 1.5.x packages' 'baseurl=http://packages.elasticsearch.org/logstash/1.5/centos' 'gpgcheck=1' 'gpgkey=http://packages.elasticsearch.org/GPG-KEY-elasticsearch' 'enabled=1' >> /etc/yum.repos.d/logstash.repo
yum -y install logstash
# Enable and start the Logstash service
systemctl start logstash
# Display notices for the user at the end of the installation script
echo ""
echo "***** A new version of java has been installed on the system. *****"
echo "***** If you have multiple versions of Java installed, use *****"
echo "***** the 'alternatives --config java' command to manually *****"
echo "***** select the latest one to be active. *****"
echo "***** *****"
echo "***** For extra security, change the network.host setting *****"
echo "***** of ElasticSearch. Change the line 'network.host:<ip>' *****"
echo "***** into 'network.host: localhost'. Do this in the file: *****"
echo "***** /etc/elasticsearch/elasticsearch.yml and restart *****"
echo "***** the ElasticSearch service. *****"
echo "***** *****"
echo "***** CIF Logserver components have been installed! *****"