Showing posts with label CentOS Tutorials. Show all posts
Showing posts with label CentOS Tutorials. Show all posts

Thursday, March 27, 2014

How to map Google Drive on CentOS



I am learning around with grive, a third party Google Drive client.  It’s pretty cool, but the instructions are based on an Ubuntu install.  I had an interesting time setting it up on CentOS 6.3 64bit, so I decided to share what I learned.

First, get connected EPEL and all repositories,

#yum update
#yum install json-c* expat* curl* 
# rpm -i http://www.mirrorservice.org/sites/dl.atrpms.net/el6.3-x86_64/atrpms/testing/cmake-2.8.4-1.el6.x86_64.rpm
# git clone git://github.com/Grive/grive.git
# cd grive
# cmake .
# make

If there are errors, just install new Boost version follow:

http://thoaimedia.com/install-boost-1-55-0-version-on-centos/

after that you give build again:
#cd ./grive  # grive repo is already checked out here
#git clean -fdx
#cmake .
#make


[root@mrcool]# cp ./grive/grive /home/mrcool/GoogleDrive/
[root@mrcool]# cd /home/mrcool/GoogleDrive/
[root@mrcool GoogleDrive]# ./grive -a

Please go to this URL and get an authentication code:

https://accounts.google.com/o/oauth2/auth?........




Please input the authentication code here: 
xxxxxx
Reading local directories
Synchronizing folders
Reading remote server file list
Synchronizing files
sync ./grive doesn't exist in server, uploading

Finished!

Install Boost 1.55.0 version on CentOS

Boost

Issue the following commands in the shell (don't type $; that represents the shell's prompt):
$ cd path/to/boost_1_55_0
$ ./bootstrap.sh --help

Select your configuration options and invoke ./bootstrap.sh again without the --help option. Unless you have write permission in your system's /usr/local/ directory, you'll probably want to at least use
$ ./bootstrap.sh --prefix=path/to/installation/prefix

to install somewhere else. Also, consider using the --show-libraries and --with-libraries=library-name-list options to limit the long wait you'll experience if you build everything. Finally,
$ ./b2 install

will leave Boost binaries in the lib/ subdirectory of your installation prefix. You will also find a copy of the Boost headers in the include/ subdirectory of the installation prefix, so you can henceforth use that directory as an #include path in place of the Boost root directory.

 

My complete commands:
wget http://sourceforge.net/projects/boost/files/boost/1.55.0/boost_1_55_0.tar.gz/download
tar -xvzf boost_1_55_0.tar.gz
cd boost_1_55_0/
./bootstrap.sh --with-libraries=atomic,date_time,exception,filesystem,iostreams,locale,program_options,regex,signals,system,test,thread,timer,log
./b2 install

Install qmake on CentOS

CentOS 6.4


cd /etc/yum.repos.d
nano qk.repo


# Place this in a file in your /etc/yum.repos.d/ directory with a qt.repo extension

[epel-qt48] name=Software Collection for Qt 4.8 baseurl=http://repos.fedorapeople.org/repos/sic/qt48/epel-$releasever/$basearch/ enabled=1 skip_if_unavailable=1 gpgcheck=0 [epel-qt48-source] name=Software Collection for Qt 4.8 - Source baseurl=http://repos.fedorapeople.org/repos/sic/qt48/epel-$releasever/SRPMS enabled=0 skip_if_unavailable=1 gpgcheck=0

yum install qt48-qt-webkit-devel

ln -s /opt/rh/qt48/root/usr/include/QtCore/qconfig-64.h  /opt/rh/qt48/root/usr/include/QtCore/qconfig-x86_64.h

source /opt/rh/qt48/enable

export PATH=/opt/rh/qt48/root/usr/lib64/qt4/bin/${PATH:+:${PATH}}

Friday, March 7, 2014

How To Install Tomcat 7.0.52 Server on CentOS & RedHat 5/6

Apache Tomcat is an opensource webserver product of Apache Foundation like Apache HTTP server. It is used to deploying Java Servlet and JSP applications. To deploy any application in Tomcat we can simply create a war file and deploy them. For more details about you can visit apache official site http://tomcat.apache.org/ .

tomcat-apache-software-foundation

This article will help you to install Apache Tomcat 7 on CentOS/RHEL servers. We are using CentOS 6.5 and installing Apache tomcat 7. To read more about this release read Tomcat Release Notes.
Step 1: Check JAVA

JAVA is the first requirement of tomcat installation. Use following command to check if you have java installed already on your system.
# java -version

If you do not have java installed, Use this guide to install Java.
Step 2: Download and Extract Tomcat Archive

Download Apache tomcat archive file from Apache tomcat official site using below download url
Download URL: http://tomcat.apache.org/download-70.cgi
# cd /opt
# wget http://www.eu.apache.org/dist/tomcat/tomcat-7/v7.0.52/bin/apache-tomcat-7.0.52.tar.gz

After competed download extract archive file in /opt directory. You may change this location as per your setup.
# tar xzf apache-tomcat-7.0.52.tar.gz

Step 3: Start Tomcat Service

Tomcat is very easy to use, There are no need to compile its source. You simple extract the archive and start the tomcat server. Tomcat by default start on port 8080, So make sure no other application using the same port.
# cd apache-tomcat-7.0.52
# ./bin/startup.sh

[Sample Output]
Using CATALINA_BASE:   /opt/apache-tomcat-7.0.52
Using CATALINA_HOME: /opt/apache-tomcat-7.0.52
Using CATALINA_TMPDIR: /opt/apache-tomcat-7.0.52/temp
Using JRE_HOME: /usr
Using CLASSPATH: /opt/apache-tomcat-7.0.52/bin/bootstrap.jar:/opt/apache-tomcat-7.0.52/bin/tomcat-juli.jar

Step 4: Access Tomcat in Browser

Tomcat server works on port 8080 default. Access tomcat on web browser by connecting your server on port 8080.
http://svr2.tecadmin.net:8080

apache-tomcat-setup
Step 5: 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.
# user manager can access only manager section.
<role rolename="manager-gui" />
<user username="manager" password="_SECRET_PASSWORD_" roles="manager-gui" />

# user admin can access manager and admin section both.
<role rolename="admin-gui" />
<user username="admin" password="_SECRET_PASSWORD_" roles="manager-gui,admin-gui" />

I hope above steps will help you to setup tomcat on your server.

Thanks

Sunday, January 19, 2014

How to Resize the Root Partition in Linux on Amazon EC2

Check the Root Partition size before resize:
df -h

1The current root partition size is ~8 GB.

After that, stop your instance:
sudo poweroff

2

Go to Volumes on the left-hand EC2 navigation control panel.Right-click on the volume you want to resize and select Create Snapshot.

3Note: Make sure you also check the availability zone.

Fill out the details of the snapshot you are creating.

4

Go to Snapshots on the left-hand EC2 navigation control panel.Right-click on the snapshot you created and select Create Volume from Snapshot.

5

Enter the new size of the partition that you would like to be, select the same availability zone in which your instance is running and click Yes,Create.

6

Go back to the Volumes in the EC2 control panel. Select the old root volume, right click on it and select Detach Volume.

7

Now right click on the new volume that we have just created and select Attach Volume.

8

Please make sure that the volume should be attached as /dev/sda1:

9

Now turn on your instance. Make a note of your partition name, in my case it is /dev/xvda1. Type the resize2fs /dev/xvda1 command.
sudo resize2fs /dev/xvda1

10

After that view the new root partition size.
df -h

11

Yes, it’s work

Hope this will help you!

Please Remember me in your prayers!

OpenVPN server on CentOS 6.4 behind NAT

This tutorial describes that how to configure the OpenVPN Server in CentOS 6.4 and clients in Windows XP/7.

I am taking the scenario of SOHO network, which is protected by Firewall, we’ll implement the OpenVPN on internal CentOS 6.4 server to access the internal SOHO network (Server and PCs) through the internet from anywhere securely.

openvpn

Before starting this tutorial, we need to install the RPMforge and EPEL repositories:

RPMforge Installation:
wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
rpm -K rpmforge-release-0.5.2-2.el6.rf.*.rpm
rpm -i rpmforge-release-0.5.2-2.el6.rf.*.rpm
yum repolist

EPEL Installation:
wget http://ftp.riken.jp/Linux/fedora/epel/RPM-GPG-KEY-EPEL-6
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm --import RPM-GPG-KEY-EPEL-6
rpm -ivh epel-release-6-8.noarch.rpm
yum repolist

OpenVPN Server Installation:

Install the openvpn package using the following command:
yum install openvpn easy-rsa

1

Make the openvpn service to start automatically on boot:
chkconfig openvpn on

1a

Make an easy-rsa/keys directory inside /etc/openvpn:
mkdir -p /etc/openvpn/easy-rsa/keys

2

Copy the default easy-rsa into /etc/openvpn for setting up Certificate Authority (CA), certificates and keys generation for OpenVPN server and clients:
cp -rf /usr/share/easy-rsa/2.0/* /etc/openvpn/easy-rsa

3

Edit /etc/openvpn/easy-rsa/vars:
cd /etc/openvpn/easy-rsa/
vi vars

4

Edit these parameters according to your need:
export KEY_COUNTRY="US"
export KEY_PROVINCE="NC"
export KEY_CITY="Winston-Salem"
export KEY_ORG="Example Company"
export KEY_EMAIL="me@example.com"

5

Move to the /etc/openvpn/easy-rsa/ and enter these commands:
cd /etc/openvpn/easy-rsa/
cp openssl-1.0.0.cnf openssl.cnf
source vars
./clean-all

6

Now, generate the CA certificate and key:
./build-ca

7

Next, generate a server certificate and private key:
./build-key-server tendo

8Note: tendo is my server name in above command, you can use your server name here.

For OpenVPN server,Diffie Hellman parameters are must:
./build-dh

9

Copy all the certificates and keys into /etc/openvpn/ from /etc/openvpn/easy-rsa/key/ subdirecotory:
cd keys/
cp ca.crt tendo.crt tendo.key dh1024.pem /etc/openvpn/

10

Create a /etc/openvpn/server.conf file and enter the certificates and keys information that we have created above:
vi /etc/openvpn/server.conf

11

Here is my server.conf file as an example, you can change it according to your requirement:
port 1194
proto udp
dev tun
ca ca.crt
cert tendo.crt
key tendo.key # This file should be kept secret
dh dh1024.pem
#VPN subnet for OpenVPN to draw client addresses from.
server 172.16.10.0 255.255.255.0
ifconfig-pool-persist ipp.txt
#Push routes to the client to allow it to reach other
#private subnets behind the server.
push "route 10.10.10.0 255.255.255.0"
#If you want that all of your Internet traffic pass
#through the VPN server then enable this
;push "redirect-gateway def1 bypass-dhcp"
# For name resolution, enable this
;push "dhcp-option DNS 10.10.10.254"
client-to-client
keepalive 10 120
comp-lzo
max-clients 10
persist-key
persist-tun
status openvpn-status.log
verb 5
mute 20

12

Now, start the OpenVPN server:
service openvpn start

13Note: Forward udp port 1194 to your internal OpenVPN server on edge firewall.
Client Certificates:

VPN client also need a certificate to authenticate itself to the server. Using the root user, create the different certificate for each client:
cd /etc/openvpn/easy-rsa/
./build-key rblaptop

14Note: rblaptop is my vpn client name in above command, you can use your client name here.

Copy these files to the client machine using winscp or any other method:
1) /etc/openvpn/ca.crt
2) /etc/openvpn/easy-rsa/keys/rblaptop.crt
3) /etc/openvpn/easy-rsa/keys/rblaptop.key

Your files name will be differ, so adjust them as per your need.
OpenVPN Client Configuration on Windows Machine:

Download free OpenVPN client for windows from here, and install it. Below is the step by step procedure to configure this OpenVPN client in order to connect to the OpenVPN server that we have configured above:

1

2

3

4

5

6

7

8

9

10

11

Check the routing table on client machine:
netstat -r

12

Ping to the OpenVPN internal ip:

13

For internal host, the ping will be failed because internal host doesn’t know about this vpn pool. To overcome this problem, we need to configure NAT on OpenVPN server:

Edit the /etc/sysctl.conf file:
vi /etc/sysctl.conf

15

Enable IP forwarding by changing “net.ipv4.ip_forward” line to 1:
net.ipv4.ip_forward=1

16

Create an iptables rule to allow the proper routing of VPN subnet.
iptables -t nat -A POSTROUTING -s 172.16.10.0/24 -o eth0 -j MASQUERADE
service iptables save
service iptables restart

17

Reboot the server or issue this command to load the change:
sysctl -p

Ping to the internal host again:

14

Success 
Hope this will help you!

Please Remember me in your prayers

Saturday, October 19, 2013

Backup to Amazon S3 Bucket from CentOS 6.4

In this tutorial I’ll make mysql db backup and then upload it to AMAZON S3 Bucket using S3CMD tool and bash script. The script will also create the separate folder automatically for each day inside the bucket.

Before starting this tutorial, we need to install the EPEL for s3cmd tools:
wget http://ftp.riken.jp/Linux/fedora/epel/RPM-GPG-KEY-EPEL-6 
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm --import RPM-GPG-KEY-EPEL-6
rpm -ivh epel-release-6-8.noarch.rpm
yum repolist

Switch to the root user:
sudo su -

1

Install the s3cmd tools:
yum install s3cmd

2

After installation, run the following command in order to configure the s3cmd tools using your AMAZON ACCESS KEY and SECRET KEY.
s3cmd --configure

3

It is always a good practice to create a separate scripts directory:
mkdir /script
cd /script
nano mysqlbackuptos3.sh

4

Paste the below code into the script (Please modify the following script to suit your purposes):
#!/bin/bash
#############################################################
# Created by: Thoai Nguyen (thoai.nguyenanh{at}gmail(dot)com) #
#                                                           #                                                                                                #
#############################################################
## Specify the name of the database that you want to backup
DATABASE="tendodb"

## USERNAME and PASSWORD to take the backup
USER="arbab"
PASSWORD="PASSWORD"
## Defination of some necessary variables
S3_BUCKET=tendodbbackup
DATE=`date +%A-"(%d.%m.%Y)".%H`
BACKUP_LOC=/tmp/backups
S3BDIR=`date +%d.%A-"(%d.%m.%Y)"`
mysql_backup(){
/usr/bin/mysqldump -u $USER -p$PASSWORD --databases $DATABASE | gzip -9 > $BACKUP_LOC/tendodb_$DATE.sql.gz
s3cmd ls s3://$S3_BUCKET/$S3BDIR > /tmp/log.txt
grep -lr "$S3BDIR" /tmp/log.txt
if [ $? -ne 0 ]
then
mkdir /tmp/$S3BDIR
s3cmd put -r /tmp/$S3BDIR s3://$S3_BUCKET/
s3cmd sync -r $BACKUP_LOC/ s3://$S3_BUCKET/$S3BDIR/
else
s3cmd sync -r $BACKUP_LOC/ s3://$S3_BUCKET/$S3BDIR/
fi
}
mysql_backup
echo "----------------------------------------------------------------------------------------------" >> /scripts/dbbackup.log
echo "Backup Successfully uploading to the S3 Bucket at `date +%A.%Y%m%d-%H.%M`" >> /script/dbbackup.log
echo "##############################################END#############################################" >> /scripts/dbbackup.log
rm -rf $BACKUP_LOC/* /tmp/$S3BDIR
exit 0

5

Create the backups directory inside the tmp directory (or anywhere else, as per your desire) to hold the mysql backup temporarily before uploading it to the s3 bucket:
mkdir /tmp/backups
chmod 0777 /tmp/backups

6

Verify the access to the bucket, where you want to upload the backup using the following command:
s3cmd ls

7

Give the execute right to the script and run it:
cd /script
chmod +x mysqlbackuptos3.sh
ls
./mysqlbackuptos3.sh

8

This bash script also creates a log file inside the /script directory:
cd /script
ls
cat dbbackup.log

9

Inside the S3 Bucket, it will create the mysql backup like this:

10

To automate this process using the cronjob, enter crontab -e at the shell prompt:
crontab -e

11

Add this line to run the script at midnight every day:
0 * * * * /script/mysqlbackuptos3.sh > /dev/null

12

Enjoy :-)

Hope this will help you!

Please Remember me in your prayers!