소스 검색

add nodered to iot, update mosquitto. monit now also usable with iot.

Thomas Buck 3 년 전
부모
커밋
4ffc24a063

+ 19
- 0
roles/iot/DESIGN.md 파일 보기

@@ -0,0 +1,19 @@
1
+# Design Description for IoT Role
2
+
3
+This role works differently compared to the others.
4
+It installs the basics for a home automation setup:
5
+
6
+ * InfluxDB time series database
7
+ * Grafana visualizations
8
+ * Mosquitto MQTT broker
9
+ * Node-Red scripting language
10
+
11
+It does not work with subdomains, everything runs under one domain.
12
+The top level routes to grafana.
13
+Going to the /nodered subdirectory leads to Node-Red.
14
+Going to /mqtt gets an MQTT-Admin UI.
15
+
16
+The ports for MQTT (with and without ssl, 1883 and 8883 respectively), as well as for MQTT SSL WebSockets (8083) will be opened in the firewall.
17
+
18
+This should be used together with the sslselfsigned role!
19
+When monitoring role is used as well, it can be accessed under /monit.

+ 1
- 0
roles/iot/tasks/main.yml 파일 보기

@@ -2,3 +2,4 @@
2 2
 - include: influx.yml tags=iot
3 3
 - include: mosquitto.yml tags=iot
4 4
 - include: mqtt_admin.yml tags=iot
5
+- include: nodered.yml tags=iot

+ 3
- 12
roles/iot/tasks/mosquitto.yml 파일 보기

@@ -1,16 +1,6 @@
1 1
 ---
2 2
 # Installs Mosquitto MQTT Broker
3 3
 
4
-- name: Ensure repository key for Mosquitto is in place
5
-  apt_key: url=https://repo.mosquitto.org/debian/mosquitto-repo.gpg.key state=present
6
-  tags:
7
-    - dependencies
8
-
9
-- name: Add Mosquitto repository
10
-  apt_repository: repo="deb https://repo.mosquitto.org/debian {{ ansible_distribution_release }} main"
11
-  tags:
12
-    - dependencies
13
-
14 4
 - name: Install Mosquitto from official repository
15 5
   apt:
16 6
     name: "{{ packages }}"
@@ -46,8 +36,9 @@
46 36
 - name: Set firewall rules for Mosquitto
47 37
   ufw: rule=allow port={{ item }} proto=tcp
48 38
   with_items:
49
-    - 8883  # mqtts (+ ssl)
50
-    - 8083  # mqtt websocket
39
+    - 1883 # mqtt (only enable in private networks!)
40
+    - 8883 # mqtts (+ ssl)
41
+    - 8083 # mqtt websocket
51 42
   tags: ufw
52 43
 
53 44
 - name: Register new Mosquitto service

+ 18
- 0
roles/iot/tasks/nodered.yml 파일 보기

@@ -0,0 +1,18 @@
1
+- name: Create temporary Node-Red directory
2
+  file: state=directory path=/root/nodered
3
+
4
+- name: Download Node-Red install script
5
+  get_url:
6
+    url="https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered"
7
+    dest=/root/nodered/update-nodejs-and-nodered
8
+    owner=root
9
+    mode=0755
10
+
11
+- name: Run Node-Red install script
12
+  shell: /root/nodered/update-nodejs-and-nodered --confirm-root --confirm-install --skip-pi --restart --update-nodes
13
+
14
+- name: Register new Node-Red service
15
+  systemd: name=nodered daemon_reload=yes enabled=yes
16
+
17
+- name: Start new Node-Red instance
18
+  service: name=nodered state=started

+ 8
- 0
roles/iot/templates/etc_apache2_sites-available_grafana.j2 파일 보기

@@ -8,6 +8,7 @@
8 8
 <VirtualHost *:443>
9 9
     ServerName {{ grafana_subdomain }}.{{ item.name }}
10 10
     ServerAlias {{ grafana_subdomain }}
11
+    ServerAlias {{ domain }}
11 12
 
12 13
     SSLEngine               On
13 14
     DocumentRoot            "{{ item.doc_root }}"
@@ -23,6 +24,13 @@
23 24
 
24 25
     ProxyRequests           Off
25 26
     ProxyPreserveHost       On
27
+
28
+    ProxyPass               /nodered/ http://localhost:1880/
29
+    ProxyPassReverse        /nodered/ http://localhost:1880/
30
+
31
+    ProxyPass               /monit/ http://localhost:2812/
32
+    ProxyPassReverse        /monit/ http://localhost:2812/
33
+
26 34
     ProxyPass               / http://localhost:{{ grafana_internal_port }}/
27 35
     ProxyPassReverse        / http://localhost:{{ grafana_internal_port }}/
28 36
 </VirtualHost>

+ 1
- 1
roles/iot/templates/etc_mosquitto_conf.d_20-default.j2 파일 보기

@@ -1 +1 @@
1
-listener 1883 localhost
1
+listener 1883

+ 2
- 0
roles/monitoring/defaults/main.yml 파일 보기

@@ -8,3 +8,5 @@ monit_alert_emails:
8 8
 
9 9
 monit_page_public: 1
10 10
 monit_subdomain: status
11
+
12
+default_http_redirect: true

+ 8
- 0
roles/monitoring/files/etc_monit_conf.d_mongodb 파일 보기

@@ -0,0 +1,8 @@
1
+check process mongodb matching "mongod"
2
+  group database
3
+  start program = "/bin/systemctl start mongod"
4
+  stop program = "/bin/systemctl stop mongod"
5
+  if failed port 27017 type tcp
6
+    with timeout 10 seconds
7
+    then restart
8
+  if 5 restarts within 5 cycles then timeout

+ 6
- 0
roles/monitoring/files/etc_monit_conf.d_pgsql_deb11 파일 보기

@@ -0,0 +1,6 @@
1
+check process postgres with pidfile /var/run/postgresql/13-main.pid
2
+  group database
3
+  start program = "/bin/systemctl start postgresql"
4
+  stop program = "/bin/systemctl stop postgresql"
5
+  if failed host localhost port 5432 protocol pgsql then restart
6
+  if 5 restarts within 5 cycles then timeout

+ 8
- 0
roles/monitoring/files/etc_monit_conf.d_rocketchat 파일 보기

@@ -0,0 +1,8 @@
1
+check process rocketchat matching "Rocket.Chat"
2
+  group social
3
+  start program = "/bin/systemctl start rocketchat"
4
+  stop program = "/bin/systemctl stop rocketchat"
5
+  if failed port 3042 protocol http
6
+    with timeout 10 seconds
7
+    then restart
8
+  if 5 restarts within 5 cycles then timeout

+ 5
- 0
roles/monitoring/tasks/logwatch.yml 파일 보기

@@ -12,9 +12,14 @@
12 12
 - name: Configure logwatch
13 13
   template: src=etc_logwatch_conf_logwatch.conf.j2 dest=/etc/logwatch/conf/logwatch.conf
14 14
 
15
+- name: Determine if rspamd is installed
16
+  stat: path=/etc/rspamd
17
+  register: rspamd_config_file
18
+
15 19
 - name: Configure rspamd to let logs through
16 20
   template: src=etc_rspamd_rspamd.conf.local.j2 dest=/etc/rspamd/rspamd.conf.local
17 21
   notify: restart rspamd
22
+  when: rspamd_config_file.stat.exists == True
18 23
 
19 24
 - name: Remove logwatch's dist cronjob
20 25
   file: state=absent path=/etc/cron.daily/00logwatch

+ 116
- 25
roles/monitoring/tasks/monit.yml 파일 보기

@@ -1,21 +1,42 @@
1 1
 - name: Add monitoring vhost to apache
2 2
   template: src=etc_apache2_sites-available_00-status.conf dest=/etc/apache2/sites-available/00-status.conf
3
+  notify: restart apache
4
+  when: default_http_redirect
3 5
 
4 6
 - name: Enable the status vhost
5 7
   command: a2ensite 00-status.conf creates=/etc/apache2/sites-enabled/00-status.conf
6 8
   notify: restart apache
9
+  when: default_http_redirect
10
+
11
+- name: add buster-backport for Monit
12
+  apt_repository: repo='deb http://deb.debian.org/debian buster-backports main' state=present update_cache=yes
13
+  tags:
14
+    - dependencies
15
+  when: ansible_distribution_version == '10'
7 16
 
8 17
 - name: Install monit
9 18
   apt:
10 19
     name: monit
11 20
     state: present
21
+    default_release: buster-backports
12 22
   tags:
13 23
     - dependencies
24
+  when: ansible_distribution_version == '10'
25
+
26
+- name: Install monit
27
+  apt:
28
+    name: monit
29
+    state: present
30
+  tags:
31
+    - dependencies
32
+  when: ansible_distribution_version != '10'
14 33
 
15 34
 - name: Copy monit master config file into place
16 35
   template: src=etc_monit_monitrc.j2 dest=/etc/monit/monitrc
17 36
   notify: restart monit
18 37
 
38
+# ---------------------------------------
39
+
19 40
 - name: Determine if ZNC is installed
20 41
   stat: path=/usr/lib/znc/configs/znc.conf
21 42
   register: znc_config_file
@@ -76,6 +97,52 @@
76 97
   stat: path=/etc/jitsi/jicofo/config
77 98
   register: jitsi_config_file
78 99
 
100
+- name: Determine if MongoDB is installed
101
+  stat: path=/etc/mongod.conf
102
+  register: mongodb_config_file
103
+
104
+- name: Determine if Rocket.Chat is installed
105
+  stat: path=/usr/local/bin/Rocket.Chat/main.js
106
+  register: rocketchat_config_file
107
+
108
+- name: Determine if Apache2 is installed
109
+  stat: path=/etc/apache2/apache2.conf
110
+  register: apache2_config_file
111
+
112
+- name: Determine if Dovecot is installed
113
+  stat: path=/etc/dovecot/dovecot.conf
114
+  register: dovecot_config_file
115
+
116
+- name: Determine if Postfix is installed
117
+  stat: path=/etc/postfix/main.cf
118
+  register: postfix_config_file
119
+
120
+- name: Determine if sshd is installed
121
+  stat: path=/etc/ssh/sshd_config
122
+  register: sshd_config_file
123
+
124
+- name: Determine if pgsql_deb9 is installed
125
+  stat: path=/etc/postgresql/9.6/main/pg_ctl.conf
126
+  register: pgsql9_config_file
127
+
128
+- name: Determine if pgsql_deb10 is installed
129
+  stat: path=/etc/postgresql/11/main/pg_ctl.conf
130
+  register: pgsql10_config_file
131
+
132
+- name: Determine if pgsql_deb11 is installed
133
+  stat: path=/etc/postgresql/13/main/pg_ctl.conf
134
+  register: pgsql11_config_file
135
+
136
+- name: Determine if tomcat_deb9 is installed
137
+  stat: path=/etc/tomcat8/server.xml
138
+  register: tomcat9_config_file
139
+
140
+- name: Determine if tomcat_deb10 is installed
141
+  stat: path=/etc/tomcat9/server.xml
142
+  register: tomcat10_config_file
143
+
144
+# ---------------------------------------
145
+
79 146
 - name: Copy ZNC monit service config files into place
80 147
   copy: src=etc_monit_conf.d_znc dest=/etc/monit/conf.d/znc
81 148
   notify: restart monit
@@ -156,38 +223,62 @@
156 223
   notify: restart monit
157 224
   when: openvpn_config_file.stat.exists == True
158 225
 
159
-- name: Copy monit service config files into place
160
-  copy: src=etc_monit_conf.d_{{ item }} dest=/etc/monit/conf.d/{{ item }}
161
-  with_items:
162
-    - apache2
163
-    - dovecot
164
-    - postfix
165
-    - sshd
226
+- name: Copy MongoDB monit service config files into place
227
+  copy: src=etc_monit_conf.d_mongodb dest=/etc/monit/conf.d/mongodb
166 228
   notify: restart monit
229
+  when: mongodb_config_file.stat.exists == True
167 230
 
168
-- name: Copy monit service config files into place
169
-  copy: src=etc_monit_conf.d_{{ item }} dest=/etc/monit/conf.d/{{ item }}
170
-  with_items:
171
-    - pgsql_deb9
172
-    - tomcat_deb9
231
+- name: Copy Rocket.Chat monit service config files into place
232
+  copy: src=etc_monit_conf.d_rocketchat dest=/etc/monit/conf.d/rocketchat
173 233
   notify: restart monit
174
-  when: ansible_distribution_version == '9'
234
+  when: rocketchat_config_file.stat.exists == True
175 235
 
176
-- name: Copy monit service config files into place
177
-  copy: src=etc_monit_conf.d_{{ item }} dest=/etc/monit/conf.d/{{ item }}
178
-  with_items:
179
-    - pgsql_deb10
180
-    - tomcat_deb10
236
+- name: Copy apache2 monit service config files into place
237
+  copy: src=etc_monit_conf.d_apache2 dest=/etc/monit/conf.d/apache2
181 238
   notify: restart monit
182
-  when: ansible_distribution_version == '10'
239
+  when: apache2_config_file.stat.exists == True
183 240
 
184
-- name: Copy monit service config files into place
185
-  copy: src=etc_monit_conf.d_{{ item }} dest=/etc/monit/conf.d/{{ item }}
186
-  with_items:
187
-    - pgsql_deb10
188
-    - tomcat_deb10
241
+- name: Copy dovecot monit service config files into place
242
+  copy: src=etc_monit_conf.d_dovecot dest=/etc/monit/conf.d/dovecot
189 243
   notify: restart monit
190
-  when: ansible_distribution_version == '11'
244
+  when: dovecot_config_file.stat.exists == True
245
+
246
+- name: Copy postfix monit service config files into place
247
+  copy: src=etc_monit_conf.d_postfix dest=/etc/monit/conf.d/postfix
248
+  notify: restart monit
249
+  when: postfix_config_file.stat.exists == True
250
+
251
+- name: Copy sshd monit service config files into place
252
+  copy: src=etc_monit_conf.d_sshd dest=/etc/monit/conf.d/ssh
253
+  notify: restart monit
254
+  when: sshd_config_file.stat.exists == True
255
+
256
+- name: Copy pgsql deb9 monit service config files into place
257
+  copy: src=etc_monit_conf.d_pgsql_deb9 dest=/etc/monit/conf.d/pgsql_deb9
258
+  notify: restart monit
259
+  when: pgsql9_config_file.stat.exists == True
260
+
261
+- name: Copy tomcat deb9 monit service config files into place
262
+  copy: src=etc_monit_conf.d_tomcat_deb9 dest=/etc/monit/conf.d/tomcat_deb9
263
+  notify: restart monit
264
+  when: tomcat9_config_file.stat.exists == True
265
+
266
+- name: Copy pgsql deb10 monit service config files into place
267
+  copy: src=etc_monit_conf.d_pgsql_deb10 dest=/etc/monit/conf.d/pgsql_deb10
268
+  notify: restart monit
269
+  when: pgsql10_config_file.stat.exists == True
270
+
271
+- name: Copy tomcat deb10 monit service config files into place
272
+  copy: src=etc_monit_conf.d_tomcat_deb10 dest=/etc/monit/conf.d/tomcat_deb10
273
+  notify: restart monit
274
+  when: tomcat10_config_file.stat.exists == True
275
+
276
+- name: Copy pgsql deb11 monit service config files into place
277
+  copy: src=etc_monit_conf.d_pgsql_deb11 dest=/etc/monit/conf.d/pgsql_deb11
278
+  notify: restart monit
279
+  when: pgsql11_config_file.stat.exists == True
280
+
281
+# ---------------------------------------
191 282
 
192 283
 # TODO add to fail2ban when monit_page_public == 1
193 284
 

Loading…
취소
저장