Category: CentOS

  • Install elasticsearch on CentOS 7

    To install elasticsearch, first install java

    yum -y install java-1.8.0-openjdk
    

    Import key

    rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
    

    Create file

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

    Paste following

    [elasticsearch]
    name=Elasticsearch repository for 7.x packages
    baseurl=https://artifacts.elastic.co/packages/7.x/yum
    gpgcheck=1
    gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
    enabled=0
    autorefresh=1
    type=rpm-md
    

    Install elasticsearch

    yum install --enablerepo=elasticsearch elasticsearch
    

    Set elastic search to start on boot

    systemctl enable elasticsearch
    

    To start/stop/status

    systemctl stop elasticsearch.service
    systemctl start elasticsearch.service
    systemctl status elasticsearch.service
    

    To see logs

    tail -f /var/log/elasticsearch/elasticsearch.log
    

    ElasticSearch runs on port 9200

    [root@server ~]# netstat -lntp | grep java
    tcp6       0      0 127.0.0.1:9200          :::*                    LISTEN      1289/java           
    tcp6       0      0 ::1:9200                :::*                    LISTEN      1289/java           
    tcp6       0      0 127.0.0.1:9300          :::*                    LISTEN      1289/java           
    tcp6       0      0 ::1:9300                :::*                    LISTEN      1289/java           
    [root@server ~]# 
    

    If you get error starting elasticsearch, check Elasticsearch failed to start on CentOS 7

    If you have a previous installation, make sure you delete left over files before you install differnt version of elasticsearch. I removed following files/folders when i had to downgrade elasticsearch.

    /etc/sysconfig/elasticsearch.rpmsave
    /var/lib/elasticsearch
    /var/log/elasticsearch
    

    See elasticsearch

  • yum [Errno 5] [Errno 2] No such file or directory

    When running yum update on CentOS 7 server, i get following error

    [root@server2 yum.repos.d]# yum update curl
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    Resolving Dependencies
    --> Running transaction check
    ---> Package curl.x86_64 0:7.29.0-54.el7 will be updated
    ---> Package curl.x86_64 0:7.29.0-57.el7_8.1 will be an update
    --> Processing Dependency: libcurl = 7.29.0-57.el7_8.1 for package: curl-7.29.0-57.el7_8.1.x86_64
    --> Running transaction check
    ---> Package libcurl.x86_64 0:7.29.0-54.el7 will be updated
    --> Processing Dependency: libcurl = 7.29.0-54.el7 for package: libcurl-devel-7.29.0-54.el7.x86_64
    ---> Package libcurl.x86_64 0:7.29.0-57.el7_8.1 will be an update
    --> Running transaction check
    ---> Package libcurl-devel.x86_64 0:7.29.0-54.el7 will be updated
    ---> Package libcurl-devel.x86_64 0:7.29.0-57.el7_8.1 will be an update
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ============================================================================================================================================================================================================
     Package                                            Arch                                        Version                                                  Repository                                    Size
    ============================================================================================================================================================================================================
    Updating:
     curl                                               x86_64                                      7.29.0-57.el7_8.1                                        updates                                      271 k
    Updating for dependencies:
     libcurl                                            x86_64                                      7.29.0-57.el7_8.1                                        updates                                      223 k
     libcurl-devel                                      x86_64                                      7.29.0-57.el7_8.1                                        updates                                      303 k
    
    Transaction Summary
    ============================================================================================================================================================================================================
    Upgrade  1 Package (+2 Dependent packages)
    
    Total download size: 796 k
    Is this ok [y/d/N]: y
    Downloading packages:
    No Presto metadata available for updates
    
    
    Error downloading packages:
      libcurl-7.29.0-57.el7_8.1.x86_64: [Errno 5] [Errno 2] No such file or directory
      libcurl-devel-7.29.0-57.el7_8.1.x86_64: [Errno 5] [Errno 2] No such file or directory
      curl-7.29.0-57.el7_8.1.x86_64: [Errno 5] [Errno 2] No such file or directory
    
    [root@server2 yum.repos.d]#
    

    Someone had tried to install differnt version of python on this server. That caused this problem.

    When i run urlgrabber-ext-down, i get error saying python missing.

    [root@server2 ~]# /usr/libexec/urlgrabber-ext-down
    -bash: /usr/libexec/urlgrabber-ext-down: /usr/bin/python: bad interpreter: No such file or directory
    [root@server2 ~]#
    

    Problem fixed by creating symlink

    ln -s /usr/bin/python2.7 /usr/bin/python
    

    See yum

  • Install bind in CentOS 7

    bind is a DNS server. To install bind on CentOS 7, run

    yum install bind bind-utils -y
    

    Enable bind to start on boot

    systemctl enable named
    

    Start bind

    systemctl start named
    

    You can see status with

    systemctl status named
    

    Setup firewall

    You need to allow DNS ports UDP/TCP 53 in firewall. On CentOS 7, you can run

    firewall-cmd --zone=public --permanent --add-service=dns
    firewall-cmd --reload
    

    Configure bind

    By default bind only listens to local IP, to make it accessable from outside, you need to edit named.conf

    vi /etc/named.conf
    

    Find

            listen-on port 53 { 127.0.0.1; };
            listen-on-v6 port 53 { ::1; };
    

    Comment out those two lines by adding # at start of the lines.

            #listen-on port 53 { 127.0.0.1; };
            #listen-on-v6 port 53 { ::1; };
    

    We need our DNS server access query from anyone on internet. For this, find

            allow-query     { localhost; };
    

    Replace with

            allow-query     { any; };
    

    Since we only want our DNS server resolve domains hosted on our server, disable recursion.

    Find

            recursion yes;
    

    Replace with

            recursion no;
    

    Now restart bind with

    systemctl restart bind
    

    Adding Domain to bind

    To server a domain, you need to add the domain to bind. For this edit file

    vi /etc/named.conf
    

    at end of the file, add

    zone "DOMAIN.EXTN" IN {
       type master;
       file "/var/named/DOMAIN.EXTN.zone";
       allow-update { none; };
    };
    

    Now create zone file

    vi /var/named/DOMAIN.EXTN.zone
    

    Add following

    $TTL            86400
    @                 IN SOA            DOMAIN.EXT.  admin.DOMAIN.EXT. (
    100     ; serial
    1H      ; refresh
    1M      ; retry
    1W      ; expiry
    1D )    ; minimum
    @                   IN NS             ns1.DOMAIN.EXT.
    @                   IN A                 YOUR_IP_ADDR_HERE
    ns1                 IN A                 YOUR_IP_ADDR_HERE
    @                   IN MX   10      mail.DOMAIN.EXT.
    mail                IN A                 YOUR_IP_ADDR_HERE
    www                 IN A                 YOUR_IP_ADDR_HERE
    

    Restart bind

    vi /var/named/DOMAIN.EXTN.zone
    

    You can verify domain is resolving with command

    nslookup DOMAIN.EXT SERVER_IP_HERE
    

    See bind

  • Install Python 3.8 on CentOS 6 from source

    To install Python 3.8 on CentOS, you need to install OpenSSL as the one installed by CentOS from yum is very old.

    cd /usr/local/src
    wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz
    tar xvf openssl-1.1.1g.tar.gz
    cd openssl-1.1.1g
    ./config --prefix=/usr/serverok/openssl --openssldir=/usr/serverok/openssl no-ssl2
    make
    make install
    

    Now edit file

    vi ~/.bash_profile
    

    at end of the file, add

    export PATH=/usr/serverok/openssl/bin:$PATH
    export LD_LIBRARY_PATH=/usr/serverok/openssl/lib
    export LC_ALL="en_US.UTF-8"
    export LDFLAGS="-L/usr/serverok/openssl/lib -Wl,-rpath,/usr/serverok/openssl/lib"
    

    Make the settings active with command

    source ~/.bash_profile
    

    Now we can install Python 3.8 with

    cd /usr/local/src
    wget https://www.python.org/ftp/python/3.8.4/Python-3.8.4.tar.xz
    tar xvf Python-3.8.4.tar.xz
    cd /usr/local/src/Python-3.8.4
    make clean && make distclean
    ./configure --enable-optimizations  --with-openssl=/usr/serverok/openssl/
    make altinstall
    

    Now python 3.8 will be available in your system under /usr/local/bin

    root@server12:~# python3.8 --version
    Python 3.8.4
    root@server12:~# which python3.8
    /usr/local/bin/python3.8
    root@server12:~# 
    
  • yum list all available packages in a repo

    To list all packages available on a specific repo, run

    yum  --disablerepo="*" --enablerepo="REPO_NAME_HERE" list available
    
    
    You can get list of all available repos with command
    
    
    yum repolist
    

    Example:

    yum list available

    yum  --disablerepo="*" --enablerepo="litespeed" list available
    

    This command list all packages available in repo "litespeed"

  • Install PHP 7 on CentOS VestaCP

    To install PHP 7. you need to first enable epel and remi repo.

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

    Remove existing PHP

    yum -y remove php
    

    Install PHP 7.3

    yum --enablerepo=remi-php73 install php73-php php73-php-mbstring php73-php-mysqlnd php73-php-gd php73-php-fpm php73-php-intl php73-php-cli php73-php-xml php73-php-opcache php73-php-pdo php73-php-gmp php73-php-process php73-php-pecl-imagick php73-php-devel
    

    start php-fpm

    service php-fpm stop
    service php73-php-fpm start
    

    Set php 7.3 as default PHP for cli

    rm /usr/bin/php
    ln -s /usr/bin/php73 /usr/bin/php
    

    Restart apache

    service httpd restart
    
  • rpmdb DB_RUNRECOVERY: Fatal error, run database recovery

    When running yum update on a CentOS server, i get following error.

    [root@ip-172-30-0-39 ~]# yum update
    error: rpmdb: BDB0113 Thread/process 12797/46913889995840 failed: BDB1507 Thread died in Berkeley DB library
    error: db5 error(-30973) from dbenv->failchk: BDB0087 DB_RUNRECOVERY: Fatal error, run database recovery
    error: cannot open Packages index using db5 -  (-30973)
    error: cannot open Packages database in /var/lib/rpm
    CRITICAL:yum.main:
    
    Error: rpmdb open failed
    [root@ip-172-30-0-39 ~]#
    

    To fix it, run

    rm -f /var/lib/rpm/__db.00*
    
  • rpm verify packages

    To verify a package installed on system, you can use

    rpm -V PKG_NAME

    Example

    [root@hello-1 curl-curl-7_69_0]# rpm -V bind
    S.5....T.  c /etc/named.conf
    [root@hello-1 curl-curl-7_69_0]# 

    Here bind package have /etc/named.conf file modified.

    To verify all packages on system, run

    rpm -Va

    Back to rpm

  • CentOS 7 resolv.conf make changes permanent

    On rebooting the CentOS 7 server, changes made to resolv.conf is lost. This is because one of the network interface is configured to use DNS server.

    [root@server ~]# grep DNS /etc/sysconfig/network-scripts/ifcfg-*
    /etc/sysconfig/network-scripts/ifcfg-eno1:DNS1="127.0.0.1"
    [root@server ~]# 

    To fix, edit

    vi /etc/sysconfig/network-scripts/ifcfg-eno1

    Remove the line

    DNS1="127.0.0.1"

    Now NetworkManager will not modify /etc/resolv.conf file on boot.

    Or you can set valid DNS servers in network config file like

    [root@server ~]# cat /etc/sysconfig/network-scripts/ifcfg-eno1 | grep DNS
    DNS1="1.1.1.1"
    DNS2="8.8.8.8"
    [root@server ~]# 

    If your network configuration use DHCP, set set PEERDNS=no.

    BOOTPROTO=dhcp
    PEERDNS=no

    Another solution is to make file immutable with

    chattr +i /etc/resolv.conf

    Related Posts

    Domain Resolver

  • Install Pure-FTPd on CentOS with Virtual Users

    To install Pure-FTPd on CentOS, run

    yum install -y pure-ftpd
    

    Edit configuration file

    vi /etc/pure-ftpd/pure-ftpd.conf
    

    To disable anonymous FTP, find

    NoAnonymous                  no
    

    Replace with

    NoAnonymous                  yes
    

    To enable Virtual Users, find

    # PureDB                        /etc/pure-ftpd/pureftpd.pdb
    

    Uncomment the line.

    PureDB                        /etc/pure-ftpd/pureftpd.pdb
    

    To Allow Apache user to login via FTP, find

    MinUID                      1000
    

    Replace with

    MinUID                      47
    

    I set MinUID value to 47, as apache user have UID/GID of 48. By setting MinUID below that apache user should be able to login.

    Set pureftpd to start on Boot

    systemctl enable pure-ftpd
    

    Restart pure-ftpd

    systemctl start pure-ftpd
    

    Create a Virual User

    To create a virtual user, run

    pure-pw useradd  USER_NAME_HERE -u apache -g apache -d /var/www/html/
    

    It will ask you to enter password two times.

    Now run

    pure-pw mkdb
    systemctl restart pure-ftpd
    

    Change Password of an existing Virual User

    pure-pw passwd USER_NAME_HERE
    

    It will ask you to enter new password.

    Rebuild password database and restart pure-ftpd with

    pure-pw mkdb
    systemctl restart pure-ftpd
    

    Related Posts

    Install pureftpd on Ubuntu

    pureftpd

  • Install vim from source on CentOS

    To install vim from source on the CentOS server, run

    yum -y install  ncurses-devel
    cd /usr/local/src
    wget https://github.com/vim/vim/archive/master.zip	
    unzip master.zip
    cd vim-master/src/
    ./configure
    make
    make install

    This will install the latest version of Vim. You can start it with the command

    vim
    

    To get it work with “vi” command, i removed preinstalled vim editor with command

    rpm -e --nodeps  vim-minimal

    Now create a symlink with

    ln -s /usr/local/bin/vim /bin/vi
  • Install clamav Antivirus on CentOS 7

    ClamAV is provided by the EPEL repo. Install epel repo

    yum install -y epel-release
    

    Install ClamAV with

    yum install clamav
    

    Back to ClamAV