Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Thursday, September 10, 2015

How to install Maven on CentOS

Steps to install and configure Maven on CentOS

  • Download the tar.gz file from Apache Maven site
  • Untar the file at some location (Eg: /opt/maven)
    • tar xzf <filename>
  • Add the environment variable to ~/.bash_profile file
    • cd $HOME
    • vi ~/.bash_profile
      • Append PATH variable with maven path
      • Add M2_HOME variable
      • export M2_HOME
    • Save and restart your system


  • Verify maven installation
    • mvn --version

How to install and configure Apache Tomcat 7 on Cent OS

Here are the steps to install and configure Apache Tomcat 7 on Cent OS :



  • Stop the tomcat
    • sh /opt/tomcat7/bin/shutdown.sh

  • [Optional] To access admin|manager pages, you need to create user accounts. Add below lines inside <tomcat-users></tomcat-users> tags in ${tomcat7}/conf/tomcat-users.xml file.
    <role rolename="manager-gui"/>
      <user username="manager" password="root123" roles="manager-gui"/>
      <role rolename="admin-gui"/>
      <user username="admin" password="root123" roles="manager-gui,admin-gui"/>




How to install and Configure Apache Http Server on Cent OS

Here are the steps to install and configure Apache WebServer on Cent OS :
  • Install Apache HTTP Server (By default Cent OS comes with Apache)
    • yum install httpd
  • Set to Chkconfig to start on boot
    • chkconfig --level 235 httpd on
  • Uncomment below line from configuration(/etc/httpd/conf/httpd.conf) file
    • NameVirtualHost *:80
  • Restart Apache Http Server
    • service httpd restart
  • Verify Apache Server
    • Goto your browser and check localhost or localhost.localdomain It will display Apache Test Page



How to install and configure MySQL on Cent OS

Here are the steps to install and configure MySQL on Cent OS :
  • Install MySql Server
    • yum install mysql-server mysql php-mysql
  • Set to Chkconfig to start on boot
    • chkconfig –level 235 mysqld on
  • Start the MySQL service
    • service mysqld start
  • Set the password for all domains
    • myql -u root
    • SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new-password');
    • SET PASSWORD FOR 'root'@'localhost.localdomain' = PASSWORD('new-password');
    • SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('new-password');
  • Exit and verify the MySQL version
    • exit
    • mysql --version
      • mysql Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1




Friday, May 29, 2015

How to install SVN Client on CENT OS 6

It is quite easy to install SVN Client using YUM command line manage utility on CENT OS 6.

Install :

# yum clean all
# yum install subversion

Verify Subversion

# svn --version

Thanks..!!!

Tuesday, December 9, 2014

How to extract a JSON value from a BASH script



Requirement : I was working on shell script where I need to get Id value from JSON and I tried so many thing but unable to get it without using any other tools. So, After trying so many failure attempt, I end up with this site (A big thanks to you) which resolved my issue.


Here is how I fetched value from JSON,


JSON = <YOUR_JSON>
PROPERTY_TO_FETCH="<VALUE>" (In my case, it was "id")

ID = `echo $JSON| sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w $PROPERTY_TO_FETCH`

echo ${ID ##*|}


Which will print the value of 'id' from JSON.

Tuesday, March 18, 2014

How to set permanent IP in Ubuntu ?

Steps :

*) Open the interfaces file :
          sudo vi /etc/network/interfaces

If you are using DHCP you will see the following lines :
          auth eth0
          iface eth0 inet dhcp 


*) To make it static, Change the line iface eth0 inet dhcp to iface eth0 inet static and add the following just below it:

address 10.35.34.209 (IP address that you need to set)
netmask 255.255.255.0 (Default mask which in this case is the default class c subnet)
gateway 10.35.34.1 (Typically your router’s IP address)
network 10.35.34.0 (The network that this machine is running on)
broadcast 10.35.34.255

Here is a screenshot of how it should look below :


*) Once you save this file you need to restart your networking service.
       sudo /etc/init.d/networking restart
or
       sudo service networking restart

Note :
 /etc/init.d/networking restart command is deprecated on new debian and ubuntu, So in such case you can use :
            ifdown eth0 && ifup eth0

Thursday, March 7, 2013

What is RPM and How to build your RPM?

Introduction

RPM (RPM Package Manager) is a popular utility for installing software on Unix-like systems, particularly Red Hat Linux. The name RPM variously refers to the .rpm file format.
It is an open packaging system available for anyone to use. It allows users to take source code for new software and package it into source and binary form such that binaries can be easily installed and tracked and source can be rebuilt easily. It also maintains a database of all packages and their files that can be used for verifying packages and querying for information about files and/or packages.

Design Goals

RPM provides the capability to install an entire application with a single command, to track the files it put on the system, and to remove those files by using another single command.
  • Make it easy to get packages on and off the system.
  • Make it easy to verify a package was installed correctly.
  • Make it easy for the package builder.
  • Make it start with original source code.
  • Make it work on different computer architecture

Terminology

RPM packages are provided as compressed archive files that contain one or more files, as well as instructions specifying installation information about those files, including the ownerships and permissions that should be applied to each file during installation.
The instructions can also contain scripts to be run after installation or before uninstallation. These package files are extremely convenient, they provide a single file that can be easily transferred between machines for installation rather than having to transfer each file to be installed. To help in installation and management, all package files are labeled with highly identifiable names.
Package files have four-part names, which typically look something like:
mxlcloudsso.2.4.18-3.noarch.rpm
The four parts of each name are separated from each other by dashes or periods. The structure of the package file name is
name-version-release.architecture.rpm where
name - > name of an application or package that the archive installs on the system version → version number of the software that is contained in the package file release → release of that version of the software the package file contains architecture → architecture identifies the system types for which the package file is appropriate

Building RPMs

When building RPMs, go through the following steps:
  • Set up the directory structure.
  • Place the sources in the right directory.
  • Create a spec file that tells the rpmbuild command what to do.
  • Build the source and binary RPMs.

The following sections provide details for these steps.

Setting up the directory structure

RPM requires a set of directories (as listed in below Table)in which to perform the build. While the directories locations and names can be changed, unless there's a reason to do so, it's best to use the default layout. Note that if you've installed RPM, the build directories are most likely in place already.

RPM directories

Directory
Usage
BUILD
The directory in which the sources are unpacked, and the software is built.
RPMS
Contains the binary package files created by the build process.
SOURCES
Contains the original sources, patches, and icon files.
SPECS
Contains the spec files used to control the build process.
SRPMS
Contains the source package files created by the build process.

The RPMS directory usually has a number of architecture-specific subdirectories, such as the following (on an Intel architecture system):
athlon, i386, i486, i586, i686, noarch.

By default, Red Hat Linux systems expect RPMs to be built in the /usr/src/redhat directory.

Warning:
Do not build RPMs while logged in as root as root can alter any file on the system. Mistakes in building packages can have serious consequences if you are logged in as root.

To build RPMs, At a minimum you need only two things:
  • source code in the SOURCES directory
  • spec file in the SPECS directory

 Placing your sources into the directory structure

The first thing we need to do in order to build a package is to place all the source file directly in the /usr/src/redhat/SOURCES directory. It will be easier if you create a tarball of the source you want to build and then place in the SOURCES directory.
The convention for these tarball files is package-version.tar.gz. For example:
myfile-1.17.tar.gz

Creating the spec file

The spec file is nothing more than a text file with a special syntax and having extension .spec. It defines all the actions the rpmbuild command should take to build your application, as well as all the actions necessary for the rpm command to install and remove the application.
The normal naming convention is to name the file with the package name and a .spec filename extension.
The following sections describe these spec file sections and the necessary syntax in each section.

Introduction section

The introduction section contains information about the package, the type of information.
Example :
  • Summary : This is a one line description of the package.
  • Name: This must be the name string from the rpm filename you plan to use.
  • Version : This must be the version string from the rpm filename you plan to use.
  • Release : This is the release number for a package of the same version.
  • Copyright : This line tells how a package is copyrighted.
  • Group : This is a group that the package belongs to in a higher level package tool or the Red Hat installer.
  • Buildroot : This line allows you to specify a directory as the "root" for building and installing the new package.
  • %description: This is a multi−line field that should be used to give a comprehensive description of the package.

 

prep section

This is the second section in the spec file. It is short for prepare, defines the commands necessary to prepare for the build. If you are starting with a compressed tar archive (a tarball) of the sources, the prep section needs to extract the sources. The prep section starts with a %prep statement.
For example:
%prep
%setup -q


build section

The build section contains the commands to build the software. Any sh commands can go here. It starts with a %build statement.
Example:
%build
./configure CXXFLAGS=-O3 --prefix=$RPM_BUILD_ROOT/usr
make

Install section

The install section holds the commands necessary to install the newly built application or library. In most cases, your install section should clean out the Buildroot directory and run the make install command. The install section starts with an %install statement.
Example:
%install
rm -fr $RPM_BUILD_ROOT
make install

Clean section

The clean section cleans up the files that the commands in the other sections create, It starts with a %clean statement. %clean
rm -rf $RPM_BUILD_ROOT


Files section The files section lists the files to go into the binary RPM, along with the defined file attributes. It starts with a %files statement
Example:
%files
%defattr(-,root,root)

Sample

While working on one of my project, Once there was a requirement where I have to deploy the tomcat, place the war into the tomcat at the appropriate directory and also start the tomcat on the client machine using rpm.
To achieve above task, I went through the following steps;
  1. Created RPM build directory structure.
  2. Placed our tar file into SOURCE directory.
  3. Spec file into SPEC directory
I have uploaded the rpm structure on the https://github.com/abdulwaheed18/redhat with spec file and tar file. You can refer it for better understanding.
Note : For security purpose, while creating tar I have removed the war file. So to make it working,
Download the tar file from SOURCES, untar it and then add your war file with name “mxlcloudsso.war” and tar it again and place into SOURCES directory.


To build the rpm :
rpmbuild -ba $redhat/SPECS/mxl_installer.spec
The rpm file will get created under $redhat/RPMS/noarch directory structure.


To install the package:
rpm -i mfe-cloudsso-sl-installer-1.0.0-1.noarch.rpm
It will install the tomcat on your machine, deploy your war file in tomcat ,start the tomcat.


To remove the package:
rpm -e mfe-cloudsso-sl-installer
Note : To remove the rpm, We just need the package name.

Useful command :

To build RPMs with the rpmbuild command, use the following basic syntax:
rpmbuild -bBuildStage spec_file
The -b option tells rpmbuild to build an RPM. The extra BuildStage option is a special code that tells the rpmbuild command



Option
Usage
-ba
Build all, both a binary and source RPM
-bb
Build a binary RPM
-bc
Build (compile) the program but do not make the full RPM, stopping just after the %build section
-bp
Prepare for building a binary RPM, and stop just after the %prep section.
-bi
Create a binary RPM and stop just after the %install section
-bl
Check the listing of files for the RPM and generate errors if
the buildroot is missing any of the files to be installed
-bs
Build a source RPM only


References:

http://fedoraproject.org/wiki/How_to_create_an_RPM_package
http://www.ibm.com/developerworks/library/l-rpm1/







Monday, July 23, 2012

chkconfig Command Examples

chkconfig command is used to setup, view, or change services that are configured to start automatically during the system startup.

chkconfig has five distinct functions: adding new services for management, removing services from management, listing the current startup information for services, changing the startup information for services, and checking the startup state of a particular service.

chkconfig --list [name]
chkconfig --add name
chkconfig --del name
chkconfig [--level levels] name <on|off|reset>
chkconfig [--level levels] name 

OPTIONS

--level levels
Specifies the run levels an operation should pertain to. It is given as a string of numbers from 0 to 7. For example, --level 35 specifies runlevels 3 and 5.
--add name
This option adds a new service for management by chkconfig.
--del name
The service is removed from chkconfig management.
--list name
This option lists all of the services which chkconfig knows about, and whether they are stopped or started in each runlevel. If name is specified, information in only display about service name
 
Example : 

1 .  How to add any scripts in the chkconfig ?

You have to modify the script a little bit to make it work at boot time. Just add the following lines at the beginning of the file

#!/bin/sh
#chkconfig: 2345 80 30 
#description: Service Description


This says that the random script should be started in levels 2, 3, 4, and 5, that its start priority should be 80, and that its stop priority should be 30. You should be able to figure out what the description says; the \ causes the line to be continued. The extra space in front of the line is ignore
Note : There is no space in between '#' and 'chkconfig'.

2.  Copy your scripts into init.d folder.
    copy the scripts file to /etc/init.d.

3. How to add service to the startup

   chkconfig --add service_name

4. How to view status of startup services
     chkconfig --list
     To view particular service : chkconfig --list | grep service_name
   
 5. How to remove a service from startup list
   chkconfig --del service_name

6. How to Turn-on or Turn-off a service for a selected Run level
   Sometimes you might not want to delete the whole service. Instead, you might just want to turn the  flag on or off for a particular run level (for a particular service).
   chkconfig --level 3 service_name on/off 

 7. How to check service startup status from shell script
    create a file check.sh
    vi check.sh
    chkconfig service_name && echo "${service_name} service is configured"
    chkconfig service_name --level 3 && echo "${service_name} service is configured for level 3"
  
   ./check.sh


NOTE:

 - Run level 0 – /etc/rc.d/rc0.d/
 - Run level 1 – /etc/rc.d/rc1.d/
 - Run level 2 – /etc/rc.d/rc2.d/
 - Run level 3 – /etc/rc.d/rc3.d/
 - Run level 4 – /etc/rc.d/rc4.d/
 - Run level 5 – /etc/rc.d/rc5.d/
 - Run level 6 – /etc/rc.d/rc6.d/

 - Under the /etc/rc.d/rc*.d/ directories, you would see programs that start with S and K.
 - Programs starts with S are used during startup. S for startup.
 - Programs starts with K are used during shutdown. K for kill.
 - There are numbers right next to S and K in the program names. Those are the sequence number in which the programs should be started or killed.


Wednesday, June 13, 2012

How to find exact version of Red Hat Linux


[root@localhost ]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.2 (Tikanga)


For others:

Slackware: /etc/slackware-version
Mandrake: /etc/mandrake-release
Red Hat: /etc/redhat-release
Fedora: /etc/fedora-release

Friday, January 27, 2012

How to install libflashplayer.so on linux

When we trying to install the flash player for your linux operating system, we download file libflashplayer.so but we do know where to put this file.

This article guild you step by step to install the flash player for linux.


Step 1: Go to Adobe website and download you suitable version of flash player libflashplayer.so 32-bit/64bit . Then extract it to libflashplayer.so File.

Step 2:
cd to the folder has file libflashplayer.so and install
  • If you are using FireFox:
  • sudo mv libflashplayer.so /usr/lib/mozilla/plugins/libflashplayer.so
     
  • If you are using Google Chrome + Firefox
sudo mv libflashplayer.so /usr/lib/mozilla/plugins/libflashplayer.so
    sudo mkdir /opt/google/chrome/plugins
    sudo cp /usr/lib/flashplugin-installer/libflashplayer.so 
    /opt/google/chrome/plugins
Thanks.

Wednesday, January 18, 2012

Basic Linux Commands



*) How to extract tr.gz. file
To extract one or more members from an archive :
             tar -zxvf {file.tar.gz}

For example, If your tar name is backup.tar.gz, enter the following at a shell prompt:
             tar -zxvf backup.tar.gz



*) How to run .bin file

Change the permission of the file you downloaded to be executable. Type the following command:
              $ chmod +x file.bin

Start the installation process or run .bin file.Type the following command:
             ./file.bin

For example if .bin file name is application.bin. Type:
        $ chmod +x application.bin
        $ ./application.bin



*) How to set a BASH variable equal to the output from a command?

Use $(), which I find easier to read, and allows for nesting.
        OUTPUT=$(ls -1) echo $OUTPUT


*) How to read IP Address In a Shell Script

Type the following command:

ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'


*) How to find out particular ProcessId
                  ps -ef | grep processname
                  eg: ps -ef | grep mysql


*) How to display Line number from a file
          sed -n "linenumber p" file.txt
          sed -n "3 p" file1.txt

*) How to check Hidden file
          ls -a

*) How to check port
         netstat -tulpn


*) How to find directory on linux?
        find / -name 'httpdocs' -type d

the first parameter "/" is where to look, in this case "/" it's the entire system.
-name could be -iname to ignore case also -type is not mandatory
use : man find for more option


*) How to check free RAM size ?
                  free -m


*) How to clear cache memory ? 
        echo 1 > /proc/sys/vm/drop_caches

*) How to check linux version
              cat /proc/version

*) How to check which all service is running ?
                   intictl list 
For a particular service
                   intictl list | grep nova




Wednesday, January 4, 2012

How to Set JAVA_HOME / PATH variables Under Linux

After installing Java Development Kit on Linux/Unix, you may still need to do some configuration to get Java ready for running or compiling Java programs. The following instruction will guide you through the process of setting up JDK for software development.

In Linux, ~/.bash_profile is a startup script which generally runs once. This particular file is used for commands which run when the normal user logs in. Common uses for .bash_profile are to set environment variables such as PATH, JAVA_HOME, to create aliases for shell commands, and to set the default permissions for newly created files.

Set JAVA_HOME / PATH for single user

Login to your account and open .bash_profile file
$ cd $HOME
$ vi ~/.bash_profile

Set PATH and JAVA_HOME as follows:
 
PATH=$PATH:$HOME/bin:/usr/jdk1.6.0_30/bin
JAVA_HOME=/usr/jdk1.6.0_30


Note: Don't delete the previous PATH, Just append the jdk path after : like "/usr/jdk1.6.0_30/bin" as above .

export PATH
export JAVA_HOME

Save and close the file. Just logout and login back to see new changes:
$ echo $JAVA_HOME
$ echo $PATH


Tip: Use the following command to find out exact path to which java executable under UNIX / Linux:
$ which java


How to set JAVA PATH on Windows

How TOPT Works: Generating OTPs Without Internet Connection

Introduction Have you ever wondered how authentication apps like RSA Authenticator generate One-Time Passwords (OTPs) without requiring an i...