Month: December 2007

Denial of Service (DoS)

Denial of Service (DoS)

Introduction –

Denial of Service (DoS) attack is an attack in which one user takes up so much or maximum resources that none of the resources is left for other users. Denial of services (DOS) attack compromise the availability of resources. Those resources can be processes, disk space, % of CPU, Printer paper, modems or time of a harried system administration. UNIX can limit users to allow maximum number of files and processes.

There are two types of DoS-

  • Attack attempts to damage or destroy resources
  • Attack which overloads some system services or exhausts some recourses


Network Denial of services attacks –

Network DoS prevents legitimate users from using network. There three comon network DoS.

  • Service Overloading
  • Message flooding
  • Single Grounding

1) Service Overloading –
Occurs when floods of network request are made to a server daemon on a single computer. So that the machine is busy servicing interrupt requests and network packets that is unable to process regular tasks in a timely fashion.

2) Message flooding –

Program that answers network request in the server’s place for eq. client/user program which issue his own replies for network request.

3) Single Grounding –

The grounding the signal on network cable, introducing some other signal or removing an ethernet terminator all have the effect of preventing client from transmitting or receiving messages until the problem fixed.

Thank you,

Arun Bagul

Subversion (svn/cvs) repository backup script

Subversion (svn/cvs) repository backup script

By using this script we can take HOT backup and dump of subversion repository.

root@indiangnu.org:/home/arun# cat SVN-Backup.sh

#!/bin/bash

echo -e “Welocme to Subversion Backup utility by Arun Bagul”
echo -e “————————————————————–”

BACKUP_DIR=”/root/SVN_DB_Backup”
choice=$1
repository_path=$2
dest_name=$3
mydate=$(date +%d-%b-%Y)
SVNadmin=$(which svnadmin)
SVNlook=$(which svnlook)
#######################
if [ -d $BACKUP_DIR ]; then
echo “Backup directory $BACKUP_DIR exist”
echo -e “——————————————–”
else
echo “Backup directory $BACKUP_DIR does not exist”
exit
fi
#######################
if [ $# -eq 3 ]; then

case $choice in

dump)

backup_path=”${BACKUP_DIR}/${dest_name}_${mydate}”
#svnadmin path and dump $repository_path $backup_path
echo “Dump of Respository”
#echo “svnadmin dump $repository_path > $backup_path”
$SVNadmin dump $repository_path > $backup_path
;;
hotbkup)

backup_path=”${BACKUP_DIR}/${dest_name}_${mydate}_DIR”
#HotBackup of svn repository
echo “Hot Backup…”
#echo “$SVNadmin hotcopy $repository_path $backup_path”
$SVNadmin hotcopy $repository_path $backup_path
;;
esac
######
elif [ $# -eq 1 ]; then
if [ “$choice” = “lookup” ]; then
#svn look up
$SVNlook youngest $repository_path
fi
else
echo “Usage: SVN-Backup.sh { dump|hotbkup|lookup } repository_path dest file/dir_name”
fi

#####
echo “Done”
exit 0

root@indiangnu.org:/home/arun#

  • How to use this script-

root@indiangnu.org:/home/arun# /sbin/SVN-Backup
Welocme to Subversion Backup utility by Arun Bagul
————————————————————–
Backup directory /root/SVN_DB_Backup exist
——————————————–
Usage: SVN-Backup.sh { dump|hotbkup|lookup } repository_path dest file/dir_name
Done
root@indiangnu.org:/home/arun#

eg (1)-

root@indiangnu.org:~# SVN-Backup dump /usr/local/repos/ myrepos
Welocme to Subversion Backup utility by Arun Bagul
————————————————————————————–
Backup directory /root/SVN_Backup exist
——————————————–
Dump of Respository
* Dumped revision 0.
* Dumped revision 1.
* Dumped revision 2.
* Dumped revision 3.
* Dumped revision 4.
Done

root@indiangnu.org:~#

eg (2)-
root@indiangnu.org:~#SVN-Backup hotbkup /usr/local/repos/ myrepos
Welocme to Subversion Backup utility by Arun Bagul
————————————————————————————–
Backup directory /root/SVN_Backup exist
——————————————–
Hot Backup…
Done
root@indiangnu.org:~#SVN-Backup dump /usr/local/repos/ myrepos

Welocme to Subversion Backup utility by Arun Bagul
————————————————————————————–
Backup directory /root/SVN_Backup exist
——————————————–
Dump of Respository
* Dumped revision 0.
* Dumped revision 1.
* Dumped revision 2.
* Dumped revision 3.
* Dumped revision 4.
Done

root@indiangnu.org:~#SVN-Backup hotbkup /usr/local/repos/ myrepos
Welocme to Subversion Backup utility by Arun Bagul
—————————————————————————————–

Backup directory /root/SVN_Backup exist
——————————————–
Hot Backup…
Done
root@indiangnu.org:~#

UMASK – set file mode creation mask

UMASK – set file mode creation mask

UMASK is a UNIX environment variable which automatically sets file permissions on newly created files.

The UMASK variable can be confusing to use, because it does work as a mask. In other words, you set the permissions that you do not want in the UMASK.

To calculate permissions which will result from specific UMASK values, subtract the UMASK from 666 for files and from 777 for directories.

If you want all files created with permissions of 666, set your UMASK to 000. Alternatively, if you want all files created with permissions of 000, set your UMASK to 666.

A reasonable value for UMASK is 022, which will cause files to be created with permissions of 644 (rw-r–r–) and directories to be created with permissions of 755 (rwxr-xr-x).

A more secure value for UMASK is 066, which will cause files to be created with permissions of 600 (rw——-) and directories to be created with permissions of 700 (rwx——).

UMASK is nomally defined in the .profile or .login user startup files.

Thank you,

Ravi Bhure

RAID 0+1 — Optimize for Performance and Redundancy

RAID 0+1 — Optimize for Performance and Redundancy

RAID (Redundant Array of Independent Disks) is a set of technology standards for teaming disk drives to improve fault tolerance and performance.

RAID Levels

Level

Name

0 Striping
1 Mirroring
2 Parallel Access with Specialized Disks
3 Synchronous Access with Dedicated Parity Disk
4 Independent Access with Dedicated Parity Disk
5 Independent Access with Distributed Parity
6 Independent Access with Double Parity

Choosing a RAID Level

Each RAID level represents a set of trade-offs between performance, redundancy, and cost.

RAID 0 — Optimized for Performance

RAID 0 uses striping to write data across multiple drives simultaneously. This means that when you write a 5GB file across 5 drives, 1GB of data is written to each drive. Parallel reading of data from multiple drives can have a significant positive impact on performance.

The trade-off with RAID 0 is that if one of those drives fail, all of your data is lost and you must restore from backup.

RAID 0 is an excellent choice for cache servers, where the actual data being stored is of little value, but performance is very important.

RAID 1 — Optimized for Redundancy

RAID 1 uses mirroring to write data to multiple drives. This means that when you write a file, the file is actually written to two disks. If one of the disks fails, you simply replace it and rebuild the mirror.

The tradeoff with RAID 1 is cost. With RAID 1, you must purchase double the amount of storage space that your data requires.

RAID 5 — A Good Compromise

RAID 5 stripes data across multiple disks. RAID 5, however, adds a parity check bit to the data. This slightly reduces available disk capacity, but it also means that the RAID array continues to function if a single disk fails. In the event of a disk failure, you simply replace the failed disk and keep going.

The tradeoffs with RAID 5 are a small performance penalty in write operations and a slight decrease in usabable storage space.

RAID 0+1 — Optimize for Performance and Redundancy

RAID 0+1 combines the performance of RAID 0 with the redundancy of RAID 1.

To build a RAID 0+1 array, you first build a set of RAID 1 mirrored disks and you then combine these disk sets in a RAID 0 striped array.

A RAID 0+1 array can survive the loss of one disk from each mirrored pair. RAID 0+1 cannot survive the loss of two disks in the same mirrored pair.

Thank you,

Ravi Bhure

Who is Computer Hacker?

Who is Computer Hacker?

In Magnet Tech we had organised two Hackfest in past one and half years. During Hackfest, new guys who were participating in Hackfest always have common query/question in there mind… ie nothing but
“Who is Computer Hacker?”.

Defination –

Hacker is a person who enjoys learning the details of computer systems and how to stretch their capabilities as oppose to most users of computers who prefer to learn only minimum amount necessary”.

“Hacker is a person who programs enthusiastically or who enjoys programming rather than just theorising about programming”.

Thank you,

Arun & Yogesh

Float numbers comparision (shell script)

Float numbers comparision (shell script)

Introduction

Since long time I was thinking about How I can compare float numbers in shell script?.

Finally I got answer of this question!! There is no simple & straight forward way to compare float numbers in shell script….

* There are two ways you can solve this. The first is to actually use some sort of more sophisticated mathematical tool like bc to push out the conditional expression, then test its return value to see if your condition was met or not. That’s a bit tricky, particularly since bc can be difficult to use. Another way to use our own logic with beautiful shell commands

Here is my script with will compare float numbers –

root@indianGNU.org:/home/arun# cat float_compare.sh

#! /bin/bash
RESULT=””
################################
#This function will compare LHS > RHS or not
function is_greater_than ()
{
LHS=$1
RHS=$2
min=$((echo $LHS ; echo $RHS) | sort -n | head -1)
if [ “$min” = “$LHS” ]; then
return 1
else
return 0
fi
}
############################
#This function will compare LHS < RHS or not
is_less_than()
{
LHS=$1
RHS=$2
min=$((echo $LHS ; echo $RHS) | sort -n | head -1)
if [ “$min” = “$LHS” ]; then
return 0
else
return 1
fi
echo $min
}

############################
function compare()
{
function=$1
arg1=$2
arg2=$3
#echo -n “$FUNC $ARG1 $ARG2 … ”
################
$function $arg1 $arg2
if [ $? -eq 0 ]; then
#echo TRUE
RESULT=”TRUE”
else
#echo FALSE
RESULT=”FALSE”
fi
}

############################

num1=$1
num2=$2

if [ “$num1” = “$num2” ]; then
echo “$num1 is equal to $num2”
else
## compare num1 > num2
compare is_greater_than $num1 $num2
if [ “$RESULT” = “TRUE” ] ; then
echo “$num1 > $num2”
fi
## compare num1 < num2
compare is_less_than $num1 $num2
if [ “$RESULT” = “TRUE” ] ; then
echo “$num1 < $num2”
fi
fi

root@indianGNU.org:/home/arun#

How to use or Test this script –

root@indianGNU.org:/home/arun# ./float_compare.sh 2 2.33
2 < 2.33
root@indianGNU.org:/home/arun# ./float_compare.sh 2.60  2.33
2.60 > 2.33
root@indianGNU.org:/home/arun# ./float_compare.sh 56.55  65.80
56.55 < 65.80
root@indianGNU.org:/home/arun# ./float_compare.sh 44.80  44.80
44.80  is equal to 44.80
root@indianGNU.org:/home/arun#

MySQL Replication ( One master multiple slave )

MySQL Replication ( One master multiple slave )

Introduction : –

MySQL Replication allows databases on one MySQL server to be duplicated on another, were introduced in MySQL 3.23.15.

For a description of the syntax of replication-related SQL statements,I suggest that you visit Web site at http://www.mysql.com often and read updates to this chapter. Replication is constantly being improved, and updates the manual frequently with the most current information.

MySQL support for one-way replication. One server acts as the master, while one or more other servers act as slaves. The master server writes updates to its binary log files, and maintains an index of the files to keep track of log rotation. These logs serve as a record of updates to be sent to slave servers. When a slave server connects to the master server, it informs the master of its last position within the logs since the last successfully propagated update. The slave catches up any updates that have occurred since then, and then blocks and waits for the master to notify it of new updates.

A slave server can also serve as a master if you want to set up chained replication servers.

Note that when you are using replication, all updates to the tables that are replicated should be performed on the master server. Otherwise, you must always be careful to avoid conflicts between updates that users make to tables on the master and updates that they make to tables on the slave.

1] One-way replication has benefits for robustness, speed, and system administration –

* Robustness is increased with a master/slave setup. In the event of problems with the master, you can switch to the slave as a backup.
* Better response time for clients can be achieved by splitting the load for processing client queries between the master and slave servers.
* SELECT queries may be sent to the slave to reduce the query processing load of the master. Statements that modify data should still be sent to the master so that the master and slave do not get out of sync. This load-balancing strategy is effective if non-updating queries dominate, but that is the normal case.
* Another benefit of using replication is that you can perform backups using a slave server without disturbing the master. The master continues to process updates while the backup is being made.

2] Replication Implementation Overview –

MySQL replication is based on the master server keeping track of all changes to your databases (updates, deletes, and so on) in the binary logs. Therefore, to use replication, you must enable binary logging on the master server. Each slave server receives binary log from the master. Master saves updates which master has recorded in its binary log, so that the slave can execute the same updates on its copy of the data.

It is very important to realize that the binary log is simply a record starting from the fixed point in time at which you enable binary logging. Any slaves that you set up will need copies of the databases on your master as they existed at the moment you enabled binary logging on the master. If you start your slaves with databases that are not the same as what was on the master when the binary log was started, your slaves may fail.

One way to copy the master’s data to the slave is to use the LOAD DATA FROM MASTER statement. Be aware that LOAD DATA FROM MASTER is available only as of MySQL 4.0.0 and currently works only if all the tables on the master are MyISAM type. Also, this statement acquires a global read lock, so no updates on the master are possible while the tables are being transferred to the slave. When we implement lock-free hot table backup (in MySQL 5.0), this global read lock will no longer be necessary.

Due to these limitations, we recommend that at this point you use LOAD DATA FROM MASTER only if the dataset on the master is relatively small, or if a prolonged read lock on the master is acceptable. While the actual speed of LOAD DATA FROM MASTER may vary from system to system, a good rule of thumb for how long it will take is 1 second per 1MB of data. That is only a rough estimate, but you should get close to it if both master and slave are equivalent to 700MHz Pentium performance and are connected through a 100MBit/s network.

After the slave has been set up with a copy of the master’s data, it will simply connect to the master and wait for updates to process. If the master goes away or the slave loses connectivity with your master, it will keep trying to connect periodically until it is able to reconnect and resume listening for updates. The retry interval is controlled by the –master-connect-retry option. The default is 60 seconds.

Each slave keeps track of where it left off. The master server has no knowledge of how many slaves there are or which ones are up to date at any given time.

3] Replication Implementation Details –

MySQL replication capabilities are implemented using three threads (one on the master server and two on the slave). When START SLAVE is issued, the slave creates an I/O thread. The I/O thread connects to the master and asks it to send the statements recorded in its binary logs. The master creates a thread to send the binary log contents to the slave. This thread can be identified as the Binlog Dump thread in the output of SHOW PROCESSLIST on the master. The slave I/O thread reads what the master Binlog Dump thread sends and simply copies it to some local files in the slave’s data directory called relay logs. The third thread is the SQL thread, which the slave creates to read the relay logs and execute the updates they contain.

In the preceding description, there are three threads per slave. For a master that has multiple slaves, it creates one thread for each currently connected slave, and each slave has its own I/O and SQL threads.

For versions of MySQL before 4.0.2, replication involves only two threads (one on the master and one on the slave). The slave I/O and SQL threads are combined as a single thread, and no relay log files are used.

The advantage of using two slave threads is that statement reading and execution are separated into two independent tasks. The task of reading statements is not slowed down if statement execution is slow. For example, if the slave server has not been running for a while, its I/O thread can quickly fetch all the binary log contents from the master when the slave starts, even if the SQL thread lags far behind and may take hours to catch up. If the slave stops before the SQL thread has executed all the fetched statements, the I/O thread has at least fetched everything so that a safe copy of the statements is locally stored in the slave’s relay logs for execution when next the slave starts. This allows the binary logs to be purged on the master, because it no longer need wait for the slave to fetch their contents.

The SHOW PROCESSLIST statement provides information that tells you what is happening on the master and on the slave regarding replication.

MySQL Master — 192.168.0.8

[root@testserver ~]# cat /etc/my.cnf
[mysqld]
set-variable = max_connections=500
safe-show-database
#log = /var/log/mysql/mysql.log

############################################
##MySQL replication setting

server-id = 1
log-bin = /var/log/mysql/binary/mysql-bin.log
binlog-do-db = student
binlog-ignore-db = mysql
log = /var/log/mysql/mysql.log

[root@testserver ~]#

[root@testserver ~]# mkdir /var/log/mysql/binary/
[root@testserver ~]# ll -d /var/log/mysql/binary/
drwxr-xr-x 2 root root 4096 Jan 30 15:30 /var/log/mysql/binary/
[root@testserver ~]# ll -d /var/log/mysql/
drwxr-xr-x 3 mysql mysql 4096 Jan 30 15:30 /var/log/mysql/
[root@testserver ~]# chown mysql:mysql -R /var/log/mysql/
binary/ mysql.log
[root@testserver ~]# chown mysql:mysql -R /var/log/mysql/binary/
[root@testserver ~]#

[root@testserver ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 950
Server version: 5.0.45-community-log MySQL Community Edition (GPL)

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| mysql |
+——————–+
9 rows in set (0.00 sec)

mysql> create database student;
Query OK, 1 row affected (0.03 sec)

mysql> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| mysql |
| student |
+——————–+
10 rows in set (0.00 sec)

mysql> use student;
Database changed
mysql>

mysql> create table class ( rollno INT(5) NOT NULL PRIMARY KEY AUTO_INCREMENT , name VARCHAR(30) );
Query OK, 0 rows affected (0.32 sec)

mysql> DESC class;
+——–+————-+——+—–+———+—————-+
| Field | Type | Null | Key | Default | Extra |
+——–+————-+——+—–+———+—————-+
| rollno | int(5) | NO | PRI | NULL | auto_increment |
| name | varchar(30) | YES | | NULL | |
+——–+————-+——+—–+———+—————-+
2 rows in set (0.03 sec)

mysql>

mysql> INSERT INTO class VALUES (”, ‘Arun Bagul’);
Query OK, 1 row affected, 1 warning (0.01 sec)

mysql>
mysql> SELECT * FROM class;
+——–+————+
| rollno | name |
+——–+————+
| 1 | Arun Bagul |
+——–+————+
1 row in set (0.00 sec)

mysql> INSERT INTO class VALUES (”, ‘Suhail Thakur’);
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> INSERT INTO class VALUES (”, ‘Bhavesh Vala’);
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> SELECT * FROM class;
+——–+—————+
| rollno | name |
+——–+—————+
| 1 | Arun Bagul |
| 2 | Suhail Thakur |
| 3 | Bhavesh Vala |
+——–+—————+
3 rows in set (0.00 sec)

mysql>
[root@testserver ~]#

[root@testserver ~]# /etc/init.d/mysql restart
Shutting down MySQL… [ OK ]
Starting MySQL [ OK ]
[root@testserver ~]# /etc/init.d/mysql restart
[root@testserver ~]# cd /var/log/mysql/binary/mysql-bin.
mysql-bin.000001 mysql-bin.index
[root@testserver ~]# cd /var/log/mysql/binary/
[root@testserver binary]# ls
mysql-bin.000001 mysql-bin.index
[root@testserver binary]#

[root@testserver binary]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.0.45-community-log MySQL Community Edition (GPL)

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql>
mysql> use student;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+——————-+
| Tables_in_student |
+——————-+
| class |
+——————-+
1 row in set (0.00 sec)

mysql> SELECT * FROM class;
+——–+—————+
| rollno | name |
+——–+—————+
| 1 | Arun Bagul |
| 2 | Suhail Thakur |
| 3 | Bhavesh Vala |
+——–+—————+
3 rows in set (0.00 sec)

mysql> INSERT INTO class VALUES (”, ‘Nishit Shah’);
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> SELECT * FROM class;
+——–+—————+
| rollno | name |
+——–+—————+
| 1 | Arun Bagul |
| 2 | Suhail Thakur |
| 3 | Bhavesh Vala |
| 4 | Nishit Shah |
+——–+—————+
4 rows in set (0.00 sec)

mysql>

4] Create user on master server which has permission to read binary logs –

mysql> GRANT REPLICATION SLAVE ON *.* TO ‘replication’@’192.168.0.%’ IDENTIFIED BY ‘mypwd’;
Query OK, 0 rows affected (0.01 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
[root@testserver binary]#

[root@testserver binary]# mysql -u root -p
Enter password:
\Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 340
Server version: 5.0.45-community-log MySQL Community Edition (GPL)

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> SHOW MASTER STATUS;
+——————+———-+—————–+——————+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+——————+———-+—————–+——————+
| mysql-bin.000002 | 98 | student,student | mysql,mysql |
+——————+———-+—————–+——————+
1 row in set (0.02 sec)

mysql>

mysql> SHOW PROCESSLIST;
+—-+——-+———–+——-+———+——+————+——————————————————————————————————+
| Id | User | Host | db | Command | Time | State | Info |
+—-+——-+———–+——-+———+——+————+——————————————————————————————————+
| 31 | root | localhost | NULL | Query | 0 | NULL | SHOW PROCESSLIST |
| 41 | horde | localhost | horde | Sleep | 0 | | NULL |
| 42 | horde | localhost | horde | Query | 1 | statistics | SELECT session_data FROM horde_sessionhandler WHERE session_id = ‘f70a7d64bd353917679814813a513c8f’ |
| 43 | horde | localhost | horde | Query | 1 | statistics | SELECT session_data FROM horde_sessionhandler WHERE session_id = ‘f70a7d64bd353917679814813a513c8f’ |
+—-+——-+———–+——-+———+——+————+——————————————————————————————————+
4 rows in set (0.00 sec)

mysql> SHOW PROCESSLIST\G;
*************************** 1. row ***************************
Id: 31
User: root
Host: localhost
db: NULL
Command: Query
Time: 0
State: NULL
Info: SHOW PROCESSLIST
1 row in set (0.00 sec)

ERROR:
No query specified

mysql>

=========================================================

MySQL Slave — 192.168.0.191

5] Edit my.cnf file of replication slave and create DB and upload the dump of DB –

[root@arun ~]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1

########################################
##slave setting
server-id=4
master-port=3306
master-host=192.168.0.8
master-user=replication
master-password=mypwd
master-connect-retry=60
replicate-do-db=student

#slave setting end

[mysql.server]
user=mysql
#basedir=/var/lib

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root@arun ~]#

[root@arun ~]# mysqladmin create student -u root -p
Enter password:
[root@arun ~]# mysql -u root -p student < /root/arun.sql
Enter password:
[root@arun ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1020
Server version: 5.0.45-community MySQL Community Edition (GPL)

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> SHOW DATABASES;
+——————–+
| Database |
+——————–+
| information_schema |
| mysql |
| student |
+——————–+
12 rows in set (0.01 sec)

mysql> USE student;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> SHOW TABLES;
+——————-+
| Tables_in_student |
+——————-+
| class |
+——————-+
1 row in set (0.00 sec)

mysql> SELECT * FROM class;
+——–+—————+
| rollno | name |
+——–+—————+
| 1 | Arun Bagul |
| 2 | Suhail Thakur |
| 3 | Bhavesh Vala |
| 4 | Nishit Shah |
| 5 | Yogesh Nikam |
| 6 | Deven Jadhav |
+——–+—————+
6 rows in set (0.00 sec)

mysql> quit
Bye
[root@arun ~]# /etc/init.d/mysql restart
Shutting down MySQL. [ OK ]
Starting MySQL [ OK ]
[root@arun ~]#

6] Now login to Master (192.168.0.8) and check Master status —

[root@testserver ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1599
Server version: 5.0.45-community-log MySQL Community Edition (GPL)

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> SHOW MASTER STATUS;
+——————+———-+—————–+——————+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+——————+———-+—————–+——————+
| mysql-bin.000001 | 98 | student,student | mysql,mysql |
+——————+———-+—————–+——————+
1 row in set (0.00 sec)

mysql>

mysql> USE student;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> SHOW TABLES;
+——————-+
| Tables_in_student |
+——————-+
| class |
+——————-+
1 row in set (0.01 sec)

mysql> SELECT * FROM class;
+——–+—————+
| rollno | name |
+——–+—————+
| 1 | Arun Bagul |
| 2 | Suhail Thakur |
| 3 | Bhavesh Vala |
| 4 | Nishit Shah |
| 5 | Yogesh Nikam |
| 6 | Deven Jadhav |
+——–+—————+
6 rows in set (0.06 sec)

mysql> quit
Bye
[root@testserver ~]#

7] Now login to Slave ie 192.168.0.191 in my case –

[root@arun ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.0.45-community MySQL Community Edition (GPL)

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> SHOW SLAVE STATUS;
+—————-+—————+——————–+——————–+——————–+—————–+——————-+—————-+———————–+
| Slave_IO_State | Master_Host | Master_User | Master_Port | Connect_Retry | Master_Log_File | Read_Master_Log_Pos | Relay_Log_File | Relay_Log_Pos | Relay_Master_Log_File | Slave_IO_Running | Slave_SQL_Running | Replicate_Do_DB | Replicate_Ignore_DB | Replicate_Do_Table | Replicate_Ignore_Table | Replicate_Wild_Do_Table | Replicate_Wild_Ignore_Table | Last_Errno | Last_Error | Skip_Counter | Exec_Master_Log_Pos | Relay_Log_Space | Until_Condition | Until_Log_File | Until_Log_Pos | Master_SSL_Allowed | Master_SSL_CA_File | Master_SSL_CA_Path | Master_SSL_Cert | Master_SSL_Cipher | Master_SSL_Key | Seconds_Behind_Master |
+—————-+—————+——————–+——————–+——————–+—————–+——————-+—————-+———————–+
| Waiting for master to send event | 192.168.0.8 | replication | 3306 | 60 | mysql-bin.000001 | 98 | arun-relay-bin.000002 | 235 | mysql-bin.000001 | Yes | Yes | student,student | | | | | | 0 | | 0 | 98 | 235 | None | | 0 | No | | | | | | 0 |
+—————-+—————+——————–+——————–+——————–+—————–+——————-+—————-+———————–+
1 row in set (0.00 sec)

mysql>

8] Now login to Master Server (192.168.0.8)and check processlist –
mysql> SHOW MASTER STATUS;
+——————+———-+—————–+——————+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+——————+———-+—————–+——————+
| mysql-bin.000001 | 98 | student,student | mysql,mysql |
+——————+———-+—————–+——————+
1 row in set (0.01 sec)

mysql> SHOW PROCESSLIST;
+——+————-+———————+———–+————-+——+—————————————————————-+——————+
| Id | User | Host | db | Command | Time | State | Info |
+——+————-+———————+———–+————-+——+—————————————————————-+——————+
| 570 | eximstats | localhost | eximstats | Sleep | 401 | | NULL |
| 1578 | replication | 192.168.0.191:38843 | NULL | Binlog Dump | 494 | Has sent all binlog to slave; waiting for binlog to be updated | NULL |
| 1633 | root | localhost | NULL | Query | 0 | NULL | SHOW PROCESSLIST |
+——+————-+———————+———–+————-+——+—————————————————————-+——————+
3 rows in set (0.00 sec)

mysql>

mysql> SHOW PROCESSLIST\G;
*************************** 1. row ***************************
Id: 570
User: eximstats
Host: localhost
db: eximstats
Command: Sleep
Time: 508
State:
Info: NULL
*************************** 2. row ***************************
Id: 1578
User: replication
Host: 192.168.0.191:38843
db: NULL
Command: Binlog Dump
Time: 601
State: Has sent all binlog to slave; waiting for binlog to be updated
Info: NULL
*************************** 3. row ***************************
Id: 1633
User: root
Host: localhost
db: NULL
Command: Query
Time: 0
State: NULL
Info: SHOW PROCESSLIST
3 rows in set (0.00 sec)

ERROR:
No query specified

mysql>

9] Now login to Slave ie (192.168.0.191) and check the processlist –

mysql> SHOW PROCESSLIST;
+—-+————-+———–+——+———+——+———————————————————————–+——————+
| Id | User | Host | db | Command | Time | State | Info |
+—-+————-+———–+——+———+——+———————————————————————–+——————+
| 1 | system user | | NULL | Connect | 685 | Waiting for master to send event | NULL |
| 2 | system user | | NULL | Connect | 685 | Has read all relay log; waiting for the slave I/O thread to update it | NULL |
| 5 | root | localhost | NULL | Query | 0 | NULL | SHOW PROCESSLIST |
+—-+————-+———–+——+———+——+———————————————————————–+——————+
3 rows in set (0.00 sec)

mysql> SHOW PROCESSLIST\G;
*************************** 1. row ***************************
Id: 1
User: system user
Host:
db: NULL
Command: Connect
Time: 690
State: Waiting for master to send event
Info: NULL
*************************** 2. row ***************************
Id: 2
User: system user
Host:
db: NULL
Command: Connect
Time: 690
State: Has read all relay log; waiting for the slave I/O thread to update it
Info: NULL
*************************** 3. row ***************************
Id: 5
User: root
Host: localhost
db: NULL
Command: Query
Time: 0
State: NULL
Info: SHOW PROCESSLIST
3 rows in set (0.00 sec)

ERROR:
No query specified

mysql>

10] How to reset Binary log position on the slave –

mysql> CHANGE MASTER TO MASTER_HOST=’192.168.0.8′,MASTER_USER=’replication’,MASTER_PASSWORD=’mypwd’, MASTER_LOG_FILE=’mysql-bin.000004′,MASTER_LOG_POS=412;
Query OK, 0 rows affected (0.01 sec)

11] Now login to Master (192.168.0.8) and add records in “class” table of “student” DB –

[root@testserver ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1642
Server version: 5.0.45-community-log MySQL Community Edition (GPL)

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> USE student;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> SHOW TABLES;
+——————-+
| Tables_in_student |
+——————-+
| class |
+——————-+
1 row in set (0.00 sec)

mysql> SELECT * FROM class;
+——–+—————+
| rollno | name |
+——–+—————+
| 1 | Arun Bagul |
| 2 | Suhail Thakur |
| 3 | Bhavesh Vala |
| 4 | Nishit Shah |
| 5 | Yogesh Nikam |
| 6 | Deven Jadhav |
+——–+—————+
6 rows in set (0.02 sec)

mysql>

mysql> INSERT INTO class VALUES (”, ‘Kaushik Kawa’);
Query OK, 1 row affected, 1 warning (0.02 sec)

mysql> INSERT INTO class VALUES (”, ‘Dipak Jadhav’);
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> INSERT INTO class VALUES (”, ‘Binish Philip’);
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql>
mysql> SELECT * FROM class;
+——–+—————+
| rollno | name |
+——–+—————+
| 1 | Arun Bagul |
| 2 | Suhail Thakur |
| 3 | Bhavesh Vala |
| 4 | Nishit Shah |
| 5 | Yogesh Nikam |
| 6 | Deven Jadhav |
| 7 | Kaushik Kawa |
| 8 | Dipak Jadhav |
| 9 | Binish Philip |
+——–+—————+
9 rows in set (0.00 sec)

mysql>

mysql> SHOW MASTER STATUS;
+——————+———-+—————–+——————+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+——————+———-+—————–+——————+
| mysql-bin.000001 | 520 | student,student | mysql,mysql |
+——————+———-+—————–+——————+
1 row in set (0.00 sec)

mysql>

12] Now Login to Slave (192.168.0.191) and520 check if Data is replicated or not –

[root@arun ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.0.45-community MySQL Community Edition (GPL)

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> USE student;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> SHOW TABLES;
+——————-+
| Tables_in_student |
+——————-+
| class |
+——————-+
1 row in set (0.00 sec)

mysql> SELECT * FROM class;
+——–+—————+
| rollno | name |
+——–+—————+
| 1 | Arun Bagul |
| 2 | Suhail Thakur |
| 3 | Bhavesh Vala |
| 4 | Nishit Shah |
| 5 | Yogesh Nikam |
| 6 | Deven Jadhav |
| 7 | Kaushik Kawa |
| 8 | Dipak Jadhav |
| 9 | Binish Philip |
+——–+—————+
9 rows in set (0.00 sec)

mysql>

mysql> SHOW SLAVE STATUS;
+—————–+——————-+—————-+———————–+
| Slave_IO_State | Master_Host | Master_User | Master_Port | Connect_Retry | Master_Log_File | Read_Master_Log_Pos | Relay_Log_File | Relay_Log_Pos | Relay_Master_Log_File | Slave_IO_Running | Slave_SQL_Running | Replicate_Do_DB | Replicate_Ignore_DB | Replicate_Do_Table | Replicate_Ignore_Table | Replicate_Wild_Do_Table | Replicate_Wild_Ignore_Table | Last_Errno | Last_Error | Skip_Counter | Exec_Master_Log_Pos | Relay_Log_Space | Until_Condition | Until_Log_File | Until_Log_Pos | Master_SSL_Allowed | Master_SSL_CA_File | Master_SSL_CA_Path | Master_SSL_Cert | Master_SSL_Cipher | Master_SSL_Key | Seconds_Behind_Master |
+—————–+——————-+—————-+———————–+
| Waiting for master to send event | 192.168.0.8 | replication | 3306 | 60 | mysql-bin.000001 | 520 | arun-relay-bin.000002 | 657 | mysql-bin.000001 | Yes | Yes | student,student | | | | | | 0 | | 0 | 520 | 657 | None | | 0 | No | | | | | | 0 |
+———————————-+————-+————-+————-
1 row in set (0.00 sec)

mysql>

13 ]How to reset MySQL slave –

mysql> STOP SLAVE;
Query OK, 0 rows affected (0.00 sec)

mysql> STOP SLAVE;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> RESET SLAVE;
Query OK, 0 rows affected (0.03 sec)

mysql> SHOW SLAVE STATUS;
+—————-+————-+————-+————-+—————| Slave_IO_State | Master_Host | Master_User | Master_Port | Connect_Retry | Master_Log_File | Read_Master_Log_Pos | Relay_Log_File | Relay_Log_Pos | Relay_Master_Log_File | Slave_IO_Running | Slave_SQL_Running | Replicate_Do_DB | Replicate_Ignore_DB | Replicate_Do_Table | Replicate_Ignore_Table | Replicate_Wild_Do_Table | Replicate_Wild_Ignore_Table | Last_Errno | Last_Error | Skip_Counter | Exec_Master_Log_Pos | Relay_Log_Space | Until_Condition | Until_Log_File | Until_Log_Pos | Master_SSL_Allowed | Master_SSL_CA_File | Master_SSL_CA_Path | Master_SSL_Cert | Master_SSL_Cipher | Master_SSL_Key | Seconds_Behind_Master |
+—————–+——————-+—————-+———————–+
| | 192.168.0.8 | replication | 3306 | 60 | | 4 | arun-relay-bin.000001 | 4 | | No | No | student,student | | | | | | 0 | | 0 | 0 | 117 | None | | 0 | No | | | | | | NULL |
+—————-+————-+————-+————-+—————
1 row in set (0.00 sec)

mysql> CHANGE MASTER TO MASTER_HOST=’192.168.0.8′, MASTER_USER=’replication’, MASTER_PASSWORD=’mypwd’, MASTER_LOG_FILE=’mysql-bin.000001′,MASTER_LOG_POS=520;
Query OK, 0 rows affected (0.02 sec)

mysql> SHOW SLAVE STATUS;
+—————+——————–+——————–+——————–+—————–+——————-+—————-+———————–+
| Slave_IO_State | Master_Host | Master_User | Master_Port | Connect_Retry | Master_Log_File | Read_Master_Log_Pos | Relay_Log_File | Relay_Log_Pos | Relay_Master_Log_File | Slave_IO_Running | Slave_SQL_Running | Replicate_Do_DB | Replicate_Ignore_DB | Replicate_Do_Table | Replicate_Ignore_Table | Replicate_Wild_Do_Table | Replicate_Wild_Ignore_Table | Last_Errno | Last_Error | Skip_Counter | Exec_Master_Log_Pos | Relay_Log_Space | Until_Condition | Until_Log_File | Until_Log_Pos | Master_SSL_Allowed | Master_SSL_CA_File | Master_SSL_CA_Path | Master_SSL_Cert | Master_SSL_Cipher | Master_SSL_Key | Seconds_Behind_Master |
+—————-+————-+————-+————-+—————+——————+———————+———————–+—————+———————–+——————+——————-+—————–+———————+——————–+————————+————————-+—————————–+————+————+————–+———————+—————–+—————–+—————-+—————+——————–+——————–+——————–+—————–+——————-+—————-+———————–+
| | 192.168.0.8 | replication | 3306 | 60 | mysql-bin.000001 | 520 | arun-relay-bin.000001 | 4 | mysql-bin.000001 | No | No | student,student | | | | | | 0 | | 0 | 520 | 98 | None | | 0 | No | | | | | | NULL |
+—————–+——————-+—————-+———————–+
1 row in set (0.00 sec)

mysql>

** you may use this command to start the slave

mysql> START SLAVE;
Query OK, 0 rows affected (0.03 sec)

mysql>quit
Bye
[root@arun ~]#

Regards,

Arun Bagul

Unable to Verify HTTPS Certificate (Unknown Authority)

Unable to Verify HTTPS Certificate (Unknown Authority)

I facing same problem since few day after creating certificate for Secure HTTPS sites. then whenever I am browsing sites with https it was showing me error like “Website Certified by Unknown Authority – unable to verify the identity of indiangnu.org site”

I was thinking that this might be problem with browser incompatibility issue and my borwser is not supporting HTTPS. But I was wrong and finally I found that there is some simple miss configuration on server side.

* Virtual Hosting of My Site –

<VirtualHost 192.168.1.200:443>
ServerAdmin webmaster@indiangnu.org
ServerName www.indiangnu.org
DocumentRoot /home/indgnu/public_html

User indgnu
Group indgnu
ScriptAlias /cgi-bin/ /home/indgnu/public_html/cgi-bin/

SSLEnable
SSLCertificateFile /usr/share/ssl/certs/indiangnu.org.crt
SSLCertificateKeyFile /usr/share/ssl/private/indiangnu.org.key
SSLCACertificateFile /usr/share/ssl/certs/intermediate.crt

SSLLogFile /var/log/apache/domlogs/indiangnu.org-ssl_data_log

</VirtualHost>

If you are using Certificate authorize by CA then you need to add this line and intermediate.crt Certificate of your CA.

SSLCACertificateFile /usr/share/ssl/certs/intermediate.crt

If you are using Self signed Certificate then you may not face this problem..

* The options might depends upon the version of Apache.

* Screenshot of error

https

Thank you,

Arun Bagul

Rsync Client script

Rsync Client script

This is the Rsync client side shell scrpit.. You can specify setting for backup in backup.conf file and set cron job. This script will take backup of mentioned directory of respective users at given time.

1] sample backup file –

root@indiangnu.org:/home/arun# cat /etc/backup/backup.conf

#This is the Backup conf for client
#username:path_to_backup:where_to_backup:when_to_backup:time:
#when_to_backup=> daily=1,weekly=2, monthly=3
#where_to_backup=>USERNAME [server is 192.168.1.50], time=>0930 like 9:30 as 0930
root:/etc/:Server-conf/Fileserver_etc-dir:09:09:no
arun:/home/arun/public_html:arun/bkup:10:09:no
nishit:/home/nishit/public_html:nishit/bkup:11:09:no

root@indiangnu.org:/home/arun#

2] Set cronjob –

#Cronjob for Backup on Fileserver

0 08-12 * * * /etc/backup/rsync-client.sh

3] Rsync client script –

root@indiangnu.org:/home/arun# cat /etc/backup/rsync-client.sh

#!/bin/bash
#User define Function (UDF)……..
HOSTNAME=192.168.1.160

#Process backup.conf
########################################
processLine()
{
#echo $line
#username:path_to_backup:where_to_backup:when_to_backup:time:
username=$(echo $line | awk -F: ‘{ print $1 }’)
path_to_bkup=$(echo $line | awk -F: ‘{ print $2 }’)
where_to_bkup=$(echo $line | awk -F: ‘{ print $3 }’)
when_to_bkup=$(echo $line | awk -F: ‘{ print $4 }’)
time=$(echo $line | awk -F: ‘{ print $5 }’)
status=$(echo $line | awk -F: ‘{ print $6 }’)
#echo “Arg[1]–>”$username
#echo “Arg[2]–>”$path_to_bkup
#echo “Arg[3]–>”$where_to_bkup
#echo “Arg[4]–>”$when_to_bkup
#echo “Arg[5]–>”$time
#echo “Arg[6]–>”$status

#Test the backup.conf
################
if [ “$username” == “” ] ; then
echo “Record is Null”
else
#Check who is running this script root or normal user.
who_is_running=$(id -nu)
#call function to check password file

password_fun $who_is_running $username
system_time=$(date +%H)
if [ “$system_time” == “$time” ] ; then
#call backup function
backup $username $path_to_bkup $where_to_bkup $when_to_bkup $time $status
#echo “system_time=”$system_time
#echo “time=”$time
fi
fi
################
}

#Password Function
########################################
password_fun()
{
#user=”$@” #get all argument
is_root_user=$1
user=$2
#where is secret.conf file
if [ “$is_root_user” == “root” ]; then
if [ “$user” == “root” ]; then
pwd_file=”/root/.secret.conf”
else
pwd_file=”/home/$user/.secret.conf”
fi
#Check file exist or not
if [ ! -f $pwd_file ]; then
echo “$pwd_file file does not exist!”
echo “creating File..”
touch $pwd_file
echo “changing ownership and permission”
owner=”root:root $pwd_file”
echo “owner “$owner
chown root:root $pwd_file
chmod 600 $pwd_file
echo “password” > $pwd_file
#echo $(ls -l $pwd_file)
fi
else
echo “permission denied to read pwd file”
fi
}

#Set ENV variable
########################################
set_ENV_var()
{
user=$1
TERM=xterm
LANGUAGE=en_IN:en
LOGNAME=$user
if [ “$user” == “root” ]; then
USER=root
PWD=/root
HOME=/root
PATH=$PATH:/usr/bin/X11:/usr/games
else
USER=${user}
PATH=/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
HOME=/home/${user}
PWD=/home/${user}
fi
}
#Backup Function
########################################
backup()
{
username=$1
path_to_bkup=$2
where_to_bkup=$3
when_to_bkup=$4
time=$5
status=$6
echo “——————————————————————”
#command=”/usr/bin/rsync –password-file=”/home/$username/.secret.conf” $path_to_bkup -Cravz 192.168.0.5::$where_to_bkup”
echo “Backup started for ${username}……”
if [ “$username” == “root” ]; then
command=” –password-file=”/root/.secret.conf” ${path_to_bkup} -Cravz 192.168.1.50::${where_to_bkup}”
else
command=” –password-file=”/home/${username}/.secret.conf” ${path_to_bkup} -Cravz 192.168.1.50::${where_to_bkup}”
fi

#Set environment variable…
set_ENV_var $username
#check status ofBackup
if [ “$status” == “no” ] ; then
if [ -f $path_to_bkup ]; then
echo “$path_to_bkup file/dir does exist!”
/usr/bin/rsync $command
elif [ -d $path_to_bkup ]; then
echo “This dirname [$path_to_bkup] does exists”
/usr/bin/rsync $command
else
echo “Neither [$path_to_bkup] or [$path_to_bkup] exist”
fi
if [ $? -eq 0 ]; then
status=”yes”
else
status=”no”
fi
fi
echo “——————————————————————”
#Send mail to user
###########################
if [ $? -eq 0 ]; then
if [ “$username” != “root” ]; then
/etc/backup/mailclient 192.168.1.100 backupmail ${username} ${HOSTNAME}
fi
fi
#Set back env to root…
set_ENV_var root
#Update status function
#update_status $username $status $time
}

#Staus Function

########################################

update_status()
{
status_file=”/etc/backup/backup.status”
new_user=$1
new_status=$2
new_time=$3
update=”${new_user}:${new_status}:${new_time}:”
echo “update string:->”$update
echo “update::status file–>”$status_file
# Read $status_file using the file descriptors
file_string=””
count=”0″
while [ 1 ]
do
read myline || break
username=$(echo $line | awk -F: ‘{ print $1 }’)
if [ “$user” == “$username” ]; then
if [ $count -eq 0 ]; then
file_string=${file_string}${update}
count=`expr $count + 1`
else
file_string=${file_string}
fi
else
file_string=${file_string}${myline}
fi
#save string to file
echo $file_string > $status_file
echo -e “update”
cat $status_file
done < $status_file
#echo “update backup.status file function is end”
}

#Main script stars here
########################################
FILE=””
#Is file name given as command line argument
#Else read it from standard input device
if [ “$1” == “” ]; then
FILE=”/etc/backup/backup.conf”
else
FILE=”$1″
#make sure file exist and readable
if [ ! -f $FILE ]; then
echo “$FILE : does not exists”
exit 1
elif [ ! -r $FILE ]; then
echo “$FILE: can not read”
exit 2
fi
fi
#Read $FILE using the file descriptors
count=”1″
exec 3<&0
exec 0<$FILE
while read line
do
# use $line variable to process line in processLine() function
if [ $count -gt 4 ]; then
processLine $line
else
count=$(expr $count + 1)
fi

done
exec 0<&3
exit 0

root@indiangnu.org:/home/arun#