forked from wojciechka/nagios-install
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·214 lines (187 loc) · 6.47 KB
/
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/bin/sh
# Automatically install Nagios and Nagios plugins on multiple popular
# Linux distributions - including Debian, Ubuntu, CentOS, RHEL and others
#
# Copyright (c) 2008 - 2016, Wojciech Kocjan
#
# This script is licensed under BSD license
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
NAGIOS_VERSION=4.1.1
NAGIOS_PLUGINS_VERSION=2.1.1
# needed for older Linux distributions such as Ubuntu 12 or Debian 7
WGET="wget --no-check-certificate"
# Install prerequisites
if which apt-get >/dev/null 2>/dev/null ; then
export DEBIAN_FRONTEND=noninteractive
apt-get update || exit 1
apt-get -y upgrade || exit 1
apt-get -y install wget gcc make binutils cpp \
libpq-dev libmysqlclient-dev \
libssl1.0.0 libssl-dev pkg-config \
libgd2-xpm-dev libgd-tools \
perl libperl-dev libnet-snmp-perl snmp \
apache2 apache2-utils libapache2-mod-php5 \
unzip tar gzip || exit 1
elif yum --help >/dev/null 2>/dev/null ; then
yum -y update || exit 1
yum -y install wget gcc make imake binutils cpp \
postgresql-devel mysql-libs mysql-devel \
openssl openssl-devel pkgconfig \
gd gd-devel gd-progs libpng libpng-devel \
libjpeg libjpeg-devel perl perl-devel \
net-snmp net-snmp-devel net-snmp-perl net-snmp-utils \
httpd php \
unzip tar gzip || exit 1
else
echo "Unknown or not supported packaging system"
exit 1
fi
# Determine web server username
if [ -d /etc/apache2 ] ; then
USER_RESULT=`grep -rh '^ *User \|APACHE_RUN_USER=' /etc/apache2 | grep -v '^ *User .*APACHE_RUN_USER'`
elif [ -d /etc/httpd ] ; then
USER_RESULT=`grep -rh '^ *User ' /etc/httpd`
else
USER_RESULT=''
fi
# Parse the output if available or determine user based on known values
if [ "x$USER_RESULT" != "x" ] ; then
WEB_USER=`echo "$USER_RESULT" | sed 's,^\s*User\s\+,,;s,^.*APACHE_RUN_USER=,,'`
else
for NAME in apache www-data daemon ; do
if id -u $NAME >/dev/null 2>/dev/null ; then
WEB_USER=$NAME
break
fi
done
fi
if [ "x$WEB_USER" = "x" ] ; then
echo "Unable to determine web server username"
exit 1
fi
# Fail on errors when setting up Nagios and Nagios plugins
set -e
# Set up users and groups
groupadd nagios
groupadd nagioscmd
useradd -g nagios -G nagioscmd -d /opt/nagios nagios
if [ "x$WEB_USER" != "x" ] ; then
usermod -G nagioscmd $WEB_USER
fi
# create required directories and ensure proper ownership permissiosn
mkdir -p /opt/nagios /etc/nagios /var/nagios
chown root:root /etc/nagios /opt/nagios
chown nagios:nagios /var/nagios
chmod 0755 /opt/nagios /etc/nagios
# Prepare compilation directory
rm -fR /tmp/nagios-src ; mkdir -p /tmp/nagios-src
cd /tmp/nagios-src
# Compile Nagios
$WGET -O nagios.tar.gz https://assets.nagios.com/downloads/nagioscore/releases/nagios-$NAGIOS_VERSION.tar.gz
tar -xzf nagios.tar.gz ; rm nagios.tar.gz
cd nagios-$NAGIOS_VERSION
sh configure \
--prefix=/opt/nagios \
--sysconfdir=/etc/nagios \
--localstatedir=/var/nagios \
--libexecdir=/opt/nagios/plugins \
--with-command-group=nagioscmd
make all
make install
make install-commandmode
make install-config
make install-init
# Compile Nagios plugins
cd /tmp/nagios-src
$WGET -O nagios-plugins.tar.gz http://www.nagios-plugins.org/download/nagios-plugins-$NAGIOS_PLUGINS_VERSION.tar.gz
tar -xzf nagios-plugins.tar.gz ; rm nagios-plugins.tar.gz
cd nagios-plugins-$NAGIOS_PLUGINS_VERSION
sh configure \
--prefix=/opt/nagios \
--sysconfdir=/etc/nagios \
--localstatedir=/var/nagios \
--libexecdir=/opt/nagios/plugins
make all
make install
# re-apply permissions
chown root:root /etc/nagios /opt/nagios
chown nagios:nagios /var/nagios
chmod 0755 /opt/nagios /etc/nagios
for DIR in /etc/apache2 /etc/httpd ; do
if [ -d "$DIR" ] ; then
HTTPD_CONFIG_DIR=$DIR
break
fi
done
# for Ubuntu/Debian, enable cgi and auth_basic modules
if which a2enmod >/dev/null 2>/dev/null ; then
a2enmod cgi
a2enmod auth_basic
fi
if [ "x$HTTPD_CONFIG_DIR" != "x" ] ; then
if [ -d "$HTTPD_CONFIG_DIR/conf-available" ] && [ -d "$HTTPD_CONFIG_DIR/conf-enabled" ] ; then
HTTPD_CONFIG_FILE="$HTTPD_CONFIG_DIR/conf-available/nagios.conf"
HTTPD_CONFIG_LINK="$HTTPD_CONFIG_DIR/conf-enabled/010-nagios.conf"
elif [ -d "$HTTPD_CONFIG_DIR/conf.d" ] ; then
HTTPD_CONFIG_FILE="$HTTPD_CONFIG_DIR/conf.d/nagios.conf"
fi
fi
if [ "x$HTTPD_CONFIG_FILE" != "x" ] ; then
cat >$HTTPD_CONFIG_FILE <<EOF
ScriptAlias /nagios/cgi-bin /opt/nagios/sbin
Alias /nagios /opt/nagios/share
<Location "/nagios">
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /etc/nagios/htpasswd.users
require valid-user
</Location>
<Directory "/opt/nagios/share">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Require all granted
Order allow,deny
Allow from all
</Directory>
<Directory "/opt/nagios/sbin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Require all granted
Order allow,deny
Allow from all
</Directory>
EOF
cp /dev/null /etc/nagios/htpasswd.groups
htpasswd -b -c /etc/nagios/htpasswd.users nagiosadmin nagiosadmin
if [ "x$HTTPD_CONFIG_LINK" != "x" ] ; then
ln -s $HTTPD_CONFIG_FILE $HTTPD_CONFIG_LINK
fi
else
echo "Unable to locate Apache configuration directory - skipping web server configuration"
exit 1
fi
# cleanup
cd /
rm -fR /tmp/nagios-src
echo "Congratulations! Nagios and standard plugins are now installed."