How To Install and Enable EPEL Repo on CentOS

Install and Enable EPEL Repo on CentOS

EPEL(Extra Packages for Enterprise Linux) is a repo developed by Fedora project to ensure that there is a quality 3rd party packages available for enterprise users such as people who are using RHEL, CentOS, Oracle Linux and Scientific Linux. EPEL is a community effort to create a repository of high-quality add-on free software packages for RHEL-based distributions. Once you set up EPEL repository, you can use yum command to install any of close to 7,000 EPEL packages.

This article assumes you have at least basic knowledge of linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple. I will show you through the step by step installation and enable EPEL repository on CentOS 5, CentOS 6 and CentOS 7.

Install and Enable EPEL Repo on CentOS 5, CentOS 6 and CentOS 7

First, you need to enable EPEL repository on your system. You don’t need to configure this repository manually in your yum. Instead, download the following package and install it, which will enable the EPEL repository on your system.

  • CentOS 7 64 Bit
## RHEL/CentOS 7 64-Bit ##
# wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm
# rpm -ivh epel-release-7-8.noarch.rpm
  • CentOS 6 64 Bit
## RHEL/CentOS 6 64-Bit ##
# wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm
  • CentOS 6 32 Bit
## RHEL/CentOS 6 32-Bit ##
# wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm
  • CentOS 5 64 Bit
## RHEL/CentOS 5 64-Bit ##
# wget http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
# rpm -ivh epel-release-5-4.noarch.rpm
  • CentOS 5 32 Bit
## RHEL/CentOS 5 32-Bit ##
# wget http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
# rpm -ivh epel-release-5-4.noarch.rpm

To verify that EPEL repository has been set up successfully, run the following command to list all available repositories on your system:

 # <code>yum repolist

You Might Also Like: How To Install Nginx Web Server On CentOS

How To Install Nginx With GeoIP Module

Install Nginx With GeoIP Module

Nginx GeoIP module for country and city geo targeting can be installed in a few easy steps. It brings you a geo targeting layer allowing you to show some parts of your websites, or even split traffic according to the geographical location of the end users. By default, when you install modules from yum, nginx will not come with GeoIP module (This is module: HttpGeoipModule), so we will install from source and the active the module. This article assumes you have at least basic knowledge of linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple.

In this tutorial we will show you how to install and configuration of Nginx With GeoIP Module on your Linux server.

Install Nginx With GeoIP Module

Step 1. First install require package for compiling:

 yum install gcc-c++ pre pcre-devel zlib zlib-devel -y

Step 2. Download the latest stable version of Nginx from here and build it with GeoIP module support.

## cd /opt/nginx/
## wget http://nginx.org/download/nginx-1.6.2.tar.gz
## tar -zxf nginx-1.6.2.tar.gz
## cd nginx-1.6.2/
## ./configure
--prefix=/etc/nginx \
--sbin-path=/etc/nginx/sbin/nginx \
--conf-path=/etc/nginx/conf/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/ninx.lock \
--user=nobody \
--with-http_geoip_module \
--with-http_gzip_static_module \
--with-http_secure_link_module \
--without-mail_pop3_module \
--without-mail_imap_module \
--without-mail_smtp_module \
--without-http_ssi_module

## make
## make install


Step 3. Create an init script for Nginx.

get -O /etc/init.d/nginx https://raw.githubusercontent.com/Fleshgrinder/nginx-sysvinit-script/master/nginx
chmod 0755 /etc/init.d/nginx
chown root:root /etc/init.d/nginx

Step 4. Finally, start Nginx.

 service nginx start

Step 5. Install GeoIP library via yum

# For CentOS 6 – 64-bit

rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm 

# yum install geoip geoip-devel -y

After successful installation, the library will be stored in: /usr/share/GeoIP/GeoIP.dat
For the latest updates can be downloaded at: http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz

Configure Nginx

  • Configure on main file:
#nano /etc/nginx/conf/nginx.conf

http {
[...]
geoip_country /usr/share/GeoIP/GeoIP.dat;
map $geoip_country_code $allowed_country {
default yes;
CN no;
}
[...]
}
  • Configure nginx virtualhost:
#nano /etc/nginx/conf.d/yourdomain.conf

server {
[...]
if ($allowed_country = no) {
return 444;
# # This means the server will stop processing, returns error 444 (The connection was reset),
# # And ignore always sending the response header.
# # Replace 444 by 403 if you want
}
[...]
}

The above configuration will accept all IP and banned only from China IP (CN). About Code of the country in GeoIP database you can refer here: http://dev.maxmind.com/geoip/legacy/codes/iso3166/

Congratulation’s! You have successfully installed Nginx With GeoIP Module. Thanks for using this tutorial for installing Nginx With GeoIP Module on Linux system. For additional help or useful information, we recommend you to check the official Nginx web site.

You Might Also Like: How To Install Nginx Web Server On CentOS

How To Install and Configure HAproxy on CentOS 6

Install and Configure HAproxy on CentOS 6

HAProxy is a free and open-source Linux application used for load balancing network traffic. This article assumes you have at least basic knowledge of linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple. I will show you through the step by step installation of HAproxy on CentOS 6.x from source.

In this tutorial we will show you how to install and configuration of HAProxy on your CentOS 6 server.

Install and Configure HAproxy on CentOS 6

Step 1. First add yum repository your system.

HAProxy isn’t available in the default repositories for CentOS. In order for us to be able to install it, we need to either compile it from source (preferred) or add the EPEL repository to our server and install it using Yum.

#CentOS 6 – 32-bit
 rpm -Uvh http://mirror.overthewire.com.au/pub/epel/6/i386/epel-release-6-8.noarch.rpm

#CentOS 6 – 64-bit
 rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

Step 2. Install HAProxy using Yum.

 yum install haproxy

Step 3. Configuring HAProxy.

We have to modify the configuraion file of haproxy i.e. /etc/haproxy/haproxy.cfg as per our requirement. (Change this configuration as your network requirements). For more configuration details check this url.

#nano /etc/haproxy/haproxy.cfg global

log 127.0.0.1 local0
log 127.0.0.1 local1 debug
maxconn 45000 # Total Max Connections. This is dependent on ulimit
user haproxy
group haproxy
daemon

defaults
timeout server 86400000
timeout connect 86400000
timeout client 86400000
timeout queue 1000s

# Configuration for HTTP site
listen http_wpcademy 192.168.2.102:80
mode http
balance roundrobin # Load Balancing algorithm
option httpchk
option forwardfor
server server1 192.168.2.100:80 weight 1 maxconn 512 check
server server2 192.168.2.101:80 weight 1 maxconn 512 check

# Configuration for HTTPS site listen  
https_wpcademy 192.168.2.102:443
mode tcp
balance source# Load Balancing algorithm
reqadd X-Forwarded-Proto:\ http
server server1 192.168.2.100:443 weight 1 maxconn 512 check
server server2 192.168.2.101:443 weight 1 maxconn 512 check

listen stats 192.168.2.102:31337
mode http
option httpclose
balance roundrobin
stats uri /
stats realm Haproxy\ Statistics
stats refresh 5s
stats auth admin:passwd123

Step 4. Once you have configured HAProxy, its time to start the service.

service haproxy start
chkconfig haproxy on

Step 5. Now you will able to browse your applicaiton using the IP of the haproxy server. For haproxy Status dashboard you have to browse the URL: http://192.168.2.102:31337. It will ask you for the username and password. Use the username and password you defined on the configuraion file as “stats auth”.

Congratulation’s! You have successfully installed HAProxy. Thanks for using this tutorial for installing HAProxy on CentOS 6 system. For additional help or useful information, we recommend you to check the official HAProxy web site.

You Might Also Like: How To Install Nginx Web Server On CentOS

How To Install ClamAV on CentOS 6

Install ClamAV on CentOS 6

ClamAV is an open source (GPL) antivirus engine designed for detecting viruses, malware and other malicious threats on Linux.  It’s easy to use and best for Linux based Web & Mail server. In this article, I will show you through the step by step installation of ClamAV on CentOS 6.x from source.

In this tutorial we will show you how to install and configuration of ClamAV on your CentOS 6 server.

Install ClamAV on CentOS 6

Step 1. First add yum repository your system.

The EPEL repo is enabled by simply installing an RPM. Please use the command below to install the EPEL repository on your CentOS server.

#CentOS 6 – 32-bit
rpm -Uvh http://mirror.overthewire.com.au/pub/epel/6/i386/epel-release-6-8.noarch.rpm

#CentOS 6 – 64-bit
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm


Step 2.
Install required ClamAV packages.

 yum install clamav clamd

Step 3. Start the clamd service on system boot.

chkconfig clamd on
service clamd start

Update ClamAV’s signatures:

 freshclam

Step 4. Configuring daily scan.

In this example, I will configure a cronjob to scan the /home/ directory every day:

 nano /etc/cron.daily/clamav_scan

Add following piece of code into clamav_scan file.

#!/bin/bash
SCAN_DIR="/home"
LOG_FILE="/var/log/clamav/manual_clamscan.log"
/usr/bin/clamscan -i -r $SCAN_DIR >> $LOG_FILE

Give our cron script executable permissions:

 chmod +x /etc/cron.daily/clamav_scan

Congratulation’s! You have successfully installed ClamAV. Thanks for using this tutorial for installing ClamAV in CentOS 6 system. For additional help or useful information, we recommend you to check the official ClamAV web site.

You Might Also Like: How To Install Rar/Unrar on CentOS

How To Install PPTP VPN on CentOS 6

Install PPTP VPN on CentOS 6

The Point-to-Point Tunneling Protocol (PPTP) is a method for implementing virtual private networks. PPTP uses a control channel over TCP and a GRE tunnel operating to encapsulate PPP packets. The PPTP specification does not describe encryption or authentication features and relies on the Point-to-Point Protocol being tunneled to implement security functionality. We use PPTP because it is supported natively on almost all devices, Windows, Linux, Android, iOS and Mac OS.

This article assumes you have at least basic knowledge of linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple. Here is the steps to install PPTP VPN on CentOS 6.

In this tutorial we will show you how to install and configuration of PPTP VPN on your CentOS 6 server.

Install PPTP VPN on CentOS 6

Step 1. First install pptpd

yum install ppp iptables nano
cd /usr/local/src

#For 64bit OS
wget http://poptop.sourceforge.net/yum/stable/packages/pptpd-1.4.0-1.el6.x86_64.rpm
rpm -Uhvpptpd-1.4.0-1.el6.x86_64.rpm

#For 32bit os
wget http://poptop.sourceforge.net/yum/stable/packages/pptpd-1.4.0-1.el6.i686.rpm
rmp -Uhv pptpd-1.4.0-1.el6.i686.rpm

Step 2. Setup pptpd

Edit IP setttings in /etc/pptpd.conf:

#nano /etc/pptpd.conf

localip 192.168.0.1 # your VPS/Dedicated Server IP address 
remoteip 192.168.0.101-200

And the following settings to /etc/ppp/options.pptpd:

ms-dns 8.8.8.8
ms-dns 4.4.4.4

Step 3. Create user to access the VPN server

Add user account in/etc/ppp/chap-secrets (assign username and password):

#nano /etc/ppp/chap-secrets

vpn pptpd vpnpassword *

Step 4. Enable network forwarding in /etc/sysctl.conf

#nano /etc/sysctl.conf

net.ipv4.ip_forward = 1

#To make the changes to sysctl.conf take effect, use the following command.

sysctl -p

Step 5. Setup iptables

You need to add the following iptables rules in order to open the correct ports and properly forward the data packets:

iptables -A INPUT -i eth0 -p tcp --dport 1723 -j ACCEPT
iptables -A INPUT -i eth0 -p gre -j ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Step 6. Start PPTP VPN server

service pptpd restart
chkconfig pptpd on

Congratulation’s! You have successfully installed PPTP VPN. Thanks for using this tutorial for installing PPTP VPN on CentOS 6 system. For additional help or useful information, we recommend you to check the official PPTP VPN web site.

How To Install Htop on CentOS 6

Install Htop on CentOS 6

Htop is an interactive and real-time system-monitor process-viewer written for Linux. It is designed to replace the Unix program top. It shows a frequently updated list of the processes running on a computer, normally ordered by the amount of CPU usage. Unlike top, htop provides a full list of processes running, instead of the top resource-consuming processes. Htop uses color and gives visual information about processor, swap and memory status. It is a must have when you want to monitor the resources of your linux server over an ssh connection for example.

This article assumes you have at least basic knowledge of linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple. Here is the steps to install ‘htop’ on CentOS 6.

Install Htop on CentOS 6

Step 1. First add yum repository your system.

wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
rpm -ihv rpmforge-release*.rf.i686.rpm

Step 2. Install htop using yum command:

 yum install htop

Step 3. After installation, launch htop by entering:

 htop

Install htop from source code

# wget http://downloads.sourceforge.net/project/htop/htop/1.0.2/htop-1.0.2.tar.gz
# tar -xvf htop-1.0.2.tar.gz
# cd htop-1.0.2
# ./configure
# make
# make install

htop-process-monitoring-tool

Congratulation’s! You have successfully installed htop. Thanks for using this tutorial for installing htop process monitoring tool on CentOS 6 system. For additional help or useful information, we recommend you to check the official htop web site.

You Might Also Like: How To Install Nginx Web Server On CentOS

How To Fix 502 Bad Gateway Error on Nginx

Fix 502 Bad Gateway Error on Nginx

If you run a Nginx web server you may have already encountered the annoying 502 bad gateway errors. This is pretty common error, are generated most probably by the PHP or  FastCGI buffer and timeouts settings. This tutorial shows you how to fix nginx 502 bad gateway on the nginx webserver. This post shows how to fix this problem, and the configuration option to prevent it occurring again on reboot.

This article assumes you have at least basic knowledge of linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges. I will show you through the step by step solve 502 bad gateway error on Nginx web server.

In this tutorial we will show you how to fix 502 bad gateway error on Nginx web server.

Fix 502 Bad Gateway Error on Nginx

Method 1. Changes in Nginx Config

#nano /etc/nginx/nginx.conf

http {
    ...
    fastcgi_buffers 8 16k;
    fastcgi_buffer_size 32k;
    ...
}

Method 2. Change PHP-FPM to listen on a unix socket or TCP socket.

#nano /etc/php-fpm.d/www.conf

listen = /var/run/php5-fpm.sock

To:

listen = 127.0.0.1:9000

If you are configuring php-fpm to listen on a Unix socket, you should also check that the socket file has the correct owner and permissions.

chmod 0660 /var/run/php5-fpm.sock
chown www-data:www-data /var/run/php5-fpm.sock

Method 3. Disable APC.

APC caching can cause 502 Bad Gateway issues under particular environments causing segmentation faults. I highly suggest using Memcache(d), but XCache is also a good alternative.

Congratulation’s! You have successfully solved 502 bad gateway issues. Thanks for using this tutorial to fix 502 bad gateway issues on Linux system. For additional help or useful information, we recommend you to check the official Nginx web site.

You Might Also Like: How To Hide Nginx Server Default Header