admin

  • The unix tool yes provides one simple yet very useful functionality. It repeatedly  prints ‚yes‘ (or any other string) to the console.

    This can be used to automatically answer questions in scripted environments.

    Example:

    yes|sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm

     

  • Two simple things are easily achievable .

    1. Loading logs into a log file analyser https://matomo.org/
    2. Depersonalize

    An example setup on Ubuntu is shown below.

    Configure two daily running cronjobs

    0 1 * * * /scripts/import-logfiles.sh
    0 2 * * * /scripts/depersonalize-apache-logs.sh

    Use import-logfiles.sh to load all server requests into the matomo database. Use depersonalize-apache-logs.sh to anonymize all logs older than seven days. Depersonalization is achieved by replacing the last two bytes of IP-adresses with  0.

    Both scripts work on a default Ubuntu setup of apache2.  Apache  Logfiles are  compressed and end with ‚gz‘. They are placed in ‚/var/log/apache2‘ and start with the prefix ‚localhost-access.‘

  • Zwei Dinge, die gut umzusetzen sind:

    1. In ein Analysetool laden. z.B. https://matomo.org/
    2. Anonymisieren

    Hier ein Beispiel Setup auf einem Ubunturechner.

    Es werden zwei täglich laufende Cronjobs angelegt

    0 1 * * * /scripts/import-logfiles.sh
    0 2 * * * /scripts/depersonalize-apache-logs.sh

    Mit dem `import-logfiles.sh` Skript werden nun einmal täglich die Serverrequests vom letzten Tag in die Matomodatenbank geladen. Mit dem  `depersonalize-apache-logs.sh` werden alle Logfiles, die älter als sieben Tage sind bearbeitet. Dabei werden für alle IPs die letzten zwei Bytes auf 0 gesetzt.

    Beide Beispielskripte lassen sich auf Github finden. Beide Skripte gehen dabei davon aus, dass der Apache seine Logfiles rolliert und zu `gz` Dateien komprimiert, die unter `/var/log/apache2` liegen und immer mit dem String „other_vhosts_access.“ beginnen.

    import-logfiles.sh

    depersonalize-apache-logs.sh

  • This is how I backup MySQL databases.

    Solution consists of three files

    Find complete solution here

    The backup-db.sh is called every day with Parameter -b for backup and with parameter -c for cleanup. The backup routine dumps all MySQL databases into one file. The  cleanup routine removes old backups (older than 30 days, see LIMIT variable). The restore routine requires to hardcode a certain snapshot into the script. The variables.conf must be placed in same folder as backup-db.sh .

    This is how the backup folder looks after running the script for 32 days at 23h.

    20181009-023001.sql 20181020-023001.sql 20181031-023001.sql
    20181010-023001.sql 20181021-023001.sql 20181101-023001.sql
    20181011-023001.sql 20181022-023001.sql 20181102-023001.sql
    20181012-023001.sql 20181023-023001.sql 20181103-023001.sql
    20181013-023001.sql 20181024-023001.sql 20181104-023001.sql
    20181014-023001.sql 20181025-023001.sql 20181105-023001.sql
    20181015-023001.sql 20181026-023002.sql 20181106-023001.sql
    20181016-023001.sql 20181027-023001.sql 20181107-023001.sql
    20181017-023001.sql 20181028-023001.sql 20181108-023001.sql
    20181018-023001.sql 20181029-023002.sql
    20181019-023001.sql 20181030-023001.sql

    The folder will contain backups for the last 31 days.

     

  • Mit dem ufw-Kommando (Uncomplicated Firewall) steht auf Ubuntu eine sehr einfache Möglichkeit zur Verfügung, den iptables2 Paketfilter zu konfigurieren.

    Bevor man die Firewall aktiviert, sollte man zumindest den SSH Zugriff freigeben! und die Dienste, die nach außen notwendig sind, z.B.

    z.B

    sudo ufw allow http
    sudo ufw allow https
    sudo ufw allow ssh

    Nun kann man die neu gesetzten Regeln aktivieren

    sudo ufw enable
    sudo ufw status

    Der Server wird jjetzt nur noch Anfragen auf den Ports 80,443 und 22 beantworten. Das Verhalten lässt sich im Logfile beobachten unter

    sudo tail -f /var/log/ufw.log

    Du kannst auch weitere Ports freigeben

    ufw allow _any_port_number_

    Oder auch einzelne Ports für einzelne IPs

    ufw allow from 192.168.0.1 to any port 8080