Archive

Posts Tagged ‘linux’

MySQL master master replication on Debian 5 (Lenny)

May 19, 2011 1 comment

This article is about setting up mysql master master replication between two cloud servers. The operating system which I’m going to use is Debian 5 (Lenny) Rackspace cloud base image.

Setup outline:

We will have two cloud servers, named debian501 and debian502 during this exercise. Both servers have two IP addresses(one public, one private). We will configure the replication to be done using the private IP interface so that we don’t incur any bandwidth charges.

Creating the cloud servers:

You need to create two Linux cloud servers, using the Debian 5 image. You can create them by logging into your cloud control panel, and spinning up two cloud servers. Choose the RAM configuration depending on your requirement of the database. Name the server accordingly so that you can easily identify. For my exercise I have named them debian501 and debian502. All the below command I’m running as a root user.

Instaling MySQL:

We need to install mysql on both the debian cloud servers. Before installing MySQL we need to run few extra commands needed for any freshly installed Debian.

Update the package database:

#aptitude update

Install locales:

#aptitude install locales
#dpkg-reconfigure locales

The dpkg-reconfigure locales command will bring up a locales setting window where you can choose the locales for your system depending on your country and region. In my case I have choose “en_GB.UTF-8″.

Now, you can run the following commands to get the MySQL installed:

#aptitude install mysql-server mysql-client libmysqlclient15-dev

Enabling the replication

After this we need to make configuration changes into each of the server to enable replication.

First on debian501 server

We need to create our database which we will setup for replication, and also we need to create a replication username and password. Run the following commands to set it up. Do change all the values as per your needs.

#mysql -u root -p               --> Login to your mysql with password you setup during mysql installation.<br />
mysql>

Open the file /etc/mysql/my.cnf and create/update following entries:

bind-address = 0.0.0.0
server-id = 1
log-bin = /usr/local/mysql/var/bin.log
log-slave-updates
log-bin-index = /usr/local/mysql/var/log-bin.index
log-error = /usr/local/mysql/var/error.log
relay-log = /usr/local/mysql/var/relay.log
relay-log-info-file = /usr/local/mysql/var/relay-log.info
relay-log-index = /usr/local/mysql/var/relay-log.index
auto_increment_increment = 10
auto_increment_offset = 1
master-host = [private IP address of debian502]
master-user = [replication username]
master-password = [replication password
replicate-do-db = [database name to be replicated]

Second on debian502 server

Open the file /etc/mysql/my.cnf and create/update following entries:

bind-address = 0.0.0.0
server-id = 2
log-bin = /usr/local/mysql/var/bin.log
log-slave-updates
log-bin-index = /usr/local/mysql/var/log-bin.index
log-error = /usr/local/mysql/var/error.log
relay-log = /usr/local/mysql/var/relay.log
relay-log-info-file = /usr/local/mysql/var/relay-log.info
relay-log-index = /usr/local/mysql/var/relay-log.index
auto_increment_increment = 10
auto_increment_offset = 2
master-host = [ private IP address of debian501 ]
master-user = [ replication username ]
master-password = [ replication password ]
replicate-do-db = [ database name to be replicated ]

Now, restart both databases. If the service restart on either server fails, then please check the /var/log/mysql/error.log file for any errors, and update the configuration checking for any typos, etc.,

Testing the scenarios:

For the purpose of testing our replication setup, we can create the database specified in the configuration section above (replicate-do-db), as well as a test table on one of the nodes and watch the log files in /var/log/mysql directory. Note that any and all the database changes should be replicated to our other server immediately.

mysql> create database [your-db-name];
mysql> use [your-db-name]
mysql> create table foo (id int not null, username varchar(30) not null);
mysql> insert into foo values (1, 'bar');

An additional test is to stop the MySQL service on debian502, making database changes on the debian501 and then starting the service on debian502 once again. The debian502 MySQL service should sync up all the new changes automatically.

you should also consider changing the default binary log rotation values (expire_logs_days and max_binlog_size) in the /etc/mysql/my.cnf file, as by default all the binary logs will be kept for 10 days. If you have high transaction count in you database and application then it can cause signifient hard disk space usage in logs. So, I would recommend changing those values as per your server backup policies. For example, if you have daily backups setup of your MySQL node then it makes no sense to keep 10 days worth of binary logs.

Good luck!
-Sandeep

Extract pages from a PDF file in Ubuntu 10.10

December 11, 2010 1 comment

Yesterday I got an odd task at hand. One of senior members in my team and really amazing person I must say, e-mailed me few PDFs of Linux Journal from past months, and asked if I could extract the troubleshooting articles from them and compile them as a one single pdf, which we can keep for future references, plus this was needed as he has promised the other team to do this in return of the PDFs he gets from their subscription :)

So, then I begin my search on tools and ways to do this in Ubuntu 10.10.  Yes, for the past 3-4 weeks Ubuntu has been my main operating system, not like earlier when I have always kept one windows machine with me. This time I thought lets move completely to Linux without taking any whatsoever help from windows, and let me tell you its been really going great, even better than windows. But more on this later.

Quick Google search revealed that there are a number of ways to extract a range of pages from PDF files. There are PDF related toolkits for doing it or you can use Ghostscript directly for command line option, and also there are graphic applications as well. So I decided to put them all together here.

First: Use of poppler-tools and psutils.
One can extract a range of pages from a larger PDF file using these tools. Like, if you want to extract pages 18–22 of the PDF file one_big_file.pdf, you could use the following command:

$ pdftops one-big-file.pdf - | psselect -p18-22 | ps2pdf - new-file-name.pdf

The pdftops command converts the PDF file to PostScript and psselect command selects the relevant pages from the PostScript, then ps2pdf command converts the selected PostScript into a new PDF file.

Second:Using pdftk toolkit
For example, to extract pages 18-22 from a big PDF file.

Splitting pages from one big file:
$ pdftk A=one_big_file.pdf cat A18-22 new_file_name.pdf

Joining pages into one big file:
$ pdftk file1.pdf file2.pdf cat output single_big_file.pdf

for more options like attaching files, filling forms, etc., check this link

Third:Using Ghostscript
Use of Ghostscript, which unlike pdftk is installed nearly everywhere and you’ve been using it in the last command anyway, goes like following.

$ gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER \
-dFirstPage=18 -dLastPage=22 \
-sOutputFile=new_file_name.pdf one_big_file.pdf

Merging files with Ghostscript

$ gs -q -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER \
-sOutputFile=one_big_file.pdf file1.pdf file2.pdf file3.pdf

When using Ghostscript to combine PDF files, you can add any PDF-related option to the command line. For example, you can compress the file, target it to an eBook reader, or encrypt it. See the Ghostscript documentation for more information.

Conclusion
Regarding speed and efficiency of the processing and more important the quality of the output file, the first method above is for sure the worst of the three. The conversion of the original PDF to PostScript and back to PDF (known as “refrying”) is very unlikely to completely preserve advanced PDF features (such as transparency information, font hinting, overprinting information, color profiles, trapping instructions, etc.).

The 3rd method uses Ghostscript only (which the 1st one uses anyway, because ps2pdf is nothing more than a wrapper script around a more or less complicated Ghostscript command line. The 3rd method also preserves all the important PDF objects on your pages as they are, without any “roundtrip” conversions.

Little extra
The only drawback of the 3rd method is that it’s a longer and more complicated command line to type. But you can overcome that drawback if you save it as a bash function. Just put these lines in your ~/.bashrc file:

function pdf-extract()
{
# this function uses 3 arguments:
# $1 is the first page of the range to extract
# $2 is the last page of the range to extract
# $3 is the input file
# output file will be named "inputfile_pXX-pYY.pdf"
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER \
-dFirstPage=${1} \
-dLastPage=${2} \
-sOutputFile=${3%.pdf}_page${1}_to_page${2}.pdf \
${3}
}

Now you only need to type (after starting a new copy bash or sourcing .bashrc) the following:
$ pdf-extract 22 36 inputfile.pdf
which will result in the file inputfile_p22-p36.pdf in the same directory as the input file.

For a graphic optionhttp://sourceforge.net/projects/pdfshuffler/

Categories: Linux, Ubuntu 10.10 Tags: , ,

Java runtime environment on fedora 14

November 29, 2010 Leave a comment

The standard installation of Fedora comes with OpenJDK off of Sun Java. However if not, it can be installed using YUM:
yum install java-1.6.0-openjdk java-1.6.0-openjdk-plugin
If you installed OpenJDK, all the ava application and web applets should automatically work. Unfortunately some applets may not run properly and the OpenJDK might have some limitations. Majority of user should find OpenJDK perfect for everyday use.

Installing Sun Java:
Download java from here:
http://www.java.com/en/download/manual.jsp?locale=en&host=www.java.com

Always use the latest update. Select Java JRE 6 Update 18 (the JDK is for developers) On the next page, for Platform select “Linux” for 32-bit users, and “Linux x64″ for 64-bit users. For Language select “Multi-language”. Also accept the license agreement, and hit “Continue”.

On the next page, select the RPM option:
64bit – jre-6u22-linux-x64-rpm.bin
or
32bit – jre-6u22-linux-i586-rpm.bin

Installation:
For 64bit: #sh jre-6u18-linux-i586-rpm.bin
For 32bit: #sh jre-6u18-linux-x64-rpm.bin

You will need to hit ‘space’ till it reaches the end, then type ‘yes’. It should install the RPM files automatically, but if it doesn’t install then you can manually install it using RPM command rpm -ivh

Now, if you run command #java -version, you will see that by default its running java from OpenJDK. In order to use Sun Java, use the alternatives command.

In Fedora you can use alternatives to have multiple versions of java installed on your system and change between then as and when required.

Running the following command(for both 32-bit and 64-bit users):
# /usr/sbin/alternatives --install /usr/bin/java java /usr/java/default/bin/java 20000

Explanation:
alternatives –install
name: is the generic name for the master link.
link: is the name of its sym‐link. (this link will be created by alternatives, so don’t try to look up the path, it won’t be there unless you have run alternatives command earlier)
path: is the alternative being introduced for the master link.
priority: is the priority of the alternatives group. Higher priorities take precendence if no alternative is manually selected.

Setup the Mozilla/Firefox browser plugin.
For 32-bit users:
# /usr/sbin/alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so /usr/java/default/lib/i386/libnpjp2.so 20000
For 64-bit users:
/usr/sbin/alternatives --install /usr/lib64/mozilla/plugins/libjavaplugin.so
libjavaplugin.so.x86_64 /usr/java/default/lib/amd64/libnpjp2.so 20000

Note: don’t try to locate the file libjavaplugin.so in mozilla/plugins directory, it won’t be there by default. Actually, alternatives is going to create a symbolic link with that name in mozilla/plugins directory which will point to configured javaplugin using alternatives. So, just type in the above command as it’s and hit the enter.

You need to restart firefox to see the plugin take effect.

You can run following commands to change between different versions of java as per your needs.

/usr/sbin/alternatives --config java
/usr/sbin/alternatives --config libjavaplugin.so
(or for 64-bit)
/usr/sbin/alternatives --config libjavaplugin.so.x86_64
Above commands will show all the different versions of java available under alternatives control, and which one is default setup, you can change the default settings by using the numbers displayed on screen.

You can use the following command to see current settings for java
/usr/sbin/alternatives --display java and similarly for others. It will display the current default java in use.

Cheers!!

Categories: Linux Tags: , ,
Follow

Get every new post delivered to your Inbox.