Wednesday, 24 October 2012

How to create LVM on HP-UX

HP-UX


  • Create a new LVM
  • Extend an existing LVM

Create a new LVM


         STEPS:

      • Create the Physical Volume
      • Create the Volume Group
      • Create a Logical Volume
      • Create the File System


1.Check the list of devices, look for a new disk. The new devices will have a hardware path, but no device file associated with it  (no /dev/dsk/c*t*d* /dev/rdsk/c*t*d*)

# ioscan - fnkc disk

2.Create the device special file for the new hardware path

# insf

3.Check the list of devices to very the special files have been created

# ioscan -fnkC disk

4.Create the PV

# pvcreate /dev/rdsk/c*t*d*    (use -B to have a PV boot capable)

5.Create the Volume Group directory

# mkdir /dev/vgXX

6.Create the group file

Determine the minor number to use:

# ls -l /dev/*/group | sort +5

Choose the next unused number (0x0X0000)

# mknod /dev/vgXX/group c 64 0x0X0000

7.Create the volume group

# vgcreate -s 16 /dev/vgXX /dev/dsk/cxtxdx /dev/dsk/cxtydx

# vgextend /dev/vgxx /dev/dsk/cxtzdx

8.Create the Logical Volume

Check the space available on the VG

# vgdisplay -v vgXX ( Multiply the "Free PE" by "PE Size (MBytes)" to get spare capacity in MB of the volume group )

create the LV

# lvcreate -L 100 -n LVname /dev/vgXX

check the created LV

# vgdisplay -v LVname 

9.Create the FileSystem

# mkfs -F vxfs -o largefiles /dev/vgXX/LVname

10.Create the Mount Point

# mkdir -p <full path to mountpoint>

11.Set the proper ownership and permissions on the mount point

# chown owner:group /<mount point>
# chmod XXX /<mount point>

12.Mount the File System

Edit /etc/fstab using vi and add the proper entry

/dev/vgXX/LVname  /mountpoint vxfs rw,suid,largefiles 0 2

# mount /mountpoint

Check everything is ok

# bdf

DONE



Extend an existing LVM

          STEPS:
      • Add a disk to VG
      • Extend the LV
      • Extend the FS

1.Any devices that are on the ioscan, but are NOT on the vgdisplay are available for use

To get the list of devices:

# ioscan -fnC disk | sed 1,2d | xargs -n 10 | grep HITACHI

To get the list of disks used in the VG's

# vgdisplay -v | grep  "PV Name"

Compare the two and find unused disks 

2.Add unused disks to VG

# pvcreate /dev/rdsk/unused_cxtxdx

# vgextend /dev/vgxx /dev/dsk/unused_cxtxdx


3.Extend the Logical Volume

# lvextend -L XXXMb /dev/vgXX/LVname

4.Extend File System

First kill all process locking the FS then unmount the FS finally extend the FS and mount again the FS

# fuser -ku /dev/vgXX/LVname
# umount /dev/vgXX/LVname 
# extendfs /mountpoint
# mount /mountpoint


DONE




Monday, 22 October 2012

Install Tomcat 7


CentOS 5.7 - Tomcat 7.0.27 - JDK 7u4


  • Install Java
  • Install Tomcat


1.Download JDK

http://www.oracle.com/technetwork/java/javase/downloads/index.html

jdk-7u4-linux-i586.tar.gz


2.Download Tomcat

http://tomcat.apache.org/index.html

apache-tomcat-7.0.27.tar.gz


3.Install Java

a.create /usr/java

# mkdir  /usr/java

b.extract jdk-7u4-linux-i586.tar.gz in it

# tar xzf jdk-7u4-linux-i586.tar.gz

c.set JAVA_HOME in  ~/.bashrc or ~/.bash_profile

JAVA_HOME=/usr/java/jdk1.7.0_04  
export JAVA_HOME  
PATH=$JAVA_HOME/bin:$PATH  
export PATH  

d.reload .bash_profile

# source .bash_profile


4.Install Tomcat

a.copy tomcat in /usr/share

cp /root/tomcat/apache-tomcat-7.0.27.tar.gz /usr/share

b.extract tomcat

cd /usr/share
tar xzf apache-tomcat-7.0.27.tar.gz


c.Run tomcat with tomcat user

groupadd tomcat
useradd -s /bin/bash -g tomcat tomcat
chown -Rf tomcat.tomcat /usr/share/apache-tomcat-7.0.27/

d.create a startup script

# cd /etc/init.d/

# vi tomcat

---------------------------------------------------------------------
#!/bin/bash  
# description: Tomcat Start Stop Restart  
# processname: tomcat  
# chkconfig: 234 20 80  
JAVA_HOME=/usr/java/jdk1.7.0_04  
export JAVA_HOME  
PATH=$JAVA_HOME/bin:$PATH  
export PATH  
CATALINA_HOME=/usr/share/apache-tomcat-7.0.27  
  
case $1 in  
start)  
/bin/su tomcat $CATALINA_HOME/bin/startup.sh  
;;   
stop)     
/bin/su tomcat $CATALINA_HOME/bin/shutdown.sh  
;;   
restart)  
/bin/su tomcat $CATALINA_HOME/bin/shutdown.sh  
/bin/su tomcat $CATALINA_HOME/bin/startup.sh  
;;   
esac      
exit 0  
---------------------------------------------------

e.Change file permission for execution

# chmod 755 tomcat

f.Configure tomcat to automatically start

# chkconfig --add tomcat  
# chkconfig --level 234 tomcat on 

g.Test the script

# service tomcat start
# service tomcat restart
# service tomcat stop

h.Check the logs

# more /usr/share/apache-tomcat-7.0.27/logs/catalina.out

i.Start tomcat and connect to web

# service tomcat start
# http://yourIPaddress:8080


l.Configure access to Tomcat Manager gui

# vi $CATALINA_HOME/conf/tomcat-users.xml

m.Manage Memory Usage Using JAVA_OPTS : set our inital heap size, Xms, and our maximum heap size, Xmx, to the same value of 128 Mb

# vi Catalina.sh

JAVA_OPTS="-Xms128m -Xmx128m" 


DONE

Install LAMP on CentOS


CentOS 5.7


  • Install Mysql
  • Install Apache with Php

1.Install Mysql Server

# yum install mysql mysql-server

2.Start and Enable Mysql service

# systemctl start mysqld.service
# systemctl enable mysqld.service

Create Mysql password  with  :

# mysqladmin -u root password [your_password_here]

Check the connexion  to the databae server with:

# mysql -h localhost -u root -p

2.Install HTTPD and  PHP

a.Install Apache (httpd)

# yum install httpd php php-common

b.Start  and  enable  httpd  service

# /etc/init.d/httpd start

 ---OR---

# service httpd start

# chkconfig --levels 235 httpd on

3.Check if php works

create a .php test file

# vi /var/www/html/info.php

insert:

<?php
phpinfo();
?>

save and    open browser to check   : http://ip/info.php


DONE

Create MySql replication on CentOS



CentOS 5.7  - Mysql 5.5
  • Install MySql
  • Configure Master and Slave



Install Mysql


1. Remove previously installed MySQL (if applicable)

# yum erase mysql

2. Install additional repos

Navigate to temporary directory

# cd /tmp

Install EPEL repo

# wget http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm

# rpm -Uvh epel-release-5-4.noarch.rpm

Install remi repo

# wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm

# rpm -Uvh remi-release-5.rpm

3. Ensure the repo contains MySQL 5.5

# yum --enablerepo=remi list mysql mysql-server 

4. Install MySQL 5.5

# yum install --enablerepo=remi mysql*

5. Start MySQL and configure to start on boot

# service mysqld start

# chkconfig mysqld on 

6. Run mysql upgrade script

# mysql_upgrade -u root

7. Change Mysql default Password

# mysqladmin -u root password "XXXXX"

8. Check to ensure mysql 5.5 is installed. 

# mysql -uroot -p

SELECT version();


Configure Master and Slave

Master


1. Edit master configuration

# vi /etc/my.cnf

Comment out those lines if present

#skip-networking
#bind-address            = 127.0.0.1
 
Add those lines in [mysqld] section

log-bin = /var/logs/mysql/mysql-bin.log
binlog-do-db=my_database
server-id=1

2. restart MySQL

# service mysqld restart

3. Connect to mysql and create a replication user

mysql -u root -p
Enter password:

GRANT REPLICATION SLAVE ON *.* TO 'slave_user'@'%' IDENTIFIED BY '<some_password>';

FLUSH PRIVILEGES;

Next (still on the MySQL shell) do this:

USE exampledb;
FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;

Write down this information, i will need it later on the slave

 File                        | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+---------------+-------------------+
| mysql-bin.000001 |      107  | employees        |                               |


quit

4. take a backup of db


# mysqldump -u root -p<password> --opt exampledb > exampledb.sql

5. Finally we have to unlock the tables in exampledb:

# mysql -u root -p
Enter password:
UNLOCK TABLES;
quit;


Slave

1. Create db

# mysql -u root -p
Enter password:
CREATE DATABASE exampledb;
quit;

2. Import data from master

mysql -u root -p<password> exampledb < /path/to/exampledb.sql

3. Edit slave config

 # vi /etc/my.cnf

For mysql 5.1
[mysqld]
server-id=2
master-host=192.168.0.100
master-user=slave_user
master-password=secret
master-connect-retry=60
replicate-do-db=exampledb

[mysqld_safe]
relay-log = /var/log/mysql/slave-relay.log
relay-log-index = /var/log/mysql/slave-relay-log.index

For mysql 5.5

[mysqld]
server-id=2
replicate-do-db=exampledb

[mysqld_safe]
relay-log = /var/log/mysql/slave-relay.log
relay-log-index = /var/log/mysql/slave-relay-log.index

4. From mysql shell

$ change master to master_host='192.168.0.11', master_port=3306, master_user='slave_user', master_password='slave_user', master_log_file='mysql-bin.000001', master_log_pos=107, master_connect_retry=10;


START SLAVE;

SHOW SLAVE STATUS \G;


DONE