forked from bmfmancini/cacti-install-wizard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cacti-install-wizard-centos.sh
executable file
·574 lines (368 loc) · 14.5 KB
/
cacti-install-wizard-centos.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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
#!/bin/bash
##Author Sean Mancini
#www.seanmancini.com
#Version 2.0
##Purpose this script will facilitate the installation of Cacti along with all supporting binaries
#this script will also ensure that proper configurations are put in place to get up and running with cacti
##Dont forget to checkout cacti @ www.cacti.net
# This program is free software: you can redistribute it and/or modify#
# it under the terms of the GNU General Public License as published by#
# the Free Software Foundation, either version 3 of the License, or#
# (at your option) any later version.#
# This program is distributed in the hope that it will be useful,#
# but WITHOUT ANY WARRANTY; without even the implied warranty of#
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the#
# GNU General Public License for more details.#
# You should have received a copy of the GNU General Public License#
# along with this program. If not, see <https://www.gnu.org/licenses/>.#
if
[[ $(id -u) -ne 0 ]] ;
then echo "this script must be run as root" ;
sudo su ; fi
echo "this script requires git"
yum install -y git
function new_install () {
echo "This script will download all Cacti dependecies and download the chosen cacti version from the cacti github"
echo "Dont forget to support cacti @ cacti.net!"
echo "set selinux to disabled"
setenforce 0
sed -i 's/enforcing/disabled/g' /etc/selinux/config /etc/selinux/config
#Download chosen release
echo "here are some of the current cacti release versions"
git ls-remote --tags https://github.com/Cacti/cacti|grep 'release/[[:digit:]\.]*$'|tail -10|awk '{print $2}'|tr 'refs/tags/release' ' '|sed 's/^ *//;s/ *$//'
echo "which release would you like to download ? Hit enter for latest"
read version
if [ "$version" == "" ]
then
git clone -b 1.2.x https://github.com/Cacti/cacti.git
else
yum install -y wget unzip
wget https://github.com/Cacti/cacti/archive/release/$version.tar.gz
tar -xvf $version.tar.gz
mv cacti-release-$version cacti
fi
echo "will you be using the spine poller enter 1 for yes 2 for no"
read answer
if [ $answer == "1" ]
then
##Download packages needed for spine
yum install -y gcc mysql-devel net-snmp-devel autoconf automake libtool dos2unix help2man
echo "downloading and compling spine"
git clone https://github.com/Cacti/spine.git
cd spine
chmod +x bootstrap
./bootstrap
./configure
make
make install
chown root:root /usr/local/spine/bin/spine
chmod u+s /usr/local/spine/bin/spine
cd ..
else
echo "spine dependecies will not be installed"
fi
echo "On Centos systems we need to enable EPEL repos"
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
yum install yum-utils -y
yum-config-manager --enable remi-php72
echo "Downloading PHP modules needed for Cacti install"
yum install -y rrdtool mariadb-server net-snmp-utils net-snmp snmpd php php-mysql php-snmp php-xml php-mbstring php-json php-gd php-gmp php-zip php-ldap php-mc php-posix
###Start services
systemctl enable httpd
systemctl enable mariadb
systemctl start mariadb
systemctl start httpd
####Open Port 80 and 443 on firewalld
echo "Open http and https ports on firewalld"
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=443/tcp --permanent
firewall-cmd --reload
##Timezone settings needed for cacti
echo "Enter your PHP time zone i.e America/Toronto Default is US/Central "
read timezone
if [$timezone = ""]
then
echo "date.timezone =" US/Central >> /etc/php.ini
else
echo "date.timezone =" "$timezone" >> /etc/php.ini
fi
echo "Where would you like to install cacti default location is /var/www/html hit enter for default location"
read location
if [$location = ""]
then
location="/var/www/html"
mv cacti /var/www/html
else
mv cacti $location
fi
#Create cacti user and change permission of directory
echo "Which user would you like to run Cacti under (Default is apache) hit enter for default"
read user
if [$user = ""]
then
user="apache"
echo "cacti will be run under apache"
chown -R apache:apache $location/cacti
else
useradd $user
chown -R $user:$user $location/cacti
fi
#assign permissions for cacti installation
chown -R apache:apache $location/cacti/resource/snmp_queries/
chown -R apache:apache $location/cacti/resource/script_server/
chown -R apache:apache $location/cacti/resource/script_queries/
chown -R apache:apache $location/cacti/scripts/
chown -R apache:apache $location/cacti/cache/boost/
chown -R apache:apache $location/cacti/cache/mibcache/
chown -R apache:apache $location/cacti/cache/realtime/
chown -R apache:apache $location/cacti/cache/spikekill/
touch $location/cacti/log/cacti.log
chmod 664 $location/cacti/log/cacti.log
chown -R apache:apache $location/cacti/log/
cp $location/cacti/include/config.php.dist $location/cacti/include/config.php
chown -R apache:apache $location/cacti/include/config.php
###Make a backup of maria db config before making changes
cp /etc/my.cnf.d/server.cnf /etc/my.cnf.d/server.cnf.backup
echo "Applying recommended DB settings"
echo "
innodb_file_format = Barracuda
character_set_client = utf8mb4
max_allowed_packet = 16777777
join_buffer_size = 32M
innodb_file_per_table = ON
innodb_large_prefix = 1
innodb_buffer_pool_size = 250M
innodb_additional_mem_pool_size = 90M
innodb_flush_log_at_trx_commit = 2
innodb_doublewrite = OFF
" >> /etc/my.cnf.d/server.cnf
systemctl restart mariadb
##Create database
echo "would you like to customize the database name and user ? hit enter for defaults"
read customize
if [[ $customize = "" ]]
then
password="$(openssl rand -base64 32)"
mysql -uroot <<MYSQL_SCRIPT
CREATE DATABASE cacti DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
GRANT ALL PRIVILEGES ON cacti.* TO 'cacti'@'localhost' IDENTIFIED BY '$password'; ;
GRANT SELECT ON mysql.time_zone_name TO cacti@localhost;
USE mysql;
ALTER DATABASE cacti CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
FLUSH PRIVILEGES;
MYSQL_SCRIPT
#pre populate cacti db
mysql -u root cacti < $location/cacti/cacti.sql
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
sed -i -e 's@^$database_type.*@$database_type = "mysql";@g' /var/www/html/cacti/include/config.php
sed -i -e 's@^$database_default.*@$database_default = "cacti";@g' /var/www/html/cacti/include/config.php
sed -i -e 's@^$database_hostname.*@$database_hostname = "127.0.0.1";@g' /var/www/html/cacti/include/config.php
sed -i -e 's@^$database_username.*@$database_username = 'cacti';@g' /var/www/html/cacti/include/config.php
sed -i -e 's@^$database_password.*@$database_password = "'$password'";@g' /var/www/html/cacti/include/config.php
sed -i -e 's@^$database_port.*@$database_port = "3306";@g' /var/www/html/cacti/include/config.php
sed -i -e 's@^$database_ssl.*@$database_ssl = "false";@g' /var/www/html/cacti/include/config.php
sed -i -e 's@^//$url_path@$url_path@g' /var/www/html/cacti/include/config.php
###Cacti spine settomgs
cp /usr/local/spine/etc/spine.conf.dist /usr/local/spine/etc/spine.conf
sed -i -e 's@^DB_Host.*@DB_Host 127.0.0.1@g' /usr/local/spine/etc/spine.conf
sed -i -e 's@^DB_User.*@DB_User cacti@g' /usr/local/spine/etc/spine.conf
sed -i -e 's@^DB_Pass.*@DB_Pass cacti@g' /usr/local/spine/etc/spine.conf
echo "default database setup with following details"
echo "database name cacti\n
database username cacti\n
database password $password"
else
echo "enter db name"
read customdbname
echo "enter db user"
read customdbuser
echo "enter db password"
read customdbpassword
mysql -u root <<MYSQL_SCRIPT
CREATE DATABASE $customdbname;
GRANT ALL PRIVILEGES ON $customdbname.* TO '$customdbuser'@'localhost' IDENTIFIED BY '$customdbpassword';
GRANT SELECT ON mysql.time_zone_name TO $customdbuser@localhost;
ALTER DATABASE $customdbname CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
FLUSH PRIVILEGES;
MYSQL_SCRIPT
echo "Pre-populating cacti DB"
mysql -u root $customdbname < $location/cacti/cacti.sql
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
sed -i -e 's@^$database_type.*@$database_type = "mysql";@g' $location/cacti/include/config.php
sed -i -e 's@^$database_default.*@$database_default = '$customdbname'\;@g' $location/cacti/include/config.php
sed -i -e 's@^$database_hostname.*@$database_hostname = "127.0.0.1";@g' $location/cacti/include/config.php
sed -i -e 's@^$database_username.*@$database_username = '$customdbuser';@g' $location/cacti/include/config.php
sed -i -e 's@^$database_password.*@$database_password = '$customdbpassword';@g' $location/cacti/include/config.php
sed -i -e 's@^$database_port.*@$database_port = "3306";@g' "$location"/cacti/include/config.php
sed -i -e 's@^$database_ssl.*@$database_ssl = "false";@g' "$location"/cacti/include/config.php
sed -i -e 's@^//$url_path@$url_path@g' $location/cacti/include/config.php
cp /usr/local/spine/etc/spine.conf.dist /usr/local/spine/etc/spine.conf
sed -i -e 's@^DB_Host.*@DB_Host 127.0.0.1@g' /usr/local/spine/etc/spine.conf
sed -i -e 's@^DB_User.*@DB_User '$customdbuser'@g' /usr/local/spine/etc/spine.conf
sed -i -e 's@^DB_Pass.*@DB_Pass '$customdbpassword'@g' /usr/local/spine/etc/spine.conf
fi
###Adding recomended PHP settings
sed -e 's/max_execution_time = 30/max_execution_time = 60/' -i /etc/php.ini
sed -e 's/memory_limit = 128M/memory_limit = 400M/' -i /etc/php.ini
echo "Restarting Mariadb service"
systemctl restart mariadb
echo "this script can download the following plugins monitor,thold would you like to install them ? type yes to download hit enter to skip"
read plugins
if [[ $plugins = "yes" ]]
then
git clone https://github.com/Cacti/plugin_thold.git thold thold
git clone https://github.com/Cacti/plugin_monitor.git monitor
mv thold $location/cacti/plugins
mv monitor $location/cacti/plugins
else
echo "plugins will not be installed"
fi
echo "Would you like to download my RRD Monitoring script ? type yes to download hit enter to skip "
read mon_script
if [[ $mon_script == "yes" ]]
then
git clone https://github.com/bmfmancini/rrd-monitor.git
else
echo "Script will not be downloaded"
fi
touch /etc/cron.d/$user
echo "*/5 * * * * $user php $location/cacti/poller.php > /dev/null 2>&1" > /etc/cron.d/$user
echo "refreshing services"
systemctl restart httpd
systemctl restart mariadb
echo "The setup has completed you can now either install cacti via the CLI or access the websetup to continue install via CLI type yes"
read installanswer
if [[ $installanswer == "yes" ]]
then
php $location/cacti/cli/install_cacti.php --accept-eula --install -d
else
echo "please complete install on web console"
fi
}
function spine_install () {
##Download packages needed for spine
yum install -y gcc mysql-devel net-snmp-devel autoconf automake libtool dos2unix help2man
echo " Which version of spine would you like to use ? Hit enter for the latest or enter the release vesrion i.e 1.2.3 Usually should Match your installed version of Cacti"
read version
if [$version = ""]
then
echo "downloadinglatest version of spine and compling "
git clone https://github.com/Cacti/spine.git
cd spine
chmod +x bootstrap
./bootstrap
./configure
make
make install
chown root:root /usr/local/spine/bin/spine
chmod u+s /usr/local/spine/bin/spine
else
wget https://github.com/Cacti/spine/archive/release/$version.zip
unzip $version.zip
cd spine-release-$version
chmod +x bootstrap
./bootstrap
./configure
make
make install
chown root:root /usr/local/spine/bin/spine
chmod u+s /usr/local/spine/bin/spine
fi
cp /usr/local/spine/etc/spine.conf.dist /usr/local/spine/etc/spine.conf
echo "Spine has been compiled and installed you will now need to configure your DB credentials to /usr/local/spine/etc/spine.conf"
echo "Would you like to configure you spine.conf file? y or n"
read answer
if [ $answer == "y" ]
then
echo "Enter database user"
read user
echo "enter database password"
read password
echo "enter database name"
read databasename
sed -i -e 's@^DB_Host.*@DB_Host 127.0.0.1@g' /usr/local/spine/etc/spine.conf
sed -i -e 's@^DB_User.*@DB_User '$user'@g' /usr/local/spine/etc/spine.conf
sed -i -e 's@^DB_Pass.*@DB_Pass '$password'@g' /usr/local/spine/etc/spine.conf
sed -i -e 's@^DB_Database.*@DB_Database '$databasename'@g' /usr/local/spine/etc/spine.conf
else
echo "spine install completed"
fi
}
function cacti_upgrade () {
echo "Stopping cron service"
systemctl stop crond
echo "this option will upgrade you existing cacti installation
you will need to supply you db information and cacti installation path"
echo "specify your db username"
read currentdbuser
echo "specify your database name"
read currentdb
echo "specify your current db password"
read currentdbpwd
echo "specify your cacti install path usually /var/www/html hit enter to accept default"
read currentpath
if [ "$currentpath" == "" ]
then
currentpath="/var/www/html"
fi
echo "specify a backup path to backup cacti files default is /tmp"
read backpath
if [ "$backpath" == "" ]
then
backpath="/tmp"
fi
echo "backing up DB"
mysqldump -u $currentdbuser -p $currentdbpassword $currentdb > cacti_db_backup.sql
echo "which release would you like to upgrade to? Hit enter for latest"
read version
if [ "$version" == "" ]
then
git clone -b 1.2.x https://github.com/Cacti/cacti.git
else
wget https://github.com/Cacti/cacti/archive/release/$version.zip
unzip $version
mv cacti-release-$version cacti
fi
mv $currentpath/cacti $backpath
mv cacti $currentpath
echo "adding old config.php file into new cacti folder"
cp $backpath/cacti/include/config.php $currentpath/cacti/include/config.php
echo "Moving plugin files back into new cacti folder"
cp -R $backpath/cacti/plugins/* $currentpath/cacti/plugins/
echo "what system user do you run cacti as ? usually www-data"
read cactiuser
chown -R $cactiuser:$cactiuser $currentpath/cacti
echo "cacti has been upgraded to " $version
echo " a backup of your previous release has been made to" $backpath
echo "once you have confirmed everything is working remove the backup from" $backpath
systemctl start crond
echo "Would you like to update spine ? hit enter to skip"
read spineupdate
if [ "$spineupdate" == "yes" ]
then
spine_install
else
echo "upgrade complete"
fi
}
#####Menu
choice='Select a operation: '
options=("New-installation" "spine-only-installation" "cacti-upgrade" "Quit")
select opt in "${options[@]}"
do
case $opt in
"New-installation")
new_install
;;
"spine-only-installation")
spine_install
;;
"cacti-upgrade")
cacti_upgrade
;;
"Quit")
break
;;
*) echo invalid option;;
esac
done