Monday 30 October 2017

How to change a disk in SVM Solaris volume manager

In this post, I will take my sparc server machine. My Sun Sparc server consist 2 hard disk, let us assume the server has 2 hard disk: c0t0d0 and c0t1d0. We will assume c0t0d0 failed and need to be replaced.

Step by Step Method as described below:

1. In the initial step, we will find that which hard disk is down or faulty. To check this we will used "format" command.

!-[solaris]## format
       0. c0t0d0 <__drive type unknown__>
          /pci@0,600000/pci@0/pci@8/pci@0/scsi@1/sd@0,0
       1. c0t1d0 <SUN146G cyl 14087 alt 2 hd 24 sec 848>
          /pci@0,600000/pci@0/pci@8/pci@0/scsi@1/sd@1,0

If you see the "format" command output, we have two disk "c0t0d0,c0t1d0". Disk "c0t0d0" is in faulty state and it's down, You can see the drive type is in unknown state.

2. If you are running the "metastat" command you can see the status of hard disk which is show status in "need maintenance".

!-[solaris]## metastat    # will show status in "need maintenance"

        flags           first blk       block count
     a        u         16              8192            /dev/dsk/c0t0d0s7
     a        u         8208            8192            /dev/dsk/c0t0d0s7
     a    p  luo        16              8192            /dev/dsk/c0t1d0s7
     a    p  luo        8208            8192            /dev/dsk/c0t1d0s7

!-[solaris]## metadb -d c0t0d0s7
!-[solaris]## metadb

Using above command we delete metadb on failing disk and check that metadb on the other disk.

4. Now, we will unconfigure the corresponding disk which is down right now. This is the main step of this post so you can more careful while running the command which is given below.

!-[solaris]## cfgadm -al
!-[solaris]## cfgadm -f -c unconfigure c0::dsk/c0t0d0
!-[solaris]## cfgadm -al

Using cfgadm command we will unconfigure the c0t0d0 faulty hard disk so that we will replace the down hard disk in next step.

5. Now you can change the faulty disk to new one and reconfigure it again with same name.

!-[solaris]## cfgadm -c configure c0::dsk/c0t0d0
!-[solaris]## cfgadm -al

6. In this steo we will duplicate partitionning schema of first disk to the second and create metadb.

!-[solaris]## prtvtoc /dev/rdsk/c0t1d0s2 | fmthard -s - /dev/rdsk/c0t0d0s2
!-[solaris]## metadb -a -f -c2 /dev/dsk/c0t0d0s7

7. In second last step you will run all the below command for replacement of the failinf SVM partition.

!-[solaris]## metastat
!-[solaris]## metareplace -ef d4 c0t0d0s4
!-[solaris]## metareplace -ef d3 c0t0d0s3
!-[solaris]## metareplace -ef d1 c0t0d0s1
!-[solaris]## metareplace -ef d0 c0t0d0s0
!-[solaris]## metareplace -ef d5 c0t0d0s5
!-[solaris]## metareplace -ef d6 c0t0d0s6
!-[solaris]## metasync d0
!-[solaris]## metasync d1
!-[solaris]## metasync d3
!-[solaris]## metasync d4
!-[solaris]## metasync d5
!-[solaris]## metasync d6
!-[solaris]## metasync d7

8. In final step you need to make the disk bootable so that operating system will be boot on the mirror disk.

!-[solaris]## installboot /usr/platform/`uname -i`/lib/fs/ufs/bootblk /dev/rdsk/c0t0d0s0

Using this step you can make a disk bootable. I hope this post is useful for you. You are requested to please comment on the post if you have any issue, I will try to back you with my answer.

Thursday 26 October 2017

Useful SQL command for MySQL database on Linux Operating System

This post related to MySQL database SQL command which is used in daily database work by database administrator.

Please find the below points which is very useful to database admin on Linux operating system.

How to create new database:

 CREATE DATABASE <DATABASENAME>;

 e.g. CREATE DATABASE XYZ;

In this example I have created the "XYZ" named database, you can replace database name according to your choice.

How to create mater user with all level access to all available databases:

 GRANT ALL ON *.* TO <USERNAME> IDENTIFIED BY '<PASSWORD>';
 e.g.  GRANT ALL ON *.* TO TESTDBUSER IDENTIFIED BY 'TESTDBUSER';

In this example I used "testdbuser" MySQL user on the server.

How to take backup (dump) of a database:

For this command you need not to login into the database. Once you login on the database please run the below command to take a dump of server.

 mysqldump --lock-all-tables -u <USERNAME> -p -h <DATABASESERVERNAME/IP ADDRESS> <DATABASENAME> > <NEWDUMPFILENAME>.sql

 e.g. mysqldump --lock-all-tables -u ABC -p -h MACHINE1 XYZ > XYZ_16022017.sql

After this command you have to provide DB password only and dump will be done in the folder in which u are working currently.

How to take backup (dump) of a table's:

For this command you need not to login into the database.

 mysqldump -u <USERNAME> -p <DATABASENAME> <TABLENAME> > <NEWDUMPFILENAME>.sql

 e.g. mysqldump -u testdbuser -p testdb test_book > test.sql

After this command you have to provide DB password only and dump will be done in the folder in which u are working currently. for dumping multiple table use space between the table names.

How to run a database dump to another machine:

Go to the folder in which sql dump file is placed and then connect with your Database in which you want to run dump and then run below command.

 source <FILENAME>.sql;

 e.g source XYZ_16022017.sql;

How to take dump only triggers and procedure from database:

 mysqldump --routines --no-create-info --no-data --no-create-db --skip-opt -u <USERNAME> -p <DATABASENAME> > <NEWDUMPFILENAME>.sql

 e.g. mysqldump --routines --no-create-info --no-data --no-create-db --skip-opt -u TESTDBSUER -p XYZ > XYZ_16022017.sql

After this command you have to provide DB password only and dump will be done in the folder in which u are working currently.

How to show procedure/function code:

 SHOW CREATE PROCEDURE <STORED PROCEDURE/FUNCTION NAME>\G

 e.g. SHOW CREATE PROCEDURE FLIGHT_INVOICETOSAP\G;

How to increase filed width of a table attribute:

 ALTER TABLE <TABLENAME> CHANGE <EXISTING_FIELD_NAME> <NEW_FIELD_NAME> <DATATYPE>(<NEW_FIELD_WIDTH>);

 e.g. ALTER TABLE TRILOK CHANGE PASSENGER_NO PASSENGER_NUMBER VARCHAR(30);

field name and data type change is not recommended.

How to display all existing databases:

 SHOW DATABASES;

Using this command you can show all the created database list on the Linux server.

How to display all existing tables:

 SHOW TABLES;
 SHOW TABLES LIKE '<CHARACTERS>%';

Using this command you can check all the tables which is created on the database.

How to recover a MySQL root password:

This is one of the best way to recover the MySQL root password if you forget. I always used below method to reset the root password.
Stop the MySQL server process.

  # /etc/init.d/mysql stop
Start again with no grant tables.

  # mysqld_safe --skip-grant-tables &
Login to MySQL as root. Set new password.

  # mysql -u root
  mysql> use mysql;
  mysql> update user set password=PASSWORD("newrootpassword") where User='root';
  mysql> flush privileges;
  mysql> quit
Exit MySQL and restart MySQL server.

  # /etc/init.d/mysql stop
  # /etc/init.d/mysql start
Set a root password if there is on root password.

  # mysqladmin -u root password newpassword
Update a root password.

  # mysqladmin -u root -p oldpassword newpassword

How to grant privileges to a user:

If we need to provide the privileges to user we will use below two method. I will describe the step by step method for this one.

METHOD 1

Allow the user "bob" to connect to the server from localhost using the password "passwd". Login as root. Switch to the MySQL db. Give privs. Update privs.

  # mysql -u root -p
  mysql> use mysql;
  mysql> grant usage on *.* to bob@localhost identified by 'passwd';
  mysql> flush privileges;

Give user privileges for a db. Login as root. Switch to the MySQL db. Grant privs. Update privs.

  # mysql -u root -p
  mysql> use mysql;
  mysql>INSERT INTO user (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv) VALUES ('%','databasename','username','Y','Y','Y','Y','Y','N');
  mysql> flush privileges;

METHOD 2

  mysql> grant all privileges on databasename.* to username@localhost;
  mysql> flush privileges;

To update info already in a table.

Load a CSV file into a table:

 mysql> LOAD DATA INFILE '/tmp/filename.csv' replace INTO TABLE [table name] FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (field1,field2,field3);

Dump all databases for backup:

Backup file is SQL commands to recreate all databases.

  # [mysql dir]/bin/mysqldump -u root -ppassword --opt >/tmp/alldatabases.sql

Dump one database for backup.

  # [mysql dir]/bin/mysqldump -u username -p password --databases databasename >/tmp/databasename.sql

Dump a table from a database.

  # [mysql dir]/bin/mysqldump -c -u username -p password databasename tablename > /tmp/databasename.tablename.sql

Restore database (or database table) from backup.

  # [mysql dir]/bin/mysql -u username -p password databasename < /tmp/databasename.sql
  Create Table Example 1.

Using above method we can take database back very fast. I hope through this post you can easily able to create MySQL database, MySQL dump, table creation etc work.

Friday 20 October 2017

Solaris zone: error: net0: failed to create VNIC: operation not supported

In this post, I will discuss with you one of the most interesting error which I am facing when I boot the local zone on Solaris 11.3. The description of this interesting issue as describe below.

Description of error:

!-[solaris]# zoneadm -z sun01 boot

zone 'sun01': error: net0: failed to create VNIC: operation not supported

zoneadm: zone sun01: call to zoneadmd(1M) failed: zoneadmd(1M

I have try to create and configure the  VNIC on Solaris 11.3 operating server but it get failed with the same error.

!-[solaris]#dladm create-vnic -l net0 vnic01

dladm: vnic creation failed: operation not supported

If you are also facing a such error while booting the local zone on solaris 11 server, then please use the below solution to resolve such issues.

Solution of error:

➥ This error "failed to create VNIC: operation not supported" would normally come when there are not enough mac addresses to assign to the zone. So now we need to add alternate mac addresses to the network interface.So before adding the new mac address we will stop LDM.

!-[solaris]#ldm list-domain

NAME            STATE     FLAGS  CONS   VCPU MEMORY  UTIL NORM UPTIME

primary         active    -n-cv- UART   8    8G      2.0% 2.0% 41d 20h 14m

0004fb0000060000ff1d3d8336112f6f active    -n---- 5001   50   64G     0.1% 0.1% 18h 23m

➥ Now log in to the Solaris global zone and check if net0 have additional MAC addresses or not. Please use the below command to check the status.

!-[solaris]# dladm show-phys -m

LINK               SLOT    ADDRESS           INUSE CLIENT

net0               primary 0:21:f6:d6:d3:e5  yes  net0

                   1       0:14:4f:f9:6d:8d  no   --

                   2       0:14:4f:fb:10:2b  no   --

                   3       0:14:4f:f9:41:d6  no   --

                   4       0:14:4f:f8:dd:c8  no   --

net1               primary 0:21:f6:51:be:4d  yes  net1

➥ Now zone will start without any issue, as we have assigned the new mac address to this zone.

!-[solaris]# zoneadm -z sun01 start

Please let me know if you are facing any issue regarding this error.

How to mount CIFS file system on Linux Operating Server

Step by Step method for Mount CIFS on Linux Server:

➤ In the initial step we will gather all rpm's or packages information which is required for CIFS file system.

[root@localhost]# rpm -qa | grep cifs 
cifs-utils-4.8.1-20.el6.x86_64

if you see the above output, this packages is required for CIFS file system on Linux system. So you can install this rpm using rpm command if you have rpm packages on the server otherwise you will install the packages using YUM utility.

[root@localhost]#rpm -ivh cifs-utils-4.8.1-20.el6.x86_64.rpm

if you are using YUM, then please install the packages using below command.

[root@localhost]#yum install cifs-utils*

it is installed all required dependency related to CIFS file system.

➤ In this step, we will create the mount point on the server where we need to mount the CIFS file system.

[root@localhost]# mkdir -p /backup/cifs

We will create the above mount directory where i will mount the file system.

➤ Now, we will create a CIFS user and assign a password so the user can access mount folder.

[root@localhost]# touch /etc/cifspasswd
[root@localhost]# chmod 600 /etc/cifspasswd

[root@localhost]#vi /etc/cifspasswd

user=castwebsvc
password=*******

➤ In this step we need to make a permanent entry of mounted file system so once we reboot the machine mounted file system not umount.

[root@localhost]# vi /etc/fstab

ADD fstab entry :

//WindowsServer/share /mount/point cifs rw,mand,user=USER,password=PASS 0 0

Example :
//192.168.0.1/CAST_data4/AICCodeUpload  /backup/cifs cifs   rw,mand,credentials=/etc/cifspasswd         0 0

You can take an example for your system. Please change the mount point as per your requirement.

➤ In the final step you need to mount the file system using below command.

[root@localhost]# mount /backup/cifs
[root@localhost]# mount -a

Using above command the CIFS file system has been mounted successfully.

How to configure NTP server and client on Solaris 10 and Solaris 11

As you know NTP ( Network time Protocol) is one of the oldest internet protocol still in use and it allows the synchronization of computer clocks distributing UTC (Coordinated Universal Time) over the network.

NTP Service on Solaris 10 and Solaris 11:

Solaris 10 used the SMF utility (Service Management Facility) and the NTP service is now managed by SMF (Service Management Facility). NTP daemon configured using Service management facility (svc:/network/ntp:default) and a bunch of sample ntp.conf files to quickly configure a machine as a client or as a server. On Solaris 11 only ships with NTP v. 4, the NTP v. 4 service is identified by the name ntp4. You can check the ntp status using below command.

!-[solaris]# svcs status ntp

STATE  STIME   FMRI
online 10:14:23 svc:/network/ntp:default

If you see the above command output it is shown that network time protocol services is enable and online on the server.

Steps for Configuring a NTP client:

Suppose your machine is just a client machine, then you can just take the /etc/inet/ntp.client file and copy it to /etc/inet/ntp.conf.

multicastclient 127.0.0.1

If you see the configuration it's a passive configuration for a Server host which listens for NTP server putting packets on the NTP multicast network, 127.0.0.1. If your machine is on LAN without NTP server then in that case we are not recveied any packet and for this we need to use Public NTP server for host.

In my case, I'm using the Indian pool in.pool.ntp.org and my configuration file contains:

server 2.in.pool.ntp.org
server 1.asia.pool.ntp.org
server 3.asia.pool.ntp.org

Normally NTP requires a poll period to elapse before starting synchronizing your clock. If you want NTP to start immediately, which you most probably will if you're configuring a desktop environment, you can take advantage of iburst keyword, introduced in NTP v. 4: it instructs NTP to start the synchronization almost right away.

server 2.in.pool.ntp.org ibrust
server 1.asia.pool.ntp.org ibrust
server 3.asia.pool.ntp.org ibrust

You must make sure you're configuring NTP implementation corresponding to the syntax you're using.

Setting up the drift file:

The last thing which is remaining for NTP server setup in the client machine is to set up  drift file location. On my machine it is 

driftfile /var/ntp/ntp.drift

After setup the drift file configuration we will start the NTP servivce again 

!-[solaris]# svcadm restart svc:/network/ntp:default
!-[solaris]# svcs status svc:/network/ntp:default
STATE  STIME   FMRI
online 12:20:12 svc:/network/ntp:default 

Once the service is running, you can check which server you're using with ntpq, Please run the below command to check the ntpq.

!-[solaris]# ntpq -p

Setting up an NTP server:

Now in above step you see the NTP service has been started successfully, so now, you'll probably want to setup all of your machines.

If you're in a LAN, you can setup an internal NTP server which will provide data to other clients on your LAN. As before, you can take inspiration from the server configuration file shipped with Solaris 10 or Solaris 11, /etc/inet/ntp.server.

After setting up the drift file and the clients you're going to use, you can examine the other options and fine-tune them at your taste. Let's give a quick look at it.

server 127.127.XType.0

Now you have configured the NTP server properly. Please comment on the post if you have any suggestion.