Install Docker on Centos 7

Install Docker:

yum install docker docker-registry 
systemctl enable docker.service
systemctl start docker.service
systemctl status docker.service

Install Docker Compose:

curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

Or alternatively :

yum install -y python-pip
pip install docker-compose 

Pull a docker image:

docker pull <imagename>

View Running Docker Containers:

docker ps 

Please stay tuned for future posts on docker containers.

Ntpdate Not syncing time correctly – Xen Host

I came across a situation where ntpdate would not sync the time correctly in a Xen Virtual machine. The time was 10 minutes ahead of what it was supposed to be. Apparently , you need to force it to not use the dom0’s clock.

vi /etc/sysctl.conf
xen.independent_wallclock = 1
sysctl -p

Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe.

You may come across this error in newer version of apache which is because the newer configurations use an event based Multi Processing Module by default. If the PHP is not compiled with threadsafe, you will need to switch to the prefork MPM, which does not use threads.

Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe.  You need to recompile PHP.
 AH00013: Pre-configuration failed
httpd.service: control process exited, code=exited status=1

Look for the following in the Load Modules sections of your apache configuration file :

LoadModule mpm_event_module modules/mod_mpm_event.so

And replace it with the following module :

LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

NFS Version 4 Export

Install the required Packages:

yum install nfs-utils nfs4-acl-tools portmap

Export the folder to share:

echo "/folder/to/share  IpAddressToShareWith(rw,no_root_squash,async,fsid=0)" >> /etc/exports

Map NFS User for ownership:

vi /etc/idmapd.conf

Domain=YourDomain.com

 

 

Nobody-User=apache Nobody-Group=apache

Iptables Rule :

iptables -A INPUT -p tcp -m tcp --dport 2049 -j ACCEPT

Start / Restart Services :

service nfs start
service rpcidmapd restart
service portmap start

SSL Root Certificate update in Linux for curl

When you use curl in Linux machines to make remote calls to SSL sites, you need to have latest root certificates installed. Recently I came across a situation where the newer root certificate were not available and so the remote call suddenly started failing.

First, you will have to find the location of your certificate files :

curl-config --ca

Now, you download the latest bundle to the path found from above , which usually is /etc/pki/tls folder

curl http://curl.haxx.se/ca/cacert.pem -o /etc/pki/tls/certs/ca-bundle.crt

 

You can check whether the curl call works by sample command given below :

curl --verbose --cacert ./certs/verisign-intermediate-ca.crt --head https://remotesite.com/

Processes in Linux

D : This means the process is in uninterruptible sleep mode. Usually Input and output are in this mode.

R : Currently Running Process or is in the running queue.

S :  Is in sleep state waiting for an event to complete.

T :  Means the process is stopped by a signal.
X :  X means a dead process.

Z :  Zombie or dysfunctional process which has terminated.
< : High priority process

N : Low priority process

L : This represents a process which has pages locked into the memory for real time processing or input output.
s : Means that this process is leading the session.

l : Multithreaded process.

+ : Running in the foreground.

Sending Signal to Processes :

Send Continue Signal to a Process :

kill -19 pid

GIT Common Commands and How Tos

To Discard Changes which have not yet been indexed to server , run this command :

git stash save --keep-index

git stash drop

To Clone Git Repo on the local filesystem

  git clone file:////path/to/repo/project.git/ .

PHP function to remove whitespaces from a string

Usage :

$spaceRemovedString = removeWhiteSpaces($stringWithSpace);

 

Function :

function removeWhiteSpaces($spaceStr)
{
	$newStr = preg_replace('/\s+/', '', $spaceStr);
	return $newStr;
}

Repairing Accidental Damage to file system permissions and ownership

There are cases when you might accidently change the system permissions and you want to revert it back to default permissions. You can revert ownership and permissions on installed packages by using rpm or you can copy permissions from a clone machine if you have one.

Copying permissions and resetting from a clone machine :

Export the permissions from a good machine :

find / /usr /home -xdev | xargs getfacl -P > /tmp/goodPermissions

Now copy that file and  Import on the damaged machine

setfacl --restore=/tmp/goodPermissions

 

Reset Permissions using RPM

rpm --setperms –a

Or To reset for a single package :

rpm --setperms <packagename>

 

To reset the ownership :

rpm --setugids –a 

or to reset ownership on single package :

rpm --setugids <packagename>

Handling Multiple SSH Keys and Ports for Multiple Machines

You might have to deal with a lot of machines with different keys and ports. Here is a simple way to make that easier.

Edit / Create ssh config file.

vi ~yourUserName/.ssh/config

Put the information about your hosts into the config file:

 

Host server1.example.com

HostName server1.example.com
IdentityFile ~/.ssh/server1_rsa
User userName
Port xxxx
ServerAliveInterval 30
ServerAliveCountMax 120

PROMPT_COMMAND='echo -ne "33]0;${USER}@${HOSTNAME}: ${PWD}07"'

Now whenever you try to connect to that host, it will use the key, username and port defined in this config file.