Monday, March 7, 2016

Solaris/MySQL: "host not allowed to connect" problem

Edit /etc/mysql/my.cnf file and find a line like:

# vi /etc/mysql/my.conf

bind-address = 127.0.0.1

 

Add another line below stating your public address:

bind-address = 192.168.1.1

 

Where 192.168.1.1 corresponds to the IP for which you want to enable remote connections. 127.0.0.1is the original IP for localhost.

After saving, login into mysql:

mysql -u USERNAME -pPASSWORD

 

Where USERNAME and PASSWORD are the MySQL credentials to access MySQL default database.

Take a look at the MySQL users system table:

mysql> select host, user from mysql.user;

+-----------+------------------+

| host      | user             |

+-----------+------------------+

| 127.0.0.1 | root             |

| localhost | debian-sys-maint |

| localhost | root             |

| ubuntu    | root             |

+-----------+------------------+

4 rows in set (0.00 sec)

 

Fix privileges with the following command:

mysql> update mysql.user set host='%' where host='127.0.0.1';

 

Check the users table again:

mysql> select host, user from mysql.user;

+-----------+------------------+

| host      | user             |

+-----------+------------------+

| %         | root             |

| localhost | debian-sys-maint |

| localhost | root             |

| ubuntu    | root             |

+-----------+------------------+

4 rows in set (0.00 sec)

 

Things are fine, % stands for 'any host'.

Now we logout from mysql with Ctrl+D and restart the server:

# service mysql restart

 

Solaris: Zone stuck in shutting_down state

This situation occurs when we execute a zoneadm -z ZONENAME halt command and, after it, the status of Solaris Local Zone doesn't change from Running state to an Installed state and remaining in Shutting_down state.

To solve this problem, try one or more of following commands at Global Zone until the zone state changes to Installed:

# ps -fz ZONENAME

# zoneadm -z ZONENAME unmount -f

# zoneadm -z ZONENAME reboot -- -s

# pkill -9 -z ZONENAME

 

After the first command, kill the listed processes of ps command.

It after these commands the zone stills in shutting_down or down states, a reboot of Global Zone should be necessary.

Linux: Extract single file from a compressed tarball

In Linux, execute the following command:

# tar -zxvf FILE.tar.gz --wildcards --no-anchored SINGLE_FILE_TO_EXTRACT

Where FILE.tar.gz corresponds to compressed tarball file and SINGLE_FILE_TO_EXTRACT is a desired file to extract to original directory inside current directory.

Solaris / Linux: Change a text string inside file without using an editor

This is useful when we need to change string or sentence inside file without editing it with and editor like vi or vim.

Execute the following command script to change the desired string globally, in other words this syntax changes all corresponding strings inside file:

perl -pi -e 's/OLD_STRING/NEW_STRING/g' FILE

 

Example:

perl -pi -e 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config

 

Solaris: Rename Oracle VM guest (LDOM)

This procedure is about renaming an Oracle VM for SPARC guest (LDOM) that means backup and restore.

 

There is no way to rename LDOM without rebooting.

 

Execute the following commands to backup configuration and delete the old LDOM:

 

#ldm list-constraints -x OLD_LDOM_NAME > NEW_LDOM_NAME.xml

#ldm stop OLD_LDOM_NAME

#ldm unbind OLD_LDOM_NAME

#ldm destroy OLD_LDOM_NAME

 

Edit the XML file and locate and change OLD_LDOM_NAME string to NEW_LDOM_NAME string as desired.

 

#vi NEW_LDOM_NAME.xml

 

Execute the following commands to restore configuration and start the new LDOM with same configuration from the old LDOM:

 

#ldm add-domain -i NEW_LDOM_NAME.xml

#ldm bind NEW_LDOM_NAME

#ldm start NEW_LDOM_NAME

 

Where OLD_LDOM_NAME is the LDOM to change its name and NEW_LDOM_NAME is the new name as desired.

 

IMPORTANT: Put NEW_LDOM_NAME.xml file in a safe place to avoid any problem when restoring configuration of LDOM.

Sunday, March 6, 2016

RHEL / Solaris : RSYNC – sync the data between two servers

How to sync the data between two servers without using SAN replication? Do you have better than RSYNC tool for this job ? I don’t think so, you we will not get better than RSYNC. It uses ‘rsync algorithm’ which provides a very fast method for syncing the directories or filesystems. An important feature of rsync is that the mirroring takes place with only one transmission in each direction and which is not available in other similar programs.

 

Rsync’s default port is 873 and it’s an opensource software. Rsync is available for Unix, Linux and windows operating systems. You can freely download rsync source code from rsync.samba web portal.

 

Here we will see how to sync data between two servers using automated script.

Operating system:                  Red Hat Linux

Source Server IP:                     192.168.10.20 (mylinz1)
Source Server Path
:                /db/oracle/


Destination Server IP:             192.168.10.25 (mylinz2)
Destination Server Path
:         /db/oracle-bck/

 

Before proceeding to rsync part,you need to configure key-less authentication to ensure each can communicate using that.

 

Configuring  key-less authentication

1.      Verify whether your host will allow to perform RSA key-less authentication.If you didn’t get similar output,then  you need to comment out the lines in sshd_config.

 

[root@mylinz1 ~]# cat /etc/ssh/sshd_config |egrep "RSA|Pubkey|Authorized" |grep -v "#"

RSAAuthentication yes

PubkeyAuthentication yes

AuthorizedKeysFile      .ssh/authorized_keys

 

[root@mylinz1 ~]#

 

[root@mylinz2 ~]# cat /etc/ssh/sshd_config |egrep "RSA|Pubkey|Authorized" |grep -v "#"

RSAAuthentication yes

PubkeyAuthentication yes

AuthorizedKeysFile      .ssh/authorized_keys

 

2.      Generate the keygen if you didn’t have one already. Here the user is “root”.

[root@mylinz1 ~]# ssh-keygen

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

94:e6:6f:66:bb:cd:a8:30:4d:90:94:31:ae:64:f6:5e root@mylinz1

The key's randomart image is:

+--[ RSA 2048]----+

|      +o         |

|     o.o .       |

|    + + +        |

|   + o =         |

|    . . E        |

|     . + .       |

|      + . =      |

|       o + =     |

|        ..+.o    |

+-----------------+

 

[root@mylinz1 ~]# cd .ssh/

[root@mylinz1 .ssh]# ls -lrt

total 8

-rw-r--r--. 1 root root  394 Jun 19 00:43 id_rsa.pub

-rw-------. 1 root root 1671 Jun 19 00:43 id_rsa

 

[root@mylinz1 .ssh]#

 

[root@mylinz2 ~]# ssh-keygen

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

e7:a8:19:ac:dd:e3:28:b3:42:00:a0:84:4a:10:4e:fe root@mylinz2

The key's randomart image is:

+--[ RSA 2048]----+

|B+               |

|O.               |

|=o               |

|o .              |

| . E    S .      |

|  .  .   +       |

| .    o . .      |

|  . oo *.        |

|   .o+=.o.       |

+-----------------+

 

[root@mylinz2 ~]# cd .ssh/

[root@mylinz2 .ssh]# ls -lrt

total 12

-rw-r--r--. 1 root root  395 Jun 19 00:17 known_hosts

-rw-------. 1 root root 1675 Jun 19 00:44 id_rsa

-rw-r--r--. 1 root root  394 Jun 19 00:44 id_rsa.pub

 

3.      Share the “id_rsc.pub” file across the servers to enable the ssh key-less authentication.

[root@mylinz1 .ssh]# scp -r id_rsa.pub 192.168.10.25:/root/.ssh/authorized_keys

The authenticity of host '192.168.10.25 (192.168.10.25)' can't be established.

RSA key fingerprint is 5a:56:fd:69:cf:f2:b8:78:b9:67:e8:d0:f2:a4:ef:cb.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '192.168.10.25' (RSA) to the list of known hosts.

root@192.168.10.25's password:

id_rsa.pub                               100%  394     0.4KB/s   00:00

 

[root@mylinz1 .ssh]#

 

[root@mylinz2 .ssh]# scp -r id_rsa.pub 192.168.10.20:/root/.ssh/authorized_keys

root@192.168.10.20's password:

id_rsa.pub                                  100%  394     0.4KB/s   00:00

 

[root@mylinz2 .ssh]#

 

4.      Verify your work.

[root@mylinz2 ~]# ssh 192.168.10.20

Last login: Wed Jun 19 00:42:27 2013 from 192.168.10.101

 

[root@mylinz1 ~]# ssh 192.168.10.25

Last login: Tue Jun 18 23:59:19 2013 from 192.168.10.101

 

[root@mylinz2 ~]#

 

Let’s move to RSYNC part.

RSYNC SCRIPT


Here is the rsync script which will be used for syncing the data between servers’ mylinz1 & mylinz2.


Here I am running script from mylinz1 to sync the data.

[root@mylinz1 ~]# cat rsync_oracle.sh

#!/bin/bash

# RSYNC SCRIPT TO SYNC TWO SERVER'S SPECIFIC DIRECTORIES

# Website:solariscat.blogspot.com

SOURCE_PATH='/db/oracle/'

SOURCE_SERVER='192.168.10.20'  #Added for reference

DESTINATION_PATH='/db/oracle-bck/'

DESTINATION_HOST='192.168.10.25'

DESTINATION_USER='root'

LOGFILE='rsync_oralce.log'

echo $'\n\n' >> $LOGFILE

rsync -av --rsh=ssh $SOURCE_PATH $DESTINATION_USER@$DESTINATION_HOST:$DESTINATION_PATH 2>&1 >> $LOGFILE

echo "Sync Completed at:`/bin/date`" >> $LOGFILE

 

[root@mylinz1 ~]#pwd

/root

 

[root@mylinz1 ~]#chmod 700 rsync_oracle.sh


This script creates log as well with newly synchronized files information.


 

Testing rsync script:

1.      Run the script manually.

[root@mylinz1 ~]#./rsync_oracle.sh

 

2.      Verify the log file.

[root@mylinz1 ~]# tail -1rsync_oralce.log

kshrc

latrace.conf

ld.so.cache

ld.so.conf

libaudit.conf

libuser.conf

sent 160321 bytes  received 1155 bytes  107650.67 bytes/sec

total size is 156728  speedup is 0.97

Completed at:Wed Jun 19 01:02:25 IST 2013

 

[root@mylinz1 oracle]#

 

3.      Create a new file to sync the data to mylinz2 server.

[root@mylinz1 oracle]#cd /db/oracle/

[root@mylinz1 oracle]# touch verify_rsync

[root@mylinz1 oracle]# ls -lrt verify_rsync

-rw-r--r--. 1 root root 0 Jun 19 01:04 verify_rsync

 

[root@mylinz1 oracle]# cd /root

 

[root@mylinz1 ~]# ./rsync_oracle.sh

 

[root@mylinz1 ~]#

 

[root@mylinz1 ~]# tail -10 rsync_oralce.log

sending incremental file list

./

verify_rsync

 

sent 1093 bytes  received 34 bytes  2254.00 bytes/sec

total size is 156728  speedup is 139.07

Completed at:Wed Jun 19 01:05:03 IST 2013

 

[root@mylinz1 ~]#

 

4.      Verify the whether the newly created file synced in mylinz2.

[root@mylinz2 ~]# cd /db/oracle-bck/

 

[root@mylinz2 oracle-bck]# ls -lrt verify_rsync

-rw-r--r--. 1 root root 0 Jun 19 01:04 verify_rsync

 

[root@mylinz2 oracle-bck]#

 

That’s it. Our rsync script is working fine.


Automating sync

If you want to sync the data between two servers automatically on preferred time interval,you can add the script in to crontab.

Add the below line in root’s crontab to sync the data for every 5 minutes. 

 

0,5,10,15,20,25,30,35,40,45,50,55 * * * * /root/rsync.sh 2>&1 > /dev/null

 

That’s it!!!