Category: Linux

  • Install Jenkins on Ubuntu

    Install Jenkins on Ubuntu

    Jenkins is an open source automation server. It helps automate the parts of software development related to building, testing, and deploying, facilitating continuous integration and continuous delivery.

    Jenkins is a Java Application. So you need to install JRE (Java Runtime Environment). Install it with

    sudo apt-get install default-jre
    

    You can find instructions for installing Jenkins on Debian/Ubuntu at

    https://pkg.jenkins.io/debian-stable/

    Install Jenkins

    wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
    sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
    sudo apt-get update
    sudo apt-get install jenkins
    

    Enable Jenkins to start on boot

    sudo systemctl enable jenkins
    

    Start Jenkins

    sudo systemctl start jenkins
    

    To check status

    sudo systemctl status jenkins
    

    You can verify Jenkins running on port 8080 with command

    root@jenkins:~# 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.53:53           0.0.0.0:*               LISTEN      186/systemd-resolve 
    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      256/sshd: /usr/sbin 
    tcp6       0      0 :::22                   :::*                    LISTEN      256/sshd: /usr/sbin 
    tcp6       0      0 :::8080                 :::*                    LISTEN      4774/java           
    root@jenkins:~#
    

    To find the initial password, run the command

    cat /var/lib/jenkins/secrets/initialAdminPassword
    
  • Install Tomcat on CentOS 7

    Install Tomcat on CentOS 7

    Apache Tomcat is an open source implementation of the Java Servlet and Java Server Pages. To install Apache Tomcat on CentOS 7, run

    yum install tomcat
    

    To enable tomcat start on boot

    systemctl enable tomcat
    

    You can manage tomcat with

    systemctl stop tomcat
    systemctl start tomcat
    systemctl status tomcat
    systemctl restart tomcat
    

    To see the ports used by tomcat

    [root@tomcat ~]# netstat -lntp| grep java
    tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      31423/java          
    tcp6       0      0 :::8009                 :::*                    LISTEN      31423/java          
    tcp6       0      0 :::8080                 :::*                    LISTEN      31423/java          
    [root@tomcat ~]# 
    

    webapps are stored in the directory

    /var/lib/tomcat/webapps
    

    Create the default page with

    mkdir /var/lib/tomcat/webapps/ROOT
    echo "Hello Cat" > /var/lib/tomcat/webapps/ROOT/index.html
    

    Tomcat web server can be accessed using

    http://your-server-ip:8080
    

    To open 8080 port on the firewall, use commands

    firewall-cmd --permanent --zone=public --add-port=8080/tcp
    firewall-cmd --reload
    

    Tomcat configurations are available in the directory.

    /etc/tomcat/
    

    Install tomcat Manager

    To install the Tomcat manager GUI application, run

    yum install tomcat-admin-webapps.noarch -y
    

    To create user, edit file

    vi /etc/tomcat/tomcat-users.xml
    

    Inside ““, add

    
    
    

    USER_NAME_HERE and PW_HERE – replace with the username and password you need.

    Restart tomcat to activate Tomcat Manager GUI.

    systemctl restart tomcat
    

    To access GUI, go to

    http://your-server-ip-here:8080/manager/
    
  • How to change Node Exporter  port

    How to change Node Exporter port

    Node Exporter by default uses port 9100. You may need to use another port for Node Exporter if port 9100 is already used by another program on your server. On an OVH VPS, noderig was running in port 9100 and Node Exporter failed to start. To fix the issue, i had to run Node Exporter on a different port.

    To change the Node Exporter port, edit the file

    /etc/systemd/system/node_exporter.service

    Find line

    ExecStart=/usr/local/bin/node_exporter

    Replace it with

    ExecStart=/usr/local/bin/node_exporter --web.listen-address=:9101

    In the above line, 9101 is the new Node Exporter port. You can change it to any other port as required.

    Here is the complete code

    root@ns568267:~# cat /etc/systemd/system/node_exporter.service
    [Unit]
    Description=Node Exporter
    Wants=network-online.target
    After=network-online.target
    
    [Service]
    User=node_exporter
    Group=node_exporter
    Type=simple
    ExecStart=/usr/local/bin/node_exporter --web.listen-address=:9101
    
    [Install]
    WantedBy=multi-user.target
    root@ns568267:~# 

    Reload systemd

    systemctl daemon-reload

    Restart node exporter

    systemctl start node_exporter

    You can verify node_exporter is running with the command

    root@ns568267:~# netstat -lntp | grep node_
    tcp6       0      0 :::9101                 :::*                    LISTEN      15630/node_exporter 
    root@ns568267:~# 
  • top

    top

    top command is used to see current system resource usage

    To show the current process

    top -n 1 -b

    Top sorted by memory

    top -b -n 1 -o %MEM | sort -nk 6

    Delay 3 second

    top -cd3

    Back to Linux Commands

  • ack show the matched files name only

    ack show the matched files name only

    ack is a command-line utility written in Perl for searching strings inside files. By default when you search, it shows you the file name along with the matching content of the file. Sometimes you may only want to list file names that match your search. This can be done with -l option

    ack -l "search string here"
    

    Example

    ack list files

    See ack

  • Install .NET SDK on Ubuntu 20.04

    Install .NET SDK on Ubuntu 20.04

    Microsoft .NET SDK and Run time now available for Linux. To install .NET SDK and runtime on Ubuntu 20.04, follow the instructions below

    Run the following commands as user root. If you are logged in as a normal user, use the command “sudo su” to become user root.

    wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
    dpkg -i packages-microsoft-prod.deb
    rm packages-microsoft-prod.deb
    

    Update the repo and install apt-transport-https

    apt-get update
    apt-get install -y apt-transport-https
    

    Search for available dotnet-sdk versions

    apt-cache search dotnet-sdk
    

    apt search dotnet-sdk

    On Ubuntu 20.04, Microsoft provides .NET SDK version 2.1, 3.1, and 5. Let’s install version 5.

    apt-get install -y dotnet-sdk-5.0
    

    To find the version of .NET SDK, run

    dotnet --version
    

    Find  dotnet version in Ubuntu

    You can find .NET SDK and runtime available with commands

    dotnet --list-sdks
    dotnet --list-runtimes
    
  • Enable/Disable Nextcloud Maintenance Mode

    Enable/Disable Nextcloud Maintenance Mode

    Maintenance mode is useful when you are making changes to your nextcloud installation like a software upgrade.

    To enable maintenance mode, run the command

    php7.3 occ maintenance:mode --on
    

    To disable maintenance mode, run

    php7.3 occ maintenance:mode --off
    

    Example

    www-data@mail:/www/nextcloud$ php occ maintenance:mode --off
    Maintenance mode disabled
    www-data@mail:/www/nextcloud$ 
    

    See Nextcloud

  • Module php-imagick in this instance has no SVG support

    Module php-imagick in this instance has no SVG support

    On Ubuntu server running Nextcloud, I got the following warning in Nextcloud

    Module php-imagick in this instance has no SVG support. For better compatibility it is recommended to install it.
    

    To fix this warning, install libmagickcore-6.q16-6-extra package with the command

    apt-get install libmagickcore-6.q16-6-extra
    

    See Nextcloud

  • chattr: Operation not supported while reading flags

    chattr: Operation not supported while reading flags

    When making a file immutable with chattr command, I get the following error

    [root@vps784847 vhosts]# chattr +i serverok.in.conf 
    chattr: Operation not supported while reading flags on serverok.in.conf
    [root@vps784847 vhosts]#

    The error was due to the file I was trying to chattr being a symlink, not a real file.

    [root@vps784847 vhosts]# ls -la
    total 0
    drwxr-xr-x. 2 root root  31 Oct 27 08:11 .
    drwxr-xr-x. 7 root root 131 Jun  1 02:03 ..
    lrwxrwxrwx. 1 root root  51 Jul 24 12:39 serverok.in.conf -> /var/www/vhosts/system/serverok.in/conf/nginx.conf
    [root@vps784847 vhosts]# 

    To fix the error, chattr the actual file.

    chattr +i /var/www/vhosts/system/serverok.in/conf/nginx.conf

    Back to Linux Commands

  • Checking NVMe Disk

    Checking NVMe Disk

    You can use nvme-cli to check your NVMe disks. To install nvme-cli, run

    On Ubuntu/Debian

    sudo apt-get install -y nvme-cli
    

    On RHEL

    sudo yum install nvme-cli
    

    To list of NVMe drives, use

    nvme list
    

    Example

    [root@server52 ~]# nvme list
    Node             SN                   Model                                    Namespace Usage                      Format           FW Rev  
    ---------------- -------------------- ---------------------------------------- --------- -------------------------- ---------------- --------
    /dev/nvme0n1     S439NA0N900171       SAMSUNG MZQLB1T9HAJR-00007               1         531.97  GB /   1.92  TB    512   B +  0 B   EDA5402Q
    /dev/nvme1n1     S439NA0N900057       SAMSUNG MZQLB1T9HAJR-00007               1         532.00  GB /   1.92  TB    512   B +  0 B   EDA5402Q
    [root@server52 ~]# 
    

    To find smart data, run

    nvme smart-log DEVICE_NAME_HERE
    

    Example

    [root@server52 ~]# nvme smart-log /dev/nvme0n1
    Smart Log for NVME device:nvme0n1 namespace-id:ffffffff
    critical_warning                    : 0
    temperature                         : 39 C
    available_spare                     : 100%
    available_spare_threshold           : 10%
    percentage_used                     : 0%
    data_units_read                     : 130,334,241
    data_units_written                  : 69,361,921
    host_read_commands                  : 866,547,209
    host_write_commands                 : 710,448,251
    controller_busy_time                : 998
    power_cycles                        : 88
    power_on_hours                      : 5,464
    unsafe_shutdowns                    : 83
    media_errors                        : 0
    num_err_log_entries                 : 0
    Warning Temperature Time            : 0
    Critical Composite Temperature Time : 0
    Temperature Sensor 1                : 39 C
    Temperature Sensor 2                : 43 C
    Temperature Sensor 3                : 47 C
    Thermal Management T1 Trans Count   : 0
    Thermal Management T2 Trans Count   : 0
    Thermal Management T1 Total Time    : 0
    Thermal Management T2 Total Time    : 0
    [root@server52 ~]# 
    

    To see the NVMe error log

    nvme error-log	DEVICE_NAME_HERE
    
  • mount: unknown filesystem type ‘LVM2_member’.

    mount: unknown filesystem type ‘LVM2_member’.

    When I try to mount a partition, I get the following error

    [root@sysresccd ~]# mount /dev/nvme0n1p3 /mnt
    mount: /mnt: unknown filesystem type 'LVM2_member'.
    [root@sysresccd ~]# 
    

    This is because the disk is LVM. First of all identify the name of the volume group and logical volume.

    vgs
    lvs
    

    Example

    [root@sysresccd ~]# vgs
      VG #PV #LV #SN Attr   VSize  VFree
      vg   2   3   0 wz--n- <1.82t    0 
    [root@sysresccd ~]# lvs
      LV   VG Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
      root vg -wi-a-----   1.80t                                                    
      swap vg -wi-a----- <15.69g                                                    
      tmp  vg -wi-a-----   1.00g                                                    
    [root@sysresccd ~]#
    

    From the above result, we found the server has 3 logical volumes. The biggest volume is root. Other volumes swap and tmp we can ignore. So the device name is

    /dev/vg/root
    

    Next run

    modprobe dm-mod
    lvscan
    vgchange -ay
    

    Example

    [root@sysresccd ~]# lvscan
      ACTIVE            '/dev/vg/swap' [<15.69 GiB] inherit
      ACTIVE            '/dev/vg/tmp' [1.00 GiB] inherit
      ACTIVE            '/dev/vg/root' [1.80 TiB] inherit
    [root@sysresccd ~]# vgchange -ay
      3 logical volume(s) in volume group "vg" now active
    [root@sysresccd ~]#
    

    Now you should be able to mount with disk using command

    mount /dev/vg/root /mnt/
    
  • Delayed block allocation failed for inode

    Delayed block allocation failed for inode

    On a CentOS server, nginx web server stopped serving files. On checking logs, I found the following error message

    2021/10/25 19:08:35 [crit] 42762#0: *78977627 pread() "/var/www/html/995.mp4" failed (5: Input/output error) while sending response to client, client: 59.92.71.53, server: 158.58.173.92, request: "GET /995.mp4 HTTP/1.1", host: "domain.tld"

    I tried to copy the file, copy filed with error message “Input/output error”

    [root@mta1 html]# cp /var/www/html/995.mp4 ~/
    cp: error reading '/var/www/html/995.mp4': Input/output error
    [root@mta1 html]# 

    On /var/log/messages, I had the following error message

    Oct 25 19:19:03 mta1 kernel: EXT4-fs error (device dm-0): ext4_wait_block_bitmap:520: comm kworker/u32:2: Cannot read block bitmap - block_group = 7705, block_bitmap = 252182537
    Oct 25 19:19:03 mta1 kernel: EXT4-fs (dm-0): Delayed block allocation failed for inode 39976964 at logical offset 33810 with max blocks 14 with error 5
    Oct 25 19:19:03 mta1 kernel: EXT4-fs (dm-0): This should not happen!! Data will be lost

    The problem is fixed by rebooting the server into rescue mode, then running the fsck command.

    [root@sysresccd ~]# fsck -y /dev/vg/root
    fsck from util-linux 2.35.2
    e2fsck 1.45.6 (20-Mar-2020)
    /dev/mapper/vg-root contains a file system with errors, check forced.
    Pass 1: Checking inodes, blocks, and sizes
    Pass 2: Checking directory structure
    Pass 3: Checking directory connectivity
    Unconnected directory inode 61210647 (/var/cache/dnf/epel-modular-95d9a0c53e492cbd/???)
    Connect to /lost+found? yes
    
    Unconnected directory inode 61210656 (/var/cache/dnf/extras-2770d521ba03e231/???)
    Connect to /lost+found? yes
    
    Unconnected directory inode 61210668 (/var/cache/dnf/epel-6519ee669354a484/???)
    Connect to /lost+found? yes
    
    Pass 4: Checking reference counts
    Inode 39845944 ref count is 1, should be 2.  Fix? yes
    
    ...
    
    Unattached inode 61210637
    Connect to /lost+found? yes
    
    Inode 61210637 ref count is 2, should be 1.  Fix? yes
    
    Inode 61210641 ref count is 3, should be 2.  Fix? yes
    
    Directories count wrong for group #7474 (5, counted=0).
    Fix? yes
    
    Free inodes count wrong (120894192, counted=120894225).
    Fix? yes
    
    Padding at end of inode bitmap is not set. Fix? yes
    
    
    /dev/mapper/vg-root: ***** FILE SYSTEM WAS MODIFIED *****
    /dev/mapper/vg-root: 44271/120938496 files (2.2% non-contiguous), 235802671/483741696 blocks
    [root@sysresccd ~]# 

    See fsck