forked from defaultusers/storage-system-monitoring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
280 lines (222 loc) · 7.37 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#!/bin/bash
#
# Это скрипт установщик для системы мониторинга дисковой подсистемы серверов компании FastVPS Eesti OU
# Если у Вас есть вопросы по работе данной системы, рекомендуем обратиться по адресам:
# - https://github.com/FastVPSEestiOu/storage-system-monitoring
# - https://bill2fast.com (через тикет систему)
#
# Данные пакеты обязательны к установке, так как используются скриптом мониторинга
DEBIAN_DEPS="wget libstdc++5 parted smartmontools liblwp-useragent-determined-perl libnet-https-any-perl libcrypt-ssleay-perl libjson-perl"
CENTOS_DEPS="wget libstdc++ parted smartmontools perl-Crypt-SSLeay perl-libwww-perl perl-JSON"
# init.d script для smartd
SMARTD_INIT_DEBIAN=/etc/init.d/smartmontools
SMARTD_INIT_CENTOS=/etc/init.d/smartd
GITHUB_FASTVPS_URL="https://raw.github.com/FastVPSEestiOu/storage-system-monitoring"
# Diag utilities repo
DIAG_UTILITIES_REPO="https://raw.github.com/FastVPSEestiOu/storage-system-monitoring/master/raid_monitoring_tools"
MONITORING_SCRIPT_NAME="storage_system_fastvps_monitoring.pl"
# Monitoring script URL
MONITORING_SCRIPT_URL="$GITHUB_FASTVPS_URL/master/$MONITORING_SCRIPT_NAME"
# Monitoring CRON file
CRON_FILE=/etc/cron.d/storage-system-monitoring-fastvps
# Installation path
INSTALL_TO=/usr/local/bin
# smartd config command to run repiodic tests (short/long)
SMARTD_COMMAND="# smartd.conf by FastVPS
\n# backup version of distrib file saved to /etc/smartd.conf.dist
\n
\n# Discover disks and run short tests every day at 02:00 and long tests every sunday at 03:00
\nDEVICESCAN -d removable -n standby -s (S/../.././02|L/../../7/03)"
ARCH=
DISTRIB=
#
# Functions
#
check_n_install_debian_deps()
{
echo "Installing Debian dependencies: $DEBIAN_DEPS ..."
apt-get update
res=`apt-get install -y $DEBIAN_DEPS`
if [ $? -ne 0 ]
then
echo "Something went wrong while installing dependencies. APT log:"
echo $res
fi
echo "Finished installation of debian dependencies."
}
check_n_install_centos_deps()
{
echo "Installing CentOS dependencies: $CENTOS_DEPS ..."
res=`yum install -y $CENTOS_DEPS`
if [ $? -ne 0 ]
then
echo "Something went wrong while installing dependencies. YUM log:"
echo $res
fi
echo "Finished installation of CentOS dependencies."
}
# Проверяем наличие аппаратный RAID контроллеров и в случае наличия устанавливаем ПО для их мониторинга
check_n_install_diag_tools()
{
# utilities have suffix of ARCH, i.e. arcconf32 or megacli64
ADAPTEC_UTILITY=arcconf
LSI_UTILITY=megacli
lsi_raid=0
adaptec_raid=0
# флаг -m не используется, так как он не поддерживается в версии parted на CentOS 5
parted_diag=`parted -ls`
echo "Checking hardware for LSI or Adaptec RAID controllers..."
if [ -n "`echo $parted_diag | grep -i adaptec`" ]
then
echo "Found Adaptec raid"
adaptec_raid=1
fi
if [ -n "`echo $parted_diag | egrep -i 'lsi|perc'`" ]
then
echo "Found LSI raid"
lsi_raid=1
fi
if [ $adaptec_raid -eq 0 -a $lsi_raid -eq 0 ]
then
echo "Hardware raid not found"
return
fi
echo ""
if [ $adaptec_raid -eq 1 ]
then
echo "Installing diag utilities for Adaptec raid..."
wget --no-check-certificate "$DIAG_UTILITIES_REPO/arcconf$ARCH" -O"$INSTALL_TO/$ADAPTEC_UTILITY"
chmod +x "$INSTALL_TO/$ADAPTEC_UTILITY"
echo "Finished installation of diag utilities for Apactec raid"
fi
echo ""
if [ $lsi_raid -eq 1 ]
then
echo "Installing diag utilities for LSI MegaRaid..."
# Dependencies installation
case $DISTRIB in
debian)
wget --no-check-certificate "$DIAG_UTILITIES_REPO/megacli.deb" -O/tmp/megacli.deb
dpkg -i /tmp/megacli.deb
rm -f /tmp/megacli.deb
;;
centos)
yum install -y "$DIAG_UTILITIES_REPO/megacli.rpm"
;;
*)
echo "Can't install LSI tools for you distributive"
exit 1
;;
esac
echo "Finished installation of diag utilities for LSI raid"
fi
}
install_monitoring_script()
{
# Remove old monitoring run script
OLD_SCRIPT_RUNNER="/etc/cron.hourly/storage-system-monitoring-fastvps"
if [ -e "$OLD_SCRIPT_RUNNER" ] ; then
rm -f "$OLD_SCRIPT_RUNNER"
fi
echo "Installing monitoring.pl into $INSTALL_TO..."
wget --no-check-certificate $MONITORING_SCRIPT_URL -O"$INSTALL_TO/$MONITORING_SCRIPT_NAME"
chmod +x "$INSTALL_TO/$MONITORING_SCRIPT_NAME"
echo "Installing CRON task to $CRON_FILE"
echo "# FastVPS disk monitoring tool" > $CRON_FILE
echo "# https://github.com/FastVPSEestiOu/storage-system-monitoring" >> $CRON_FILE
# We should randomize run time for prevent ddos attacks to our gates
CRON_START_TIME=$RANDOM
# Limit random numbers by 59 minutes
let "CRON_START_TIME %= 59"
echo "We tune cron task to run on $CRON_START_TIME minutes of every hour"
echo "$CRON_START_TIME * * * * root perl $INSTALL_TO/$MONITORING_SCRIPT_NAME --cron" >> $CRON_FILE
chmod 644 $CRON_FILE
}
start_smartd_tests()
{
echo -n "Creating config for smartd... "
# Backup /etc/smartd.conf
if [ ! -e /etc/smartd.conf.dist ]
then
mv /etc/smartd.conf /etc/smartd.conf.dist
fi
echo -e $SMARTD_COMMAND > /etc/smartd.conf
echo "done."
# restart service
case $DISTRIB in
debian)
$SMARTD_INIT_DEBIAN restart
;;
centos)
$SMARTD_INIT_CENTOS restart
;;
esac
if [ $? -ne 0 ]
then
echo "smartd failed to start. This may be caused by absence of disks SMART able to monitor."
tail /var/log/daemon.log
fi
}
#
# Start installation procedure
#
if [ -n "`echo \`uname -a\` | grep -e \"-686\|i686\"`" ]
then
ARCH=32
fi
if [ -n "`echo \`uname -a\` | grep -e \"amd64\|x86_64\"`" ]
then
ARCH=64
fi
if [ -n "`cat /etc/issue | grep -i \"Debian\"`" ]
then
DISTRIB=debian
fi
if [ -n "`cat /etc/issue | grep -i \"CentOS\"`" ]
then
DISTRIB=centos
fi
if [ -n "`cat /etc/issue | grep -i \"Parallels\"`" ]
then
DISTRIB=centos
fi
# detect Ubuntu as Debian
if [ -n "`cat /etc/issue | grep -i \"Ubuntu\"`" ]
then
DISTRIB=debian
fi
# detect Citrix XenServer as CentOS
if [ -n "`cat /etc/issue | grep -i \"Citrix XenServer\"`" ]
then
DISTRIB=centos
fi
echo "We working on $DISTRIB $ARCH"
# Dependencies installation
case $DISTRIB in
debian)
check_n_install_debian_deps
;;
centos)
check_n_install_centos_deps
;;
*)
echo "Can't determine OS. Exiting..."
exit 1
;;
esac
# Diagnostic tools installation
check_n_install_diag_tools
# Monitoring script installation
install_monitoring_script
# Periodic smartd tests
start_smartd_tests
echo "Send data to FastVPS..."
$INSTALL_TO/$MONITORING_SCRIPT_NAME --cron
if [ $? -ne 0 ]
then
echo "Can't run script in --cron mode"
else
echo "Data sent successfully"
fi
echo "Checking disk system..."
$INSTALL_TO/$MONITORING_SCRIPT_NAME --detect