Archive

Archive for the ‘Linux application Installations’ Category

Custom TLD for local network

November 19, 2013 Leave a comment

 

 

In this post I will mention the steps to setup a TLD ( top level domain ) which can be used in a local network. Even though I have configured dns zones manually, this was the first time I configured a TLD zone(eventhough local one) of my own and it felt really cool after completing the setup 🙂

 

ASSUMPTION:

1) TLD used: “.jackal”
2) Bind version: 9
3) OS: Debian 7 (wheezy)
4) DNS/Nameserver ip: 10.111.44.221

 

SOLUTION:

1) Install bind and required packages,

apt-get install bind9 dnsutils

 

2) Insert the following into file “/etc/bind/named.conf.default-zones”,

zone "jackal." {
        type master;
        file "/etc/bind/db.jackal";
        allow-transfer { any;};
        allow-query { any;};
};

 

3) Verify configuration,

root@dns01:~# named-checkconf 
root@dns01:~#

 

4) Create the zone file for “jackal.” in “/etc/bind/db.jackal”

;
; BIND data file for TLD ".jackal"
;
$TTL	604800
@	IN	SOA	jackal. root.jackal. (
			      2		; Serial
			 604800		; Refresh
			  86400		; Retry
			2419200		; Expire
			 604800 )	; Negative Cache TTL
;
@	  IN	NS	ns1.jackal.
@	  IN	NS	ns2.jackal.
@	  IN	A	10.111.44.221
dns01	  IN 	A	10.111.44.222
apache01  IN	A	10.111.44.223
mysql01   IN	A	10.111.44.224
postfix01 IN	A	10.111.44.225
dovecot01 IN	A 	10.111.44.226
ns1	  IN	A	10.111.44.221
ns2	  IN	A 	10.111.44.221

 

5) And verify the zone file, bind configuration and after that restart bind service.

root@dns01:/etc/bind# named-checkzone jackal. db.jackal 
zone jackal/IN: loaded serial 2
OK
root@dns01:/etc/bind# named-checkconf 
root@dns01:/etc/bind# service bind9 restart
[....] Stopping domain name service...: bind9waiting for pid 2279 to die
. ok 
[ ok ] Starting domain name service...: bind9.
root@dns01:/etc/bind#

 

6) Create a separate directory for storing zone files of domains,

mkdir /etc/bind/zones/

 

7) Use the “initdns.sh” script for creating dns zone entries.
NOTE: We are using TLD’s ending with “.jackal”. Also customize the “initdns.sh” for your own use 😀

root@dns01:/# ./initdns.sh rogerjo.jackal
[*] Created zone file for rogerjo.jackal
[*] Added zone entry for rogerjo.jackal in bind configuration
root@dns01:/# named-checkzone rogerjo.jackal /etc/bind/zones/rogerjo.jackal 
zone rogerjo.jackal/IN: loaded serial 1378789827
OK
root@dns01:/# rndc reload
server reload successful
root@dns01:/#

 

 

 

initdns.sh

#!/bin/bash

if [ $# -ne 1 ];then
	echo "Usage: initdns.sh "
	exit 1
fi

## Domain name
MYDOMAIN=$1
ZONECONFIG="/etc/bind/named.conf.default-zones"

if [ `sed -n '/^zone "'${MYDOMAIN}'."/p' ${ZONECONFIG}|wc -l` -eq 1 ];then
	echo "[ERROR] Entry for ${MYDOMAIN} already exists"
	exit 1
fi

## Nameservers
NAMESERVER1="ns1.jackal"
NAMESERVER2="ns2.jackal"

## Apache and ftp service are running on the same host
APACHE_IP="10.111.44.222"
FTP_IP="10.111.44.222"

##Mail server
SMTP_IP="10.111.44.224"
POP_IMAP_IP="10.111.44.225"

## DB Server
MYSQL_IP="10.111.44.223"

## Create zone file
cat > /etc/bind/zones/${MYDOMAIN} << EOF \$TTL    86400 @       IN      SOA     ns.${MYDOMAIN}. root.${MYDOMAIN}. (                         1378789827      ; Serial                         10800   ; Refresh                         3600    ; Retry                         604800  ; Expire                         10800 ) ; Minimum ${MYDOMAIN}.       IN NS   ${NAMESERVER1}. ${MYDOMAIN}.       IN NS   ${NAMESERVER2}. ${MYDOMAIN}.       IN A    ${APACHE_IP} www.${MYDOMAIN}.   IN CNAME ${MYDOMAIN}. ${MYDOMAIN}.       IN MX  10  mx01.${MYDOMAIN}. ${MYDOMAIN}.       IN MX  10  mx02.${MYDOMAIN}. mx01.${MYDOMAIN}.  IN A	   ${SMTP_IP} mx02.${MYDOMAIN}.  IN A	   ${SMTP_IP} pop.${MYDOMAIN}.   IN A    ${POP_IMAP_IP} imap.${MYDOMAIN}.  IN A    ${POP_IMAP_IP} mysql.${MYDOMAIN}. IN A	   ${MYSQL_IP} ftp.${MYDOMAIN}.   IN A	   ${FTP_IP} EOF echo "[*] Created zone file for ${MYDOMAIN}" ## Create zone entry in bind configuration cat >> ${ZONECONFIG} << EOF

zone "${MYDOMAIN}." {
  	type master;
	file "/etc/bind/zones/${MYDOMAIN}";
};
EOF

echo "[*] Added zone entry for ${MYDOMAIN} in bind configuration"

 

 

 

removedns.sh

#!/bin/bash

if [ $# -ne 1 ];then
	echo "Usage: removedns.sh <domainname>"
	exit 1
fi

## Domain name
DOMAIN=$1

ZONECONFIG="/etc/bind/named.conf.default-zones"

if [ `sed -n '/^zone "'${DOMAIN}'."/p' /etc/bind/named.conf.default-zones|wc -l` -eq 1 ];then
	##Remove entries from dns configuration file
	sed -i -e '/^zone "'${DOMAIN}'."/,/^};/d' ${ZONECONFIG}
	sed -i '$d' ${ZONECONFIG}

	echo "[*] Removed zone entries from bind configuration"
else
	echo "[ERROR] ${DOMAIN} not present in bind configuration"
	exit 1
fi

#Remove zone file if it exists
if [ -f /etc/bind/zones/${DOMAIN} ];then
	rm -f /etc/bind/zones/${DOMAIN}
	echo "[*] Removed zone db file"
fi

Sync svn repo commits to website documentroot in Cpanel Server

June 8, 2013 Leave a comment

 

SITUATION: Customer has a cpanel server with one domain hosted on a shared ip and wants to setup svn repository for this domain in such a way that whenever the svn commit operation takes place, the contents of the repository is exported to the documentroot. Thus all updates to files inside documentroot can be done over svn instead of via ftp. Also use ‘svnserve’ daemon for setup and don’t use ‘mod_dav’.

 

ASSUMPTIONS:
1) Cpanel Server is used.
2) Domain is setup on a shared ip
3) Suphp is the php handler used
4) ‘username’ is the username of the website

 

SOLUTION:

1) Install subversion in cpanel server

yum install subversion.x86_64 -y

2) Create a directory named ‘repos’ inside the default documentroot of apache(ie, /usr/local/apache/htdocs/) and start the ‘svnserve’ daemon from that directory. Also make sure that the port 3690 is opened in firewall and you are starting the service as root user.

mkdir /usr/local/apache/htdocs/repos
svnserve -d -r /usr/local/apache/htdocs/repos

3) Create a repository named ‘username’ and import its home directory(/home/username/public_html) to the repository,

cd /usr/local/apache/htdocs/repos
svnadmin create username
cd ~
svn import /home/username/public_html file:///usr/local/apache/htdocs/repos/username -m "username"

4) Now open up the svn repository configuration file “/usr/local/apache/htdocs/repos/username/conf/svnserve.conf” and disable anonymous access and specify the user authentication and authorization files,

[general]
anon-access = none
auth-access = write

password-db = /usr/local/apache/htdocs/repos/username/conf/passwd
authz-db = /usr/local/apache/htdocs/repos/username/conf/authz
realm = Project
logfile = /tmp/svn.log

5) Create a new user in user database file “/usr/local/apache/htdocs/repos/username/conf/passwd”

[users]
jackal777 = pnity29#@I

6) Set authorization for user created in password file via “/usr/local/apache/htdocs/repos/username/conf/authz”

[/]
jackal777 = rw

7) Now finally create post commit hook inside the repository directory “/usr/local/apache/htdocs/repos/username/hooks/post-commit” and set execute permission for that file. Paste the following contents to that file,

#!/bin/bash
svn export --force file:///usr/local/apache/htdocs/repos/username/ /home/username/public_html/
chown -R username:username /home/username/public_html/

The post commit script will export the contents of the repository to the website documentroot and assigns the proper permission to the directory.

 

TESTING:

 

Now checkout the repository to your local directory,

svn co svn://37.71.13.54/username --username=jackal777

Make modifications with the files and then commit to the repository,

cd username
svn commit

Now login to the server and check whether the commit made to repository are shown inside “/home/username/public_html”.

That’s it 🙂

Apache proxy redirect

June 7, 2013 1 comment

SITUATION: Customer has a single website with four different web applications installed under four sub directories of the website. Now configure apache to serve all these four applications from four different ports.

ASSUMPTIONS:

1) OS – Ubuntu 11

2) Website name and documentroot,

Name: jackal777.com

DocumentRoot:  /home/jackal/public_html

3) Web application sub-directories and the ports going to be used,

/home/jackal/public_html/app1 : Port 7001
/home/jackal/public_html/app2 : Port 7002
/home/jackal/public_html/app3 : Port 7003
/home/jackal/public_html/app4 : Port 7004

4) Apache mod_proxy module is installed. You can install it using,

apt-get install libapache2-mod-proxy-html -y

SOLUTION:

1) Open up /etc/apache2/ports.conf and add the following directives,

Listen 80
Listen 127.0.0.1:7001
Listen 127.0.0.1:7002
Listen 127.0.0.1:7003
Listen 127.0.0.1:7004

2) Enable mod_proxy by copying the configuratons from ‘mods-available’ directory to ‘mods-enabled’

cp -pr /etc/apache2/mods-available/*proxy* /etc/apache2/mods-enabled/

3) Create a virtualhost file “/etc/apache2/sites-enabled/jackal777.com” for website with the following contents,

<VirtualHost *:80>
ServerName jackal777.com
DocumentRoot /home/jackal/public_html

ProxyPass /app1/ http://127.0.0.1:7001/
ProxyPass /app2/ http://127.0.0.1:7002/
ProxyPass /app3/ http://127.0.0.1:7003/
ProxyPass /app4/ http://127.0.0.1:7004/

</VirtualHost>

<VirtualHost 127.0.0.1:7001>
DocumentRoot /home/jackal/public_html/app1
</VirtualHost>

<VirtualHost 127.0.0.1:7002>
DocumentRoot /home/jackal/public_html/app2
</VirtualHost>

<VirtualHost 127.0.0.1:7003>
DocumentRoot /home/jackal/public_html/app3
</VirtualHost>

<VirtualHost 127.0.0.1:7004>
DocumentRoot /home/jackal/public_html/app4
</VirtualHost>

4) Test configuration and gracefully restart apache.

apache2ctl -t
apache2ctl -k graceful

5) Now access the url’s,

http://jackal777.com/app1/
http://jackal777.com/app2/
http://jackal777.com/app3/
http://jackal777.com/app4/

 

SCOPE: Using mod_proxy, we could forward requests coming to different servers and make the applications running from several different servers.

 

Hope this info will be somewhat useful 🙂

Installing JBoss AS 7.0 on Centos 5

August 22, 2012 Leave a comment

 

 

TASK: Install JBoss AS 7.0 on Centos 5

 

Dependencies: JBoss AS 7.0 requires Oracle java >= 1.6.0 and Maven >= 3.0.0

 

Steps:

 

1) Download Oracle Java and Maven for your system architecture,

 

cd /opt
lynx "http://download.oracle.com/otn-pub/java/jdk/7u6-b24/jdk-7u6-linux-x64.tar.gz?AuthParam=1345589629_a56cd35fc7c36d655693a50d06acb57f"
tar xzf jdk-7u6-linux-x64.tar.gz
mv jdk1.7.0_06 /usr/lib/java-1.7.0_06
wget http://apache.techartifact.com/mirror/maven/binaries/apache-maven-3.0.4-bin.tar.gz
tar xzf apache-maven-3.0.4-bin.tar.gz
cd apache-maven-3.0.4

 

 

2) Add the required environment variables in your /etc/profile system file at the bottom,

 

M2_HOME=/opt/apache-maven-3.0.4
JAVA_HOME=/usr/lib/java-1.7.0_06
PATH=${JAVA_HOME}/bin:${M2_HOME}/bin:${PATH}
export M2_HOME JAVA_HOME PATH

 

After adding the above run the command,

source /etc/profile

 

3) Download JBoss AS 7.0 and change the local host ip address in the configuration to your public ip and start JBoss,

 

lynx "http://download.jboss.org/jbossas/7.0/jboss-as-7.0.2.Final/jboss-as-web-7.0.2.Final.tar.gz"
tar xzf jboss-as-web-7.0.2.Final.tar.gz
replace "127.0.0.1" "68.44.59.12" -- jboss-as-web-7.0.2.Final/standalone/configuration/standalone.xml
./jboss-as-web-7.0.2.Final/bin/standalone.sh

 

After this you can access JBoss via url http://<Your server IP>:8080/”

 

 

Ref: https://docs.jboss.org/author/display/AS7/Installing+and+starting+JBoss+AS+on+Linux,+Unix+or+Mac+OS+X