Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Monday, May 8, 2017

Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

Hello Friends,

In this post, I would explain to you how to resolve one of the most intreseting issue on linux servers "Kernel Panic". I think the linux lovers much awaited such issue while they are working on Unix troubleshooting part.

As everyone knows Kernel are most importent part of any operating system and if it is crashed that's means your system crashed.

Normally kernel panic occur when you upgrade the server or upgrade the packages on the server. Here, you can find one of the Kernel panic issue as describe below.

Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
Pid: 1, comm: swapper Not tainted 2.6.32-502.el6.x86_64 #1
Call Trace:
 [<ffffffff815292bc>] ? panic+0xa7/0x16f
 [<ffffffff81c2b432>] ? mount_block_root+0x216/0x2cb
 [<ffffffff81002930>] ? bstat+0x2b0/0x980
 [<ffffffff81c2b53d>] ? mount_root+0x56/0x5a
 [<ffffffff81c2b6b1>] ? prepare_namespace+0x170/0x1a9
 [<ffffffff81c2a92a>] ? kernel_init+0x2e1/0x2f7
 [<ffffffff8100c20a>] ? child_rip+0xa/0x20
 [<ffffffff81c2a649>] ? kernel_init+0x0/0x2f7
 [<ffffffff8100c200>] ? child_rip+0x0/0x20


Solution : Normally this issue occur while you upgrade your server using yum and after reboot server is not boot due to kernel panic problem. This problem occur while kernel version has not been changed properly.

You can boot your linux server in grup mode and check the kernel and initrd paramtere. Match both the parameter if they are using same kernel version. During upgrade the initrd version normally not changed so you can manually change the correct kernel version entry in this file.

Once you modified the initrd files boot the server and make a same changes in grub.conf file too, otherwise once you take a reboot or shutdown the machine same kerenl panic error will occur.

[root@localhost]# vi /etc/grub.conf

#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS 6 (2.6.32-504.el6.x86_64)
        root (hd0,0)
        kernel /vmlinuz-2.6.32-504.el6.x86_64 ro root=/dev/mapper/vstorage-root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=vstorage/root  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
        initrd /initramfs-2.6.32-504.el6.x86_64.img

In above example, the default value 0 identifies the first title option to be used as default, the corresponding kernel version in title option line as 2.6.32-504.el6.x86_64 and the initramfs image file as initramfs-2.6.32-504.el6.x86_64.img. 

Before changing thing please take a backup of grub.conf file. now you can rename the kernel version in the initrd line and matched the same version at both the line and reboot the server, after reboot your linux machine will boot normally.

Hope your kernel panic issue will be resolved after reading this post. Please let me know if you are still facing this issue, I would try to help you.

How To Fix “Device eth0 does not seem to be present, delaying initialization” Error

This Ethernet card error is normally occur on Linux operating system like CentOS, Red Hat Linux etc. When you try to up the Ethernet card it is showing you the above topic error.

So in this post, we will provide you the step by step solutions and troubleshoot all the issue related this error.

In the initial step, you will check which Ethernet card is down , for this you can run the "ifconfig -a" command. Using this command you can check how many internet card is present on the server and on which Ethernet card used IP address.

Let's suppose you are using eth0 on your machine, and if this Ethernet card not taking any ip address and now show on your device that means it is down right now, so please try to start Eth0 device as given below command.

[root@localhost]# ifup eth0
Device eth0 does not seem to be present, delaying initialization

If your internet card show such issue that means you have an issue with MAC address. So in this post I would explain you how to resolve such issue.

1. In this step, please check the MAC Addresses are set correctly or not. For checking this you need to go the network card directory "/etc/sysconfig/network-scripts"

[root@localhost]# cd /etc/sysconfig/network-scripts

[root@localhost]# cat ifcfg-eth0

HWADDR=”00:15:5D:00:91:91”

In the configuration file, you can see the current hardware address of eth0 card, I have show you only HWADDR entry of my eth0 file. In this directory you can see if other Ethernet card is present or not. In my Linux machine i have two Ethernet card , please find the below second Ethernet card MAC address.

[root@localhost]# cat ifcfg-eth1

HWADDR=”00:15:5D:00:91:90”

2. Now we will see which link is present on the system currently and which is not active, for this you can use the below command to check the status.

[root@localhost]# ip -o link

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN \    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000\    link/ether 00:15:5D:00:91:90 brd ff:ff:ff:ff:ff:ff

3: eth2: mtu 1500 qdisc   pfifo_fast state UP qlen 1000\ link/ether 00:15:5D:00:91:91 brd ff:ff:ff:ff:ff:ff

Here, no eth1 but there is an eth2 present on the system, so might be problem is that the eth0 is renamed to eth2 but we will confirm with below command.

[root@localhost]# dmesg | grep eth0

udev: renamed network interface eth0 to eth2
udev: renamed network interface rename3 to eth0

From this command it shows that udev rename the network interface, so in the next step we will remove the wrong entry and configure the Ethernet card 

3. Now please open the network rules file to confirm the mac address. Please open this file "/etc/udev/rules.d/70-persistent-net.rules" 

[root@localhost]# cat /etc/udev/rules.d/70-persistent-net.rules

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:15:5d:00:91:90", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:15:5d:00:91:91", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:15:5d:00:91:91", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

Looks like there are multiple entries for the same MAC address. Removed the incorrect entry and restart the interface using below command.

[root@localhost]# ifup eth0

Now you eth0 card is up and if you are running "ifconfig -a" command you can see the eth0 card with mac address. 

Hope you are get the solution of the above issue, also please let me know if you have any other issue.

Tuesday, April 4, 2017

How to Configure Proxy Settings in Linux

In this post, I will explain , how we set or configure the proxy setting in Linux server. Usually when you work on the cooperate server you work behind the proxy. So if you are trying to download any packages or software on the Linux operating system machine, you need to configure the proxy on your browser or on system profile.

1. If you want to set http_proxy shell variable on Linux terminal or bash shell, then please use the below command or method to set the proxy settings on terminal.

# export http_proxy=http://Proxy_IP:Proxyport

or

# export http_proxy=http://Proxy_Domain:ProxyPort

You can use above command to set the proxy on bash shell or on terminal. You can use Proxy IP as well as Proxy DNS name to configure the proxy on shell. In my case I have use proxy IP on my server.

#export http_proxy=http://192.168.1.70:8080

If you want to use https proxy then please run the below command to set the proxy settings on bash or any other shell.

#export https_proxy=https://Proxy_IP:ProxyPort

or

#export https_proxy=https://Proxy_Domain:ProxyPort

You can use this proxy on open shell only if you close the terminal or shell then you need to set proxy variable again.

If your proxy use authentication then you need to give proxy user name and password while you are running the above command.

#export http_proxy=http://Proxy_User:Proxy_Password@Proxy_IP:Port

2. If you want to setup proxy variable for all users then you need to set proxy environment as a global variable. To do this you need to set proxy variable on /etc/profile file.

# vi /etc/profile

export http_proxy=http://Proxy_IP:Proxyport

or

export http_proxy=http://Proxy_User:Proxy_Password@Proxy_IP:Port

3. If you want to set the proxy access to a specific user then you need to set the variable on their bash profile.

# vi /home/vibhor/.bash_profile

Append the following line:

export http_proxy=http://Proxy_User:Proxy_Password@Proxy_IP:Port

or 

export http_proxy=http://Proxy_IP:Proxyport

You can use the https proxy or ftp proxy also only required to change the name of the varibale. 

Monday, March 20, 2017

10 Practical Examples of RPM Commands in Linux

In this post, I will explain you the usage of RPM (Red Hat Package Manager) command with an example. RPM commands are widely used in Linux operating system to install, remove or update the packages on operating system.

RPM (Red Hat Package Manager) is a default open source and package management utlity which is widely used on Redhat, CentOS linux operating system. You can install , remove, upgrade the packages using this commnad. In this post We will explain each syntax with an example so you can understand how this command is very useful on linux operating system. So here, we will explain best 20 example which is related to Red Hat Package Manager.

1. How to Check an RPM Signature Package:

This command with syntax is used for to check the PGP signature of packages before installing them on your Linux systems and make sure its integrity and origin is fine.

[root@locahost]# rpm --checksig vsftpd-2.2.2-14.el6.x86_64.rpm
vsftpd-2.2.2-14.el6.x86_64.rpm: rsa sha1 (md5) pgp md5 OK

2. How to Install an RPM Package:

Using below syntax you can install the rpm packages on the linux system.

[root@localhost]# rpm -ivh vsftpd-2.2.2-14.el6.x86_64.rpm
Preparing...               ########################################### [100%]
1:vsftpd                    ########################################### [100%]

On the above syantx we are using "-i" option to install the rpm packages on Linux operating system.

3. How to check dependencies of RPM Package before Installing:

If you want to check which packages or dependency is required for RPM packages then you can run the below command to check the dependency.

[root@localhost]# rpm -qpR samba-winbind-3.6.23-12.el6.x86_64.rpm

Here, you can find the syantx meaning of the above command.
-q : Query a package.
-p : List capabilities this package provides.
-R: List capabilities on which this package depends.

4. How to Install a RPM Package Without Dependencies:

If you want to install the packages without any dependency please use the below syntax.

[root@localhost]# rpm -ivh --nodeps samba-winbind-3.6.23-12.el6.x86_64.rpm
Preparing...                       ########################################### [100%]
1:Samba-winbind             ########################################### [100%]

The above command forcefully install rpm package by ignoring dependencies errors, but if those dependency files are missing, then the program will not work at all, until you install them.

5. How to check an Installed RPM Package:

If you want to check which RPM package is installed on the operating system then please use -q option with package name.

[root@localhost]# rpm -q samba
package samba is not installed

If you see the samba packages is not installed on my system so it is show you this message.

[root@localhost]# rpm -q vsftpd
vsftpd-2.2.2-14.el6.x86_64

You can see the above ftp server packages is installed on the system.

6. How to Upgrade a RPM Package:

If you want to upgrade any RPM packages then please use "-U" syntax with rpm name.

[root@localhost]# rpm -Uvh vsftpd-3.0.2-11.el6.x86_64.rpm
Preparing...             ########################################### [100%]
1:vsftpd                 ########################################### [100%]

If you see the above example the packages is upgrade with the new version of vsftpd.

7. How to Remove a RPM Package:

If you want to uninstall or remove the package from the server then please use "-e" erase option is used to remove package.

[root@localhost]# rpm -evv vsftpd

Using above command we can remove the packages with all dependency.

8. How to Remove an RPM Package Without Dependencies:

If you want to remove installed packages without any dependecy then use the below syntax to remove the rpm.

[root@localhost]# rpm -ev --nodeps vsftpd

Using above syntax "--nodeps" we can remove the packages without dependency.

9. How to Import an RPM GPG key:

If you want to import the RPM GPG key then please verify RHEL/CentOS/Fedora packages, you must import the GPG key.

[root@localhost]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

So using above syantx we can import the GPG key on the server.

10. How to List all Imported RPM GPG keys:

To print all the imported GPG keys in your system, use the following command.

[root@localhost]# rpm -qa gpg-pubkey*
gpg-pubkey-0608b895-4bd22942
gpg-pubkey-7fac5991-4615767f

You can see the above entry these are the GPG key which is installed on the server.

Tuesday, March 14, 2017

How to disable the SELinux in Linux machine

In this post, I will explain you the how to disable SELINUX on Redhat or CentOS Operating system. Before going to main work first we need to understand what is SELINUX and how its work on Linux enviorement.

Security-enhanced Linux (SELINUX): SELinux is know as Security enhanced linux system which is the security feature of the Linux kernel system. It is define the security Policy which makes system proctative agaginst the misconfiguration of the daemons. SELinux running in 3 modes which is disabled, enabled and permissive. We will explain these mode in configuration steps.

How to disable SELinux on Linux system:

1. In the first step you can check the current status of SELinux. To do this please run the below command.

[redhat]# getenforce
Enabled

"getenforce" command is used for checking the current status of SELinux.

2. As you see on my machine when I run the above command my SElinux is enabled, So in this step we will change the SELinux mode.

[redhat]# vi /etc/sysconfig/selinux

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

Normally selinux configuration file you can found on the above location. You can edit the SELINUX entry to disabled. All the command is run by super user "root" only.

3. Once you change the entry in SELinux configuration file then for permanent effect you need to take a reboot of the system.

[redhat]#init 6

Once you reboot the server all the configuration files changes has been done.

4. In the last step you will run the "getenforce" command again to verify the new status of SELinux.
[redhat]# getenforce
Disabled

If you comparison the both step 1 and this step output you can found that SELinux policy is not disabled on the Linux operating system.

Friday, March 10, 2017

How to mount CIFS file system on Linux Server

Hope you are doing well at your end. In this post, I will explain how we mount the CIFS file system on Linux operating system.

Normally on linux machine if we mount the any other linux machine folder is quite easiy in comparision to mount the window shared folder on linux machine. So let's going to final topic where i will explain step by step method to mount the CFS folder on Linux server.

Step by Step method for Mount CIFS on Linux Server:

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

redhat# 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.

redhat#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.

redhat#yum install cifs-utils*

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

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

redhat# mkdir -p /backup/cifs

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

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

redhat# touch /etc/cifspasswd
redhat# chmod 600 /etc/cifspasswd

redhat#vi /etc/cifspasswd

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

4. 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.

redhat# 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.

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

redhat# mount /backup/cifs
redhat# mount -a

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

Monday, March 6, 2017

How to configure YUM Server in Red hat linux 6

In this post, We will get know how to install or configure the Yum server on Red Hat Linux 6 operating system.

As you know their are several ways using which we can install the packages or rpm on the server. Please find the below step by step method to install the packages using YUM.

1. In the initial step please install the cd in cdrom and open a terminal for mount the cd in /mnt directory.

#mount –o loop /dev/cdrom /mnt

Here, we mount the CD of ISO in /mnt direcoty. You must enough space on /mnt folder before mounting this ISO.

2. Now in second step we will create a directory where we make a YUM repository.

#mkdir /rhel6

In this directory we will install all the YUM configuration files.

3. Now we will copy all the files from mount folder to newly created folder.

#cp –rvf /mn/* /rhel6

4. In this step, we will install the required packages which is required for create a repo on the server.

#cd /rhel6/Packages 
#rpm –ivh python*
#rpm –ivh createrepo*

These above packages is required for repostiory creation in YUM server.

5. Now move back again repodata directory and create a new repo for repository installation.

#createrepo  –v /rhel6/Packages

This is install all the packages on /rhel6 directory which is used for YUM configuration.

6. In this step we will create a new repo files in this directory.

#cd /etc/yum.repos.d/
#rm –rf *
#vi ss.repo

[Packages]
baseurl=file:///rhel6/Packages 
gpgcheck=0
enable=1

In this step if any exsiting repo if you found please remove it and create a new repo.

7. In the final step we will clean the repo and check the list of all rpm's using below commands.

#yum clean all
#yum list

Hope, using this post, you can easily install and configured the packages on the Red Hat Operating system. Please comment on the post if you encouter any issue.

Monday, February 20, 2017

How to Increase or extend the size of a Linux LVM by adding a new hard disk

Hello Friends,

This post will cover how to increase the disk space for a VMware virtual machine running Linux that is using logical volume manager (LVM). Firstly we will add a new disk to the virtual machine and then extend the original LVM over this additional space.

As there are a number of different ways to increase disk space but I have also posted simple and step by step method. Using this method I am sure you will increase the space easily.

1. First of all before adding any hard disk please run the below command to check the how much space is currently left on the VG group.

#vgdisplay 









If you see above image you can found the volume group name, in my case it is "rootvg".

2. Now run the below command to see the existing LVM disk is currently used in LVM.

#fdisk -l














You can see the above output, the /dev/sda2 hard disk is in used for existing LVM. Now you can add new hard disk on the server.

3. Once you added the new hard disk on the server to increase the size on Linux LVM, lets assume the new hard disk labelled is /dev/sdb. In this step we will need to partition the new hard disk so we can use it.

#fdisk /dev/sdb

It should show us below message to us for next selection.

root@localhost:~# fdisk /dev/sdb
Command (m for help): n

Please select the "n" for adding a new partition. Once we will select the "n" for new partition it is show to us below screen.

Command action
   e   extended
   p   primary partition (1-4)p

We will select the "p" for primary partition so we will add new had disk /dev/sdb as a primary partition.
----------------------------------------------------------------------------------------
Partition number (1-4): 1

First cylinder (1-2610, default 1): "enter"
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): "enter"
Using default value 2610
----------------------------------------------------------------------------------------
In above screen, we will select 1 for primary partition and make a default settings.

‘t’ is selected to change to a partitions system ID, in this case we change to ’1′ automatically as this is currently our only partition.
----------------------------------------------------------------------------------------
Command (m for help): t
Selected partition 1
----------------------------------------------------------------------------------------
The hex code ’8e’ was entered as this is the code for a Linux LVM which is what we want this partition to be, as we will be joining it with the original Linux LVM which is currently using /dev/sda4.
----------------------------------------------------------------------------------------
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
----------------------------------------------------------------------------------------
‘w’ is used to write the table to disk and exit, all changes that have been done will be saved and then you will be exited from fdisk.
----------------------------------------------------------------------------------------
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
----------------------------------------------------------------------------------------

By using “fdisk -l” now you will be able to see that /dev/sdb1 is listed, this is the new partition created on our newly added /dev/sdb disk.

4. Now we will create a physical volume with this newly added hard disk /dev/sdb1. For physical volume creation we will use "pvcreate" command.

#pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created.

In above command output, you can see the /dev/sdb1 physical volume group has been created.

5. Now the most important steps of this post is using physical volume you can extend or create a new volume group.

If you want to extend the logical volume size of existing Volume group then please use the below command and method. 

#vgextend test /dev/sdb1

In my case my VG name is "test" so I will extend the space in existing VG "test".

If you want to create the new logical voume and want to add physical volume in new VG, please use the below command and method.

#vgcreate rootvg /dev/sdb1

In this case my new VG name is "rootvg".

So, as per my this post, you can add new hard disk in to existing volume group or newly created volume group. Using this volume group you can create or extend the Linux LVM size.

How to check Operating Systems Version is 64-bit or 32-Bit

Hello Friends,

In this post, you can see how we will check the operating system is 32 bit or 64 bit. Normally when we download any software on Unix platform they have dependency regarding the operating system version. So after following my this post you can easily get the information about the operating system version information.
When you work on Unix operating system then you must know the version of operating system. Because without getting exact version of OS, you can not install the packages on the Linux system.

Here, I mentioned the command and their output using these commands you can easily found the version of operating system. It is 32 bit or 64 bit.

Linux Operating System:

#uname –a
Linux vibhor 3.10.0-229.el7.x86_64 #1 SMP Fri Mar 6 11:36:42 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

#uname  -m
x86_64

If the output has "x86_64",the environment is 64 bit.

Solaris Operating System:

#isainfo options

-v         Prints detailed information about the other options
-b         Prints the number of bits in the address space of the native instruction set.
-n         Prints the name of the native instruction set used by portable applications supported by the current version of the OS.
-k         Prints the name of the instruction set or sets that are used by the OS kernel components such as device drivers and STREAMS modules.

[vibhor]# isainfo -v

64-bit sparcv9 applications
        ima fmaf vis2 vis popc
32-bit sparc applications
        ima fmaf vis2 vis popc v8plus div32 mul32

[vibhor]# isainfo -b
64

[vibhor]#isainfo
sparcv9 sparc

The output for the above command should be sparcv9 sparc for a 64-bit operating System.

AIX Operating System:

vibhor:/> getconf -a | grep KERN
KERNEL_BITMODE:                         64

vibhor:/> bootinfo -y
64

The output of the above command should be 64 for a 64-bit hardware. The command must be executed as root.

Note: on AIX, the -y option will specify if the hardware is 32- or 64-bit mode while bootinfo -k will specify if the kernel is 32- or 64-bit (this command must be run as root).

HP-UX Operating system:
         
 hpx:/> getconf KERNEL_BITS
 64
         
The output of the above command should be 64 for a 64-bit operating system.

Friday, February 17, 2017

SQL command for MySQL database on Linux operating system

In this post, i will explain you how we will create, import, export & backup of MySQL database.

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 VIBHOR;

In this example I have created the "vibhor" 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 VIBHOR > VIBHOR_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 VIBHOR_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 VIBHOR > VIBHOR_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.

Wednesday, February 15, 2017

Step by Step NFS Server and Client Configuration in HP-UX

In this post, I will explain step by step method of NFS server and client configuration on HP-UX operating system. Network File System is a distriubted file system which allows a client computer to access a file system that shared on another computer’s or server's.

NFS server is configured on the server locally on attached physically disk. On my HP-UX server i will configured the NFS server and for client you can use same HP-UX operating machine or other linux machine.

We can used the below NFS server IP and client IP on my own HP-UX machine and Linux machine.

NFS Server : 10.135.0.27 and share folder /backup
NFS Client : 10.135.0.2 and mount point /home/backup

Steps involved to configure the NFS Server:

1. First we will make sure both NFS server(10.135.0.27) and client(10.135.0.2) are accessible. After that we will make an entry in /etc/hosts or Configure it in DNS to resolve the IP if you use server name instead of IP address. But in our case we will use IP address instead of name.

hpx:/>vi /etc/hosts

10.135.0.27 hpxnfsserver
10.135.0.2 hpxnfsclient

The /etc/hosts entry would we same on both server and client machine so it can be accessible to each other.


2. In second step we will identify the folder to be export from server to the client. On my HP-UX server machine, I am going to export the folder /backup.

3. Now we will change the shared folder permission, normally we don't provide the read/write access to shared folder but in my case for testing purpose i will provide the (777) permission so that NFS client user can read/write the data on shared folder.

hpx:/>#chmod 777 /backup

4. In this step we change the NFS_SERVER=1 to enable your server to act as a NFS Server in the configuration file /etc/rc.config.d/nfsconf

hpx:/>vi /etc/rc.config.d/nfsconf
Change the NFS_SERVER parameter as follow.
NFS_SERVER=1
PCNFS_SERVER=0
START_NFSLOGD=0
START_MOUNTD=1
MOUNTD_OPTIONS=""
Save and exit the file.

5. In final step we will add an entry of our shared folder in the export file /etc/dfs/dfstab with proper permission.

#vi /etc/dfs/dfstab
/usr/sbin/share -F nfs -o rw -d “Test directory” /backup

Save and exit the file.

If you see the above line "/backup is shared folder and we will provide the "rw" read/write access to this folder.

6. Now please restart the nfs service on NFS server and make it permanent so after reboot of HP-UX server the shared folder is not umount.

hpx:/>/sbin/init.d/nfs.server stop
hpx:/>/sbin/init.d/nfs.server start

7. Using below command we can check the NFS folder is shared or not and also we can ensure which client can access this machine.

hpx:/>/usr/sbin/exportfs -av

shareall -F nfs

Steps involved to access the NFS shared folder to the NFS clients:

1. Now for NFS client configuration i will login on my Linux machine.In my case i will use my Centos machine as a client, You can select your NFS client machine as per your requirement.

2. On client machine, please select the mount point to where we have to mount the NFS shared folder /backup which we exported from NFS Server 10.135.0.27. On my Linux machine, I will mount it on /home/backup.

3. In this step we will verify the list of shares available on client machine. Please use the below "showmount" command to check which NFS shared folder is accessible.

hpx:/>showmount -e 10.135.0.27
export list for 10.135.0.27
/backup

If we get the output, server side export configuration doesnt have any problem between nfs server and client.

3. In next step we will mount the nfs share locally on our desintation mount point folder.

hpx:/>mount 10.135.0.27:/backup /home/backup

4. In final step, you can check the NFS mount folder using "bdf" command. It is show you the mount folder where all existing data is store. For testing purpose you can create any file on /home/backup.

Hope, you will like my this post, it is cover all the installation and configuration part step by step. Please let me know if you encouter any issue during NFS configuration on HP-UX machine.

Friday, February 10, 2017

How to Create Local YUM Repository on CentOS 7 / RHEL 7

In this post, I describes how to setup a local Yum repository on CentOS 7 & RHEL 7 server operating system.

The local YUM repository is the most significant way to perform any type of package installation without any internet connection. If you have to install software, security updates and fixes often in multiple systems in your local network, then having a local repository is an efficient way. 

All required packages are downloaded over the fast LAN connection from your local server, so that it will save your Internet bandwidth and reduces your annual cost of Internet.

Now, please find the step by step method to create a YUM repository on RHEL 7 & CentOS 7.

Mount the Local Media:

In this step we mount our CentOS 7 / RHEL 7 installation DVD. For example, let us mount the installation media on /mnt directory.

#mount -o loop /dev/cdrom /mnt

In my Linux machine i will insert the ISO on cdrom and mount it on /mnt directory.

Copy or Extract the Media:

In this step, we will extract or copy iso files to local machine. For this work we will create a one mount point directory and copy all the packages files from /mnt.

#mkdir /centos
#cp -rvf /mnt/* /centos

So all the packages are copied on the "/centos" directory.

Install repository packages:

In this step, we will create repository but before this we need to install the "createrepo" rpm on the YUM server.

For createrepo, you need to install some dependency rpm which are listed in "Packages" folder.

#rpm -ivh libxml2-python-2.9.1-5.el7_0.1.x86_64.rpm
#rpm -ivh python-deltarpm-3.6-3.el7.x86_64.rpm
#rpm -ivh deltarpm-3.6-3.el7.x86_64.rpm
#rpm -ivh createrepo-0.9.9-23.el7.noarch.rpm

Once these required packages is installed we create the repo using createrepo command.

#createrepo -v /centos/Packages

Remove the Online Repository:

Please remove the old repository from /etc/yum.repos.d directory. In this directory all the default local centOS / RHEL repository are exist.

#rm -rf /etc/yum.repos.d/*

Create Local Repository:

In this step we will create the local repostiory which is always kept as a local. Using this local repo we can install all the packages and their dependency.

#vi /etc/yum.repos.d/local.repo

[Packages]
baseurl=file:///centos/Packages
gpgcheck=0
enable=1

After save the file your local.repo repository has been created. In next step we will enable it.

Enable Local Repository:

After successfully creation of YUM repository we will enable it.

#yum clean all
#yum repolist all

Using this repolist command you can check the newly created and existing repository on the server. After that you can easily install the pacakges using YUM in RHEL 7 & CentOS 7.

How to setup NFS Server on CentOS 7 / RHEL 7

In this post, I would explain you , how to setup NFS server on CentOS 7 & RHEL 7. This step by step installation and configuration method of NFS server is work in Fedora 22 version also.

Network File System is used for to share files and folders between Linux / Unix systems. NFS enables you to mount a remote share locally as well as it allows to have updated files across the share.

Before starting the setup method , we need to understand which service and files are used for NFS setup.

Please find the below services which are used for NFS setup. its must be always runs on operating system.

rpcbind service: The rpcbind server is used to converts RPC program numbers into universal addresses.

nfs-server service:  Its enables the NFS clients to access NFS shares.

nfs-lock / rpc-statd service: these are the recovery services when an NFS server crashes and reboots.

nfs-idmap service: It translates user and group ids into names, and to translate user and group names
into ids.

The mail configuration file for NFS server and client is "/etc/exports". It controls which file systems are exported to remote hosts and specifies options.

Now, we will start the step by step process for setup of NFS server on CentOS 7 / RHEL 7.

NFS Server Setup:

1. First we need to install the NFS packages on the server where we want to setup of NFS server. We can install the required NFS packages using YUM.

#yum install nfs-utils libnfsidmap

It's installed all the required packages on NFS server.

2. Once the packages are installed we will enable and start all the above services which we explain in my post.

#systemctl enable rpcbind
#systemctl enable nfs-server
#systemctl start rpcbind
#systemctl start nfs-server
#systemctl start rpc-statd
#systemctl start nfs-idmapd

You can check the status of all these service by using this command "systemctl status service_name" to ensure all are working fine.

3. Now we will created the shared directory which we want to share for client.

#mkdir /backup
#chmod -R 777 /backup

We can change the permission of NFS folder as per your requirement. In my case I'll provide the read write permession to all NFS client on this shared folder, so they can easily copy and remove the files. Ideally for security purpose we never provide 777 permission.

4. In this step we will make an entry of shared folder and client information , what permission we give to client to access the folder and which client can access the NFS shared folder.

# vi /etc/exports

/backup 10.135.0.27(rw,sync,no_root_squash)

In above command output, you can see the "/backup" is shared NFS server folder and "10.135.0.27" user client have rights to access this shared folder.

Also in brackets if you see the permission parameter which is very important when we setup the NFS setup. Please find the small idea about these permission parameteres.

rw: Writable permission to shared folder

sync:  all changes to the according filesystem are immediately flushed to disk.

no_root_squash: By default, any file request made by user root on the client machine is treated as by user nobody on the server. If no_root_squash is selected, then root on the client machine will have the same level of access to the files on the system as root on the server

5. Now, we will export the shared directories using following command.

# exportfs -r

We can use other syntax as well for this, which is listed below.

exportfs -v : Displays a list of shares files and export options on a server
exportfs -a : Exports all directories listed in /etc/exports
exportfs -u : Unexport one or more directories
exportfs -r : Reexport all directories after modifying /etc/exports

6. Now in above step 5, we configured and installed the NFS server but if firewall is running on your machine then we need to add NFS services in firewall as well.

#firewall-cmd --permanent --zone public --add-service mountd
#firewall-cmd --permanent --zone public --add-service rpc-bind
#firewall-cmd --permanent --zone public --add-service nfs
#firewall-cmd --reload

NFS Client Steup:

1. Once we installed the NFS server, now we will mount the remote file system on NFS client machine. So for this , on client machine we will install the same NFS packages which we installed during NFS server setup.

#yum install nfs-utils libnfsidmap

It's installed all the required packages on NFS client. Once the packages is installed on NFS client machine we will start the "rpcbind" services on client machine.

#systemctl enable rpcbind
#systemctl start rpcbind

2. Now we will mount the NFS shared folder on client machine but before doing that we will check on client machine which NFS server is available.


client# showmount -e 10.135.0.27    (10.135.0.2 is myserver machine IP)

Export list for 10.135.0.27:
/backup      10.135.0.2

So you can able to see on client machine our NFS shared folder is available on 10.135.0.27 NFS server. 

3. In this step , now we will mount this NFS shared folder on NFS client machine, for this we will create a mount point on client machine where we mount the server shared folder.

client# mkdir /mnt/backup
client#mount 10.135.0.27:/backup /mnt/backup

So you can check the mount folder using "df -h" command.

4. To make a permanent entry on client machine so that once you take a reboot of client machine , the shared folder is not umount.

client# vi /etc/fstab
10.135.0.27:/backup/ /mnt/backup nfs rw,sync,hard,intr 0 0

Please make an entry permanent on client machine and save it and take a restart of machine , after reboot once you login you will see the shared folder still available on the client machine.

5. For testing of shared folder, you can create a one file on client machine then check on the server this newly created file is shown on the server folder also.

So, using all these steps you can easily setup the NFS server and client on your machine.

Wednesday, February 8, 2017

How To Install VNC Server On CentOS 7 & RHEL 7

In this post, you can find the step by step method of installation and configuration of VNC server on CentOS 7 / RHEL 7. VNC server installation on CentOS 7 / RHEL 7 is quite different from older version of linux.

Before moving to installation part, first we need to know what is VNC server and how it is works on Linux environment.

VNC (Virtual Network Computing):

VNC stands for Virtual Network Computing server which allows for remote desktop connection in graphical GUI mode by using their remote client. For VNC client we can use VNC viewer. We can use other VNC client as wll for taking a remote connection of VNC server.  Some packages is required for installation and configuration which we explain during the post.

Step by Step Installation and Configuration method for VNC Server:

First we need to install the required packages on the server. You can install the packages using "YUM" command and if you have source package you can install it. On my machine I have yum repo , so we can install the rpm using YUM.

1. In my machine I am using GNOME desktop, if GNOME desktop is not installed on your machine then you need to install it by using below command.

#yum groupinstall "GNOME Desktop"

Using above command you can install all the packages which are required for desktop version. When you run the above command you can see all listed packages before installation.

2. After installation of GNOME packages we will install tigervnc-server packages which is mandatory for VNC server installation.

#yum install tigervnc-server*

here, "*" sign is used for all dependency, if you use this sign it is automatically installed all dependency. Using above command we can install all the VNC server rpm's.

3. Now we will add VNC user on the server.

#useradd vibhor

In my case I used my name but you can use any name.

4. In CentOS 7,there is change in the vncserver configuration file, becuase in older version of CentOS it was /etc/sysconfig/vncservers and now it have changed in /lib/systemd/system/vncserver@.service

#cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:2.service

5. Now we will edit the vncserver file as describe below.

#vi /etc/systemd/system/vncserver@:2.service

[...]
[Service]
Type=forking
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
#ExecStart=/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"
#PIDFile=/home/<USER>/.vnc/%H%i.pid
ExecStart=/sbin/runuser -l vibhor -c "/usr/bin/vncserver %i"
PIDFile=/home/vibhor/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

In the above file, you need to set the user name which use add on the server for access the VNC server. You can add more user on the server but for each user you need to create new service file and in each file you will change the user string.

6. If your firewall is enable on your machine then you need to add VNC server service on the firewall and make a permanent, in my machine it is enable so i will use it.

#firewall-cmd --permanent --zone=public --add-service vnc-server
#firewall-cmd --reload

7.  Now please switch the user from root and start the vnc server for vnc user.

#su - vibhor

vibhor@localhost~]$ vncserver

You will require a password to access your desktops.

Password:<--yourvncpassword
Verify:<--yourvncpassword
xauth:  file /home/vibhor/.Xauthority does not exist

New 'localhost:2 (vibhor)' desktop is localhost:2

Creating default startup script /home/vibhor/.vnc/xstartup
Starting applications specified in /home/vibhor/.vnc/xstartup
Log file is /home/vibhor/.vnc/localhost:2.log

It is creating the file in your home direcotory , if you see the service is startup and working fine.

8. Now please start the all required services for vnc server and make it permanent so once you take a reboot of machine it is not disable. All the service start and enable through root user.

#systemctl daemon-reload
#systemctl enable vncserver@:2.service
#systemctl start vncserver@:2.service

9. Now  go to your workstation or laptop and install the VNC client and connect the server using "vibhor" vnc user. when you run the client it is asking for host name so you will enter the host name and enter the vncuser password after that you can connect the server graphically.

Friday, February 3, 2017

How to Shrink or reduce size of LVM partitons in RHEL/CentOS

LVM (Logical Volume Manager) is a tool for logical volume management which includes allocating disks, striping, mirroring and resizing logical volumes.With LVM, a hard drive or set of hard drives is allocated to one or more physical volumes.

LVM allows users to create partitions from more than one disk and allows them to extend the filesystem size online within few seconds.

In this post, we will see how we can shrink the size of an LVM partition without losing data.

On my linux virtual machine, the VG name is “rootvg” and LV name is “Vibhor” which has 60 GB size. I want to reduce the LV size to 4GB. Please note down the following points before proceeding with the shrinking of filesystem.

  • Make sure the current disk usage of the filesystem is less than the size to which you are going to reduce the logical volume.
  • Always take a backup of filesystem data before doing any size change in LVM as a simple mistake in command can cause filesystem corruption and hence loss of data.

Now, please find the below steps which we need to follow for reduce or shrink the partition size.

Umount the filesystem:

We will check the file system through fsck command but before running fsck on the filesystem, it should be unmounted.You can unmount the filesystem “/vibhor” as follows.

#umount /Vibhor

Performing filesystem check:
Before proceeding with reducing filesystem, “fsck” should be done in order to avoid inconsistency of filesystem data.
#e2fsck –f /dev/mapper/rootvg/rootvg_vibhor

Resizing filesystem:

Now, we will reducing the size of the Logical Volume, but before we need to reduce the filesystem in it. The command “resize2fs” can be used for this as follows.

#resize2fs –p /dev/mapper/rootvg/rootvg_vibhor 4G

This will decrease or shrink the filesystem size to 4GB.

Reducing the LV size:

After reduce or shrink the filesystem, we can reducing the LV as given below.

#lvreduce –L 4G /dev/mapper/rootvg/rootvg_vibhor

This will reduce the logical volume size to 4 GB. Now I will mount the filesystem again and check it using the command “df –h”. the file system has reduced to 4 GB without losing any data.

#mount /Vibhor
#df –h

This output will show you the reduce filesystem size.