Category: CentOS

  • Yum Error Operation too slow

    When i did yum update on a CloudLinux server, i get following error

    error was [Errno 12] Timeout on https://cl-mirror.dewabiz.com/XMLRPC/GET-REQ/cloudlinux-x86_64-server-7/repodata/filelists.xml.gz: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 120 seconds')
    

    This is because server is unable to connect to one of the yum mirrors.

    To fix this, we need to disable the mirror that cause this timeout.

    Edit file

    vi /etc/yum/pluginconf.d/fastestmirror.conf
    

    Find

    enabled=0
    

    Replace with

    enabled=1
    

    Find

    exclude=
    

    Add below

    exclude=cl-mirror.dewabiz.com
    

    run

    yum clean all
    yum makecache
    

    Now yum will work.

    See yum

  • yum fix duplicate package error

    When installing a package, i get following error

    Protected multilib versions: 1:systemd-libs-219-78.el7.cloudlinux.i686 != 1:systemd-libs-219-78.el7_9.2.cloudlinux.x86_64
    

    To fix, remove the conflicting package with

    rpm -e --nodeps --justdb systemd-libs
    

    See yum, Fix yum duplicate packages

  • Red Hat Killing CentOS Linux, Fight for CentOS clone

    Red Hat Killing CentOS Linux, Fight for CentOS clone

    RedHat, parent company of CentOS Linux announce it will stop supporting CentOS 8, the latest version of CentOS. CentOS is build from the source code RHEL, making a free version of stable and well-tested enterprise ready RHEL Linux. CentOS 7 will keep getting security updates until it reaches End Of Life June 30th, 2024. For Red Hat, maintaining CentOS wont help with their business. Now they don’t need to maintain CentOS, this will force many users to pay for Red Hat Enterprise Linux (RHEL).

    RedHat Killing CentOS Linux

    The new version of CentOS known as CentOS Stream is a rolling release. It will be used as a staging version of RHEL. Red Hat expect CentOS Stream to be stable and allow community participation as users will be able to contribute to CentOS Steam. With CentOS, community contribution was limited because it was a copy of RHEL.

    CentOS is populary used in web hosting servers as cpanel only supposed RHEL based Linux. With death of CentOS 8, cpanel have announced they will accelerate investment in development efforts to support additional operating systems. cPanel will suport Ubuntu LTS and expect to deliver a production-ready version in late 2021. After Ubuntu LTS, they will look into supporting Debian. Ubuntu is very popular with Cloud Servers as it come with latest software compared to CentOS. With many developers already using Ubuntu on their Desktop, supporting Ubuntu is wise decision by cpanel.

    With CentOS 8 unexpected demise, many users will be looking for alternative OS. This opens up market for next CentOS clone.

    Rocky Linux

    CentOS co-founder, Gregory Kurtzer announced he will be releasing his own Red Hat Enterprise Linux (RHEL) replacement Rocky Linux. No ETA on release date yet.

    https://rockylinux.org

    You can join discussion on their reddit.com/r/RockyLinux/

    Project Lenix

    Igor Seletskiy, CloudLinux CEO and founder said they will make their own RHEL patch to patch compatible Open Source Linux – Project Lenix.

    CloudLinux is a CentOS based commerical Linux, that is popular amoung web hosting providers as it allow resource limit per user and user isolation with CageFS. They also have support for kernel update with out reboot.

    CloudLinux will be investing more than a million dollar into Project Lenix. CentOS 8 users will be able to convert into Project Lenix or CloudLinux easily with out reboot. In the announcement Igor Seletskiy said “Red Hat’s announcement has left users looking for an alternative with all that CentOS provides and without the disruption of having to move to alternative distributions. We promise to dedicate the resources required to Project Lenix that will ensure impartiality and a not-for-profit community initiative. CloudLinux already has the assets, infrastructure, and experience to carry out the mission, and we promise to be open about the process of developing Project Lenix”.

    See CentOS

  • CentOS 6 Invalid release/repo/arch combination

    CentOS 6 Invalid release/repo/arch combination

    When i run yum update on a CentOS 6 server, i get error “Invalid release/repo/arch combination/”.

    CentOS 6 invalid release

    This error is due to CentOS reaching its End Of Life and no longer supported.

    What you need to do is upgrade your server to the latest supported CentOS versions like CentOS 7 or CentOS 8. Converting to Oracle Linux 6 is another option, it is binary compatible with CentOS/RHEL 6, offers extended support until Jun 2024 and Indefinite Sustaining Support. If you want to convert CentOS 6 to Oracle Linux, see How to Migrate CentOS to Oracle Linux.

    If you just need to fix the error, you need to go through each .repo file in the folder

    /etc/yum.repos.d/
    

    Comment out lines like

    mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
    

    Replace it with centos 6 vault repo URL

    baseurl=https://vault.centos.org/centos/$releasever/os/$basearch/
    

    You can find modified yum repository files at

    https://github.com/serverok/centos6-repo

    You can replace your existing repository files inside /etc/yum.repos.d folder with files in the above git repository with following commands.

    cd /etc
    mv yum.repos.d yum.repos.d-old
    git clone https://github.com/serverok/centos6-repo.git yum.repos.d
    

    If you get git not found error, you may need to manually download files from the repo and place in the directory /etc/yum.repos.d/.

    After this, you will be able to update your system. If you have any other repo installed, you can copy it from yum.repos.d-old folder to make it active again.

    Here is the updated CentOS-Base.repo file

    https://raw.githubusercontent.com/serverok/centos6-repo/main/CentOS-Base.repo

    # CentOS-Base.repo
    #
    # The mirror system uses the connecting IP address of the client and the
    # update status of each mirror to pick mirrors that are updated to and
    # geographically close to the client.  You should use this for CentOS updates
    # unless you are manually picking other mirrors.
    #
    # If the mirrorlist= does not work for you, as a fall back you can try the 
    # remarked out baseurl= line instead.
    #
    #
    
    [base]
    name=CentOS-$releasever - Base
    baseurl=https://vault.centos.org/centos/$releasever/os/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    
    #released updates 
    [updates]
    name=CentOS-$releasever - Updates
    baseurl=https://vault.centos.org/centos/$releasever/updates/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    
    #additional packages that may be useful
    [extras]
    name=CentOS-$releasever - Extras
    baseurl=https://vault.centos.org/centos/$releasever/extras/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    
    #additional packages that extend functionality of existing packages
    [centosplus]
    name=CentOS-$releasever - Plus
    baseurl=https://vault.centos.org/centos/$releasever/centosplus/$basearch/
    gpgcheck=1
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    
    #contrib - packages by Centos Users
    [contrib]
    name=CentOS-$releasever - Contrib
    baseurl=https://vault.centos.org/centos/$releasever/contrib/$basearch/
    gpgcheck=1
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    

    After updating yum repo, run

    yum clean all
    yum makecache
    
  • Install Xfce VNC remote desktop on CentOS 7

    Install Xfce VNC remote desktop on CentOS 7

    Xfce is a lightweight linux desktop environment. You can install Xfce on a remote server or virtual machine, connect to it using VNC to use it as a desktop.

    xfce remote desktop

    To install Xfce, enable EPEL repo

    yum install -y epel-release
    

    Install Xfce

    yum groupinstall Xfce
    

    You can see other groups available with command “yum grouplist”.

    Insall vnc server

    yum install -y tigervnc-server
    

    Creating User

    We need to create a normal linux user to use with Xfce. Using it as root is not recommended.

    To create user, run

    useradd -m --shell /bin/bash serverok
    

    Replace “serverok” with whatever username you want to use.

    Configure VNC server

    Change to the user we created before

    su - serverok
    

    To create initial vnc config files and set password, run

    vncserver -fg
    

    We used -fg option to keep vncserver in forground. vcnserver will ask you to set password, this will be used to connect to VNC server.

    When i run “vncserver -fg” on CentOS, it exited with error. If it keep running, press CTRL+C to stop vnc server.

    If you run with out -fg option, you can stop vnc server with command

    vncserver -kill :1
    

    Edit file

    vi /home/serverok/.vnc/xstartup
    

    Replace contents of this file with following

    #!/bin/sh
    
    unset SESSION_MANAGER
    unset DBUS_SESSION_BUS_ADDRESS
    /etc/X11/xinit/xinitrc
    /bin/startxfce4
    

    Now you can start vncserver manually with command

    vncserver -fg
    

    You will be able to connect to VNC server with YOUR_SERVER_IP:1

    Auto start VNC server

    Following need to be done as user root.

    Edit file

    vi /usr/lib/systemd/system/[email protected]
    

    Find

    ExecStart=/usr/bin/vncserver_wrapper  %i
    

    Replaced with

    ExecStart=/usr/bin/vncserver_wrapper serverok %i
    

    reload systemctl

    systemctl daemon-reload
    

    Enable vncserver to start on boot

    systemctl enable vncserver@:1.service
    

    Start vncserver

    systemctl start vncserver@:1.service
    

    Open port in firewall

    You need to open VNC port in firewall. vnc ports start at 5900, for :1, it will be 5901.

    [root@centos7 ~]# netstat -lntp | grep vnc
    tcp        0      0 0.0.0.0:5901            0.0.0.0:*               LISTEN      1951/Xvnc           
    tcp        0      0 0.0.0.0:6001            0.0.0.0:*               LISTEN      1951/Xvnc           
    tcp6       0      0 :::5901                 :::*                    LISTEN      1951/Xvnc           
    tcp6       0      0 :::6001                 :::*                    LISTEN      1951/Xvnc           
    [root@centos7 ~]# 
    

    If you are using firewalld, you can open port 5901 with

    firewall-cmd --zone=public --add-port=5901/tcp
    firewall-cmd --zone=public --add-port=5901/tcp --permanent
    

    firewall-cmd command is run 2 times as first command only make changes in current session. second command with –permanent option make changes permanent, but that only happens after you reload firewalld or reboot server. Running command 2 times make the changes permanent and apply changes to current session.

    See VNC, Remote Desktop

  • Disable SELinux on CentOS/RHEL

    To disable SELinux

    Method 1

    sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
    setenforce 0
    

    Method 2

    edit file

    vi /etc/selinux/config
    

    Find

    SELINUX=enforcing
    

    Replace with

    SELINUX=disabled
    

    Reboot the server with

    reboot
    

    You can disable selinux for current session by running command

    setenforce 0
    

    See SELinux

  • Install Latest MariaDB on CentOS

    Install Latest MariaDB on CentOS

    To install the latest MariaDB on the CentOS server, go to

    https://mariadb.org/download/?t=repo-config

    On this page, select CentOS, then select your CentOS version and MariaDB version you need.

    MariaDB install CentOS

    Below you will see instructions for your specific version of CentOS.

    Install MariaDB 10.5 on CentOS 7

    CentOS 7 by default provide MariaDB 5.5. To install MariaDB 10.5

    Create file

    vi /etc/yum.repos.d/MariaDB.repo
    

    Add

    # MariaDB 10.5 CentOS repository list - created 2020-11-05 08:27 UTC
    # http://downloads.mariadb.org/mariadb/repositories/
    [mariadb]
    name = MariaDB
    baseurl = http://yum.mariadb.org/10.5/centos7-amd64
    gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
    gpgcheck=1
    

    Now you can install MariDB with command

    yum install MariaDB-server MariaDB-client
    

    To start MariaDB, run

    systemctl start mariadb
    

    You can replace start with stop/restart/status. To auto start MariaDB on boot, run

    systemctl enable mariadb
    

    See MySQL

  • Prometheus init script for CentOS 6

    Create init file.

    touch /etc/rc.d/init.d/prometheus
    chmod 755 /etc/rc.d/init.d/prometheus
    vi /etc/rc.d/init.d/prometheus
    

    Add following

    #!/bin/bash
    #
    # /etc/rc.d/init.d/prometheus
    #
    # Prometheus monitoring server
    #
    #  chkconfig: 2345 20 80 Read
    #  description: Prometheus monitoring server
    #  processname: prometheus
    
    # Source function library.
    . /etc/rc.d/init.d/functions
    
    PROGNAME=prometheus
    PROG=/usr/hostonnet/prometheus/$PROGNAME
    USER=prometheus
    LOGFILE=/var/log/prometheus.log
    DATADIR=/usr/hostonnet/prometheus/data
    LOCKFILE=/var/run/$PROGNAME.pid
    CONFIG_FILE=/usr/hostonnet/prometheus/prometheus.yml
    ALERT_MGR_URL=localhost:9093
    
    start() {
        echo -n "Starting $PROGNAME: "
        cd /usr/hostonnet/prometheus/
        #daemon --user $USER --pidfile="$LOCKFILE" "$PROG -config.file $CONFIG_FILE -storage.local.path $DATADIR -alertmanager.url $ALERT_MGR_URL &>$LOGFILE &"
        daemon --user $USER --pidfile="$LOCKFILE" "$PROG -config.file $CONFIG_FILE -storage.local.path $DATADIR &>$LOGFILE &"
        echo $(pidofproc $PROGNAME) >$LOCKFILE
        echo
    }
    
    stop() {
        echo -n "Shutting down $PROGNAME: "
        killproc $PROGNAME
        rm -f $LOCKFILE
        echo
    }
    
    
    case "$1" in
        start)
        start
        ;;
        stop)
        stop
        ;;
        status)
        status $PROGNAME
        ;;
        restart)
        stop
        start
        ;;
        reload)
        echo "Sending SIGHUP to $PROGNAME"
        kill -SIGHUP $(pidofproc $PROGNAME)
        ;;
        *)
            echo "Usage: service prometheus {start|stop|status|reload|restart}"
            exit 1
        ;;
    esac
    

    Create User For Prometheus

    groupadd -r prometheus
    useradd -r -g prometheus -s /sbin/nologin -d /usr/hostonnet/prometheus/ -c "prometheus Daemons" prometheus
    chown -R prometheus:prometheus /usr/hostonnet/prometheus/
    chown prometheus:prometheus /var/log/prometheus.log
    
    

    Run prometheus on Boot

    chkconfig --add prometheus
    chkconfig prometheus on
    

    Verify it is enabled

    [root@backup ~]# chkconfig --list | grep prome
    prometheus     	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    [root@backup ~]# 
    

    “3:on” will start prometheus on run level 3, that is normal boot.

    Start Prometheus

    [root@backup ~]# service prometheus start
    Starting prometheus:                                       [  OK  ]
    [root@backup ~]# 
    

    See Monitor Server with Prometheus and Grafana

  • rpmquery

    rpmquery command allow you to check if a specific rpm package installed on your computer.

    rpmquery PKG_NAME
    

    Example

    root@server20 [~]# rpmquery nmap
    nmap-6.40-19.el7.x86_64
    root@server20 [~]# 

    See rpm

  • Install PHP 5.6 on CentOS 7

    To install PHP 5.6 on CentOS 7, enable EPEL repo and remi repo

    yum install epel-release -y
    rpm -ivh https://rpms.remirepo.net/enterprise/remi-release-7.rpm
    

    Install yum-utils and enable remi-php56 repo

    yum install yum-utils
    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
    
  • yum commands

    Install a software with yum

    yum install PKG_NAME
    

    Uninstall a software

    yum remove 
    

    Example for installing php and GD

    yum install php php-gd
    

    When you need to update all install software, run

    yum update
    

    List all available software

    yum list available
    yum list available "software-name"
    

    List all installed software

    yum list installed
    

    See yum

  • EPEL – Extra Packages for Enterprise Linux

    EPEL (Extra Packages for Enterprise Linux) provide additional software for CentOS and RHEL.

    You can find more information about EPEL at

    http://fedoraproject.org/wiki/EPEL

    On CentOS 7/8, you can enable EPEP repo with command

    yum instal epel-release
    

    Or just download rpm package from the site and install.

    RHEL/CentOS 6:

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

    RHEL/CentOS 7:

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

    RHEL/CentOS 8:

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

    See CentOS, yum