Archive for December, 2014

2014 in review

Posted: December 30, 2014 in other

The WordPress.com stats helper monkeys prepared a 2014 annual report for this blog.

Here’s an excerpt:

A San Francisco cable car holds 60 people. This blog was viewed about 1,200 times in 2014. If it were a cable car, it would take about 20 trips to carry that many people.

Click here to see the complete report.


When you install PostgreSQL, by default connection to the database using TCP/IP is not allowed.

When you try to connect from a client to a remote PostgreSQL database using psql command, you might get “psql: could not connect to server: Connection refused” error message

For example:
# psql -U postgres -h 62.181.1.126
psql: could not connect to server: Connection refused
        Is the server running on host "62.181.1.126" and accepting
        TCP/IP connections on port 5432?

To enable TCP/IP connection for PostgreSQL database, you need to follow the two steps mentioned below:

1. Modify pg_hba.conf to add Client Authentication Record:

On the PostgreSQL database server, by default, you’ll notice the following records towards the end of the /var/lib/pgsql/data/pg_hba.conf or /var/lib/pgsql/9.3/data/pg_hba.conf

As indicated below, it accepts connections only from the localhost.

# IPv4 local connections:
host    all         all         127.0.0.1/32          trust

Add the following line to the pg_hba.conf server.If you want to allow connection from multiple client machines on a specific network, specify the network address here in the CIDR-address format.

# vi /var/lib/pgsql/9.3/data/pg_hba.conf
host all all 62.181.1.126/24 trust

2. Change the Listen Address in postgresql.conf

On the PostgreSQL database server, by default, the listen address will be localhost in the postgresql.conf file as shown below.

grep listen /var/lib/pgsql/9.3/data/postgresql.conf
#listen_addresses = ‘localhost’ # what IP address(es) to listen on;

Modify this line and give *. If you have multiple interfaces on the server, you can also specify a specific interface to be listened.

grep listen /var/lib/pgsql/9.3/data/postgresql.conf
listen_addresses = ‘*’ # what IP address(es) to listen on;

3. Test the Remote Connection

$ psql -U postgres -h 62.181.1.126
psql (9.3.5)
Type "help" for help.
postgres=#

Also, if you don’t want to specify the hostname in the command line parameter every time, you can setup the remote PostgreSQL database ip-address in PGHOST environment variable name as shown below.

$ export PGHOST=62.181.1.126
$ psql -U postgres
psql (9.3.5)
Type "help" for help.
postgres=#

PostgreSQL

Posted: December 5, 2014 in Databases

PostgreSQL is a open source object-relational, highly scalable, SQL compliant database management system. PostgreSQL is developed at the University of California at Berkeley Computer Science Department.

Step 1: Add PostgreSQL Yum Repository
CentOS/RHEL 6, 64-Bit:
# rpm -Uvh http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-redhat93-9.3-1.noarch.rpm
Step 2: Install PostgreSQL Server
# yum install postgresql93-server postgresql93
Step 3: Initialize PGDATA
After installing PostgreSQL server, It’s required to initialize it before using first time. To initialize database use below command
# /etc/init.d/postgresql-9.3 initdb
Initializing database: [ OK ]
PostgreSQL data directory Path: /var/lib/pgsql/9.3/data/
Step 4: Start PostgreSQL Server
[root@fenige_db1 ~]# service postgresql-9.3 start
Starting postgresql-9.3 service: [ OK ]
# chkconfig postgresql-9.3 on
Step 5: Verify PostgreSQL Installation
# su – postgres
Use psql command to access PostgreSQL prompt with admin privileges.
[root@localhost ~]# su – postgres
-bash-4.1$ psql
psql (9.3.5)
Type “help” for help.
-bash-4.1$ createuser redmoon
-bash-4.1$ createdb mydb
-bash-4.1$ psql
psql (9.3.5)
Type “help” for help.
postgres=# alter user redmoon with encrypted password ‘centos’;
ALTER ROLE
postgres=# grant all privileges on database mydb to redmoon;
GRANT
[redmoon@fenige_db1 ~]$ psql -d mydb -U redmoon -W
Password for user redmoon:
psql (9.3.5)
Type “help” for help.
mydb=>
I have created moon user and created mydb databases. And provide previleges to moon
Also created the username master and blaster. And able to access the databases.
For example:
[root@localhost]# su – master
[master@localhost ]$ psql -d postgres
psql (9.3.5)
Type “help” for help.

I have set the necessary roles to the users master and blaster.

postgres=# ALTER USER master WITH SUPERUSER;
ALTER ROLE

postgres=# ALTER USER blaster WITH SUPERUSER;
ALTER ROLE

postgres=# ALTER ROLE master CREATEROLE CREATEDB;
ALTER ROLE

postgres=# ALTER ROLE blaster CREATEROLE CREATEDB;
ALTER ROLE

postgres=# \du
List of roles
Role name | Attributes | Member of
———–+————————————————+———–
master | Superuser, Create role, Create DB | {}
blaster | Superuser, Create role, Create DB | {}
postgres | Superuser, Create role, Create DB, Replication | {}
moon | Create role, Create DB | {}


Subversion (SVN) is an open source version control system. It helps you keep track of a collection of files and folders.

Step 1: Install Apache/PHP Packages

We need to install apache web server to access svn server using http urls.

# yum install httpd php php-devel php-cli php-pear

Start Apache web server and setup to auto start on system boot

# service httpd restart
# chkconfig httpd on

Step 2: Install Subversion Using Yum

Use following command to install subversion and mod_dav_svn packages.

# yum install mod_dav_svn subversion

Step 3: Configure Subversion with Apache

Subversion creates an apache configuration file, we just need to make necessary changes to it.

# vim /etc/httpd/conf.d/subversion.conf
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so

<Location /svn>
DAV svn
SVNParentPath /var/www/svn
AuthType Basic
AuthName “Subversion User Authentication ”
AuthUserFile /etc/svn-users
Require valid-user
</Location>
Step 4: Create First SVN Repository

Use following command to create your fist svn repository.

# cd /var/www/svn
# svnadmin create myrepo
# chown -R apache.apache myrepo
Step 5: Add SVN Users

# htpasswd -cm /etc/svn-users user1

Step 6: Access Your Repository in Browser

Use http urls to access your repository in browser. It will prompt for authentication. Use login credentials created in Step 5.

 

[root@localhost]# elinks http://your_ip_address/svn/myrepo or use in your fav browser.

CHEERS 🙂

Jenkins on CentOS

Posted: December 5, 2014 in Open source

In a nutshell Jenkins CI is the leading open-source continuous integration server. Built with Java, it provides 1009 plugins to support building and testing virtually any project.

First we need to set up the repository as follows:
$ sudo wget -O /etc/yum.repos.d/jenkins.repo \
http://jenkins-ci.org/redhat/jenkins.repo
$ sudo rpm –import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
Next we need to check java is installed or not.
Next, we can install the package as shown here:
$ sudo yum install jenkins
This will install the latest version of Jenkins into the /usr/lib/jenkins directory. The default Jenkins home directory will be in /var/lib/jenkins.

Now we can start Jenkins using the service command:
$ sudo service jenkins start
By deafult jenkins listen 8080 port. But here we want to change to some other port.
Initially the jenkins will not start, when Installing Jenkins on CentOS:

[root@fenige_www_dev ~]# service jenkins status
jenkins dead but pid file exists
Edit
/etc/sysconfig/jenkins
Change
JENKINS_PORT from JENKINS_PORT=”8080″ to JENKINS_PORT=”8070″
Change it from JENKINS_AJP_PORT=”8009″ OR whatever value to JENKINS_AJP_PORT=”-1″
It will work for sure.
Login as:
http://your_ip_address:8070/
Created logins:
Username: test
Password: secret
Standard Security Setup:
The most common set up — let Jenkins maintain its own user database
Initial steps
1. Go to the Configure Global Security screen and choose “enable security”.
2. Select “Jenkins’s own user database” as the security realm.
3. Place a check mark next to “Allow users to sign up”
4. Select “Matrix-based security” as the authorization
5. Give anonymous user the read access
6. In the text box below the table, type in your user name (you’d be creating this later) and click “add”
7. Give yourself a full access by checking the entire row for your user name
8. Scroll all the way to the bottom, click “save”
At this point, you’ll be taken back to the top page, and Jenkins is successfully secured.
Restart Jenkins (service jenkins restart)
Now you need to create an user account for yourself.

a. Click “login” link at the top right portion of the page
b. Choose “create an account”
c. Use the user name you’ve used in the above step, and fill in the rest.

Tomcat in centos

Posted: December 5, 2014 in Open source

Step 1: Verify JAVA
JAVA is the first requirement of Tomcat installation. Use following command to check if you have java installed already on your system.
[server@localhost ~]$ java -version
java version “1.8.0_25”
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
Tomcat 8.0 is designed to run on Java SE 7 and later.

Step 2: Download and Extract Tomcat Archive
# cd /opt
# wget http://www.us.apache.org/dist/tomcat/tomcat-8/v8.0.15/bin/apache-tomcat-8.0.15.tar.gz
# tar apache-tomcat-8.0.15.tar.gz

Step 3: Setup Environment Variable
Before starting Tomcat, Configure environment variables using following commands.
# echo “export CATALINA_HOME=\”/opt/apache-tomcat-8.0.15\”” >> ~/.bashrc
# source ~/.bashrc

Step 4: Start Tomcat Service
# cd apache-tomcat-8.0.15
# ./bin/startup.sh
[redmoon@fenige_www_dev apache-tomcat-8.0.15]$ sudo ./bin/startup.sh
Using CATALINA_BASE: /opt/apache-tomcat-8.0.15
Using CATALINA_HOME: /opt/apache-tomcat-8.0.15
Using CATALINA_TMPDIR: /opt/apache-tomcat-8.0.15/temp
Using JRE_HOME: /usr
Using CLASSPATH: /opt/apache-tomcat-8.0.15/bin/bootstrap.jar:/opt/apache-tomcat-8.0.15/bin/tomcat-juli.jar
Tomcat started.

Step 5: Access Tomcat in Browser
http://your_ip_address:8080/

Step 6: Setup User Accounts
Finally we need to create user accounts to secure and access admin/manager pages. Edit conf/tomcat-users.xml file in your editor and paste inside <tomcat-users> </tomcat-users> tags.

[root@localhost]# cat tomcat-users.xml
<?xml version=’1.0′ encoding=’utf-8′?>
<tomcat-users>
<role rolename=”tomcat”/>

<role rolename=”manager-gui”/>

<role rolename=”admin-gui”/>

<user username=”test1″ password=”secret” roles=”manager-gui,admin-gui”/>
<user username= “test2″ password=”secret” roles=”manager-gui,admin-gui”/>
<user username=”test3″ password=”secret” roles=”admin-gui,manager-gui”/>
</tomcat-users>
————————————-

And its ready to use these users, you can restart the tomcat and access http://your_ip_address:8080/, click the manger app or host manger etc.

How to start tomcat at the system startup:
Create tomcat8 file in /etc/init.d/ like this:
#vi /etc/init.d/tomcat8
and paste following code:

#!/bin/bash
export CATALINA_HOME=/your/path/here ( for eg: the path where my tomcat  is installed /opt/apache-tomcat-8.0.15 )
PATH=/sbin:/bin:/usr/sbin:/usr/bin
start() {
sh $CATALINA_HOME/bin/startup.sh
}
stop() {
sh $CATALINA_HOME/bin/shutdown.sh
}
case $1 in
start|stop) $1;;
restart) stop; start;;
*) echo “Run as $0 “; exit 1;;
esac
And later modify /etc/init.d/tomcat8 file permissions:
#chmod 755 /etc/init.d/tomcat8
And we can start or stop the tomcat… 🙂

Java in centos

Posted: December 5, 2014 in Open source

Step 1: Download JAVA Archive
For 64Bit

# cd /opt/
# wget –no-cookies –no-check-certificate –header “Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie” “http://download.oracle.com/otn-pub/java/jdk/8u25-b17/jdk-8u25-linux-x64.tar.gz&#8221;
# tar xzf jdk-8u25-linux-x64.tar.gz
Step 2: Install JAVA using Alternatives
# cd /opt/jdk1.8.0_25/
# alternatives –install /usr/bin/java java /opt/jdk1.8.0_25/bin/java 2
# alternatives –config java
There is 1 program that provides ‘java’.
Selection Command
———————————————–
*+ 1 /opt/jdk1.8.0_25/bin/java
Enter to keep the current selection[+], or type selection number: 1
At this point JAVA 8 has been successfully installed on your system. We also recommend to setup javac and jar commands path using alternatives
# alternatives –install /usr/bin/jar jar /opt/jdk1.8.0_25/bin/jar 2
# alternatives –install /usr/bin/javac javac /opt/jdk1.8.0_25/bin/javac 2
# alternatives –set jar /opt/jdk1.8.0_25/bin/jar
# alternatives –set javac /opt/jdk1.8.0_25/bin/javac
Step 3: Check Version of JAVA
Check the installed version of java using following command.
[server@localhost ~]$ java -version
java version “1.8.0_25”
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

Step 4: Setup Environment Variables
Most of java based application’s uses environment variables to work. Set the java environment variables using following commands
Setup JAVA_HOME Variable
# export JAVA_HOME=/opt/jdk1.8.0_25
Setup JRE_HOME Variable
# export JRE_HOME=/opt/jdk1.8.0_25/jre
Setup PATH Variable
# export PATH=$PATH:/opt/jdk1.8.0_25/bin:/opt/jdk1.8.0_25/jre/bin