Category: Linux

  • IO Load

    IO Load

    To get IO read/write rate, run

    sar -b 1 30
    

    Example

    root@server12:~# sar -b 1 30
    Linux 2.6.32-754.18.2.el6.x86_64 (server12.hosthat.com) 	12/07/2021 	_x86_64_	(8 CPU)
    
    08:47:15 PM       tps      rtps      wtps   bread/s   bwrtn/s
    08:47:16 PM    121.00      0.00    121.00      0.00    940.00
    08:47:17 PM      0.00      0.00      0.00      0.00      0.00
    08:47:18 PM      6.06      6.06      0.00    549.49      0.00
    08:47:19 PM      0.00      0.00      0.00      0.00      0.00
    08:47:20 PM    204.95     11.88    193.07    174.26   2879.21
    08:47:21 PM    579.38      2.06    577.32     16.49   4950.52
    08:47:22 PM      2.04      0.00      2.04      0.00      2.04
    08:47:23 PM      6.06      6.06      0.00     48.48      0.00
    08:47:24 PM     50.51     50.51      0.00    694.95      0.00
    08:47:25 PM    206.12     16.33    189.80    195.92   2746.94
    08:47:26 PM   1239.39     30.30   1209.09    985.86  10927.27
    08:47:27 PM    369.70      3.03    366.67     24.24   4906.06
    08:47:28 PM      7.14      5.10      2.04     40.82      1.02
    08:47:29 PM      0.00      0.00      0.00      0.00      0.00
    08:47:30 PM    211.22      6.12    205.10     97.96   3114.29
    08:47:31 PM    646.00      0.00    646.00      0.00   5426.00
    08:47:32 PM     16.16     14.14      2.02    129.29      2.02
    08:47:33 PM      0.00      0.00      0.00      0.00      0.00
    08:47:34 PM      4.08      4.08      0.00     48.98      0.00
    08:47:35 PM    216.00      2.00    214.00    512.00   3410.00
    08:47:36 PM    448.00      8.00    440.00     96.00   3652.00
    08:47:37 PM      2.06      0.00      2.06      0.00      2.06
    08:47:38 PM      0.00      0.00      0.00      0.00      0.00
    08:47:39 PM     10.10     10.10      0.00    177.78      0.00
    08:47:40 PM    189.00      8.00    181.00    160.00   2650.00
    08:47:41 PM    294.85      0.00    294.85      0.00   2420.62
    08:47:42 PM      8.00      6.00      2.00     48.00      2.00
    08:47:43 PM      2.02      2.02      0.00    517.17      0.00
    08:47:44 PM     12.12     12.12      0.00    113.13      0.00
    08:47:45 PM    179.59      6.12    173.47     65.31   2434.69
    Average:       168.06      7.02    161.04    157.19   1686.36
    root@server12:~# 
    

    To see system load, run

    sar -u -o  1 30
    
  • View systemctl service file

    View systemctl service file

    To view the content of a systemd service file, run the command

    systemctl cat SERVICE_NAME_HERE
    

    Example

    boby@sok-01:~$ systemctl cat nginx
    # /lib/systemd/system/nginx.service
    # Stop dance for nginx
    # =======================
    #
    # ExecStop sends SIGSTOP (graceful stop) to the nginx process.
    # If, after 5s (–retry QUIT/5) nginx is still running, systemd takes control
    # and sends SIGTERM (fast shutdown) to the main process.
    # After another 5s (TimeoutStopSec=5), and if nginx is alive, systemd sends
    # SIGKILL to all the remaining processes in the process group (KillMode=mixed).
    #
    # nginx signals reference doc:
    # http://nginx.org/en/docs/control.html
    #
    [Unit]
    Description=A high performance web server and a reverse proxy server
    Documentation=man:nginx(8)
    After=network.target

    [Service]
    Type=forking
    PIDFile=/run/nginx.pid
    ExecStartPre=/usr/sbin/nginx -t -q -g ‘daemon on; master_process on;’
    ExecStart=/usr/sbin/nginx -g ‘daemon on; master_process on;’
    ExecReload=/usr/sbin/nginx -g ‘daemon on; master_process on;’ -s reload
    ExecStop=-/sbin/start-stop-daemon –quiet –stop –retry QUIT/5 –pidfile /run/nginx.pid
    TimeoutStopSec=5
    KillMode=mixed

    [Install]
    WantedBy=multi-user.target
    boby@sok-01:~$

  • Redis error currently not able to persist on disk

    Redis error currently not able to persist on disk

    When doing a FLUSHALl on redis server, i get following error message

    [root@server ~]# redis-cli FLUSHALL
    (error) MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). Please check the Redis logs for details about the RDB error.
    [root@server ~]#

    The error was because redis data directory was not properly configured.

    To fix, the error, edit redis config file

    vi /etc/redis/redis.conf
    

    Find

    dir ./
    

    Replace with

    dir /var/lib/redis
    

    Create a directory

    mkdir /var/lib/redis
    

    Make it owned by user redis

    chown redis:redis /var/lib/redis
    

    Restart redis server

    systemctl restart redis
    

    See Redis

  • How to flush Redis cache

    How to flush Redis cache

    To delete everything from redis cache, run the command

    redis-cli FLUSHDB
    

    This will delete all keys from the current DB.

    To delete cache from all DB, run

    redis-cli FLUSHALL
    

    If Redis is on another server or needs password, you can use the following command

    redis-cli -h IP_HERE -p PORT_HERE -a PASSWORD_HERE FLUSHDB
    

    See Redis

  • How to find Redis data directory

    How to find Redis data directory

    To find the data directory in redis, run the command

    redis-cli config get dir
    

    redis data directory

    Redis data directory is specified in the configuration file

    /etc/redis/redis.conf 
    

    The entry is

    dir /var/lib/redis
    

    redis data directory should be owned by user redis

    chown redis:redis /var/lib/redis
    

    Example

    [root@server redis]# cd /var/lib/redis/
    [root@server redis]# ls -la
    total 12
    drwxrwx---   2 redis redis 4096 Dec  2 06:44 .
    drwxr-xr-x. 37 root  root  4096 Nov 20 17:30 ..
    -rw-r--r--   1 redis redis   92 Dec  2 06:44 dump.rdb
    [root@server redis]#
    

    See Redis

  • How to Install Gnome and xRDP on RHEL 8 (CentOS 8/Alma Linux/Rocky Linux)

    How to Install Gnome and xRDP on RHEL 8 (CentOS 8/Alma Linux/Rocky Linux)

    You can install Gnome Desktop + xdrp on a remote server (VPS/cloud or dedicated) and use it as a remote desktop for browsing or running applications. This instruction works for any RHEL 8 based distributions like CentOS 8, Alma Linux 8, Rocky Linux 8, and Oracle Linux 8.

    Install Gnome Desktop with

    dnf groupinstall -y --nobest Workstation
    

    After installing, reboot the server

    reboot
    

    xrdp package is provided by epel repository, so let’s enable it with

    dnf install -y epel-release
    

    install xrdp

    dnf install -y xrdp xrdp-selinux xorgxrdp
    

    Enable and start xrdp

    systemctl enable xrdp
    systemctl start xrdp
    

    Open port 3389 in the firewall

    firewall-cmd --add-port=3389/tcp --permanent
    firewall-cmd --reload
    

    Create a user and set a password for the user. This user will be used to login to remote desktop

    useradd -m --shell /bin/bash serverok
    usermod -aG wheel serverok
    passwd serverok
    

    Now you should be able to login to remote desktop using RDP.

    Once logged in, you may need to disable desktop animations to avoid lag by running the following command in the terminal.

    gsettings set org.gnome.desktop.interface enable-animations false
    
  • Find files older than X minutes

    Find files older than X minutes

    To find files that are older than X minutes, use the command

    find /path/ -type f -mmin +30

    This will find all files inside /path/ that are older than 30 minutes.

    If you need to delete those files, run

    find /path/ -type f -mmin +30 -delete

    To find files created in the last 30 minutes, run

    find /path/ -type f -mmin 30

    See find

  • Configure Failover IP in Ubuntu 20.04 OVH VPS

    Configure Failover IP in Ubuntu 20.04 OVH VPS

    To configure IP on OVH VPS, you need to manually configure networking as OVH gateway is outside the failover IP subnet. For most hosting providers getaway will be in the same subnet as the IP address. To configure IP using netplan, see instruction here.

    First, install ifupdown package

    apt install -y ifupdown
    

    Now edit file

    vi /etc/network/interfaces
    

    Add

    auto NETWORK_INTERFACE_HERE
    iface NETWORK_INTERFACE_HERE inet static
        address FO_IP_ADDR
        netmask 255.255.255.255
        broadcast FO_IP_ADDR
        dns-nameservers 8.8.8.8 8.8.4.4
        post-up ip route add GATEWAY_ADDR dev NETWORK_INTERFACE_HERE
        post-up ip route add default via GATEWAY_ADDR dev NETWORK_INTERFACE_HERE
        pre-down ip route del GATEWAY_ADDR dev NETWORK_INTERFACE_HERE
        pre-down ip route del default via GATEWAY_ADDR dev NETWORK_INTERFACE_HERE
    

    In the above text, replace

    NETWORK_INTERFACE_HERE = with your actual network interface name, for example, eth0, ens18, etc.
    FO_IP_ADDR = Your VPS IP address, OVH calls this Failover IP address. It is just any secondary IP address you purchase.
    GATEWAY_ADDR = Gateway IP address. This is the same as the Main IP of the server with the last octal replaced by 254

    Example

    Ubuntu 20.04 failover IP

    Configuration is the same as Ubuntu 18.04, the only difference is post-up and pre-down tines, where Ubuntu 18.04 used older route command, in Ubuntu 20.04, we use “ip route” command instead.

  • Bitnami WordPress Failed to update Plugin

    Bitnami WordPress Failed to update Plugin

    On a Bitnami WordPress server, plugin installation/upgrade failed with permission error. The error is because the web server in bitmai servers runs as user daemon. When you upload a file as user bitnami, you need to make sure you set file permission properly so anyone in the group can write.

    To fix the error, run

    sudo chown -R bitnami:daemon /home/bitnami/stack/wordpress
    sudo chown -R bitnami:daemon /bitnami/wordpress/wp-content
    sudo chmod -R 770 /bitnami/wordpress/wp-content
    sudo chmod -R 770 /home/bitnami/stack/wordpress
    

    Some bitnami installations use different file structure

    sudo chown -R bitnami:daemon /home/bitnami/apps/wordpress/htdocs
    sudo chmod -R 770 /home/bitnami/apps/wordpress/htdocs
    

    in wp-config.php, added the following when I migrated a site, refer to original wp-config.php for your exact path

    define('FS_METHOD', 'direct');
    define('WP_TEMP_DIR', '/opt/bitnami/apps/wordpress/tmp');
    
  • Install latest Redis on Ubuntu/Debian Server

    Install latest Redis on Ubuntu/Debian Server

    To install the latest version of Redis on Ubuntu/Debian server, run

    curl https://packages.redis.io/gpg | sudo apt-key add -
    echo "deb https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
    sudo apt-get update
    sudo apt-get install redis
    

    Enable redis server to start on boot

    systemctl enable redis-server
    

    Start redis server

    systemctl start redis-server
    

    See Redis

  • How to Install PHP 5.6 on Oracle Linux 7

    How to Install PHP 5.6 on Oracle Linux 7

    Oracle Linux is a free RHEL based Linux distro. We will install PHP 5.6 on an Oracle Linux 7 server.

    First, enable EPEL repo

    yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    

    Enable Remi repo

    yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
    

    Install yum-utils package

    yum install yum-utils
    

    Enable remi-php56

    yum-config-manager --enable remi-php56
    

    Install PHP 5.6 with

    yum install -y php php-bcmath php-cli php-common php-devel php-gd \
        php-imap php-intl php-json php-ldap php-lz4 php-mbstring php-mysqlnd \
        php-soap php-intl php-opcache php-xml php-pdo
    

    This will only install the CLI version of PHP 5.6. To make Apache work with PHP 5.6, install

    yum install php-pecl-http.x86_64
    

    This will create file /etc/httpd/conf.d/php.conf, that enable PHP module in Apache.

    Restart apache webserver

    systemctl restart httpd
    

    Now Apache will be able to serve PHP files.