kknds Wiki

website·Indexed 29 days ago

https://wiki.kknds.com

A personal knowledge base and technical documentation site covering Linux server management, networking, and software development. Topics include OpenWrt installation, Docker, Python development, Gitea maintenance, Restic backups, disk partitioning, and SSH key configuration.

Tokens
12.6K
Snippets
96
Records
104
Agent score
50%

What's inside kknds Wiki

  1. Build multi-architecture Docker images

    Build images for both ARM and x86_64 architectures. This can be done manually using manifests or automatically using buildx.
    # Option 1: Manual build and manifest
    docker build --tag image-amd:tag --platform linux/amd64 .
    docker build --tag image-arm:tag --platform linux/arm64 .
    docker manifest create image:tag image-amd:tag image-arm:tag
    docker manifest push image:tag
    
    # Option 2: Using buildx
    docker buildx create --name=container --driver=docker-container
    docker buildx build --tag image:tag --platform linux/arm64,linux/amd64 --builder container --push .
  2. Check disk usage and free space

    Use df -h for a quick overview of free space. For a detailed interactive analysis of disk usage, use the ncdu utility.
    # Install ncdu (Arch)
    pacman -S ncdu
    
    # Run ncdu
    ncdu
    
    # Check free space
    df -h
  3. Manage Python virtual environments

    Python projects typically require a virtual environment to isolate dependencies. Use the following commands to create, activate, and deactivate environments.
    # Create a virtual environment
    python -m venv C:\path\to\new\virtual\environment
    
    # Activate the environment
    source <venv>/bin/activate
    
    # Deactivate the environment
    deactivate
  4. Generate self-signed SSL certificates with OpenSSL

    Generate a private key, a certificate signing request (CSR), and a self-signed certificate for HTTPS testing.
    # 1. Create 2048-bit RSA private key
    openssl genrsa -out server.key 2048
    
    # 2. Create self-signed request (CSR)
    openssl req -new -key server.key -out server.csr
    
    # 3. Create SSL certificate (valid for 365 days)
    openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
    
    # 4. Test the certificate
    openssl x509 -in server.crt -text -noout
    
    # Optional: Combine key and certificate into a PEM file
    cat server.crt server.key > server.pem
  5. Create a software RAID array with mdadm

    On Arch Linux, install mdadm via pacman. Ensure drives are partitioned as 'Linux RAID' and are unmounted. After creating the array, save the configuration to /etc/mdadm/mdadm.conf and update the initramfs to ensure the array is available at boot.
    # Install mdadm (Arch)
    pacman -S mdadm
    
    # Create RAID array
    mdadm --create --verbose --level=0 --metadata=1.2 --raid-devices=2 /dev/md/myRAIDarray /dev/sda1 /dev/sdb1
    
    # Verify status
    cat /proc/mdstat
    mdadm --detail --scan
    
    # Persist configuration
    sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
    sudo update-initramfs -u

    Parameter Details:

    • --level: RAID type (0=RAID0, 1=RAID1, 5=RAID5, 10=RAID10).
    • --metadata: Default 1.2; use 1.0 if booting an OS from the RAID.
    • --raid-devices: Number of partitions in the array.
  6. Configure SNMP monitoring with mini-snmpd

    Install mini_snmpd to collect network device information. Configure the service in /etc/config/mini_snmpd to define community strings, listening interfaces, and monitored disks/interfaces.
    opkg update
    opkg install mini_snmpd
    /etc/init.d/mini_snmpd start
    # /etc/config/mini_snmpd
    config mini_snmpd 'default'
    	option enabled 1
    	option community 'public'
    	option listen_interface ''
    	list disks '/overlay'
    	list disks '/tmp'
    	list interfaces 'lan'
    	list interfaces 'wan'
  7. Intercept DNS traffic (DNS Hijacking)

    Force all local network DNS traffic through the router by creating a port forward rule in LuCI: Network → Firewall → Port Forwards. Set the rule to intercept TCP/UDP port 53 from the lan source zone.
  8. Create and manage ZFS pools

    ZFS provides data corruption prevention and redundancy. Install zfs-dkms and zfsutils-linux (Debian requires the contrib library). Use wipefs to clean disks before creating a pool.
    # Clean disks
    wipefs -a /dev/sd1 /dev/sd2 /dev/sd3
    
    # Create RAIDZ1 pool (RAID 5 equivalent, min 3 disks)
    zpool create -f -o ashift=12 mypool raidz1 /dev/sd1 /dev/sd2 /dev/sd3
    
    # Enable LZ4 compression
    zfs set compression=lz4 mypool
    
    # Check pool status
    zpool status

    ZFS Pool Types:

    • stripe: RAID 0
    • mirror: RAID 1
    • raidz1: RAID 5 (1 drive parity)
    • raidz2: RAID 6 (2 drive parity)
    • raidz3: 3 drive parity

    Key Flags:

    • -f: Forces use of vdevs.
    • -o ashift=12: Sets smallest chunk size to 4096 bytes.
  9. Configure Dynamic DNS (DDNS) with Cloudflare on OpenWRT

    To set up Dynamic DNS using Cloudflare, create a custom API token in your Cloudflare account with the following permissions: Zone -> Zone -> Read and Zone -> DNS -> Write.

    In the LuCI web interface, navigate to Services > DDNS, edit myddns_ipv4, and select cloudflare.com-v4 as the provider. Use the following configuration:

    • Enabled: true
    • Lookup Hostname: yourdomain.com (or sub.yourdomain.com)
    • Domain: yourdomain.com
    • Username: Bearer
    • Password: [Your Cloudflare API Token]
    • Use HTTP Secure: true
    • Path to CA Certificate: /etc/ssl/certs
    # Required packages for Cloudflare DDNS
    opkg update
    opkg install ddns-scripts ddns-scripts-cloudflare ddns-scripts-services luci-app-ddns
  10. Back up and restore Docker volumes manually

    Use a temporary Ubuntu container with the --volumes-from flag to archive volume contents to the host and extract them on a new host.
    # Backup: Archive volume to host
    docker run --rm --volumes-from container_name -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar /container_volume
    
    # Restore: Extract archive into new container volume
    docker run --rm --volumes-from new_container_name -v $(pwd):/backup ubuntu bash -c "cd /container_volume && tar xvf /backup/backup.tar --strip 1"
  11. Enable DNS Encryption (DNS-over-HTTPS)

    Encrypt DNS traffic by installing the dns-https-proxy and luci-app-dns-https-proxy packages. This allows the router to forward DNS traffic over HTTPS/TLS.
    opkg install dns-https-proxy luci-app-dns-https-proxy
  12. Run processes in the background and prevent SSH hang-ups

    In Bash, adding & to the end of a command runs it in the background. To prevent a process from terminating when an SSH session disconnects (SIGHUP), use nohup. It is recommended to redirect stdout and stderr to a log file and redirect stdin from /dev/null to ensure the process remains autonomous.
    # Basic background execution
    command &
    
    # Suspend active command (Ctrl+Z), then move to background
    bg
    
    # Bring background process to foreground
    fg
    
    # List active background jobs
    jobs
    
    # Run a script that persists after logout/disconnect
    nohup myscript.sh >myscript.log 2>&1 </dev/null &