Quantcast
Channel: Saheetha Shameer – LinOxide
Viewing all 60 articles
Browse latest View live

How to Install CPanel 11.52 on CentOS 7

$
0
0

In September 2015, the product was launched. And it is available in the STABLE release tier now. The new brand cPanel 54 version is launched and it is available in the current release tier for this installation. Cpanel & WHM version 11.52 supports the CloudLinux 7/RHEL 7/CentOS 7 operating systems for fresh installations.

In this article, I'm going to discuss about the features/Pre-requisites/installation of latest LTS release of cPanel & WHM 11.52 on CentOS 7 OS version. Before going to the installation, we can take a look on some of the new features of this release comparing the rest of the releases.

New features:

CloudLinux/RHEL/CentOS 7 support
Quota support & XFS file system
Amazon Linux AMI support
Webmail Branding
MultiPHP
Easy Apache 3 to 4 updates
Linux Container support
Common Mail providers tabs to WHM's Greylisting.

Network Requirements

  • Hostname should be a fully qualified domain name.
  • Should have a valid ipaddress, subnet address and default gateway
  • Ethernet device with a static IP & hostname
  • Disable OS Firewall

Hardware Requirements

  1. Processor : 226 Mhz
  2. RAM : Minimum 1GB ( 2GB recommended for smooth functioning)
  3. Disk Space : Minimun 20 GB (40GB recommended for smooth functioning )

Disable Selinux

Need to edit the selinux configuration file located at : /etc/selinux/config

Modify the SELINUX parameter to disabled and reboot the server.

Installation steps followed for installing cPanel 11.52 on CentOS 7

Before installation make sure the server meets all the pre-requisites.

1. Set hostname to a fully qualified domain

This is how we set the hostname for the server to a fully qualified domain name "server1.centos7-test.com" and confirm the hostname status once it is done.

root@server1 [~]# hostnamectl set-hostname server1.centos7-test.com –static
root@server1 [~]# hostnamectl status
Static hostname: server1.centos7-test.com
Icon name: computer-vm
Chassis: vm
Machine ID: 72863e389b584a4dab36fae7f3bffda2
Boot ID: 8bd4f714d7ba4ebf9d53f059d0a1fe8b
Virtualization: xen
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 4.1.5-x86_64-linode61
Architecture: x86-64
root@server1 [~]#

2. Check for the IP addr, subnet addr and gateway

Make sure we have a static IP with a proper subnet mask and default gateway. In this case our IP address is 45.79.183.73 with a proper subnet mask and gateway.

root@server1 [~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 45.79.183.73 netmask 255.255.255.0 broadcast 45.79.183.255
inet6 fe80::f03c:91ff:fef1:78d9 prefixlen 64 scopeid 0x20<link>
inet6 2600:3c03::f03c:91ff:fef1:78d9 prefixlen 64 scopeid 0x0<global>
ether f2:3c:91:f1:78:d9 txqueuelen 1000 (Ethernet)
RX packets 38095 bytes 13241381 (12.6 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 41505 bytes 45527241 (43.4 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

3. Check the OS, disk usage and RAM usage for the server

Our server is installed with CentOS 7.2, having a disk space of 20GB and around 1GB RAM. Please see the results of the hardware checks below:

OS version check:

#cat/etc/redhat-release

root@server1 [~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
root@server1 [~]#

Disk usage check:

#df-h

root@server1 [~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 20G 5.9G 14G 31% /
devtmpfs 492M 0 492M 0% /dev
tmpfs 494M 0 494M 0% /dev/shm
tmpfs 494M 14M 480M 3% /run
tmpfs 494M 0 494M 0% /sys/fs/cgroup
/dev/loop0 662M 736K 627M 1% /tmp
tmpfs 99M 0 99M 0% /run/user/0

RAM usage check:

free -m or cat /proc/meminfo

root@server1 [~]# free -m
total used free shared buff/cache available
Mem: 987 336 275 12 375 607
Swap: 511 1 510

4. Disable Firewall

It is recommended to disable the OS firewalls before the cPanel & WHM installations. First of all we need to save the firewall rules and then stop the firewalld service. And make sure the service is disabled.

iptables-save > ~/firewall.rules
systemctl stop firewalld.service
systemctl disable firewalld.service

root@server1 [~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)

Jan 09 06:50:28 server1.centos7-test.com systemd[1]: Stopped firewalld - dynamic firewall daemon.

5. Disable Selinux

Modify the SELINUX parameter to disabled in /etc/selinux/config and reboot the server.
root@server1 [~]# cat /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted

5. Installation of Perl

cPanel is programmed in Perl language. Hence, we need to install Perl prior to the cPanel installation if it isn't installed in the server before.

yum install -y perl

6. Download/Install/Run cPanel/WHM script.

We need to download the cPanel installation script into the /home directory and run the script from there.

#cd /home
#curl -o latest -L https://securedownloads.cpanel.net/latest
#sh latest

This is how we download and install the cPanel installation script from our server's home directory.

The script can take half an hour or more to complete the installation procedures.

Installation log

2016-01-07 07:15:51 227 ( INFO): cPanel install finished in 32 minutes and 14 seconds!
2016-01-07 07:15:51 964 ( INFO): Congratulations! Your installation of cPanel & WHM 11.52 is now complete. The next step is to configure your server.
2016-01-07 07:15:51 964 ( INFO):
2016-01-07 07:15:51 964 ( INFO): Before you configure your server, ensure that your firewall allows access on port 2087.
2016-01-07 07:15:51 964 ( INFO): On RHEL, CentOS, and CloudLinux systems, execute /scripts/configure_firewall_for_cpanel to accomplish this.
2016-01-07 07:15:51 964 ( INFO):
2016-01-07 07:15:51 964 ( INFO): After ensuring that your firewall allows access on port 2087, you can configure your server.
2016-01-07 07:15:51 964 ( INFO):
2016-01-07 07:15:51 964 ( INFO): 1. Open your preferred browser
2016-01-07 07:15:51 964 ( INFO):
2016-01-07 07:15:51 964 ( INFO): 2. Type https://45.79.183.73:2087 in the address bar
2016-01-07 07:15:51 964 ( INFO):
2016-01-07 07:15:51 964 ( INFO): 3. Enter the word root in the Username text box
2016-01-07 07:15:51 964 ( INFO):
2016-01-07 07:15:51 964 ( INFO): 4. Enter your root password in the Password text box
2016-01-07 07:15:51 964 ( INFO):
2016-01-07 07:15:51 964 ( INFO): 5. Click the Login button
2016-01-07 07:15:51 964 ( INFO):
2016-01-07 07:15:51 964 ( INFO): Visit http://go.cpanel.net/whminit for more information about first-time configuration of your server.
2016-01-07 07:15:51 964 ( INFO):
2016-01-07 07:15:51 964 ( INFO): Visit http://support.cpanel.net or http://go.cpanel.net/whmfaq for additional support
2016-01-07 07:15:51 964 ( INFO):
2016-01-07 07:15:51 964 ( INFO): Thank you for installing cPanel & WHM 11.52!
2016-01-07 07:15:51 835 ( WARN): !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

7. Adding ports 2087/2086 to the firewalld service

After completing the installation procedures, we need to ensure that our server allows the required service ports in the firewall.

[root@server1 zones]# firewall-cmd --zone=public --add-port=2087/udp
success
[root@server1 zones]# firewall-cmd --zone=public --add-port=2086/udp
success
[root@server1 zones]# firewall-cmd --zone=public --add-port=2086/tcp
success
[root@server1 zones]# firewall-cmd --zone=public –add-port=2087/tcp

[root@server1 zones]#firewall-cmd --reload

If your server has enough resources, then it is always advised to disable the OS firewall and configure CSF/APF to ensure better security and allow all required cPanel service ports by default. I would recommend to go with CSF for a cPanel server.

CSF Installation steps:

 wget http://configserver.com/free/csf.tgz
tar -xzf csf.tgz
cd csf & ./install.cpanel.sh

Access the WHM via the URL

You can access WHM using the URL https://server-hostname:2087 or http://server-hostname:2086

After accessing the URL mentioned above, you can put your username as root and its password to login.

Read through the terms and conditions & accept the license agreement.

Now you can do your initial configuration steps one by one as below:

1. Setup Networking
2. Setup IP address
3. Nameservers
4. Services
5. Setup quotas

Visit http://go.cpanel.net/whminit for more information about first-time configuration of your server.

Now you will have your WHM ready to use!!!

cpanelwhm

 

I believe this article will be a great help for you guys! Thank you for referring to this. I would appreciate your valuable comments for further improvements.

The post How to Install CPanel 11.52 on CentOS 7 appeared first on LinOxide.


How to Enable Multiple PHP Versions on cPanel 11.52

$
0
0

One of the major improvements for the latest EA4 is the support for multiple PHP versions. This allows the server to run upto three PHP versions in parallel namely PHP54, PHP55 and PHP56 with the required modules. It also allows you to run and quickly update the domains with different PHP versions with the help of MultiPHP Manager tool provided in the WHM interface.

These are also enhanced with auto-upgrades to ensure that your PHP applications are up-to-update and secured.

CPanel 11.52 provides both EA3 and EA4 support. To enable the MultiPHP support, we need to upgrade the EA (EasyApache) software to EA4.

Upgrading EA3 to EA4

Before upgrading to EA4, there are certain things to be taken cared of.

1. You need to make sure that the RPMUP key's value it set to daily in the /etc/cpupdate.conf

root@server1 [~]# grep RPMUP /etc/cpupdate.conf
RPMUP=daily

This is to ensure that your server receive RPM updates automatically.

2. Now navigate to "Update Preferences" tab in WHM (Home >> Server Configuration >> Update Preferences) and ensure that the Operating System Package update settings is set to Automatic. It will be set to automatic by default, if not modify it.

Conversion from EA3 to EA4

You can run the following script to upgrade from EA3 to EA4. But make sure to run this script as root user.

/scripts/migrate_ea3_to_ea4 --run

root@server1 [~]# /scripts/migrate_ea3_to_ea4 --run
This action will install a Technology Preview release of EasyApache4 for cPanel & WHM. This means that you understand the following:
• Not all features in cPanel & WHM are operational.
• Not all EasyApache features are included in the Technology Preview.
• Features and functionality in the release may change over time.
• We will quickly address severe or critical issues only.
• Security bounties are not available.
Do you wish to continue? [y/N]y

Once you type 'yes' to continue. The following packages will be installed in the server.

Dependencies Resolved

===============================================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================================
Installing:
ea-cpanel-tools x86_64 1.0-3.1 EA4 5.5 k
ea-profiles-cpanel x86_64 1.0-21.1 EA4 6.7 k
yum-plugin-universal-hooks x86_64 0.1-7.7 EA4 7.6 k

Transaction Summary
===============================================================================================================================================

It will take a few minutes to complete the installation process. After the installation, the EA4 loads with a custom profile of Apache 2.4 with minimal installations including the basic modules that you need to run a minimal web server. It will have only one PHP version available and that will be PHP 5.5 which is the default PHP version in cPanel 11.52 installations.
EA4 provides six profiles in addition. You can navigate to EasyApache 4 section in the WHM interface (Home »Software »EasyApache 4) to view all available profiles and install the most suitable one for your production server.

EA profiles

You can either provision the required profiles from the WHM interface itself or you can use the command-line tools for installations.

This is how I installed my required EA4 profile from CLI.  All the available profiles are present inside the "/etc/cpanel/ea4/profiles/" folder.

root@server1 [/etc/cpanel/ea4/profiles/cpanel]# ll
total 40
drwxr-xr-x 2 root root 4096 Jan 12 08:28 ./
drwxr-xr-x 4 root root 4096 Jan 12 08:28 ../
-rw-r--r-- 1 root root 4291 Dec 15 15:28 allphp.json
-rw-r--r-- 1 root root 4255 Dec 15 15:28 allphp-opcache.json
-rw-r--r-- 1 root root 1846 Dec 15 15:28 default.json
-rw-r--r-- 1 root root 1801 Dec 15 15:28 mpm_itk.json
-rw-r--r-- 1 root root 600 Dec 15 15:28 nophp.json
-rw-r--r-- 1 root root 1830 Dec 15 15:28 ruid2.json

I preferred to install the default.json (cPanel Default) profile. This is the standard Apache package with up-to-date PHP and modules. This package can host multiple sites and users. This includes three PHP packages namely PHP54, PHP55, PHP56 with minimum, but required modules.

This is how I did that on CLI!

root@server1 [/etc/cpanel/ea4/profiles/cpanel]# /usr/local/bin/ea_install_profile --install default.json

===============================================================================
Package Arch Version Repository
Size
================================================================================
Installing:
ea-apache24-mod_cgid x86_64 2.4.18-1.1 EA4 35 k
ea-apache24-mod_mpm_worker x86_64 2.4.18-1.1 EA4 38 k
ea-php54 x86_64 1.1-10.7 EA4 4.1 k
ea-php54-php-bcmath x86_64 5.4.45-7.7 EA4 56 k
ea-php54-php-calendar x86_64 5.4.45-7.7 EA4 44 k
ea-php54-php-cli x86_64 5.4.45-7.7 EA4 2.6 M
ea-php54-php-common x86_64 5.4.45-7.7 EA4 360 k
ea-php54-php-curl x86_64 5.4.45-7.7 EA4 57 k
ea-php54-php-ftp x86_64 5.4.45-7.7 EA4 50 k
ea-php54-php-gd x86_64 5.4.45-7.7 EA4 125 k
ea-php54-php-mcrypt x86_64 5.4.45-7.7 EA4 46 k
ea-php54-php-mysqlnd x86_64 5.4.45-7.7 EA4 172 k
ea-php54-php-pdo x86_64 5.4.45-7.7 EA4 97 k
ea-php54-php-posix x86_64 5.4.45-7.7 EA4 42 k
ea-php54-php-sockets x86_64 5.4.45-7.7 EA4 52 k
ea-php54-php-xml x86_64 5.4.45-7.7 EA4 156 k
ea-php54-runtime x86_64 1.1-10.7 EA4 14 k
ea-php55 x86_64 1.1-10.7 EA4 3.6 k
ea-php55-php-xml x86_64 5.5.30-7.7 EA4 158 k
ea-php56 x86_64 1.1-10.7 EA4 3.7 k
ea-php56-php-bcmath x86_64 5.6.16-5.7 EA4 57 k
ea-php56-php-calendar x86_64 5.6.16-5.7 EA4 46 k
ea-php56-php-cli x86_64 5.6.16-5.7 EA4 2.6 M
ea-php56-php-xml x86_64 5.6.16-5.7 EA4 159 k
ea-php56-runtime x86_64 1.1-10.7 EA4 13 k
================================================================================

These many packages will be installed. It will take a while to complete.

Now I can make use MultiPHP support enabled in our server. You can select the MultiPHP Manager tool from WHM (Home »Software »MultiPHP Manager)
to easily configure the default server PHP version and also modify individual domain PHP versions as required.

multiphp

 

custom-php

You can even modify the PHP basic & INI settings for the installed versions using MultiPHP INI Editor tool.

phpvariables

Now you see how easy to install and manage multiple PHP versions on cPanel 11.52 server. I hope this article is  informative and useful for you. Thank you referring to this :). I would appreciate your valuable comments and suggestions on this.

The post How to Enable Multiple PHP Versions on cPanel 11.52 appeared first on LinOxide.

How to Enable Multiple PHP-FPM Instances with Nginx / Apache

$
0
0

PHP-FPM is also known as PHP FastCGI Process Manager. It is an advancement of PHP FastCGI implementation with more useful features for handling heavy-loaded servers and websites. Some of those features are listed below:

New Features

  • Advanced process managament capability with graceful start/stop options.
  • Ability to run the processes with different userids/groupids listening on different ports and using different PHP configurations.
  • Error logging.
  • Acceleration upload support
  • Special function to finish request and flush all data while doing some time consuming tasks
  • Both Dynamic and Static Child process Spawning
  • IP Address restriction

In this article, I'm going to discuss about installing PHP-FPM along with Nginx and Apache on a CentOS 7 server running cPanel 11.52 with EA3(EasyApache) and how to manage those installed multiple PHP-FPM instances via CPanel.

Before going to the installation procedures, let us take a look on the pre-requisites.

Pre-requisites

  1.  Enable Mod_proxy_fcgi module
  2.  Enable MPM_Event

Since, we are installing PHP-FPM on a EA3 server, we need to run EasyApache to compile Apache to enable these modules.

You can refer my previous document on how to install Nginx as reverse proxy on a Apache server to confirm with the Nginx installation.

I'll brief those installation steps once again here. You can refer to my previous documentation (How to Set Nginx as Reverse Proxy on CentOS 7 /CPanel Server) for details.

Step 1: Install the Epel repo
Step 2: Install nDeploy RPM repo which is the most **IMPORTANT** step in this installation.
Step 3: Install nDeploy and Nginx plugin using yum from the nDeploy repo.
Step 4: Enable/Configure Nginx as reverse proxy

Once this is done, install the PHP-FPM packages for all PHP versions available in the server. EA3 uses remi repository for installing these packages. You can run this nDeploy script to download all packages.

root@server1 [~]# /opt/nDeploy/scripts/easy_php_setup.sh
Loaded plugins: fastestmirror, tsflags, universal-hooks
EA4 | 2.9 kB 00:00:00
base | 3.6 kB 00:00:00
epel/x86_64/metalink | 9.7 kB 00:00:00
epel | 4.3 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/2): epel/x86_64/updateinfo | 460 kB 00:00:00
(2/2): epel/x86_64/primary_db

Running this script will install all these FPM packages for PHP 54, PHP 55, PHP 56 and PHP 70.

Installed Packages
php54-php-fpm.x86_64 5.4.45-3.el7.remi @remi
php55-php-fpm.x86_64 5.5.31-1.el7.remi @remi
php56-php-fpm.x86_64 5.6.17-1.el7.remi @remi
php70-php-fpm.x86_64 7.0.2-1.el7.remi @remi

After this installation, you need to enable PHP-FPM SAPI for Apache. You can run this script to enable PHP-FPM instances.

root@server1 [~]# /opt/nDeploy/scripts/apache_php-fpm_setup.sh enable
mod_proxy_fcgi.c
Please choose one default PHP version from the list below
PHP70
PHP56
PHP54
PHP55
Provide the exact desired version string here and press ENTER: PHP54
ConfGen:: lxblogger
ConfGen:: blogr
ConfGen:: saheetha
ConfGen:: satest
which: no cagefsctl in (/usr/local/jdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/root/bin)
info [rebuildhttpdconf] Missing owner for domain server1.centos7-test.com, force lookup to root
Built /usr/local/apache/conf/httpd.conf OK
Waiting for “httpd” to restart gracefully …waiting for “httpd” to initialize ……
…finished.

It will ask the required PHP version which you prefer to run as default on the server. You can enter those details and proceed to configure and generate the virtual host files for the existing domains.

I've chosen PHP 54 as the default PHP-FPM version on my server.

confirm-php-fpm

Even though, the server is configured with PHP-FPM 54, we can modify the PHP-FPM instances for the individual domains via cPanel.

I'll explain you on how to modify the PHP-FPM instances for individual domains via cPanel using some screenshots.

The installation of Nginx plugin will provide you with an icon of Nginx Webstack in your domain's cPanel. You can click on that icon to configure your Web server. I've logged into one of my domain's cPanel to configure it's Web server.

Please check these snapshots.

nginx webstack

nginxicon1

Now you can configure the web-server for the selected main domain as required(I've selected the main domain saheetha.com here). I've gone ahead with automatic configuration options since, I don't have any manual settings to add.

nginx_auto_proxy

Once Nginx is configured, you can select the PHP-FPM instance for your domain here.

php-fpm1

php54

php55

As you can see in these snapshots, my default PHP-FPM  on the server is PHP 54 and I'm  changing the PHP-FPM instance for my domain alone to PHP 55. Once you've modified the PHP-FPM for your domain, you can confirm it by accessing the phpinfo page.

Thank you for referring to this article. I believe this article is really informative and useful for you. I would recommend your valuable comments on this :).

The post How to Enable Multiple PHP-FPM Instances with Nginx / Apache appeared first on LinOxide.

How to Set Nginx as Reverse Proxy on Centos7 CPanel

$
0
0

Nginx is one of the fastest and most powerful web-server. It is known for its high performance and low resource utilization. It can be installed as both a standalone and a Reverse Proxy Web-server. In this article, I'm discussing about the installation of Nginx as a reverse proxy along with Apache on a CPanel server with latest CentOS 7 installed.

Nginx as a reverse proxy will work as a frontend webserver serving static contents along with Apache serving the dynamic files in backend. This setup will boost up the overall server performance.

Let's walk through the installation steps for Nginx as reverse proxy in CentOS7 x86_64 bit server with cPanel 11.52 installed.

First of all, we need to install the EPEL repo to start-up with the process.

Step 1 : Install the EPEL repo.

root@server1 [/usr]# yum -y install epel-release
Loaded plugins: fastestmirror, tsflags, universal-hooks
Loading mirror speeds from cached hostfile
* EA4: 66.23.237.210
* base: mirrors.linode.com
* extras: mirrors.linode.com
* updates: mirrors.linode.com
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-5 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================================
Installing:
epel-release noarch 7-5 extras 14 k

Step 2: After installing the repo, we can start with the installation of the nDeploy RPM repo for CentOS to install our required nDeploy Webstack and Nginx plugin.

root@server1 [/usr]# yum -y install http://rpm.piserve.com/nDeploy-release-centos-1.0-1.noarch.rpm
Loaded plugins: fastestmirror, tsflags, universal-hooks
nDeploy-release-centos-1.0-1.noarch.rpm | 1.7 kB 00:00:00
Examining /var/tmp/yum-root-ei5tWJ/nDeploy-release-centos-1.0-1.noarch.rpm: nDeploy-release-centos-1.0-1.noarch
Marking /var/tmp/yum-root-ei5tWJ/nDeploy-release-centos-1.0-1.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package nDeploy-release-centos.noarch 0:1.0-1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================================
Installing:
nDeploy-release-centos noarch 1.0-1 /nDeploy-release-centos-1.0-1.noarch 110

Step 3: Install the nDeploy and Nginx nDeploy plugins.

root@server1 [/usr]# yum --enablerepo=ndeploy install nginx-nDeploy nDeploy
Loaded plugins: fastestmirror, tsflags, universal-hooks
epel/x86_64/metalink | 9.9 kB 00:00:00
epel | 4.3 kB 00:00:00
ndeploy | 2.9 kB 00:00:00
(1/4): ndeploy/7/x86_64/primary_db | 14 kB 00:00:00
(2/4): epel/x86_64/group_gz | 169 kB 00:00:00
(3/4): epel/x86_64/primary_db | 3.7 MB 00:00:02

Dependencies Resolved

===============================================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================================
Installing:
nDeploy noarch 2.0-11.el7 ndeploy 80 k
nginx-nDeploy x86_64 1.8.0-34.el7 ndeploy 36 M
Installing for dependencies:
PyYAML x86_64 3.10-11.el7 base 153 k
libevent x86_64 2.0.21-4.el7 base 214 k
memcached x86_64 1.4.15-9.el7 base 84 k
python-inotify noarch 0.9.4-4.el7 base 49 k
python-lxml x86_64 3.2.1-4.el7 base 758 k

Transaction Summary
===============================================================================================================================================
Install 2 Packages (+5 Dependent packages)

With these steps, we've completed with the installation of Nginx plugin in our server. Now we need to configure Nginx as reverse proxy and create the virtualhost for the existing cPanel user accounts. For that we can run the following script.

Step 4: To enable Nginx as a front end Web Server and create the default configuration files.

root@server1 [/usr]# /opt/nDeploy/scripts/cpanel-nDeploy-setup.sh enable
Modifying apache http and https port in cpanel

httpd restarted successfully.
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/ndeploy_watcher.service to /usr/lib/systemd/system/ndeploy_watcher.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/ndeploy_backends.service to /usr/lib/systemd/system/ndeploy_backends.service.
ConfGen:: saheetha
ConfGen:: satest

As you can see these script will modify the Apache port from 80 to another port to make Nginx run as a front end web server and create the virtual host configuration files for the existing cPanel accounts. Once it is done, confirm the status of both Apache and Nginx.

Apache Status:

root@server1 [/var/run/httpd]# systemctl status httpd
● httpd.service - Apache Web Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2016-01-18 06:34:23 UTC; 12s ago
Process: 25606 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
Main PID: 24760 (httpd)
CGroup: /system.slice/httpd.service
‣ 24760 /usr/local/apache/bin/httpd -k start

Jan 18 06:34:23 server1.centos7-test.com systemd[1]: Starting Apache Web Server...
Jan 18 06:34:23 server1.centos7-test.com apachectl[25606]: httpd (pid 24760) already running
Jan 18 06:34:23 server1.centos7-test.com systemd[1]: Started Apache Web Server.

Nginx Status:

root@server1 [~]# systemctl status nginx
● nginx.service - nginx-nDeploy - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2016-01-17 17:18:29 UTC; 13h ago
Docs: http://nginx.org/en/docs/
Main PID: 3833 (nginx)
CGroup: /system.slice/nginx.service
├─ 3833 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
├─25473 nginx: worker process
├─25474 nginx: worker process
└─25475 nginx: cache manager process

Jan 17 17:18:29 server1.centos7-test.com systemd[1]: Starting nginx-nDeploy - high performance web server...
Jan 17 17:18:29 server1.centos7-test.com nginx[3804]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Jan 17 17:18:29 server1.centos7-test.com nginx[3804]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Jan 17 17:18:29 server1.centos7-test.com systemd[1]: Started nginx-nDeploy - high performance web server.

Nginx act as a frontend webserver running on port 80 and Apache configuration is modified to listen on http port 9999 and https port 4430. Please see their status below:

root@server1 [/usr/local/src]# netstat -plan | grep httpd
tcp 0 0 0.0.0.0:4430 0.0.0.0:* LISTEN 17270/httpd
tcp 0 0 0.0.0.0:9999 0.0.0.0:* LISTEN 17270/httpd
tcp6 0 0 :::4430 :::* LISTEN 17270/httpd
tcp6 0 0 :::9999 :::* LISTEN 17270/httpd

apacheport
root@server1 [/usr/local/src]# netstat -plan | grep nginx
tcp 0 0 127.0.0.1:80 0.0.0.0:* LISTEN 17802/nginx: master
tcp 0 0 45.79.183.73:80 0.0.0.0:* LISTEN 17802/nginx: master

The virtualhost entries created for the existing users as located in the folder "/etc/nginx/sites-enabled". This file path is included in the Nginx main configuration file.

root@server1 [/etc/nginx/sites-enabled]# ll | grep .conf
-rw-r--r-- 1 root root 311 Jan 17 09:02 saheetha.com.conf
-rw-r--r-- 1 root root 336 Jan 17 09:02 saheethastest.com.conf

Sample Vhost for a domain:

server {

listen 45.79.183.73:80;
#CPIPVSIX:80;

# ServerNames
server_name saheetha.com www.saheetha.com;
access_log /usr/local/apache/domlogs/saheetha.com main;
access_log /usr/local/apache/domlogs/saheetha.com-bytes_log bytes_log;

include /etc/nginx/sites-enabled/saheetha.com.include;

}

We can confirm the working of the web server status by calling a website in the browser. Please see the web server information on my server after the installation.

root@server1 [/home]# ip a | grep -i eth0
3: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
inet 45.79.183.73/24 brd 45.79.183.255 scope global dynamic eth0
root@server1 [/home]# nginx -v
nginx version: nginx/1.8.0

webserver-status

Nginx will create the virtual host automatically for any newly created accounts in cPanel. With these simple steps we can configure Nginx as reverse proxy on a CentOS 7/CPanel server.

Advantages of Nginx as Reverse Proxy:

  1. Easy to install and configure
  2. Performance and efficiency
  3. Prevent DDOS attacks
  4. Allows .htaccess PHP rewrite rules

I hope this article is useful for you guys. Thank you for referring to this. I would appreciate your valuable comments and suggestions on this for further improvements.

The post How to Set Nginx as Reverse Proxy on Centos7 CPanel appeared first on LinOxide.

How to Update CURL with CPanel on CentOS 7

$
0
0

CURL is a simple module that allows you to connect and communicate to various types of servers using various types of protocols. Curl mainly supports http, https, ftp, gopher, telnet, dict, file, and ldap protocols. It also supports SMB, SMBS, IMAP, IMAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, TFT, HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, and user/password authentication.

We know that, an increasing amount of web applications has made the HTTP scripting more frequently requested and necessary. There is a high demand for such a tool which helps us to automatically extract information from the Web, upload, proxy or POST data to the web servers.

CURL is a simple commandline tool which can be used to do all these URL manipulations and data transfers. It is powered by libcurl, which is a library created by Daniel Stenberg.

It is mandatory to keep such softwares always updated, since there is a chance of hacking attempts, data diddling or loop holes due to old insecure versions. In this article, I'm discussing a simple method on how to update the Curl in a more efficient way to the latest available versions on a cPanel server.

First of all, check the current version installed on the server. Please see the current CURL version in my server below:

root@server1 [/usr/local/src]# /usr/bin/curl -V
curl 7.38.0 (x86_64-redhat-linux-gnu) libcurl/7.38.0 NSS/3.19.1 Basic ECC zlib/1.2.7 libidn/1.28 libssh2/1.4.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smtp smtps telnet tftp
Features: IDN IPv6 Largefile NTLM NTLM_WB SSL UnixSockets

current_curl_status

As you can see the CURL version is 7.38 and is compiled to support these many protocols like dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, ldaps, pop3, pop3s, rtsp, scp, sftp, smtp, smtps, telnet and tftp.

We are going to configure CURL with Asynchronous DNS to improve its performance and make the requests more faster without any delays. Let's start our update process now.

Step 1. Download the latest Curl and Asynchronous DNS Package from their website and extract.

root@server1 [~]# cd /usr/local/src/
root@server1 [/usr/local/src]# wget http://c-ares.haxx.se/download/c-ares-1.10.0.tar.gz
--2016-01-26 06:29:25-- http://c-ares.haxx.se/download/c-ares-1.10.0.tar.gz
Resolving c-ares.haxx.se (c-ares.haxx.se)... 2a00:1a28:1200:9::2, 80.67.6.50
Connecting to c-ares.haxx.se (c-ares.haxx.se)|2a00:1a28:1200:9::2|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 809073 (790K) [application/x-gzip]
Saving to: ‘c-ares-1.10.0.tar.gz’

100%[=====================================================================================================>] 8,09,073 1.18MB/s in 0.7s

2016-01-26 06:29:26 (1.18 MB/s) - ‘c-ares-1.10.0.tar.gz’ saved [809073/809073]

root@server1 [/usr/local/src]#tar -xvf c-ares-1.10.0.tar.gz
root@server1 [/usr/local/src]# wget http://curl.haxx.se/download/curl-7.46.0.tar.gz
--2016-01-26 06:29:59-- http://curl.haxx.se/download/curl-7.46.0.tar.gz
Resolving curl.haxx.se (curl.haxx.se)... 2a00:1a28:1200:9::2, 80.67.6.50
Connecting to curl.haxx.se (curl.haxx.se)|2a00:1a28:1200:9::2|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4551902 (4.3M) [application/x-gzip]
Saving to: ‘curl-7.46.0.tar.gz’

100%[=====================================================================================================>] 45,51,902 3.79MB/s in 1.1s

2016-01-26 06:30:01 (3.79 MB/s) - ‘curl-7.46.0.tar.gz’ saved [4551902/4551902]

root@server1 [/usr/local/src]#tar -xvf curl-7.46.0.tar.gz

Step 2. Configure, make and install the Asynchronous DNS package.

root@server1 [/usr/local/src/c-ares-1.10.0]# ./configure

root@server1 [/usr/local/src/c-ares-1.10.0]# make
make all-am
make[1]: Entering directory `/usr/local/src/c-ares-1.10.0'
/bin/sh ./libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I. -DCARES_BUILDING_LIBRARY -DCARES_SYMBOL_HIDING -fvisibility=hidden -g0 -O2 -Wno-system-headers -MT libcares_la-ares__close_sockets.lo -MD -MP -MF .deps/libcares_la-ares__close_sockets.Tpo -c -o libcares_la-ares__close_sockets.lo `test -f 'ares__close_sockets.c' || echo './'`ares__close_sockets.c
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I. -DCARES_BUILDING_LIBRARY -DCARES_SYMBOL_HIDING -fvisibility=hidden -g0 -O2 -Wno-system-headers -MT libcares_la-ares__close_sockets.lo -MD -MP -MF .deps/libcares_la-ares__close_sockets.Tpo -c ares__close_sockets.c -fPIC -DPIC -o .libs/libcares_la-ares__close_sockets.o
make[1]: Leaving directory `/usr/local/src/c-ares-1.10.0'

root@server1 [/usr/local/src/c-ares-1.10.0]# make install

/usr/bin/install -c -m 644 ares_version.3 ares_inet_pton.3 ares_inet_ntop.3 '/usr/local/share/man/man3'
/usr/bin/mkdir -p '/usr/local/lib/pkgconfig'
/usr/bin/install -c -m 644 libcares.pc '/usr/local/lib/pkgconfig'
make[1]: Leaving directory `/usr/local/src/c-ares-1.10.0'

Step 3. Now configure CURL with Asynchornous DNS and all other required Protocols.

root@server1 [/usr/local/src/curl-7.46.0]# ./configure --enable-ares=/usr/local/src/c-ares-1.10.0 --enable-http --enable-imap --enable-pop3 --enable-ftp --enable-proxy --enable-tftp --enable-ntlm --enable-static --with-ssl=/usr/local/ssl --enable-ipv6 --enable-shared --disable-ldap --enable-gobher --enable-smtp --with-libidn --disable-rtsp --without-zlib
root@server1 [/usr/local/src/curl-7.46.0]#make
curl version: 7.46.0
Host setup: x86_64-pc-linux-gnu
Install prefix: /usr/local
Compiler: gcc
SSL support: enabled (OpenSSL)
SSH support: no (--with-libssh2)
zlib support: no (--with-zlib)
GSS-API support: no (--with-gssapi)
TLS-SRP support: no (--enable-tls-srp)
resolver: c-ares
IPv6 support: enabled
Unix sockets support: enabled
IDN support: enabled
Build libcurl: Shared=yes, Static=yes
Built-in manual: enabled
--libcurl option: enabled (--disable-libcurl-option)
Verbose errors: enabled (--disable-verbose)
SSPI support: no (--enable-sspi)
ca cert bundle: /etc/pki/tls/certs/ca-bundle.crt
ca cert path: no
LDAP support: no (--enable-ldap / --with-ldap-lib / --with-lber-lib)
LDAPS support: no (--enable-ldaps)
RTSP support: no (--enable-rtsp)
RTMP support: no (--with-librtmp)
metalink support: no (--with-libmetalink)
PSL support: no (libpsl not found)
HTTP2 support: disabled (--with-nghttp2)
Protocols: DICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS POP3 POP3S SMB SMBS SMTP SMTPS TELNET TFTP
root@server1 [/usr/local/src/curl-7.46.0]# make install
Making install in lib
make[1]: Entering directory `/usr/local/src/curl-7.46.0/lib'
make[2]: Entering directory `/usr/local/src/curl-7.46.0/lib'
/usr/bin/mkdir -p '/usr/local/lib'
/bin/sh ../libtool --mode=install /usr/bin/install -c libcurl.la '/usr/local/lib'
libtool: install: /usr/bin/install -c .libs/libcurl.so.4.4.0 /usr/local/lib/libcurl.so.4.4.0
libtool: install: (cd /usr/local/lib && { ln -s -f libcurl.so.4.4.0 libcurl.so.4 || { rm -f libcurl.so.4 && ln -s libcurl.so.4.4.0 libcurl.so.4; }; })
libtool: install: (cd /usr/local/lib && { ln -s -f libcurl.so.4.4.0 libcurl.so || { rm -f libcurl.so && ln -s libcurl.so.4.4.0 libcurl.so; }; })
libtool: install: /usr/bin/install -c .libs/libcurl.lai /usr/local/lib/libcurl.la
libtool: install: /usr/bin/install -c .libs/libcurl.a /usr/local/lib/libcurl.a
libtool: install: chmod 644 /usr/local/lib/libcurl.a
libtool: install: ranlib /usr/local/lib/libcurl.a
libtool: finish: PATH="/usr/local/jdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/root/bin:/sbin" ldconfig -n /usr/local/lib
----------------------------------------------------------------------
Libraries have been installed in:
/usr/local/lib

Step 4 . Edit the file /var/cpanel/easy/apache/rawopts/all_php5 to enable custom CURL module with our downloaded latest asynchronous DNS package as below

root@server1 [~]# vim /var/cpanel/easy/apache/rawopts/all_php5
--with-gssapi
--with-curl=/usr/local/src/curl-7.46.0
--enable-ares=/usr/local/src/c-ares-1.10.0

Step 5. Run EasyApache to configure and install the latest CURL package.

root@server1 [~]#/scripts/easyapache

Step 6. Check and confirm the version and settings of the newly installed Curl version.

root@server1 [~]# curl-config --version
libcurl 7.46.0
root@server1 [/usr/local/src/curl-7.46.0]# curl-config --features --protocols
SSL
IPv6
UnixSockets
AsynchDNS
IDN
NTLM
NTLM_WB
DICT
FILE
FTP
FTPS
GOPHER
HTTP
HTTPS
IMAP
IMAPS
POP3
POP3S
SMB
SMBS
SMTP
SMTPS
TELNET
TFTP
root@server1 [/usr/local/src/curl-7.46.0]# curl --version
curl 7.46.0 (x86_64-pc-linux-gnu) libcurl/7.46.0 OpenSSL/1.0.1e c-ares/1.10.0 libidn/1.28
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s smb smbs smtp smtps telnet tftp
Features: AsynchDNS IDN IPv6 Largefile NTLM NTLM_WB SSL UnixSockets

Now you see our CURL is updated to the latest version available CURL 7.46.0 and it's compiled with Asynchronous DNS to support all the required protocols. You can confirm the compiled curl status with a PHPINFO page.

curl_latest

PHP can be coded to make use of these asynchronous CURL requests to fasten the script execution more efficiently. I hope you find this article useful and informative. I would recommend your valuable comments and suggestions on this.

Enjoy!!

The post How to Update CURL with CPanel on CentOS 7 appeared first on LinOxide.

How to Install MariaDB 10 on CentOS 7 CPanel Server

$
0
0

MariaDB is a enhanced open source and drop-in replacement for MySQL. It is developed by MariaDB community and available under the terms of the GPL v2 license. Software Security is the main focus for the MariaDB developers. They maintain its own set of security patches for each MariaDB releases. When any critical security issues are discovered, the developers introduces a new release of MariaDB to get the fix out as soon as possible.

MariaDB is always up-to-date with the latest MySQL releases. It is highly compatible and works exactly like the MySQL. Almost all commands, data, table definition files, Client APIs, protocols, interfaces, structures, filenames, binaries, ports, database storage locations etc are same as the MySQL. It isn't even needed to convert databases to switch to MariaDB.

Advantages of MariaDB

  • Truly Open source
  • More quicker and transparent security releases
  • Highly Compatible with MySQL
  • Improved Performance
  • More storage engines compared to MySQL

In this article, I provides guidelines on how to upgrade MySQL 5.5 to the latest MariaDB on a CentOS 7 CPanel server. Let's walk through the Pre-installation steps.

Pre-requisites:

1. Stop current MySQL Service

root@server1 [/var/# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5859
Server version: 5.5.47-cll MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

root@server1 [~]# systemctl stop mysql
root@server1 [~]# systemctl status mysql
● mysql.service - LSB: start and stop MySQL
Loaded: loaded (/etc/rc.d/init.d/mysql)
Active: failed (Result: exit-code) since Sun 2016-01-31 10:00:02 UTC; 1min 31s ago
Docs: man:systemd-sysv-generator(8)
Main PID: 23430 (code=exited, status=203/EXEC)

Jan 31 10:00:02 server1.centos7-test.com systemd[1]: Started MySQL Server.
Jan 31 10:00:02 server1.centos7-test.com systemd[1]: Starting MySQL Server...
Jan 31 10:00:02 server1.centos7-test.com systemd[1]: mysql.service: main process exited, code=exited, status=203/EXEC
Jan 31 10:00:02 server1.centos7-test.com systemd[1]: Unit mysql.service entered failed state.
Jan 31 10:00:02 server1.centos7-test.com systemd[1]: mysql.service failed.

2. Move all configuration files and databases prior to the upgrade

Move the DB storage path and MySQL configuration files

root@server1 [~]# cp -Rf /var/lib/mysql /var/lib/mysql-old

root@server1 [/var/lib/mysql]# cat /etc/my.cnf
[mysqld]
default-storage-engine=MyISAM
innodb_file_per_table=1
max_allowed_packet=268435456
open_files_limit=10000

root@server1 [~]#mv /etc/my.cnf /etc/my.cnf-old

3. Remove and uninstall all MySQL rpms from the server

Run the following commands to disable the MySQL RPM targets. By running this commands, cPanel will no longer handle MySQL updates, and mark these rpm.versions as uninstalled on the system.

/scripts/update_local_rpm_versions --edit target_settings.MySQL50 uninstalled
/scripts/update_local_rpm_versions --edit target_settings.MySQL51 uninstalled
/scripts/update_local_rpm_versions --edit target_settings.MySQL55 uninstalled
/scripts/update_local_rpm_versions --edit target_settings.MySQL56 uninstalled

Now run the this command:

/scripts/check_cpanel_rpms --fix --targets=MySQL50,MySQL51,MySQL55,MySQL56 to remove all existing MySQL rpms on the server and leave a clean environment for MariaDB installation. Please see its output below:

root@server1 [/var/lib/mysql]# /scripts/check_cpanel_rpms --fix --targets=MySQL50,MySQL51,MySQL55,MySQL56
[2016-01-31 09:53:59 +0000]
[2016-01-31 09:53:59 +0000] Problems were detected with cPanel-provided files which are RPM controlled.
[2016-01-31 09:53:59 +0000] If you did not make these changes intentionally, you can correct them by running:
[2016-01-31 09:53:59 +0000]
[2016-01-31 09:53:59 +0000] > /usr/local/cpanel/scripts/check_cpanel_rpms --fix
[2016-01-31 09:53:59 +0000]
[2016-01-31 09:53:59 +0000] The following RPMs are unneeded on your system and should be uninstalled:
[2016-01-31 09:53:59 +0000] MySQL55-client-5.5.47-1.cp1148
[2016-01-31 09:53:59 +0000] MySQL55-devel-5.5.47-1.cp1148
[2016-01-31 09:53:59 +0000] MySQL55-server-5.5.47-1.cp1148
[2016-01-31 09:53:59 +0000] MySQL55-shared-5.5.47-1.cp1148
[2016-01-31 09:53:59 +0000] MySQL55-test-5.5.47-1.cp1148
[2016-01-31 09:53:59 +0000] compat-MySQL50-shared-5.0.96-4.cp1136
[2016-01-31 09:53:59 +0000] compat-MySQL51-shared-5.1.73-1.cp1150
[2016-01-31 09:53:59 +0000] Removing 0 broken rpms:
[2016-01-31 09:53:59 +0000] rpm: no packages given for erase
[2016-01-31 09:53:59 +0000] No new RPMS needed for install
[2016-01-31 09:53:59 +0000] Disabling service monitoring.
[2016-01-31 09:54:01 +0000] Uninstalling unneeded rpms: MySQL55-test MySQL55-server MySQL55-client compat-MySQL51-shared compat-MySQL50-shared MySQL55-shared MySQL55-devel
[2016-01-31 09:54:04 +0000] Removed symlink /etc/systemd/system/multi-user.target.wants/mysql.service.
[2016-01-31 09:54:04 +0000] Restoring service monitoring.

With these steps, we've uninstalled existing MySQL RPMs, marked targets to prevent further MySQL updates and made the server ready and clean for the MariaDB installation.

To startup with the installation, we need to create a yum repository for MariaDB depending on the MariaDB & CentOS versions. This is how I did it!

Installation procedures:

Step 1: Creating a YUM repository.

root@server1 [~]# vim /etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos7-amd64/
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
root@server1 [/etc/yum.repos.d]# cat /etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos7-amd64/
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

Step 2: Open the /etc/yum.conf and modify the exclude line as below:

Remove this line exclude=courier* dovecot* exim* filesystem httpd* mod_ssl* mydns* mysql* nsd* php* proftpd* pure-ftpd* spamassassin* squirrelmail*

And replace with this line exclude=courier* dovecot* exim* filesystem httpd* mod_ssl* mydns* nsd* proftpd* pure-ftpd* spamassassin* squirrelmail*
**IMPORTANT ***

We need to make sure, we've removed the MySQL and PHP from the exclude list.

Step 3: Run the following command to install MariaDB and related packages.

yum install MariaDB-server MariaDB-client MariaDB-devel php-mysql

root@server1 [~]#yum install MariaDB-server MariaDB-client MariaDB-devel php-mysql

Dependencies Resolved

===============================================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================================
Installing:
MariaDB-client x86_64 10.0.23-1.el7.centos mariadb 10 M
MariaDB-devel x86_64 10.0.23-1.el7.centos mariadb 6.3 M
MariaDB-server x86_64 10.0.23-1.el7.centos mariadb 55 M
php-mysql x86_64 5.4.16-36.el7_1 base 99 k
Installing for dependencies:
MariaDB-common x86_64 10.0.23-1.el7.centos mariadb 43 k
MariaDB-shared x86_64 10.0.23-1.el7.centos mariadb 1.2 M
libzip x86_64 0.10.1-8.el7 base 48 k
php-common x86_64 5.4.16-36.el7_1 base 563 k
php-pdo x86_64 5.4.16-36.el7_1 base 97 k

Transaction Summary
===============================================================================================================================================
Install 4 Packages (+5 Dependent package)

Step 4: Restart and make sure the MySQL service is up.

root@server1 [~]# systemctl start mysql
root@server1 [~]#
root@server1 [~]#
root@server1 [~]# systemctl status mysql
● mysql.service - LSB: start and stop MySQL
Loaded: loaded (/etc/rc.d/init.d/mysql)
Active: active (exited) since Sun 2016-01-31 10:01:46 UTC; 3s ago
Docs: man:systemd-sysv-generator(8)
Process: 23717 ExecStart=/etc/rc.d/init.d/mysql start (code=exited, status=0/SUCCESS)
Main PID: 23430 (code=exited, status=203/EXEC)

Jan 31 10:01:46 server1.centos7-test.com systemd[1]: Starting LSB: start and stop MySQL...
Jan 31 10:01:46 server1.centos7-test.com mysql[23717]: Starting MySQL SUCCESS!
Jan 31 10:01:46 server1.centos7-test.com systemd[1]: Started LSB: start and stop MySQL.

Step 5 : Run mysql_upgrade command

It will examine all tables in all databases for incompatibilities with the current installed version and upgrades the system tables if necessary to take advantage of new privileges or capabilities that might have added with the current version.

root@server1 [~]# mysql_upgrade
MySQL upgrade detected
Phase 1/6: Checking and upgrading mysql database
Processing databases
mysql
mysql.columns_priv OK
mysql.db OK
mysql.event OK
mysql.func OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.host OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.servers OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK
Phase 2/6: Fixing views from mysql
Phase 3/6: Running 'mysql_fix_privilege_tables'
Phase 4/6: Fixing table and database names
Phase 5/6: Checking and upgrading tables
Processing databases
cphulkd
cphulkd.auths OK
cphulkd.blacklist OK
cphulkd.brutes OK
cphulkd.good_logins OK
cphulkd.ip_lists OK
cphulkd.known_netblocks OK
cphulkd.login_track OK
cphulkd.logins OK
cphulkd.report OK
cphulkd.whitelist OK
eximstats
eximstats.defers OK
eximstats.failures OK
eximstats.sends OK
eximstats.smtp OK
information_schema
leechprotect
leechprotect.hits OK
modsec
modsec.hits OK
performance_schema
roundcube
roundcube.cache OK
roundcube.cache_index OK
roundcube.cache_messages OK
roundcube.cache_shared OK
roundcube.cache_thread OK
roundcube.contactgroupmembers OK
roundcube.contactgroups OK
roundcube.contacts OK
roundcube.cp_schema_version OK
roundcube.dictionary OK
roundcube.identities OK
roundcube.searches OK
roundcube.session OK
roundcube.system OK
roundcube.users OK
saheetha_test
saheetha_test.authors OK
whmxfer
whmxfer.sessions OK
Phase 6/6: Running 'FLUSH PRIVILEGES'
OK

Step 6 : Restart the MySQL service once again to ensure everything works perfect.

root@server1 [~]# systemctl restart mysql
root@server1 [~]#
root@server1 [~]# systemctl status mysql
● mysql.service - LSB: start and stop MySQL
Loaded: loaded (/etc/rc.d/init.d/mysql)
Active: active (running) since Sun 2016-01-31 10:04:11 UTC; 9s ago
Docs: man:systemd-sysv-generator(8)
Process: 23831 ExecStop=/etc/rc.d/init.d/mysql stop (code=exited, status=0/SUCCESS)
Process: 23854 ExecStart=/etc/rc.d/init.d/mysql start (code=exited, status=0/SUCCESS)
Main PID: 23430 (code=exited, status=203/EXEC)
CGroup: /system.slice/mysql.service
├─23861 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/server1.centos7-test.com.pid
└─23933 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/v...

Jan 31 10:04:10 server1.centos7-test.com systemd[1]: Starting LSB: start and stop MySQL...
Jan 31 10:04:11 server1.centos7-test.com mysql[23854]: Starting MySQL. SUCCESS!
Jan 31 10:04:11 server1.centos7-test.com systemd[1]: Started LSB: start and stop MySQL.

Step 7: Run EasyApache to rebuild Apache/PHP with MariaDB and ensure all PHP modules remains intact.

root@server1 [~]#/scripts/easyapache --build

****IMPORTANT *****
If you forget to rebuild Apache/PHP after the MariaDB installation, it will report the library error as below:

root@server1 [/etc/my.cnf.d]# php -v
php: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory

Step 8: Now verify the installation and databases.

root@server1 [/var/lib/mysql]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 15
Server version: 10.0.23-MariaDB MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show storage engines;
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
| CSV | YES | CSV storage engine | NO | NO | NO |
| MRG_MyISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |
| MyISAM | YES | MyISAM storage engine | NO | NO | NO |
| InnoDB | DEFAULT | Percona-XtraDB, Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| ARCHIVE | YES | Archive storage engine | NO | NO | NO |
| FEDERATED | YES | FederatedX pluggable storage engine | YES | NO | YES |
| PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
| Aria | YES | Crash-safe tables with MyISAM heritage | NO | NO | NO |
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
10 rows in set (0.00 sec)

That's all :). Now we're all set to go with MariaDB with its improved and efficient features. Hope you enjoyed reading this documentation. I would recommend your valuable suggestions and feedback on this!

The post How to Install MariaDB 10 on CentOS 7 CPanel Server appeared first on LinOxide.

How to Install Interworx on CentOS 7

$
0
0

InterWorx is a hosting control panel purely based on Linux. It relies on the RPM package system for distribution of InterWorx itself, as well as for handling various software packages for web hosting platforms. Hence, It strongly recommends to have an RPM-compatible Linux distribution for installation.

In this article, I'm explaning about the installation of this control panel on a CentOS 7 server which is a RPM compatible Linux distribution. Previously the installation on this OS wasn't supported. But I believe you guys will be happy to know that the new Interworx release version 5.1.5 is designed to support the latest RHEL/CentOS distribution.
InterWorx Control Panel runs on a variety of systems and hardware including Virtual Private Server (VPS) systems supported on OpenVZ, Virtuazzo, Xen and VMware. It is also supports CloudLinux platforms.

Minimum hardware requirements

  • Memory : at least 256 MB; 512MB is recommended
  • CPU : Pentium III 866 CPU
  • Disk Space : 512 MB; 1GB is recommeded

Pre-requisites

  • A linux server or a supported VPS systems as mentioned above with atleast minimum hardware requirements is needed.
  • A clean install of the RPM-compatible Linux distribution supported OS is needed.
  • A valid and active InterWorx Control Panel license key is required
  • UIDs 102 - 107 and GIDs 102 & 103 should be free to use.

Installation steps

1. Login to the server as root.

2. Download and run the installer script

sh <((curl -sL interworx.com/inst.sh))

This installation script will prompt you to proceed further. If you don't want to be prompted after each configuration step, you can run the downloader script as below:

sh <((curl -sL interworx.com/inst.sh)) -l

I run the initial installer script to check the installation procedure one by one.

You will receive this prompt on initial setup. You can verify your OS settings ans press "enter" to proceed.

=-=-=-=-= Installing InterWorx-CP =-=-=-=-=-

This script will install InterWorx-CP on your system.
Please make sure that you have backed up any critical
data!

This script may be run multiple times without any
problems. This is helpful if you find an error
during installation, you can safely ctrl-c out of
this script, fix the error and re-start the script.

Details of this installation will be logged in iworx-install.log

TARGET : CentOS Linux release 7.0.1406 (Core)
PLATFORM : GNU/Linux
PROCESSOR : x86_64
RPM TARGET: rhe7x
RPM DISTRO: cos7x
RPM DIR : /usr/src/redhat/RPMS
SRPM DIR : /usr/src/redhat/SRPMS
SRPM HOST : updates.interworx.com
IWORX REPO: release

Press <enter> to begin the install...

Then it will proceed with the installation and remove the following packages listed below if it is pre-existed in the server.

InterWorx-CP needs to remove some packages that may conflict
The following packages will be removed (if they exist)
STATUS: - bind
STATUS: - redhat-config-bind
STATUS: - caching-nameserver
STATUS: - sendmail
STATUS: - postfix
STATUS: - exim
STATUS: - mutt
STATUS: - fetchmail
STATUS: - spamassassin
STATUS: - redhat-lsb
STATUS: - evolution
STATUS: - mod_python
STATUS: - mod_auth_mysql
STATUS: - mod_authz_ldap
STATUS: - mod_auth_pgsql
STATUS: - mod_auth_kerb
STATUS: - mod_perl
STATUS: - mdadm
STATUS: - dovecot
STATUS: - vsftpd
STATUS: - httpd-tools
Is this ok? (Y/n):

After proceeding with this prompt, it will complete the installation and you will get a message which will direct you to the control panel access.

-=-=-=-=-= Installation Complete! Next Step: License Activation! =-=-=-=-=-

To activate your license, go to
http://your-ip:2080/nodeworx/ or
https://your-ip:2443/nodeworx/
Also, check out http://www.interworx.com for news, updates, and support!

-=-=-=-=-= THANK YOU FOR USING INTERWORX! =-=-=-=-=-

You can either activate the license via CLI or you can activate it via browser by logging into the control panel.

Command Line license activation

You can login to the server as root user and run the script as below:

[root@server1 ~]# /home/interworx/bin/goiworx.pex

You will be prompted to provide your license key which will look like this "INTERWORX_XXXXXXXXXX". Enter these details to activate the license via CLI. Make sure, the port 2443 is opened incase your server is firewalled.

License activation from Control Panel

You can login to the control panel using the URL http://your-ip:2080/nodeworx/ or https://your-ip:2443/nodeworx/. Now you will be directed to the login session as below:

interworx installation

Enter the details to proceed. Now you've done with the activation.

Once the license is activated, it will automatically configure the settings for the panel. Wait until the progress bar completes the setup.

interworx_installation_complete

You need to agree the license agreement to proceed and set the DNS to completes the Panel setup.

DNS_intrwx

Now you'll have a Server Manager Panel (Nodeworx) and a Website Manager Panel (Siteworx). This is how you can access it.

Nodeworx:

nodeworx
You can manage your server from Nodeworx and manage your individual domain using Siteworx.

Siteworx:

Click the Siteworx icon next to the domain to access its siteworx panel.

siteworx1

siteworx

How to create a domain in Interworx

You can login to the Nodeworx and navigate through the options Siteworx >> Accounts >> Add Siteworx account to proceed.

account_creation
You can modify its account settings anytime, with the "Edit" option on the left hand side of the created account.

Advantages of Interworx

  • Provides the best performance with Apache 2.4.10 installed with 5.5.44-MariaDB and PHP 5.4.16 with primary installation
  • Provides SPAM filtering and Virus filtering interfaces which can be managed from Panel
  • Provides SNI support
  • Provides high-Availability Load Balancing At A Fraction Of The Price

I hope you guys enjoyed reading this article. It is a very light control panel which can be installed within a few minutes and it has a user friendly interface to manage the accounts efficiently. Since it is an RPM based Control Panel, all software installations/upgrades are independent and can be carried out easily,

I appreciate your valuable comments on this :).

Thank you and have a good day!!

The post How to Install Interworx on CentOS 7 appeared first on LinOxide.

How to Install PrestaShop on CentOS 7

$
0
0

PrestaShop is the most powerful, dynamic and fully-featured free eCommerce software enriched with innovative tools. It is used by more than 2,50,000 people around the world for making their online stores at no cost. It's been used widely across the globe due to its simplicity and efficiency.

If you're planing to start with an online webstore, then you're on the right place. In this article, I'm providing the guidelines on how I installed PrestaShop on my CentOS 7 server to build up my online store.

Pre-requisites

  •  Disable Selinux
  • Install the LAMP stack
  • Create a Database/User
  • Confirm the installation of the PHP modules GD, Mcrypt, Mbstring and PDO MySQL

1. Disable Selinux

Need to edit the selinux configuration file located at : /etc/selinux/config

Modify the SELINUX parameter to disabled and reboot the server.

2. Install the LAMP stack

I've set a proper hostname for my server and start with the LAMP installation. Firstly, install Apache.

[root@server1 ~]# yum install httpd -y

This will install all the required Apache packages. Make sure it is enabled and working in the server.

root@server1 ~]# systemctl enable httpd
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'

[root@server1~]# systemctl status httpd.service
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
Active: active (running) since Tue 2016-02-23 09:18:28 UTC; 2s ago
Docs: man:httpd(8)
man:apachectl(8)
Process: 15550 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
Main PID: 15561 (httpd)
Status: "Processing requests..."
CGroup: /system.slice/httpd.service
├─15561 /usr/sbin/httpd -DFOREGROUND
├─15562 /usr/sbin/httpd -DFOREGROUND
├─15563 /usr/sbin/httpd -DFOREGROUND
├─15564 /usr/sbin/httpd -DFOREGROUND
├─15565 /usr/sbin/httpd -DFOREGROUND
└─15566 /usr/sbin/httpd -DFOREGROUND

Now create the VHOST for the domain which we're planning to install Prestashop. I'm installing Prestashop for my domain saheetha.com.
Here is my Vhost for the domain. Make sure you create the document root and log folders, here it is /var/www/saheetha.com/public_html/ and /var/www/saheetha.com/logs/ before restarting the Apache.

[root@server1 ~]# cat /etc/httpd/conf.d/vhost.conf
NameVirtualHost *:80
<VirtualHost 139.162.54.130:80>
ServerAdmin webmaster@saheetha.com
ServerName saheetha.com
ServerAlias www.saheetha.com
DocumentRoot /var/www/saheetha.com/public_html/
ErrorLog /var/www/saheetha.com/logs/error.log
CustomLog /var/www/saheetha.com/logs/access.log combined
</VirtualHost>

Now install MySQL, I'm installing MySQL 5.5. Download your MySQL Community Repository in your Linux distribution. I downloaded the latest MySQL repo. And installed MySQL 5.5 in my server. Please see the steps I did to choose my required version.

[root@server1 ~]# wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
[root@server1 ~]# yum localinstall mysql57-community-release-el7-7.noarch.rpm
root@server1 ~]# yum install -y yum-utils *//Install the yum-utility packages //*

[root@server1 ~]# yum repolist enabled | grep "mysql.*-community.*" *//Checked the enabled repo before installation //*
mysql-connectors-community/x86_64 MySQL Connectors Community 17
mysql-tools-community/x86_64 MySQL Tools Community 31
mysql57-community/x86_64 MySQL 5.7 Community Server 56

[root@server1 ~]# yum-config-manager --disable mysql57-community *//Disabling MySQL 5.7 repo from installing*//

Loaded plugins: fastestmirror
=========================================================== repo: mysql57-community ===========================================================
[mysql57-community]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/7
baseurl = http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/
cache = 0
cachedir = /var/cache/yum/x86_64/7/mysql57-community
check_config_file_age = True
cost = 1000
deltarpm_metadata_percentage = 100
deltarpm_percentage =
enabled = 0
enablegroups = True
exclude =
failovermethod = priority
gpgcadir = /var/lib/yum/repos/x86_64/7/mysql57-community/gpgcadir
gpgcakey =
gpgcheck = True
gpgdir = /var/lib/yum/repos/x86_64/7/mysql57-community/gpgdir
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
hdrdir = /var/cache/yum/x86_64/7/mysql57-community/headers
http_caching = all
includepkgs =
ip_resolve =
keepalive = True
keepcache = False
mddownloadpolicy = sqlite
mdpolicy = group:small
mediaid =
metadata_expire = 21600
metadata_expire_filter = read-only:present
metalink =
minrate = 0
mirrorlist =
mirrorlist_expire = 86400
name = MySQL 5.7 Community Server
old_base_cache_dir =
password =
persistdir = /var/lib/yum/repos/x86_64/7/mysql57-community
pkgdir = /var/cache/yum/x86_64/7/mysql57-community/packages
proxy = False
proxy_dict =
proxy_password =
proxy_username =
repo_gpgcheck = False
retries = 10
skip_if_unavailable = False
ssl_check_cert_permissions = True
sslcacert =
sslclientcert =
sslclientkey =
sslverify = True
throttle = 0
timeout = 30.0
ui_id = mysql57-community/x86_64
ui_repoid_vars = releasever,
basearch
username =

[root@server1 ~]# yum-config-manager --enable mysql55-community *//Enabling the MySQL 5.5 Repo from the Yum repository //*
Loaded plugins: fastestmirror
=========================================================== repo: mysql55-community ===========================================================
[mysql55-community]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/7
baseurl = http://repo.mysql.com/yum/mysql-5.5-community/el/7/x86_64/
cache = 0
cachedir = /var/cache/yum/x86_64/7/mysql55-community
check_config_file_age = True
cost = 1000
deltarpm_metadata_percentage = 100
deltarpm_percentage =
enabled = 1
enablegroups = True
exclude =
failovermethod = priority
gpgcadir = /var/lib/yum/repos/x86_64/7/mysql55-community/gpgcadir
gpgcakey =
gpgcheck = True
gpgdir = /var/lib/yum/repos/x86_64/7/mysql55-community/gpgdir
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
hdrdir = /var/cache/yum/x86_64/7/mysql55-community/headers
http_caching = all
includepkgs =
ip_resolve =
keepalive = True
keepcache = False
mddownloadpolicy = sqlite
mdpolicy = group:small
mediaid =
metadata_expire = 21600
metadata_expire_filter = read-only:present
metalink =
minrate = 0
mirrorlist =
mirrorlist_expire = 86400
name = MySQL 5.5 Community Server
old_base_cache_dir =
password =
persistdir = /var/lib/yum/repos/x86_64/7/mysql55-community
pkgdir = /var/cache/yum/x86_64/7/mysql55-community/packages
proxy = False
proxy_dict =
proxy_password =
proxy_username =
repo_gpgcheck = False
retries = 10
skip_if_unavailable = False
ssl_check_cert_permissions = True
sslcacert =
sslclientcert =
sslclientkey =
sslverify = True
throttle = 0
timeout = 30.0
ui_id = mysql55-community/x86_64
ui_repoid_vars = releasever,
basearch
username =

[root@localhost ~]# yum repolist enabled | grep "mysql.*-community.*" *//Confirm the enabled MySQL repo versions //*
mysql-connectors-community/x86_64 MySQL Connectors Community 17
mysql-tools-community/x86_64 MySQL Tools Community 31
mysql55-community/x86_64 MySQL 5.5 Community Server 199
Now install the MySQL 5.5 from the Repo.

[root@server1~]# yum install mysql-community-server

After completing with the installation, start the MySQL service and confirm its status.

[root@server1 ~]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
[root@server1 ~]#
[root@server1 ~]#
[root@server1 ~]# systemctl status mysqld.service
mysqld.service - MySQL Community Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled)
Active: active (running) since Tue 2016-02-23 09:27:44 UTC; 8s ago
Process: 15717 ExecStartPost=/usr/bin/mysql-systemd-start post (code=exited, status=0/SUCCESS)
Process: 15664 ExecStartPre=/usr/bin/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 15716 (mysqld_safe)
CGroup: /system.slice/mysqld.service
├─15716 /bin/sh /usr/bin/mysqld_safe
└─15862 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mysqld...

Feb 23 09:27:42 server1.centos7-test.com mysql-systemd-start[15664]: Alternatively you can run:
Feb 23 09:27:42 server1.centos7-test.com mysql-systemd-start[15664]: /usr/bin/mysql_secure_installation
Feb 23 09:27:42 server1.centos7-test.com mysql-systemd-start[15664]: which will also give you the option of removing the test
Feb 23 09:27:42 server1.centos7-test.com mysql-systemd-start[15664]: databases and anonymous user created by default. This is
Feb 23 09:27:42 server1.centos7-test.com mysql-systemd-start[15664]: strongly recommended for production servers.
Feb 23 09:27:42 server1.centos7-test.com mysql-systemd-start[15664]: See the manual for more instructions.
Feb 23 09:27:42 server1.centos7-test.com mysql-systemd-start[15664]: Please report any problems at http://bugs.mysql.com/
Feb 23 09:27:42 server1.centos7-test.com mysqld_safe[15716]: 160223 09:27:42 mysqld_safe Logging to '/var/log/mysqld.log'.
Feb 23 09:27:42 server1.centos7-test.com mysqld_safe[15716]: 160223 09:27:42 mysqld_safe Starting mysqld daemon with databases from /v.../mysql
Feb 23 09:27:44 server1.centos7-test.com systemd[1]: Started MySQL Community Server.
Hint: Some lines were ellipsized, use -l to show in full.

[root@server1 ~]# mysql --version
mysql Ver 14.14 Distrib 5.5.48, for Linux (x86_64) using readline 5.1

Now you can run the MySQL secure installation script to secure your MySQL installation by removing remote root login, setting root password, disabling anonymous users etc as needed.

root@server1 ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
... Success!

Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
... Success!

By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] n
... skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
... Success!

Cleaning up...

All done! If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

Now it's time for PHP. Install the PHP with all required modules.

[root@server1 ~]# yum install php-mcrypt php php-common php-pdo php-cli php-mysql php-gd php-xml libtool-ltdl mhash mcrypt -y

[root@server1 ~]# php -v
PHP 5.4.16 (cli) (built: Jun 23 2015 21:17:27)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

3. Create a Database/User

Now create a database for Prestashop installation. I created a database namely prestashopdb and user prestashopuser prior to the installation. You can do it from MySQL CLI or you can install PhpMyadmin and manage databases using that.

[root@server1 ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.5.48 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database prestashopdb;
Query OK, 1 row affected (0.00 sec)

mysql> GRANT ALL ON prestashopdb.* TO prestashopuser@localhost IDENTIFIED BY 'prestashop123#';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

4. Confirm the installation of the PHP modules GD, Mcrypt, Mbstring and PDO MySQL

PHP modules like GD and PDO MySQL are installed during the initial PHP setup. I need to enable the Mcrypt and MBstring module to complete the pre-requisites for the Prestashop installation.

Mcrypt Installation:

Install EPEL repo for YUM
yum -y install epel-release
yum install php-mcrypt -y

MBstring installation

yum install php-mbstring -y

Installing Prestashop

Download the latest Prestashop version from the link and extract it in the home folder. Modify the permissions of the folders/files to 755.

root@server1 home]# unzip prestashop_1.6.1.2.zip
root@server1 prestashop]# chmod -R 755 *.*
[root@server1 prestashop]# ll
total 160
drwxr-xr-x 2 root root 4096 Feb 23 09:45 Adapter
drwxr-xr-x 9 root root 4096 Feb 23 09:45 admin
-rwxr-xr-x 1 root root 12320 Oct 29 16:16 architecture.md
drwxr-xr-x 8 root root 4096 Feb 23 09:45 cache
drwxr-xr-x 17 root root 4096 Feb 23 09:45 classes
drwxr-xr-x 3 root root 4096 Feb 23 09:45 config
-rwxr-xr-x 1 root root 3617 Oct 29 16:16 CONTRIBUTING.md
-rwxr-xr-x 1 root root 5847 Oct 29 16:17 CONTRIBUTORS.md
drwxr-xr-x 4 root root 4096 Feb 23 09:45 controllers
drwxr-xr-x 4 root root 4096 Feb 23 09:45 Core
drwxr-xr-x 2 root root 4096 Feb 23 09:45 css
drwxr-xr-x 4 root root 4096 Feb 23 09:45 docs
drwxr-xr-x 2 root root 4096 Feb 23 09:45 download
-rwxr-xr-x 1 root root 2454 Oct 29 16:16 error500.html
-rwxr-xr-x 1 root root 1218 Oct 29 16:16 footer.php
-rwxr-xr-x 1 root root 1247 Oct 29 16:16 header.php
-rwxr-xr-x 1 root root 4717 Oct 29 16:16 images.inc.php
drwxr-xr-x 18 root root 4096 Feb 23 09:45 img
-rwxr-xr-x 1 root root 1068 Oct 29 16:16 index.php
-rwxr-xr-x 1 root root 1154 Oct 29 16:16 init.php
drwxr-xr-x 12 root root 4096 Feb 23 09:45 install
drwxr-xr-x 7 root root 4096 Feb 23 09:45 js
drwxr-xr-x 2 root root 4096 Feb 23 09:45 localization
drwxr-xr-x 2 root root 4096 Feb 23 09:45 log
drwxr-xr-x 3 root root 4096 Feb 23 09:45 mails
drwxr-xr-x 79 root root 4096 Feb 23 09:45 modules
drwxr-xr-x 5 root root 4096 Feb 23 09:45 override
drwxr-xr-x 2 root root 4096 Feb 23 09:45 pdf
-rwxr-xr-x 1 root root 6576 Oct 29 16:16 README.md
drwxr-xr-x 3 root root 4096 Feb 23 09:45 themes
drwxr-xr-x 18 root root 4096 Feb 23 09:45 tools
drwxr-xr-x 3 root root 4096 Feb 23 09:45 translations
drwxr-xr-x 2 root root 4096 Feb 23 09:45 upload
drwxr-xr-x 2 root root 4096 Feb 23 09:45 webservice

root@server1 home]# cp -rp prestashop/* /var/www/saheetha.com/public_html/

Now copy the prestashop folder contents from /home to document root of the required domain which is meant to be our online store. It is this path "/var/www/saheetha.com/public_html/" in my case.

Now open up in your browser the URL >>http://domain.com/install/

Please navigate through the screenshots which describes each installation stage.

Stage 1 : Language Selection

prest1

Stage 2 : License Agreement 

Agree the terms and conditions in the license agreement and click "Next" to proceed further.

 

license2

Stage 3 : System Compatibility check 

It will check for the installation of the required PHP modules and folders/file permissions to continue with the installation.

prestashop3

Stage 4: Creating your own Store information:

Pres5DBconnec

Stage 6 : Installation Stage

pres6config

Stage 7 : Final Stage

It will provide you with the login credentials to manages your Online store.

pres7

Now you're all set with your installation.  Please make sure to delete your "Install" folder from your domain document root for security reasons.

How can we access the Admin Panel?

Before accessing the admin Panel for our installation, you need to rename your "admin" folder under the installation domain document root to some other name for security reasons. Or else you will get a message like this on the browser while accessing your admin panel.

For security reasons, you cannot connect to the back office until you have
renamed the /admin folder (e.g. admin847v0u8kk/)
Please then access this page by the new URL (e.g. http://saheetha.com/admin847v0u8kk/)

I renamed my admin folder and accessed my admin panel with the login credentials.  You can manage your products, orders, customers, price details etc from this.

prestashop_saheethaadmin

Now you can head over to the Prestashop user manuals  to learn more about managing your Online store.

You see how easy you can build up an online webstore using this software. Congratulation on your new venture with e-shops :).  I hope you enjoyed reading this article. I recommend your valuable comments and suggestions on this.

Have a Good Day!

The post How to Install PrestaShop on CentOS 7 appeared first on LinOxide.


How to Build a Minecraft Server on your CentOS 7

$
0
0

MINECRAFT is an open world video game developed in Java, originally created by Markus "Notch" Persson and maintained by Mojang AB. It is presently owned by Microsoft studios as well. This game involves players interacting within by placing and breaking various types of blocks in a three-dimensional environment. The players can even  collect resources, build structures, battle mobs, manage hunger, explore the land  simply, creates & destroys structures on both multiplayer servers and singleplayer worlds across multiple game modes. These are the six game modes available as below:

  • Survival
  • Creative
  • Hardcore
  • Adventure
  • Spectator
  • Demo

In this article, I'm discussing on how to setup a Minecraft server on a CentOS 7 build.

minecraft-server-logo

First of all, let me go through the installation requirements.

Prerequisites

  •  VPS or Dedicated servers with SSH access
  •  RAM : 1GB or more
  •  Disk Space : 5GB or more
  •  Install the latest Java compatible with the OS architecture.
  •  Disable Selinux

Let us start with the installation procedures. We need to install the latest Java version for the server depending on its architecture.

Install JAVA

Minecraft server requires the latest JAVA version to be installed and running.

root@server1 ~]#yum install java-1.6.0-openjdk

===============================================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================================
Installing:
java-1.6.0-openjdk x86_64 1:1.6.0.38-1.13.10.0.el7_2 updates 42 M
Installing for dependencies:
alsa-lib x86_64 1.0.28-2.el7 base 391 k
flac-libs x86_64 1.3.0-5.el7_1 base 169 k
fontconfig x86_64 2.10.95-7.el7 base 228 k
fontpackages-filesystem noarch 1.44-8.el7 base 9.9 k
giflib x86_64 4.1.6-9.el7 base 40 k
gsm x86_64 1.0.13-11.el7 base 30 k
javapackages-tools noarch 3.4.1-11.el7 base 73 k
libICE x86_64 1.0.9-2.el7 base 65 k
libSM x86_64 1.2.2-2.el7 base 39 k
libX11 x86_64 1.6.3-2.el7 base 605 k
libX11-common noarch 1.6.3-2.el7 base 162 k
libXau x86_64 1.0.8-2.1.el7 base 29 k
libXext x86_64 1.3.3-3.el7 base 39 k
libXi x86_64 1.7.4-2.el7 base 40 k
libXrender x86_64 0.9.8-2.1.el7 base 25 k
libXtst x86_64 1.2.2-2.1.el7 base 20 k
libasyncns x86_64 0.8-7.el7 base 26 k
libjpeg-turbo x86_64 1.2.90-5.el7 base 134 k
libogg x86_64 2:1.3.0-7.el7 base 24 k
libpng x86_64 2:1.5.13-7.el7_2 updates 213 k
libsndfile x86_64 1.0.25-10.el7 base 149 k
libvorbis x86_64 1:1.3.3-8.el7 base 204 k
libxcb x86_64 1.11-4.el7 base 189 k
libxslt x86_64 1.1.28-5.el7 base 242 k
pulseaudio-libs x86_64 6.0-7.el7 base 576 k
python-javapackages noarch 3.4.1-11.el7 base 31 k
python-lxml x86_64 3.2.1-4.el7 base 758 k
tzdata-java noarch 2016a-1.el7 updates 176 k

These many packages will be installed. Now we need to download the Minecraft server package from there website into the "minecraft" folder.

Create a MINECRAFT folder

Create a minecraft folder for the installation and other game files. It is always advised to run this executable inside a dedicated folder, as it creates several configuration files. This will make it more easier to organize and locate all the files.

root@server1 ~]#mkdir minecraft
[root@server1 ~]# cd minecraft

Download the Minecraft server jar file

Download the minecraft .jar file to the minecraft folder and modify the .jar file permissions to make it executable.

[root@server1 minecraft]# wget https://minecraft.net/download/minecraft_server.jar
--2016-03-09 07:28:39-- https://minecraft.net/download/minecraft_server.jar
Connecting to minecraft.net (minecraft.net)|54.192.151.239|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft_server.jar [following]
--2016-03-09 07:28:39-- https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft_server.jar
Resolving s3.amazonaws.com (s3.amazonaws.com)... 54.231.81.212
Connecting to s3.amazonaws.com (s3.amazonaws.com)|54.231.81.212|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2360903 (2.3M) [application/octet-stream]
Saving to: ‘minecraft_server.jar’

100%[=====================================================================================================>] 23,60,903 84.3KB/s in 28s

2016-03-09 07:29:09 (81.7 KB/s) - ‘minecraft_server.jar’ saved [2360903/2360903]

[root@server1 minecraft]# chmod +x minecraft_server.jar

Make sure Screen is installed in your server or else run this command to install screen for your server.

[root@server1 minecraft]# yum install screen

Run the Application

Now get into a screen session and run the minecraft .jar file as per the required resolution and hardware settings. Both the Java and the executable version can be run from the command line with extra parameters to configure depending on the memory, graphical interface, mode, architecture etc.

Depending on my server capability, I prefer to ran my Minecraft server on 512MB without graphical interface to lower the CPU and memory resource usages.

root@server1 minecraft]# java -Xmx512M -Xms512M -jar minecraft_server.jar nogui

The launching text will look like this:
229 recipes
27 achievements
2016-03-09 07:30:09 [INFO] Starting minecraft server version 1.5.2
2016-03-09 07:30:09 [WARNING] To start the server with more ram, launch it as "java -Xmx1024M -Xms1024M -jar minecraft_server.jar"
2016-03-09 07:30:09 [INFO] Loading properties
2016-03-09 07:30:09 [WARNING] server.properties does not exist
2016-03-09 07:30:09 [INFO] Generating new properties file
2016-03-09 07:30:09 [INFO] Default game type: SURVIVAL
2016-03-09 07:30:09 [INFO] Generating keypair
2016-03-09 07:30:09 [INFO] Starting Minecraft server on *:25565
2016-03-09 07:30:09 [WARNING] Failed to load operators list: java.io.FileNotFoundException: ./ops.txt (No such file or directory)
2016-03-09 07:30:09 [WARNING] Failed to load white-list: java.io.FileNotFoundException: ./white-list.txt (No such file or directory)
2016-03-09 07:30:09 [INFO] Preparing level "world"
2016-03-09 07:30:10 [INFO] Preparing start region for level 0
2016-03-09 07:30:11 [INFO] Preparing spawn area: 4%
2016-03-09 07:30:12 [INFO] Preparing spawn area: 9%
2016-03-09 07:30:13 [INFO] Preparing spawn area: 16%
2016-03-09 07:30:14 [INFO] Preparing spawn area: 24%
2016-03-09 07:30:15 [INFO] Preparing spawn area: 35%
2016-03-09 07:30:16 [INFO] Preparing spawn area: 45%
2016-03-09 07:30:17 [INFO] Preparing spawn area: 55%
2016-03-09 07:30:18 [INFO] Preparing spawn area: 61%
2016-03-09 07:30:19 [INFO] Preparing spawn area: 70%
2016-03-09 07:30:20 [INFO] Preparing spawn area: 78%
2016-03-09 07:30:21 [INFO] Preparing spawn area: 84%
2016-03-09 07:30:22 [INFO] Preparing spawn area: 95%
2016-03-09 07:30:23 [INFO] Done (13.396s)! For help, type "help" or "?"

You can get back to your normal screen by press ctrl +A +D

You can get back to the screen where Minecraft is running by using the screen resume command.
# screen -r (screenid)
You can even run this executable using 1GB memory or more depending on your server specifications. This is how we run for 1GB memory usage.

java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui
Tip: If you want to spare more memory, you may set the -Xms parameter with a lower value, say:

java -Xms512M -Xmx1024M -jar minecraft_server.jar nogui

The parameter controls how much memory is reserved on startup. Your server will start with 512MB RAM and whenever it needs more memory it will allocate some until it reaches the allotted maximum value of 1GB.

Hurray!! Your Minecraft is all set and it should be running good. You can have your friends login to your server and start building.

You can have any number of players depending on your server resources. There is a software called Multicraft to manage your Minecraft servers. You can download this software from their official website and use it as a user friendly control Panel managing your MC servers.
I hope you enjoyed reading this article. I would recommend your valuable suggestions and comments on this.

Thank you and have a great day :)

The post How to Build a Minecraft Server on your CentOS 7 appeared first on LinOxide.

How to Secure CentOS 7 Server with ModSecurity

$
0
0

ModSecurity is an open source web application firewall which enables web application defenders to gain visibility into HTTP traffic and provides powerful rule sets to enhance high security and protection. It provides a full package with real-time web monitoring, logging and access control. The rule sets can be customized and managed according to the user preferences. The freedom to choose what to do is an essential advantage of ModSecurity and really adds to the context of an open source. With full access to the source code, we've the ability to customize and extend the tool to fit our needs.

In this article, I'm explaining how to install and configure ModSecurity on a CentOS 7 server. Let's walk through the installation steps.

First of all, I would like to verify the server settings, mainly the present Apache version and the modules installed.

[root@server1 ~]# httpd -V
Server version: Apache/2.4.6 (CentOS)
Server built: Nov 19 2015 21:43:13
Server's Module Magic Number: 20120211:24
Server loaded: APR 1.4.8, APR-UTIL 1.5.2
Compiled using: APR 1.4.8, APR-UTIL 1.5.2
Architecture: 64-bit
Server MPM: prefork
threaded: no
forked: yes (variable process count)
Server compiled with....
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_SYSVSEM_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=256
-D HTTPD_ROOT="/etc/httpd"
-D SUEXEC_BIN="/usr/sbin/suexec"
-D DEFAULT_PIDLOG="/run/httpd/httpd.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="conf/mime.types"
-D SERVER_CONFIG_FILE="conf/httpd.conf"

You can use these command to identify the dynamically compiled modules enabled with Apache.

[root@server1 ~]# httpd -M
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
access_compat_module (shared)
actions_module (shared)
alias_module (shared)
allowmethods_module (shared)
auth_basic_module (shared)
auth_digest_module (shared)
authn_anon_module (shared)
authn_core_module (shared)
authn_dbd_module (shared)
authn_dbm_module (shared)
authn_file_module (shared)
authn_socache_module (shared)
authz_core_module (shared)
authz_dbd_module (shared)
authz_dbm_module (shared)
authz_groupfile_module (shared)
authz_host_module (shared)
authz_owner_module (shared)
authz_user_module (shared)
autoindex_module (shared)
cache_module (shared)
cache_disk_module (shared)
data_module (shared)
dbd_module (shared)
deflate_module (shared)
dir_module (shared)
dumpio_module (shared)
echo_module (shared)
env_module (shared)
expires_module (shared)
ext_filter_module (shared)
filter_module (shared)
headers_module (shared)
include_module (shared)
info_module (shared)
log_config_module (shared)
logio_module (shared)
mime_magic_module (shared)
mime_module (shared)
negotiation_module (shared)
remoteip_module (shared)
reqtimeout_module (shared)
rewrite_module (shared)
setenvif_module (shared)
slotmem_plain_module (shared)
slotmem_shm_module (shared)
socache_dbm_module (shared)
socache_memcache_module (shared)
socache_shmcb_module (shared)
status_module (shared)
substitute_module (shared)
suexec_module (shared)
unique_id_module (shared)
unixd_module (shared)
userdir_module (shared)
version_module (shared)
vhost_alias_module (shared)
dav_module (shared)
dav_fs_module (shared)
dav_lock_module (shared)
lua_module (shared)
mpm_prefork_module (shared)
proxy_module (shared)
lbmethod_bybusyness_module (shared)
lbmethod_byrequests_module (shared)
lbmethod_bytraffic_module (shared)
lbmethod_heartbeat_module (shared)
proxy_ajp_module (shared)
proxy_balancer_module (shared)
proxy_connect_module (shared)
proxy_express_module (shared)
proxy_fcgi_module (shared)
proxy_fdpass_module (shared)
proxy_ftp_module (shared)
proxy_http_module (shared)
proxy_scgi_module (shared)
proxy_wstunnel_module (shared)
systemd_module (shared)
cgi_module (shared)
php5_module (shared)

Installation

Once verifying the Apache setup, you can install ModSecurity package from the  CentOS base repo.

[root@server1 yum.repos.d]# yum install mod_security -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.metrocast.net
* extras: mirror.metrocast.net
* updates: mirror.metrocast.net
Resolving Dependencies
--> Running transaction check
---> Package mod_security.x86_64 0:2.7.3-5.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================================
Installing:
mod_security x86_64 2.7.3-5.el7 base 177 k

Transaction Summary
===============================================================================================================================================
Install 1 Package

This will install the mod_security on your server. Now we need to configure it on our server.

Check and confirm the integration of the module to Apache

Check for the configuration file generated with the default set of rules. The configuration file will be located inside the Apache custom modules folder "/etc/httpd/conf.d/".

[root@server1 conf.d]# pwd
/etc/httpd/conf.d
[root@server1 conf.d]# ll mod_security.conf
-rw-r--r-- 1 root root 2139 Jun 10 2014 mod_security.conf

[root@server1 conf.d]# httpd -M | grep security
security2_module (shared)

Now restart the Apache and verify whether the Mod_security module is loaded on restart in the Apache logs.

[root@server1 conf.d]# tail -f /etc/httpd/logs/error_log
Mon Apr 18 06:24:35.170359 2016] [suexec:notice] [pid 2819] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Mon Apr 18 06:24:35.170461 2016] [:notice] [pid 2819] ModSecurity for Apache/2.7.3 (http://www.modsecurity.org/) configured.
[Mon Apr 18 06:24:35.170469 2016] [:notice] [pid 2819] ModSecurity: APR compiled version="1.4.8"; loaded version="1.4.8"
[Mon Apr 18 06:24:35.170476 2016] [:notice] [pid 2819] ModSecurity: PCRE compiled version="8.32 "; loaded version="8.32 2012-11-30"
[Mon Apr 18 06:24:35.170483 2016] [:notice] [pid 2819] ModSecurity: LUA compiled version="Lua 5.1"
[Mon Apr 18 06:24:35.170488 2016] [:notice] [pid 2819] ModSecurity: LIBXML compiled version="2.9.1"
[Mon Apr 18 06:24:35.451568 2016] [auth_digest:notice] [pid 2819] AH01757: generating secret for digest authentication ...
[Mon Apr 18 06:24:35.452305 2016] [lbmethod_heartbeat:notice] [pid 2819] AH02282: No slotmem from mod_heartmonitor
[Mon Apr 18 06:24:35.501101 2016] [mpm_prefork:notice] [pid 2819] AH00163: Apache/2.4.6 (CentOS) PHP/5.4.16 configured -- resuming normal operations

From the logs, you can identify the ModSecurity version loaded and other details.

Identifying the Nature

We need to go through the ModSecurity configuration file to identify the include path for the custom rules which we can add for customization and also identify the log file path for further analysis.

We can add the custom rules inside this path according to the configuration.

# ModSecurity Core Rules Set configuration
IncludeOptional modsecurity.d/*.conf
IncludeOptional modsecurity.d/activated_rules/*.conf

[root@server1 modsecurity.d]# pwd
/etc/httpd/modsecurity.d
[root@server1 modsecurity.d]# ll
total 4
drwxr-xr-x 2 root root 4096 Jun 10 2014 activated_rules

And we can inspect the log file at /var/log/httpd/modsec_audit.log

Customizing ModSecurity with the Core rule sets

We can get the custom rule sets from the official repo. These rule sets are automatically symlinked to the activated rules and make it effective on install by default.

root@server1 conf.d]# yum -y install mod_security_crs
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.metrocast.net
* extras: mirror.metrocast.net
* updates: mirror.metrocast.net
Resolving Dependencies
--> Running transaction check
---> Package mod_security_crs.noarch 0:2.2.6-6.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================================
Installing:
mod_security_crs noarch 2.2.6-6.el7 base 90 k

These are the general core rule sets installed from the official repo file. We need to modify certain rules to prevent  from blocking the legitimate server requests.

[root@server1 base_rules]# ll
total 332
-rw-r--r-- 1 root root 1980 Jun 9 2014 modsecurity_35_bad_robots.data
-rw-r--r-- 1 root root 386 Jun 9 2014 modsecurity_35_scanners.data
-rw-r--r-- 1 root root 3928 Jun 9 2014 modsecurity_40_generic_attacks.data
-rw-r--r-- 1 root root 2610 Jun 9 2014 modsecurity_41_sql_injection_attacks.data
-rw-r--r-- 1 root root 2224 Jun 9 2014 modsecurity_50_outbound.data
-rw-r--r-- 1 root root 56714 Jun 9 2014 modsecurity_50_outbound_malware.data
-rw-r--r-- 1 root root 22861 Jun 9 2014 modsecurity_crs_20_protocol_violations.conf
-rw-r--r-- 1 root root 6915 Jun 9 2014 modsecurity_crs_21_protocol_anomalies.conf
-rw-r--r-- 1 root root 3792 Jun 9 2014 modsecurity_crs_23_request_limits.conf
-rw-r--r-- 1 root root 6933 Jun 9 2014 modsecurity_crs_30_http_policy.conf
-rw-r--r-- 1 root root 5394 Jun 9 2014 modsecurity_crs_35_bad_robots.conf
-rw-r--r-- 1 root root 19157 Jun 9 2014 modsecurity_crs_40_generic_attacks.conf
-rw-r--r-- 1 root root 43961 Jun 9 2014 modsecurity_crs_41_sql_injection_attacks.conf
-rw-r--r-- 1 root root 87470 Jun 9 2014 modsecurity_crs_41_xss_attacks.conf
-rw-r--r-- 1 root root 1795 Jun 9 2014 modsecurity_crs_42_tight_security.conf
-rw-r--r-- 1 root root 3660 Jun 9 2014 modsecurity_crs_45_trojans.conf
-rw-r--r-- 1 root root 2253 Jun 9 2014 modsecurity_crs_47_common_exceptions.conf
-rw-r--r-- 1 root root 2787 Jun 9 2014 modsecurity_crs_48_local_exceptions.conf.example
-rw-r--r-- 1 root root 1835 Jun 9 2014 modsecurity_crs_49_inbound_blocking.conf
-rw-r--r-- 1 root root 22314 Jun 9 2014 modsecurity_crs_50_outbound.conf
-rw-r--r-- 1 root root 1448 Jun 9 2014 modsecurity_crs_59_outbound_blocking.conf
-rw-r--r-- 1 root root 2674 Jun 9 2014 modsecurity_crs_60_correlation.conf
[root@server1 base_rules]# pwd
/usr/lib/modsecurity.d/base_rules

These rules are automatically symlinked to the activated rule set to enable by default on installation.

[root@server1 activated_rules]# ls
modsecurity_35_bad_robots.data modsecurity_crs_23_request_limits.conf modsecurity_crs_47_common_exceptions.conf
modsecurity_35_scanners.data modsecurity_crs_30_http_policy.conf modsecurity_crs_48_local_exceptions.conf.example
modsecurity_40_generic_attacks.data modsecurity_crs_35_bad_robots.conf modsecurity_crs_49_inbound_blocking.conf
modsecurity_41_sql_injection_attacks.data modsecurity_crs_40_generic_attacks.conf modsecurity_crs_50_outbound.conf
modsecurity_50_outbound.data modsecurity_crs_41_sql_injection_attacks.conf modsecurity_crs_59_outbound_blocking.conf
modsecurity_50_outbound_malware.data modsecurity_crs_41_xss_attacks.conf modsecurity_crs_60_correlation.conf
modsecurity_crs_20_protocol_violations.conf modsecurity_crs_42_tight_security.conf
modsecurity_crs_21_protocol_anomalies.conf modsecurity_crs_45_trojans.conf
[root@server1 activated_rules]# pwd
/etc/httpd/modsecurity.d/activated_rules

 

We can even customize your ModSecurity by choosing the rule set from OWASP CRS.

OWASP ModSecurity CRS provides a set of generic attack detection rules to ensure baselevel protection for the Web Applications. We can make it more complex as per our security needs. OWASP CRS too provides protections in the following categories:

HTTP Protection
Real-time Blacklist Lookups
DDOS Attacks
Common Web Attacks Protection
Automation Detection - Detecting bots, crawlers, scanners and other surface malicious activity.
Detects Malicious File uploads via Web with AV Scanning
Tracking Sensitive Data - Tracks Credit Card usage and blocks leakages.
Trojan Protection
Identification of Application Defects
Error Detection and Hiding
You can refer this guide OWASP CRS directives to configure our own rule sets.

To install OWASP CRS rule set instead of the default generic rules from the official repo. You can download the OWASP CRS and copy the configuration file and rule sets to the /etc/httpd/modsecurity.d/ folder.

Before enabling OWASP Core Rule set, you can remove modsecurity_crs which is enabled from the repo.

Now go to the /usr/local/src folder and download the repo file from  OWASP CRS download.

[root@server1 src]# wget https://github.com/SpiderLabs/owasp-modsecurity-crs/zipball/master
--2016-04-18 08:28:01-- https://github.com/SpiderLabs/owasp-modsecurity-crs/zipball/master
Resolving github.com (github.com)... 192.30.252.131
Connecting to github.com (github.com)|192.30.252.131|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/SpiderLabs/owasp-modsecurity-crs/legacy.zip/master [following]
--2016-04-18 08:28:01-- https://codeload.github.com/SpiderLabs/owasp-modsecurity-crs/legacy.zip/master
Resolving codeload.github.com (codeload.github.com)... 192.30.252.161
Connecting to codeload.github.com (codeload.github.com)|192.30.252.161|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/zip]
Saving to: ‘master’

[ <=> ] 3,43,983 --.-K/s in 0.04s

2016-04-18 08:28:02 (7.68 MB/s) - ‘master’ saved [343983]

Since the downloaded file is a zip file, extract the file for the contents.

[root@server1 src]# file master
master: Zip archive data, at least v1.0 to extract

root@server1 src]# unzip master

root@server1 src]# ls
master SpiderLabs-owasp-modsecurity-crs-f16e0b1

Once the files are downloaded, copy the crs configuration file and the base rule set to the location /etc/httpd/modsecurity.d/

[root@server1 modsecurity.d]# cp -rp /usr/local/src/SpiderLabs-owasp-modsecurity-crs-f16e0b1/modsecurity_crs_10_setup.conf.example .
[root@server1 modsecurity.d]# ls
activated_rules modsecurity_crs_10_setup.conf.example
[root@server1 modsecurity.d]# mv modsecurity_crs_10_setup.conf.example modsecurity_crs_10_setup.conf

Now change the directory to the activated_rules folder and copy the base rules from the installation to that.

[root@server1 modsecurity.d]# cd activated_rules/

[root@server1 activated_rules]# cp -rp /usr/local/src/SpiderLabs-owasp-modsecurity-crs-f16e0b1/base_rules/* .
[root@server1 activated_rules]# ll
total 344
-rw-r--r-- 1 root root 1969 Apr 14 08:49 modsecurity_35_bad_robots.data
-rw-r--r-- 1 root root 386 Apr 14 08:49 modsecurity_35_scanners.data
-rw-r--r-- 1 root root 3928 Apr 14 08:49 modsecurity_40_generic_attacks.data
-rw-r--r-- 1 root root 2224 Apr 14 08:49 modsecurity_50_outbound.data
-rw-r--r-- 1 root root 56714 Apr 14 08:49 modsecurity_50_outbound_malware.data
-rw-r--r-- 1 root root 23038 Apr 14 08:49 modsecurity_crs_20_protocol_violations.conf
-rw-r--r-- 1 root root 8107 Apr 14 08:49 modsecurity_crs_21_protocol_anomalies.conf
-rw-r--r-- 1 root root 3792 Apr 14 08:49 modsecurity_crs_23_request_limits.conf
-rw-r--r-- 1 root root 6907 Apr 14 08:49 modsecurity_crs_30_http_policy.conf
-rw-r--r-- 1 root root 5410 Apr 14 08:49 modsecurity_crs_35_bad_robots.conf
-rw-r--r-- 1 root root 20881 Apr 14 08:49 modsecurity_crs_40_generic_attacks.conf
-rw-r--r-- 1 root root 44677 Apr 14 08:49 modsecurity_crs_41_sql_injection_attacks.conf
-rw-r--r-- 1 root root 99654 Apr 14 08:49 modsecurity_crs_41_xss_attacks.conf
-rw-r--r-- 1 root root 1795 Apr 14 08:49 modsecurity_crs_42_tight_security.conf
-rw-r--r-- 1 root root 3660 Apr 14 08:49 modsecurity_crs_45_trojans.conf
-rw-r--r-- 1 root root 2247 Apr 14 08:49 modsecurity_crs_47_common_exceptions.conf
-rw-r--r-- 1 root root 2787 Apr 14 08:49 modsecurity_crs_48_local_exceptions.conf.example
-rw-r--r-- 1 root root 1838 Apr 14 08:49 modsecurity_crs_49_inbound_blocking.conf
-rw-r--r-- 1 root root 22328 Apr 14 08:49 modsecurity_crs_50_outbound.conf
-rw-r--r-- 1 root root 1448 Apr 14 08:49 modsecurity_crs_59_outbound_blocking.conf
-rw-r--r-- 1 root root 2674 Apr 14 08:49 modsecurity_crs_60_correlation.conf

Once the rules are copied, you can restart the Apache and confirm its status to make sure everything is configured correctly.

[root@server1 activated_rules]# systemctl status httpd
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
Active: active (running) since Mon 2016-04-18 08:35:13 UTC; 16s ago
Docs: man:httpd(8)
man:apachectl(8)
Process: 3571 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
Main PID: 3576 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─3576 /usr/sbin/httpd -DFOREGROUND
├─3578 /usr/sbin/httpd -DFOREGROUND
├─3579 /usr/sbin/httpd -DFOREGROUND
├─3580 /usr/sbin/httpd -DFOREGROUND
├─3581 /usr/sbin/httpd -DFOREGROUND
└─3582 /usr/sbin/httpd -DFOREGROUND

Apr 18 08:35:12 server1.centos7-test.com systemd[1]: Starting The Apache HTTP Server...
Apr 18 08:35:13 server1.centos7-test.com systemd[1]: Started The Apache HTTP Server.
[root@server1 activated_rules]# tail -f /etc/httpd/logs/error_log
[Mon Apr 18 08:35:13.237779 2016] [suexec:notice] [pid 3576] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Mon Apr 18 08:35:13.237912 2016] [:notice] [pid 3576] ModSecurity for Apache/2.7.3 (http://www.modsecurity.org/) configured.
[Mon Apr 18 08:35:13.237921 2016] [:notice] [pid 3576] ModSecurity: APR compiled version="1.4.8"; loaded version="1.4.8"
[Mon Apr 18 08:35:13.237929 2016] [:notice] [pid 3576] ModSecurity: PCRE compiled version="8.32 "; loaded version="8.32 2012-11-30"
[Mon Apr 18 08:35:13.237936 2016] [:notice] [pid 3576] ModSecurity: LUA compiled version="Lua 5.1"
[Mon Apr 18 08:35:13.237941 2016] [:notice] [pid 3576] ModSecurity: LIBXML compiled version="2.9.1"
[Mon Apr 18 08:35:13.441258 2016] [auth_digest:notice] [pid 3576] AH01757: generating secret for digest authentication ...
[Mon Apr 18 08:35:13.442048 2016] [lbmethod_heartbeat:notice] [pid 3576] AH02282: No slotmem from mod_heartmonitor
[Mon Apr 18 08:35:13.476079 2016] [mpm_prefork:notice] [pid 3576] AH00163: Apache/2.4.6 (CentOS) configured -- resuming normal operations
[Mon Apr 18 08:35:13.476135 2016] [core:notice] [pid 3576] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'

Ensuring the Server Security with ModSecurity

Now we can test the working of ModSecurity on our server. Just try to access any file from the server via browser. I just tried accessing the /etc/shadow file from the browser and it reported the forbidden error.

forbidden

 

Inspecting the details on the server from the ModSecurity logs (/var/log/httpd/modsec_audit.log). This is what is reported on the server end.

 

--ffddb332-A--
[19/Apr/2016:05:40:50 +0000] VxXE4nawj6tDGNi3ESgy8gAAAAM 101.63.70.47 60553 45.33.76.60 80
--ffddb332-B--
GET /etc/shadow HTTP/1.1
Host: 45.33.76.60
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:43.0) Gecko/20100101 Firefox/43.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Cookie: Drupal.toolbar.collapsed=0; SESS1dba846f2abd54265ae8178776146216=cVBBus2vUq_iMWD3mvj-0rM8ca21X1D7UrcVRzsmIZ8
Connection: keep-alive

--ffddb332-F--
HTTP/1.1 403 Forbidden
Content-Length: 212
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1

--ffddb332-E--

--ffddb332-H--
Message: Access denied with code 403 (phase 2). Pattern match "^[\\d.:]+$" at REQUEST_HEADERS:Host. [file "/etc/httpd/modsecurity.d/activated_rules/modsecurity_crs_21_protocol_anomalies.conf"] [line "98"] [id "960017"] [rev "2"] [msg "Host header is a numeric IP address"] [data "45.33.76.60"] [severity "WARNING"] [ver "OWASP_CRS/2.2.9"] [maturity "9"] [accuracy "9"] [tag "OWASP_CRS/PROTOCOL_VIOLATION/IP_HOST"] [tag "WASCTC/WASC-21"] [tag "OWASP_TOP_10/A7"] [tag "PCI/6.5.10"] [tag "http://technet.microsoft.com/en-us/magazine/2005.01.hackerbasher.aspx"]
Action: Intercepted (phase 2)
Stopwatch: 1461044450304152 4953 (- - -)
Stopwatch2: 1461044450304152 4953; combined=735, p1=505, p2=135, p3=0, p4=0, p5=91, sr=158, sw=4, l=0, gc=0
Response-Body-Transformed: Dechunked
Producer: ModSecurity for Apache/2.7.3 (http://www.modsecurity.org/); OWASP_CRS/2.2.9.
Server: Apache/2.4.6 (CentOS)
Engine-Mode: "ENABLED"

--ffddb332-Z--

This log clearly states the IP 101.63.70.47 details which was trying to download a file /etc/shadow from the server. And according to the logs, the HTTP reported forbidden error from the server. The details for this server response is also reported in the logs as it was denied as per the ModSecurity rule "/etc/httpd/modsecurity.d/activated_rules/modsecurity_crs_21_protocol_anomalies.conf". The server identified this web request to be a violation  of the Modsecurity rule specified and thus reported this error code.

Now you see how easy to install and configure the ModSecurity on CentOS 7.  ModSecurity, when properly configured, harden an Apache web server against several threats including DDoS attacks, SQL injections, Malicious attacks and should be considered in deployments exposed on the Internet.

I hope you enjoyed reading this article. Thank you for reading this :) I would recommend your valuable suggestions and recommendations on this.

The post How to Secure CentOS 7 Server with ModSecurity appeared first on LinOxide.

How to Install AIDE on CentOS 7

$
0
0

AIDE otherwise called as Advanced Intrusion Detection Environment. AIDE is one of the most popular tools for monitoring the server changes in a LINUX based system. It is used as a files/folders integrity checker. The installation of this Software is much simple. This is originally written by Rami Lehti and Pablo Virolainen in 1999. The system check is initialized by database. This database is created from a regular expresssion rules in the configuration files. Once the database is initialized, it can be further used to verify the server integrity. Several digest algorithms are incorporated to serve this purpose. It can be also used to check the file attributes for inconsistencies.

MAIN features:

  • Support several digest algorithms like md5, sha1, rmd160, tiger, crc32, sha256, sha512, whirlpool and several others
  • Support file attributes like file type, permissions, Inode, Uid, Gid, Link name, Size, Block count, Number of links, Mtime, Ctime and Atime
  • Supports Posix ACL, SELinux, XAttrs and Extended file system attributes
  • Support regular expression to include or exclude files/directories selectively.
  • Support GZIP database compression.
  • Standalone Static binary for easy client/server monitoring configurations.

In this article, I'm discussing about installing and configuring the current stable version 0.15.1 of AIDE on a CentOS 7 server. Let's walk through the procedures.

Step 1: Installation

We can use yum command to install the AIDE software.

[root@server1 ~]# yum install aide
Loaded plugins: fastestmirror

Dependencies Resolved

===============================================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================================
Installing:
aide x86_64 0.15.1-9.el7 base 129 k

Transaction Summary
===============================================================================================================================================
Install 1 Package

Total download size: 129 k
Installed size: 304 k

Step 2: Check and verify the AIDE version

We can run this command to confirm the AIDE version and locate the configuration file.

[root@server1 ~]# aide -v
Aide 0.15.1

Compiled with the following options:

WITH_MMAP
WITH_POSIX_ACL
WITH_SELINUX
WITH_PRELINK
WITH_XATTR
WITH_E2FSATTRS
WITH_LSTAT64
WITH_READDIR64
WITH_ZLIB
WITH_GCRYPT
WITH_AUDIT
CONFIG_FILE = "/etc/aide.conf"

Step 3: Create the database

Once the installation of the AIDE is done, we need to create the primary database which is initialized from the set of rules/expressions in the configuration files.

[root@[root@server1 ~]# aide --init

AIDE, version 0.15.1

### AIDE database at /var/lib/aide/aide.db.new.gz initialized.
server1 ~]# aide --init

AIDE, version 0.15.1

### AIDE database at /var/lib/aide/aide.db.new.gz initialized.

Once the database is created, you can move it to orginal one by re-naming it to make the AIDE work.

root@server1 ~]# mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
[root@server1 ~]# cd /var/lib/aide
[root@server1 aide]# ls
aide.db.gz
[root@server1 aide]#
[root@server1 aide]#
[root@server1 aide]# ls -lt
total 2136
-rw------- 1 root root 2186673 Apr 1 04:09 aide.db.gz

Step 4: Run the AIDE check

[root@server1 aide]# aide --check

AIDE, version 0.15.1

### All files match AIDE database. Looks okay!

Step 5 : Confirm its functionality and create an updated AIDE database

Create a binary file manually and check if AIDE detects that.

root@server1 aide]# touch /usr/sbin/testbinary
[root@server1 aide]#
[root@server1 aide]#
[root@server1 aide]# aide --check
AIDE 0.15.1 found differences between database and filesystem!!
Start timestamp: 2016-04-01 04:14:10

Summary:
Total number of files: 23028
Added files: 1
Removed files: 0
Changed files: 1
---------------------------------------------------
Added files:
---------------------------------------------------

added: /usr/sbin/testbinary

---------------------------------------------------
Changed files:
---------------------------------------------------

changed: /usr/sbin

---------------------------------------------------
Detailed information about changes:
---------------------------------------------------
Directory: /usr/sbin
Mtime : 2016-04-01 03:42:47 , 2016-04-01 04:14:03
Ctime : 2016-04-01 03:42:47 , 2016-04-01 04:14:03

We can verify the presence of the new file from the AIDE check reports. We can even identify any file attribute changes too from these checks.
Once we've reviewed these changes, it is always better to update the aide database so that it's not reported again on the next AIDE check.

[root@server1 aide]# aide --update
AIDE 0.15.1 found differences between database and filesystem!!
Start timestamp: 2016-04-01 04:15:21

Summary:
Total number of files: 23028
Added files: 1
Removed files: 0
Changed files: 1
---------------------------------------------------
Added files:
---------------------------------------------------

added: /usr/sbin/testbinary

---------------------------------------------------
Changed files:
---------------------------------------------------

changed: /usr/sbin

---------------------------------------------------
Detailed information about changes:
---------------------------------------------------

It is always advised to keep the old AIDE database untouched and re-name the updated database on daily basics to keep track.

[root@server1 tmp]# cd /var/lib/aide/
root@server1 aide]# ls
aide.db.gz aide.db.new.gz
[root@server1 aide]# mv aide.db.gz aide.db.gz-Apr012016
[root@server1 aide]# mv aide.db.new.gz aide.db.gz

These processes are rather tedious to check each time and re-name the database, we can use some scripts to update these settings.

Step 6 : Set cronjob to run AIDE check and report automatically

I create a cron to automatically initiate AIDE check to confirm my server integrity and report me on daily basis. Please see my script details below:

[root@server1 cron]# crontab -l
00 01 * * 0-6 /var/log/aide/aidechk.sh

[root@server1 cron]# systemctl restart crond.service
[root@server1 cron]#
[root@server1 cron]# systemctl status crond.service
crond.service - Command Scheduler
Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled)
Active: active (running) since Fri 2016-04-01 04:28:22 UTC; 8s ago
Main PID: 12378 (crond)
CGroup: /system.slice/crond.service
└─12378 /usr/sbin/crond -n

Apr 01 04:28:22 server1.centos7-test.com systemd[1]: Started Command Scheduler.
Apr 01 04:28:22 server1.centos7-test.com crond[12378]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 98% if used.)
Apr 01 04:28:22 server1.centos7-test.com crond[12378]: (CRON) INFO (running with inotify support)
Apr 01 04:28:22 server1.centos7-test.com crond[12378]: (CRON) INFO (@reboot jobs will be run at computer's startup.)
[root@server1 cron]#

root@server1 tmp]# cat /var/log/aide/aidechk.sh

#!/bin/sh
#aide check - SShameer
DATE=`date +%Y-%m-%d`
echo $DATE
REPORT="Aide-"$DATE.txt
echo $REPORT
echo "System check !! `date`" > /tmp/$REPORT
aide --check > /tmp/aidecheck.txt
cat /tmp/aidecheck.txt|/bin/grep -v failed >> /tmp/$REPORT
echo "**************************************" >> /tmp/$REPORT
tail -20 /tmp/aidecheck.txt >> /tmp/$REPORT
echo "****************DONE******************" >> /tmp/$REPORT
mail -s "$REPORT `date`" sshameer@gmail.com < /tmp/$REPORT

Install the mailx command or mail utilities to enhance the emailing, if it isn't present. As per our script, the report will be regenerated on /tmp with the time stamp and will be emailed to us on a daily basis. Please see one of my sample report format below:

root@server1 tmp]# cat Aide-2016-04-01.txt
System check !! Fri Apr 1 05:04:40 UTC 2016
AIDE 0.15.1 found differences between database and filesystem!!
Start timestamp: 2016-04-01 05:04:40

Summary:
Total number of files: 23043
Added files: 15
Removed files: 0
Changed files: 4
---------------------------------------------------
Added files:
---------------------------------------------------

added: /etc/mail.rc
added: /usr/bin/Mail
added: /usr/bin/mail
added: /usr/bin/mailx
added: /usr/bin/nail
added: /usr/share/doc/mailx-12.5
added: /usr/share/doc/mailx-12.5/AUTHORS
added: /usr/share/doc/mailx-12.5/COPYING
added: /usr/share/doc/mailx-12.5/README
added: /usr/share/man/man1/Mail.1.gz
added: /usr/share/man/man1/mail.1.gz
added: /usr/share/man/man1/mailx.1.gz
added: /usr/share/man/man1/nail.1.gz
added: /var/log/aide/aidechk.sh
added: /var/spool/cron/root

---------------------------------------------------
Changed files:
---------------------------------------------------

changed: /root
changed: /usr/bin
changed: /usr/share/doc
changed: /usr/share/man/man1

---------------------------------------------------
Detailed information about changes:
---------------------------------------------------
Directory: /root
Mtime : 2014-07-07 21:41:51 , 2016-04-01 05:02:57
Ctime : 2014-07-07 21:41:51 , 2016-04-01 05:02:57

Directory: /usr/bin
Mtime : 2014-10-21 14:33:45 , 2016-04-01 05:04:29
Ctime : 2014-10-21 14:33:45 , 2016-04-01 05:04:29

Directory: /usr/share/doc
Mtime : 2016-04-01 03:42:47 , 2016-04-01 05:04:29
Ctime : 2016-04-01 03:42:47 , 2016-04-01 05:04:29
Linkcount: 240 , 241

Directory: /usr/share/man/man1
Mtime : 2016-04-01 03:42:47 , 2016-04-01 05:04:29
Ctime : 2016-04-01 03:42:47 , 2016-04-01 05:04:29
**************************************
Detailed information about changes:
---------------------------------------------------
Directory: /root
Mtime : 2014-07-07 21:41:51 , 2016-04-01 05:02:57
Ctime : 2014-07-07 21:41:51 , 2016-04-01 05:02:57

Directory: /usr/bin
Mtime : 2014-10-21 14:33:45 , 2016-04-01 05:04:29
Ctime : 2014-10-21 14:33:45 , 2016-04-01 05:04:29

Directory: /usr/share/doc
Mtime : 2016-04-01 03:42:47 , 2016-04-01 05:04:29
Ctime : 2016-04-01 03:42:47 , 2016-04-01 05:04:29
Linkcount: 240 , 241

Directory: /usr/share/man/man1
Mtime : 2016-04-01 03:42:47 , 2016-04-01 05:04:29
Ctime : 2016-04-01 03:42:47 , 2016-04-01 05:04:29
****************DONE******************

We can also modify the AIDE configuration file /etc/aide.conf for advanced settings. But the default configuration is almost worthwhile and good to go.

This is how we can make use of AIDE to understand the server changes and identify the unauthorized access to our server which can be either through some malicious contents or by human intervention. I hope this article is useful for you! I would recommend your valuable suggestions and recommendations on this.

Thank you! Have a Good day :)

The post How to Install AIDE on CentOS 7 appeared first on LinOxide.

How to Install Bamboo on CentOS 7

$
0
0

Bamboo is a continuous integration and deployment server. It provides an automated and reliable build/test process for software source-codes. It is an efficient way to manage the build that have different requirements. The build and test processes are triggered automatically on completion of the code. It provides sophisticated methodology for the Software development teams as:

a) An automated building and testing of software source-code
b) Providing updates on successful and failed builds
c) Reporting tools for statistical Analysis
d) Build information

System Requirements for the installation

Hardware Considerations:

  1. The Software only supports 64 bit derived hardware platforms.
  2. The CPU/RAM depends upon the complexity of the plans. For a minimum installation setup I recommend atleast 4 core CPU and 2GB RAM
  3.  20GB storage is the minimum requirement for the installation

Software Considerations:

  1.  Bamboo requires a full Java Development Kit (JDK) platform to be installed on the server. It's purely a Java application and run on any platforms provided all the Java requirements are satisfied.
  2.  It is a Web application, hence needs an application server. Tomcat is the application server used for this.
  3.  It supports almost all popular relational database servers like PostgreSQL, MySQL, Oracle, MicroSoft SQL server etc

In this article, I'm providing the guidelines for the installation of this Web Application on a CentOS 7 server. Let's walk through the installation steps.

1. Check the supported platforms

As mentioned above, you can check and confirm the availability of the system requirements including the hardware and software considerations.

2. Check the Java version

This application requires the JDK 1.8 version to be installed on the server. If you've not installed this. Then make sure you download and install this exact JDK version as required.

[root@server1 kernels]#yum install java-1.8.0-openjdk

Dependencies Resolved

===============================================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================================
Installing:
java-1.8.0-openjdk x86_64 1:1.8.0.91-0.b14.el7_2 updates 219 k
Installing for dependencies:
alsa-lib x86_64 1.0.28-2.el7 base 391 k
fontconfig x86_64 2.10.95-7.el7 base 228 k
fontpackages-filesystem noarch 1.44-8.el7 base 9.9 k
giflib x86_64 4.1.6-9.el7 base 40 k
java-1.8.0-openjdk-headless x86_64 1:1.8.0.91-0.b14.el7_2 updates 31 M
javapackages-tools noarch 3.4.1-11.el7 base 73 k
libICE x86_64 1.0.9-2.el7 base 65 k
libSM x86_64 1.2.2-2.el7 base 39 k
libXext x86_64 1.3.3-3.el7 base 39 k
libXfont x86_64 1.5.1-2.el7 base 150 k
libXi x86_64 1.7.4-2.el7 base 40 k
libXrender x86_64 0.9.8-2.1.el7 base 25 k
libXtst x86_64 1.2.2-2.1.el7 base 20 k
libfontenc x86_64 1.1.2-3.el7 base 30 k
lksctp-tools x86_64 1.0.13-3.el7 base 87 k
python-javapackages noarch 3.4.1-11.el7 base 31 k
python-lxml x86_64 3.2.1-4.el7 base 758 k
ttmkfdir x86_64 3.0.9-42.el7 base 48 k
tzdata-java noarch 2016d-1.el7 updates 179 k
xorg-x11-font-utils x86_64 1:7.5-20.el7 base 87 k
xorg-x11-fonts-Type1 noarch 7.5-9.el7 base 521 k

Transaction Summary
===============================================================================================================================================
Install 1 Package (+21 Dependent packages)

Total download size: 34 M
Installed size: 110 M

[root@server1 kernels]# echo $JAVA_HOME
[root@server1 kernels]# java -version
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)

2. Install PostgreSQL

Bamboo installation choose PostgreSQL database by default. Install this if you plan to use this database server for this application. You can even use other external databases like MySQL, but you need to connect the application to this external database in that case. JDBC driver for PostgreSQL is bundled with the Bamboo installation. But for any other external application we need to configure Bamboo JDBC connection to the external database. I've choosen to use PostgreSQL as my database server. I've run this command to install this.

root@server1 ~]# yum install postgresql

3. Creating the application user and managing installation/application folders.

It is always recommended to run an application as its dedicated user rather than as root. I created a user to run this application and also created an application data and installation folder prior to the installation. I changed the ownerships of the folders to the dedicated bamboo user created.

root@server1 kernels]# useradd --create-home -c "Bamboo role account" bamboo
[root@server1 bamboo]# mkdir -p /opt/atlassian/bamboo
[root@server1 bamboo]# chown bamboo: /opt/atlassian/bamboo
[root@server1 bamboo]# ls -ld /opt/atlassian/bamboo
drwxr-xr-x 2 bamboo bamboo 4096 Apr 26 05:26 /opt/atlassian/bamboo

Now you can switch to the bamboo user and download the Bamboo installation packages from their website and extract that in the installation folder.

root@server1 bamboo]# su - bamboo
[bamboo@server1 ~]$ cd /opt/atlassian/bamboo
[bamboo@server1 bamboo]$

[bamboo@server1 tmp]$ wget https://www.atlassian.com/software/bamboo/downloads/binary/atlassian-bamboo-5.10.3.tar.gz
--2016-04-26 05:28:54-- https://www.atlassian.com/software/bamboo/downloads/binary/atlassian-bamboo-5.10.3.tar.gz
Resolving www.atlassian.com (www.atlassian.com)... 52.87.106.229, 54.86.154.79
Connecting to www.atlassian.com (www.atlassian.com)|52.87.106.229|:443... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://my.atlassian.com/software/bamboo/downloads/binary/atlassian-bamboo-5.10.3.tar.gz [following]
--2016-04-26 05:28:55-- https://my.atlassian.com/software/bamboo/downloads/binary/atlassian-bamboo-5.10.3.tar.gz
Resolving my.atlassian.com (my.atlassian.com)... 131.103.28.9
Connecting to my.atlassian.com (my.atlassian.com)|131.103.28.9|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://downloads.atlassian.com/software/bamboo/downloads/atlassian-bamboo-5.10.3.tar.gz [following]
--2016-04-26 05:28:55-- https://downloads.atlassian.com/software/bamboo/downloads/atlassian-bamboo-5.10.3.tar.gz
Resolving downloads.atlassian.com (downloads.atlassian.com)... 72.21.81.96
Connecting to downloads.atlassian.com (downloads.atlassian.com)|72.21.81.96|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 214301412 (204M) [application/x-gzip]
Saving to: ‘atlassian-bamboo-5.10.3.tar.gz’

100%[=====================================================================================================>] 214,301,412 62.1MB/s in 3.4s

2016-04-26 05:28:58 (61.0 MB/s) - ‘atlassian-bamboo-5.10.3.tar.gz’ saved [214301412/214301412]

[bamboo@server1 tmp]$ cd -
/opt/atlassian/bamboo
[bamboo@server1 bamboo]$
[bamboo@server1 bamboo]$ tar -xvf /tmp/atlassian-bamboo-5.10.3.tar.gz

Create a symlink to a directory current for the ease of managing the files.

[bamboo@server1 bamboo]$ ln -s atlassian-bamboo-5.10.3 current
[bamboo@server1 bamboo]$ ll
total 4
drwxr-xr-x 13 bamboo bamboo 4096 Mar 14 14:47 atlassian-bamboo-5.10.3
lrwxrwxrwx 1 bamboo bamboo 23 Apr 26 05:30 current -> atlassian-bamboo-5.10.3

Now create and modify the application-data folder location in the Bamboo configuration files.

[root@server1 bamboo]# mkdir -p /var/atlassian/application/bamboo
[root@server1 var]# chown bamboo: /var/atlassian/application/bamboo/
[bamboo@server1 bamboo]$ cat current/atlassian-bamboo/WEB-INF/classes/bamboo-init.properties
## You can specify your bamboo.home property here or in your system environment variables.

#bamboo.home=C:/bamboo/bamboo-home
bamboo.home=/var/atlassian/application/bamboo

It is recommended to keep different folder locations for the installation and storage of this application.

4. Start Bamboo

Now you switch to the bamboo user and move to your installation folder. Run the startup script from the installation folder.

bamboo@server1 current]$ pwd
/opt/atlassian/bamboo/current

[bamboo@server1 current]$ bin/start-bamboo.sh

To run Bamboo in the foreground, start the server with start-bamboo.sh -fg

Server startup logs are located in /home/bamboo/current/logs/catalina.out

Bamboo Server Edition
Version : 5.10.3

If you encounter issues starting or stopping Bamboo Server, please see the Troubleshooting guide at https://confluence.atlassian.com/display/BAMBOO/Installing+and+upgrading+Bamboo

Using CATALINA_BASE: /home/bamboo/current
Using CATALINA_HOME: /home/bamboo/current
Using CATALINA_TMPDIR: /home/bamboo/current/temp
Using JRE_HOME: /
Using CLASSPATH: /home/bamboo/current/bin/bootstrap.jar:/home/bamboo/current/bin/tomcat-juli.jar
Tomcat started.

[bamboo@server1 current]$ tail -f /home/bamboo/current/logs/catalina.out
2016-04-26 07:42:38,834 INFO [localhost-startStop-1] [lifecycle] * Bamboo is starting up *
2016-04-26 07:42:38,834 INFO [localhost-startStop-1] [lifecycle] *******************************
2016-04-26 07:42:38,835 INFO [localhost-startStop-1] [ServletContextHolder] Setting servlet context: Bamboo
2016-04-26 07:42:38,877 INFO [localhost-startStop-1] [lifecycle] atlassian.org.osgi.framework.bootdelegation set to javax.servlet,javax.servlet.*,sun.*,com.sun.*,org.w3c.dom.*,org.apache.xerces.*
2016-04-26 07:42:40,737 INFO [localhost-startStop-1] [lifecycle] Starting Bamboo 5.10.3 (build #51020 Mon Mar 14 14:26:34 UTC 2016) using Java 1.8.0_91 from Oracle Corporation
2016-04-26 07:42:40,737 INFO [localhost-startStop-1] [lifecycle] Real path of servlet context: /home/bamboo/atlassian-bamboo-5.10.3/atlassian-bamboo/
2016-04-26 07:42:40,822 INFO [localhost-startStop-1] [DefaultSetupPersister] Current setup step: setupLicense
2016-04-26 07:42:40,828 INFO [localhost-startStop-1] [lifecycle] Bamboo home directory: /var/atlassian/application/bamboo
2016-04-26 07:42:40,828 INFO [localhost-startStop-1] [lifecycle] Default charset: UTF-8
2016-04-26 07:42:40,841 INFO [localhost-startStop-1] [UpgradeLauncher] Upgrades not performed since the application has not been set up yet.

2016-04-26 07:43:21,900 INFO [localhost-startStop-1] [SessionIdGeneratorBase] Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [41,050] milliseconds

You can make sure the process status.

[root@server1 bamboo]# ps aux | grep bamboo
bamboo 21018 88.5 42.7 2705504 432068 ? Sl 05:54 0:20 //bin/java -Djava.util.logging.config.file=/opt/atlassian/bamboo/current/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xms256m -Xmx384m -Djava.endorsed.dirs=/opt/atlassian/bamboo/current/endorsed -classpath /opt/atlassian/bamboo/current/bin/bootstrap.jar:/opt/atlassian/bamboo/current/bin/tomcat-juli.jar -Dcatalina.base=/opt/atlassian/bamboo/current -Dcatalina.home=/opt/atlassian/bamboo/current -Djava.io.tmpdir=/opt/atlassian/bamboo/current/temp org.apache.catalina.startup.Bootstrap start
root 21041 0.0 0.2 112656 2380 pts/0 S+ 05:54 0:00 grep --color=auto bamboo

You can also create an Init script to manage this application.

5. Creating Init Script

You can create an init script file  /etc.init.d/bamboo and make it executableYou can place this script inside the init script.

[root@server1 bamboo]# cat /etc/init.d/bamboo
#!/bin/sh
set -e
### BEGIN INIT INFO
# Provides: bamboo
# Required-Start: $local_fs $remote_fs $network $time
# Required-Stop: $local_fs $remote_fs $network $time
# Should-Start: $syslog
# Should-Stop: $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Atlassian Bamboo Server
### END INIT INFO
# INIT Script
######################################

# Define some variables
# Name of app ( bamboo, Confluence, etc )
APP=bamboo
# Name of the user to run as
USER=bamboo
# Location of application's bin directory
BASE=/opt/atlassian/bamboo/current

case "$1" in
# Start command
start)
echo "Starting $APP"
/bin/su - $USER -c "export BAMBOO_HOME=${BAMBOO_HOME}; $BASE/bin/startup.sh &> /dev/null"
;;
# Stop command
stop)
echo "Stopping $APP"
/bin/su - $USER -c "$BASE/bin/shutdown.sh &> /dev/null"
echo "$APP stopped successfully"
;;
# Restart command
restart)
$0 stop
sleep 5
$0 start
;;
*)
echo "Usage: /etc/init.d/$APP {start|restart|stop}"
exit 1
;;
esac

exit 0

root@server1 bamboo]# chmod +x /etc/init.d/bamboo
[root@server1 bamboo]# /sbin/chkconfig --add bamboo
[root@server1 bamboo]#
[root@server1 bamboo]# chkconfig --list bamboo

 

bamboo 0:off 1:off 2:on 3:on 4:on 5:on 6:off

 

After starting the application, you can access your Bamboo instance by going to your web browser and entering the address http://45.33.76.60:8085/

6. Configure Bamboo

You need to acquire a valid license for the Bamboo installation from their store here. I've took my Bamboo evaluation license and start up with the installation.

acquirelicense

We need to provide this license information to proceed with the installation. Once the license is provided, you can choose any set-up method according to our preferences for the installation. I choose the Express Installation Method.

expressfinalinstall

7. Setup Administrator User

Now you can create an administrator user to manage the application which is the final installation step.

expressinstallation

This user will have the global administrative privileges for the entire Bamboo installation and should not be deleted.

Once you've entered these details and click Finish. The Bamboo dashboard will be ready to use.

Congratulations, you have successfully set up Bamboo!

Build Dashboard - Atlassian Bamboo 2016-04-26 13-22-20

 

Now we've completed with the installations and set-ups. You can start your work with this application!! I hope you enjoyed reading this article and is useful and informative. Thank you for reading this. I appreciate your valuable comments and suggestions on this.

The post How to Install Bamboo on CentOS 7 appeared first on LinOxide.

How to Install Splunk on CentOS 7

$
0
0

Splunk is one of the most powerful tool for exploring and searching data. It is one of the easiest, faster and secured way to search, analysis, collect and visualize massive data streams in realtime from applications, webservers, databases, server platforms, Cloud networks and many more. The Splunk developers are offering Splunk software packages compatible on different platforms, we can choose the best one which suits our purpose. This software makes it simple to collect, analyze and work upon the unbroached value of massive data generated by any IT enterprise, security systems or any business applications, giving you a total insights to obtain the best operational performance and business results.

There are no official pre-requisites for the installations, but I recommend a proper hostname, firewall and network configuration for the server prior to the installations. This software supports only 64 bit server architecture. In this article, I'm guiding you on how to install Splunk Enterprise version on a CentOS 7 server. Let's walk through the installation steps one by one.

1. Create a Splunk User

It is always recommended to run this application as its dedicated user rather than as root. I created a user to run this application and created a application folder for the installation.

[root@server1 tmp]# groupadd splunk
[root@server1 tmp]# useradd -d /opt/splunk -m -g splunk splunk
[root@server1 tmp]# su - splunk
[splunk@server1 ~]$ id
uid=1001(splunk) gid=1001(splunk) groups=1001(splunk)

Confirm the server architecture

[splunk@server1 ~]$ getconf LONG_BIT
64

2. Download and extract the Splunk Enterprise version

Create a Splunk account and download the Splunk software from their official website here.

Splunk

Now extract the tar file and copy the files to the Splunk application folder namely /opt/splunk created.

root@server1 tmp]# tar -xvf splunk-6.4.0-f2c836328108-Linux-x86_64.tgz
[root@server1 tmp]# cp -rp splunk/* /opt/splunk/
[root@server1 tmp]# chown -R splunk: /opt/splunk/

3. Splunk Installation

Once the Splunk software is downloaded, you can login to your Splunk user and run the installation script. I choose the trial license, so it will take it by default.

root@server1 tmp]# su - splunk
Last login: Fri Apr 29 08:14:12 UTC 2016 on pts/0

[splunk@server1 ~]$ cd bin/
[splunk@server1 bin]$ ./splunk start --accept-license

This appears to be your first time running this version of Splunk.

Copying '/opt/splunk/etc/openldap/ldap.conf.default' to '/opt/splunk/etc/openldap/ldap.conf'.
Generating RSA private key, 1024 bit long modulus
.++++++
..................++++++
e is 65537 (0x10001)
writing RSA key

Generating RSA private key, 1024 bit long modulus
................++++++
..++++++
e is 65537 (0x10001)
writing RSA key

Moving '/opt/splunk/share/splunk/search_mrsparkle/modules.new' to '/opt/splunk/share/splunk/search_mrsparkle/modules'.

Splunk> Australian for grep.

Checking prerequisites...
Checking http port [8000]: open
Checking mgmt port [8089]: open
Checking appserver port [127.0.0.1:8065]: open
Checking kvstore port [8191]: open
Checking configuration... Done.
Creating: /opt/splunk/var/lib/splunk
Creating: /opt/splunk/var/run/splunk
Creating: /opt/splunk/var/run/splunk/appserver/i18n
Creating: /opt/splunk/var/run/splunk/appserver/modules/static/css
Creating: /opt/splunk/var/run/splunk/upload
Creating: /opt/splunk/var/spool/splunk
Creating: /opt/splunk/var/spool/dirmoncache
Creating: /opt/splunk/var/lib/splunk/authDb
Creating: /opt/splunk/var/lib/splunk/hashDb
Checking critical directories... Done
Checking indexes...
Validated: _audit _internal _introspection _thefishbucket history main summary
Done
New certs have been generated in '/opt/splunk/etc/auth'.
Checking filesystem compatibility... Done
Checking conf files for problems...
Done
Checking default conf files for edits...
Validating installed files against hashes from '/opt/splunk/splunk-6.4.0-f2c836328108-linux-2.6-x86_64-manifest'
All installed files intact.
Done
All preliminary checks passed.

Starting splunk server daemon (splunkd)...
Generating a 1024 bit RSA private key
.....................++++++
...........................++++++
writing new private key to 'privKeySecure.pem'
-----
Signature ok
subject=/CN=server1.centos7-test.com/O=SplunkUser
Getting CA Private Key
writing RSA key
Done
[ OK ]

Waiting for web server at http://127.0.0.1:8000 to be available.... Done
If you get stuck, we're here to help.
Look for answers here: http://docs.splunk.com

The Splunk web interface is at http://server1.centos7-test.com:8000

Now you can access your Splunk Web interface at http://IP:8000/ or http://hostname:8000. You need to make sure this port 8000 is open in your server firewall.

4. Configuring Splunk Web Interface

I've completed with my installation and I've my Splunk Service up & running in my server. Now I need to set-up my Splunk Web interface. I accessed my Splunk web interface and set my administrator password.

splunks1

First time when you're accessing the Splunk interface, you can use the user/password provided in the page which is admin/changeme in this case. Once logged in, on the very next page it will ask to change and confirm your new password.

splunk2

Now, you've set your admin password. Once you log in with the new password, you will have your Splunk Dashboard ready to use.

splunkhome

There are different categories listed over in the home page. You can choose the required one and start splunking.

6. Adding a task

I'm adding an example for a simple task which is been added to the Splunk system. Just see my snapshots to understand how I added it. My task is to add /var/log folder to the Splunk system for monitoring.

  1. Open up the Splunk Web interface. Click on the Settings Tab >> Choose the Add Data option

add data

2. The Add Data Tab opens up with three options : Upload, Monitor and Forward. Here our task is to monitor a folder, so we go ahead with Monitor.

monitor

In the Monitor option, there are four categories as below:

File & Directories : To monitor files/folders

HTTP Event Collector : Monitor data streams over HTTP

TCP/UDP : Monitor Service ports

Scripts : Monitor Scripts

3. According to our purpose, I choose the Files & Directories option.

files-folders

4. Now, I'm choosing the exact folder path from the server to monitor. Once you confirm with the settings, you can click Next and Review.

var-log

var-log2

var-log3

 

5. Now you can start searching and monitoring the log file as required.

var-log4

donemonitor

You can just see the logs been narrowed to one of my REDIS application on the server.

redis_splunk

This is just a simple example for Splunking, you can add as many tasks to this and explore your server data. I hope this article is informative and useful for you. Thank you for reading this :) I recommend your valuable suggestions and comments on this. Now just try Splunk!!

Enjoy Splunking :)

The post How to Install Splunk on CentOS 7 appeared first on LinOxide.

Getting Started with Ansible on Command Line

$
0
0

ANSIBLE is an open source software platform for configuration management, provisioning, application deployment and service orchestration. It can be used for configuring our servers in production, staging and developments. It can also be used in managing application servers like Webservers, database servers and many others. Other systems similar to configuration management is CHEF, Puppet, SALT and Distelli, compared to all these ANSIBLE is the most simple and easily managed tool. The main advantage of using Ansible is as follows:

1. Modules can be written in any programming language.
2. No agent running on the client machine.
3. Easy to install and Manage.
4. Highly reliable.
5. Scalable

In this article, I'll explain some of the basics about your first steps with Ansible.

Understanding the hosts file

Once you've installed Ansible, the first thing is to understand its inventory file. This files contains the list of target servers which are managed by Ansible. The default hosts file location is /etc/ansible/hosts. We can edit this file to include our target systems. This file specifies several groups in which you can classify your hosts as your preference.

ansible_hosts

As mentioned here, important things to note in creating the hosts file:

# - Comments begin with the '#' character
# - Blank lines are ignored
# - Groups of hosts are delimited by [header] elements
# - You can enter hostnames or IP addresses
# - A hostname/ip can be a member of multiple groups
# - Remote hosts can have assignments in more than one groups
# - Include host ranges in one string as server-[01:12]-example.com

PS : It's not recommended to make modifications in the default inventory file, instead we can create our own custom inventory files at any locations as per our convenience.

How Ansible works?

First of all, Ansible admin client connects to the target server using SSH. We don't need to setup any agents on the client servers. All you need is Python and a user that can login and execute the scripts. Once the connection is established, then it starts gathering facts about the client machine like operating systems, services running and packages. We can execute different commands, copy/modify/delete files & folders, manage or configure packages and services using Ansible easily. I'll demonstrate it with the help of my demo setup.

My client servers are 45.33.76.60 and 139.162.35.39. I created my custom inventory hosts file under my user. Please see my inventory file with three groups namely webservers, production and testing.

In webservers, I've included two of my client servers. And separated them in two other groups as one in production and other in testing.

linuxmonty@linuxmonty-Latitude-E4310:~$ cat hosts
[webservers]
139.162.35.39
45.33.76.60

[production]
139.162.35.39

[Testing]
45.33.76.60

Establishing SSH connections

We need to create the SSH keys for the Admin server and copy this over to the target servers to enhance the SSH connections. Let's take a look on how I did that for my client servers.

linuxmonty@linuxmonty-Latitude-E4310:~$ # ssh-keygen -t rsa -b4096
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
2e:2f:32:9a:73:6d:ba:f2:09:ac:23:98:0c:fc:6c:a0 linuxmonty@linuxmonty-Latitude-E4310
The key's randomart image is:
+--[ RSA 4096]----+
| |
| |
| |
| |
|. S |
|.+ . |
|=.* .. . |
|Eoo*+.+o |
|o.+*=* .. |
+-----------------+

Copying the SSH keys

This is how we copy the SSH keys from Admin server to the target servers.

Client 1:

linuxmonty@linuxmonty-Latitude-E4310# ssh-copy-id root@139.162.35.39
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@139.162.35.39's password:

Number of key(s) added: 1

Now try logging into the machine, with: "ssh 'root@139.162.35.39'"
and check to make sure that only the key(s) you wanted were added.

linuxmonty@linuxmonty-Latitude-E4310#

Client 2:

linuxmonty@linuxmonty-Latitude-E4310# ssh-copy-id root@45.33.76.60
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@139.162.35.39's password:

Number of key(s) added: 1

Now try logging into the machine, with: "ssh 'root@45.33.76.60'"
and check to make sure that only the key(s) you wanted were added.

linuxmonty@linuxmonty-Latitude-E4310#

Once you execute these commands from your admin server, your keys will be added to the target servers and saved in the authorized keys.

Familiarizing some basic Ansible Modules

Modules controls system resources, configuration, packages, files etc. There are about 450+ modules used in Ansible. First of all, let's use the module to check the connectivity between your admin server and the target servers. We can run the ping module from your Admin server  to confirm the connectivity.

linuxmonty@linuxmonty-Latitude-E4310:~$ ansible -i hosts all -m ping -u root
139.162.35.39 | success >> {
"changed": false,
"ping": "pong"
}

45.33.76.60 | success >> {
"changed": false,
"ping": "pong"
}
-i : Represents the inventory file selection
-m : Represents the module name selection
-u : Represents the user for execution.

Since you're running this command as a user to connect to the target servers, you need to switch to the root user for module execution.

This is how to check the inventory status in the hosts file.

linuxmonty@linuxmonty-Latitude-E4310:~$ ansible -i hosts webservers --list-hosts
139.162.35.39
45.33.76.60
linuxmonty@linuxmonty-Latitude-E4310:~$
linuxmonty@linuxmonty-Latitude-E4310:~$ ansible -i hosts production --list-hosts
139.162.35.39
linuxmonty@linuxmonty-Latitude-E4310:~$ ansible -i hosts Testing --list-hosts
45.33.76.60

Setup Module:

Now you run the setup module to gather more facts about your target servers to organize your playbooks. This module provides you the information about the server hardware, network and some of the ansible-related software settings. These facts can be described in the playbooks section and represent discovered variables about your system. These can be also used to implement conditional execution of tasks.

linuxmonty@linuxmonty-Latitude-E4310:~$ ansible -i hosts all -m setup -u root

setup

You can view the server architecture, CPU information, python version, memory, OS version etc by running this module.

Command Module:

Here are some examples of the command module usage. We can pass any argument to this command module to execute.

uptime:

linuxmonty@linuxmonty-Latitude-E4310:~$ ansible -i hosts all -m command -a 'uptime' -u root
139.162.35.39 | success | rc=0 >>
14:55:31 up 4 days, 23:56, 1 user, load average: 0.00, 0.01, 0.05

45.33.76.60 | success | rc=0 >>
14:55:41 up 15 days, 3:20, 1 user, load average: 0.20, 0.07, 0.06

hostname:

linuxmonty@linuxmonty-Latitude-E4310:~$ ansible -i hosts all -m command -a 'hostname' -u root
139.162.35.39 | success | rc=0 >>
client2.production.com

45.33.76.60 | success | rc=0 >>
client1.testing.com

w:

linuxmonty@linuxmonty-Latitude-E4310:~$ ansible -i hosts all -m command -a 'w' -u root
139.162.35.39 | success | rc=0 >>
08:07:55 up 4 days, 17:08, 2 users, load average: 0.00, 0.01, 0.05
USER TTY LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 07:54 7:54 0.00s 0.00s -bash
root pts/1 08:07 0.00s 0.05s 0.00s w

45.33.76.60 | success | rc=0 >>
08:07:58 up 14 days, 20:33, 2 users, load average: 0.03, 0.03, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 101.63.79.157 07:54 8:01 0.00s 0.00s -bash
root pts/1 101.63.79.157 08:07 0.00s 0.05s 0.00s w

Similarly, we can execute any linux commands  across multiple target servers using the command module in Ansible.

Managing User and Groups

Ansible provides a module called "user" which server this purpose. The ‘user’ module allows easy creation and manipulation of existing user accounts, as well as removal of the existing user accounts as per our needs.

Usage : # ansible -i inventory selection -m user -a "name=username1 password=<crypted password here>"

linuxmonty@linuxmonty-Latitude-E4310:~$ ansible -i hosts all -m user -a "name=adminsupport password=<default123>" -u root
45.33.76.60 | success >> {
"changed": true,
"comment": "",
"createhome": true,
"group": 1004,
"home": "/home/adminsupport",
"name": "adminsupport",
"password": "NOT_LOGGING_PASSWORD",
"shell": "/bin/bash",
"state": "present",
"system": false,
"uid": 1004
}

In the above server, this command initiates the creation of this adminsupport user. But in the server 139.162.35.39 this user is already present, hence, it skips any other modifications for that user.

139.162.35.39 | success >> {
"changed": true,
"comment": "",
"createhome": true,
"group": 1001,
"home": "/home/adminsupport",
"name": "adminsupport",
"password": "NOT_LOGGING_PASSWORD",
"shell": "/bin/bash",
"state": "present",
"stderr": "useradd: warning: the home directory already exists.\nNot copying any file from skel directory into it.\nCreating mailbox file: File exists\n",
"system": false,
"uid": 1001
}

Usage : ansible -i inventory selection -m user -a 'name=username state=absent'

linuxmonty@linuxmonty-Latitude-E4310:~$ ansible -i hosts Testing -m user -a "name=adminsupport state=absent" -u root
45.33.76.60 | success >> {
"changed": true,
"force": false,
"name": "adminsupport",
"remove": false,
"state": "absent"
}

This command deletes the user adminsupport from our Testing server 45.33.76.60.

File Transfers

Ansible provides a module called "copy" to enhance the file transfers across multiple servers. It can securely transfer a lot of files to multiple servers in parallel.


Usage : ansible -i inventory selection -m copy -a "src=file_name dest=file path to save"

I'm copying a shell script called test.sh from my admin server to all my target servers /root. Please see the command usage below:

linuxmonty@linuxmonty-Latitude-E4310:~$ ansible -i hosts all -m copy -a "src=test.sh dest=/root/" -u root
139.162.35.39 | success >> {
"changed": true,
"dest": "/root/test.sh",
"gid": 0,
"group": "root",
"md5sum": "d910e95fdd8efd48d7428daafa7706ec",
"mode": "0755",
"owner": "root",
"size": 107,
"src": "/root/.ansible/tmp/ansible-tmp-1463040011.67-93143679295729/source",
"state": "file",
"uid": 0
}

45.33.76.60 | success >> {
"changed": true,
"dest": "/root/test.sh",
"gid": 0,
"group": "root",
"md5sum": "d910e95fdd8efd48d7428daafa7706ec",
"mode": "0755",
"owner": "root",
"size": 107,
"src": "/root/.ansible/tmp/ansible-tmp-1463040013.85-235107847216893/source",
"state": "file",
"uid": 0
}

Output Result:

[root@client2 ~]# ll /root/test.sh
-rwxr-xr-x 1 root root 107 May 12 08:00 /root/test.sh

If you use playbook, you can take advantage of the module template to perform the same task.

It also provides a module called "file" which will help us to change the ownership and permissions of the files across multiple servers. We can pass these options directly to the "copy" command. This module can also be used to create or delete the files/folders.

Example :

I've modified the ownerships and groups for an existing file test.sh on the destination server and changed its permission to 600.

linuxmonty@linuxmonty-Latitude-E4310:~$ ansible -i hosts production -m file -a "dest=/root/test.sh mode=600 owner=adminsupport group=adminsupport" -u root
139.162.35.39 | success >> {
"changed": true,
"gid": 1001,
"group": "adminsupport",
"mode": "0600",
"owner": "adminsupport",
"path": "/root/test.sh",
"size": 107,
"state": "file",
"uid": 1001
}

Output :

[root@client2 ~]# ll | grep test.sh
-rw------- 1 adminsupport adminsupport 107 May 12 08:00 test.sh

Creating A folder

Now, I need to create a folder with a desired ownership and permissions. Let's see the command to acquire that. I'm creating a folder "ansible" on my production server group and assign it to the owner "adminsupport" with 755 permissions.

linuxmonty@linuxmonty-Latitude-E4310:~$ ansible -i hosts production -m file -a "dest=/root/ansible mode=755 owner=adminsupport group=adminsupport state=directory" -u root
139.162.35.39 | success >> {
"changed": true,
"gid": 1001,
"group": "adminsupport",
"mode": "0755",
"owner": "adminsupport",
"path": "/root/ansible",
"size": 4096,
"state": "directory",
"uid": 1001
}

Output :

[root@client2 ~]# ll | grep ansible
drwxr-xr-x 2 adminsupport adminsupport 4096 May 12 08:45 ansible
[root@client2 ~]# pwd
/root

Deleting a folder

We can even use this module for deleting folders/files from multiple target servers. Please see how I did that.

linuxmonty@linuxmonty-Latitude-E4310:~$ ansible -i hosts production -m file -a "dest=/root/ansible state=absent" -u root
139.162.35.39 | success >> {
"changed": true,
"path": "/root/ansible",
"state": "absent"
}

The only variable that determines the operation is the arbitrary variable called "state", it is modified to absent to delete that particular folder from the server.

Managing Packages

Let's see how we can manage packages using Ansible. We need to identify the platform of the target servers and use the desired package manager modules like yum or  apt that suits the purpose. We can use apt or yum according to the target servers OS version. It also has modules for managing packages under many platforms.

Installing a VsFTPD package on my production server in my inventory.

linuxmonty@linuxmonty-Latitude-E4310:~$ ansible -i hosts production -m yum -a 'name=vsftpd state=present' -u root
139.162.35.39 | success >> {
"changed": true,
"msg": "",
"rc": 0,
"results": [
"Loaded plugins: fastestmirror\nLoading mirror speeds from cached hostfile\n * base: mirrors.linode.com\n * epel: mirror.wanxp.id\n * extras: mirrors.linode.com\n * updates: mirrors.linode.com\nResolving Dependencies\n--> Running transaction check\n---> Package vsftpd.x86_64 0:3.0.2-11.el7_2 will be installed\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package Arch Version Repository Size\n================================================================================\nInstalling:\n vsftpd x86_64 3.0.2-11.el7_2 updates 167 k\n\nTransaction Summary\n================================================================================\nInstall 1 Package\n\nTotal download size: 167 k\nInstalled size: 347 k\nDownloading packages:\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n Installing : vsftpd-3.0.2-11.el7_2.x86_64 1/1 \n Verifying : vsftpd-3.0.2-11.el7_2.x86_64 1/1 \n\nInstalled:\n vsftpd.x86_64 0:3.0.2-11.el7_2 \n\nComplete!\n"
]
}

linuxmonty@linuxmonty-Latitude-E4310:~$ ansible -i hosts production -m yum -a 'name=vsftpd state=present' -u root
139.162.35.39 | success >> {
"changed": false,
"msg": "",
"rc": 0,
"results": [
"vsftpd-3.0.2-11.el7_2.x86_64 providing vsftpd is already installed"
]
}

If you notice, you can see that, when I execute the ansible command to install the package first time, the "changed" variable was "true" which means this command has installed the package. But when I run that command again, it reported the variable "changed" as "false" which means the command checked for the package installation and it found that to be already installed, so nothing was done on that server.

Similarly, we can update or delete a package, the only variable which determines that is the state variable which can be modified to latest to install the latest available package and absent to remove the package from the server.

Examples:

Updating the package:

linuxmonty@linuxmonty-Latitude-E4310:~$ ansible -i hosts production -m yum -a 'name=vsftpd state=latest' -u root
139.162.35.39 | success >> {
"changed": false,
"msg": "",
"rc": 0,
"results": [
"All packages providing vsftpd are up to date"
]
}

This claims that the installed software is already in the latest version and there are no available updates.

Removing the package:

linuxmonty@linuxmonty-Latitude-E4310:~$ ansible -i hosts production -m yum -a 'name=vsftpd state=absent' -u root
139.162.35.39 | success >> {
"changed": true,
"msg": "",
"rc": 0,
"results": [
"Loaded plugins: fastestmirror\nResolving Dependencies\n--> Running transaction check\n---> Package vsftpd.x86_64 0:3.0.2-11.el7_2 will be erased\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package Arch Version Repository Size\n================================================================================\nRemoving:\n vsftpd x86_64 3.0.2-11.el7_2 @updates 347 k\n\nTransaction Summary\n================================================================================\nRemove 1 Package\n\nInstalled size: 347 k\nDownloading packages:\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n Erasing : vsftpd-3.0.2-11.el7_2.x86_64 1/1 \n Verifying : vsftpd-3.0.2-11.el7_2.x86_64 1/1 \n\nRemoved:\n vsftpd.x86_64 0:3.0.2-11.el7_2 \n\nComplete!\n"
]
}

linuxmonty@linuxmonty-Latitude-E4310:~$ ansible -i hosts production -m yum -a 'name=vsftpd state=absent' -u root
139.162.35.39 | success >> {
"changed": false,
"msg": "",
"rc": 0,
"results": [
"vsftpd is not installed"
]
}

First time when we run the ansible command it removed the VsFTPD package and then we run it again to confirm that there is no package existing in the server now.

Managing Services

It is necessary to manage the services which are installed on the target servers. Ansible provides the module service to attain that. We can use this module to enable on-boot and start/stop/restart services. Please see the examples for each case.

Starting/Enabling a Service:

linuxmonty@linuxmonty-Latitude-E4310:~$ ansible -i hosts all -m service -a 'name=nginx enabled=yes state=started' -u root
45.33.76.60 | success >> {
"changed": false,
"enabled": true,
"name": "nginx",
"state": "started"
}

139.162.35.39 | success >> {
"changed": false,
"enabled": true,
"name": "nginx",
"state": "started"
}

Stopping a Service:

linuxmonty@linuxmonty-Latitude-E4310:~$ ansible -i hosts all -m service -a 'name=nginx state=stopped' -u root
139.162.35.39 | success >> {
"changed": true,
"name": "nginx",
"state": "stopped"
}

45.33.76.60 | success >> {
"changed": true,
"name": "nginx",
"state": "stopped"
}

Restarting a Service:

linuxmonty@linuxmonty-Latitude-E4310:~$ ansible -i hosts all -m service -a 'name=nginx state=restarted' -u root
139.162.35.39 | success >> {
"changed": true,
"name": "nginx",
"state": "started"
}

45.33.76.60 | success >> {
"changed": true,
"name": "nginx",
"state": "started"
}

As you can see the state variable is modified to started, restarted and stopped status to manage the service.

Playbooks

Playbooks are Ansible’s configuration, deployment, and orchestration language. They can assign different roles, perform tasks like copying or deleting files/folders, make use of mature modules that shifts most of the functionality or substitute variables to make your deployments dynamic and re-usable.

Playbooks define your deployment steps and configuration. They are modular and can contain variables. They can be used to orchestrate steps across multiple machines. They are configuration files written in simple YAML file which is the Ansible automation language. They can contain multiple tasks and can make use of "mature" modules.

Here is an example of a simple Playbook.

linuxmonty@linuxmonty-Latitude-E4310:~$ cat simpleplbook.yaml
---

- hosts: production
remote_user: root

tasks:
- name: Setup FTP
yum: pkg=vsftpd state=installed
- name: start FTP
service: name=vsftpd state=started enabled=yes

This is a simple playbook with two tasks as below:

  1. Install FTP server
  2. Ensure the Service status

Let's see each statement in details

- hosts: production  -   This selects the inventory host to initiate this process.

remote_user: root  - This specifies the user which is meant to execute this process on the target servers.

tasks:
1. - name: Setup FTP
2. yum: pkg=vsftpd state=installed
3. - name: start FTP
4. service: name=vsftpd state=started enabled=yes

These specifies the two tasks which is meant to be performed while running this playbook.  We can divide it to four statements for more clarity. First statement describes the task which is setting up an FTP server and the second statement performs that by choosing/installing the package on the target server. Third statement describes the next task and fourth one ensure the service status by starting the FTP server and enable it on boot.

Now let' see the output of this playbook.

linuxmonty@linuxmonty-Latitude-E4310:~$ ansible-playbook -i hosts simpleplbook.yaml

PLAY [production] *************************************************************

GATHERING FACTS ***************************************************************
ok: [139.162.35.39]

TASK: [Setup FTP] *************************************************************
changed: [139.162.35.39]

TASK: [start FTP] *************************************************************
changed: [139.162.35.39]

PLAY RECAP ********************************************************************
139.162.35.39 : ok=3 changed=2 unreachable=0 failed=0

We can see that playbooks are executed sequentially according to the tasks specified in the playbook. First it chooses the inventory and then it starts performing the plays one by one.

Application Deployments

I'm going to set-up my webservers using a playbook. I created a playbook for my "webservers" inventory group. Please see my playbook details below:

linuxmonty@linuxmonty-Latitude-E4310:~$ cat webservers_setup.yaml
---

- hosts: webservers
vars:
- Welcomemsg: "Welcome to Ansible Application Deployment"

tasks:
- name: Setup Nginx
yum: pkg=nginx state=installed
- name: Copying the index page
template: src=index.html dest=/usr/share/nginx/html/index.html
- name: Enable the service on boot
service: name=nginx enabled=yes
- name: start Nginx
service: name=nginx state=started

Now let us run this playbook from my admin server to deploy it.

linuxmonty@linuxmonty-Latitude-E4310:~$ ansible-playbook -i hosts -s webservers_setup.yaml -u root

PLAY [webservers] *************************************************************

GATHERING FACTS ***************************************************************
ok: [139.162.35.39]
ok: [45.33.76.60]

TASK: [Setup Nginx] ***********************************************************
changed: [139.162.35.39]
changed: [45.33.76.60]

TASK: [Copying the index page] ************************************************
changed: [139.162.35.39]
changed: [45.33.76.60]

TASK: [Enable the service on boot] ********************************************
changed: [139.162.35.39]
changed: [45.33.76.60]

TASK: [start Nginx] ***********************************************************
changed: [139.162.35.39]
changed: [45.33.76.60]

PLAY RECAP ********************************************************************
139.162.35.39 : ok=5 changed=4 unreachable=0 failed=0
45.33.76.60 : ok=5 changed=4 unreachable=0 failed=0

This playbook describes four tasks as evident from the result. After running this playbook, we can confirm the status by checking the target servers in the browser.

ansiblewebserver

Now, I'm planning to add a PHP Module namely php-gd to the target servers. I can edit my playbook to include that task too and run it again. Let's see what happens now. My modified playbook is as below:

linuxmonty@linuxmonty-Latitude-E4310:~$ cat webservers_setup.yaml
---

- hosts: webservers
vars:
- Welcomemsg: "Welcome to Nginx default page"
- WelcomePHP: "PHP GD module enabled"

tasks:
- name: Setup Nginx
yum: pkg=nginx state=installed
- name: Copying the index page
template: src=index.html dest=/usr/share/nginx/html/index.html
- name: Enable the service on boot
service: name=nginx enabled=yes
- name: start Nginx
service: name=nginx state=started
- name: Setup PHP-GD
yum: pkg=php-gd state=installed

As you can see, I append these highlighted lines to my playbook. So this is how it goes now.

linuxmonty@linuxmonty-Latitude-E4310:~$ ansible-playbook -i hosts -s webservers_setup.yaml -u root

PLAY [webservers] *************************************************************

GATHERING FACTS ***************************************************************
ok: [139.162.35.39]
ok: [45.33.76.60]

TASK: [Setup Nginx] ***********************************************************
ok: [139.162.35.39]
ok: [45.33.76.60]

TASK: [Copying the index page] ************************************************
changed: [139.162.35.39]
changed: [45.33.76.60]

TASK: [Enable the service on boot] ********************************************
ok: [139.162.35.39]
ok: [45.33.76.60]

TASK: [start Nginx] ***********************************************************
ok: [139.162.35.39]
ok: [45.33.76.60]

TASK: [Setup PHP-GD] **********************************************************
changed: [45.33.76.60]
changed: [139.162.35.39]

PLAY RECAP ********************************************************************
139.162.35.39 : ok=6 changed=2 unreachable=0 failed=0
45.33.76.60 : ok=6 changed=2 unreachable=0 failed=0

On close analysis of this result, you can see that only two sections in this have reported modifications to the target servers. One is the index file modification and other is the installation of our additional PHP module. Now we can evident the changes for the target servers in the browser.

PHPmodule+Nginx

Roles

Ansible roles are a special kind of playbooks that are fully self-contained and portable. The roles contains tasks, variables, configuration templates and other supporting tasks that needs to complete complex orchestration. Roles can be used to simplify more complex operations. You can create different roles like common, webservers, db_servers etc categorizing with different purpose and include in the main playbook by just mentioning the roles.  This is how we create the roles.

linuxmonty@linuxmonty-Latitude-E4310:~$ ansible-galaxy init common
common was created successfully

Now, I've created a role named common to perform some of the common tasks in all my target servers. Each role contains their individual tasks, configuration templates, variables, handlers etc.

total 40
drwxrwxr-x 9 linuxmonty linuxmonty 4096 May 13 14:06 ./
drwxr-xr-x 34 linuxmonty linuxmonty 4096 May 13 14:06 ../
drwxrwxr-x 2 linuxmonty linuxmonty 4096 May 13 14:06 defaults/
drwxrwxr-x 2 linuxmonty linuxmonty 4096 May 13 14:06 files/
drwxrwxr-x 2 linuxmonty linuxmonty 4096 May 13 14:06 handlers/
drwxrwxr-x 2 linuxmonty linuxmonty 4096 May 13 14:06 meta/
-rw-rw-r-- 1 linuxmonty linuxmonty 1336 May 13 14:06 README.md
drwxrwxr-x 2 linuxmonty linuxmonty 4096 May 13 14:06 tasks/
drwxrwxr-x 2 linuxmonty linuxmonty 4096 May 13 14:06 templates/
drwxrwxr-x 2 linuxmonty linuxmonty 4096 May 13 14:06 vars/

We can create our YAML file inside each of these folders as per our purpose. Later on, we can run all these tasks by just specifying these roles inside a playbook. You can get more details on Ansible roles here.

I hope this documentation provided you with the basic knowledge on how to manage your servers with Ansible. Thank you for reading this. I would recommend your valuable suggestions and comments on this.

Happy Automation!!

The post Getting Started with Ansible on Command Line appeared first on LinOxide.

How to Install Chef Workstation / Server / Node on CentOS 7

$
0
0

Chef is an automation platform that configures and manages your infrastruture. It transforms the infrastruture into code. It is a Ruby based configuration management tool. This automation platform consists of a Chef workstation, a Chef server and chef clients which are the nodes managed by the Chef server. All the chef configuration files, recipes, cookbooks, templates etc are created and tested on the Chef workstation and are uploaded to the Chef Server, then it distributes these across every possible nodes registered within the organisations.  It is an ideal automation framework for the Ceph and OpenStack. Not only it gives us complete control but it's super easy to work with.

In this article, I'm explaining the steps I followed for implementing a Chef automation environment on my CentOS 7 servers.

Pre-requisites

  • It is recommended to have a FQDN hostname
  • Chef supports only 64 bit architecture
  • Proper network/Firewall/hosts configurations are recommended

How Chef works?

work procedure

Chef comprises of a workstation which is configured to develop the recipes and cookbooks. It is also configured to run the knife and synchronizes with the chef-repo to keep it up-to-date.  It helps in configuring organizational policy, including defining roles & environments and ensuring that critical data is being stored in data bags. Once these recipes/cookbooks are tested in the workstations, we can upload it to our Chef server. Chef server stores these recipes and assigns on to the nodes depending on their requirements. Basically nodes communicates with only the chef server and takes instructions and recipes from there.

In my demo setup, I'm having three servers namely

  1. chefserver.test20.com         -     Chef Server
  2. chefwork.test20.com           -     Chef Workstation
  3. chefnode.test20.com           -     Chef Node

Let's us start with building Workstation.

Setup a Workstation

First of all, login to our server chefwork, then download the Chef development package. Once the package is downloaded, we can install the package using rpm command.

root@chefwork ~]# wget https://packages.chef.io/stable/el/7/chefdk-0.14.25-1.el7.x86_64.rpm
--2016-05-20 03:47:31-- https://packages.chef.io/stable/el/7/chefdk-0.14.25-1.el7.x86_64.rpm
Resolving packages.chef.io (packages.chef.io)... 75.126.118.188, 108.168.243.150
Connecting to packages.chef.io (packages.chef.io)|75.126.118.188|:443... connected.
HTTP request sent, awaiting response... 302
Location: https://akamai.bintray.com/87/879656c7736ef2a061937c1f45c623e99fd57aaa2f6d802e9799d333d7e5342f?__gda__=exp=1463716772~hmac=ef9ce287129ab2f035449b76a1adc32b7bf8cae37f018f59da5a642d3e2650fc&response-content-disposition=attachment%3Bfilename%3D%22chefdk-0.14.25-1.el7.x86_64.rpm%22&response-content-type=application%2Foctet-stream [following]
--2016-05-20 03:47:32-- https://akamai.bintray.com/87/879656c7736ef2a061937c1f45c623e99fd57aaa2f6d802e9799d333d7e5342f?__gda__=exp=1463716772~hmac=ef9ce287129ab2f035449b76a1adc32b7bf8cae37f018f59da5a642d3e2650fc&response-content-disposition=attachment%3Bfilename%3D%22chefdk-0.14.25-1.el7.x86_64.rpm%22&response-content-type=application%2Foctet-stream
Resolving akamai.bintray.com (akamai.bintray.com)... 104.123.250.232
Connecting to akamai.bintray.com (akamai.bintray.com)|104.123.250.232|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 143927478 (137M) [application/octet-stream]
Saving to: ‘chefdk-0.14.25-1.el7.x86_64.rpm’

100%[====================================================================================================>] 14,39,27,478 2.52MB/s in 55s

2016-05-20 03:48:29 (2.49 MB/s) - ‘chefdk-0.14.25-1.el7.x86_64.rpm’ saved [143927478/143927478]

[root@chefwork ~]# rpm -ivh chefdk-0.14.25-1.el7.x86_64.rpm
warning: chefdk-0.14.25-1.el7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 83ef826a: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:chefdk-0.14.25-1.el7 ################################# [100%]
Thank you for installing Chef Development Kit!

What is ChefDK?

The Chef Development Kit contains everything to start with Chef, along with the tools essential for code managing.

  • It contains a new command-line tool, "chef"
  • The cookbook dependency manager Berkshelf
  • The Test Kitchen integration testing framework.
  • ChefSpec for testing the cookbook syntax
  • Foodcritic, a tool for doing static code analysis on cookbooks.
  • It also has all the Chef tools like Chef Client, Knife, Ohai and Chef Zero

Let's start with creating a some recipes in the Workstation and test it locally to ensure its working.

Create a folder named chef-repo on /root/ and inside that folder we can create our recipes.

[root@chefwork ~]# mkdir chef-repo
[root@chefwork ~]# cd chef-repo

Creating a recipe called hello.rb.
[root@chefwork chef-repo]# vim hello.rb
[root@chefwork chef-repo]#
[root@chefwork chef-repo]# cat hello.rb
file '/etc/motd' do
content 'Welcome to Chef'
end

This recipe hello.rb creates a file named /etc/motd with content "Welcome to Chef". This recipe make use of the resource file to enhance this task. Now we can run this recipe to check its working.

[root@chefwork chef-repo]# chef-apply hello.rb
Recipe: (chef-apply cookbook)::(chef-apply recipe)
* file[/etc/motd] action create (up to date)

Confirm the recipe execution:

[root@chefwork chef-repo]# cat /etc/motd
Welcome to Chef

Deleting the file

We can modify our recipe file to delete the created file and run using the command chef-apply as below:

[root@chefwork chef-repo]# cat hello.rb
file '/etc/motd' do
action :delete
end

[root@chefwork chef-repo]# chef-apply hello.rb
Recipe: (chef-apply cookbook)::(chef-apply recipe)
* file[/etc/motd] action delete
- delete file /etc/motd

Installing a package

We're modifying our recipe file to install httpd package on our server and copy an index.html file to the default document root to confirm the installation. The package and the service resources are used to implement this. Default action for a package resource is installation, hence we needn't specify that action separately.

[root@chefwork chef-conf]# cat hello.rb
package 'httpd'
service 'httpd' do
action [:enable, :start]
end

file '/var/www/html/index.html' do
content 'Welcome to Apache in Chef'
end
[root@chefwork chef-conf]# chef-apply hello.rb
Recipe: (chef-apply cookbook)::(chef-apply recipe)
* yum_package[httpd] action install
- install version 2.4.6-40.el7.centos.1 of package httpd
* service[httpd] action enable
- enable service service[httpd]
* service[httpd] action start
- start service service[httpd]
* file[/var/www/html/index.html] action create (up to date)

The command execution clearly describes each instance in the recipe. It installs the Apache package , enables and starts the httpd service on the server. And it creates an index.html file in the default document root with the content "Welcome to Apache in Chef". So we can verify it by running the server IP in the browser.

welcomepage_httpd

Creating Cookbooks

Now we can create our first cookbook, create a folder called chef-repo under the /root directory and execute the command "chef generate cookbook [cookbook name]" to generate our cookbook.

root@chefwork chef-repo]# mkdir cookbooks
[root@chefwork chef-repo]# cd cookbooks/
[root@chefwork cookbooks]# chef generate cookbook httpd_deploy
Installing Cookbook Gems:
Compiling Cookbooks...
Recipe: code_generator::cookbook
* directory[/root/chef-repo/cookbook/httpd_deploy] action create
- create new directory /root/chef-repo/cookbook/httpd_deploy

 

cookbook filestructure

 

This is the file structure of the created cookbook, let's see the use of these  files/folders inside the cookbook one by one.

Berksfile : It is the configuration file, which mainly tells BerkShelf what are the cookbook's dependencies, which can be specified directly inside this file or indirectly through metadata.rb. It also tells Berkshelf where it should look for those dependencies.

Chefignore : It tells Chef which all files should be ignored while uploading a cookbook to the Chef server.

metadata.rb : It contains meta information about you cookbook, such as name, contacts or description. It can also state the cookbook’s dependencies.

README.md : It contains documentation entry point for the repo.

Recipes : Contains the cookbook's recipes. It starts with executing the file default.rb.

default.rb : The default recipe format.

specs : It will be storing the unit test cases of your libraries.

test : It will be storing the unit test cases of your recipes.

Creating a template

Next we are going to create a template file for ourselves. Earlier, we created a file with some contents, but that can't be fit in with our recipes and cookbook structures. so let's see how we can create a template.

[root@chefwork cookbook]# chef generate template httpd_deploy index.html
Installing Cookbook Gems:
Compiling Cookbooks...
Recipe: code_generator::template
* directory[./httpd_deploy/templates/default] action create
- create new directory ./httpd_deploy/templates/default
* template[./httpd_deploy/templates/default/index.html.erb] action create
- create new file ./httpd_deploy/templates/default/index.html.erb
- update content in file ./httpd_deploy/templates/default/index.html.erb from none to e3b0c4
(diff output suppressed by config)

 

template

Now if you see our cookbook file structure, there is a folder created with the name template with index.html.erb file. We can edit our index.html.erb template file and add to our recipe as below:

root@chefwork default]# cat index.html.erb
Welcome to Chef Apache Deployment
[root@chefwork default]# pwd
/root/chef-repo/cookbook/httpd_deploy/templates/default

Creating the recipe with this template

[root@chefwork recipes]# pwd
/root/chef-repo/cookbook/httpd_deploy/recipes
[root@chefwork recipes]# cat default.rb
#
# Cookbook Name:: httpd_deploy
# Recipe:: default
#
# Copyright (c) 2016 The Authors, All Rights Reserved.
package 'httpd'
service 'httpd' do
action [:enable, :start]
end

template '/var/www/html/index.html' do
source 'index.html.erb'
end

Now go back to our chef-repo folder and run/test our recipe on our Workstation.

[root@chefwork chef-repo]# chef-client --local-mode --runlist 'recipe[httpd_deploy]'
[2016-05-20T05:44:40+00:00] WARN: No config file found or specified on command line, using command line options.
Starting Chef Client, version 12.10.24
resolving cookbooks for run list: ["httpd_deploy"]
Synchronizing Cookbooks:
- httpd_deploy (0.1.0)
Installing Cookbook Gems:
Compiling Cookbooks...
Converging 3 resources
Recipe: httpd_deploy::default
* yum_package[httpd] action install
- install version 2.4.6-40.el7.centos.1 of package httpd
* service[httpd] action enable
- enable service service[httpd]
* service[httpd] action start
- start service service[httpd]
* template[/var/www/html/index.html] action create
- update content in file /var/www/html/index.html from 152204 to 748cbd
--- /var/www/html/index.html 2016-05-20 04:18:38.553231745 +0000
+++ /var/www/html/.chef-index.html20160520-20425-1bez4qs 2016-05-20 05:44:47.344848833 +0000
@@ -1,2 +1,2 @@
-Welcome to Apache in Chef
+Welcome to Chef Apache Deployment

Running handlers:
Running handlers complete
Chef Client finished, 4/4 resources updated in 06 seconds

[root@chefwork chef-repo]# cat /var/www/html/index.html
Welcome to Chef Apache Deployment

According to our recipe, Apache is installed on our workstation, service is being started and enabled on boot. And a template file has been created  on our default document root.

Now we've tested our Workstation. It's time for the Chef server setup.

Setting up the Chef Server

First of all login to our Chef server "chefserver.test20.com" and download the chef server package combatible with our OS version.

[root@chefserver ~]# wget https://packages.chef.io/stable/el/7/chef-server-core-12.6.0-1.el7.x86_64.rpm
--2016-05-20 07:23:46-- https://packages.chef.io/stable/el/7/chef-server-core-12.6.0-1.el7.x86_64.rpm
Resolving packages.chef.io (packages.chef.io)... 75.126.118.188, 108.168.243.150
Connecting to packages.chef.io (packages.chef.io)|75.126.118.188|:443... connected.
HTTP request sent, awaiting response... 302
Location: https://akamai.bintray.com/5a/5a36d0ffa692bf788e90315171582a758d4c5d8033a892dca9a81d3c03c44d14?__gda__=exp=1463729747~hmac=86e28bf2d5197154c84b571330b4c897006c2cb7f14cc9fc386c62d8b6e34c2d&response-content-disposition=attachment%3Bfilename%3D%22chef-server-core-12.6.0-1.el7.x86_64.rpm%22&response-content-type=application%2Foctet-stream [following]
--2016-05-20 07:23:47-- https://akamai.bintray.com/5a/5a36d0ffa692bf788e90315171582a758d4c5d8033a892dca9a81d3c03c44d14?__gda__=exp=1463729747~hmac=86e28bf2d5197154c84b571330b4c897006c2cb7f14cc9fc386c62d8b6e34c2d&response-content-disposition=attachment%3Bfilename%3D%22chef-server-core-12.6.0-1.el7.x86_64.rpm%22&response-content-type=application%2Foctet-stream
Resolving akamai.bintray.com (akamai.bintray.com)... 23.15.249.68
Connecting to akamai.bintray.com (akamai.bintray.com)|23.15.249.68|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 481817688 (459M) [application/octet-stream]
Saving to: ‘chef-server-core-12.6.0-1.el7.x86_64.rpm’

100%[====================================================================================================>] 48,18,17,688 2.90MB/s in 3m 53s

[root@chefserver ~]# rpm -ivh chef-server-core-12.6.0-1.el7.x86_64.rpm
warning: chef-server-core-12.6.0-1.el7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 83ef826a: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:chef-server-core-12.6.0-1.el7 ################################# [100%]

Now our Chef server is installed. But we need to reconfigure the Chef server to enable and start all the services which is composed in the Chef server. We can run this command to reconfigure.

root@chefserver ~]# chef-server-ctl reconfigure
Starting Chef Client, version 12.10.26
resolving cookbooks for run list: ["private-chef::default"]
Synchronizing Cookbooks:
- enterprise (0.10.0)
- apt (2.9.2)
- yum (3.10.0)
- openssl (4.4.0)
- chef-sugar (3.3.0)
- packagecloud (0.0.18)
- runit (1.6.0)
- private-chef (0.1.0)
Installing Cookbook Gems:
Compiling Cookbooks...
[2016-05-19T02:38:37+00:00] WARN: Chef::Provider::AptRepository already exists! Cannot create deprecation class for LWRP provider apt_repository from cookbook apt
Chef Client finished, 394/459 resources updated in 04 minutes 05 seconds
Chef Server Reconfigured!

Please confirm the service status and their pids by running this command.

[root@chefserver ~]# chef-server-ctl status
run: bookshelf: (pid 6140) 162s; run: log: (pid 6156) 162s
run: nginx: (pid 6051) 165s; run: log: (pid 6295) 156s
run: oc_bifrost: (pid 5987) 167s; run: log: (pid 6022) 167s
run: oc_id: (pid 6038) 165s; run: log: (pid 6042) 165s
run: opscode-erchef: (pid 6226) 159s; run: log: (pid 6214) 161s
run: opscode-expander: (pid 6102) 162s; run: log: (pid 6133) 162s
run: opscode-solr4: (pid 6067) 164s; run: log: (pid 6095) 163s
run: postgresql: (pid 5918) 168s; run: log: (pid 5960) 168s
run: rabbitmq: (pid 5876) 168s; run: log: (pid 5869) 169s
run: redis_lb: (pid 5795) 290s; run: log: (pid 6280) 156s

Hurray!! Our Chef Server is ready :). Now we can install the management console to get an web interface to manage our Chef server.

Installing Management Console for Chef Server

We can install the management console by just running this command "chef-server-ctl install chef-manage" from the chef server.

[root@chefserver ~]# chef-server-ctl install chef-manage
Starting Chef Client, version 12.10.26
resolving cookbooks for run list: ["private-chef::add_ons_wrapper"]
Synchronizing Cookbooks:
- enterprise (0.10.0)
- apt (2.9.2)
- yum (3.10.0)
- openssl (4.4.0)
- runit (1.6.0)
- chef-sugar (3.3.0)
- packagecloud (0.0.18)
- private-chef (0.1.0)
Installing Cookbook Gems:
Compiling Cookbooks...
Converging 4 resources
Recipe: private-chef::add_ons_wrapper
* ruby_block[addon_install_notification_chef-manage] action nothing (skipped due to action :nothing)
* remote_file[/var/opt/opscode/local-mode-cache/chef-manage-2.3.0-1.el7.x86_64.rpm] action create
- create new file /var/opt/opscode/local-mode-cache/chef-manage-2.3.0-1.el7.x86_64.rpm
- update content in file /var/opt/opscode/local-mode-cache/chef-manage-2.3.0-1.el7.x86_64.rpm from none to 098cc4
(file sizes exceed 10000000 bytes, diff output suppressed)
* ruby_block[locate_addon_package_chef-manage] action run
- execute the ruby block locate_addon_package_chef-manage
* yum_package[chef-manage] action install
- install version 2.3.0-1.el7 of package chef-manage
* ruby_block[addon_install_notification_chef-manage] action create
- execute the ruby block addon_install_notification_chef-manage

Running handlers:
-- Installed Add-On Package: chef-manage
- #<Class:0x00000006032b80>::AddonInstallHandler
Running handlers complete
Chef Client finished, 4/5 resources updated in 02 minutes 39 seconds

After installing the management console, we need to reconfigure the chef server to restart the chef server and its services to update these changes.

[root@chefserver ~]# opscode-manage-ctl reconfigure
To use this software, you must agree to the terms of the software license agreement.
Press any key to continue.
Type 'yes' to accept the software license agreement, or anything else to cancel.
yes
Starting Chef Client, version 12.4.1
resolving cookbooks for run list: ["omnibus-chef-manage::default"]
Synchronizing Cookbooks:
- omnibus-chef-manage
- chef-server-ingredient
- enterprise
Recipe: omnibus-chef-manage::default
* private_chef_addon[chef-manage] action create (up to date)
Recipe: omnibus-chef-manage::config
Running handlers:
Running handlers complete
Chef Client finished, 62/79 resources updated in 44.764229437 seconds
chef-manage Reconfigured!

[root@chefserver ~]# chef-server-ctl reconfigure

Now our Management console is ready, we need to setup our admin user to manage our Chef Server.

Creating Admin user/Organization

I've created the admin user named chefadmin with an organization linox on my chef server to manage it. We can create the user using the chef command chef-server-ctl user-create and organization using the command chef-server-ctl org-create.

root@chefserver ~]# chef-server-ctl user-create chefadmin saheetha shameer saheetha@gmail.com 'chef123' --filename /root/.chef/chefadmin.pem
[root@chefserver ~]#

[root@chefserver .chef]# chef-server-ctl org-create linox Chef Linoxide --association_user chefadmin --filename /root/.chef/linoxvalidator.pem

Our keys are saved inside the folder /root/.chef folder. We need to copy these keys from the Chef server to the Work station to initiate the communication between our Chef server and workstation.

Copying the Keys

I'm copying my user and validator keys from the Chef server to the workstation to enhance the connection between the servers.

[root@chefserver .chef]# scp chefadmin.pem root@139.162.35.39:/root/chef-repo/.chef/
The authenticity of host '139.162.35.39 (139.162.35.39)' can't be established.
ECDSA key fingerprint is 5b:0b:07:85:9a:fb:b6:59:51:07:7f:14:1b:07:07:f0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '139.162.35.39' (ECDSA) to the list of known hosts.
root@139.162.35.39's password:
chefadmin.pem 100% 1678 1.6KB/s 00:00
[root@chefserver .chef]#

[root@chefserver .chef]# scp linoxvalidator.pem root@139.162.35.39:/root/chef-repo/.chef/
The authenticity of host '139.162.35.39 (139.162.35.39)' can't be established.
ECDSA key fingerprint is 5b:0b:07:85:9a:fb:b6:59:51:07:7f:14:1b:07:07:f0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '139.162.35.39' (ECDSA) to the list of known hosts.
root@139.162.35.39's password:
linoxvalidator.pem 100% 1678 1.6KB/s 00:00
[root@chefserver .chef]#

Now login to our Management console for our Chef server with the user/password  "chefadmin" created.

chef_management console

It'll ask to create an organization from the Panel on Sign up. Just create a different one.

Download the Starter Kit for WorkStation

Choose any of your organization and download the Starter Kit from the Chef Server to our Work Station.

starterdownloadStarter

After downloading this kit. Move it your Workstation /root folder and extract. This provides you with a default Starter Kit to start up with your Chef server. It includes a chef-repo.

root@chefwork ~]# ls
chef-starter.zip hello.rb
[root@chefwork~]# unzip chef-starter.zip
Archive: chef-starter.zip
creating: chef-repo/cookbooks/
creating: chef-repo/cookbooks/starter/
creating: chef-repo/cookbooks/starter/recipes/
inflating: chef-repo/cookbooks/starter/recipes/default.rb
creating: chef-repo/cookbooks/starter/files/
creating: chef-repo/cookbooks/starter/files/default/
inflating: chef-repo/cookbooks/starter/files/default/sample.txt
creating: chef-repo/cookbooks/starter/templates/
creating: chef-repo/cookbooks/starter/templates/default/
inflating: chef-repo/cookbooks/starter/templates/default/sample.erb
inflating: chef-repo/cookbooks/starter/metadata.rb
creating: chef-repo/cookbooks/starter/attributes/
inflating: chef-repo/cookbooks/starter/attributes/default.rb
inflating: chef-repo/cookbooks/chefignore
inflating: chef-repo/README.md
inflating: chef-repo/.gitignore
creating: chef-repo/.chef/
creating: chef-repo/roles/
inflating: chef-repo/.chef/knife.rb
inflating: chef-repo/roles/starter.rb
inflating: chef-repo/.chef/chefadmin.pem
inflating: chef-repo/.chef/ln_blog-validator.pem

chef-repo

This is the file structure for the downloaded Chef repository. It contains all the required file structures to start with.

Cookbook SuperMarket

Chef cookbooks are available in the Cookbook Super Market, we can go to the Chef SuperMarket here. Download the required cookbooks from there. I'm downloading one of the cookbook to install Apache from there.

root@chefwork chef-repo]# knife cookbook site download learn_chef_httpd
Downloading learn_chef_httpd from Supermarket at version 0.2.0 to /root/chef-repo/learn_chef_httpd-0.2.0.tar.gz
Cookbook saved: /root/chef-repo/learn_chef_httpd-0.2.0.tar.gz

Extract this cookbook inside the "cookbooks" folder.

[root@chefwork chef-repo]# tar -xvf learn_chef_httpd-0.2.0.tar.gz

learn

All the required files are automatically created under this cookbook. We didn't require to make any modifications. Let's check our recipe description inside our recipe folder.

[root@chefwork recipes]# cat default.rb
#
# Cookbook Name:: learn_chef_httpd
# Recipe:: default
#
# Copyright (C) 2014
#
#
#
package 'httpd'

service 'httpd' do
action [:enable, :start]
end

template '/var/www/html/index.html' do
source 'index.html.erb'
end

service 'iptables' do
action :stop
end
[root@chefwork recipes]#
[root@chefwork recipes]# pwd
/root/chef-repo/cookbooks/learn_chef_httpd/recipes
[root@chefwork recipes]#

So we just need to upload this cookbook to our Chef server as it looks perfect.

Validating the Connection b/w Server and Workstation

Before uploading the cookbook, we need to check and confirm the connection between our Chef server and Workstation. First of all, make sure you've proper Knife configuration file.

[root@chefwork .chef]# cat knife.rb
current_dir = File.dirname(__FILE__)
log_level :info
log_location STDOUT
node_name "chefadmin"
client_key "#{current_dir}/chefadmin.pem"
validation_client_name "linox-validator"
validation_key "#{current_dir}/linox-validator.pem"
chef_server_url "https://chefserver.test20.com:443/organizations/linox"

cookbook_path ["#{current_dir}/../cookbooks"]

This configuration file is location at /root/chef-repo/.chef folder. The highlighted portions are the main things to take care. Now you can run this command to check the connections.

root@chefwork .chef]# knife client list
ERROR: SSL Validation failure connecting to host: chefserver.test20.com - SSL_connect returned=1 errno=0 state=error: certificate verify failed
ERROR: Could not establish a secure connection to the server.
Use `knife ssl check` to troubleshoot your SSL configuration.
If your Chef Server uses a self-signed certificate, you can use
`knife ssl fetch` to make knife trust the server's certificates.

Original Exception: OpenSSL::SSL::SSLError: SSL Error connecting to https://chefserver.test20.com/clients - SSL_connect returned=1 errno=0 state=error: certificate verify failed

You can see an SSL error reporting. In order to rectify this error, we need to fetch the SSL certificate for our Chef Server and store it inside the /root/.chef/trusted_certs folder. We can do this by running this command.

root@chefwork .chef]# knife ssl fetch
WARNING: Certificates from chefserver.test20.com will be fetched and placed in your trusted_cert
directory (/root/chef-repo/.chef/trusted_certs).

Knife has no means to verify these are the correct certificates. You should
verify the authenticity of these certificates after downloading.

Adding certificate for chefserver.test20.com in /root/chef-repo/.chef/trusted_certs/chefserver_test20_com.crt

Verifying the SSL:

[root@chefwork .chef]# knife ssl check
Connecting to host chefserver.test20.com:443
Successfully verified certificates from `chefserver.test20.com'

[root@chefwork .chef]# knife client list
chefnode
linox-validator
[root@chefwork .chef]# knife user list
chefadmin

Uploading the Cookbook

We can upload our cookbook to our chef server from the workstation using the knife command as below:

#knife cookbook upload learn_chef_httpd

[root@chefwork cookbooks]# knife cookbook upload learn_chef_httpd
Uploading learn_chef_httpd [0.2.0]
Uploaded 1 cookbook.

Verify the cookbook from the Chef Server Management console.

uploadedcookbook

 

Adding a Node

This is the final step in the Chef implementation. We've setup a workstation, a Chef server and then now we need to add our clients to the Chef server for automation. I'm adding my chefnode to the server using the knife bootstrap command as below:

[root@chefwork cookbooks]# knife bootstrap 45.33.76.60 --ssh-user root --ssh-password dkfue@321 --node-name chefnode
Creating new client for chefnode
Creating new node for chefnode
Connecting to 45.33.76.60
45.33.76.60 -----> Installing Chef Omnibus (-v 12)
45.33.76.60 downloading https://omnitruck-direct.chef.io/chef/install.sh
45.33.76.60 to file /tmp/install.sh.5457/install.sh
45.33.76.60 trying wget...
45.33.76.60 el 7 x86_64
45.33.76.60 Getting information for chef stable 12 for el...
45.33.76.60 downloading https://omnitruck-direct.chef.io/stable/chef/metadata?v=12&p=el&pv=7&m=x86_64
45.33.76.60 to file /tmp/install.sh.5466/metadata.txt
45.33.76.60 trying wget...
45.33.76.60 sha1 4def83368a1349959fdaf0633c4d288d5ae229ce
45.33.76.60 sha256 6f00c7bdf96a3fb09494e51cd44f4c2e5696accd356fc6dc1175d49ad06fa39f
45.33.76.60 url https://packages.chef.io/stable/el/7/chef-12.10.24-1.el7.x86_64.rpm
45.33.76.60 version 12.10.24
45.33.76.60 downloaded metadata file looks valid...
45.33.76.60 downloading https://packages.chef.io/stable/el/7/chef-12.10.24-1.el7.x86_64.rpm
45.33.76.60 to file /tmp/install.sh.5466/chef-12.10.24-1.el7.x86_64.rpm
45.33.76.60 trying wget...
45.33.76.60 Comparing checksum with sha256sum...
45.33.76.60 Installing chef 12
45.33.76.60 installing with rpm...
45.33.76.60 warning: /tmp/install.sh.5466/chef-12.10.24-1.el7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 83ef826a: NOKEY
45.33.76.60 Preparing... ################################# [100%]
45.33.76.60 Updating / installing...
45.33.76.60 1:chef-12.10.24-1.el7 ################################# [100%]
45.33.76.60 Thank you for installing Chef!
45.33.76.60 Starting the first Chef Client run...
45.33.76.60 Starting Chef Client, version 12.10.24
45.33.76.60 resolving cookbooks for run list: []
45.33.76.60 Synchronizing Cookbooks:
45.33.76.60 Installing Cookbook Gems:
45.33.76.60 Compiling Cookbooks...
45.33.76.60 [2016-05-20T15:36:41+00:00] WARN: Node chefnode has an empty run list.
45.33.76.60 Converging 0 resources
45.33.76.60
45.33.76.60 Running handlers:
45.33.76.60 Running handlers complete
45.33.76.60 Chef Client finished, 0/0 resources updated in 08 seconds
[root@chefwork chef-repo]#

This command will also initialize the installation of the Chef-client in the Chef node. You can verify it from the CLI on the workstation using the knife commands below:

[root@chefwork chef-repo]# knife node list
chefnode

[root@chefwork chef-repo]# knife node show chefnode
Node Name: chefnode
Environment: _default
FQDN: chefnode.test20.com
IP: 45.33.76.60
Run List: recipe[learn_chef_httpd]
Roles:
Recipes:
Platform: centos 7.2.1511
Tags:

Verifying it from the Management console.

added nodechef

We can get more information regarding the added node by selecting the node and viewing the Attributes section.

node details

Managing Node Run List

Let's see how we can add a cookbook to the node and manage its runlist from the Chef server. As you see in the screenshot, you can click the Actions tab and select the Edit Runlist option to manage the runlist.

node_run

In the Available Recipes,  you can see our learn_chef_httpd recipe, you can drag that from the available packages to the current run list and save the runlist.

drag_recipe

Now login to your node and just run the command chef-client to execute your runlist.

root@chefnode ~]# chef-client
Starting Chef Client, version 12.10.24
resolving cookbooks for run list: ["learn_chef_httpd"]
Synchronizing Cookbooks:
- learn_chef_httpd (0.2.0)
Installing Cookbook Gems:
Compiling Cookbooks...
Converging 4 resources
Recipe: learn_chef_httpd::default
* yum_package[httpd] action install

Similarly, we can add any number of nodes to your Chef Server depending on its configuration and hardware. I hope this article provided you with the basic understanding of Chef implementation. I would recommend your valuable comments and suggestions on this. Thank you for reading this :)

Happy Automation with Chef!!

The post How to Install Chef Workstation / Server / Node on CentOS 7 appeared first on LinOxide.


How to Install Tomcat 8 on Ubuntu 16.04 (Multiple Instances)

$
0
0

Apache Tomcat commonly called as Tomcat is an open source Webserver and Servlet container developed by Apache Software Foundation. It is written in Java and released under Apache 2.0 License. This is a cross platform application. Tomcat is actually composed of a number of components, including a Tomcat JSP engine and a variety of different connectors, but its core component is called Catalina. Catalina provides Tomcat's actual implementation of the servlet specification.

In this article, I'll provide you guidelines to install, configure and create multiple instances of Tomcat 8 on Ubuntu 16.04. Let's walk through the installations steps.

Since Tomcat is written in Java, we need Java to be installed on our server prior to the installation.

Install Java

Tomcat 8 requires, Java 7 or later versions to be installed on the server. I updated packages on my Ubuntu server and installed the JDK packages using the commands below:

root@ubuntu:~# apt-get update
root@ubuntu:~# apt-get install default-jdk
Setting up default-jdk-headless (2:1.8-56ubuntu2) ...
Setting up openjdk-8-jdk:amd64 (8u91-b14-0ubuntu4~16.04.1) ...
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/bin/appletviewer to provide /usr/bin/appletviewer (appletviewer) in auto mode
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/bin/jconsole to provide /usr/bin/jconsole (jconsole) in auto mode
Setting up default-jdk (2:1.8-56ubuntu2) ...
Setting up gconf-service-backend (3.2.6-3ubuntu6) ...
Setting up gconf2 (3.2.6-3ubuntu6) ...
Setting up libgnomevfs2-common (1:2.24.4-6.1ubuntu1) ...
Setting up libgnomevfs2-0:amd64 (1:2.24.4-6.1ubuntu1) ...
Setting up libgnome2-common (2.32.1-5ubuntu1) ...
Setting up libgnome-2-0:amd64 (2.32.1-5ubuntu1) ...
Processing triggers for libc-bin (2.23-0ubuntu3) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (229-4ubuntu4) ...
Processing triggers for ca-certificates (20160104ubuntu1) ...
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...

done.
done.

Check and confirm the Java Version

After the installation process, just verify the Java version installed on your server.

root@ubuntu:~# java -version
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-0ubuntu4~16.04.1-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)

Download / Install Tomcat

We can download the latest version of Tomcat here. Download and extract this under the folder /opt/apache-tomcat8.

root@ubuntu:/opt# wget http://a.mbbsindia.com/tomcat/tomcat-8/v8.0.35/bin/apache-tomcat-8.0.35.zip
--2016-05-23 03:02:48-- http://a.mbbsindia.com/tomcat/tomcat-8/v8.0.35/bin/apache-tomcat-8.0.35.zip
Resolving a.mbbsindia.com (a.mbbsindia.com)... 103.27.233.42
Connecting to a.mbbsindia.com (a.mbbsindia.com)|103.27.233.42|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9842037 (9.4M) [application/zip]
Saving to: ‘apache-tomcat-8.0.35.zip’

apache-tomcat-8.0.35.zip 100%[===================================================================>] 9.39M 4.46MB/s in 2.1s

2016-05-23 03:02:51 (4.46 MB/s) - ‘apache-tomcat-8.0.35.zip’ saved [9842037/9842037]

Creating tomcat user / group

It is always recommended to run an application as a user instead of root user. Hence, I created a user named tomcat to run this application.

root@ubuntu:/opt# groupadd tomcat

root@ubuntu:/opt# useradd -g tomcat -s /bin/bash -d /opt/apache-tomcat8 tomcat

Now make all scripts under the Tomcat bin folder executable for the user.

root@ubuntu:/opt/apache-tomcat8/bin# chmod 700 *.sh

root@ubuntu:/opt# chown -R tomcat.tomcat apache-tomcat8/

Start the Tomcat Application

Now switch to the tomcat user and execute the script startup.sh inside the Tomcat binary folder namely  /opt/apache-tomcat8/bin/ to run this application.

tomcat@ubuntu:~/bin$ sh startup.sh
Using CATALINA_BASE: /opt/apache-tomcat8
Using CATALINA_HOME: /opt/apache-tomcat8
Using CATALINA_TMPDIR: /opt/apache-tomcat8/temp
Using JRE_HOME: /usr
Using CLASSPATH: /opt/apache-tomcat8/bin/bootstrap.jar:/opt/apache-tomcat8/bin/tomcat-juli.jar
Tomcat started.

Now we can access this URL http://serverip:8080 on the browser to confirm the Tomcat working.

tomcat

We can even confirm the status using this command from CLI as below:

root@ubuntu:/opt# lsof -i :8080
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 22722 tomcat 53u IPv6 100669 0t0 TCP *:http-alt (LISTEN)

PS : To shutdown the application you can use the script shutdown.sh inside the Tomcat binaries.

root@ubuntu:/opt/apache-tomcat8# sh bin/shutdown.sh
Using CATALINA_BASE: /opt/apache-tomcat8
Using CATALINA_HOME: /opt/apache-tomcat8
Using CATALINA_TMPDIR: /opt/apache-tomcat8/temp
Using JRE_HOME: /usr
Using CLASSPATH: /opt/apache-tomcat8/bin/bootstrap.jar:/opt/apache-tomcat8/bin/tomcat-juli.jar
May 24, 2016 3:32:35 AM org.apache.catalina.startup.Catalina stopServer
SEVERE: Could not contact localhost:8005. Tomcat may not be running.
May 24, 2016 3:32:36 AM org.apache.catalina.startup.Catalina stopServer
SEVERE: Catalina.stop:

Tomcat Web Application Manager

In a production environment, it is very useful to have the capablility to deploy a new web application or undeploy an existing one, without having to shutdown/restart the entire server. In addition, you can even reload an exisiting application itself, even without declaring it to be reloadable in the Tomcat server configuration file.

This Management Web console supports the following functions:

  • Deploy a new web application from the uploaded WAR file or on a specified context path from the server f/s.
  • List the currently deployed web applications and the sessions that are currently active
  • Reload an existing web applications, to reflect changes in the contents of the /WEB-INF/classes or /WEB-INF/lib.
  • Get the server information about the OS and JVM
  • Start and Stop an existing web applications, --stopping the existing application thus making it unavailable. But don't undeploy it.
  • Undeploy a deployed web application and delete its document base directory

We can create the users to manage the Tomcat Management Web console. You can edit the Tomcat user configuration file namely conf/tomcat-users.xml  to create the admin users to manage the Panel.

I've appended  these lines to the Tomcat user configuration file to create two users namely manager and admin with the passwords as listed.

<user username="manager" password="tomcat123" roles="manager-gui" />

<user username="admin" password="tomcat123" roles="manager-gui,admin-gui"/>

We can access the Tomcat Web Application Manager using the URL >>http://SERVERIP:8080/manager/ with the users created.

TManager

Enabling SSL/TLS support on Tomcat

Tomcat uses a password protected file "keystore" to save the SSL transactions. We need to create a keystore file to store the server's private key and self-signed certificate by executing the following command:

root@ubuntu:/usr/local# keytool -genkey -alias tomcat -keyalg RSA -keystore /usr/local/keystore
Enter keystore password:
Re-enter new password:
What is your first and last name?
[Unknown]: Saheetha Shameer
What is the name of your organizational unit?
[Unknown]: VIP
What is the name of your organization?
[Unknown]: VIP
What is the name of your City or Locality?
[Unknown]: Kochi
What is the name of your State or Province?
[Unknown]: Kerala
What is the two-letter country code for this unit?
[Unknown]: IN
Is CN=Saheetha Shameer, OU=VIP, O=VIP, L=Kochi, ST=Kerala, C=IN correct?
[no]: yes

Enter key password for <tomcat>
(RETURN if same as keystore password):

Options:

-genkeypair : Generate key pair

-keyalg : Key algorithm

-keystore : Keystore file path

After entering the details for generating the certification, you can edit the Tomcat server configuration to enable the SSL/TLS support directing to the keystore file.

We need to add this section to the Tomcat server configuration file namely conf/server.xml

<Connector port="8443" protocol="HTTP/1.1"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="/usr/local/keystore"
keystorePass="tomcat123"/>

Restart the Tomcat application once confirming the keystore contents.

tomcat@ubuntu:~$ keytool -list -keystore /usr/local/keystore
Enter keystore password:

Keystore type: JKS
Keystore provider: SUN

Your keystore contains 1 entry

tomcat, May 23, 2016, PrivateKeyEntry,
Certificate fingerprint (SHA1): A3:99:A8:DD:F1:11:4F:69:37:95:11:66:41:59:A5:05:68:23:3E:B2

Now you can access the Tomcat application on the port 8443 on URL https://SERVER IP:8443 to confirm its working.

tomcatssl

Creating Multiple Tomcat instances

In order to create multiple Tomcat instances, you can download and extract the Tomcat application to a different folder. I extracted the contents to a different folder namely /opt/apache-tomcat8-2. After extracting the files, we need to make proper changes to the Tomcat Server configuration file for modifying the Connector ports and other important ports for the application to avoid conflicts with the existing application.

These are the following changes applied to the Tomcat Server configuration file namely conf/server.xml.

1. Modified the shutdown port from 8005 to 8006

 <Server port="8005" shutdown="SHUTDOWN">

to

<Server port="8006" shutdown="SHUTDOWN">

2.  Modified the connector port from 8080 to 8081

<Connector port="8080" protocol="HTTP/1.1"

connectionTimeout="20000"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<!--

to

<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<!--

3. Modified the AJP port  from 8009 to 8010

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

<Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />

After applying these changes, restart our new Tomcat Application under /opt/apache-tomcat8-2

root@ubuntu:/opt# chown -R tomcat.tomcat /opt/apache-tomcat8-2

root@ubuntu:/opt#cd apache-tomcat8-2

Making the script executable for the user.

root@ubuntu:/opt/apache-tomcat8-2# chmod 700 bin/*.sh

Switch to tomcat user and start the application.

tomcat@ubuntu:/opt/apache-tomcat8-2/bin$ sh startup.sh
Using CATALINA_BASE: /opt/apache-tomcat8-2
Using CATALINA_HOME: /opt/apache-tomcat8-2
Using CATALINA_TMPDIR: /opt/apache-tomcat8-2/temp
Using JRE_HOME: /usr
Using CLASSPATH: /opt/apache-tomcat8-2/bin/bootstrap.jar:/opt/apache-tomcat8-2/bin/tomcat-juli.jar
Tomcat started.

Verify the second Tomcat instance at the port 8081 at the URL http://SERVERIP:8081

tomcat2instance

That's it! you're done with the basic things on Tomcat installations. I hope you enjoyed reading this article. I would recommend your valuable suggestions and comments on this. Thank you for reading this :)

Have a Good day!

The post How to Install Tomcat 8 on Ubuntu 16.04 (Multiple Instances) appeared first on LinOxide.

How to Install RainLoop Webmail on Ubuntu 16.04

$
0
0

RainLoop Webmail is an Open Source Web Application software written in PHP. It is a simple, fast and web-based email client. It provides a fast web interface to access your emails on almost all major mail providers like Yahoo, GMail, Outlook and many others as well as your own mail servers. These are some of the main features of this Email client.

1. Modern user interface with efficient memory use which can work on low-end webservers.
2. Provides complete support of IMAP and SMTP protocols including SSL and STARTTLS.
3. Minimum resource requirements.
4. Provides interface to set filters.
5. Direct access to the mail server, no storing of emails locally on webservers
6. It allows adding multiple domain accounts.
7. Really simple and fast installation.
8. It can be integrated with Facebook, twitter, Dropbox and Google.
9. Built-in caching system allows for improving overall performance and reducing load on web and mail servers.

In this article, I'm providing the guidelines on how to install RainLoop Webmail on Ubuntu 16.04. Let's see the pre-requisites for the installation.

Pre-requisites

This application requires a LAMP setup prior to the installation.

  • This works with any of these Web servers: Apache, nginx, lighttpd, MS IIS or other with PHP support
  • PHP Support: 5.3 and above recommended
  • Required PHP extensions: CURL, iconv, json, libxml, dom, openssl, DateTime, PCRE, SPL
  • Supported Browsers: Internet Explorer 9+, Firefox, Opera 10+, Safari 3+, Google Chrome
  • Optional: PDO (MySQL/PostgreSQL/SQLite) PHP extension (for contacts)

As mentioned in the context, RainLoop Webmail is based on PHP, so it is recommended to have a Webserver installed with fully functional PHP to make it working. I've installed Apache, PHP and MySQL on my server prior to the installation. I'll brief the installation steps one by one here.

root@ubuntu:/var/#apt-get install python-software-properties  *//Install the Python Software packages//*
root@ubuntu:/var/#apt install software-properties-common
root@ubuntu:/var# add-apt-repository ppa:ondrej/php
root@ubuntu:/var#apt-get update  *//Update the Softwares//*
root@ubuntu:/var#apt-get install -y php7.0 *// Install PHP //*
Processing triggers for man-db (2.7.5-1) ...
Setting up php7.0-common (7.0.4-7ubuntu2.1) ...
Setting up php7.0-mcrypt (7.0.4-7ubuntu2.1) ...
Setting up php7.0-imap (7.0.4-7ubuntu2.1) ...
Setting up php7.0-xml (7.0.4-7ubuntu2.1) ...
Setting up php7.0-readline (7.0.4-7ubuntu2.1) ...
Setting up php7.0-opcache (7.0.4-7ubuntu2.1) ...
Setting up php7.0-odbc (7.0.4-7ubuntu2.1) ...
Setting up php7.0-mysql (7.0.4-7ubuntu2.1) ...
Setting up php7.0-json (7.0.4-7ubuntu2.1) ...
Setting up php7.0-curl (7.0.4-7ubuntu2.1) ...
Setting up php7.0-cli (7.0.4-7ubuntu2.1) ...
Setting up php7.0-fpm (7.0.4-7ubuntu2.1) ...
Setting up php7.0 (7.0.4-7ubuntu2.1) ...

root@ubuntu:/var# add-apt-repository ppa:ondrej/apache2 *// Add the latest packages for Apache2 //*
root@ubuntu:/var/#apt-get update
root@ubuntu:/var/#apt-get install apache2 *//Install Apache2 //*
root@ubuntu:/var/#add-apt-repository -y ppa:ondrej/mysql-5.6 *//Add the packages for MySQL 5.6 //*
root@ubuntu:/var/# apt-get update
root@ubuntu:/var/# apt-get install mysql-server-5.7 *//Install MySQL 5.6 //*
root@ubuntu:/var/#apt-get install libapache2-mod-php7.0 php7.0-mysql php7.0-curl php7.0-json

Confirming the Installations

After the installation, we need to confirm the installed Apache, PHP and MySQL versions.

root@ubuntu:~# apache2 -v
Server version: Apache/2.4.18 (Ubuntu)
Server built: 2016-04-15T18:00:57

root@ubuntu:~# php -v
PHP 7.0.4-7ubuntu2 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

root@ubuntu:~# mysql -v
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.12-0ubuntu1 (Ubuntu)

Adding to the hosts file

We need to add proper hosts file entry to make it resolve as required.

cat /etc/hosts

139.162.55.62 rainloop.webmail.com

Creating the Virtual Host

Now we can create the virtual host for the domain. In addition, make sure to create the document root folder and error log folder mentioned in the virtual host, if it's not created before.

root@ubuntu:/etc/apache2/sites-enabled# cat rainloop.conf

<VirtualHost *:80>
ServerName rainloop.webmail.com
DocumentRoot "/var/www/rainloop/"
ServerAdmin you@example.com
ErrorLog "/var/log/httpd/rainloop-error_log"
TransferLog "/var/log/httpd/rainloop-access_log"

<Directory />
Options +Indexes +FollowSymLinks +ExecCGI
AllowOverride All
Order deny,allow
Allow from all
Require all granted
</Directory>

</VirtualHost>

Creating the folders specified in the Virtual host

root@ubuntu:~#mkdir /var/www/rainloop/
root@ubuntu:/#mkdir -p /var/log/httpd/

Enabling SSL for the host

For adding an SSL, we need to first generate a self signed certificate for our hostname "rainloop.webmail.com" and then add it in the Virtual host to enable the SSL support. Let's see how to create a self signed certificate.

root@ubuntu:/var/#openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/httpd/conf/ssl/rainloop.webmail.com.key -out /etc/httpd/conf/ssl/rainloop.webmail.com.crt
Generating a 2048 bit RSA private key
....................................................................................+++
.....................+++
writing new private key to '/etc/httpd/conf/ssl/rainloop.webmail.com.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:IN
State or Province Name (full name) [Some-State]:K-----A
Locality Name (eg, city) []:C-----N
Organization Name (eg, company) [Internet Widgits Pty Ltd]:VIP
Organizational Unit Name (eg, section) []:VIP
Common Name (e.g. server FQDN or YOUR name) []:rainloop.webmail.com
Email Address []:-----@gmail.com

As seen here, you can provide the details required to generate the certificate. Once it is created, you can add those to our Apache configuration file, as below:

root@ubuntu:/etc/apache2/sites-available# cat rainloop-ssl.conf
<VirtualHost *:443>
ServerName rainloop.lan
DocumentRoot "/var/www/rainloop/"
ServerAdmin you@example.com
ErrorLog "/var/log/httpd/rainloop-ssl-error_log"
TransferLog "/var/log/httpd/rainloop-ssl-access_log"

SSLEngine on
SSLCertificateFile "/etc/httpd/conf/ssl/rainloop.lan.crt"
SSLCertificateKeyFile "/etc/httpd/conf/ssl/rainloop.lan.key"

<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>

BrowserMatch "MSIE [2-5]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0

CustomLog "/var/log/httpd/ssl_request_log" \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

<Directory />
Options +Indexes +FollowSymLinks +ExecCGI
AllowOverride All
Order deny,allow
Allow from all
Require all granted
</Directory>

</VirtualHost>

Enabling SSL for the Vhost

We can use this command a2ensite in Ubuntu to enable SSL for the enabled domain VirtualHost.

root@ubuntu:/etc# a2ensite rainloop-ssl
Site rainloop-ssl already enabled

Modify the open_basedir value in the PHP configuration file

I've installed PHP 7 in my server, the PHP configuration file is located at /etc/php/7.0/fpm/php.ini. You need to modify the open_basedir value in the PHP configuration file to limit our file operations.

root@ubuntu:~# grep open_basedir /etc/php/7.0/fpm/php.ini
; open_basedir, if set, limits all file operations to the defined directory
open_basedir = /var/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps/:/srv/www/_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps/:/var/www/

After modifying the PHP configuration file, we need to restart the Apache service to make it effective.

Confirm ths status of required PHP modules

This webmail application requires some of the PHP modules to be enabled on the server. Please confirm whether these modules are enabled on your server.

root@rainloop:~# php -m | egrep 'odbc|mcrypt|mysqli|iconv|imap|openssl|pdo|SPL'
iconv
imap
mcrypt
mysqli
odbc
openssl
pdo_mysql
SPL

Also confirm whether the required SSL protocols are enabled on PHP

SSL_supported_phpinfo

Download/Install the RainLoop Webmail application

You can go to the Official RainLoop site and download the latest version available from their website.

root@ubuntu:~# wget http://repository.rainloop.net/v1/rainloop-latest.zip
--2016-05-26 06:10:42-- http://repository.rainloop.net/v1/rainloop-latest.zip
Resolving repository.rainloop.net (repository.rainloop.net)... 104.28.6.34, 104.28.7.34
Connecting to repository.rainloop.net (repository.rainloop.net)|104.28.6.34|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4794510 (4.6M) [application/zip]
Saving to: ‘rainloop-latest.zip’

rainloop-latest.zip 100%[==================================================================>] 4.57M 1.52MB/s in 3.0s

2016-05-26 06:10:46 (1.52 MB/s) - ‘rainloop-latest.zip’ saved [4794510/4794510]

root@ubuntu:~# unzip rainloop-latest.zip -d /var/www/rainloop/

Once extracting the folder, you can fix the files/folder permissions and ownerships as per the URL here.

root@ubuntu:/var/www/rainloop# chown -R www-data:www-data .

Configure RainLoop via Web Interface

You can manage the Webmail interface either from the Web interface or by modifying the variables in the file /var/www/rainloop/data/_data_dc70aaa98299c32ee3d3ee747f40c63b/_default_/configs/application.ini.

Web interface provides a user-friendly access to modify the settings. We can access the Admin interface from the URL >>http://rainloop.webmail.com/?admin with default user/password. The default admin password is "12345".

admin_webmail

After login, you need to update your user password to secure one. You can further modify your admin password at Security tab.

security_password reset

If you don't have a database, you can create one named rainloop and provide the required access. All your email contacts and filters will be saved in this database.

mysql_contacts

By default, this webmail includes GMail, yahoo, qq and outlook mail servers. We can even include as many mail servers domains to this as required.

domains

As you can see all the mail server settings for GMail are added to this system by default.

gmail-rainloop

 

The plugin tab displays the available plugins and their purpose. You can install any available plugins as per your purpose from the Plugins tab.

rainloop plugin

I installed the plugin called POPPASSD which provided me an option to change my email account password. After enabling the required settings. You can access your mail server domain in the browser from the URL >>http://rainloop.webmail.com/

rainloopadmin

You can give the required email/password to access your email. I accessed one of my test yahoo account with my credentials.

rainloop-yahoo

You can get more information regarding the Rain Loop Webmail here.  Howdy! your new advanced email client is ready to use now. Thank you for reading this. I hope you enjoyed reading this article. I would appreciate your valuable comments and suggestions on this.

Have a Good Day!

The post How to Install RainLoop Webmail on Ubuntu 16.04 appeared first on LinOxide.

How to Install Jenkins on Ubuntu 16.04

$
0
0

Jenkins is an open source continuous integration tool, which is used for continuous build, continuous deployment and Testing across multiple servers faster.  It is a self-contained web-based program, ready to run out-of-the-box, with packages for Windows, Mac OS X and Linux operating systems.  It is a Web application build in Java. It performs these tasks automatically when the configurations are added. In this article, I'm providing the guidelines on how to install and configure Jenkins on your Ubuntu 16.04 server.

Pre-requisites

1. A Web Server (Apache/Nginx/Tomcat)
2. Web-Browser
3. Java Platform
Let's start with the installation steps one by one

Install Java

Since, this web application is build on Java platform, the server needs to be installed with the Latest Java Development Kit. I've used this command to install Java on my server.

root@ubuntu:~# apt-get update
root@ubuntu:~# apt-get install default-jdk

You can confirm the Java Version after installing.

root@ubuntu:~# java -version
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-0ubuntu4~16.04.1-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)

Install Apache2

Every Web application requires a Web browser to server the application. I'm using the Apache Webserver to server this purpose. We can install the Apache webserver with this command.

root@ubuntu:~#apt-get install apache2

root@ubuntu:~# apache2 -v
Server version: Apache/2.4.20 (Ubuntu)
Server built: 2016-05-05T15:42:04
root@ubuntu:~#

Installing Jenkins

Before installing Jenkins, we need to add keys and Jenkins packages to the source list.

root@ubuntu:/usr/local/src# sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'

root@ubuntu:/usr/local/src# cat /etc/apt/sources.list.d/jenkins.list
deb http://pkg.jenkins-ci.org/debian binary/
root@ubuntu:/etc/apt# apt-get install jenkins
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
daemon jenkins
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 68.1 MB of archives.
After this operation, 69.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.linode.com/ubuntu xenial/universe amd64 daemon amd64 0.6.4-1 [98.2 kB]
10% [Connecting to ftp.icm.edu.pl (2001:6a0:0:31::2)]
10% [Connecting to ftp.icm.edu.pl (2001:6a0:0:31::2)]
10% [Connecting to ftp.icm.edu.pl (2001:6a0:0:31::2)]
Get:2 http://pkg.jenkins-ci.org/debian binary/ jenkins 2.7 [68.0 MB]
Fetched 68.1 MB in 2min 34s (441 kB/s)
Selecting previously unselected package daemon.
(Reading database ... 34869 files and directories currently installed.)
Preparing to unpack .../daemon_0.6.4-1_amd64.deb ...
Unpacking daemon (0.6.4-1) ...
Selecting previously unselected package jenkins.
Preparing to unpack .../archives/jenkins_2.7_all.deb ...
Unpacking jenkins (2.7) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for systemd (229-4ubuntu6) ...
Processing triggers for ureadahead (0.100.0-19) ...
Setting up daemon (0.6.4-1) ...
Setting up jenkins (2.7) ...
Processing triggers for systemd (229-4ubuntu6) ...
Processing triggers for ureadahead (0.100.0-19) ..

Start the application after installation

root@ubuntu:/etc/apt# /etc/init.d/jenkins start
[ ok ] Starting jenkins (via systemctl): jenkins.service.

You can manage the Jenkins service using Jenkins daemon. Furthermore, you can analyse the Jenkins log at /var/log/jenkins/jenkins.log for any service troubleshooting.

Confirm the Service Status

root@ubuntu~# netstat -plan | grep java
tcp6 0 0 :::8080 :::* LISTEN 27574/java
tcp6 0 0 :::44507 :::* LISTEN 27574/java
udp6 0 0 :::5353 :::* 27574/java
udp6 0 0 :::33848 :::*

Jenkins runs on the default port 8080. You can modify the Jenkins port 8080 in /etc/default/jenkins file.

root@ubuntu:~# grep HTTP_PORT /etc/default/jenkins
HTTP_PORT=8080

After installing the Jenkins, you can access the Jenkins portal at the URL at http://IP:8080 or http://hostname:8080

Setting up an Apache2 Proxy for port 80 to 8080

We need to configure the virtualhost to proxy port 80 to 8080, so that you can access the Jenkins without specifying any ports, just calling the URL >>>http://IP

Enable Proxy module

You can enable the proxy module by just running this command.

root@jenkins:~# a2enmod proxy
Enabling module proxy.
To activate the new configuration, you need to run:
service apache2 restart

root@jenkins:~# a2enmod proxy_http
Considering dependency proxy for proxy_http:
Module proxy already enabled
Enabling module proxy_http.
To activate the new configuration, you need to run:
service apache2 restart

Restart the Apache service once enabling this module. Now we need to create the virtual host for proxy passing the port. Please see the virtual host details:

root@jenkins:/etc/apache2/sites-available# cat jenkins.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName jenkins.ubuntuserver.com
ServerAlias jenkins
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPreserveHost on
ProxyPass / http://localhost:8080/ nocanon
AllowEncodedSlashes NoDecode
</VirtualHost>

root@jenkins:/etc/apache2/sites-enabled# a2ensite jenkins
Enabling site jenkins.
To activate the new configuration, you need to run:
service apache2 reload

By executing this command, you can enable the Jenkins configuration created. That's all :).  Access your Jenkins portal by just calling http://IP or http://hostname.

Configure Jenkins

After installing Jenkins, we can access the Jenkins Portal. It will look as the snapshot below:

JenkinsAdmin

Now we need to copy and paste this file content from this above location mentioned "/var/lib/jenkins/secrets/initialAdminPassword" and paste in here to continue. This will direct to the next page.

Jenkin_setup

We need to install the suggested Jenkins plugins as per our requirement. Once installed it will ask us to create the Admin user to manage the Jenkins portal. We need to provide these details to continue.Jenkinadmin

Now it gives us the management Portal.

Jenkinadminpage

That's all :). Now we're ready to get started with our continuous integration tool.  Thank you for reading this article. I hope you enjoyed reading this. I would recommend your valuable comments and suggestions on this.

The post How to Install Jenkins on Ubuntu 16.04 appeared first on LinOxide.

How to Run Puppet on Container Infrastructure using Docker

$
0
0

Docker is an Opensource Container based technology. It is giving us a workflow around containers which is much easy to use. Docker separates application from underlying operating system using container technology, similar to how Virtual Machines separate the operating system from underlying hardware.

Docker Container Vs Virtual Machines

The Virtual Machines includes applications, necessary binaries and libraries along with an entire guest operating systems which may weigh around 10s of GBs

While, the Docker Engine container comprises just the application and its dependencies. It runs as an isolated process in the user space on the host operating system, sharing the kernel with other containers. Thus, it enjoys the resource isolation and allocation benefits of VMs, but is much more fast, portable, scalable and efficient.

Docker Benefits

Scalability : These containers are extremely lightweight which makes scaling up and scaling down very fast and very easy to launch more containers as we need them or shut them down as we no longer need them.

Portablility : We can move them very easily. We're going to get into images and registries. But essentially, we can take  snapshots of  our environment and upload it to the public/private registry and then download that images for making containers of it anywhere.

Deployments : We can run  these containers almost anywhere  to deploy it namely Desktops, laptops, Virtual machines, Public/Private clouds etc.

In this article, I'm explaining how to install Docker on Ubuntu 1604 server and run Puppet inside a Docker container.

Installing Docker

It is supported in almost all operating Systems. To install Docker in a Ubuntu server, it requires a 64 bit architecture and a kernal version  of atleast or above 3.10. Let's start with the installation prerequisites.

Pre-requisites

Check the Kernel version and Architecture

We can use this commands to confirm the architecture and kernel version of our OS.

root@ubuntu:~# arch
x86_64
root@ubuntu:~# uname -r
4.4.0-21-generic

Now, next step is to update the APT repository packages. In addition, we need to ensure that it runs with https and install the required CA certificates. Run the following command to achieve this.

root@ubuntu:~# apt-get update

root@ubuntu:~# apt-get install apt-transport-https ca-certificates
Reading package lists... Done
Building dependency tree
Reading state information... Done
ca-certificates is already the newest version (20160104ubuntu1).
The following packages will be upgraded:
apt-transport-https
1 upgraded, 0 newly installed, 0 to remove and 54 not upgraded.
Need to get 25.7 kB of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.linode.com/ubuntu xenial-updates/main amd64 apt-transport-https amd64 1.2.12~ubuntu16.04.1 [25.7 kB]
Fetched 25.7 kB in 0s (2,540 kB/s)
(Reading database ... 25186 files and directories currently installed.)
Preparing to unpack .../apt-transport-https_1.2.12~ubuntu16.04.1_amd64.deb ...
Unpacking apt-transport-https (1.2.12~ubuntu16.04.1) over (1.2.10ubuntu1) ...
Setting up apt-transport-https (1.2.12~ubuntu16.04.1) ...

Creating Repository file for Docker

Make sure your repository configuration file is properly set to download the packages for Docker.

root@ubuntu:/etc/apt/sources.list.d# cat /etc/apt/sources.list.d/docker.list
deb https://apt.dockerproject.org/repo ubuntu-xenial main

Once it's added, you can update the packages once more by running "apt-get update". Make sure it takes the updates from the right repos. Remove any old docker package if it exists.

root@ubuntu:/etc/apt/sources.list.d# apt-get purge lxc-docker
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package 'lxc-docker' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 54 not upgrad

root@ubuntu:~# apt-cache policy docker-engine
docker-engine:
Installed: (none)
Candidate: 1.11.2-0~xenial
Version table:
1.11.2-0~xenial 500
500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
1.11.1-0~xenial 500
500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
1.11.0-0~xenial 500
500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages

Install Kernel packages

For Ubuntu Xenial 16.04 version, it's recommended to install the linux_extra_image package which is compatible with the Kernel package. This package enables the Aufs storage driver.  AUFS storage driver takes multiple directories on a single host, stacks them on top of each other, providing a single unified view.

root@ubuntu:~# apt-get install linux-image-extra-$(uname -r)
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
crda iw libnl-3-200 libnl-genl-3-200 wireless-regdb
The following NEW packages will be installed:
crda iw libnl-3-200 libnl-genl-3-200 linux-image-extra-4.4.0-21-generic wireless-regdb
0 upgraded, 6 newly installed, 0 to remove and 54 not upgraded.
Need to get 39.0 MB of archives.

Installation

Now we can go ahead with the installation of the Docker.

root@ubuntu:~# apt-get install docker-engine
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
aufs-tools cgroupfs-mount git git-man liberror-perl libltdl7 libperl5.22 patch perl perl-modules-5.22 rename xz-utils
Suggested packages:
mountall git-daemon-run | git-daemon-sysvinit git-doc git-el git-email git-gui gitk gitweb git-arch git-cvs git-mediawiki git-svn
diffutils-doc perl-doc libterm-readline-gnu-perl | libterm-readline-perl-perl make
The following NEW packages will be installed:
aufs-tools cgroupfs-mount docker-engine git git-man liberror-perl libltdl7 libperl5.22 patch perl perl-modules-5.22 rename xz-utils
0 upgraded, 13 newly installed, 0 to remove and 54 not upgraded.
Need to get 24.8 MB of archives.
After this operation, 139 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
WARNING: The following packages cannot be authenticated!

Start and confirm the Docker status

root@ubuntu:~# service docker start

root@ubuntu:~# docker version
Client:
Version: 1.11.2
API version: 1.23
Go version: go1.5.4
Git commit: b9f10c9
Built: Wed Jun 1 22:00:43 2016
OS/Arch: linux/amd64

Server:
Version: 1.11.2
API version: 1.23
Go version: go1.5.4
Git commit: b9f10c9
Built: Wed Jun 1 22:00:43 2016
OS/Arch: linux/amd64
root@ubuntu:~#

This below command downloads a test image namely hello-world from the Docker registry and runs it in a container. When the container runs, it prints an informational message. Then, it exits. Thus we can confirm the Docker working.

root@ubuntu:~# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
4276590986f6: Pull complete
a3ed95caeb02: Pull complete
Digest: sha256:a7d7a8c072a36adb60f5dc932dd5caba8831ab53cbf016bcdd6772b3fbe8c362
Status: Downloaded newer image for hello-world:latest

Hello from Docker.
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker Hub account:
https://hub.docker.com

For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/

Now we're ready to start with Docker. We can download all required images from the Docker Hub using the command

docker pull image_name. For instance, let see how I'm downloading the some of the useful images.

root@ubuntu:~# docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
5ba4f30e5bea: Pull complete
9d7d19c9dc56: Pull complete
ac6ad7efd0f9: Pull complete
e7491a747824: Pull complete
a3ed95caeb02: Pull complete
Digest: sha256:46fb5d001b88ad904c5c732b086b596b92cfb4a4840a3abd0e35dbb6870585e4
Status: Downloaded newer image for ubuntu:latest

This has downloaded the Ubuntu image from the Docker Hub and we can use this for creating a Ubuntu container with this image.

root@ubuntu:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 2fa927b5cdd3 11 days ago 122 MB
hello-world latest 94df4f0ce8a4 6 weeks ago 967 B

Creating Puppet inside a Docker container

For creating puppet containers, first we need to download the Puppet packages from the docker hub.

  • puppet/puppet-agent-ubuntu
  • puppet/puppetserver
  • puppet/puppetdb
  • puppet/puppetdb-postgres

Let's see how I downloaded these images from the Docker hub. You can use the command docker pull Image_name for that.

root@ubuntu:~# docker pull puppet/puppetserver
Using default tag: latest
latest: Pulling from puppet/puppetserver
5ba4f30e5bea: Already exists
9d7d19c9dc56: Already exists
ac6ad7efd0f9: Already exists
e7491a747824: Already exists
a3ed95caeb02: Already exists
158cd0fe54d8: Pull complete
7a15dfe1145a: Pull complete
0bb8d51ae57c: Pull complete
7b09944cb025: Pull complete
6bf96d82eed5: Pull complete
58fa7008c2bc: Pull complete
659b4b2b3359: Pull complete
0e205bb6d03b: Pull complete
915e3853b669: Pull complete
750b3208f97d: Pull complete
8fec247907de: Pull complete
Digest: sha256:c43290ca040a7693d9f41448eab4ff2444c61757aa303bd7979f7f1ef3e4ae95
Status: Downloaded newer image for puppet/puppetserver:latest

root@ubuntu:~# docker pull puppet/puppetdb
Using default tag: latest
latest: Pulling from puppet/puppetdb
0be59000882d: Pull complete
f20b6f990572: Pull complete
53662c966c9f: Pull complete
a3ed95caeb02: Pull complete
5eae59cbe62c: Pull complete
2b8ff6279504: Pull complete
612d7a4576b7: Pull complete
60577ed4c036: Pull complete
f99ad2d50f6f: Pull complete
9da7f43c61dc: Pull complete
e4c4271df64b: Pull complete
Digest: sha256:6532e4e3750183cd6951df6deb7bb1adb1e0e0ed37aa9e1e0294e257d73d9b1f
Status: Downloaded newer image for puppet/puppetdb:latest

root@ubuntu:~# docker pull puppet/puppetdb-postgres
Using default tag: latest
latest: Pulling from puppet/puppetdb-postgres
8b87079b7a06: Pull complete
a3ed95caeb02: Pull complete
ff6abb23e531: Pull complete
8364ca902ad3: Pull complete
84179c1b7ff6: Pull complete
be951654637c: Pull complete
4841dfc8333f: Pull complete
8e92fd62d485: Pull complete
13e5de4be2f2: Pull complete
d6aaf4d83b1c: Pull complete
3113f93aec6d: Pull complete
055e85b433f4: Pull complete
a97f9981bfe1: Pull complete
6c162fdd1104: Pull complete
Digest: sha256:d42428f0ecf75f7a0dbebee79cb45afaebfd193051fa1002e64fa026b2060f13
Status: Downloaded newer image for puppet/puppetdb-postgres:latest

root@ubuntu:~# docker pull puppet/puppet-agent-ubuntu
Using default tag: latest
latest: Pulling from puppet/puppet-agent-ubuntu
0be59000882d: Already exists
f20b6f990572: Already exists
53662c966c9f: Already exists
a3ed95caeb02: Already exists
576aca0f90fb: Pull complete
b1842b47756f: Pull complete
Digest: sha256:1867bcbe733adcbdfa004ec76ce8940a0927eef8877ee4f07b1ace4e68e7c5fa
Status: Downloaded newer image for puppet/puppet-agent-ubuntu:latest

Now we've downloaded all required images. You can view it by running docker images command.

root@ubuntu:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
puppet/puppetserver latest 0ac3058fad18 4 days ago 379.9 MB
puppet/puppetdb latest f3f9d8b3e54f 6 days ago 368.4 MB
puppet/puppet-agent-ubuntu latest 57fe50639909 6 days ago 202.9 MB
puppet/puppetdb-postgres latest 4f4ed55af431 10 days ago 265.8 MB
ubuntu latest 2fa927b5cdd3 11 days ago 122 MB
hello-world latest 94df4f0ce8a4 6 weeks ago 967 B

Before creating our Puppet container, we need to create a Docker network to add these Puppet containers as below.

root@ubuntu:~# docker network create puppet
e1ebd861dbb39be31da81a88e411e7f4762814ee203b371fca7643a7bb6840eb

Creating Puppet Master server

We can create puppet server with the image "puppet/puppetserver" with name puppet in the puppet network with hostname "puppet-linoxide".

root@ubuntu:~# docker run --net puppet --name puppet --hostname puppet.linoxide puppet/puppetserver
Warning: The following options to parse-opts are unrecognized: :flag
2016-06-08 09:36:24,348 INFO [o.e.j.u.log] Logging initialized @27125ms
2016-06-08 09:36:36,393 INFO [p.s.v.versioned-code-service] No code-id-command set for versioned-code-service. Code-id will be nil.
2016-06-08 09:36:36,394 INFO [p.s.v.versioned-code-service] No code-content-command set for versioned-code-service. Attempting to fetch code content will fail.
2016-06-08 09:36:36,396 INFO [p.t.s.w.jetty9-service] Initializing web server(s).
2016-06-08 09:36:36,450 INFO [p.s.j.jruby-puppet-service] Initializing the JRuby service
2016-06-08 09:36:36,455 WARN [p.s.j.jruby-puppet-service] The 'jruby-puppet.use-legacy-auth-conf' setting is set to 'true'. Support for the legacy Puppet auth.conf file is deprecated and will be removed in a future release. Change this setting to 'false' and migrate your authorization rule definitions in the /etc/puppetlabs/puppet/auth.conf file to the /etc/puppetlabs/puppetserver/conf.d/auth.conf file.
2016-06-08 09:36:36,535 INFO [p.s.j.jruby-puppet-internal] Creating JRuby instance with id 1.
2016-06-08 09:36:53,825 WARN [puppetserver] Puppet Comparing Symbols to non-Symbol values is deprecated
(file & line not available)
2016-06-08 09:36:54,019 INFO [puppetserver] Puppet Puppet settings initialized; run mode: master
2016-06-08 09:36:56,811 INFO [p.s.j.jruby-puppet-agents] Finished creating JRubyPuppet instance 1 of 1
2016-06-08 09:36:56,849 INFO [p.s.c.puppet-server-config-core] Initializing webserver settings from core Puppet
2016-06-08 09:36:59,780 INFO [p.s.c.certificate-authority-service] CA Service adding a ring handler
2016-06-08 09:36:59,827 INFO [p.s.p.puppet-admin-service] Starting Puppet Admin web app
2016-06-08 09:37:06,473 INFO [p.s.m.master-service] Master Service adding ring handlers
2016-06-08 09:37:06,558 WARN [o.e.j.s.h.ContextHandler] Empty contextPath
2016-06-08 09:37:06,572 INFO [p.t.s.w.jetty9-service] Starting web server(s).
2016-06-08 09:37:06,606 INFO [p.t.s.w.jetty9-core] webserver config overridden for key 'ssl-cert'
2016-06-08 09:37:06,607 INFO [p.t.s.w.jetty9-core] webserver config overridden for key 'ssl-key'
2016-06-08 09:37:06,608 INFO [p.t.s.w.jetty9-core] webserver config overridden for key 'ssl-ca-cert'
2016-06-08 09:37:06,608 INFO [p.t.s.w.jetty9-core] webserver config overridden for key 'ssl-crl-path'
2016-06-08 09:37:07,037 INFO [p.t.s.w.jetty9-core] Starting web server.
2016-06-08 09:37:07,050 INFO [o.e.j.s.Server] jetty-9.2.z-SNAPSHOT
2016-06-08 09:37:07,174 INFO [o.e.j.s.h.ContextHandler] Started o.e.j.s.h.ContextHandler@18ee4ac3{/puppet-ca,null,AVAILABLE}
2016-06-08 09:37:07,175 INFO [o.e.j.s.h.ContextHandler] Started o.e.j.s.h.ContextHandler@4c1434a7{/puppet-admin-api,null,AVAILABLE}
2016-06-08 09:37:07,176 INFO [o.e.j.s.h.ContextHandler] Started o.e.j.s.h.ContextHandler@7eef9da2{/puppet,null,AVAILABLE}
2016-06-08 09:37:07,177 INFO [o.e.j.s.h.ContextHandler] Started o.e.j.s.h.ContextHandler@26ad2d06{/,null,AVAILABLE}
2016-06-08 09:37:07,364 INFO [o.e.j.s.ServerConnector] Started ServerConnector@66b8635c{SSL-HTTP/1.1}{0.0.0.0:8140}
2016-06-08 09:37:07,365 INFO [o.e.j.s.Server] Started @70146ms
2016-06-08 09:37:07,381 INFO [p.s.m.master-service] Puppet Server has successfully started and is now ready to handle requests
2016-06-08 09:37:07,393 INFO [p.s.l.legacy-routes-service] The legacy routing service has successfully started and is now ready to handle requests

Now we've our Puppet Server created and running.

root@ubuntu:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f4b9f456a4c2 puppet/puppetserver "dumb-init /docker-en" 3 minutes ago Up 3 minutes 8140/tcp puppet

Creating Puppet Client

By running this command, you're creating another container as Puppet client with hostname Puppeet-client-linoxide with the docker image puppet/puppet-agent-ubuntu agent. You can either use this command to create the Puppet client or you can just use docker run --net puppet puppet/puppet-agent-ubuntu  to built one. If you're running this command,  with a onetime flag which means, Puppet exits after the first run.

root@ubuntu:~# docker run --net puppet --name puppet-client --hostname puppet-client-linoxide puppet/puppet-agent-ubuntu agent --verbose --no-daemonize --summarize
Info: Creating a new SSL key for puppet-client-linoxide.members.linode.com
Info: Caching certificate for ca
Info: csr_attributes file loading from /etc/puppetlabs/puppet/csr_attributes.yaml
Info: Creating a new SSL certificate request for puppet-client-linoxide.members.linode.com
Info: Certificate Request fingerprint (SHA256): 62:E2:37:8A:6E:0D:18:AC:81:0F:F1:3E:D6:08:10:29:D4:D6:21:16:59:B7:6D:3F:AA:5C:7A:08:38:B6:6B:07
Info: Caching certificate for puppet-client-linoxide.members.linode.com
Info: Caching certificate_revocation_list for ca
Info: Caching certificate for ca
Notice: Starting Puppet client version 4.5.1
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for puppet-client-linoxide.members.linode.com
Info: Applying configuration version '1465378896'
Info: Creating state file /opt/puppetlabs/puppet/cache/state/state.yaml
Notice: Applied catalog in 0.01 seconds
Changes:
Events:
Resources:
Total: 7
Time:
Schedule: 0.00
Config retrieval: 1.55
Total: 1.56
Last run: 1465378896
Filebucket: 0.00
Version:
Config: 1465378896
Puppet: 4.5.1

But if you're using this above command, then the container won't exit, It stays online and updates Puppet every 30 minutes based on the latest content from the Puppet Server. Now we've our Puppet server/Client running on our Docker.

root@ubuntu:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5f29866a103b puppet/puppet-agent-ubuntu "/opt/puppetlabs/bin/" 8 minutes ago Up 8 minutes puppet-client
f4b9f456a4c2 puppet/puppetserver "dumb-init /docker-en" 13 minutes ago Up 13 minutes 8140/tcp puppet

 

Creating PuppetDB

We can run a PuppetDB server in a docker container. Inorder to run a PuppetDB, we need a Postgres Server running. Docker supports only PostgreSQL server. This too can be another container instance, or RDS (Relational Database Service) end point or a Physical DB somewhere.  In addition, It requires a Puppet Master running. In order to use SSL certs during the initialization, you will need at least a token puppet master running that the container can connect to initialize the certs.

root@ubuntu:~# git clone https://github.com/tizzo/docker-puppetdb.git
Cloning into 'docker-puppetdb'...
remote: Counting objects: 12, done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 12 (delta 3), reused 12 (delta 3), pack-reused 0
Unpacking objects: 100% (12/12), done.
Checking connectivity... done.

root@ubuntu:~# cd docker-puppetdb/

Create a Docker file compatible with Ubuntu 16.04. I got my Dockerfile and run the docker build.

root@ubuntu:~/docker-puppetdb# docker build .
Sending build context to Docker daemon 68.1 kB
Step 1 : FROM ubuntu:16.04
16.04: Pulling from library/ubuntu
5ba4f30e5bea: Already exists
9d7d19c9dc56: Already exists
ac6ad7efd0f9: Already exists
e7491a747824: Already exists
a3ed95caeb02: Already exists
Digest: sha256:f5edf3b741a08b573eca6bf25257847613540538a17b86e2b76e14724a0be68a
Status: Downloaded newer image for ubuntu:16.04
---> 2fa927b5cdd3
Step 2 : MAINTAINER Gareth Rushgrove "gareth@puppet.com"
---> Running in 555edbbd1017
---> a3d4cea623ac
Removing intermediate container 555edbbd1017
Step 3 : ENV PUPPETDB_VERSION "4.1.0" PUPPET_AGENT_VERSION "1.5.1" DUMB_INIT_VERSION "1.0.2" UBUNTU_CODENAME "xenial" PUPPETDB_USER puppetdb PUPPETDB_PASSWORD puppetdb PUPPETDB_JAVA_ARGS "-Djava.net.preferIPv4Stack=true -Xms256m -Xmx256m" PATH /opt/puppetlabs/server/bin:/opt/puppetlabs/puppet/bin:/opt/puppetlabs/bin:$PATH
---> Running in 4cb8a8220b1c

Once this is completed we can create our PuppetDB container.

root@ubuntu:~# docker run --net puppet --name puppetdb-postgres -e POSTGRES_PASSWORD=puppetdb -e POSTGRES_USER=puppetdb -d postgres
855a6b13fefa4123d5e16cdde84ebc7174ba149e66699e4c94c14e8fbfcac22f

root@ubuntu:~# docker run --net puppet -d -P --name puppetdb --link puppetdb-postgres:postgres puppet/puppetdb
bfe56b64bd980d20570374ed8204136303d82de8cbf1a4279c2f2fd25a798f59

All our containers are  running, we can even confirm its status by with this command, docker ps as shown below:

puppetcontainers

We can access our PuppetDB Dashboard at the URL >>http://Docker-Server-IP:32771

PuppetDB: Dashboard

Hurray! This is how we can make Puppet to run on a container infrastructure inside Docker. I hope you enjoyed reading this article. I would recommend your valuable comments and suggestions on this.

Thank you! Have a Nice Day :)

The post How to Run Puppet on Container Infrastructure using Docker appeared first on LinOxide.

How to Run Single-Node Cassandra Cluster in Ubuntu 16.04

$
0
0

Apache Cassandra is a open source distributed, high performance, extremely scalable and fault tolerant post-relational database solution. It can serve as both real-time data store for online/transactional applications, and as read-intensive database for business intelligence systems.

Relational DB Vs Cassandra

Relational database systems handles moderate incoming data velocity and fetches data from one or few locations. It manages primarily structured data and supports complex/nested transactions with single points of failure with fail over.

Cassandra handles high incoming data velocity by fetching data from many locations. It manages all data types and supports simple transactions with no single points of failure; it provides constant uptime. In addition, it provides read/write scalability.

In this article, I'm providing the guidelines on how I installed Apache Cassandra and ran a single-node cluster on my Ubuntu 16.04 server.

 Pre-requisites

  • It requires a Java Platform to run
  • A user to run this application

Install Java

Cassandra needs Java application to be running on your server, make sure you have installed latest Java version. You can update the APT repository packages and install Java. Cassandra 3 or later requires Java 8+ version to be installed.

root@ubuntu:~# apt-get update

root@ubuntu:~# apt-get install default-jdk
Setting up default-jdk (2:1.8-56ubuntu2) ...
Setting up gconf-service-backend (3.2.6-3ubuntu6) ...
Setting up gconf2 (3.2.6-3ubuntu6) ...
Setting up libgnomevfs2-common (1:2.24.4-6.1ubuntu1) ...
Setting up libgnomevfs2-0:amd64 (1:2.24.4-6.1ubuntu1) ...
Setting up libgnome2-common (2.32.1-5ubuntu1) ...
Setting up libgnome-2-0:amd64 (2.32.1-5ubuntu1) ...
Processing triggers for libc-bin (2.23-0ubuntu3) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (229-4ubuntu4) ...
Processing triggers for ca-certificates (20160104ubuntu1) ...
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...

done.
done.

You can confirm the Java version installed.

root@ubuntu:~# java -version
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-0ubuntu4~16.04.1-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)

Creating a user to run Cassandra

It is always recommended to run this application as a user instead of root. Hence, I created my Cassandra user to run this application.

root@ubuntu:~# groupadd cassandra
root@ubuntu:~# useradd -d /home/cassandra -s /bin/bash -m -g cassandra cassandra

root@ubuntu:~# grep cassandra /etc/passwd
cassandra:x:1000:1000::/home/cassandra:/bin/bash

Download and Install Cassandra

Now we can download the latest Apache Cassandra from here and copy to your preferred directory. I downloaded this tar file to my /tmp folder and extracted the contents to my cassandra "home" there.

root@ubuntu:/tmp# wget http://mirror.cc.columbia.edu/pub/software/apache/cassandra/3.6/apache-cassandra-3.6-bin.tar.gz
--2016-06-12 08:36:47-- http://mirror.cc.columbia.edu/pub/software/apache/cassandra/3.6/apache-cassandra-3.6-bin.tar.gz
Resolving mirror.cc.columbia.edu (mirror.cc.columbia.edu)... 128.59.59.71
Connecting to mirror.cc.columbia.edu (mirror.cc.columbia.edu)|128.59.59.71|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 35552323 (34M) [application/x-gzip]
Saving to: ‘apache-cassandra-3.6-bin.tar.gz’

apache-cassandra-3.6-bin.tar.gz 100%[===================================================================>] 33.91M 6.43MB/s in 12s

2016-06-12 08:37:01 (2.93 MB/s) - ‘apache-cassandra-3.6-bin.tar.gz’ saved [35552323/35552323]

root@ubuntu:/tmp# tar -xvf apache-cassandra-3.6-bin.tar.gz -C /home/cassandra --strip-components=1

Correcting the ownerships and setting variables

You can correct the ownerships for the files and set proper environment variables to run this application smoothly.

root@ubuntu:/home/cassandra# export CASSANDRA_HOME=/home/cassandra
root@ubuntu:/home/cassandra# export PATH=$PATH:$CASSANDRA_HOME/bin
root@ubuntu:/home/cassandra# chown -R cassandra.cassandra .

Now you can switch to the cassandra user and run this application as below:

cassandra@ubuntu:~$ sh bin/cassandra

INFO 09:10:39 Cassandra version: 3.6
INFO 09:10:39 Thrift API version: 20.1.0
INFO 09:10:39 CQL supported versions: 3.4.2 (default: 3.4.2)
INFO 09:10:39 Initializing index summary manager with a memory pool size of 24 MB and a resize interval of 60 minutes
INFO 09:10:39 Starting Messaging Service on localhost/127.0.0.1:7000 (lo)
INFO 09:10:39 Loading persisted ring state
INFO 09:10:39 Starting up server gossip
INFO 09:10:39 Updating topology for localhost/127.0.0.1
INFO 09:10:39 Updating topology for localhost/127.0.0.1
INFO 09:10:39 Node localhost/127.0.0.1 state jump to NORMAL

This output means, your Cassandra server is up and running fine now. Now we can check and confirm the status of our Cluster by this command.

root@ubuntu:/home/cassandra# nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 127.0.0.1 142.65 KiB 256 100.0% fc76be14-acde-47d4-a4a2-5d015804bb3c rack1

The status and state notation UN means it is up and normal.

We are done with installing Single Node Cassandra cluster. Now we can see how to connect to our cluster.

Connecting to our Cluster

We can execute this shell script  "cqlsh" to connect to our cluster node.

cassandra1These are the various CQL commands used in Cassandra. You can get more information on how to use this here.

Howdy! we're done with a Single-Node Cassandra Cluster in our Ubuntu 16.04 server. I hope you enjoyed reading this. I would recommend your valuable comments and suggestions on this.

Thank you!

The post How to Run Single-Node Cassandra Cluster in Ubuntu 16.04 appeared first on LinOxide.

Viewing all 60 articles
Browse latest View live