Thursday, March 22, 2018

XFS


Few Points on XFS:


  • Default file system on RHEL 7
  • XFS is a highly-scalable 64-bit jounraling file system that can used on a single host.
  • It supports metadata journaling which means the crash recovery is quicker.
  • Even though we can grow an XFS file system online, it is not possible to shrink.
  • No file system check at boot time
  • Can go upto 500TB filesytems and 50TB files
  • Less cpu intensive

 

Some commands...

To create an XFS file system on a newly created logical volume:
# mkfs.xfs /dev/vgxx/lvxx

To grow an XFS file system:
# xfs_growfs /mount-point -D size

To label an xfs file system:
# xfs_admin -L "label" /dev/vgxx/lvxx

To show the label of an xfs file system:
# xfs_admin -l /dev/vgxx/lvxx

To repair an XFS file system (make sure the file system is unmounted before you run the below command):
# xfs_repair /dev/vgxx/lvxx

In case of dirty log, use the following command to clear the log.
# xfs_repair -L /dev/vgxx/lvxx

To freeze an xfs file system:
# xfs_freeze -f /mount/point

To unfreeze an XFS file system:
# xfs_freeze -u /mount/point

To show the file system information:
# xfs_info /dev/vgxx/lvxx

To do a full backup a xfs file system on a tape:
# xfsdump -l 0 -f /dev/st1 /data

Here "-l" means the level of backup. 0 always mean a full backup. You may replace it with the numbers from 1 to 9 which means an incremental backup.

To do a labelled full backup:
# xfsdump -l 0 -L "/data backup on 3rd March 2018" -f /dev/st1 /data

To list the backup labels on a tape:
# xfsrestore -I -f /dev/st0

To restore a xfs backup using a label a different location:
# xfsrestore -L "/data backup on 3rd March 2018" -f /dev/st1 /data-temp

To display quota:
# xfs_quota -x -c 'report -h' /data

To set the soft and hard data(block) quota (in MB) for a user:
# xfs_quota -x -c 'limit bsoft=500m bhard=900 mark' /data/

To set soft and hard inode quota for a group:
# xfs_quota -x -c 'limit -g isoft=1000 ihard=1500 dba' /data/

Monday, December 19, 2016

Managing Swap space in Red Hat Linux

1. To extend a swap logical volume

a. Disable swapping for the concerned logical volume
# swapoff -v /dev/VolGroup00/LogVol05

b. Extend the logical volume by 1GB
# lvm lvresize /dev/VolGroup00/LogVol05 -L +1G

c. Format the logical volume
# mkswap /dev/VolGroup00/LogVol05

d. Enable the swap device
# swapon -va


2. To reduce a swap logical volume

a. Disable swapping for the concerned logical volume
# swapoff -v /dev/VolGroup00/LogVol05

b. Reduce the logical volume by 512MB
# lvm lvresize /dev/VolGroup00/LogVol05 -L -512M

c. Format the logical volume
# mkswap /dev/VolGroup00/LogVol05

d. Enable the swap device
# swapon -va


3. To list all the configured swap devices:

# cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/mapper/VolGroup00-LogVol05         partition       6062072 2180    -1


4. To list the total/used/free swap space:

# free -tm
             total       used       free     shared    buffers     cached
Mem:          7983       7918         65          0        585       4943
-/+ buffers/cache:       2389       5594
Swap:         5919          2       5917
Total:       13903       7920       5982


5. To create a swap file of size 100MB :

# dd if=/dev/zero of=/swap1 bs=1024 count= 102400
# chmod 0600 /swap1
# mkswap /swap1
# swapon /swap1

Finally add the below entry in /etc/fstab so that it enables on every boot.

/swap1          swap            swap    defaults        0 0


6. To enable swap space on a file :

# swapon -v /swap1


7. To disable swap space on a file :

# swapoff -v /swap1

Software RAID in Red Hat Linux

To create a linear RAID array:

# mdadm --create --verbose /dev/md0 --level=linear --raid-devices=2 /dev/sdb /dev/sdc
# mdadm --detail --brief /dev/md0 >> /etc/mdadm.conf


To create a striped RAID array (RAID-0):

# mdadm --create --verbose /dev/md0 --level=0 --raid-devices=2 /dev/sdb /dev/sdc
# mdadm --detail --brief /dev/md0 >> /etc/mdadm.conf


To create a mirrored RAID array (RAID-1):

# mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc
# mdadm --detail --brief /dev/md0 >> /etc/mdadm.conf


To start a RAID Array:

# mdadm --assemble /dev/md0 /dev/sdb /dev/sdc /dev/sdd

                                                    OR

# mdadm --scan --assemble --uuid=a26bf396:31389f83:0df1722d:f404fe4c


To list all software raid arrays and their component devices:

# cat /proc/mdstat
Personalities : [linear]
md0 : active linear sdd[0]
      10485752 blocks super 1.2 0k rounding

md1 : active linear sde[0]
      52428792 blocks super 1.2 0k rounding

unused devices:




 

To query a software raid array :

# mdadm --query /dev/md1
/dev/md1: 129.100GiB linear 1 devices, 0 spares. Use mdadm --detail for more detail.


To list details of a RAID array:

# mdadm --detail /dev/md1
/dev/md1:
        Version : 1.2
  Creation Time : Thu Dec 11 09:32:37 2011
     Raid Level : linear
     Array Size : 52428792 (50.00 GiB 53.69 GB)
   Raid Devices : 1
  Total Devices : 1
    Persistence : Superblock is persistent

    Update Time : Thu Dec 11 09:32:37 2011
          State : clean
 Active Devices : 1
Working Devices : 1
 Failed Devices : 0
  Spare Devices : 0

       Rounding : 0K

           Name : server123:1  (local to host server123)
           UUID : c5804771:253326af:e062f685:cab35fed
         Events : 0

    Number   Major   Minor   RaidDevice State
       0       8       32        0      active sync   /dev/sdc


To examine a RAID array:

# mdadm --examine /dev/md0


To add a raid disk device and extend a linear software raid array :

# mdadm --detail /dev/md3 | tail -n 3
    Number   Major   Minor   RaidDevice State
       0       8        1        0      active sync   /dev/sdc
       1       8       17        1      active sync   /dev/sdd

# mdadm --grow /dev/md3 --add /dev/sde


To remove a RAID array:

# mdadm --stop /dev/md3
# mdadm --remove /dev/md3
# mdadm --zero-superblock /dev/sdc /dev/sdd

Friday, September 9, 2016

MySQL - Part 1

Packages required:
mysql - contains client programs, configuration files and documentation
mysql-server - contains server daemon, startup script and various administrative files and directories
mysql-devel - contains libraries and header files for development purpose

Optional packages:
php-mysql - contains a shared library to allow PHP applications access MySQL databases
mod_auth_mysql - contains tools to authorize Apache Web server access from data in a MySQL database
perl-DBD-MySQL - contains a perl interface to MySQL databases
mysql-bench - contains scripts for benchmarking MySQL databases
MySQL-python - contains a Python interface to MySQL
qt-MySQL - MySQL drivers for QT SQL classes
mysql-administrator - GUI based tool to manage MySQL databases


Server daemon: mysqld

Startup script: /etc/init.d/mysqld

Configuration file: /etc/my.cnf

Log file: /var/log/mqsqld.log

Few Tips for beginners:

1. To set password for root user in MySQL (this is different from the root password in OS):

# mysqladmin -u root password mypasswd

You need to mention this password whenever you run a mysql command.
To make it easy, you can add the password to the file /root/.my.cnf and change the permission to 600

Here is a sample content of /root/.my.cnf

[client]
mypassword


2. What happens when you start MySQL server for the first time:

It creates tables for 2 databases mysql and test. And the information is stored in the /var/lib/mysql/mysql and /var/lib/mysql/test directories, respectively.

3. How to start mqsql command ?

$ mysql -u root
Enter password: *********

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13

Server version: 5.0.37 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer

mysql>

If you want to connect to mysql on a remote server, use -h hostname or ipaddress to the end of the command.


Some mysql interface commands :

1. Shows the version, connected database, remote or local connection,etc...

mysql> status

2. To create a new database :

mysql> CREATE DATABASE mydb;

You can also create a database using mysqladmin command as below

# mysqladmin -u root -p create

3. To list all the databases on your mysql server :

mysql> SHOW DATABASES;

4. Before working on a database, make it as your current database.

mysql> USE mydb;

5. To create a table:

mysql> CREATE TABLE employee (
-> name      varchar(20)    not null,
-> empid       varchar(6)    not null,
-> phonenumber     varchar(10)    not null,
-> city           varchar(20)    not null,
-> state          varchar(20)    not null,
-> zipcode        varchar(10)    not null
-> );

6. To show all tables in your current database :

mysql> SHOW tables;

7. To display the format of the "employee" table :

mysql> DESCRIBE employee;

8. To add data to the table "employee" :

mysql> INSERT INTO employee
-> VALUES ('Mike','112233','2349871239',
-> 'Philadelphia','PA','11227');

9. To list the contents of the table:

mysql> SELECT * FROM employee;

10. To load data from a text file into a table:

$ mysql -u root -p
Enter password: *******
mysql> USE mydb
Database changed
mysql> LOAD DATA INFILE "/tmp/emp.txt" INTO TABLE employee;
Query OK, 5 rows affected (0.04 sec)
Records: 5  Deleted: 0 Skipped: 0 Warnings: 0

Wednesday, January 27, 2016

How to integrate Red Hat Satellite with VMWare (ESX)



You can integrate Red Hat Satellite with VMWare ESX Hypervisor so that you can just use one license "Red Hat Enterprise Linux for Virtual Datacenters, Standard" per ESX.

Here is the procedure to make your satellite talk to ESX hypervisor to retrive the UUIDs


1. Register a VMWare based Linux server on Satellite

2. Install virt-who package

# yum install virt-who

3. Add the following lines onto /etc/sysconfig/virt-who


4. Enable and restart virt-who service

# chconfig virt-who on

# service virt-who restart

5. Now virt-who will populate all your hypervisors on RedHat satellite webUI.

6. Go to Content > Content host. Here you will find some systems with UUID. These are all hypervisors reported by your virt-who service.

7. Select a hypervisor > Subscription > Add > Select virtual datacenter subscription. > attach.
Follow this step for all hypervisors available on web UI.

8. Now on your virt-who server execute the following command to list out the hypervisors inherited virtual datacenter subscription.
This subscription contains the pool id. Note down this pool id.

# subscription-manager list --available

9. Now subscribe your system

# subscription-manager subscribe --pool=

Friday, December 18, 2015

Daemons used in Satellite 6.1

Here are some daemons used in Satellite 6.1.

MongoDB - Database used by Pulp.

To Manage on RHEL6:
# chkconfig mongod on
# service mongod start

To Manage on RHEL7:
# systemctl enable mongod
# systemctl start mongod


Qpid - Message bus used by Pulp.

To Manage on RHEL6:
# chkconfig qpidd on
# service qpidd start

To Manage on RHEL7:
# systemctl enable qpidd
# systemctl start qpidd


Apache - Web Server

To Manage on RHEL6:
# chkconfig httpd on
# service httpd start

To Manage on RHEL7:
# systemctl enable httpd
# systemctl start httpd


Pulp Workers -

To Manage on RHEL6:
# chkconfig pulp_workers on
# service pulp_workers start

To Manage on RHEL7:
# systemctl enable pulp_workers
# systemctl start pulp_workers


Pulp Celerybeat -  This process performs a job similar to a cron daemon for Pulp.

Config File:  /etc/default/pulp_celerybeat

To Manage on RHEL6:
# chkconfig pulp_celerybeat on
# service pulp_celerybeat start

To Manage on RHEL7:
# systemctl enable pulp_celerybeat
# systemctl start pulp_celerybeat


Pulp Resource Manager  - This process acts as a task router.

Config File: /etc/default/pulp_resource_manager

To Manage on RHEL6:
# chkconfig pulp_resource_manager on
# service pulp_resource_manager start

To Manage on RHEL7:
# systemctl enable pulp_resource_manager
# systemctl start pulp_resource_manager

Scan a recently added virtual disk in a VMWare based Linux server

1. Take an output of the currently available disks

# fdisk -l


2. Scan for the new disk

# echo "- - -" > /sys/class/scsi_host/host0/scan


3. List the available disk to find out the name of newly created disk

# fdisk -l

4. View the messages file for confirmation

# tail -f /var/log/messages

How to do release update on Red Hat Linux ?

 Following procedure guides you on how to update a Red Hat Linux server from RHEL 6.3 to 6.4.

1. Mount the file RHEL6.4-Server-20130130.0-x86_64-DVD1.iso on a directory.

# mount -o loop RHEL6.4-Server-20130130.0-x86_64-DVD1.iso /media/rhel6/

2. Copy the repo file from the ISO to local repos.d directory.

# cp /media/rhel6/media.repo /etc/yum.repos.d/rhel6.repo

3. Modify the file /etc/yum.repos.d/rhel6.repo

baseurl=file:///media/rhel6/

4. Update the OS

# yum update

5. Unmount the file system

# umount /media/rhel6

6. Remove the temporary repo file

# rm /etc/yum.repos.d/rhel6.repo

7. Reboot the server

8. Check the OS version.

# cat /etc/redhat-release

Managing Activation Key using Hammer commands

1. To create an activation key,

# hammer activation-key create --name "rhel70ak" \
 --content-view "rhel70cv" --lifecycle-environment Library \
 --organization "MyCompany"

2. To update the release version on an activation key,

# hammer activation-key update --release-version "7Server"  \
 --organization "MyCompany" --name "rhel70ak"

3. To display and find out the ID of the subscriptions available,

# hammer subscription list --organization "MyCompany"

4. To list and find out the ID of the activation keys,

# hammer activation-key list --organization "MyCompany"

5. Attach the subscription to the activation key,

# hammer activation-key add-subscription --id 2 --subscription-id 12

6. To list the subscriptions attached to an activation key,

# hammer activation-key subscriptions --id 2 --organization "MyCompany"

Managing Content views using Hammer commands:


1. To list all the available repositories,

# hammer repository list --organization "MyCompany"

---|-------------------------------------------------------------------|---------------------------------|--------------|---------------------------------------------------------------------------------
ID | NAME                                                              | PRODUCT                         | CONTENT TYPE | URL                                                                            
---|-------------------------------------------------------------------|---------------------------------|--------------|---------------------------------------------------------------------------------
1  | Red Hat Enterprise Linux 7 Server Kickstart x86_64 7.1            | Red Hat Enterprise Linux Server | yum          | https://cdn.redhat.com/content/dist/rhel/server/7/7.1/x86_64/kickstart         
4  | Red Hat Enterprise Linux 7 Server - RH Common RPMs x86_64 7Server | Red Hat Enterprise Linux Server | yum          | https://cdn.redhat.com/content/dist/rhel/server/7/7Server/x86_64/rh-common/os  
2  | Red Hat Enterprise Linux 7 Server RPMs x86_64 7Server             | Red Hat Enterprise Linux Server | yum          | https://cdn.redhat.com/content/dist/rhel/server/7/7Server/x86_64/os            
3  | Red Hat Satellite Tools 6.1 for RHEL 7 Server RPMs x86_64         | Red Hat Enterprise Linux Server | yum          | https://cdn.redhat.com/content/dist/rhel/server/7/7Server/x86_64/sat-tools/6....
---|-------------------------------------------------------------------|---------------------------------|--------------|---------------------------------------------------------------------------------

2. To create a content view,.

# hammer content-view create --name "rhel70cv" \
 --description "RHEL 7.0 Content View" --organization "MyCompany"

3. To add the required repositories to the content view,

# hammer content-view update --repository-ids 4,2,3 --name "rhel70cv" --organization "MyCompany"

4. Publish the content view so that its contents are locked,

# hammer content-view publish --name "rhel70cv" --organization "MyCompany"