Category: Linux

  • How to Migrate CentOS 8 to AlmaLinux

    How to Migrate CentOS 8 to AlmaLinux

    CentOS 8 is reaching its End of Life in December 2021. If you are using CentOS 8, you may need to consider migrating to other operating systems.

    Other alternatives for CentOS 8 are AlmaLinux, Rocky Linux, and Oracle Linux. All of these are free and are based on RHEL 8.

    AlmaLinux is released a migration script

    https://github.com/AlmaLinux/almalinux-deploy

    This script allows you to convert CentOS 8 to AlmaLinux.

    WARNING: Make sure you take a full system backup before migrating.

    Before migrating, make sure your system is up to date.

    dnf update

    If you get error, Error: Failed to download metadata for repo ‘appstream’, run

    sed -i -e "s|mirrorlist=|#mirrorlist=|g" /etc/yum.repos.d/CentOS-*
    sed -i -e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-*
    dnf update

    Reboot the server

    reboot

    Once the server is back online, we can run the AlmaLinux migration script to start the migration.

    curl -O https://raw.githubusercontent.com/AlmaLinux/almalinux-deploy/master/almalinux-deploy.sh
    bash almalinux-deploy.sh

    After the migration is complete, run

    dnf distro-sync -y

    Now you need to reboot the server

    reboot
  • How to find out what service is using a certain port?

    To find out which service or program using a port on a Linux machine, you can use the command

    fuser -vn tcp PORT_HERE
    

    Example

    root@sok-01:~# fuser -vn tcp 80
                         USER        PID ACCESS COMMAND
    80/tcp:              root       1144 F.... nginx
                         boby       1145 F.... nginx
                         boby       1146 F.... nginx
                         boby       1147 F.... nginx
                         boby       1148 F.... nginx
    root@sok-01:~# 
    

    In this case, TCP port 80 is used by a process with PID 1144, that is Nginx. This process has multiple subprocesses with PID 1145, 1146, 1147, and 1148.

    You can also use

    root@sok-01:~# fuser 80/tcp
    80/tcp:               1144  1145  1146  1147  1148
    root@sok-01:~# 
    

    This just lists all process IDs. You can find the process by looking at the result of “ps aux” command and finding the process with the above process ids.

    Using netstat

    Another method is to use “netstat -lntp” command

    root@sok-01:~# netstat -lntp
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
    tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      913/cupsd           
    tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      1144/nginx: master  
    tcp        0      0 127.0.0.1:5982          0.0.0.0:*               LISTEN      22719/VBoxHeadless  
    tcp        0      0 0.0.0.0:7070            0.0.0.0:*               LISTEN      1036/anydesk        
    tcp        0      0 127.0.0.1:7878          0.0.0.0:*               LISTEN      2969/ssh            
    tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      1118/mysqld         
    tcp        0      0 127.0.0.1:2222          0.0.0.0:*               LISTEN      22719/VBoxHeadless  
    tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/init              
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1144/nginx: master  
    tcp        0      0 10.42.0.1:53            0.0.0.0:*               LISTEN      26291/dnsmasq       
    tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      1532/dnsmasq        
    tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      856/systemd-resolve 
    tcp6       0      0 ::1:631                 :::*                    LISTEN      913/cupsd           
    tcp6       0      0 ::1:7878                :::*                    LISTEN      2969/ssh            
    tcp6       0      0 :::5900                 :::*                    LISTEN      22719/VBoxHeadless  
    tcp6       0      0 :::111                  :::*                    LISTEN      1/init              
    root@sok-01:~# 
    

    This lists all listening ports. The last column shows PID/Program name. To find a specific port, you can use grep

    root@sok-01:~# netstat -lntp | grep 80
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1144/nginx: master  
    root@sok-01:~# 
    

    In the above command, we find which program uses port 80.

  • Install Thin web server

    Thin is a Ruby web server that can handle high levels of concurrency.

    Install it with

    gem install thin
    
    root@server70 [/home/redmine]# gem install thin
    Building native extensions.  This could take a while...
    Building native extensions.  This could take a while...
    Successfully installed eventmachine-0.12.10
    Successfully installed daemons-1.1.2
    Successfully installed thin-1.2.11
    3 gems installed
    Installing ri documentation for eventmachine-0.12.10...
    Installing ri documentation for daemons-1.1.2...
    Installing ri documentation for thin-1.2.11...
    Installing RDoc documentation for eventmachine-0.12.10...
    Could not find main page README
    Could not find main page README
    Could not find main page README
    Could not find main page README
    Installing RDoc documentation for daemons-1.1.2...
    Installing RDoc documentation for thin-1.2.11...
    root@server70 [/home/redmine]# 
    

    Installing thin on Ubuntu

    You can install thin web server on Ubuntu/Debian using

    apt install thin
    
  • How to host static site using pm2

    PM2 is a process manager for node.js applications. You can use PM2 to host static websites.

    To host a static website, create a folder, and put your files inside.

    mkdir /home/website

    Let’s create a static file, say index.html

    echo "Welcome" > /home/website/index.html

    Now you can make the site live using the following pm2 command

    pm2 serve /home/website 8082

    Now the static site will be available at

    http://localhost:8082

    If you have a Single Page Application (SPA) like Angular, React, you can use the option –spa with pm2 command so all non-existent pages get routed to index.html internally.

    pm2 serve --spa
  • dmidecode

    dmidecode

    dmidecode is a tool for dumping a computer’s DMI (SMBIOS ) table contents in a human-readable format. This table contains a description of the system’s hardware components, as well as other useful pieces of information such as serial numbers and BIOS revision. Thanks to this table, you can retrieve this information without having to probe for the actual hardware. While this is a good point in terms of report speed and safeness, this also makes the presented information possibly unreliable.

    The DMI table doesn’t only describe what the system is currently made of, it also can report the possible evolutions (such as the fastest supported CPU or the maximal amount of memory supported).

    SMBIOS stands for System Management BIOS, while DMI stands for Desktop Management Interface. Both standards are tightly related and developed by the DMTF (Desktop Management Task Force).

    To see system details, run

    dmidecode
    

    How to find RAM details in Linux

  • How to find RAM details in Linux

    How to find RAM details in Linux

    To find RAM memory details (model number/manufacturer) in Linux, you can use the command

    dmidecode --type 17
    

    To show only model numbers, run

    dmidecode --type 17 | grep "Part Number"
    

    Linux find ram details

    Once you find the Part Number, you can search in google for the part number to see more details about the RAM.

    On Ubuntu/Debian, you can install dmidecode with the command

    apt install -y dmidecode
    

    On RHEL, CentOS, OracleLinux, you can use the command

    yum install dmidecode
    

    On newer RHEL systems, you can use dnf instead of yum.

  • How to Install Elasticsearch in Docker

    How to Install Elasticsearch in Docker

    To Install Elasticsearch with Docker, first, you need to install docker on your server with command

    wget -qO- https://get.docker.com/ | sh
    

    Docker images for Elasticsearch are available from

    https://hub.docker.com/_/elasticsearch

    You can see all available versions at

    https://hub.docker.com/_/elasticsearch?tab=tags&page=1&ordering=last_updated

    To create an elasticsearch container, run

    docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.5.2

    To run it in the background

    docker run --name sok-elasticsearch --restart=unless-stopped \
     -d -p 9200:9200 -p 9300:9300 \
     -e "xpack.security.enabled=false" \
     -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.5.2

    To verify if ElasticSearch works, run

    boby@sok-01:~$ curl localhost:9200
    {
      "name" : "730d385743b3",
      "cluster_name" : "docker-cluster",
      "cluster_uuid" : "V9XDIPXZQt-Tfgcy8hoIDg",
      "version" : {
        "number" : "7.5.2",
        "build_flavor" : "default",
        "build_type" : "docker",
        "build_hash" : "8bec50e1e0ad29dad5653712cf3bb580cd1afcdf",
        "build_date" : "2020-01-15T12:11:52.313576Z",
        "build_snapshot" : false,
        "lucene_version" : "8.3.0",
        "minimum_wire_compatibility_version" : "6.8.0",
        "minimum_index_compatibility_version" : "6.0.0-beta1"
      },
      "tagline" : "You Know, for Search"
    }
    boby@sok-01:~$ 

    Back to Elasticsearch

  • How to find CPU of a Linux Server

    To find CPU used on a Linux system, run command

    cat /proc/cpuinfo
    

    Example

    boby@sok-01:~$ cat /proc/cpuinfo | grep -i "model name"
    model name	: AMD Ryzen 3 2200G with Radeon Vega Graphics
    model name	: AMD Ryzen 3 2200G with Radeon Vega Graphics
    model name	: AMD Ryzen 3 2200G with Radeon Vega Graphics
    model name	: AMD Ryzen 3 2200G with Radeon Vega Graphics
    boby@sok-01:~$ 
    
  • How to Delete Website (Virtual Server) in Virtualmin

    How to Delete Website (Virtual Server) in Virtualmin

    In the Virtualmin Hosting control panel, websites are called Virtual Server. To delete a website, click on the Virtualmin tab.

    Delete website in virtualmin

    From the dropdown menu, select the website you need to delete.

    On the left menu, click on “Disable and Delete’. Then click on “Delete Virtual Server” Link.

    Virtualmin > Domain > Disable and Delete > Delete Virtial Server
    

    It will ask for confirmation. Click on the red “Yes, Delete it” button to delete the website.

    See Virtualmin

  • How to display /proc/*/environ file in separate lines?

    How to display /proc/*/environ file in separate lines?

    environ is a file located in /proc/PID/environ, it shows environment variables for a process.

    If you run “cat environ”, you will get a long string.

    linux proc evviron file

    To make it readable, you can use sed command.

    cat environ | sed -z 's/$/\n/'
    cat cmdline | tr '\0' ' ' ; echo

    Example

    linux procs environ display with sed

  • Watermark video using ffmpeg

    To watermark video using FFmpeg, run

    ffmpeg -i SOURCE.mp4 -vf "drawtext=text='WATERMARK_TEXT':x=10:y=H-th-10:fontsize=32:fontcolor=white:shadowcolor=black:shadowx=2:shadowy=2" OUT.mp4
    

    In the above command replace

    SOURCE.mp4 = file name of the video you need to watermark.
    OUT.mp4 = file name for the watermarked video.
    WATERMARK_TEXT =  Text you need to watermark on the video.
    

    See ffmpeg