Offsite LDAP server setup

To configure your offsite running LDAP server, you should have below prerequisites.
- Both Master and slave server running with the same slapd.conf file.
- Password less authentication configured to log in from Master server to slave server.

Slave server's IP address: 192.168.19.20

Run below shell script on Master server.

#!/bin/sh

#Below command will export from Master server
/usr/sbin/slapcat -f /etc/openldap/slapd.conf > /ldapbackup/ldap-` date +%d-%m-%Y`.ldif

###############Backup Restoration on LDAP Backup/slave server#########################

#Below command will stop LDAP service on Slave server
ssh root@192.168.19.20 "/etc/init.d/ldap stop"

#This command will remove LDAP schema directory from the server
ssh root@192.168.19.20 "rm -rf /var/lib/ldap/domain.com/"

#This command will create schema directory on Slave server
ssh root@192.168.19.20 "mkdir -p /var/lib/ldap/domain.com/"

#This command will set ldap as owner of Schema directory
ssh root@192.168.19.20 "chown -R ldap.ldap /var/lib/ldap/domain.com/"

#This command will copy backup from Master server to Slave server on /root/ldapback_letest.ldif location
scp /ldapbackup/ldap-` date +%d-%m-%Y`.ldif root@192.168.19.20:/root/ldapback_letest.ldif

#This command will start LDAP service on Slave server
ssh root@192.168.19.20 "/etc/init.d/ldap start"

#This command will stop LDAP service on Slave server
ssh root@192.168.19.20 "/etc/init.d/ldap stop"

#This command will restore LDAP backfile on Slave server
ssh root@192.168.19.20 "slapadd -v -c -l /root/ldapback_letest.ldif -f /etc/openldap/slapd.conf"

#This command will start LDAP on Slave server
ssh root@192.168.19.20 "/etc/init.d/ldap start"

MSSQL backup Script retaining 3 days backup

I was looking for a script, which takes backup of MS SQL databases and store it some location. The retention period should be 3 days. I googled and found script. Run below steps if you have such requirement.

First we will create a script which will search files older than 3 days and delete them. So copy/paste below script content into "DeletesOlderThan.js" file.

Please note: this file will delete content of the current directory, so before using this file need to go to particular folder which data needs to be deleted.

To invoke this file, run following command. (Here 3 is the #day. This command will delete files older than 3 days)

wscript "e:\DeletesOlderThan.js" 3



////////////////////////////////////////////////////////
// Deletes file older than a number of days
// in the current directory
////////////////////////////////////////////////////////
// Usage: wscript DeleteOlderThan.js [#Days]
// By default, remove files older than 30 days
////////////////////////////////////////////////////////

function removeDays(date, nDays)
{
var dateRet = date
return dateRet.setDate(date.getDate() - nDays);
}

function addSlash(strPath)
{
var c = strPath.substr(-1, 1);
if( c !== '\\' && c !== '/' )
{
strPath += '\\';
}
return strPath;
}

// Read arguments
var nDays = WScript.Arguments(0) || 30;

// Create system objects
var fs = WScript.CreateObject("Scripting.FileSystemObject");
var shell = WScript.CreateObject("WScript.Shell");

// Retrieve current directory
var strDirectoryPath = addSlash(shell.CurrentDirectory);

// Compute date
var dateNow = new Date();
var dateTest = removeDays(dateNow, nDays);

// Iterate on files
var folder = fs.GetFolder(strDirectoryPath);
var files = folder.Files;

for( var it = new Enumerator(files); !it.atEnd(); it.moveNext() )
{
var file = it.item();

if( file.DateLastModified < dateTest)
{
file.Delete(true);
}
}



For MS SQL db backup, I am just taking its data and log file backup. So below command will be enough I guess. (In below command I am taking backup of "mydb" database. I have installed 7zip to compress backup).

 

"C:\Program Files\7-Zip\7z.exe" a -tzip e:\Backup\mydb-%V_Day%-%V_Month%-%V_Year%.zip "C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\mydb.mdf" "C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\mydb.ldf"

I hope this will be helpful.

Set JAVA memory parameters in Tomcat

Edit catalina.sh file and add following line. Memory parameters can be set according to requirement.

export JAVA_OPTS="$JAVA_OPTS -server -Xss128k -Xms128M -Xmx1024M -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:MaxPermSize=512M"

If you are running windows XP and having issue while running tomcat. Append the below line in setenv.bat file.
set JAVA_OPTS=%JAVA_OPTS% -Xms256m -Xmx512m -XX:MaxPermSize=256m

Password less authentication from Windows to Linux


This is the most common requirement, I have ever needed. I hope this will help other as well.
Basically here, I am going to show you steps for connecting Linux machine from windows using putty. This is key based authetication not with password.
So first login into linux machine and run below command.

[demouser@ip-10-36-100-23 ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/demouser/.ssh/id_rsa):
Created directory '/home/demouser/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/demouser/.ssh/id_rsa.
Your public key has been saved in /home/demouser/.ssh/id_rsa.pub.
The key fingerprint is:
6f:e1:0d:97:fb:82:b0:2c:48:fc:e4:50:1b:a1:7c:70 demouser@ip-10-36-100-23
[demouser@ip-10-36-100-23 ~]$ 

Now go to .ssh directory and add id_rsa.pub content into authorized_keys file.
[demouser@ip-10-36-100-23 .ssh]$ cd .ssh
[demouser@ip-10-36-100-23 .ssh]$ cat id_rsa.pub >> authorized_keys

Now change permission of all files in /home/demouser/.ssh directory.
[demouser@ip-10-36-100-23 .ssh]$ chmod 600 *

Now copy content of "id_rsa" file and paste it in notepad and save it with demouser.ppk in windows. Now download "puttygen". Open Puttygen and click on Load button, load demouser.ppk file. and click on "Save Private Key". Do not give any password to protect private key. Save the new key.

You can utilize that new key to login into linux server using putty without password based authentication.

Installing Java on Windows

How to install Java JDK in windows XP and set up Java_home Environment and Java Path



Java is a programming language that allows programs to be written that can then be run on more than one type of operating system. A program written in Java can run on Windows, UNIX, Linux etc. as long as there is a Java runtime environment installed.This tutorial will show how to install Java and set up Java Environment in windows XP.

1. Download Java: The very first thing to do is download the Java Developer's Kit (jdk) onto your computer. Go to this download link to downalod the latest version of JDK.

2. Install Java: Double click on the file you just download. The installer will guide you through the installation. You should install java in either C:/java or C:/ program files/Java. Make sure you remeber where you install it, we are gonna need it. For this tutorial, lets assume, we are installing java in C:\Program Files\Java

3. Set up JAVA_HOME environment variables: 

  1. Right click on the My Computer icon from start menu and select properties

  2. Click the Advanced Tab

  3. Click the Environment Variables button

  4. Under System Variable, click New

  5. Enter the variable name as JAVA_HOME

  6. Enter the variable value as the install path for the Development Kit (C:\Program Files\Java\jdk1.5.0_14\)

  7. Click OK

  8. Click Apply Changes



4.Set Up Java Path:

  1. Follow the first three steps from 3. set up java environment to go to the Environment Variable window.

  2. In the system Variables, find "Path" (they are odered alphabetically so keep scrolling until you reach P). Select it and click edit.

  3. Now, add this" %JAVA_HOME%\bin; " add the end of the variable value with the quotes "" and with the semicolon ; . For example, if the variable value already had %SystemRoot%;%SystemRoot%\system32;...you just add %JAVA_HOME%\bin; with it making the whole variable value %SystemRoot%;%SystemRoot%\system32;%JAVA_HOME%\bin;

  4. Click Ok and Apply changes.


 

5. Test: To test that you have correctly installed java go to Start>Run>type cmd to open command prompt.
Then, type
C:\Users\username>java -version
C:\Users\username>javac -version

Successful installation of java should show appropriate information.


6. Done!!!!!
If you have any  question or problem regarding how to install Java and set up Java_home Environment and Java Path in windows XP, ask me in the comment ...
If you want to install it on Linux platform, follow below link.

http://alpeshbhavsar.wordpress.com/2010/06/14/installing-java-in-linux/

MySQL Error : Can't get hostname for your address

When try to connect remote MySQL Sever 5.5 then it generate an error message 'Can't get host name for your address'. I don't know the exact reason for this error, but in my assumption MySQL Server can't resolve the host IP/name which we pass to server for establishing connection.To solve this issue, just add 'skip-name-resolve '  in my.ini /my.cnf under [mysqld] and restart the server. In windows this file location is

C:\Program Files\MySQL\MySQL Server 5.5\my.ini

[mysqld]
skip-name-resolve

Alfresco Clustering

Scenario: 
Alfresco Version: Alfresco Enterprise 3.1
OS: Centos 5.5
Alfresco installation directory: /opt/alfresco
node1 IP: 10.165.22.11
node2 IP: 10.165.22.12

We have two nodes (node1 and node2). We are here going to use alf_data and db of node1 in all cluster nodes
(node1 and node2). alf_data will be shared through nfs and in Database we have allowed access for both the
nodes to connect.

To configure cluster perform following steps.

On node 1:
Step1 : First share alf_data directory through nfs
open /etc/export file and add following line in it.
/opt/alfresco/alf_data 10.165.22.12(rw,no_root_squash,async)

then restart nfs service.
/etc/init.d/nfs restart

Step2 : Create DB and grant permission for both nodes to connect. Run following queries on mysql.
create database alfresco default character set utf8 collate utf8_bin;
grant all on alfresco.* to 'alfresco'@'localhost' identified by 'alfresco' with grant option;
grant all on alfresco.* to 'alfresco'@'localhost.localdomain' identified by 'alfresco' with grant option;
grant all on alfresco.* to 'alfresco'@'10.165.22.12' identified by 'alfresco' with grant option;
grant all on alfresco.* to 'alfresco'@'10.165.22.11' identified by 'alfresco' with grant option;

Step3 : Now create directory for dir.index and dir.index.backup
mkdir -p /opt/alfresco/alf_data.index
mkdir -p /opt/alfresco/alf_data.index_backup/

Step4 : now edit /opt/alfresco/tomcat/shared/classes/alfresco/extension/custom-repository.properties file and
change following things.
dir.root=/opt/alfresco/alf_data/
dir.indexes=/opt/alfresco/alf_data.index
dir.indexes.backup=/opt/alfresco/alf_data.index_backup
alfresco.cluster.name=testcluster
index.recovery.mode=AUTO
db.username=alfresco
db.password=alfresco

disable derby connection, putting comments in front of below two lines.
#db.driver=org.apache.derby.jdbc.EmbeddedDriver
#db.url=jdbc:derby:alf_data/derby_data/alfresco;create=true

Enable mysql connection, by removing comments in front of these two lines.
db.driver=org.gjt.mm.mysql.Driver
db.url=jdbc:mysql://10.165.22.11/alfresco

Step4 : Now create ehcache-custom.xml file. Run following command.
cp /opt/alfresco/tomcat/shared/classes/alfresco/extension/ehcache-custom.xml.sample.cluster
/opt/alfresco/tomcat/shared/classes/alfresco/extension/ehcache-custom.xml

On node2:

Step1 : First mount alf_data directory through below procedure.
Do entry in /etc/fstab file to access shared directory of node1. Save the file and exit.
10.165.22.11:/opt/alfresco/alf_data /opt/alfresco/alf_data nfs rsize=8192,wsize=8192,timeo=14,intr

Now mount alf_data directory through below command.
mount /opt/alfresco/alf_data

Step2 : Now create directory for dir.index and dir.index.backup
mkdir -p /opt/alfresco/alf_data.index
mkdir -p /opt/alfresco/alf_data.index_backup/

Step3 : Now copy custom-repository.properties and ehcache-custom.xml files from node 1 and paste in
/opt/alfresco/tomcat/shared/classes/alfresco/extension/ directory.

Now start the alfresco on both nodes and do testing.

checking for SSL headers... configure: error: Cannot find ssl headers

checking for SSL headers... configure: error: Cannot find ssl headers

If you get the following error while installing nrpe.

Solution:

Install libssl-dev

sudo apt-get install libssl-dev

After install things work well.


*** Generating DH Parameters for SSL/TLS ***
Generating DH parameters, 512 bit long safe prime, generator 2
This is going to take a long time
checking for Kerberos include files... could not find include files
checking for perl... /usr/bin/perl
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating subst
config.status: creating include/config.h


*** Configuration summary for nrpe 2.12 03-10-2008 ***:

General Options:
-------------------------
NRPE port: 5666
NRPE user: nagios
NRPE group: nagios
Nagios user: nagios
Nagios group: nagios

Review the options above for accuracy. If they look okay,
type 'make all' to compile the NRPE daemon and client.

 

Subversion Error - svn: Could not use external editor to fetch log messages

When I was installing Subversion on CentOS 5.3 x86_64 and when I tried to do a "svn commit". The error was
"svn: Could not use external editor to fetch log message; consider putting the $SVN_EDITOR environment variable or using the --message......."
"svn: None of the environment variables SVN_EDITOR, VISUAL or EDITOR is set..............." 

To solve the issue
You have to input the environment variables in your .bash_profile in your home directory
# vim .bash_profile
--------------------------------------
export SVN_EDITOR=/usr/bin/vim
--------------------------------------
# source .bash_profile

Monitor JAVA through Jconsole remotely

Here we are going to monitor Java process running on linux server from the windows machine with Jconsole.

On linux in catalina.sh file add following line and restart tomcat.

export CATALINA_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8999 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=192.168.10.23"

Here 192.168.10.23 is the IP of the linux machine.

 

Now in Jconsole in Remote Process: 192.168.10.23:8999 This will allow you to connect to 8999 port on linux.