Use ZIP and SCP to archive and copy files remotely

We have a folder that we want to archive into a .zip file and copy it to a linux server via scp (secure copy, which uses the ssh protocol).
Let’s add the files to a zip archive first, we can use the zip utility with the -r parameter to recursively add all files (*) in the current folder and subfolders:

$ zip docker-1.zip -r *
  adding: compose.yml (deflated 66%)
  adding: config.inc.php (deflated 63%)
  adding: docker-compose.yml-old (deflated 57%)
  adding: Dockerfile.mariadb (deflated 19%)
  adding: Dockerfile.nginx (deflated 18%)
  adding: Dockerfile.php (deflated 30%)
  adding: Dockerfile.phpmyadmin (deflated 24%)
  adding: Dockerfile.php-old (deflated 30%)
  adding: html/ (stored 0%)
  adding: html/index.php (stored 0%)
  adding: html/test.php (deflated 4%)
  adding: html/mariadb.php (deflated 50%)
  adding: html/404.html (stored 0%)
  adding: nginx.conf (deflated 48%)

We can then supply parameters to the scp command, to copy the resulting archive.
We use an alternate port via the -P parameter, and a ssh keypair with the -i parameter.

Docker containers - LAMP stack to host a site with SQL and PHP

Introduction
Example of a LAMP stack to host a website

Introduction

Docker is set of technogies that allows us to run applications. It uses images that are built according to docker-compose.yml. These images are deployed to containers, each including the software needed to run a web server, database, etc..

Dockerfile → (Build) → Image → (Run) → Container.

  • Dockerfile: contains a set of Docker instructions that installs and configures the software you specify.

Ansible - automating infrastructure and applications

Setting up VMs
Creating the git repository
Installing ansible with basic configuration and testing
Using YAML playbooks
Conditional statement when
Consolidating the playbook
Using groups and tags
Activating and enabling systemd services
Troubleshooting ansible commands and results

Setting up the virtual machines

Ansible does not need an agent installed on the target machines; it needs ssh acccess to the VMs.
For this tutorial, we will need a few VMs to test and ssh keys for a local user on the machines and for ansible acccess.
You can use VirtualBox for example, to create one VM and link clone it, so that you can save disk space. You should also use bridged adatper for networking and assign static IP addresses in your router’s network settings. This way, the router will assign the IPs to the VMs and they will also access the internet. I have created a VM, debian-1, IP 192.168.1.105, and created the same user and password from my main machine; this is to quickly ssh into the VM without entering additional credentials:

Create a new K8s deployment/cluster on MS Azure

First create the cluster in Azure Kubernetes, with the appropriate resource group and name. We will be using the commandline tool az from the Azure Cloudshell.

george [ ~/k8s ]$ az group create --location ukwest --resource-group myaksrg
{
  "id": "/subscriptions/629a8f44-c84d-459e-bc17-64c887c78ced/resourceGroups/myaksrg",
  "location": "ukwest",
  "managedBy": null,
  "name": "myaksrg",
  "properties": {
    "provisioningState": "Succeeded"
  },
  "tags": null,
  "type": "Microsoft.Resources/resourceGroups"
}

Create a new cluster with 1 node and ssh key for accessing it.

az aks create \
    --resource-group myaksrg \
    --name myakscluster \
    --node-count 1 \
    --generate-ssh-keys

Run the below from the cloudshell to access the cluster:

Troubleshoot - Debian system not suspending

The below is shown in the virtual console:

Jan 08 18:24:04 dom kernel: Freezing user space processes failed after 20.006 seconds (1 tasks refusing to freeze, wq_busy=0):

Searching the sytemd logs reveals more details, including the line fuse_simple_request which points to the FUSE layer.
Use journalctl -r to list the most recent log entries, and the / key followed by freeze to search for the relevant log entry.

Jan 08 18:24:24 dom kernel: Freezing user space processes failed after 20.006 seconds (1 tasks refusing to freeze, wq_busy=0):
Jan 08 18:24:24 dom kernel: Freezing user space processes
Jan 08 18:24:04 dom kernel: Filesystems sync: 0.012 seconds
Jan 08 18:24:04 dom kernel: PM: suspend entry (s2idle)
Jan 08 18:24:04 dom kernel: PM: suspend exit
[..]
Jan 08 18:24:04 dom kernel:  </TASK>
Jan 08 18:24:04 dom kernel: R13: 000056426d10c080 R14: 000056426c6d4100 R15: 000056426d10cc80
[..]
Jan 08 18:24:04 dom kernel: RIP: 0033:0x7fddceb1e52a
Jan 08 18:24:04 dom kernel:  entry_SYSCALL_64_after_hwframe+0x76/0x7e
[..]
Jan 08 18:24:04 dom kernel:  vfs_fstatat+0x80/0xb0
Jan 08 18:24:04 dom kernel:  vfs_statx+0xa3/0x100
Jan 08 18:24:04 dom kernel:  vfs_statx_path+0x9f/0xe0
-----------------------
Jan 08 18:24:04 dom kernel:  fuse_do_getattr+0xf1/0x2c0
Jan 08 18:24:04 dom kernel:  fuse_simple_request+0x17e/0x2c0
-----------------------
Jan 08 18:24:04 dom kernel:  ? __pfx_autoremove_wake_function+0x10/0x10
Jan 08 18:24:04 dom kernel:  request_wait_answer+0xd0/0x2a0
Jan 08 18:24:04 dom kernel:  schedule+0x27/0xf0
Jan 08 18:24:04 dom kernel:  __schedule+0x3ec/0xb00
Jan 08 18:24:04 dom kernel:  <TASK>
Jan 08 18:24:04 dom kernel: Call Trace:
Jan 08 18:24:04 dom kernel: task:df              state:D stack:0     pid:28146 tgid:28146 ppid:28145  flags:0x00004006
Jan 08 18:24:04 dom kernel: Freezing user space processes failed after 20.006 seconds (1 tasks refusing to freeze, wq_busy=0):

It is the file system in user space (FUSE) that uses the SSH File Transfer Protocol (SFTP) to mount a remote file system.
In the /etc/fstab there is a mountpoint wich uses sshfs to mount a remote filesystem.

Debian log rotation for apache web server

To enable log rotation on Debian, you can use the logrotate package, which is already installed. You should enable and start the systemd service with this command - sudo systemctl enable --now logrotate.timer. You can use systemctl status logrotate.timer to show the status of the logrotate.timer unit, which is now active.

● logrotate.timer - Daily rotation of log files
     Loaded: loaded (/lib/systemd/system/logrotate.timer; enabled; preset: enabled)
     Active: active (waiting) since Sun 2025-01-05 21:38:02 UTC; 11s ago
    Trigger: Mon 2025-01-06 00:00:00 UTC; 2h 21min left
   Triggers: ● logrotate.service
       Docs: man:logrotate(8)
             man:logrotate.conf(5)

Jan 05 21:38:02 ip-172-31-27-178 systemd[1]: Stopped logrotate.timer - Daily rotation of log files.
Jan 05 21:38:02 ip-172-31-27-178 systemd[1]: Stopping logrotate.timer - Daily rotation of log files...

With the command systemctl list-timers, you can list the enabled timers, which are equivalent to cron jobs.

Debian APT Update System

This article will show you how to update your Debian system with the APT package manager.
To update the list of Debian packages, use apt update.

george@dom:/media/george$ sudo apt update
[sudo] password for george:
Hit:1 http://deb.debian.org/debian sid InRelease
Hit:2 http://deb.playonlinux.com stretch InRelease
Hit:3 https://download.docker.com/linux/debian bookworm InRelease
Hit:4 https://packages.microsoft.com/repos/code stable InRelease
Hit:5 https://updates.signal.org/desktop/apt xenial InRelease
Hit:6 https://repo.steampowered.com/steam stable InRelease
Hit:7 https://dl.google.com/linux/chrome/deb stable InRelease
Get:8 https://apt.fury.io/wez * InRelease
Fetched 5,721 B in 7s (838 B/s)
884 packages can be upgraded. Run 'apt list --upgradable' to see them.

Use apt list to see which packages can be upgraded on your system.