Übersetzungen dieser Seite:
  • de

Ubuntu

Ansible

Proxmox

Hier einige Notizen beim Spielen mit Proxmox.

System warten

root:# apt-get update
root:# apt-get dist-upgrade

Ubuntu VM

Laufwerk hinzufügen

In Proxmox:

  • VM > Hardware > [Hinzufügen] > Laufwerk

Festplatte partitionieren

In der SSH-Shell der VM:

sudo su
lsblk
parted /dev/vdb "mklabel gpt"
parted /dev/vdb "mkpart primary ext4 1M -1"
mkfs -t ext4 /dev/vdb1

Ubuntu Container

Container per SSH erreichbar machen

Auf dem Proxmox Node:

root@pve:~# lxc-attach --name {CONTAINER-ID}

Auf dem Container:

Die SSH-Konfiguration bearbeiten:

/etc/ssh/sshd_config
PermitRootLogin yes

SSH Service neu starten:

root@...: ~# service ssh restart

Festplatte einbinden

Auf den Container:

  • Mountpoint anlegen
  • Herunter fahren
root@...: ~# mkdir /mnt/hdd
root@...: ~# shutdown -h now
  • Resource hinzufügen

In Proxmox, Container > Resourcen > [Hinzufügen |V] > Mount Point

Storage: Daten-Festplatte
Pfad: /mnt/hdd

LAMP Stack installieren

Auf dem Container:

root@...: ~# apt install lamp-server^
root@...: ~# apt install php-zip php-dompdf php-xml php-mbstring php-gd php-curl php-imagick php-intl unzip

Die PHP-Konfiguration bearbeiten:

root@...: ~# vim /etc/php/7.4/apache2/php.ini
/etc/php/7.4/apache2/php.ini
upload_max_filesize = 16G
post_max_size = 16G
date.timezone = Europe/Berlin

MySQL absichern:

root@...: ~# mysql_secure_installation

MySQL root login umstellen vom Plugin auth_socket auf ein anderes Plugin, wie zum Beispiel caching_sha2_password:

mysql> SELECT USER,authentication_string,plugin,host FROM mysql.user;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'MEINPASSWORD';
mysql> FLUSH PRIVILEGES;

oder plugin mysql_native_password nehmen …

NextCloud installieren

Datenbank und user installieren:

root@...: ~# mysql
CREATE DATABASE nextcloud;
CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY 'PASSWORD';
GRANT ALL ON nextcloud.* TO 'nextclouduser'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;
root@...: ~#

Nextcloud installieren:

root@...:~# cd /tmp && wget https://download.nextcloud.com/server/releases/latest.zip
root@...:/tmp# unzip latest.zip
root@...:/tmp# mv nextcloud /var/www/

Apache VHost Datei für Nextcloud hinzufügen:

/etc/apache/sites-available/nextcloud.conf
<VirtualHost *:80>
     ServerAdmin master@domain.com
     DocumentRoot /var/www/nextcloud/
     ServerName containername.local
     ServerAlias www.demo.domain.com
 
     Alias /nextcloud "/var/www/nextcloud/"
 
     <Directory /var/www/nextcloud/>
        Options +FollowSymlinks
        AllowOverride All
        Require all granted
          <IfModule mod_dav.c>
            Dav off
          </IfModule>
        SetEnv HOME /var/www/nextcloud
        SetEnv HTTP_HOME /var/www/nextcloud
     </Directory>
 
     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined
 
</VirtualHost>

Apache Module aktivieren:

root@...:~# apachectl configtest
root@...:~# a2ensite nextcloud.conf
root@...:~# a2enmod rewrite
root@...:~# a2enmod headers
root@...:~# a2enmod env
root@...:~# a2enmod dir
root@...:~# a2enmod mime
root@...:~# systemctl restart apache2.service
root@...:~# chown -R www-data:www-data /mnt/hdd
root@...:~# chown -R www-data:www-data /var/www/nextcloud/
root@...:~# chmod -R 755 /var/www/nextcloud/
root@...:~# apt-get install avahi-daemon

hosts-Datei anpassen:

/etc/hosts
127.0.0.1    containername.local

SSL-Zertifikat installieren

Certbot installieren

root@...:~# apt-get install python3-certbot-apache
root@...:~# certbot --apache -m DEINE@EMAIL.TLD -d DEIN_FQDN

Zertifikate automatisch erneuern

certbot fügt ein Erneuerungsskript in /etc/cron.d ein, das von einem systemctl-Dienst namens certbot.timer verwaltet wird.

Status prüfen:

$ sudo systemctl status certbot.timer

Probelauf zum Testen des Erneuerungsprozess:

$ sudo certbot renew --dry-run

Nextcloud über DynDNS anbinden

DuckDNS

Zuerst bei DuckDNS eine Sub-Domain registrieren

EIn Bash-Skript für DuckDNS installieren:

root@...:~# # Prüfe ob cron verfügbar. Wenn nein - installieren
root@...:~# ps -ef | grep cr[o]n
root@...:~# # Prüfe ob curl verfügbar. Wenn nein - installieren
root@...:~# curl
root@...:~# apt install curl
root@...:~# mkdir duckdns
root@...:~# cd duckdns/
~/duckdns/duck.sh
#!/bin/bash
echo url="https://www.duckdns.org/update?domains=nc-werner-home&token=01ea9911-3a11-4b33-b36b-ef348a736853&ip=" | curl -k -o ~/duckdns/duck.log -K -
root@...:~# chmod 700 duck.sh
root@...:~# crontab -e
*/5 * * * * ~/duckdns/duck.sh >/dev/null 2>&1
root@...:~# ./duck.sh

Hetzner DNS

Hetzner bietet eine DNS-Konsole an, bei der DNS-EInträge über eine REST-API aktualisiert werden können.

Auf GitBub bei FarrowStrange/hetzner-api-dyndns findet sich ein Skript, das dies tut.

Skript über github installieren:

# git checkout https://github.com/FarrowStrange/hetzner-api-dyndns.git
# cd hetzner-api-dyndns
# nano dyndns.sh

In der Zeile auth_api_token=${HETZNER_AUTH_API_TOKEN:-'<your-hetzner-dns-api-token>'} das API-Token der DNS-Console eintragen, speichern und beenden.

Die ID der gewünschten Zone und damit die Record ID des gewünschten DNS-Records in Erfahrung bringen:

$ curl -s -H "Auth-API-Token: DEIN_API_TOKEN" --location 'https://dns.hetzner.com/api/v1/zones'
$ curl -s -H "Auth-API-Token: DEIN_API_TOKEN" --location 'https://dns.hetzner.com/api/v1/records?zone_id=ID_DER_ZONE'

Schliesslich in die crontab eintragen:

*/5 *  *   *   *     ~/hetzner-api-dyndns/dyndns.sh  -z 'ID_DER_ZONE' -r 'ID_DES_RECORDS' -n 'KEY_DES_RECORDS' -t 0 -T 'A' > /dev/null 2>&1