Showing posts with label RHEL. Show all posts
Showing posts with label RHEL. Show all posts

Sunday, 26 April 2015

How can I view, create, and remove SCSI persistent reservations and keys. from redhat

APPLIES TO:


Redhat Enterprise Linux 5, 6, 7
Oracle Enterprise Linux 5, 6, 7
SUSE Linux Enterprise Server 9,10, 11, 12

SYMPTOMS


Can't read/write to lun.
Can't join cluster.

Also you can see something like that in your dmesg:
[6902380.608058] sd 11:0:0:1: [sdc] tag#16 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_OK
[6902380.608060] sd 11:0:0:1: [sdc] tag#16 CDB: Read(10) 28 00 00 1f ff 80 00 00 08 00
[6902380.608061] blk_update_request: critical nexus error, dev sdc, sector 2097024
[6902380.608064] Buffer I/O error on dev sdc1, logical block 261872, async page read
[6902380.609007] sd 11:0:0:1: reservation conflict
[6902380.609011] sd 11:0:0:1: [sdc] tag#14 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_OK
[6902380.609013] sd 11:0:0:1: [sdc] tag#14 CDB: Read(10) 28 00 00 00 08 00 00 00 01 00
[6902380.609015] blk_update_request: critical nexus error, dev sdc, sector 2048
[6902380.609523] sd 11:0:0:1: reservation conflict
[6902380.609526] blk_update_request: critical nexus error, dev sdc, sector 0


Scsi persistent reservation, usualy used in cluster environment, it's allow scsi initiator to reserve LUN to exclusive access.

SOLUTION


Install sg3_utils package. (in case of SLES, use zypper)
# yum install sg3_utils


To view the keys registered on a LUN use the following command:
# sg_persist --in -k -d /dev/sdd

To view the reservations currently out on a device use the following command:
# sg_persist --in -r -d /dev/sdd

Keys are 6 or 8 digit HEX numbers. Key numbers can be arbitrary. For example 0xDEADBEEF or 0x123ABC To register a key on a LUN use the following command:
# sg_persist --out --register --param-sark=0xDEADBEEF /dev/sdd

You can take out a reservation on behalf of a key with the following command:
# sg_persist --out --reserve --param-rk=0xDEADBEEF --prout-type=1 /dev/sdd
The reservation types are defined in the SCSI Primary Commands spec. Here are the reservation types from the sg_persist manpage

1-> write exclusive
3-> exclusive access
5-> write exclusive - registrants only
6-> exclusive access - registrants only
7-> write exclusive - all registrants
8-> exclusive access - all registrants.



to  release a registration:

# sg_persist --out --release --param-rk=0xDEADBEEF  --prout-type=5 /dev/sdd

to unregister a key:

# sg_persist --out --register --param-rk=0xDEADBEEF  /dev/sdd

clear the reservation and all registered keys:

# sg_persist --out --clear --param-rk=0xDEADBEEF   /dev/sdd





Monday, 9 March 2015

Mount nfs4 throw ssh tunnel

GOAL


Need to mount nfs share throw ssh tunnel

SOLUTION


On nfs server side, add following lines in /etc/exports
/myshare      127.0.0.1(rw,fsid=0,insecure,no_subtree_check,sync)


reread nfs configuration
 # exportfs -rv
 exporting nfs-server.labs.localnet:/myshare

On client side
ssh -c blowfish -L 3333:127.0.0.1:2049 nfs-server.labs.localnet
mount -t nfs4 -o rw,hard,intr,proto=tcp,port=3333 127.0.0.1:/myshare /mnt/nfs



Sunday, 10 August 2014

Parted, optimal aligment

SYMPTOMS


When you labble and create partion on disk, parted say you something like this

(parted) mklabel gpt
(parted) mkpart primary 0 100%
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel?

SOLUTION


Get the alignment parameters for your array (remember to replace sdb with the name of your device as seen by the kernel).

# cat /sys/block/sdb/queue/optimal_io_size
1048576
# cat /sys/block/sdb/queue/minimum_io_size
262144
# cat /sys/block/sdb/alignment_offset
0
# cat /sys/block/sdb/queue/physical_block_size
512

Add optimal_io_size to alignment_offset and divide the result by physical_block_size. In my case this was (1048576 + 0) / 512 = 2048.
This number is the sector at which the partition should start. Your new parted command should look like:
mkpart primary 2048s 100%

The trailing ‘s’ is important: it tells parted that you’re talking about sectors, not bytes or megabytes.

Saturday, 9 August 2014

Using SCSI Persistent Reservation Fencing (fence_scsi) in RHEL 6 (RHEL KB)

Using SCSI Persistent Reservation Fencing (fence_scsi) in RHEL 6

Originally is article 40112 at access.redhat.com

1 Introduction

When cluster nodes share storage devices, it is necessary to control access to the storage devices. In the event of a node failure, the failed not should not have access to the underlying storage devices. SCSI persistent reservations provide the capability to control the access of each node to shared storage devices. Red Hat Cluster Suite employs SCSI persistent reservations as a fencing methods through the use of the fence_scsi agent. The fence_scsi agent provides a method to revoke access to shared storage devices, provided that the storage support SCSI persistent reservations.
Using SCSI reservations as a fencing method is quite different from traditional power fencing methods. It is important to understand the software, hardware, and configuration requirements prior to using SCSI persistent reservations as a fencing method.
This document describes the use of SCSI persistent reservations for Red Hat Cluster Suite version 6.0 and greater. Information about using SCSI persistent reservations with older version of Red Hat Cluster Suite can be found here: Using SCSI Persistent Reservations with Red Hat Enterprise Linux 4 or 5

2 Overview

In order to understand how Red Hat Cluster Suite is able to use SCSI persistent reservations as a fencing method, it is helpful to have some basic knowledge of SCSI persistent reservations.
There are two important concepts within SCSI persistent reservations that should be made clear: registrations and reservations.

2.1 Registrations

A registration occurs when a node registers a unique key with a device. A device can have many registrations. For our purposes, each node will create a registration on each device.

2.2 Reservations

A reservation dictates how a device can be accessed. In contrast to registrations, there can be only one reservation on a device at any time. The node that holds the reservation is known as the "reservation holder". The reservation defines how other nodes may access the device. For example, Red Hat Cluster Suite uses a "Write Exclusive, Registrants Only" reservation. This type of reservation indicates that only nodes that have registered with that device may write to the device.

2.3 Fencing

Red Hat Cluster Suite is able to perform fencing via SCSI persistent reservations by simply removing a node's registration key from all devices. When a node failure occurs, the fence_scsi agent will remove the failed node's key from all devices, thus preventing it from being able to write to those devices.

3 Requirements

3.1 Software Requirements

In order use SCSI persistent reservations as a fencing method, the following software requirements must be met:

3.2 Storage Requirements

In order to use SCSI persistent reservations as a fencing method, all shared storage must be SPC-3 compliant. In addition, all devices must support the "preempt and abort" service action. SCSI-2 devices are not supported.

4 Limitations

  • Multipath devices can be used with fence_scsi, but only use cases with device-mapper-multipath are supported by Red Hat. No other types of multipath devices are currently tested or directly supported by Red Hat.
  • All nodes in the cluster must have a consistent view of storage. In other words, all nodes in the cluster must register with the same devices. This limitation exists for the simple reason that each node must be able to remove another node's registration key from all the devices that it registered with. In order to do this, the node performing the fencing operation must be aware of all devices that other nodes are registered with.
  • If fence_scsi is used in conjunction with qdisk, the qdisk device must not be controlled by fence_scsi. If fence_scsi is configured to do automatic device detection, then the qdisk device must not be under clvmd control. If fence_scsi uses manually defined devices, the qdisk device must not be listed. See section 5.4 of this document for information about automatic and manual device configuration.
  • Devices used for the cluster volumes should be a complete LUN, not partitions. SCSI persistent reservations work on an entire LUN, meaning that access is controlled to each LUN, not individual partitions.

5 Configuration

5.1 Unfencing

In addition to the standard fence section, fence_scsi requires an additional unfence section in each clusternode entry. This unfence section is used at cluster startup to created registrations on all devices. This unfence section must contains a device entry which should be identical to the device entry in the fence section except that the unfence section must have "action=on" in its device entry.
Below is an example of the fence and unfence sections.
    <clusternode name="node-01" votes="1" nodeid="1">
        <fence>
            <method name="scsi">
            <device name="scsi_dev" key="1"/>
            </method>
        </fence>
        <unfence>
            <device name="scsi_dev" key="1" action="on"/>
        </unfence>
    </clusternode>
In this example the node's key value is manually defined. If keys are manually defined, they must be defined in both the fence and unfence elements and the key values must be equivalent. For more information about manually defined key values, see section 5.2.

5.2 Keys

SCSI persistent reservations use unique key values for registrations and reservations. These key values can be manually defined in the cluster.conf file or they can be generated automatically.
To manually define key values, use the "key" parameter within the device sections for each clusternode entry. This key value must be given in both the fence and unfence sections of the configuration file and the value must be the same within each clusternode.
Below is an example where keys are defined manually for a node.
    <clusternode name="node-01" votes="1" nodeid="1">
        <fence>
            <method name="scsi">
            <device name="scsi_dev" key="1"/>
            </method>
        </fence>
        <unfence>
            <device name="scsi_dev" key="1" action="on"/>
        </unfence>
    </clusternode>
In this example, the node will use a key value of "1". Note that the key value is given in the fence and unfence sections. All other node configurations should use the same format, except that they must use different key values. The key value can be any hexadecimal value, up to 64 bits.
To have the cluster automatically define key values, simply do not use the "key" parameter. When the "key" parameter is not defined, key values will be generated by combining the cluster_id and the nodeid. This value is guaranteed to be unique and consistent for all nodes in the cluster.

5.3 Devices

The devices to be used with fence_scsi can be manually configured or discovered automatically.
To manually define the devices to be used with fence_scsi, use the "devices" parameter within the fencedevice section. The devices parameter should be a comma-separated list of block devices. The devices listed here will receive SCSI persistent reservations commands (registrations and reservations), so each device listed must be a SPC-3 compliant.
Below is an example where devices are defined manually.
    <fencedevices>
        <fencedevice agent="fence_scsi" name="scsi_dev"
            devices="/dev/sda, /dev/sdb, /dev/sdc"/>
    </fencedevices>
In this example, there are three devices defined to be used with fence_scsi (/dev/sda, /dev/sdb, /dev/sdc).
It is important to note that specifying devices by device name (eg. /dev/sda) can be problematic and should generally be avoided. The reason for this is that a specific device may be named differently on other node. For example, the device named "/dev/sdb" on one node may be named "/dev/sdc" on another node. To avoid this problem, it is recommended that devices be listed by SCSI ID. This can be accomplished by specifying a device by way of its "/dev/disk/by-id/..." path. If the device is a dm-multipath device it is necessary for proper registration to all slave devices to use the disk/by-id device referring to the dm-multipath device and not to the scsi device.(e.g. /dev/mapper/mpathX or /dev/disk/by-id/dm-uuid-mpath-...).
To have the cluster automatically discover the devices to be used with fence_scsi, simply do not use the "devices" parameter. In the absence of this parameter, the fence_scsi agent will attempt to automatically discover cluster storage devices by querying clvmd for a list of devices that belong to cluster volumes. All devices that within cluster volumes will be used, and each must be SPC-3 compliant.

5.4 APTPL

The fence_scsi agent can be configured to optionally use the APTPL flag (Activate Persist Through Power Loss) option. This feature requires that the storage supports APTPL. To enable this feature, simply set the "aptpl" parameter in the fencedevice section of the cluster.conf file.
Below is an example where the APTPL option is enabled.
    <fencedevices>
        <fencedevice agent="fence_scsi" name="scsi_dev" aptpl="1"/>
    </fencedevices>

5.5 Logging

The fence_scsi agent can be configured to optionally write detailed logging information to a specific file. To enable logging to file, simply set the "logfile" parameter in the fencedevice section of the cluster.conf file.
Below is an example where logging to a file is enabled.
    <fencedevices>
        <fencedevice agent="fence_scsi" name="scsi_dev" logfile="/tmp/fence_scsi.log"/>
    </fencedevices>

5.6 Example

Below is a sample configuration (cluster.conf) for a cluster that uses SCSI persistent reservations as its fence method.
    <?xml version="1.0"?>
    <cluster config_version="1" name="my_cluster">
    <cman expected_votes="1" cluster_id="1"/>
    <fence_daemon post_fail_delay="0" post_join_delay="30"/>
    <clusternodes>
        <clusternode name="node-01" votes="1" nodeid="1">
            <fence>
                <method name="scsi">
                <device name="scsi_dev" key="1"/>
            </method>
        </fence>
        <unfence>
            <device name="scsi_dev" key="1" action="on"/>
        </unfence>
        </clusternode>
        <clusternode name="node-02" votes="1" nodeid="2">
            <fence>
                <method name="scsi">
                <device name="scsi_dev" key="2"/>
                </method>
            </fence>
            <unfence>
                <device name="scsi_dev" key="2" action="on"/>
            </unfence>
        </clusternode>
        <clusternode name="node-03" votes="1" nodeid="3">
            <fence>
                <method name="scsi">
                <device name="scsi_dev" key="3"/>
                </method>
            </fence>
            <unfence>
                <device name="scsi_dev" key="3" action="on"/>
            </unfence>
            </clusternode>
        </clusternodes>
    <fencedevices>
        <fencedevice agent="fence_scsi" name="scsi_dev" aptpl="1"
            devices="/dev/sda, /dev/sdb, /dev/sdc"
            logfile="/tmp/fence_scsi.log"/>
    </fencedevices>
    </cluster>

change a clustered LVM volume group to non-clustered.

GOAL


How to change clustered volume group to non-clustered and vise versa.

ERROR example:
# vgimport /dev/mapper/mpath-c0t5000CCA027C3225Cd0
  connect() failed on local socket: Connection refused 
  WARNING: Falling back to local file-based locking. 
  Volume Groups with the clustered attribute will be inaccessible. 
  Skipping clustered volume group vgclu1


SOLUTION


Check that volume group has clusterd attribute
   # vgs --config 'global {locking_type = 0}'
  WARNING: Locking disabled. Be careful! This could corrupt your metadata.
  VG     #PV #LV #SN Attr   VSize  VFree 
  vgclu1  1   1   0 wz--nc 96.00M 76.00M       <----- Attr includes the 'c' flag meaning clustered.
 
Make sure that this volume group not using cluster software, for e.x. Redhat Cluster Suite.



Force take over clusger volume group
 # vgchange -cn vgclu1 --config 'global {locking_type = 0}'
  WARNING: Locking disabled. Be careful! This could corrupt your metadata.
  Volume group "vgname" successfully changed
# vgchange -ay vgclu1 
  WARNING: After making this change, you must not activate the volume group on more than one server at a time or LVM metadata corruption can occur (even if no changes are made).
 

To temporarily activate the volume group, but leave it clustered, use the following command:
 # vgchange -ay vgclu1 --config 'global { locking_type = 0 }'
  WARNING: Locking disabled. Be careful! This could corrupt your metadata.
  1 logical volume(s) in volume group "vgclu1" now active
WARNING You must not execute this command on more than one server at a time or LVM metadata corruption can occur (even if no changes are made).

WARNING The vgchange using --config 'global {locking_type = 0}' will not work on a mirrored Logical Volume. The user must restore the VG from a valid LVM backup file using vgcfgrestore. Optionally the user can run lvconvert -m0 on the mirrored LV and run the commands outlined in steps 1-3 above then remirror using lvconvert. Please note that the re-mirroring process can take a while depending on the size of the LV being re-mirrored.

Saturday, 19 October 2013

How do I configure a CA and sign certificates using OpenSSL in Red Hat Enterprise Linux? (RedHat © )

Environment

  • Red Hat Enterprise Linux 5
  • Red Hat Enterprise Linux 6
  • openssl

Resolution

Configuring the Certificate Authority

1. Set up /etc/pki/CA as your certificate authority's working directory. To do this, open /etc/pki/tls/openssl.cnf in a text editor. Find the section labelled "[CA_default]", and edit the following lines in the section to read:
dir = /etc/pki/CA
certificate = $dir/my-ca.crt
crl = $dir/my-ca.crl
private_key = $dir/private/my-ca.key
2. The "[req_distinguished_name]" section lists several default options you may want to change. For example, you may want to set new defaults for C, ST, L, and O to appropriate values for your organization, such as:
countryName_default =US
stateOrProvinceName_default = North Carolina
localityName_default = Raleigh
organizationName_default = Example, Inc.
3. Create some supporting directories for certificates and CRLs: The /etc/pki/CA directory should be owned as root.root and have permissions 0700. It should contain a private subdirectory with the same permissions:
# mkdir /etc/pki/CA/{certs,crl,newcerts}
4. Create an empty certificate index:
# touch /etc/pki/CA/index.txt
5. In addition, create a file to indicate the next certificate serial number to be issued:
# echo 01 > /etc/pki/CA/serial
6. Next, while in /etc/pki/CA, you need to generate a private key and a self-signed CA certificate. You will be prompted for a passphrase, which will be needed later:
# (umask 077; openssl genrsa -out private/my-ca.key -des3 2048)
7. For your CA certificate, take the defaults for CountryName, StateOrProvinceName, LocalityName, and Organization, and for CommonName use"$hostname Certificate Authority". Set the other fields as you see fit:
# openssl req -new -x509 -key private/my-ca.key -days 365 > my-ca.crt
The /etc/pki/CA/private/my-ca.key file is the private key for your CA. This file must be very carefully protected. The my-ca.crt file is the public CA certificate that will eventually be distributed to your users.
At this point your CA is ready to sign certificates and can sign CSR (Certificate Signing Request) generated by different applications like LDAP, Dovecot, and Apache

Signing CA certificate using the Certificate Authority

  1. Create a private key for the service from the application server
    #  openssl genrsa 1024 > ldap_server.key
    
    Make sure to set correct permissions for the key (It should not be world readable)
  2. Create the certificate signing request
    # openssl req -new -key ldap_server.key  -out ldap_server.csr
    
    Fill CountryName, StateOrProvinceName, LocalityName, and Organization when prompted, make sure to use the FQDN of the host for CommonName
  3. Copy the CSR to openssl CA server.
  4. Use openssl ca command to sign the CSR.
    # openssl ca -config <path_toopenssl.cnf> -out ldap_server.crt -infiles ldap_server.csr
    
  5. Copy the signed certificate to the server, Configure the server to use the singed certificate.

Installing CA certificate on the Clients

The clients require the CA certificate to trust the server certificates signed by this CA, copy/import the CA certificate to the clients.
For example, ldap clients expects the CA certificate to be present under /etc/openldap/cacerts directory, If apache server is configured to use SSL using the CA signed cert, the CA certificate has to be imported to the web browser.

Make CA certificate available to Clients

The CA may make its public certificate easily downloadable by clients. You can use httpd to do that.
1. Install httpd
# yum install httpd
2. Start httpd:
# chkconfig httpd on; service httpd start
3. Copy my-ca.crt in /var/www/html/certs
# cp /etc/pki/CA/my-ca.crt /var/www/html/certs

Friday, 6 September 2013

Linux. Orphaned connections in CLOSE_WAIT state ( a lot of connections are in CLOSE_WAIT state )

Usually dealing with web servers we have a lot of connections in CLOSE_WAIT state. These connections hold web server threads and also consume our nofile, nproc resources described in /etc/security/limits.conf.

To prevent such situation we need to adjust some kernel variables:
  • net.ipv4.tcp_keepalive_time - the interval between the last data packet sent (simple ACKs are not considered data) and the first keepalive probe; after the connection is marked to need keepalive, this counter is not used any further.
  • net.ipv4.tcp_keepalive_intvl - the interval between subsequential keepalive probes, regardless of what the connection has exchanged in the meantime.
  • net.ipv4.tcp_keepalive_probesthe number of unacknowledged probes to send before considering the connection dead and notifying the application layer.

The first two parameters are expressed in seconds, and the last is the pure number. This means that the keepalive routines wait for two hours (7200 secs, default value) before sending the first keepalive probe, and then resend it every 75 seconds. If no ACK response is received for 9 consecutive times, the connection is marked as broken.

You can modify and persistently save your own setting using sysctl command and file /etc/sysctl.conf like this:
sysctl -w net.ipv4.tcp_keepalive_time=120 >> /etc/sysctl.conf
sysctl -w net.ipv4.tcp_keepalive_probes=3 >> /etc/sysctl.conf 
sysctl -w net.ipv4.tcp_keepalive_intvl=20 >> /etc/sysctl.conf