-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstall_zabbix_mariadb_grafana.sh
674 lines (478 loc) · 15 KB
/
Install_zabbix_mariadb_grafana.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
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
#!/bin/bash
# Version: 1.0
# Date of create: 12/07/2017
# Create by: Kelvyn Ferreira
# Description: Script for installation Zabbix-Server, MariaDB and Grafna-Server (CentOS/RHEL/Fedora)
############# Chanding ##########
#
# Data of last change: 13/07/2017
# Changer by: Kelvyn Ferreira
# Variables
DIR_ROOT="/root"
HTTP_ZBX_FILE="/etc/httpd/conf.d/zabbix.conf"
HTTP_INDEX_ZBX="/var/www/html"
ZBX_SERVER_FILE="/etc/zabbix/zabbix_server.conf"
ZBX_AGENT_FILE="/etc/zabbix/zabbix_agentd.conf"
ZBX_CONF_PHP="/etc/zabbix/web/zabbix.conf.php"
SECURITY_FILE="/etc/sysconfig/selinux"
GRAFANA_CONF="/etc/grafana/grafana.ini"
FQDN=$( ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/' )
# Functions
update-system()
{
echo " "
echo "########## Update Operational System... ##########"
echo " "
# Update System
yum -t -y -e 0 update
echo " "
echo "########## Done! ##########"
echo " "
}
install_other_packets()
{
echo "########## Install Repo EPEL... ##########"
echo " "
# Install repo Epen
yum -t -y -e 0 install epel-release
# Clean libs repo
yum clean all
echo " "
echo "########## Done! ##########"
echo " "
echo "########## Install other packeges... ##########"
echo " "
# Install others packages necessary of system
yum -t -y -e 0 install vim net-tools nc htop glances wget yum-utils unzip net-snmp-utils ntp net-snmp telnet iotop traceroute bind-utils
echo " "
echo "########## Done! ##########"
echo " "
}
open_ports_firewalld()
{
echo "########## Releasing access to ports on the firewalld ##########"
echo " "
echo "########## Enable ports 80 and 443 ##########"
echo " "
# Enable access port http and https
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=443/tcp
echo " "
echo "########## Enable port 10051 ##########"
echo " "
# Enable access port Zabbix Server
firewall-cmd --permanent --add-port=10051/tcp
echo " "
echo "########## Enable port 3306 ##########"
echo " "
# Enable access port MariaDB
firewall-cmd --permanent --add-port=3306/tcp
echo " "
echo "########## Enable port 162 ##########"
echo " "
# Enable access port SNMP
firewall-cmd --permanent --add-port=162/tcp
echo " "
echo "########## Reload Service firewall-cmd... ##########"
echo " "
# Restart service firewalld
firewall-cmd --reload
echo " "
echo "########## Check ports enable in firewalld ##########"
echo " "
# Check ports enable
firewall-cmd --list-ports
echo " "
echo "########## Done! ##########"
echo " "
}
change_security_files()
{
echo "########## Alter Mode Operation Selinux... ##########"
echo " "
echo "########## Check Mode Selinux... ##########"
# Check status selinux
getenforce
echo " "
# Alter mode Selinux config
sed -i "s/SELINUX=enforcing/SELINUX=permissive/g" $SECURITY_FILE
echo "########## Alter Mode Selinux... ##########"
echo " "
# Alter status Selinux Enforcing > Permissive
setenforce 0
echo " "
echo "########## Done! ##########"
echo " "
}
install_apache()
{
echo " "
echo "######### Install Apache Server #########"
echo " "
# Install Apache and Apache Tools
yum -t -y -e 0 install httpd httpd-tools
echo " "
echo "######### Done! #########"
echo " "
}
install_sgbd()
{
echo "########## Install MariaDB (MySQL)... ##########"
echo " "
# Install MariaDB and MariaDB-Server
yum -t -y -e 0 install mariadb mariadb-server mytop
echo " "
echo "########## Done! ##########"
echo " "
echo "########## Starting Service MariaDB... ##########"
echo " "
# Starting Service MariaDB
systemctl start mariadb
# Enable Starting Automatic Service MariaDB
systemctl enable mariadb
echo " "
echo "########## Done! ##########"
echo " "
}
config_access_sgbd()
{
echo " "
echo "########## Configuration Access MariaDB... ##########"
echo " "
# Reciver password user root for access localhost
echo -n "Enter with password for user root local MySQL: "
read "_passwdrootmysqllocal"
# Reciver password user root for access external
echo -n "Enter with password for user root external MySQL: "
read "_passwdrootmysqlext"
# Reciver password user zabbix for access localhost
echo -n "Enter with password for user zabbix MySQL: "
read "_passwdzabbixmysql"
echo " "
echo "########### Seting new password for user Root and Zabbix in MySQL... ###########"
echo ""
echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '"$_passwdrootmysqllocal"';"
echo " "
# Seting new password root localhost
mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '"$_passwdrootmysqllocal"';"
# Flush privileges database
mysql --password=$_passwdrootmysqllocal -e "FLUSH PRIVILEGES;"
echo " "
echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '"$_passwdrootmysqlext"';"
echo " "
# Seting new password root external
mysql --password=$_passwdrootmysqllocal -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '"$_passwdrootmysqlext"';"
# Flush privileges database
mysql --password=$_passwdrootmysqllocal -e "FLUSH PRIVILEGES;"
echo "########## Create Database Zabbix... ##########"
echo " "
echo " "
echo "CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;"
echo " "
# Create Database Zabbix
mysql --password=$_passwdrootmysqllocal -e "CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;"
echo " "
echo "########## Check Databases... ##########"
echo " "
# Check Databases in MySQL
mysql --password=$_passwdrootmysqllocal -e "SHOW DATABASES;"
sleep 3
echo " "
echo "GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'localhost' IDENTIFIED BY '"$_passwdzabbixmysql"';"
echo " "
# Seting password zabbix user
mysql --password=$_passwdrootmysqllocal -e "GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'localhost' IDENTIFIED BY '"$_passwdzabbixmysql"';"
# Flush privileges database
mysql --password=$_passwdrootmysqllocal -e "FLUSH PRIVILEGES;"
echo "########## Create file "#DIR_ROOT"/.my.cnf ##########"
echo " "
# Create File .my.cnf
echo "[client]
host='localhost'
user='root'
password='"$_passwdrootmysqllocal"'" > $DIR_ROOT/.my.cnf
echo " "
echo "########## Password access for MySQL... ##########"
echo " "
echo "Access for MySQL - Zabbix Server"
echo " "
echo "Password for root localhost: "$_passwdrootmysqllocal""
echo " "
echo "Password for root external: "$_passwdrootmysqlext""
echo " "
echo "Password for zabbix localhost: "$_passwdzabbixmysql""
sleep 7
echo "########## Done! ##########"
echo " "
}
install_zabbix_server()
{
echo "########## Install Zabbix-Server... ##########"
echo " "
# Import Zabbix Repo
rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
echo " "
# Install MariaDB and MariaDB-Server
yum -t -y -e 0 install zabbix-server-mysql zabbix-web-mysql zabbix-java-gateway zabbix-get zabbix-agent zabbix-sender
echo " "
echo "########## Done! ##########"
echo " "
}
import_zabbix_sql()
{
echo "########## Create Database Struct for zabbix Database... ##########"
echo " "
# Create struct database zabbix
zcat -v /usr/share/doc/zabbix-server-mysql-*/create.sql.gz | mysql --password=$_passwdrootmysqllocal zabbix
echo " "
echo "########## Check Tables in zabbix Database... ########## "
echo " "
echo "USER zabbix and SHOW TABLES"
echo " "
# Check tables zabbix database
mysql --password=$_passwdrootmysqllocal -e "USE zabbix;SHOW TABLES;"
sleep 5
echo " "
echo "########## Done! ##########"
echo " "
}
config_zabbix_file()
{
echo "########## Seting TimeZone Zabbix-Server in "$HTTP_ZBX_FILE"... ##########"
echo " "
# Seting TimeZone Zabbix-Server
sed -i "s/# php_value date.timezone Europe\/Riga/php_value date.timezone America\/Sao_paulo/g" $HTTP_ZBX_FILE
echo " "
echo "########## Done! ##########"
echo " "
echo " "
echo "########## Seting parameters in Zabbix-Agent file "$ZBX_AGENT_FILE"... ##########"
echo " "
# Enable Remote Commands
sed -i "s/# EnableRemoteCommands=0/EnableRemoteCommands=1/g" $ZBX_AGENT_FILE
# Enable Logs Remote Commands
sed -i "s/# LogRemoteCommands=0/LogRemoteCommands=1/g" $ZBX_AGENT_FILE
# Seting hostname Zabbix
sed -i "s/Hostname=Zabbix server/# Hostname=Zabbix server/g" $ZBX_AGENT_FILE
# Seting hostname system
sed -i "s/# HostnameItem=system.hostname/HostnameItem=system.hostname/g" $ZBX_AGENT_FILE
echo " "
echo "########## Done! ##########"
echo " "
echo " "
echo "########## Seting parameters in Zabbix-Server file "$ZBX_SERVER_FILE"... ##########"
echo " "
# Seting password for zabbix user
sed -i "s/# DBPassword=/DBPassword="$_passwdzabbixmysql"/g" $ZBX_SERVER_FILE
echo " "
echo "########## Done! ##########"
echo " "
}
set_zabbix_name()
{
echo "########## Seting Name for Zabbix-Server... ##########"
echo " "
# Seting Name for Zabbix-Server
echo -n "Enter with name of Zabbix-Server: "
read "zbxservername"
echo "<?php
// Zabbix GUI configuration file.
global \$DB;
\$DB['TYPE'] = 'MYSQL';
\$DB['SERVER'] = '127.0.0.1';
\$DB['PORT'] = '0';
\$DB['DATABASE'] = 'zabbix';
\$DB['USER'] = 'zabbix';
\$DB['PASSWORD'] = '"$_passwdzabbixmysql"';
// Schema name. Used for IBM DB2 and PostgreSQL.
\$DB['SCHEMA'] = '';
\$ZBX_SERVER = 'localhost';
\$ZBX_SERVER_PORT = '10051';
\$ZBX_SERVER_NAME = '"$zbxservername"';
\$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;" > $ZBX_CONF_PHP
echo " "
echo "########## Done! ##########"
echo " "
echo " "
echo "########## Create file index.php for Zabbix redirect... ##########"
echo " "
echo "<?php header ( "Location: http://$FQDN/zabbix" );?> > $HTTP_INDEX_ZBX/index.php"
echo " "
# Create file index.php for redirect /zabbix
echo "<?php header ( \"Location: http://$FQDN/zabbix\" );?>" > $HTTP_INDEX_ZBX/index.php
echo "########## Warning in case of external publishing on the Zabbix server change the index.php file by adding the DNS instead of the IP !!! ##########"
echo " "
echo "########## The index.php file is located in "$HTTP_INDEX_ZBX"/index.php ##########"
echo " "
echo "########## Done! ##########"
echo " "
}
install_grafana_server()
{
echo "########## Install Grafana-Server... ##########"
echo " "
# Clean libs repo
yum clean all
# Packets necessarys
yum -t -y -e 0 install fontconfig urw-fonts freetype*
# Install grafana-server
yum -t -y -e 0 install https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-4.4.1-1.x86_64.rpm
echo " "
echo "########## Done! ##########"
echo " "
echo "########## Install Plugins Grafana-Server... ##########"
# Install plugins Grafana
grafana-cli plugins install alexanderzobnin-zabbix-app
grafana-cli plugins install grafana-clock-panel
grafana-cli plugins install grafana-piechart-panel
grafana-cli plugins install jdbranham-diagram-panel
grafana-cli plugins install vonage-status-panel
echo " "
echo "########## Enable port 3000 ##########"
echo " "
# Enable access port Grafana-Server
firewall-cmd --permanent --add-port=3000/tcp
echo " "
echo "########## Done! ##########"
echo " "
echo "########## Reload Service firewall-cmd... ##########"
echo " "
# Restart service firewalld
firewall-cmd --reload
echo " "
echo "########## Disable sign users in "$GRAFANA_CONF"... ##########"
echo " "
# Disable sign users Grafana-Server
sed -i "s/;allow_sign_up = true/allow_sign_up = false/g" $GRAFANA_CONF
echo " "
echo "########## Done! ##########"
echo " "
echo "########## Staring Grafana-Server... ##########"
echo " "
# Start service Grafana-Server
systemctl start grafana-server
# Enable starting boot Grafana-Server
systemctl enable grafana-server
echo " "
echo "########## Done! ##########"
echo " "
echo "######### Check Status of Grafana-Server... #########"
echo " "
# Check status service Grafana-Server
systemctl status grafana-server -ll
echo " "
echo "########## Done! ##########"
}
start_services()
{
echo "######### Start Apache Server... #########"
echo " "
# Start service Apache
systemctl start httpd
echo " "
echo "######### Configuration auto start service on apache... #########"
echo " "
# Enable start service Apache on boot
systemctl enable httpd
echo " "
echo "########## Done! ##########"
echo " "
echo "######### Check Status of Apache Server... #########"
# Check status service Apache
systemctl status httpd -ll
echo " "
echo "########## Done! ##########"
echo " "
echo "######### Start Zabbix Server... #########"
echo " "
# Start service Zabbix-Sever
systemctl start zabbix-server
echo " "
echo "######### Configuration auto start service on Zabbix-Server... #########"
echo " "
# Enable service Zabbix-Server on boot
systemctl enable zabbix-server
echo " "
echo "########## Done! ##########"
echo " "
echo "######### Check Status of Zabbix Server... #########"
echo " "
# Check status Zabbix-Server
systemctl status zabbix-server -ll
echo " "
echo "########## Done! ##########"
echo " "
echo "######### Start Zabbix Agent... #########"
echo " "
# Start service Zabbix-Agent
systemctl start zabbix-agent
echo " "
echo "######### Configuration auto start service on Zabbix-Agent... #########"
echo " "
# Enable service Zabbix-Agent on boot
systemctl enable zabbix-agent
echo " "
echo "######### Check Status of Zabbix Agent... #########"
echo " "
# Check status service Zabbix-Agent
systemctl status zabbix-agent -ll
echo " "
echo "########## Done! ##########"
echo " "
}
confirm()
{
# call with a prompt string or use a default
read -r -p "${1:-Do you want to install Grafana-Server? [y/N]} " response
case "$response" in
[yY][eE][sS]|[yY])
true
update-system
install_other_packets
open_ports_firewalld
change_security_files
install_apache
install_sgbd
config_access_sgbd
install_zabbix_server
import_zabbix_sql
config_zabbix_file
set_zabbix_name
install_grafana_server
start_services
echo ""
echo "Grafana-Server Installed with success !!!"
echo " "
echo "Acces Grafana-Server Web: http://$FQDN:3000/"
echo " "
echo "Zabbix Server Installed with success !!!"
echo " "
echo "Acces Zabbix-Server Web: http://$FQDN/zabbix"
;;
*)
update-system
install_other_packets
open_ports_firewalld
change_security_files
install_apache
install_sgbd
config_access_sgbd
install_zabbix_server
import_zabbix_sql
config_zabbix_file
set_zabbix_name
start_services
echo " "
echo "Zabbix Server Installed with success !!!"
echo " "
echo "Acces Zabbix-Server Web: http://$FQDN"
false
;;
esac
}
main()
{
confirm
}
# Call main
main