-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
executable file
·315 lines (241 loc) · 10.6 KB
/
Vagrantfile
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
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'yaml'
machines = YAML.load(File.read("machines.yaml"))
Vagrant.configure("2") do |config|
machines.each do |hostname, specs|
config.vm.define "#{hostname}" do |node|
node.vm.box = "#{specs['box']}"
node.vm.hostname = "#{hostname}"
node.vm.network "private_network", ip: "#{specs['ip']}"
if specs.has_key?('exposed_ports')
specs['exposed_ports'].each do |internal_port, external_port|
node.vm.network "forwarded_port", guest: internal_port, host: external_port
end # each
end # if
@hosts_entries = []
machines.each do |h, s|
@hosts_entries << "%s %s" % [s['ip'], h]
end # each machine
hosts = @hosts_entries.join("\n")
# provision hosts file
node.vm.provision "shell", inline: <<-SHELL
echo "hello from node #{hostname}"
echo "127.0.0.1 localhost" > /etc/hosts
echo "127.0.1.1 #{hostname}" >> /etc/hosts
echo "#{hosts}" >> /etc/hosts
if [[ -f /etc/selinux/config ]]
then
sed -i s/^SELINUX=.*$/SELINUX=permissive/ /etc/selinux/config
setenforce permissive
fi
SHELL
if specs.has_key?('type')
# provision servers based on type
case specs['type']
when 'zabbix-server'
case specs['zabbix_db']
when 'postgres'
node.vm.provision "shell", inline: <<-SHELL
echo "installing Zabbix-Server with PostgreSQL backend on #{hostname}"
apt-get update -y -qq
apt-get install -y postgresql-client postgresql -qq
sudo -u postgres psql -c "CREATE DATABASE zabbix;"
sudo -u postgres psql -c "CREATE USER zabbix WITH PASSWORD 'zabbix';"
sudo -u postgres psql -c "GRANT ALL ON DATABASE zabbix TO zabbix;"
echo "127.0.0.1:5432:zabbix:zabbix:zabbix" > ~/.pgpass
chmod 600 ~/.pgpass
if [[ ! -f /root/zabbix-release.deb ]]
then
wget --quiet https://repo.zabbix.com/zabbix/5.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.0-1+bionic_all.deb -O /root/zabbix-release.deb
dpkg -i /root/zabbix-release.deb
fi
apt-get update -y -qq
apt-get install -y zabbix-server-pgsql zabbix-frontend-php zabbix-agent libapache2-mod-php php-gd php-xml php-pgsql -qq
zcat /usr/share/doc/zabbix-server-pgsql*/create.sql.gz | psql -h 127.0.0.1 -U zabbix zabbix
echo "DBHost=127.0.0.1
DBName=zabbix
DBSchema=public
DBUser=zabbix
DBPassword=zabbix
DBPort=5432
" >> /etc/zabbix/zabbix_server.conf
echo 'post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = UTC' > /etc/php/7.2/apache2/conf.d/99-zabbix.ini
systemctl restart apache2
mv /var/www/html /var/www/html.old
ln -s /usr/share/zabbix /var/www/html
echo '<?php
// Zabbix GUI configuration file
global $DB;
$DB["TYPE"] = "POSTGRESQL";
$DB["SERVER"] = "127.0.0.1";
$DB["PORT"] = "0";
$DB["DATABASE"] = "zabbix";
$DB["USER"] = "zabbix";
$DB["PASSWORD"] = "zabbix";
// SCHEMA is relevant only for IBM_DB2 database
$DB["SCHEMA"] = "";
$ZBX_SERVER = "localhost";
$ZBX_SERVER_PORT = "10051";
$ZBX_SERVER_NAME = "Zabbix";
$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
' > /var/www/html/conf/zabbix.conf.php
systemctl start zabbix-server.service
SHELL
else
node.vm.provision "shell", inline: <<-SHELL
echo "installing Zabbix-Server with MySQL backend on #{hostname}"
apt-get update -y -qq
apt-get install -y mysql-client mysql-server -qq
mysql -e "CREATE DATABASE IF NOT EXISTS zabbix DEFAULT CHARACTER SET = UTF8 COLLATE = utf8_bin;"
mysql -e "CREATE USER IF NOT EXISTS zabbix@localhost IDENTIFIED WITH mysql_native_password BY 'zabbix';"
mysql -e "GRANT ALL ON zabbix.* TO zabbix@localhost;"
if [[ ! -f /root/zabbix-release.deb ]]
then
wget --quiet https://repo.zabbix.com/zabbix/5.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.0-1+bionic_all.deb -O /root/zabbix-release.deb
dpkg -i /root/zabbix-release.deb
fi
apt-get update -y -qq
apt-get install -y zabbix-server-mysql zabbix-frontend-php zabbix-agent libapache2-mod-php php-gd php-xml php-mysql -qq
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -h localhost -uzabbix -pzabbix zabbix --init-command="SET NAMES utf8 COLLATE utf8_bin;"
echo "DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBPort=3306
" >> /etc/zabbix/zabbix_server.conf
echo 'post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = UTC' > /etc/php/7.2/apache2/conf.d/99-zabbix.ini
systemctl restart apache2
mv /var/www/html /var/www/html.old
ln -s /usr/share/zabbix /var/www/html
echo '<?php
// Zabbix GUI configuration file
global $DB;
$DB["TYPE"] = "MYSQL";
$DB["SERVER"] = "localhost";
$DB["PORT"] = "0";
$DB["DATABASE"] = "zabbix";
$DB["USER"] = "zabbix";
$DB["PASSWORD"] = "zabbix";
// SCHEMA is relevant only for IBM_DB2 database
$DB["SCHEMA"] = "";
$ZBX_SERVER = "localhost";
$ZBX_SERVER_PORT = "10051";
$ZBX_SERVER_NAME = "Zabbix";
$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
' > /var/www/html/conf/zabbix.conf.php
systemctl restart zabbix-server.service
SHELL
end # case zabbix-db
when 'mysql-server'
node.vm.provision "shell", inline: <<-SHELL
echo "installing MySQL (flavour: #{specs['mysql_flavour']}, version: #{specs['mysql_version']}) on #{hostname}"
if [[ ! -f /root/zabbix-release.deb ]]
then
wget --quiet https://repo.zabbix.com/zabbix/5.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.0-1+bionic_all.deb -O /root/zabbix-release.deb
dpkg -i /root/zabbix-release.deb
fi
apt-get update -y -qq
apt-get install -y mysql-server zabbix-agent -qq
echo "Server=#{machines['zabbix']['ip']}
ServerActive=#{machines['zabbix']['ip']}
Hostname=#{hostname}
" >> /etc/zabbix/zabbix_agentd.conf
mysql -e "CREATE USER IF NOT EXISTS zbx_monitor@localhost IDENTIFIED WITH mysql_native_password BY 'monitor';"
mysql -e "GRANT USAGE,REPLICATION CLIENT,PROCESS,SHOW DATABASES,SHOW VIEW ON *.* TO zbx_monitor@localhost;"
mysql -e "CREATE DATABASE IF NOT EXISTS sbtest;"
mysql -e "CREATE USER IF NOT EXISTS sbtest@'%' IDENTIFIED WITH mysql_native_password BY '123456';"
mysql -e "GRANT ALL ON sbtest.* TO sbtest@'%';"
echo "[mysqld]
bind-address = 0.0.0.0
innodb-buffer-pool-size = 512M
innodb-buffer-pool-instances = 8
innodb-log-file-size = 512M
innodb-flush-method = O_DIRECT
innodb-flush-log-at-trx-commit = 1
log-bin
server-id = #{spec['ip'].gsub(/./, '')}
gtid-mode = ON
enforce-gtid-consistency = ON
sync-binlog = 1
query-cache-size = 0
query-cache-type = 0
" > /etc/mysql/mysql.conf.d/zzz-overrides.cnf
systemctl restart mysql.service
mkdir -p /var/lib/zabbix
chown zabbix:zabbix /var/lib/zabbix
echo "[client]
user = 'zbx_monitor'
password = 'monitor'" > /var/lib/zabbix/.my.cnf
chown zabbix:zabbix /var/lib/zabbix/.my.cnf
chmod 600 /var/lib/zabbix/.my.cnf
if [[ -f /vagrant/mysql/template_db_mysql.conf ]]
then
cp /vagrant/mysql/template_db_mysql.conf /etc/zabbix/zabbix_agentd.d/mysql.conf
fi
systemctl restart zabbix-agent.service
SHELL
when 'postgresql-server'
node.vm.provision "shell", inline: <<-SHELL
echo "installing PostgreSQL on #{hostname}"
if [[ ! -f /root/zabbix-release.deb ]]
then
wget --quiet https://repo.zabbix.com/zabbix/5.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.0-1+bionic_all.deb -O /root/zabbix-release.deb
dpkg -i /root/zabbix-release.deb
fi
apt-get update -y -qq
apt-get install -y postgresql zabbix-agent -qq
echo "Server=#{machines['zabbix']['ip']}
ServerActive=#{machines['zabbix']['ip']}
Hostname=#{hostname}
" >> /etc/zabbix/zabbix_agentd.conf
sudo -u postgres psql -c "CREATE USER zbx_monitor WITH PASSWORD 'monitor' INHERIT;"
sudo -u postgres psql -c "GRANT pg_monitor TO zbx_monitor;"
sudo -u postgres psql -c "CREATE USER sbtest WITH PASSWORD '123456' INHERIT;"
sudo -u postgres psql -c "CREATE DATABASE sbtest WITH OWNER = sbtest"
sudo -u postgres psql -c "GRANT ALL ON DATABASE sbtest TO sbtest;"
mkdir -p /var/lib/zabbix
chown zabbix:zabbix /var/lib/zabbix
echo "*:5432:*:zbx_monitor:monitor" > /var/lib/zabbix/.pgpass
chown zabbix:zabbix /var/lib/zabbix/.pgpass
chmod 600 /var/lib/zabbix/.pgpass
echo "host all zbx_monitor 127.0.0.1/32 trust
host all zbx_monitor 0.0.0.0/0 md5
host all zbx_monitor ::0/0 md5" >> /etc/postgresql/10/main/pg_hba.conf
echo "host sbtest sbtest 127.0.0.1/32 trust
host sbtest sbtest 0.0.0.0/0 md5" >> /etc/postgresql/10/main/pg_hba.conf
echo "listen_addresses = '*'
shared_buffers = 512MB
" >> /etc/postgresql/10/main/postgresql.conf
systemctl restart postgresql.service
if [[ -f /vagrant/postgresql/template_db_postgresql.conf ]]
then
cp /vagrant/postgresql/template_db_postgresql.conf /etc/zabbix/zabbix_agentd.d/postgresql.conf
cp -Rpv /vagrant/postgresql/postgresql /var/lib/zabbix
fi
systemctl restart zabbix-agent.service
SHELL
else
node.vm.provision "shell", inline: <<-SHELL
echo "installing #{hostname} as #{specs['type']}"
apt-get update -y -qq
apt-get install -y -qq mysql-client postgresql-client wget
if [[ ! -f /root/percona-release.deb ]]
then
wget --quiet https://repo.percona.com/apt/percona-release_latest.generic_all.deb -O /root/percona-release.deb
dpkg -i percona-release
fi
apt-get update -y -qq
apt-get install -y -qq sysbench
SHELL
end # case server-type
end # spec type defined
end # machine define
end # machine loop
end # Vagrant.configure