Category: Linux

  • Mirroring a site with wget

    To mirror a web site for local viewing, you can use

    wget --mirror --convert-links --html-extension --wait=2 -o log http://www.domain.com
    

    –convert-links = After downloading, convert the links suitable for local viewing.

  • Atlassian JIRA Internal Server Error

    On on Jira Server, when accessing the site get following error

    JIRA — Internal Server Error
    Error reference: b64e4876-0fc1-439a-a46d-4a3255a48230

    Unable to render full error details at this time. Please consult the error logs for more information.

    The problem was disk full.

    root@jira /var/atlassian/application-data/jira # du -h –max-depth=1
    1.1M ./analytics-logs
    4.0G ./plugins
    293M ./log
    72K ./structure
    32M ./tmp
    11M ./caches
    632K ./logs
    52K ./tempo
    32G ./export
    368M ./data
    96K ./import
    352K ./monitor
    4.0K ./logos
    8.5M ./bt-templates
    37G .
    root@jira /var/atlassian/application-data/jira #

    The folder /var/atlassian/application-data/jira/export used 32 GB disk space. This folder store daily backups.

    I removed some of the older backups last last year, restarted the server, that fixed the problem.

    To avoid this happening again, set a cronjob

    vi /usr/serverok/clean.sh
    

    Add

    #!/bin/bash
    
    /bin/find /var/atlassian/application-data/jira/export/ -type f -mtime +60 -name "*.zip" -delete
    

    This will delete files older than 60 days.

    Set it to run daily with crontab -e

    @daily  /usr/serverok/clean.sh > /dev/null 2>&1
    
  • Enable Error Logging in php-fpm

    Edit your pool file

    vi /etc/php/7.0/fpm/pool.d/www.conf
    

    Add

    catch_workers_output = yes
    php_flag[display_errors] = on
    php_admin_value[error_log] = /var/log/fpm-php.www.log
    php_admin_flag[log_errors] = on
    

    if you only enable “log_errors”, then errors go to default nginx error log.

    php-fpm

  • Mount Windows Share in Linux

    On Ubuntu, install cifs-utils

    apt-get install cifs-utils
    

    First create a directory on which we can mount the windows share

    mkdir /media/SHARE_NAME
    

    Now create a file to store windows share username and password.

    vi /etc/SHARE_NAME.smbcredentials
    

    Add following to the file

    username=YOUR_WINDOWS_SHARE_USER
    password=YOUR_WINDOWS_SHARE_PASSWORD
    

    Now run

    mount -t cifs //192.168.0.4/SHARE_NAME /media/SHARE_NAME -o credentials=/etc/SHARE_NAME.smbcredentials,uid=LINUX_USER_NAME,iocharset=utf8,sec=ntlm,rw,dir_mode=0777,file_mode=0666
    

    192.168.0.4 – Replace with IP of your Windows computer with share.

    LINUX_USER_NAME – Replace with the Linux user name you want the files to be owned.

    To make share mounted on boot, edit

    vi /etc/fstab
    

    Add

    //192.168.0.4/SHARE_NAME  /media/SHARE_NAME  cifs  credentials=/etc/SHARE_NAME.smbcredentials,uid=LINUX_USER_NAME,gid=GID_OF_LINUX_USER,_netdev,iocharset=utf8,dir_mode=0777,file_mode=0666  0  0
    

    mount

  • Debian 9 OVH Bridge Network Configuration

    When you run VPS on OVH network behind bridge network, you need to create VMAC for each IP and assign to your network card.

    Once this is done, you need to use following network configuration in your /etc/network/inferfaces file.

    auto lo ens18
    iface lo inet loopback
    auto ens18
    iface ens18 inet static
        address FAILOVER_IP
        netmask 255.255.255.255
        broadcast FAILOVER_IP
        post-up ip route add GATEWAY_IP dev ens18
        post-up ip route add default via GATEWAY_IP dev ens18
        pre-down ip route del GATEWAY_IP dev ens18
        pre-down ip route del default via GATEWAY_IP dev ens18
    

    FAILOVER_IP = the IP you will be using for the virual machine.

    GATEWAY_IP = IP of the Host server with last digits replaced by 254. If your servers main IP is XX.YY.ZZ.100, then Your GATEWAY_IP is XX.YY.ZZ.254

    Here is an example config file i use in one of my VPS

    auto ens18
    iface ens18 inet static
        address 198.50.234.186
        netmask 255.255.255.255
        broadcast 198.50.234.186
        dns-nameservers 8.8.8.8 8.8.4.4
        post-up ip route add 158.69.124.254 dev ens18
        post-up ip route add default via 158.69.124.254 dev ens18
        pre-down ip route delete 158.69.124.254 dev ens18
        pre-down ip route delete default via 158.69.124.254 dev ens18
    

    I made a pull request to OVH as OVH documentation use route command, that is deprecated in Debian 9 and Ubuntu 18.04. We need to use “ip route” command instead of “route” command.

  • Resize gcow2 image with qemu

    To resize gcow2 image, run

    qemu-img resize FILE.qcow2 +10GB
    

    To create a gcow2 image, run

    qemu-img create -f qcow2 -o preallocation=metadata FILE.new 10G
    

    You can also use

    virt-resize --debug  --expand /dev/vda1 FILE.qcow2 FILE.qcow2.new
    

    virt-resize is part of http://libguestfs.org

  • 500 I won’t open a connection to x.x.x.x (only to y.y.y.y)

    500 I won’t open a connection to x.x.x.x (only to y.y.y.y)

    When connecting to FTP server from a remote server hosted in Microsoft Azure i get error

    500 I won’t open a connection to x.x.x.x (only to y.y.y.y)

    This is because you are behind NAT firewall and trying to use FTP in Active mode.

    To fix the error, enable FTP passive mode with command

    passive
    

    ftp

  • tar

    To extract a tar file, run

    tar xf file.tar.gz
    

    Uncompress tar.gz file

    tar -zxvf ncftp-3.2.2-src.tar.gz
    

    Uncompress tar.bz2 file

    tar -jxvf ncftp-3.2.2-src.tar.bz2
    

    Create a tar file

    tar -cvf file.tar FOLDER_OR_FILE_NAME
    

    Example

    tar -cvf backup.tar public_html
    

    Once backup.tar file is created, you can make it tar.gz with command

    gzip backup.tar
    

    Exclude a folder from tar file

    To exclude a folder, you can use –exclude option.

    tar cvf backup.tar --exclude=public_html/uploads --exclude=public_html/wordpress public_html
    

    List content of a tar file

    tar --list --verbose --file=BACKUP.tar.gz
    

    If you want to exclude a folder from the file list, use

    tar --list --verbose --file=BACKUP.tar.gz --exclude=home/haridy/Maildir
    

    This will exclude all files that are inside folder “home/haridy/Maildir”. You can use multiple –exclude if required.

    Using tar over SSH Session
    Split Large file into smaller files
    How to view the contents of tar.gz file

  • Debian

    When I install Debian 9 from CD, it did install with /etc/apt/sources.list pointing to CD.

    To get this work properly, you need to edit the file

    vi /etc/apt/sources.list
    

    Replace content with

    deb http://security.debian.org/ stretch/updates main
    deb-src http://security.debian.org/ stretch/updates main
    deb http://ftp.debian.org/debian/ stretch-updates main
    deb-src http://ftp.debian.org/debian/ stretch-updates main
    deb http://ftp.us.debian.org/debian stable main contrib non-free
    

    Debian Upgrade

  • Unable to detect ICU prefix

    When compiling PHP, i get following error.

    checking whether to enable internationalization support… yes
    checking for icu-config… no
    checking for location of ICU headers and libraries… not found
    configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.

    To fix, install libicu dev package.

    On CentOS/RHEL

    yum -y install libicu-devel
    

    On Debian/Ubuntu

    apt -y install libicu-dev
    

    Errors

  • Datacenter

    Here is some info for checking speed for various data centers.

    OVH Sydney, Australia

    Test IPv4 : 139.99.130.17
    Test IPv6 : 2402:1f00:8100:211::1
    Test files : http://syd.infrastructures.ovh/
    Test latency : http://syd.smokeping.ovh.net/smokeping?target=APAC
    Looking Glass: https://lg.ovh.net
    Network status: http://weathermap.ovh.net/#apac
    

    OVH, Singapore

    Test IPv4 : 139.99.8.97
    Test IPv6 : 2402:1f00:8000:261::1
    Test files : http://sgp.infrastructures.ovh/
    Test latency : http://sgp.smokeping.ovh.net/smokeping?target=APAC
    Looking Glass: https://lg.ovh.net
    Network status: http://weathermap.ovh.net/#apac
    

    Dedicated