Category: Linux

  • Unable to Write to Disk – Inodes Full

    Unable to Write to Disk – Inodes Full

    On a server, can’t write to disk. I checked disk usage with

    df -h

    Everything is good. Next i checked Inodes usage with

    df -hi

    Inodes usage was 100%

    [root@w8bd-blkx ~]# df -hi
    Filesystem Inodes IUsed IFree IUse% Mounted on
    /dev/ploop36812p1 6.1M 6.1M 5 100% /
    /dev/simfs 6.1M 6.1M 5 100% /tmp
    /dev/simfs 6.1M 6.1M 5 100% /var/tmp
    none 1.0M 160 1.0M 1% /dev
    [root@w8bd-blkx ~]#

    This normally happen when you have too many smaller files.

    First of all free up some Inodes by removing unwanted log files, most of the time you can delete some logs in /var/log folder.

    To find where the Inodes are used up, run command

    find / -xdev -printf '%h\n' | sort | uniq -c | sort -k 1 -n

    The command will display Inodes usage for folder sorted by Inodes.

    linux inodes usage

    In this case, httpdocs/var/session had too many session files. I removed all session files, that fixed the problem. To avoid this happening again, i created a cronjob, that delete old session files every day.

    hdd

  • Sync Files between 2 servers

    Here are some tools that can be used to sync files between 2 servers.

  • VestaCP Zero-day exploit

    VestaCP Zero-day exploit

    On 07 April 2018, many servers using VestaCP got hacked. Hacker was able to get root acceess on these servers.

    VestaCP Free Hosting Control Panel

    Hacker installed some trojan software known as Chinese Chicken that is used to DDoS other servers.

    To see if your server is hacked, check if file /etc/cron.hourly/gcc.sh is present in your server.

    ls -l  /etc/cron.hourly/gcc.sh
    

    You can read more about this DDoS Trojan at

    https://blog.avast.com/2015/01/06/linux-ddos-trojan-hiding-itself-with-an-embedded-rootkit/

    If you are running VestaCP, stop it until a solution for this exploit is released.

    service vesta stop
    systemctl stop vesta
    

    You can find discussion on this exploit on VestaCP form

    https://forum.vestacp.com/viewtopic.php?f=10&t=16556

    Once server is rooted, it is better to take backup of all your data and restore OS.

  • Create user in PostgreSQL

    Method 1

    To create user, become user “postgres” with

    su - postgres
    

    now run

    createuser USER_NAME
    

    Method 2

    You can run following commands in psql prompt

    CREATE USER USER_NAME_HERE WITH PASSWORD 'PASSWORD_HERE';
    GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO USER_NAME_HERE;
    GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO USER_NAME_HERE;
    GRANT USAGE ON SCHEMA public TO USER_NAME_HERE;
    

    https://www.postgresql.org/docs/8.0/static/sql-createuser.html

    PostgreSQL

  • SUSE Linux Enterprise Server

    SUSE Linux Enterprise Server

    SUSE Linux Enterprise Server is a commercial linux distribution available at

    https://www.suse.com/products/server/

    To find version, run

    cat /etc/*release
    

    Example

    # cat /etc/*release
    SUSE Linux Enterprise Server 12 (x86_64)
    VERSION = 12
    PATCHLEVEL = 3
    # This file is deprecated and will be removed in a future service pack or release.
    # Please check /etc/os-release for details about this release.
    NAME="SLES"
    VERSION="12-SP3"
    VERSION_ID="12.3"
    PRETTY_NAME="SUSE Linux Enterprise Server 12 SP3"
    ID="sles"
    ANSI_COLOR="0;32"
    CPE_NAME="cpe:/o:suse:sles:12:sp3"
    # 
    

    SUSE Linux use yast package manager.

    Installing Software on SUSE Linux

    To install software, you can use yast or zypper.

    yast is a GUI based software. zypper is command line tool like apt/yum/dnf etc..

  • Install MongoDB in Ubuntu

    To install MongoDB in Ubuntu/Debian, run

    apt install mongodb
    

    Configuration file for MongoDB is

    /etc/mongodb.conf
    

    To see status of MongoDB, run

    systemctl status mongodb
    

    To start/stop

    systemctl start mongodb
    systemctl stop mongodb
    

    Create a User

    mongo
    use admin
    db.createUser({user: "root", pwd: "serverok123", roles:["root"]})
    

    Now you need to enable authentication, this can be done by editing /etc/mongodb.conf

    vi /etc/mongodb.conf
    

    Uncomment the line

    auth = true
    

    Restart MongoDB

    systemctl restart mongodb
    

    Now you can login with

    mongo -u  "root" -p "serverok123" --authenticationDatabase "admin"
    

    To verify all works, run some command, for example

    show dbs
    

    On Ubuntu 18.04, default MongoDB version is

    ubuntu@ip-172-31-8-76:~$ mongo -u  "root" -p "serverok123" --authenticationDatabase "admin"
    MongoDB shell version v3.6.3
    connecting to: mongodb://127.0.0.1:27017
    MongoDB server version: 3.6.3
    Welcome to the MongoDB shell.
    For interactive help, type "help".
    For more comprehensive documentation, see
    	http://docs.mongodb.org/
    Questions? Try the support group
    	http://groups.google.com/group/mongodb-user
    Server has startup warnings: 
    2018-12-22T17:06:15.171+0000 I STORAGE  [initandlisten] 
    2018-12-22T17:06:15.171+0000 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
    2018-12-22T17:06:15.171+0000 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
    > db.version()
    3.6.3
    > 
    

    MongoDB

  • Zimbra Generate DKIM Key

    To generate DKIM key in Zimbra Mail server, login as user zimbra

    su - zimbra

    Now run

    /opt/zimbra/libexec/zmdkimkeyutil -a -d DOMAIN_NAME

    Example

    zimbra@mail:~$ /opt/zimbra/libexec/zmdkimkeyutil -a -d serverok.in
    DKIM Data added to LDAP for domain serverok.in with selector 1F6B0E4C-3AA1-11E8-9B49-B0D65E0AC318
    Public signature to enter into DNS:
    1F6B0E4C-3AA1-11E8-9B49-B0D65E0AC318._domainkey IN  TXT ( "v=DKIM1; k=rsa; "
          "p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA354ZukWI34mIZKFM/IsKnUO6fnwhF8PLpgb2NOl687yzlxk1HYwlM7lyS9T4blAWlbOEzkdT1lLpNJRzEImrlkFzmzXaBWPSMEoJQVQgTfir6OoXoCUtwuLmPqwEftb2Th+/9Wmkh3PTc3o+x7/4kV0QMCTnJVXIFSHAfNREG8mGNPgij/iXHwbpVEi2P0UzmI/882TCEJXBry"
          "nKB4g5HtiOx1WUNtsKTEAyA9/5vZqsqa1RupHLOxwqyrTcNA9IL/iadOG3Q4PCXN788pQNCzpCyUQn6OQwFDy7/S345NGygd51F93NIZGmj01qWYq8VpFiNKnAOWTX9UiW27hA/QIDAQAB" )  ; ----- DKIM key 1F6B0E4C-3AA1-11E8-9B49-B0D65E0AC318 for serverok.in
    zimbra@mail:~$

    Retrieve the DKIM Key

    Use the following command to display the DKIM key for the specified domain.

    /opt/zimbra/libexec/zmdkimkeyutil -q -d YOUR_DOMAIN_HERE

    Zimbra

  • Install MATE Desktop in Ubuntu

    Add PPA repo with command

    apt-add-repository ppa:ubuntu-mate-dev/xenial-mate
    

    To install MATE run

    apt-get update
    apt-get install mate 
    

    This install was done on remote VPS with x2go server. Once install is over, i am able to connect to remote desktop using x2go client.

    x2go

  • Install GeoIP PHP Module in Ubuntu

    To install GeoIP php module in Ubuntu, run

    apt install php-geoip
    

    To enable module, run

    phpenmod geoip
    

    You can see the PHP module with command php -m

    root@ip-172-31-26-233:~# php -m | grep geoip
    geoip
    root@ip-172-31-26-233:~# 
    

    Also it will be listed in phpinfo page.

    geoip

  • xfs

    xfs is default file system for RHEL 7.

    To format a partition in xfs format, run

    mkfs.xfs /dev/sdXX
    

    Example

    [root@ssd ~]# mkfs.xfs /dev/sdc1
    meta-data=/dev/sdc1              isize=512    agcount=6, agsize=268435455 blks
             =                       sectsz=4096  attr=2, projid32bit=1
             =                       crc=1        finobt=0, sparse=0
    data     =                       bsize=4096   blocks=1464843520, imaxpct=5
             =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
    log      =internal log           bsize=4096   blocks=521728, version=2
             =                       sectsz=4096  sunit=1 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
    [root@ssd ~]# 

    Failed to mount /sysroot XFS Boot failure
    fs

  • mod_fcgid: HTTP request exceeds MaxRequestLen

    On a ISPConfig server with PHP running in FCGI Mode, i get following error in error_log when upload images from WordPress admin area.

    [Tue Apr 03 13:45:11 2018] [warn] [client 112.133.237.47] mod_fcgid: HTTP request length 139264 (so far) exceeds MaxRequestLen (131072), referer: https://www.url.com/wp-admin/media-new.php

    ISPConfig store error log for site in “log” directory in parent folder of document root. In this case, it was

    /var/www/clients/client0/web1/log/error.log
    

    To fix the error add

    FcgidMaxRequestLen 1073741824
    

    to fcgi.conf

    On Ubuntu/Debian, you file location is

    vi /etc/apache2/mods-available/fcgid.conf
    

    On CentOS/RHEL

    vi /etc/httpd/conf.d/fcgid.conf