Saturday, April 11, 2009

Database replication an effective means of Backup !

What is Database replication?
Database replication is one of most effective means of Backup. This is more effective when you need to handle a huge volume of data in a big organization. It is an online process means the master database is backed up instantaneously as and when there are any changes to the master database. The process of Replication may work in chained fashion. Replication protects against hardware failures on one of the replicated databases but not against user stupidity or maliciousness! If a user deletes a number of records, this process will then be replicated onto the other replicated servers, making replication useless as a reliable means of backup.

How to achieve this? ( I described about MySQL Database only)
Here both the servers are of same versions i.e. version: 4.1.15

The Master server is located in the location
/home/bijit/database/mysql

To start the services:

mysqld_multi start 3
mysqld_multi start 4

To log into mysql:

/home/bijit/database/mysql/bin/mysql -u root -proot --port=3307 --socket=/home/bijit/database/mysql/config/mysql.sock

/home/bijit/database2/mysql/bin/mysql -u root -p --port=3308 --socket=/home/bijit/database2/mysql/var/mysql.sock

The slave server is located in the path
/home/bijit/database2/mysql
Steps:
On the master do the following:
1.
use database mysql;
GRANT REPLICATION SLAVE ON *.* TO replicator@localhost IDENTIFIED BY 'replicator';
FLUSH PRIVILEGES;
2.
Make a copy of tables and data i.e. the entire database of the Master server. In this case copy the data directory located in /home/bijit/database/mysql/var
3.
In the my.cnf of Master server, add the following entries;

log-bin
server-id=1
4. Login to maser mysql server, and note the bin-log file and its position as
mysql> show master status;
+----------------------+----------+--------------+------------------+
File Position Binlog_Do_DB Binlog_Ignore_DB
+----------------------+----------+--------------+------------------+
localhost-bin.000002 79
+----------------------+----------+--------------+------------------+
1 row in set (0.05 sec)

On the slave do the following:

1.
In the file my.cnf, add the following entries (under the slave servers entry),
master-host = localhost
master-user = replicator
master-password = replicator
master-port = 3307
server-id = 2

2. Start the slave server, create a user called replicator as created in the master;
mysql> use mysql;
mysql> grant all privileges on *.* to replicator@localhost identified by 'replicator';
mysql>flush privileges;
mysql> stop slave;
mysql> CHANGE MASTER TO MASTER_HOST='localhost',
MASTER_USER='root',
MASTER_PASSWORD='root',
MASTER_PORT=3307,
MASTER_LOG_FILE='localhost-bin.000002'
MASTER_LOG_POS=79
2.
Copy the data taken from the master onto the slave.

3. Login to slave server as mysql -u root -proot [This is now same as master]
Start the slave server as
mysql> start slave;
mysql> LOAD DATA FROM MASTER;

Now check both master and slave and you will see both servers are in sync.
MySql replication has begun !!!

Linux don't run well on Laptops! Who says :-)

I have successfully installed and configured Fedore Core 10 (Cambridge) on my Dell Inspirion 1525 Laptop without a hiccup.The only thing that annoyed me is that I could not play a single mp3 file in any of dozens of Music Players available on FC10. This is really a frustrating aspects of some modern Linux distros is that they do not come with mp3 support rolled in. May be, it is intentionally done to avoid any licensing issues. Also, granted using the ogg format is a much better solution as well as a much better sounding format but for a user like me who has a massive amount of mp3 files already located on multiple hard drives converting to ogg format would be a very time consuming option. So, I wanted to have the mp3 support on my native laptop itself.Here is the solution I have found.The first command will install the necessary repositories for yum to use.
First issue: rpm -ivh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm
Now it’s time to install the actual plugin for support.
yum -y install gstreamer-plugins-bad gstreamer-plugins-ugly xine-lib-extras-nonfree

Now my system will allow mp3 playback in the major players. But there is still no xmms. To install xmms with mp3 support issue the following command:
yum install xmms xmms-mp3
Once this is finished your machine is all ready for full-blown mp3 playback in just about every type of application!

Monday, June 30, 2008

Alfresco, Is it the OpenSource counterpart to Windows Sharepoint ??

Here’s how to…..
Installing Alfresco on RHEL-5 System

1. Download Information:

Download the binary alfresco-1.2i-linux-community.bin from

http://sourceforge.net/project/showfiles.php?group_id=143373&package_id=157460&release_id=396245

2. Setup permissions:
Assign execute permission on the binary
# chmod u+x alfresco-1.2i-linux-community.bin


3. Installation:
Installation takes place in an interactive fashion thus unless something goes really bad, it won’t

take more than couple of minutes;
Start installing with the help of the following command
# ./alfresco-1.2i-linux-community.bin
(Make sure, your X-server is up and running)
The default installation directory would be under /opt/alfresco-1.2
Note: Alfresco installer comes bundled with Tomcat (Application Server), MySQL database and an

openoffice suite.

4. Gotchas!!! If you have multiple MySQL….
If you already have one MySQL DB running (on default 3306 port) then assign a different port of

MySQL while installing Alfresco.
Also, please move the mysql configuration file that you have under /etc/
to /mysql_install_directory/share/
And at the same time, copy the /opt/alfresco-1.2/mysql/support-files/ my-small.cnf with a name
my.cnf under /opt/alfresco-1.2/mysql/share/my.cnf
Eg.

# cp /opt/alfresco-1.2/mysql/support-files/ my-small.cnf /opt/alfresco-1.2/mysql/share/my.cnf

MySQL Port and Socket files;
Edit the file; /opt/alfresco-1.2/mysql/share/my.cnf and make the following changes as
port = 3307

socket = /opt/alfresco-1.2/mysql/data/mysql.sock
You might need to modify the file
/opt/alfresco-1.2/tomcat/shared/classes/alfresco/extension/custom-repository.properties
And change the port as;
db.url=jdbc:mysql://localhost:3307/${db.name}


5. Start alfresco:
Although after a successful installation, alfresco would start up automatically. You might also

want start and stop the same later on, the scripts for doing that can be found under;
/opt/alfresco-1.2/alf_start.sh
/opt/alfresco-1.2/alf_stop.sh

6.
How to access:
Open a browser and type
http://localhost:8080/alfresco; this should bring up the login page.
(Initial admin credentials are Username: admin, Password: admin)

(I did not try to install it with Tomcat server already installed, if some one tries that do share)

Monday, June 23, 2008

Installing ORACLE 9i on RHEL5

Note: I have installed it successfully on "Red Hat Enterprise Linux Server release 5 (Tikanga)" 32 bit. Please understand; it involves tweaking of Kernel parameters, so take care while you do that.

Steps:
1. Create oracle User AccountLogin as root and create te user oracle which belongs to dba group.$ su - root
# groupadd dba
# useradd -g dba oracle
2. Setting System parameters:Edit the /etc/sysctl.conf with an editor like vi and add following lines:kernel.shmall = 2097152
kernel.shmmax = 536870912
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.file-max = 65536
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default=262144
net.core.wmem_default=262144
net.core.rmem_max=262144
net.core.wmem_max=262144
Note: You need to execute "sysctl -p" to apply the above settings.

3. Setting Oracle EnviromentEdit the /home/oracle/.bash_profile file and add following lines:ORACLE_BASE=/opt/oracle
ORACLE_HOME=$ORACLE_BASE/920
ORACLE_SID=orcl
LD_LIBRARY_PATH=$ORACLE_HOME/lib
ORACLE_OEM_JAVARUNTIME=/opt/jre1.3.1_15
PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_BASE ORACLE_HOME ORACLE_SID LD_LIBRARY_PATH ORACLE_OEM_JAVARUNTIME PATH

Save the .bash_profile and execute following commands to load the new environment:
# cd /home/oracle.

# .bash_profile
4. Create base directory for OracleLogin as root and create base directory for Oracle ($ORACLE_BASE).
$ su - root

# cd /opt
# mkdir oracle
# chown oracle:dba oracle
5. Download and install required .rpm packagessome additional packages may be required for successful installation . To check whether required packages are installed on your operating system use following command:

rpm -q gcc glibc-headers glibc-kernheaders glibc-devel compat-libstdc++ cpp compat-gcc
6. Download the Java Runtime Enviroment (I used j2re-1_3_1_19-linux-i586.bin) from the
Sun website. Login as root, give the file execute permission and then execute it. When the JRE is exracted move the same under the directory "/usr/local" directory.# chmod +x j2re-1_3_1_19-linux-i586.bin

# ./ j2re-1_3_1_19-linux-i586.bin
# mv jre1.3.1_19 /usr/local/
7. Download the Oracle 9i (9.2.0.4) software from
Oracle website. Extract the files using following command:


gunzip ship_9204_linux_disk1.cpio.gz

gunzip ship_9204_linux_disk2.cpio.gz
gunzip ship_9204_linux_disk3.cpio.gz
cpio -idmv "<" ship_9204_linux_disk1.cpio
cpio -idmv "<" ship_9204_linux_disk2.cpio
cpio -idmv "< "ship_9204_linux_disk3.cpio
mv Disk* /home/oracle/
chown –R oracle:dba Disk*

When all archives were extracted you've got three directories Disk1, Disk2 and Disk3.

Edit the Disk1/install/linux/oraparam.ini and modify JRE_LOCATION variable and set path to our JRE installation from Step 6. JRE_LOCATION=/usr/local/jre1.3.1_19 4.

Start the Oracle software installation process. To start the installation process; execute the following commands:

$ cd Disk1
$ ./runInstaller

***************************************************
Errors with solutions:
1. When network configuration assistant and database configuration assistant has failed during startup then do following steps:
Solution:
$ cd /opt/oracle/920
$ rm JRE $ ln -s /usr/local/jre1.3.1_19 JRE
$ su - root
# cd /opt/oracle/920/JRE/bin # ln -s java jre
# cd i386/native_threads
# ln -s java jre
2. If you encounter the following error:
ORACLE_HOME/Apache/Apache/bin/httpd: error while loading shared libraries: libdb.so.2: cannot open shared object file: No such file or directory Solution: Create a symbolic link
$ su - root
# ln -s /usr/lib/libgdbm.so.2.0.0 /usr/lib/libdb.so.2
3. If you encounter something like below at the very beginning of installation:
error while loading shared libraries: libstdc++-libc6.1-1.so.2: cannot open shared object file: No such file or directory
Solution:
$ su - root
# cd /usr/lib
# ln -s libstdc++-3-libc6.2-2-2.10.0.so libstdc++-libc6.1-1.so.2
Now, run the installer again:
$ ./runInstaller
****************************************************
Note: If you encounter any more errors, please post it here










Tuesday, September 18, 2007

Heard about SQL Injection !!!

What is SQL Injection??
SQL Injection is one of the many web attack mechanisms. As a result data from organizations are stolen by Hackers. It is an application layer attack techniques used nowadays. It is the type of attack that takes advantage of falulty coding of web applications that allows hacker to inject SQL commands into say a login form to allow them to gain access to the data held within your database.

SQL Injection is the hacking technique which attempts to pass SQL commands (statements) through a web application for execution by the backend database. If not guarded properly, web applications may result in SQL Injection attacks that allow hackers to view information from the database and/or even wipe it out.

A simple instance;
Take for instance, a simple login page where a valid user would enter his username and password to view his personal details or upload his comments in a forum.
What actually happens When the legitimate user submits his details.... Once the user input data, an SQL query is generated from these details and submitted to the database for verification. If a match is found, the user is allowed access. In other words, the web application that controls the login page will communicate with the database through a series of pre-defined commands so as to verify the username and password combination. On verification, the legitimate user is granted appropriate access.


Through SQL Injection, the hacker may input specifically manipulated SQL commands with the intent of bypassing the login form barrier and seeing what lies behind it. This is only possible if the inputs are not properly sanitised (i.e., made invulnerable) and sent directly with the SQL query to the database. SQL Injection vulnerabilities provide the means for a hacker to communicate directly to the database
The impact of SQL Injection could be of the following;

An attacker may execute arbitrary SQL statements on the vulnerable system. This may compromise the integrity of your database and/or expose sensitive information. Depending on the back-end database in use, SQL injection vulnerabilities may lead to varying levels of data/system access for the attacker. It may also be possible to manipulate existing queries, to UNION (used to select related information from two tables) arbitrary data, use subselects, or append additional queries.
Thus, If an attacker can obtain access to your database, it could spell disaster.

Unfortunately the impact of SQL Injection is only uncovered when the theft is discovered.......