Enable status in PHP-fpm + Nginx

It was a little bit confusing to set it up. So here’s the memo.

vi /etc/php5/fpm/pool.d/www.conf

pm.status_path = /status
listen = 127.0.0.1:9000

vi /etc/nginx/sites-available/monitor
location ~ ^/(status|ping)$ {
include fastcgi_params;
#access_log off;
allow 127.0.0.1;
allow xx.xx.xx.xx;
deny all;
fastcgi_param SCRIPT_FILENAME /status;
fastcgi_pass 127.0.0.1:9000;
}

Restart nginx and php-fpm processes.

Ref: Here

Resize root partition of a virtual machine on VMware

When it comes to a situation that the disk space is not enough on a virtual machine, it’s easy to extend the disk space if it’s on LVM, even the /root partition.

This post is very helpful.

For my own memo:
Case:
VM on VMware, installed with CentOS 6.x
#fdisk -l shows
Disk /dev/sda: 12GB ….
/dev/sda1 2 501 512000 83 Linux
/dev/sda2 502 12288 12069888 8e Linux LVM

On /dev/sda2
Disk /dev/mapper/vg_node1-lv_root: 7.5 GB
Disk /dev/mapper/vg_node1-lv_swap: 4 GB

Goal: Add 8G extra space to /dev/mapper/vg_node1-lv_root

Steps:
1. Using VMware GUI to add 8G to the virtual machine. Make sure it recognizes the new size.

2. Memo the current cylinder start number of /dev/sda2
/dev/sda2 502 12288 12069888 8e Linux LVM

3. Delete partition /dev/sda2 then recreate it with the new size
fdisk /dev/sda
Use command “d”, then “2” to delete /dev/sda2
Use “n” to create a new partition, partition number is “2”
Use “t” to change partition type to 8e as “Linux LVM”
Then “w” to save the change

Reboot the VM

Now the partition size is changed. I need to change the pv size and vg size.

5. Change pv size
pvsize /dev/sda2

6. Change vg size
#vgdisplay (found the free PE = 2048 )
#lvextend /dev/mapper/vg_node1-lv_root –extents +2048

7. Still need to increase file system size
#resize2fs /dev/mapper/vg_node1-lv_root

————————————————————————-
Another way to do it

1. Add disk space from vmware GUI, however the following command didn’t work, so reboot
echo “- – -” > /sys/class/scsi_host/host0/scan

2. frisk -l shows new disk space on /dev/sda
create a new partition on /dev/sda
frisk /dev/sda -> n -> p -> 3 -> it will show the right start/end block number automatically, so just hit enter,
-> t -> 8e -> w

3. fdisk shows /dev/sda3, the new partition created.
However it warns the kernel won’t use the new table until reboot, so reboot for the 2nd time

4. Create a new physical volume on lvm using sda3
pvcreate /dev/sda3

5. find vg name from vgdisplay, find vg name is using “centos”, add sda3 to virtual group
vgextend centos /dev/sda3

6. pvscan shows sda3 as a member of vg “centos”
[root@mononoke ~]# pvscan
PV /dev/sda2 VG centos lvm2 [15.51 GiB / 0 free]
PV /dev/sda3 VG centos lvm2 [9.00 GiB / 0 free]
Total: 2 [24.50 GiB] / in use: 2 [24.50 GiB] / in no VG: 0 [0 ]

7. lvdisplay shows 2 logical volumes, /dev/centos/root and /dev/centos/swap,
lvextend /dev/centos/root /dev/sda3

8. resize file system, since it’s using XFS on centos7,
xfs_growfs /dev/centos/root

Here‘s the reference

——————————————————-
To check how much free space left in a physical volume, do pvdisplay, then find value of “Free PE”

— Physical volume —
PV Name /dev/sdb2
VG Name test_vg
PV Size 20.00 GiB / not usable 1.31 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 5120
Free PE 2620
Allocated PE 2500

Check Linux server status

vmstat, iostat, top…etc are useful to check server load, I/O or memory usage.

iostat
r/s and w/s
the number of read and write requests sent to the device per second
await
the number of requests waiting in the device’s queue
svctm
the number of miliseconds spent servicing requests, from beginning to end
util
the percentage of the device utilization

vmstat
procs
r: processes are waiting for the CPU time
b: processes are in sleep (means they are waiting for I/O)
io
bi/bo: how many blocks reading in/out the device
system
in: number of interrupts per second
cs: context switches per second

Here are some good sites showing how to use them

http://www.cyberciti.biz/tips/linux-disk-performance-monitoring-howto.html
http://www.cyberciti.biz/tips/how-do-i-find-out-linux-cpu-utilization.html
http://www.linuxforums.org/articles/using-top-more-efficiently_89.html
http://software.intel.com/en-us/blogs/2011/02/09/using-linux-top-to-troubleshoot-multi-core-scalability-issues-at-dreamworks-animation/

Good article about I/O scheduler
http://www.linuxjournal.com/article/6931

Create my own AWS AMI

Followed this very detailed instruction to create my own CentOS5 AWS AMI image

How to create an Amazon Elastic Compute Cloud EC2 Machine Image (AMI)

Every thing went all right except the problem came when booting the image…it doesn’t boot.

It seems that the kernel 2.6.16 is too old, so download 2.6.18 from Amazon Dev forum.
Rebundled and registered the image with new kernel but still it doesn’t boot….
The next thing I tried is to specify the kernel ID and RAM ID as the same ones which is used to bundle/upload AMI images, when bringing up the instance. It booted this time.

Using the following way to convert the instance-store backed image to EBS backed image.
Bring up a EBS volume and attach to this server,
# mkdir /newos && mount /dev/sdf /newos
# rsync -avHx / /newos
# rsync -avHx /dev /newos
# sync;sync;sync;sync && umount /newos
Then create a snapshot of the volume.

Use command line or aws admin console to register AMI
Register the AMI
# ec2-register -a x86_64 –block-device-mapping /dev/sda1=snap-2715c442::false –name mycentos5ebs_2012 –kernel aki-xxxxxx –ramdisk ari-xxxxxx -K pk-xxxxxxxxxxxxx.pem -C cert-xxxxxxxxxxxx.pem –region us-west-1
IMAGE ami-xxxxxx
(use the same aki-xxxxx and ari-xxxxxx as the original server used for creating image)

Another issue:
When running “yum update”, it shows error message for corrupted rpm db.
It seems that rpm db is using Berkely DB and after tried to fix the db by
rm -f /var/lib/rpm/__db*
rpm –rebuilddb
It still shows error “cannot open Packages index using db3”

So initial the db by
rpm –initdb
then install the Base yum packages again
yum -y groupinstall Base

References
http://www.howtoforge.com/kernel_compilation_fedora
http://www.cyberciti.biz/tips/compiling-linux-kernel-26.html
http://aws.typepad.com/aws/2010/07/use-your-own-kernel-with-amazon-ec2.html
http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/UserProvidedkernels.html
http://www.ibm.com/developerworks/linux/library/l-linuxboot/
http://amazonaws.michael–martinez.com/

Installing Cent OS 5.5 on EC2 with the Cent OS 5.5 Kernel

New VM network issum

After brought up a new VM on VMware using CentOS template, I had problem to setup the network.
“The network device eth0 seems missing” was shown when I tried to bring up eth0. But actually the system thought the device is eth2!

Here is a good article showing how to fix this issue,

Here