Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions assets/site/scss/_main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
text-transform: uppercase;
}

.language-switcher {
font-family: sans-serif;
margin-bottom: 1.5rem;
}

.gravatar {
margin: 0.3em 1.2em 1em 0;
border-radius: 0.3rem;
Expand Down
21 changes: 20 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
baseURL: https://albertogrespan.com
disablePathToLower: true
languageCode: en-us
defaultContentLanguage: en
defaultContentLanguageInSubdir: false

languages:
en:
locale: en-US
label: English
weight: 1
title: Blog
es:
locale: es
label: Español
weight: 2
title: Blog

title: Blog

author:
Expand All @@ -23,6 +37,11 @@ params:
url: https://github.com/albertogg
handle: albertogg

markup:
goldmark:
renderer:
unsafe: true

# Taxonomies activation default.
taxonomies:
tag: "tags"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
---
date: 2021-08-31T22:52:50-04:00
title: "Instalar UniFi Network Controller en una Raspberry Pi"
slug: "/instalar-unifi-network-controller-en-una-raspberry-pi/"
description: |-
Configuración de UniFi Network Controller en una Raspberry Pi con Raspberry Pi
OS. Configuración opcional de nginx usando certificados generados con mkcert.
translationKey: unifi-network-controller-raspberrypi
categories:
- Raspberry Pi
tags:
- UniFi
- OpenJDK
- nginx
- mkcert
toc: true
---

Instrucciones simples y directas para instalar UniFi Network Controller en una
Raspberry Pi. Solo lo he probado en Raspberry Pi OS, pero también debería
funcionar en Ubuntu.

No voy a mostrar cómo instalar Raspberry Pi OS. Asumo que para este punto ya
tienes una instalación nueva del sistema operativo. Consulta el sitio oficial
para ver las [instrucciones de instalación][raspberry-pi-os] y cómo configurar
el [acceso remoto][remote-access] a la Raspberry Pi.

## Cambiar el hostname

Queremos asegurarnos de que la Raspberry Pi tenga el hostname correcto. En mi
caso tengo dnsmasq en mi red y accedo a los hosts por sus hostnames. Puedes leer
este post sobre [nombres de dominio para redes caseras][homenet-domain-name].

sudo hostnamectl set-hostname unifi-controller

## Instalar OpenJDK versión 8

Por ahora necesitaremos OpenJDK versión 8. Parece que la versión 11 también
funciona, pero no la he probado.

sudo apt install openjdk-8-jre

## Instalar UniFi Network Controller

Instala algunos requisitos adicionales de software.

sudo apt update && sudo apt install ca-certificates apt-transport-https

Agrega el [repositorio Debian para UniFi Network
Controller][install-unifi-via-apt].

echo 'deb https://www.ui.com/downloads/unifi/debian stable ubiquiti' | sudo tee /etc/apt/sources.list.d/100-ubnt-unifi.list

Instala el paquete.

sudo apt install unifi -y

En este punto el paquete `unifi` instaló todas sus dependencias y está listo
para usarse.

### Iniciar UniFi Network Controller

Ahora que todo está listo, necesitamos iniciar el servicio.

sudo service unifi start

Abre tu navegador y entra a `<dirección-IP-de-la-raspberry-pi>:8443`; verás
UniFi Network Controller.

## Pasos adicionales

Estos son pasos adicionales solo si quieres servir UniFi Network Controller
desde nginx. Los pasos adicionales incluyen:

- Un certificado SSL.
- nginx y su configuración.

**Nota:** los pasos adicionales solo funcionarán si tienes resolución DNS hacia
la dirección IP de la Raspberry Pi.

### Certificado con mkcert

Para el certificado usaremos mkcert. [mkcert][mkcert] es una herramienta simple
y sin configuración para crear certificados de desarrollo confiables localmente
con los nombres que quieras.

En este punto asumimos que tienes `dnsmasq` o resolución DNS local que te
permite resolver `unifi-controller.home.arpa` hacia la dirección IP de la
Raspberry Pi.

Genera el certificado.

mkcert "unifi-controller.home.arpa"

Con ese certificado listo, seguimos con la instalación de nginx.

### Instalar nginx

Ahora necesitamos nginx. Cualquier servidor reverse proxy funcionará.

sudo apt install nginx

### Configurar nginx

Para la configuración queremos tener redirects personalizados de HTTP a HTTPS,
algunos proxy headers y nuestros certificados personalizados.

Puedes copiar el certificado desde tu computadora local a la Raspberry Pi usando
SCP.

scp ~/unifi-controller.home.arpa* pi@unifi-controller.home.arpa:/home/pi/

Ahora la parte de configuración. Crea el siguiente código en
`/etc/nginx/sites-avaliable/unifi`


server {
listen 80;
server_name unifi-controller.home.arpa;

return 301 https://$server_name$request_uri;
}


server {
# SSL configuration
listen 443 ssl;

server_name unifi-controller.home.arpa;

ssl on;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_certificate /home/pi/unifi-controller.home.arpa.pem;
ssl_certificate_key /home/pi/unifi-controller.home.arpa-key.pem;

location / {
proxy_pass https://localhost:8443;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_buffering off;
}
}

Cuando lo tengas, enlázalo dentro de los sitios habilitados.

sudo ln -s /etc/nginx/sites-available/unifi /etc/nginx/sites-enabled/unifi

Reinicia nginx.

sudo systemctl restart nginx

Eso es todo. En este punto puedes abrir tu navegador y entrar a
`unifi-controller.local.arpa`; verás UniFi Network Controller.

[raspberry-pi-os]: https://www.raspberrypi.org/software/
[remote-access]: https://www.raspberrypi.org/documentation/computers/remote-access.html#remote-access
[homenet-domain-name]: https://www.ctrl.blog/entry/homenet-domain-name.html
[install-unifi-via-apt]: https://help.ui.com/hc/en-us/articles/220066768-UniFi-Network-How-to-Install-and-Update-via-APT-on-Debian-or-Ubuntu
[mkcert]: https://github.com/FiloSottile/mkcert
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ slug: "/unifi-network-controller-install-in-a-raspberry-pi/"
description: |-
Setting up the UniFi Network Controller in a Raspberry Pi running Raspberry Pi
OS. Optional nginx configuration using certificates generated with mkcert.
translationKey: unifi-network-controller-raspberrypi
categories:
- Raspberry Pi
tags:
Expand Down
16 changes: 16 additions & 0 deletions i18n/en.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
about:
other: "About"
resume:
other: "Resume"
rss:
other: "RSS"
tableOfContents:
other: "Table of Contents"
by:
other: "By"
readInEnglish:
other: "Read in English"
readInSpanish:
other: "Read in Spanish"
license:
other: "This work is licensed under a <a rel=\"license\" href=\"https://creativecommons.org/licenses/by-nc-sa/4.0/\">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>."
16 changes: 16 additions & 0 deletions i18n/es.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
about:
other: "Acerca de"
resume:
other: "CV"
rss:
other: "RSS"
tableOfContents:
other: "Tabla de contenidos"
by:
other: "Por"
readInEnglish:
other: "Leer en inglés"
readInSpanish:
other: "Leer en español"
license:
other: "Esta obra está bajo una licencia <a rel=\"license\" href=\"https://creativecommons.org/licenses/by-nc-sa/4.0/\">Creative Commons Atribución-NoComercial-CompartirIgual 4.0 Internacional</a>."
3 changes: 2 additions & 1 deletion layouts/_default/baseof.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang="{{ .Site.Language.Lang }}">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="x-ua-compatible" content="IE=edge,chrome=1">
Expand All @@ -13,6 +13,7 @@
<meta name="twitter:creator" content="@{{ .Site.Params.Connect.Twitter.Handle }}">
<meta name="twitter:image" content="{{ .Site.Params.Gravatar.Url }}?s=250">
<title>{{ .Page.Title }} &ndash; {{ .Site.Params.Author }}</title>
{{ partial "hreflang.html" . }}
<link href="https://fonts.googleapis.com/css?family=Merriweather:300,400,700,900" rel="stylesheet">
{{ $style := resources.Get "site/scss/style.scss" | css.Sass (dict "outputStyle" "compressed") }}
<link rel="stylesheet" type="text/css" href="{{ $style.Permalink }}">
Expand Down
2 changes: 1 addition & 1 deletion layouts/_default/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{{- range .Site.RegularPages -}}
{{- if eq .Type "blog" -}}
<li>
<span>{{ .Date.Format "January 2, 2006" }}</span> <a href="{{ .RelPermalink }}">{{ .Title }}</a>
<span>{{ partial "date.html" . }}</span> <a href="{{ .RelPermalink }}">{{ .Title }}</a>
</li>
{{- end -}}
{{- end -}}
Expand Down
7 changes: 4 additions & 3 deletions layouts/_default/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
<div id="post" class="post">
<h1>{{ .Title }}</h1>
<div class="date">
<p>&mdash; {{ .Date.Format "January 2, 2006" }}</p>
<p>&mdash; {{ partial "date.html" . }}</p>
</div> <!-- class date -->
{{ partial "language-switcher.html" . }}
{{ if .Params.toc }}
<aside>
<h4>Table of Contents</h4>
<h4>{{ i18n "tableOfContents" }}</h4>
{{ .TableOfContents }}
</aside>
<hr class="toc">
{{ end }}
{{ .Content }}
<div class="closing">
<div>
By <a href="{{ .Site.Params.Connect.Twitter.Url }}" class="twitter-follow-link">@{{ .Site.Params.Connect.Twitter.Handle }}</a>
{{ i18n "by" }} <a href="{{ .Site.Params.Connect.Twitter.Url }}" class="twitter-follow-link">@{{ .Site.Params.Connect.Twitter.Handle }}</a>
</div>
<a href="https://twitter.com/share?ref_src=twsrc%5Etfw" class="twitter-share-button" data-url="{{ .Permalink }}" data-text="{{ .Title }}" data-via="{{ .Site.Params.Connect.Twitter.Handle }}" data-show-count="false">Tweet</a><script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
</div> <!-- class closing -->
Expand Down
6 changes: 6 additions & 0 deletions layouts/partials/date.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{- if eq .Site.Language.Lang "es" -}}
{{- $months := dict "1" "enero" "2" "febrero" "3" "marzo" "4" "abril" "5" "mayo" "6" "junio" "7" "julio" "8" "agosto" "9" "septiembre" "10" "octubre" "11" "noviembre" "12" "diciembre" -}}
{{- printf "%d %s %d" .Date.Day (index $months (printf "%d" .Date.Month)) .Date.Year -}}
{{- else -}}
{{- .Date.Format "January 2, 2006" -}}
{{- end -}}
2 changes: 1 addition & 1 deletion layouts/partials/footer.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<footer id="footer">
<div class="container">
<p>This work is licensed under a <a rel="license" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.</p>
<p>{{ i18n "license" | safeHTML }}</p>
<p>2012 &#151; {{ now.Format "2006" }} albertogrespan.com</p>
</div> <!-- class containter -->
</footer> <!-- id footer -->
8 changes: 4 additions & 4 deletions layouts/partials/header.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<div class="header">
<header class="container">
<h1 class="name">
<a href="{{ .Site.BaseURL }}">{{ .Site.Params.Author }}</a>
<a href="{{ .Site.Home.RelPermalink }}">{{ .Site.Params.Author }}</a>
</h1> <!-- class name -->
<ul class="menu">
<li><a href="{{ .Site.BaseURL }}/about/">About</a></li>
<li><a href="{{ .Site.BaseURL }}/resume/">Resume</a></li>
<li><a href="{{ .Site.BaseURL }}/index.xml">RSS</a></li>
<li><a href="{{ "about/" | relURL }}">{{ i18n "about" }}</a></li>
<li><a href="{{ "resume/" | relURL }}">{{ i18n "resume" }}</a></li>
<li><a href="{{ "index.xml" | relLangURL }}">{{ i18n "rss" }}</a></li>
</ul> <!-- class menu -->
</header> <!-- class containter -->
</div> <!-- class header -->
12 changes: 12 additions & 0 deletions layouts/partials/hreflang.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- range .AllTranslations -}}
<link rel="alternate" hreflang="{{ .Language.Lang }}" href="{{ .Permalink }}">
{{- end -}}
{{- $default := . -}}
{{- if ne .Language.Lang hugo.Sites.Default.Language.Lang -}}
{{- range .Translations -}}
{{- if eq .Language.Lang hugo.Sites.Default.Language.Lang -}}
{{- $default = . -}}
{{- end -}}
{{- end -}}
{{- end -}}
<link rel="alternate" hreflang="x-default" href="{{ $default.Permalink }}">
8 changes: 8 additions & 0 deletions layouts/partials/language-switcher.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{- with .Translations -}}
<nav class="language-switcher" aria-label="Translations">
{{- range . -}}
{{- $key := cond (eq .Language.Lang "es") "readInSpanish" "readInEnglish" -}}
<a href="{{ .RelPermalink }}">{{ i18n $key }}</a>
{{- end -}}
</nav>
{{- end -}}