Tuesday, 21 November 2017

How to clear catalina.out without disabling further logging

Delete Apache Tomcat catalina.out log


Step 1 : Go to apache tomcat log directory
 
                     [root@centos ~]#   cd /apache-tomcat-8.5.12/logs/


Step 2 :  Clear the file catalina.out



                       [root@centos ~]#  echo > catalina.out





Tuesday, 24 January 2017

Backup Directories to Google Drive Automatically on CentOS/Red Hat


This tutorial explains how to backup directories to google drive.

1. Install google drive.

            Use the following link ti download google drive

           https://drive.google.com/open?id=0B2iJNfzwHersOVYzV0xsa09SZ1U

2. Move this file to "/usr/sbin/" folder.
  
       
           [root@centos ~]# mv drive /usr/sbin/drive





3. Assign right permission to the file.

              [root@centos ~]# chmod 755 /usr/sbin/drive


 


4. Now run command "dive". It will ask authentication.

      You will get a link like this.

"https://accounts.google.com/o/oauth3/auth?client_id=3453453533-7n0vf5gghru6on6o3fjinrghpdoe88eg.apps.googleusercontent.com&redirectghct_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&scope=https%3A%2F%2Fwww.goohgheapis.com%2Fauth%3Fdrive&state=state"

  Go  to the above link on browser, you will get verification code. Type verification code and hit Enter.






5. Create backup script.

----------------------------------------------------------------------------------

#!/bin/sh


# tar the bkp directory
tar -zcf "dir-backup-$(date '+%Y-%m-%d').tar.gz" /root/AAA/aby/

# encrypt the tar
#openssl aes-256-cbc -a -salt -in "dir-backup-$(date '+%Y-%m-%d').tar.gz" -out "dir-backup-$(date '+%Y-%m-%d').tar.gz.enc" -pass 'pass:123456'

# remove the original tar
#rm -rf "dir-backup-$(date '+%Y-%m-%d').tar.gz"

# upload to google drive
drive upload --file "dir-backup-$(date '+%Y-%m-%d').tar.gz" -p 0B2iJNfzwHersN3Yxa0N3U1lqeU0

----------------------------------------------------------------------------------------------------------------------





6. Execute the script.




You can Schedule this script on crontab and schedule this autobackup.




Monday, 23 January 2017

How to configure SVN Server (Subversion Edge) on CentOS/Red Hat


Apache Subversion (often abbreviated SVN, after its command name svn) is a software versioning and revision control system distributed as open source under the Apache License. Software developers use Subversion to maintain current and historical versions of files such as source code, web pages, and documentation. Its goal is to be a mostly compatible successor to the widely used Concurrent Versions System (CVS).

In this tutorial, I am using CollabNet Subversion Edge. It simplify Apache Subversion installation, automate upgrades, and manage code, instances, and users in a centralized, simple way. You can add your preferred Subversion clients and pick from a range of integrations to further extend your Subversion platform.

You can download free CollabNet Subversion Edge from following link.


Use the following steps to install svn server in your linux system,

1. Install and configure jdk.



    Download jdk-version.tar.gz from


                 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html


   Extract the downloaded jdk. 


                   # tar -xzf jdk-version.tar.gz


   Set environmental variable. 


                    Edit vim .bash_profile  --->  export PATH=(path of jdk bin):$PATH  (in centos,redhat....) 
           Edit vim .profile           --->  export PATH=(path of jdk bin):$PATH  (in ubuntu,mint....)



2. Create user svn.


[root@centos ~]# useradd svn

[root@centos ~]# passwd svn





3. Copy CollabNetSubversionEdge-5.1.5_linux-x86_64 to svn users home directory.


[root@centos ~]# cp CollabNetSubversionEdge-5.1.5_linux-x86_64.tar.gz  /home/svn/


4. Switch to svn user and add java environmental variable.


[root@centos ~]# su - svn


5. Open ".bash_profile" and add jdk path in it.


[svn@centos ~]$ vim .bash_profile

export PATH=/root/jdk1.8.0_112/bin/:$PATH







6. Extract package 


tar -xvf CollabNetSubversionEdge-5.1.5_linux-x86_64.tar.gz 




7. go to configuration folder and change csvn.conf.dist to csvn.conf


[svn@centos conf]$ cp -rp csvn.conf.dist  csvn.conf







8. Edit csvn.conf


Search for "JAVA_HOME" and uncomment this line and add jdk path. Change RUN_AS_USER=root

[svn@centos conf]$ vim csvn.conf














9. Go to bin directory and start svn.


[root@centos ~]# cd /home/svn/csvn/bin/
[root@centos bin]# ./csvn start









10. Install the application. 


[root@centos csvn]# sudo -E bin/csvn install



This installs the application so that it will run at startup. The script will swap to the user specified before it starts the console. Please note the JAVA_HOME requirement - you must have set the environment variable for your profile (or the entire system) so that it will be visible when the process starts.
When you install csvn as a service, you can control it with these commands:


    $ sudo service csvn status
    $ sudo service csvn start
    $ sudo service csvn stop


11. There are also scripts for Apache server, but you should visit the console first and go the Admin page to set the port and other options before you try to start it. It can also be started from the web UI.


[root@centos csvn]# bin/csvn-httpd start
[root@centos csvn]# sudo bin/csvn-httpd install







12.Test SVN Server.


The default username and password will be "admin"


















Tuesday, 6 December 2016

How to schedule postgresql auto vacuum in linux



Step 1: Create a .pgpass file under your home directory.


                   [root@centos6 ~]# vim .pgpass

                                localhost:5432:DB-Name:Username:Password


Step 2: Install Crond packages.  http://www.admincool.in/2016/09/how-to-scheduling-crontab-for-     backup.html

Step 3: Edit crontab


                  [root@centos6 ~]# crontab -e

                  30      10      *      *      *      /opt/PostgreSQL/9.4/bin/psql dbname=bayaTRADETest --username=dbuser -c 'VACUUM FULL VERBOSE'


Step 4: Restart crontab


                 # service crond restart


Step 5: Add crontab on startup


                # chkconfig crond on





Description


Vacuum reclaims storage occupied by dead tuples. In normal PostgreSQL operation, tuples that are deleted or obsoleted by an update are not physically removed from their table; they remain present until a Vacuum is done. Therefore it's necessary to do Vacuum periodically, especially on frequently-updated tables.


With no parameter, Vacuum processes every table in the current database that the current user has permission to vacuum. With a parameter, Vacuum processes only that table.

Plain Vacuum (without FULL) simply reclaims space and makes it available for re-use. This form of the command can operate in parallel with normal reading and writing of the table, as an exclusive lock is not obtained. However, extra space is not returned to the operating system (in most cases); it's just kept available for re-use within the same table. Vacuum FULL rewrites the entire contents of the table into a new disk file with no extra space, allowing unused space to be returned to the operating system. This form is much slower and requires an exclusive lock on each table while it is being processed.

Parameters 


FULL

Selects "full" vacuum, which can reclaim more space, but takes much longer and exclusively locks the table. This method also requires extra disk space, since it writes a new copy of the table and doesn't release the old copy until the operation is complete. Usually this should only be used when a significant amount of space needs to be reclaimed from within the table.

FREEZE

Selects aggressive "freezing" of tuples. Specifying FREEZE is equivalent to performing Vacuum with the vacuum_freeze_min_age parameter set to zero.

VERBOSE

Prints a detailed vacuum activity report for each table.

ANALYZE

Updates statistics used by the planner to determine the most efficient way to execute a query.

table

The name (optionally schema-qualified) of a specific table to vacuum. Defaults to all tables in the current database.

column

The name of a specific column to analyze. Defaults to all columns. If a column list is specified, ANALYZE is implied.


PostgreSQL Vacuum graphically 

Step 1: Right click on database and select maintenance. It will open a pop up window.

Step 2: Select maintenance operation as VACUUM.

Step 3: Select VACUUM option as FULL

Step 4: Click OK










How to schedule postgresql auto backup in linux


Step 1: Create a .pgpass file under your home directory.

                   [root@centos6 ~]# vim .pgpass

                                localhost:5432:DB-Name:Username:Password


Step 2: Install Crond packages.  http://www.admincool.in/2016/09/how-to-scheduling-crontab-for-     backup.html


Step3: Edit crontab


                  [root@centos6 ~]# crontab -e

                  30      10      *      *      *      /opt/PostgreSQL/9.4/bin/pg_dump -U username --format=c --file=/postgres-backup/dbname.backup dbname


The backup of database will scheduled every day at 10.30 AM under 'postgres-backup' directory.


Step 4: Restart crontab


                 # service crond restart


Step 5: Add crontab on startup


                # chkconfig crond on



Synopsis

pg_dump [connection-option...] [option...] [dbname]

Description


pg_dump is a utility for backing up a PostgreSQL database. It makes consistent backups even if the database is being used concurrently. pg_dump does not block other users accessing the database (readers or writers).

Dumps can be output in script or archive file formats. Script dumps are plain-text files containing the SQL commands required to reconstruct the database to the state it was in at the time it was saved. To restore from such a script, feed it to psql. Script files can be used to reconstruct the database even on other machines and other architectures; with some modifications, even on other SQL database products.

The alternative archive file formats must be used with pg_restore to rebuild the database. They allow pg_restore to be selective about what is restored, or even to reorder the items prior to being restored. The archive file formats are designed to be portable across architectures.

When used with one of the archive file formats and combined with pg_restore, pg_dump provides a flexible archival and transfer mechanism. pg_dump can be used to backup an entire database, then pg_restore can be used to examine the archive and/or select which parts of the database are to be restored. The most flexible output file format is the "custom" format (-Fc). It allows for selection and reordering of all archived items, and is compressed by default.


Options

-U username
--username=username
User name to connect as.

-F format
--format=format
Selects the format of the output. format can be one of the following:

p
plain
Output a plain-text SQL script file (the default).

c
custom
Output a custom-format archive suitable for input into pg_restore. Together with the directory output format, this is the most flexible output format in that it allows manual selection and reordering of archived items during restore. This format is also compressed by default.

d
directory
Output a directory-format archive suitable for input into pg_restore. This will create a directory with one file for each table and blob being dumped, plus a so-called Table of Contents file describing the dumped objects in a machine-readable format that pg_restore can read. A directory format archive can be manipulated with standard Unix tools; for example, files in an uncompressed archive can be compressed with the gzip tool. This format is compressed by default.

t
tar
Output a tar-format archive suitable for input into pg_restore. The tar format is compatible with the directory format: extracting a tar-format archive produces a valid directory-format archive. However, the tar format does not support compression. Also, when using tar format the relative order of table data items cannot be changed during restore.

-i
--ignore-version
A deprecated option that is now ignored.









How to configure ftp server on centos


FTP is a file transferring protocol used to transfer form one host to another over TCP.
Package used for ftp server is vsftpd (Very Secure FTP Daemon). It is able to handle number of connections efficiently and securely. It uses port 21.

FTP server is used in wide area network. No mounting is needed. File uplod and download can be possible. FTP server offers two types of login, which are anonymous login and local user login.


Configuration


Step 1: Install vsftpd package

       [root@centos6 ~]# yum install vsftpd




Step 2: After install vsftpd package open configuration file and edit the file as following.


       [root@centos6 ~]# vim /etc/vsftpd/vsftpd.conf 

anonymous_enable=NO

local_enable=YES

write_enable=YES

chroot_local_user=YES

      Note: If 'anonymous_enable=YES', anyone can access ftp server without username and password.


Step 3: Create a folder where to store ftp data. In my case I am going to install folder under '/' directory.

       [root@centos6 /]# mkdir FTP-Share


Step 4: Create a ftp user with home directory as above created folder

       [root@centos6 /]# useradd -d /FTP-Share/alleria alleria
       [root@centos6 /]# passwd alleria





Step 5: Start the vsftpd service and add on startup

       [root@centos6 /]# service vsftpd start
       [root@centos6 /]# chkconfig vsftpd on

Step 6: Now test ftp. I created a file under user alleria's home directory.

       [root@centos6 /]# cd FTP-Share/alleria/
       [root@centos6 alleria]# touch alleria.txt






Tuesday, 27 September 2016

How to find size of a directory in Linux


du is a linux command, is to display the file space allocated to each file and directory contained in the current directory. It Summarize disk usage of each FILE, recursively for directories.



                        # du    - List of directories that exist in the current directory along with their sizes.


                       # du -c   -Gives grand toal as last line of output.

                   
                       # du -s    -Displays summary of directory size.


                         # du -h   -Displays size in human readable format.









Sort Directory size in ascending order.




                         # sudo du -sh * | sort -hr