Thursday, June 23, 2016

Installing RatticDB - OpenSource Password Manager On CentOS7


Installing RatticDB - OpenSource Password Manager On CentOS7


Install CentOS 7

Install CentOS 7 with 'minimal install' option
  • yum install epel-release
  • yum update
  • yum upgrade
  • yum groupinstall development
  • yum groupinstall "Web Server"
  • yum install gcc openldap-devel bzip2-devel sqlite-devel libxml2-devel libxslt-devel wget openssl-devel python-pip cryptsetup mod_wsgi vim
  • yum install tk-devel ncurses-devel readline-devel mysql-devel ntp
  • yum install httpd-devel python-devel
  • chkconfig ntpd on
  • service ntpd start

Setup the hostname:

#vim /etc/hostname

pwdmngr.example.com

Disable SELINUX
NOTE: With CentOS 6.6 i have managed to move mysql to encrypted partition when SELINUX is enable, i haven't managed to do it with CentOS 7.
  • vim /etc/selinux/config
-  SELINUX=enforcing
+ SELINUX=disabled
  • reboot
Install and Set up MySQL (You can also install MariaDB with epel repo)
Change the root password? [Y/n] Y
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y
  • mysql -u root -p 
create database rattic;
create user rattic@localhost identified by '***rattic-db-password***';
grant all on rattic.* to rattic;

Optional: Set  up encrypted device for MySQL
  • cryptsetup luksFormat /dev/sdb1
  • cryptsetup luksOpen /dev/sdb1 rattic_encrypted
  • pvcreate /dev/mapper/rattic_encrypted
  • vgcreate rattic_VG /dev/mapper/rattic_encrypted
  • lvcreate -l 100%VG -n rattic_LV rattic_VG
  • mkfs.ext4 /dev/mapper/rattic_VG-rattic_LV
  • mkdir /opt/apps/mysql
  • mount /dev/mapper/rattic_VG-rattic_LV /opt/apps/mysql

Optional: Change MySQL Database directory
  • systemctl stop mysqld.service
  • cp -r /var/lib/mysql/* /opt/apps/mysql
  • mv /var/lib/mysql /var/lib/mysql_OLD
  • ln -s /opt/apps/mysql /var/lib/mysql
  • chown -R mysql:mysql mysql
  • vim /etc/my.cnf
- datadir=/var/lib/mysql
- socket=/var/lib/mysql/mysql.sock
+ datadir=/opt/apps/mysql
+ socket=/opt/apps/mysql/mysql.sock
  • systemctl start mysql.service

Configure RatticDB
  • cd /tmp
Download latest stable version from github
  • wget https://github.com/tildaslash/RatticWeb/archive/master.zip
  • unzip master.zip
  • mv RatticWeb /opt/apps/RatticWeb
  • cd /opt/apps/RatticWeb
  • pip install -r requirements-mysql.txt
  • mkdir /opt/apps/RatticWeb/static
  • chown -R rattic /opt/apps/RatticWeb
  • useradd -c "RatticWeb" -m rattic
  • su - rattic
Note: Change hostname with your hostname, set any secret key, set the myql password here.
  • vim /opt/apps/RatticWeb/conf/local.cfg
[ratticweb]
debug = False
secretkey = ***rattic-secret-key***
hostname = ratticdb

[filepaths]
static = /opt/apps/RatticWeb/static

[database]
engine = django.db.backends.mysql
name = rattic
user = rattic
password = ***rattic-db-password***
host = localhost
port = 3306
  • exit (back to root)

Configure Apache

Note: Change the "Server Name, Server Alias and Redirect Permanent url with hostname
  • vim /etc/httpd/conf.d/rattic.conf
<VirtualHost *:80>
ServerName ratticdb
ServerAlias ratticdb
Redirect permanent / https://ratticdb
</VirtualHost>
Alias /robots.txt /opt/apps/RatticWeb/static/robots.txt
Alias /favicon.ico /opt/apps/RatticWeb/static/favicon.ico
AliasMatch ^/([^/]*\.css) /opt/apps/RatticWeb/static/styles/$1
Alias /media/ /opt/apps/RatticWeb/media/
Alias /static/ /opt/apps/RatticWeb/static/
<Directory /opt/apps/RatticWeb/static>
#Order deny,allow
#Allow from all
Require all granted
</Directory>
<Directory /opt/apps/RatticWeb/media>
#Order deny,allow
#Allow from all
Require all granted
</Directory>
#WSGISocketPrefix run/wsgi
WSGIScriptAlias / /opt/apps/RatticWeb/ratticweb/wsgi.py
WSGIPassAuthorization On
WSGIDaemonProcess rattic processes=2 threads=25 home=/opt/apps/RatticWeb/ python-path=/opt/apps/RatticWeb display-name=%{GROUP}
WSGIProcessGroup rattic
<Directory /opt/apps/RatticWeb/ratticweb>
<Files wsgi.py>
#Order deny,allow
#Allow from all
Require all granted
</Files>
</Directory>
  • systemctl start httpd.service

Modify firewall
  • iptables -I INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT
  • iptables -I INPUT -m state --state NEW -p tcp --dport 443 -j ACCEPT



# cd /usr/local/lib/python2.7/dist-packages # this path probably varies from system to system # rm -rf kombu/transport/django/migrations djcelery/migrations # mv kombu/transport/django/south_migrations kombu/transport/django/migrations # mv djcelery/south_migrations djcelery/migrations


To sync db follow the below stepls


# pip install -r requirements-base.txt

./manage.py scripts
./manage.py syncdb --noinput
./manage.py migrate --all
./manage.py collectstatic -c --noinput
./manage.py demosetup

Tuesday, May 31, 2016

Python Auto deploy LAMP in centos7 and FreeBSD 10.x

In this Article we will show you how to  deploy and full Lamp  ( Apache /MariaDB server /Php) stack  installation from your laptop  or  local computer to your Centos 7 or FreeBSD 10.x server. In this small test i will show how i installed lamp on Centos 7 from another  Centos machine
Lets show you Python Auto deploy LAMP script how it work .
Behavior
Server1  : puppetnode1
[root@puppetnode1 ~]# lsb_release
LSB Version:    :core-4.1-amd64:core-4.1-noarch
[root@puppetnode1 ~]# lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.2.1511 (Core)
Release:        7.2.1511
Codename:       Core
[root@puppetnode1 ~]# ifconfig  | grep   192
        inet 192.168.28.142  netmask 255.255.255.0  broadcast 192.168.28.255
[root@puppetnode1 ~]#
Server 2 : puppetnode2
[root@puppetnode2 ~]# ifconfig   |  grep  192
        inet 192.168.28.141  netmask 255.255.255.0  broadcast 192.168.28.255
[root@puppetnode2 ~]# lsb_release  -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.2.1511 (Core)
Release:        7.2.1511
Codename:       Core
Show  /etc/hosts  file  on both  machines 
 cat  /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.28.142 puppetnode1.unixmen.com puppetnode1
192.168.28.141 puppetnode2.unixmen.com puppetnode2
Lets   Start   from  downloading script  in   Node2
Downlaod script  from Github
[root@puppetnode2 ~]# wget https://github.com/jamalshahverdiev/freebsd-centos7-amp/archive/master.zip
--2016-05-26 06:10:57--  https://github.com/jamalshahverdiev/freebsd-centos7-amp/archive/master.zip
Connecting to 10.133.80.35:8080... connected.
Proxy request sent, awaiting response... 302 Found
Location: https://codeload.github.com/jamalshahverdiev/freebsd-centos7-amp/zip/master [following]
--2016-05-26 06:10:57--  https://codeload.github.com/jamalshahverdiev/freebsd-centos7-amp/zip/master
Connecting to 10.133.80.35:8080... connected.
Proxy request sent, awaiting response... 200 OK
Length: 59418 (58K) [application/zip]
Saving to: ‘master.zip’
100%[=======================================================================================================>] 59,418      49.6KB/s   in 1.2s
2016-05-26 06:10:59 (49.6 KB/s) - ‘master.zip’ saved [59418/59418]
Extract  the zip  master
[root@puppetnode2 ~]# unzip  master.zip
Archive:  master.zip
81ccf91ee0ee7775c90dbc5a7b50faae4650fdb0
   creating: freebsd-centos7-amp-master/
  inflating: freebsd-centos7-amp-master/README.md
  inflating: freebsd-centos7-amp-master/add-vhost-apmyph.py
  inflating: freebsd-centos7-amp-master/apmyph.py
   creating: freebsd-centos7-amp-master/jinja2temps/
  inflating: freebsd-centos7-amp-master/jinja2temps/apvhost.conf
  inflating: freebsd-centos7-amp-master/jinja2temps/c7httpd.conf
  inflating: freebsd-centos7-amp-master/jinja2temps/cmy.cnf
  inflating: freebsd-centos7-amp-master/jinja2temps/fhttpd.conf
  inflating: freebsd-centos7-amp-master/jinja2temps/fphp.ini
  inflating: freebsd-centos7-amp-master/jinja2temps/lhttpd.conf
  inflating: freebsd-centos7-amp-master/jinja2temps/lphp.ini
  inflating: freebsd-centos7-amp-master/jinja2temps/my.cnf
  inflating: freebsd-centos7-amp-master/jinja2temps/newindex.php
  inflating: freebsd-centos7-amp-master/jinja2temps/ngindex.html
  inflating: freebsd-centos7-amp-master/jinja2temps/nginx.conf
  inflating: freebsd-centos7-amp-master/jinja2temps/ngphp.conf
  inflating: freebsd-centos7-amp-master/jinja2temps/ngphp.lan
  inflating: freebsd-centos7-amp-master/jinja2temps/ngsec.conf
  inflating: freebsd-centos7-amp-master/jinja2temps/tempindex.html
  inflating: freebsd-centos7-amp-master/jinja2temps/tempindex.php
  inflating: freebsd-centos7-amp-master/jinja2temps/www.conf
[root@puppetnode2 ~]#
Enter  the Directory 
you can also check the  content  script  of apmyph.py that we  will use
cat  apmyph.py add  the  bellow code
#!/usr/bin/env python2.7
import sys
import os
import jinja2
from fabric.api import *
from fabric.tasks import execute
import getpass
templateLoader = jinja2.FileSystemLoader( searchpath="/" )
templateEnv = jinja2.Environment( loader=templateLoader )
TEMPAVFILE = os.getcwd()+'/jinja2temps/apvhost.conf'
TEMPHFILE = os.getcwd()+'/jinja2temps/tempindex.html'
TEMPPFILE = os.getcwd()+'/jinja2temps/tempindex.php'
tempav = templateEnv.get_template( TEMPAVFILE )
tempht = templateEnv.get_template( TEMPHFILE )
tempphp = templateEnv.get_template( TEMPPFILE )
env.host_string = raw_input('Please enter WEB server IP address: ')
env.user = raw_input('Please enter username for UNIX/Linux server: ')
env.password = getpass.getpass()
sitename = raw_input('Please enter site name: ')
tempavVars = { "sname" : sitename, "domain" : sitename, }
outputavText = tempav.render( tempavVars )
outputahText = tempht.render( tempavVars )
with settings(
        hide('warnings', 'running', 'stdout', 'stderr'), 
        warn_only=True
):
    osver = run('uname -s')
    lintype = run('cat /etc/redhat-release | awk \'{ print $1 }\'')
    ftype = run('uname -v | awk \'{ print $2 }\' | cut -f1 -d \'.\'')
    if osver == 'FreeBSD' and ftype >= 10:
        print(' This is FreeBSD server...')
        getfhttpdpack = run('which httpd')
        httpdpidfile = run('cat /var/run/httpd.pid')
        httpdpid = run('ps waux | grep httpd | grep root | grep -v grep | awk \'{ print $2 }\'')
        if getfhttpdpack == '/usr/local/sbin/httpd' and httpdpidfile == httpdpid:
            print(' You have already installed and running Apache web server...')
            print(' If you want add new VirtualHost, please use ./add-vhost-apmyph.py script. ')
            sys.exit()
        elif getfhttpdpack != '/usr/local/sbin/httpd':
            run('pkg install -y apache24')
            run('echo \'apache24_enable="YES"\' >> /etc/rc.conf')
            ip = run('ifconfig em0 | grep \'inet \' | awk \'{ print $2 }\'')
            name = run('hostname')
            run('echo \"'+ip+' '+name+'.lan '+name+'\" >> /etc/hosts')
            put(os.getcwd()+'/jinja2temps/fhttpd.conf', '/usr/local/etc/apache24/httpd.conf')
            run('mkdir -p /usr/local/domen /var/log/httpd/ /var/www/'+sitename+'_public_html')
            with open(sitename+".conf", "wb") as apvhostfile:
                apvhostfile.write(outputavText)
            put(sitename+'.conf', '/usr/local/domen/'+sitename+'.conf')
            with open("index.html", "wb") as aphtfile:
                aphtfile.write(outputahText)
            put('index.html', '/var/www/'+sitename+'_public_html')
            run('/usr/local/etc/rc.d/apache24 start')
            print('Apache 24 server installed and configured...')
            print('If you want install and configure MySQL PHP just press "Enter"!!!')
            print('If you want to exit from script write "n" and press Enter button. ')
            inst = raw_input('Please select: ')
            if inst == "":
                print('You are selected "Enter" button')
                run('pkg install -y mysql55-server')
                run('pkg install -y mod_php56')
                run('pkg install -y php56-bz2 php56-mysql php56-mysqli php56-calendar php56-ctype php56-curl php56-dom php56-exif php56-fileinfo php56-filter php56-gd php56-gettext php56-hash php56-iconv php56-json php56-mbstring php56-mcrypt php56-openssl php56-posix php56-session php56-simplexml php56-tokenizer php56-wddx php56-xml php56-xmlreader php56-xmlwriter php56-xmlrpc php56-xsl php56-zip php56-zlib')
                put(os.getcwd()+'/jinja2temps/my.cnf', '/etc/my.cnf')
                put(os.getcwd()+'/jinja2temps/fphp.ini', '/usr/local/etc/php.ini')
                run('echo \'mysql_enable="YES"\' >> /etc/rc.conf')
                run('touch /var/log/mysql.log ; chown mysql:mysql /var/log/mysql.log')
                run('/usr/local/etc/rc.d/mysql-server start')
                run('echo -e "\n\nfreebsd\nfreebsd\n\n\n\n\n" | mysql_secure_installation 2>/dev/null')
                msqlpidfile = run('ps waux|grep mysql | grep -v grep| grep -v safe | awk \'{ print $2 }\'')
                msqlpid = run('cat /var/db/mysql/*.pid')
                if msqlpidfile == msqlpid:
                    print('MySQL service already running...')
                    pass
                else:
                    sys.exit()
                sitedb = raw_input('Enter name for new database: ')
                sitedbuser = raw_input('Enter new mysql user name: ')
                sitedbpasswd = getpass.getpass('Enter pass for '+sitedbuser+': ')
                sitedbpasswd1 = getpass.getpass('Repeat pass for '+sitedbuser+': ')
                if sitedbpasswd == sitedbpasswd1:
                    pass
                else:
                    print('The password for site db username must be the same!!! ')
                run('mysql -u root -p\'freebsd\' -e "CREATE DATABASE '+sitedb+';"')
                run('mysql -u root -p\'freebsd\' -e "GRANT ALL PRIVILEGES ON '+sitedb+'.* TO '+sitedbuser+'@localhost IDENTIFIED BY \''+sitedbpasswd+'\';"')
                run('mysql -u root -p\'freebsd\' -e "FLUSH PRIVILEGES;"')
                tempphVars = { "sitedb" : sitedb, "sitedbuser" : sitedbuser, "sitedbpasswd" : sitedbpasswd}
                outputphpText = tempphp.render( tempphVars )
                with open("index.php", "wb") as aphtfile:
                    aphtfile.write(outputphpText)
                put('index.php', '/var/www/'+sitename+'_public_html/index.php')
                run('/usr/local/etc/rc.d/apache24 restart')
                print('MySQL, Apache24 and PHP installed and configured...')
            elif inst == "n":
                print('You entered "n" button.')
            else:
                print('You can only press "Enter" button or write "n" and after press enter button!!!')
    elif osver == 'Linux' and lintype == 'CentOS':
        print(' This is CentOS server...')
        getlhttpdpack = run('which httpd')
        httpdpidfile = run('cat /var/run/httpd/httpd.pid')
        httpdpid = run('ps waux | grep httpd | grep root | grep -v grep | awk \'{ print $2 }\'')
        if getlhttpdpack == '/usr/sbin/httpd' and httpdpidfile == httpdpid:
            print(' You have already installed and running Apache web server...')
            print(' If you want add new VirtualHost, please use ./add-vhost-apmyph.py script')
            sys.exit()
        elif getlhttpdpack != '/usr/sbin/httpd':
            run('yum install -y httpd')
            ip = run('ifconfig `ifconfig | head -n1 | cut -f1 -d\':\'` | grep \'inet \' | awk \'{ print $2 }\'')
            name = run('hostname')
            run('echo \"'+ip+' '+name+'.lan '+name+'\" >> /etc/hosts')
            put(os.getcwd()+'/jinja2temps/c7httpd.conf', '/etc/httpd/conf/httpd.conf')
            run('mkdir -p /usr/local/domen /var/www/'+sitename+'_public_html')
            with open(sitename+".conf", "wb") as apvhostfile:
                apvhostfile.write(outputavText)
            put(sitename+'.conf', '/usr/local/domen/'+sitename+'.conf')
            with open("index.html", "wb") as aphtfile:
                aphtfile.write(outputahText)
            put('index.html', '/var/www/'+sitename+'_public_html')
            run('systemctl start httpd.service ; systemctl enable httpd.service')
            print('Apache 24 server installed and configured...')
            print('If you want install and configure MySQL PHP just press "Enter"!!!')
            print('If you want to exit from script write "n" and press Enter button. ')
            inst = raw_input('Please select: ')
            if inst == "":
                print('You are selected "Enter" button')
                run('yum -y install mariadb-server mariadb')
                run('yum -y install php php-mysql')
                run('yum -y install php-bcmath.x86_64 php-cli.x86_64 php-gd.x86_64 php-mbstring.x86_64 php-xml.x86_64')
                put(os.getcwd()+'/jinja2temps/cmy.cnf', '/etc/my.cnf')
#                put(os.getcwd()+'/jinja2temps/fphp.ini', '/etc/php.ini')
                run('touch /var/log/mysql.log ; chown mysql:mysql /var/log/mysql.log')
                run('systemctl start mariadb ; systemctl enable mariadb')
                run('echo -e "\n\nfreebsd\nfreebsd\n\n\n\n\n" | mysql_secure_installation 2>/dev/null')
                msqlpidfile = run('ps waux|grep mysql | grep -v grep| grep -v safe | awk \'{ print $2 }\'')
                msqlpid = run('cat /var/run/mariadb/mariadb.pid')
                if msqlpidfile == msqlpid:
                    print('MySQL service already running...')
                    pass
                else:
                    print('MySQL service is not running...')
                    sys.exit()
                sitedb = raw_input('Enter name for new database: ')
                sitedbuser = raw_input('Enter new mysql user name: ')
                sitedbpasswd = getpass.getpass('Enter pass for '+sitedbuser+': ')
                sitedbpasswd1 = getpass.getpass('Repeat pass for '+sitedbuser+': ')
                if sitedbpasswd == sitedbpasswd1:
                    pass
                else:
                    print('The repeated password for '+sitedbuser+' must be the same!!! ')
                run('mysql -u root -p\'freebsd\' -e "CREATE DATABASE '+sitedb+';"')
                run('mysql -u root -p\'freebsd\' -e "GRANT ALL PRIVILEGES ON '+sitedb+'.* TO '+sitedbuser+'@localhost IDENTIFIED BY \''+sitedbpasswd+'\';"')
                run('mysql -u root -p\'freebsd\' -e "FLUSH PRIVILEGES;"')
                tempphVars = { "sitedb" : sitedb, "sitedbuser" : sitedbuser, "sitedbpasswd" : sitedbpasswd}
                outputphpText = tempphp.render( tempphVars )
                with open("index.php", "wb") as aphtfile:
                    aphtfile.write(outputphpText)
                put('index.php', '/var/www/'+sitename+'_public_html/index.php')
                run('systemctl restart httpd.service')
                print('MySQL, Apache24 and PHP installed and configured...')
            elif inst == "n":
                print('You entered "n" button.')
            else:
                print('You can only press "Enter" button or write "n" and after press enter button!!!')
    else:
        print(' This script supports FreeBSD or CentOS7 server...')
Save and  exit
make  the  file executable
chmod  +x lamp.py
Run the File
[root@puppetnode2 ~]# python  lamp.py
Traceback (most recent call last):
  File "lamp.py", line 5, in <module>
    import jinja2
ImportError: No module named jinja2
Oww  issues  with  Python Jinja2  module.!!!
How to to solve  Python Jinja2 missing ?
Install   Jinja2 python module
[root@puppetnode2 ~]# yum   install python-jinja2
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.ams.host-engine.com
 * extras: centos.ams.host-engine.com
 * updates: centos.mirror.triple-it.nl
Resolving Dependencies
--> Running transaction check
---> Package python-jinja2.noarch 0:2.7.2-2.el7 will be installed
--> Processing Dependency: python-babel >= 0.8 for package: python-jinja2-2.7.2-2.el7.noarch
--> Processing Dependency: python-markupsafe for package: python-jinja2-2.7.2-2.el7.noarch
--> Running transaction check
---> Package python-babel.noarch 0:0.9.6-8.el7 will be installed
---> Package python-markupsafe.x86_64 0:0.11-10.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=================================================================================
 Package                   Arch           Version             Repository    Size
=================================================================================
Installing:
 python-jinja2             noarch         2.7.2-2.el7         base         515 k
Installing for dependencies:
 python-babel              noarch         0.9.6-8.el7         base         1.4 M
 python-markupsafe         x86_64         0.11-10.el7         base          25 k
Try again
[root@puppetnode2 ~]# python  lamp.py
Traceback (most recent call last):
  File "lamp.py", line 7, in <module>
    from fabric.api import *
ImportError: No module named fabric.api
[root@puppetnode2 ~]#

Jinja2 solved . we  need  fabric
First   install  epel-release for centos 7
yum install epel-release
Install  Fabric
yum install fabric 
=================================================================================
 Package                 Arch           Version               Repository    Size
=================================================================================
Installing:
 fabric                  noarch         1.6.2-1.el7           epel         133 k
Installing for dependencies:
 libtomcrypt             x86_64         1.17-23.el7           epel         224 k
 libtommath              x86_64         0.42.0-4.el7          epel          35 k
 python-paramiko         noarch         1.15.1-1.el7          epel         999 k
 python2-crypto          x86_64         2.6.1-9.el7           epel         475 k
 python2-ecdsa           noarch         0.13-4.el7            epel          83 k
 Run  and  start deploying from Node2 to  Node1
[root@puppetnode2 freebsd-centos7-amp-master]# ./apmyph.py
Please enter WEB server IP address: 192.168.28.142
Please enter username for UNIX/Linux server: root
Password:
Please enter site name: puppetnode1
 This is CentOS server...
Apache 24 server installed and configured...
If you want install and configure MySQL PHP just press "Enter"!!!
If you want to exit from script write "n" and press Enter button.
Please select:
You are selected "Enter" button
MySQL service already running...
Enter name for new database: UNIXMEN
Enter new mysql user name: test
Enter pass for test:
Repeat pass for test:
MySQL, Apache24 and PHP installed and configured...
Check if  Lamp is running on Node 1
Check  Ports:
[root@puppetnode1 ~]# netstat  -an  | grep    LISTEN | grep   tcp
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp6       0      0 :::80                   :::*                    LISTEN
tcp6       0      0 :::22                   :::*                    LISTEN
tcp6       0      0 :::443                  :::*                    LISTEN
Check   apache :
[root@puppetnode1 ~]# ps -ef | grep htt
root      64778      1  0 06:22 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    64780  64778  0 06:22 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    64781  64778  0 06:22 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    64782  64778  0 06:22 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    64783  64778  0 06:22 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    64784  64778  0 06:22 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
root      64965  12455  0 06:22 pts/1    00:00:00 grep --color=auto htt
[root@puppetnode1 ~]#
Check   database
[root@puppetnode1 ~]# mysql  -u test  -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 5.5.47-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   databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| UNIXMEN            |
+--------------------+
2 rows in set (0.00 sec)
MariaDB [(none)]> use UNIXMEN;
Database changed
MariaDB [UNIXMEN]>
Configure Firewall to Allow Apache  port :
[root@puppetnode1 ~]# sudo firewall-cmd --permanent --add-port=80/tcp
success
[root@puppetnode1 ~]# sudo firewall-cmd --reload
success
Check  in ur  browser if  you see  this  you are  done 
The  browser is  reading  first php file  (httpd.conf)
[root@puppetnode1 puppetnode1_public_html]# cat   index.php
<?php
ini_set('display_errors', 1); //Enable error print to the screen
$dblocation = "localhost"; //IP address for the database
$dbname = "UNIXMEN"; //Database name to which we will connect
$dbuser = "test"; //New username for new database
$dbpasswd = "test"; //Password for the new username
$dbcnx = @mysql_connect($dblocation, $dbuser, $dbpasswd);
if (!$dbcnx){
    echo "<p>So pity MySQL is not working</p>";
    exit();
}
if (!@mysql_select_db($dbname,$dbcnx)){
    echo "<p>We are sorry, to connect to the database was not successfully.</p>";
    exit();
}
$ver = mysql_query("SELECT VERSION()");
if(!$ver){
    echo "<p>Request error</p>";
    exit();
}
echo mysql_result($ver, 0);
?>
Check your  browser  now
2016-05-26_164905
it works!!. i have not tested that on FreeBSD. but i think it will  work smoothly

Thursday, March 31, 2016

Netdata – A Real-Time Performance Monitoring Tool for Linux Systems



netdata is a extremely optimized Linux utility that provides real-time (per second) performance monitoring for Linux systems, applications, SNMP devices, etc. and shows full interactive charts that absolutely render all collected values over the web browser to analyze them.
It has been developed to be installed on each Linux system, without interrupting the current running application on it. You can use this tool to monitor and get overview of what is happening in real-time and what just happened, on your Linux systems and applications.
This is what it monitors:
  1. Total and Per Core CPU usage, interrupts, softirqs and frequency.
  2. Total Memory, RAM, Swap and Kernel usage.
  3. Disk I/O (per disk: bandwidth, operations, backlog, utilization, etc).
  4. Monitors Network interfaces including: bandwidth, packets, errors, drops, etc).
  5. Monitors Netfilter / iptables Linux firewall connections, events, errors, etc.
  6. Processes (running, blocked, forks, active, etc).
  7. System Applications with the process tree (CPU, memory, swap, disk reads/writes, threads, etc).
  8. Apache and Nginx Status monitoring with mod_status.
  9. MySQL database monitoring: queries, updates, locks, issues, threads, etc.
  10. Postfix email server message queue.
  11. Squid proxy server bandwidth and requests monitoring.
  12. Hardware sensors (temperature, voltage, fans, power, humidity, etc).
  13. SNMP devices.

netdata Installation on Linux Systems

1. Before you start installing netdata utility, make sure you have these basic build environment packages installed on the system, if not install it using your respective distribution package manager as shown:

On Debian / Ubuntu

# apt-get install zlib1g-dev gcc make git autoconf autogen automake pkg-config

On Centos / Redhat / Fedora

# yum install zlib-devel gcc make git autoconf autogen automake pkgconfig
2. Next, clone the netdata repository from git and run netdata installer script to build it.
# git clone https://github.com/firehol/netdata.git --depth=1
# cd netdata
# ./netdata-installer.sh
Note: The netdata-installer.sh script will build netdata and install it on your Linux system.
Once the netdata installer finishes, the file /etc/netdata/netdata.conf will be created in your system.
3. Now it’s time to start netdata by executing the following command from the terminal.
# /usr/sbin/netdata
You can also stop netdata by terminating it’s process with killall command as shown.
# killall netdata
Note: Netdata saves on exit its round robbin database information under /var/cache/netdata file, so that when you start again netdata, it will continue from where it was stopped last time.

Starting and Testing netdata

4. Now open your browser and navigate to the following address to access the web site for all graphs:
# http://127.0.0.1:19999/
Check out the video that shows how Real-time Linux performance monitoring done here:https://www.youtube.com/watch?v=QIZXS8A4BvI
netdata - Linux Real Time Performance Monitoring
netdata – Linux Real Time Performance Monitoring
5. You can also view the running configuration of netdata at any time, by going to:
http://127.0.0.1:19999/netdata.conf
netdata Configuration
netdata Configuration

Updating netdata

6. You can update netdata daemon to the most recent version by going into netdata.git directory you downloaded before and running:
# cd /path/to/netdata.git
# git pull
# ./netdata-installer.sh
The above netdata installer script will build new version and restart netdata.