Tuesday, December 23, 2014

Script - NMAP

Script - NMAP

=========================================================
#!/bin/bash
# This script is going to scan network 192.168.1.0/24 with name and
# append to file name host-up-with-ports.txt
nmap --top-ports 65535 192.168.1.0/24 &> host-up-with-ports.txt
=========================================================
#!/bin/bash
# This script is going to scan network 192.168.1.0/24 with name and
# append to file name hosts-up-with-name.txt
nmap -sP 192.168.1.0/24 |grep "Nmap scan report" >> hosts-up-with-name.txt
=========================================================
#!/bin/bash
# This script is going to ping all hosts in network 192.168.1.0/24
# and it will append all the hosts up to to file hosts-up.txt
check_ping()
{
  ping -c 1 $1 > /dev/null
  [ $? -eq 0 ] && echo Node with IP: $i is up.
}
for i in 192.168.1.{1..255}
do
check_ping $i |grep "Node with IP" >> hosts-up.txt
done
=========================================================
#!/bin/bash
# This is a master script going to run and call another script with the following optoins
clear
# Variables
user=$(whoami)
break="====================="
echo $break
echo "Hello H4cK3R%!"
echo $break
echo
echo "Welcome, Mr. $user"
echo
echo
echo "1. Check Hosts Up"
echo "2. Scan Hosts Up"
echo "3. Scan Hosts Ports"
echo ""
echo -n "Choice: "
read choice
echo $choice
case $choice in
        1) ./check_ping.sh;;
        2) ./scan-host-with-name.sh;;
        3) ./scan_ports.sh;;
        *) echo "Please Enter the valid option."
esac



Saturday, December 20, 2014

SNMPWALK


snmpwalk

snmpwalk : retrieve a subtree of management values using SNMP GETNEXT requests.

snmpwalk [APPLICATION OPTIONS] [COMMON OPTIONS] [OID]

snmpwalk -v 2c -c C0mmunity 1.2.3.4 .1.3.6.1.4.1.8886.18.2.6.3.3.1.6.10234001

C0mmunity = Community Name
1.2.3.4 = IP address of device
.1.3.6.1.4.1.8886.18.2.6.3.3.1.6.10234001 = OID

example another command:

snmpwalk -mALL -v1 -c C0mmunity 1.2.3.4 system


#SNMP #SNMWALK

Saturday, September 13, 2014

Simple Nagios

Nagios is one of the power full monitoring system.

This script work well on OS: CentOS 64bit , Version 6.2 
Copy all the red.


#!/bin/bash

# Copy this and paste into a file name: install-nagios.sh
# Make it executable by: chmod +x install-nagios.sh
# Run this file: ./install-nagios.sh

####################
# HowTheScriptDoes #
####################
# 1. Add Repo
echo ""
echo "Adding repo..."
echo ""
wget http://epel.mirror.net.in/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm

# 2. Install dependencies
echo ""
echo "Install dependencies ..."
echo ""
yum -y install httpd php gcc glibc glibc-common gd gd-devel make net-snmp

# 3. Install Nagios
echo ""
echo "Instailling Nagios ..."
echo ""
yum -y install nagios*

# 4. Create user: nagiosadmin
echo ""
echo "Creating user: nagiosadmin ,Please Enter the Password: ..."
htpasswd /etc/nagios/passwd nagiosadmin

# 5. Start web service and Nagios
echo ""
echo "Starting web service and Nagios ..."
service httpd start
chkconfig nagios on
service nagios start
chkconfig httpd on

# 6. Allow port 80
echo ""
echo "Accepting Port 80 ..."
sed -i -e '/22/a \-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT' /etc/sysconfig/iptables
echo "Restarting service iptables ..."
service iptables restart

# 7. Finished,
echo ""
echo ""
echo "Enjoy, ... Access to your Nagios Server by: http://server-ip/nagios with your password."


Wednesday, September 3, 2014

Copy File and Folder Older then 7days

Copy File and Folder Older then 7days


find /in/this/directory/ -mtime -7 -exec cp -p {} /to/new/path/ \;

Note:

-7 = Last 7 days
cp -p = Copy and keep the owner,permission and timestamp

Rename Multiple File In One Command

Rename Multiple File In One Command


for FILE in *.txt ; do mv $FILE $FILE-04092014 ; done

Tuesday, August 19, 2014

Keys

VMware Workstation V.10 Key

HA4FW-8G052-DZ8Q0-U295P-83KLV
5F4PK-42181-9ZXP9-T31Q6-1CVKM
JY468-44L9M-DZ479-3UA72-CAKHR

4F6Z5-80H42-FZ889-L007M-ACJJN
5F6E9-DHL4J-HZ640-KLA70-8C0NN
1Z0G9-67285-FZG78-ZL3Q2-234JG
4C4EK-89KDL-5ZFP9-1LA5P-2A0J0
HY086-4T01N-CZ3U0-CV0QM-13DNU

5U4GA-DQ09H-EZK48-YTAQP-83K79
NU4FQ-DFH40-0ZA01-8A37K-32RKL
HF0DA-FF086-VZ739-AA87H-236M4
HF0A8-FMJ1P-1Z1U1-LK1N2-9AGKJ
5A477-D3284-3ZUF0-2K154-23R0P
MY47Y-2MK1M-6ZQC0-7J05M-8A60D
5V6K2-29243-HZDV0-VVA76-93A2R
NA28T-DR114-AZ9Z8-R1250-93U27
MF4JG-4H3DK-NZ3L0-KHCNM-8AMNP
NA6F3-2HKEM-6ZDF8-Q18N6-33DNN
1Y2FZ-AHJ5H-6ZU09-DKA5M-82RQ7
5U6KQ-6M240-LZMW1-U13N2-AAX7X
HA4FW-8G052-DZ8Q0-U295P-83KLV
5F4PK-42181-9ZXP9-T31Q6-1CVKM
JY468-44L9M-DZ479-3UA72-CAKHR
4F6Z5-80H42-FZ889-L007M-ACJJN
5F6E9-DHL4J-HZ640-KLA70-8C0NN

Wednesday, July 16, 2014

Life Lesson

Life Lesson

1. Life isn’t fair, but it’s still good.
2. When in doubt, just take the next small step.
3. Life is too short – enjoy it.
4. Your job won’t take care of you when you are sick. Your friends and family will.
5. Pay off your credit cards every month.
6. You don’t have to win every argument. Stay true to yourself.
7. Cry with someone. It’s more healing than crying alone.
8. It’s OK to get angry with God. He can take it.
9. Save for retirement starting with your first paycheck.
10. When it comes to chocolate, resistance is futile.
11. Make peace with your past so it won’t screw up the present.
12. It’s OK to let your children see you cry.
13. Don’t compare your life to others. You have no idea what their journey is all about.
14. If a relationship has to be a secret, you shouldn’t be in it.
15. Everything can change in the blink of an eye But don’t worry; God never blinks.
16. Take a deep breath. It calms the mind.
17. Get rid of anything that isn’t useful. Clutter weighs you down in many ways.
18. Whatever doesn’t kill you really does make you stronger.
19. It’s never too late to be happy. But it’s all up to you and no one else.
20. When it comes to going after what you love in life, don’t take no for an answer.
21. Burn the candles, use the nice sheets, wear the fancy lingerie. Don’t save it for a special occasion. Today is special.
22. Over prepare, then go with the flow.
23. Be eccentric now. Don’t wait for old age to wear purple.
24. The most important sex organ is the brain.
25. No one is in charge of your happiness but you.
26. Frame every so-called disaster with these words ‘In five years, will this matter?’
27. Always choose life.
28. Forgive
29. What other people think of you is none of your business.
30. Time heals almost everything. Give time time.
31. However good or bad a situation is, it will change.
32. Don’t take yourself so seriously. No one else does.
33. Believe in miracles.
34. God loves you because of who God is, not because of anything you did or didn’t do.
35. Don’t audit life. Show up and make the most of it now.
36. Growing old beats the alternative — dying young.
37. Your children get only one childhood.
38. All that truly matters in the end is that you loved.
39. Get outside every day. Miracles are waiting everywhere.
40. If we all threw our problems in a pile and saw everyone else’s, we’d grab ours back.
41. Envy is a waste of time. Accept what you already have not what you need.
42. The best is yet to come…
43. No matter how you feel, get up, dress up and show up.
44. Yield.
45. Life isn’t tied with a bow, but it’s still a gift.”


From: http://socialmeems.com/2014/07/14/45-lessons-life-taught

DRINK WATER ON EMPTY STOMACH

DRINK WATER ON EMPTY STOMACH

It is popular in Japan today to drink water immediately after waking up every morning. Furthermore, scientific tests have proven its value. We publish below a description of use of water for our readers. For old and serious diseases as well as modern illnesses the water treatment had been found successful by a Japanese medical society as a 100% cure for the following diseases:
Headache, body ache, heart system, arthritis, fast heart beat, epilepsy, excess fatness, bronchitis asthma, TB, meningitis, kidney and urine diseases, vomiting, gastritis, diarrhea, piles, diabetes, constipation, all eye diseases, womb, cancer and menstrual disorders, ear nose and throat diseases.
METHOD OF TREATMENT
1. As you wake up in the morning before brushing teeth, drink 4 x 160ml glasses of water
2. Brush and clean the mouth but do not eat or drink anything for 45 minute
3.. After 45 minutes you may eat and drink as normal.
4. After 15 minutes of breakfast, lunch and dinner do not eat or drink anything for 2 hours
5. Those who are old or sick and are unable to drink 4 glasses of water at the beginning may commence by taking little water and gradually increase it to 4 glasses per day.
6. The above method of treatment will cure diseases of the sick and others can enjoy a healthy life.
The following list gives the number of days of treatment required to cure/control/reduce main diseases:
1. High Blood Pressure (30 days)
2. Gastric (10 days)
3. Diabetes (30 days)
4. Constipation (10 days)
5. Cancer (180 days)
6. TB (90 days)
7. Arthritis patients should follow the above treatment only for 3 days in the 1st week, and from 2nd week onwards – daily..
This treatment method has no side effects, however at the commencement of treatment you may have to urinate a few times.
It is better if we continue this and make this procedure as a routine work in our life. Drink Water and Stay healthy and Active.
This makes sense .. The Chinese and Japanese drink hot tea with their meals not cold water. Maybe it is time we adopt their drinking habit while eating!!! Nothing to lose, everything to gain...
For those who like to drink cold water, this article is applicable to you.
It is nice to have a cup of cold drink after a meal. However, the cold water will solidify the oily stuff that you have just consumed. It will slow down the digestion.
For more Health,Love,Life Tips, Inspirational,Love,Heart Touching Viral Stories
Please Visit www.SocialMeems.com
Once this 'sludge' reacts with the acid, it will break down and be absorbed by the intestine faster than the solid food. It will line the intestine.
Very soon, this will turn into fats and lead to cancer. It is best to drink hot soup or warm water after a meal.
A serious note about heart attacks:
• Women should know that not every heart attack symptom is going to be the left arm hurting,
• Be aware of intense pain in the jaw line.
• You may never have the first chest pain during the course of a heart attack.
• Nausea and intense sweating are also common symptoms.
• 60% of people who have a heart attack while they are asleep do not wake up.
• Pain in the jaw can wake you from a sound sleep. Let's be careful and be aware. The more we know, the better chance we could survive...
A cardiologist says if everyone who gets this mail sends it to everyone they know, you can be sure that we'll save at least one life.
Please be a true friend and send this article to all your friends you care about.
PLEASE DON'T IGNORE SHARE IT. THIS MIGHT SAVE SOMEONE'S LIFE.
For more Health,Love,Life Tips, Inspirational,Love,Heart Touching Viral Stories
Please Visit www.SocialMeems.com

Monday, June 30, 2014

Script Clean Up Data

Script Clean Up Data

#!/bin/bash

# Variables
DATE=`date +%Y-%m-%d`
YEAR=`date +%Y`
THISMONTH=`date +%m`
LASTMONTH=`date +'%m' -d 'last month'`
DAYTH=`date +%d`
ERROR=/opt/scripts/error.log
ERROR1=/opt/scripts/error1.log
LOG=/opt/scripts/log.log
error=0

# Clean up Netflow Data last month older then 7 days
DATA_LASTMONTH=/data/nfsen/profiles-data/live/r4/$YEAR/$LASTMONTH/
find $NETFLOW_DATA_LASTMONTH -type d -mtime +7 -exec rm -rf {} 2>> $ERROR \;

# Clean up Netflow Data this month older then 7 days
DATA_THISMONTH=/data/nfsen/profiles-data/live/r4/$YEAR/$THISMONTH/
find $NETFLOW_DATA_THISMONTH -type d -mtime +7 -exec rm -rf {} 2>> $ERROR \;

# Clean up other file-*
find /data/all -name "file.*" -mtime +7 -exec rm -f {} 2>> $ERROR \;
find /data/dns -name "file.*" -mtime +7 -exec rm -f {} 2>> $ERROR \;
find /hoststats/data/ssh -name "file.*" -mtime +7 -exec rm -f {} 2>> $ERROR \;
find /data/telnet -name "file.*" -mtime +7 -exec rm -f {} 2>> $ERROR \;

#Check Error
/bin/cat $ERROR >> $ERROR1
        if test -s $ERROR;
  then
                error=1
        fi
sleep 2
if [ "$error" = 1 ];
then
        # Create email
        echo "From: Netflow " >> /var/tmp/mail.txt
        echo "Subject: Clean Up Netflow Files" >> /var/tmp/mail.txt
        echo " " >> /var/tmp/mail.txt
        echo "CHECK ERROR IN 12.13.14.15 in /opt/scripts/log.log"  >> /var/tmp/mail.txt
        echo "###################################################" >> /var/tmp/mail.txt
        echo "Kind of error: "  >> /var/tmp/mail.txt
        echo "---------------------------------------------------" >> /var/tmp/mail.txt
        `/bin/cat $ERROR1 >> /var/tmp/mail.txt`
        echo "###################################################" >> /var/tmp/mail.txt


        echo "CHECK THE SERVER IP 12.13.14.15" >> /var/tmp/mail.txt

        mail -s "ERROR Cleanup Netflow Data"  ken.vannakk@gmail.com < /var/tmp/mail.txt
        echo "ERROR!!!!" >> $LOG
        /bin/cat $ERROR >> $LOG
        #Delete Log
        rm /var/tmp/mail.txt
        rm $ERROR
        rm $ERROR1
fi
echo "FINISH Cleanup Netflow Data:" $DATE >> $LOG

Script Check Disk Spaces

Script Check Disk Spaces

#!/bin/bash

# This script is going to check /data if less then 200GB it going to send mail
DATA=`df | awk '/\/data/ {print $4}'`
if test $DATA -le 200000000
then
     df | mail -s "/data on Netfolw server is nearly full" ken.vannakk@gmail.com
fi

Tuesday, June 24, 2014

Scripts Check 2 directories

#!/bin/bash
# This script is going to verify make sure all users are backup.

# Home user : /home/[0-9] and /home/[a-z]
# Home backup user: /homebackup/[0-9] and /homebackup/[a-z]

for users in {0..9} {a..z}; do
diff /home/$users/ /homebackup/$users/ | grep /home/$users/ | awk '{print $4}' >> /opt/scripts/differences.txt
done
sed -i -e "/and/d" /opt/scripts/differences.txt

# Check file content
FILE=/opt/scripts/differences.txt
        if [[ -s $FILE ]] ; then
                echo "Has some difference."
                echo "Email Users not backup are:" >> /opt/scripts/mail.tmp
                echo "" >> /opt/scripts/mail.tmp
                        cat /opt/scripts/differences.txt >> /opt/scripts/mail.tmp
                echo "" >> /opt/scripts/mail.tmp
                echo "Please check MX01." >> /opt/scripts/mail.tmp
        mail -s "Mail User Not Backup" ken.vannakk@gmail.com < /opt/scripts/mail.tmp
        # Remove file
        rm /opt/scripts/differences.txt
        rm /opt/scripts/mail.tmp
        else
                echo "No difference."
        # Remove file
        rm /opt/scripts/differences.txt
        fi
# End
==================================================
#!/bin/bash

# This script is going to verify make sure all users are backup.
HOMEUSER=/home/vmail
BACKUPUSER=/homebackup/vmail

# Check the the difference between HOMEUSER and BACKUPUSER
diff $HOMEUSER $BACKUPUSER | grep $HOMEUSER | awk '{print $4}' > /opt/scripts/differences.txt
sed -i -e "/and/d" /opt/scripts/differences.txt

# Check file content
FILE=/opt/scripts/differences.txt
        if [[ -s $FILE ]] ; then
                echo "Has some difference."
                echo "Email Users not backup are:" >> /opt/scripts/vmail.tmp
                echo "" >> /opt/scripts/vmail.tmp
                        cat /opt/scripts/differences.txt >> /opt/scripts/vmail.tmp
                echo "" >> /opt/scripts/vmail.tmp
                echo "Please check MX01." >> /opt/scripts/vmail.tmp
        mail -s "Mail User Not Backup" ken.vannakk@gmail.com < /opt/scripts/vmail.tmp
        # Remove file
        rm /opt/scripts/differences.txt
        rm /opt/scripts/vmail.tmp
        else
                echo "No difference."
        # Remove file
        rm /opt/scripts/differences.txt
        fi
# End

Wednesday, May 7, 2014

Ansible

Ansible


              Ansible is the simplest way to deploy your applications. Ansible gives you the power to deploy multi-tier applications reliably and consistently, all from one common framework. You can configure needed services as well as push application artifacts from one common system.

Rather than writing custom code to automate your systems, your team writes simple task descriptions that even the newest team member can understand on first read -- saving not only up-front costs, but making it easier to react to change over time.

Introduciton

LEARN HOW ANSIBLE WORKS.

Thursday, February 20, 2014

Reset Password MySQL User

Reset Password MySQL User


Sometime we also forgot or miss mysql user password. and here are the way to reset password mysql user. But we need to have mysql root `s password.

If you are also forgot or miss mysql root`s password. 
Here is my previous article:  Recovery MySQL Root Password

HowTo -  Reset password mysql user.

1. Log in as root 
(In this example database server is "localhost", If  mysql server on different server we need to specify with -h option for database host.)
mysql -u root -p
2. Use mysql database and update new password for user "vannak"
use mysql;
UPDATE mysql.user SET Password=PASSWORD('NewPassw0rd') WHERE User='vannak' AND Host='localhost';
FLUSH PRIVILEGES;

Enjoy,
Below screen shoot is the full process HowTo:


Sunday, February 16, 2014

Configure Ethernet Channel Bonding

Configure Ethernet Channel Bonding


1. Why Ethernet channel Bonding?
2. How to

1. Why Ethernet channel Bonding?
Ethernet channel Bonding enable 2 or more Network Interfaces Card (NIC) to single virtual NIC card.
This is a great way to  achive redundant links, fault tolerance or load balancing.

2. HowTo
OS: Ubuntu 13.04

2.1 Installation
apt-get install ifenslave
2.2 Configuration
2.2.1 Check kernel support
vi /etc/modules
loop
lp
rtc
bonding

2.2.2 Enable module
modprobe bonding
2.2.3 Edit interface configuration
vi /etc/network/interfaces
-----------------------------------
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# eth0 - the first network interface
auto eth0
iface eth0 inet manual
hwaddress ether 00:0c:29:b0:00:80
bond-master bond0
# eth1 - the second network interface
auto eth1
iface eth1 inet manual
hwaddress ether 00:0c:29:b0:00:8a
bond-master bond0

# Network bond for eth0 and eth1
auto bond0
iface bond0 inet static
address 192.168.5.200
netmask 255.255.255.0
gateway 192.168.5.2
bond-mode 1
bond-miimon 100
slaves eth0 eth1
-----------------------------------
Show IP:



2.2.4 Checking bonding interface
cat /proc/net/bonding/bond0

Try to disable one of the NIC, IP: 192.168.5.200 still available,

Enjoy,


Wednesday, January 15, 2014

Install Multiple MySQL Versions On a Single Server

Install Multiple MySQL Versions On a Single Server



We usually need to use different version of a software in a single server in some case for testing, And some are because of requirements of some apps...,

In this example is going to install multiple MySQL version on a single server.

OS: Ubuntu Server 12.04
Default MySQL versoion: 5.5.34
Compiled MySQL version: 5.1.65
Note:
- mysql-server IP: 192.168.5.5
- remote-client IP: 192.168.5.1

1. Install MySQL from APT-GET
2. Install MySQL from Compile
    2.1. Required Softwares
    2.2 Compile MySQL
          2.2.1 Download
          2.2.2 Extract
          2.2.3 Compile

1. Install MySQL from APT-GET
#apt-get install mysql-server
During the installation will be ask you to enter root's password.


Log in into MySQL server by command:
# mysql -u root -p


Create a test database after login by command:
#mysql> create database dbtest1;


2. Install MySQL from Compile

2.1. Required Softwares
Install compiler tools

#apt-get install build-essential libncurses-dev libstdc++6 libc6 libltdl-dev autoconf

2.2 Compile MySQL 
Create folder structure,
In this example we are going to install another MySQL version 5.1.65 in /opt/mysql-versions/
# mkdir -p /opt/mysql-versions/mysql5165/datafiles
# mkdir -p /opt/mysql-versions/mysql5165/logs
# mkdir -p /opt/mysql-versions/mysql5165/pid
# mkdir -p /opt/mysql-versions/mysql5165/socket
2.2.1 Download 
wget http://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.65.tar.gz

2.2.2 Extract
tar -xvf mysql-5.1.65.tar.gz
2.2.3 Compile
Go to folder mysql-5.1.65:
# cd mysql-5.1.65
-------------------------------------------------------------------------------------------------------------------------
./configure --prefix=/opt/mysql-versions/mysql5165/ --enable-assembler --with-mysqld-ldflags=-all-static --with-tcp-port=3307 --with-unix-socket-path=/opt/mysql-versions/mysql5165/socket/mysql5165.sock
-------------------------------------------------------------------------------------------------------------------------

Run command: make and make install
# make
# make install

After run command "make install"
create a file name "mysql5165.cnf" with content:
-------------------------------------------------------------------------------------------------------------------------
# Example MySQL config file for medium systems.
#
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients
[client]
#password = R00tPa$$w0rd
port = 3307
socket = /opt/mysql-versions/mysql5165/socket/mysql-5165.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port = 3307
socket = /opt/mysql-versions/mysql5165/socket/mysql-5165.sock
pid-file = /opt/mysql-versions/mysql5165/pid/mysql-5165.pid
datadir = /opt/mysql-versions/mysql5165/datafiles
log = /opt/mysql-versions/mysql5165/logs/mysqld5165.log
log-error = /opt/mysql-versions/mysql5165/logs/mysqld5165.err
basedir = /opt/mysql-versions/mysql5165
skip-locking
skip-name-resolve
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M

# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking

# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin

# binary logging format - mixed recommended
binlog_format=mixed

# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id = 1

# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
#    the syntax is:
#
#    CHANGE MASTER TO MASTER_HOST=, MASTER_PORT=,
#    MASTER_USER=, MASTER_PASSWORD= ;
#
#    where you replace , , by quoted strings and
#     by the master's port number (3306 by default).
#
#    Example:
#
#    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
#    MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
#    start replication for the first time (even unsuccessfully, for example
#    if you mistyped the password in master-password and the slave fails to
#    connect), the slave will create a master.info file, and any later
#    change in this file to the variables' values below will be ignored and
#    overridden by the content of the master.info file, unless you shutdown
#    the slave server, delete master.info and restart the slaver server.
#    For that reason, you may want to leave the lines below untouched
#    (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id       = 2
#
# The replication master for this slave - required
#master-host     =  
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user     =  
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password =  
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port     =  
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin

# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /opt/mysql-versions/mysql5165/var
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /opt/mysql-versions/mysql5165/var
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout
--------------------------------------------------------------------------------------------------------------------------
Go to folder folder "bin" in the mysql compiled:
cd /opt/mysql-versions/mysql5165/bin
and issue command:
./mysql_install_db --defaults-file=/opt/mysql-versions/mysql5165/mysql5165.cnf --user=mysql

Change ownership the mysql compiled folder to user "mysql"
chown -R mysql:mysql /opt/mysql-versions/mysql5165

Test to start in safe mode
# /opt/mysql-versions/mysql5165/bin/mysqld_safe --defaults-file=/opt/mysql-versions/mysql5165/mysql5165.cnf --user=mysql &

# Note: If we want to auto start up add in : /etc/rc.local

Start the server
# /opt/mysql-versions/mysql5165/share/mysql/mysql.server start

Change root password
# /opt/mysql-versions/mysql5165/bin/mysqladmin -u root -P 3307 -S /opt/mysql-versions/mysql5165/socket/mysql-5165.sock password "R00tPa$$w0rd"

Log in with new password
# /opt/mysql-versions/mysql5165/bin/mysql -u root -P 3307 -S /opt/mysql-versions/mysql5165/socket/mysql-5165.sock -p

Allow other machine to remote to
Add a line "skip-name-resolve" in /opt/mysql-versions/mysql5165/mysql5165.cnf
# and on mysql server log into mysql: mysql> grant all privileges on *.* to 'root'@'192.168.5.1' identified by 'R00tPa$$w0rd' with grant option;

Login and create database:
mysql -u root -h 192.168.5.5 -p -P3307


Thursday, January 9, 2014

Script Change PHP Versions

Script Change PHP Versions


I am lazy to edit the vhost file to change the PHP version that I usually change,
So I create this script to help me complete this task. :D

This is the script to change PHP version which is base on where you keep the path of your PHP.
Download this script file and put somewhere on you computer.

*** Adjust this script base on your custom configurations.

How to run the script:
sudo ./change-php-version.sh
You will get the options to choose:

Please select the options, Enter the number only.
1. For list virtualhost
2. For list PHP version
3. For Change PHP version
4. For Exit

Note: If you choose option number 3 you need to provide other informations in order to change PHP version such as:
* virtualhost-name
* PHP version

As the following example:

Please Enter virtualhost file:
(example: local.demo)
local.demo

Please Enter PHP version number only:
(example: 5.3.8)
 5.4.9
If the virtualhost file exist and with PHP version is correct, Script will run without error.

Changing PHP Version to 5.4.9
 * Reloading web server config                                                              [ OK ]
Virtualhost local.demo changed to PHP version 5.4.9

Done, In this example, The script will change vhost file local.demo to PHP version 5.4.9.

==================== Here is the Script Content ================
#!/bin/bash
# Version 1.0
# Require user "root" to run this script.
if [ "$(whoami)" != 'root' ]; then
        echo "You have no permission to run $0 as non-root user."
        echo "Log in as user '"root"' or Use '"sudo"' !!!"
        exit 1;
fi
# Available options
echo ""
echo "Please select the options, Enter the number only."
echo ""
echo "1. For list virtualhost"
echo "2. For list PHP version"
echo "3. For Change PHP version"
echo "4. For Exit"
echo ""
read USERINPUT

USAGE="Pleaes enter the valid option"

if [ $USERINPUT = "1" ]
then
  CONFIG_OPTION="1"
fi

if [ $USERINPUT = "2" ]
then
  CONFIG_OPTION="2"
fi

if [ $USERINPUT = "3" ]
then
  CONFIG_OPTION="3"
fi

if [ $USERINPUT = "4" ]
then
  CONFIG_OPTION="4"
fi

if [ "$CONFIG_OPTION" = "" ]
then
  echo "$USAGE"
echo ""
  exit 1
fi

if [ "$USERINPUT" = "1" ]
then
echo "Available virtualhost files..."
echo ""
        if [ "$USERINPUT" = "1" ];
sudo ls /etc/apache2/sites-enabled/ >> /opt/php-versions/vhost.tmp ; cat /opt/php-versions/vhost.tmp ; rm /opt/php-versions/vhost.tmp
        then
echo ""
        else
           echo "$USAGE"
echo ""
        exit 1
fi
fi

if [ "$USERINPUT" = "2" ]
then
echo "Available PHP versions..."
echo ""
        if [ "$USERINPUT" = "1" ];
sudo ls /opt/php-versions/ |grep php5 >> /opt/php-versions/php-version.tmp ; cat /opt/php-versions/php-version.tmp ; rm /opt/php-versions/php-version.tmp
        then
echo ""
        else
           echo "$USAGE"
echo ""
        exit 1
        fi
fi

if [ "$USERINPUT" = "4" ]; then
        echo "Exit the programm"
        exit 1;
fi

################################################################
if [ "$USERINPUT" = "3" ]
then
echo ""
echo "Please Enter virtualhost file:"
echo ""
echo "(example: local.demo)"
echo ""
read VHOST
echo ""
echo "Checking if file virtualhost exist or not.."
echo ""

        if [ -f /etc/apache2/sites-available/$VHOST ];
        then
           echo "File virtualhost $VHOST exist..."
        else
           echo "File virtualhost $VHOST does not exists..."
        exit 1
fi
echo ""
echo "Please Enter PHP version number only:"
echo ""
echo "(example: 5.3.8) "
echo ""
read PHPVERSION
echo ""

if [ $PHPVERSION = "5.3.8" ]
then
  PHPPATH="/opt/php-versions/php538/"
fi

if [ $PHPVERSION = "5.4.9" ]
then
  PHPPATH="/opt/php-versions/php549/"
fi

if [ $PHPVERSION = "5.4.13" ]
then
  PHPPATH="/opt/php-versions/php5413/"
fi

if [ $PHPVERSION = "5.5.0" ]
then
  PHPPATH="/opt/php-versions/php550/"
 fi

if [ "$PHPPATH" = "" ]
then
  echo "This PHP Version does not exist. or not included. "
  exit 1
fi

#########################
# If $PHPVERSION = 5.3.8#
#########################
if [ $PHPVERSION = "5.3.8" ]
then
echo "Changing PHP Version to "$PHPVERSION""
# Remove "#" before Alias if more then 4 keep only 1.
sudo sed -i -e 's/#####Alias/#Alias/g' /etc/apache2/sites-available/$VHOST
# Comment all the line that exist the word "php5-default".
sudo sed -i -e 's/\/#Alias/' /etc/apache2/sites-available/$VHOST
# Uncomment the line which contain the PHP version that we want to enable
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php538\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php538\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php538\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php538\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php538\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php538\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php538\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php538\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php538\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php538\//g' /etc/apache2/sites-available/$VHOST
#service apache2 restart
sudo service apache2 reload
fi
#########################
# If $PHPVERSION = 5.4.9#
#########################
if [ $PHPVERSION = "5.4.9" ]
then
echo "Changing PHP Version to "$PHPVERSION""
# Remove "#" before Alias if more then 4 keep only 1.
sudo sed -i -e 's/#####Alias/#Alias/g' /etc/apache2/sites-available/$VHOST
# Comment all the line that exist the word "php5-default".
sudo sed -i -e 's/\/#Alias/' /etc/apache2/sites-available/$VHOST
# Uncomment the line which contain the PHP version that we want to enable
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default\//g' /etc/apache2/sites-available/$VHOST
#service apache2 restart
sudo service apache2 reload
fi
##########################
# If $PHPVERSION = 5.4.13#
##########################
if [ $PHPVERSION = "5.4.13" ]
then
echo "Changing PHP Version to "$PHPVERSION""
# Remove "#" before Alias if more then 4 keep only 1.
sudo sed -i -e 's/#####Alias/#Alias/g' /etc/apache2/sites-available/$VHOST
# Comment all the line that exist the word "php5-default".
sudo sed -i -e 's/\/#Alias/' /etc/apache2/sites-available/$VHOST
# Uncomment the line which contain the PHP version that we want to enable
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php5413\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php5413\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php5413\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php5413\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php5413\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php5413\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php5413\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php5413\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php5413\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php5413\//g' /etc/apache2/sites-available/$VHOST
#service apache2 restart
sudo service apache2 reload
fi
#########################
# If $PHPVERSION = 5.5.0#
#########################
if [ $PHPVERSION = "5.5.0" ]
then
echo "Changing PHP Version to "$PHPVERSION""
# Remove "#" before Alias if more then 4 keep only 1.
sudo sed -i -e 's/#####Alias/#Alias/g' /etc/apache2/sites-available/$VHOST
# Comment all the line that exist the word "php5-default".
sudo sed -i -e 's/\/#Alias/' /etc/apache2/sites-available/$VHOST
# Uncomment the line which contain the PHP version that we want to enable
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php550\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php550\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php550\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php550\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php550\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php550\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php550\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php550\//g' /etc/apache2/sites-available/$VHOST
sudo sed -i -e 's/#Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php550\//Alias \/fcgi-bin\/ \/var\/www\/cgi-bin\/php5-default_php550\//g' /etc/apache2/sites-available/$VHOST
#service apache2 restart
sudo service apache2 reload
fi

echo ""
echo "Virtualhost $VHOST changed to PHP version $PHPVERSION"
        else
echo ""
        exit 1
fi

####################### End Of Script #######################

Monday, January 6, 2014

Zabbix Installation on CentOS 6.X

Zabbix Installation on CentOS 6.X

1. what is Zabbix?
2. Installations
3. Usage

Here we go:

1. what is Zabbix?
Zabbix is an open source monitoring solution that can be used to monitor and track performance and availability of network servers, devices and other IT resources.
2. Requirements Installations

2.1 LAMP 
LAMP (Linux, Apache HTTP Server, MySQL database, and PHP/Perl/Python)
2.1.1 Install Apache
# yum install httpd
Start Apache and add to auto startup when every boot.
# service httpd start 
# chkconfig httpd on
Allow Port 80 through our firewall
vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

# service iptables restart
2.1.2 Install MySQL
# yum install mysql mysql-server
Start MySQL and add to auto startup when every boot.
# service mysqld start 
# chkconfig mysqld on
Set MySQL root's password by:
# mysql_secure_installation

2.1.3 Install PHP
# yum install php
# yum install php-mysql

2.2 EPEL
Before we can install Zabbix or other packages we need to install EPEL (Extra Packages for Enterprise Linux) first:
For CentOS 6.x
# wget http://epel.mirror.net.in/epel/6/i386/epel-release-6-8.noarch.rpm 
# rpm -Uvh epel-release-6-8.noarch.rpm

we can show our repository installed by:
# yum repolist

Update Repository
#yum update
Install Zabbix services
#yum install zabbix-server-mysql zabbix-agent zabbix-web-mysql

Log in into MySQL and create database and user for Zabbix
[root@zabbix ~]# mysql -u root -p
Enter password: 
mysql> create database zabbix;
mysql> GRANT ALL PRIVILEGES ON zabbix.* TO zabbix@localhost IDENTIFIED BY 'zabbixpassword';
mysql> flush privileges;
mysql> exit

Import zabbix templates to Zabbix database

# mysql -uzabbix -p zabbix < /usr/share/doc/zabbix-server-mysql-1.8.18/create/schema/mysql.sql
# mysql -uzabbix -p zabbix < /usr/share/doc/zabbix-server-mysql-1.8.18/create/data/data.sql
# mysql -uzabbix -p zabbix < /usr/share/doc/zabbix-server-mysql-1.8.18/create/data/images_mysql.sql

Configure Zabbix server
# vi /etc/zabbix/zabbix_server.conf

[...]
DBName=zabbix
[...]
DBUser=zabbix
[...]
DBPassword=zabbixpassword
[...]

Edit file /etc/zabbix/zabbix_agentd.conf
# vi /etc/zabbix/zabbix_agentd.conf
[...]
Hostname= zabbix.vannakk.net
[...]

Edit Zabbix reqirements:
vi /etc/httpd/conf.d/zabbix.conf

php_value max_execution_time 900
php_value max_input_time 600
php_value memory_limit 256M
php_value upload_max_filesize 32M
php_value post_max_size 32M

Edit PHP.ini
# vi /etc/php.ini
date.timezone = Asia/Phnom_Penh

Adjust Firewall settings
Adjust iptables to allow the zabbix ports 10050 and 10051.
# vi /etc/sysconfig/iptables
[...]
-A INPUT -m state --state NEW -m tcp -p tcp --dport 10050 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 10051 -j ACCEPT
[...]
# service iptables restart

Restart zabbix and httpd services and make them to start automatically on every reboot

# service zabbix-server start
# service zabbix-agent start
# service httpd restart
# service mysqld restart
# chkconfig zabbix-server on 
# chkconfig zabbix-agent on

Access Zabbix Web console
http://ip-address/zabbix or http://domain-name/zabbix

Follow the screen shoot and complete all the steps:










The default username/password is admin/zabbix



3. Usage
(Not yet added)