Jul 22, 2015

Change timezone in Unix/Linux

Check your current timezone.


Log in as root. Open the terminal and check which timezone your machine is currently using by executing the date command. The terminal will display the date in the following format:
Mon Aug 12 12:15:08 PST 2013.
PST in this case refers to the current timezone (Pacific Standard Time).

Select your timezone region.


Change to the directory /usr/share/zoneinfo. A list of time zone regions will be displayed.

The /usr/share/zoneinfo directory may vary depending on your Linux distribution.

Backup your old timezone settings.


If you wish, backup the previous timezone configuration by renaming it to a backup name. Use the following command
mv /etc/localtime /etc/localtime-old    

Link your machine’s clock to a city in your timezone.


Use the following command, replacing the region and city with your appropriate entries:
ln -sf /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime

If your city is not listed in the timezone list, pick one from your same timezone.

Verify that your timezone has been set.


Run the date command again and check that the timezone corresponds to the one you just changed to.

Set your clock to stay synced with internet time servers.


Most modern distributions have NTP already installed. If you do not, you will need to install the NTP server package. Use the following commands to install it, depending on your Linux distribution:

Ubuntu/Debian: sudo aptitude install ntp
CentOS: sudo yum install ntp
sudo /sbin/chkconfig ntpd on
Fedora/RedHat: sudo yum install ntp
sudo chkconfig ntpd on
Enter the ntpdate command: ntpdate && hwclock –w

There are a variety of public time servers available to connect to. You can find listings online.


Jul 21, 2015

Use 'grep' to Find File Names With a Matching String

By default, grep displays the lines in one or more files that match your search string (or regular expression). Here is how you recursively search through a directory of files and list the name(s) of the files that contain a matching string instead of the matched line.
grep -l Switch

The -l switch indicates that you want to display the names of files that contain a string that matches your query. Here is an example of its use with an entire directory of xml files (using the *.xml wildcard):
grep -l 'SEARCH_TERM' /path_to_your_directory/*.xml

This command causes grep to search for lines that match the query SEARCH_TERM in every .xml file in the given directory & will print the names of the files that contain a match to the standard output stream.
abc.xml
another_abc.xml

Replace SEARCH_TERM with your query and *.xml with any filetype or the name pattern of a set of files that you would like to search. The query can be a string or regular expression.

You can find grep documentation here

Jul 6, 2015

nodetool: Failed to connect to '127.0.0.1:7199' - ConnectException: 'Connection refused'. (Cassandra)


Error While Using Cassandra’s 'nodetool'

This error may occur when using the 'nodetool' command, such as in the following example:

$ nodetool status

For both CentOS 6 and CentOS 7 search the following configuration file:

cassandra-env.sh


This will be inside your <cassandra_home>/conf/ directory
Open this file in edit mode (Make sure you have permission to edit this file. Here I am a root user, so I have permission to edit it)

$ vim <cassandra_home>/conf/cassandra-env.sh


Tips: If you couldn't find this file, use 'locate' command to get the file location.
$ locate cassandra-env.sh


Once you open the file in edit mode, search for:

JVM_OPTS="$JVM_OPTS -Djava.rmi.server.hostname=

Which will probably result in:

# add this if you’re having trouble connecting:
# JVM_OPTS="$JVM_OPTS -Djava.rmi.server.hostname=<public name>"


Uncomment the second line, and add the hostname of your server (replace <public name> with the IP/hostname), or the IP address which you’re connecting to/from.

Then exit and save the file.

Final Note:
Make Sure to restart Cassandra once the changes are done.