Friday, April 4, 2014

OpenVZ: Mounting Host Devices/Partitions/Directories In A Container



OpenVZ: Mounting Host Devices/Partitions/Directories In A Container 

Preparing The Host

Host:
If you have added a new hard drive to the host, you should see it in the output of...
fdisk -l
... and you should see that it is unformatted (unless you have created partitions on it previously) - in this example the hard drive is /dev/sdb:
root@server1:~# fdisk -l

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00029d5c

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        3793    30461952   83  Linux
/dev/sda2            3793        3917      992257    5  Extended
/dev/sda5            3793        3917      992256   82  Linux swap / Solaris

Disk /dev/sdb: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table
root@server1:~#
Let's create one single partition on it:
fdisk /dev/sdb
root@server1:~# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x31e0dc4b.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help):
 <-- n
Command action
   e   extended
   p   primary partition (1-4)

<-- p
Partition number (1-4): <-- 1
First cylinder (1-3916, default 1): <-- ENTER
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-3916, default 3916):
 <-- ENTER
Using default value 3916

Command (m for help):
 <-- t
Selected partition 1
Hex code (type L to list codes):
 <-- L

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris
 1  FAT12           39  Plan 9          82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      3c  PartitionMagic  83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       40  Venix 80286     84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      41  PPC PReP Boot   85  Linux extended  c7  Syrinx
 5  Extended        42  SFS             86  NTFS volume set da  Non-FS data
 6  FAT16           4d  QNX4.x          87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS       4e  QNX4.x 2nd part 88  Linux plaintext de  Dell Utility
 8  AIX             4f  QNX4.x 3rd part 8e  Linux LVM       df  BootIt
 9  AIX bootable    50  OnTrack DM      93  Amoeba          e1  DOS access
 a  OS/2 Boot Manag 51  OnTrack DM6 Aux 94  Amoeba BBT      e3  DOS R/O
 b  W95 FAT32       52  CP/M            9f  BSD/OS          e4  SpeedStor
 c  W95 FAT32 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi eb  BeOS fs
 e  W95 FAT16 (LBA) 54  OnTrackDM6      a5  FreeBSD         ee  GPT
 f  W95 Ext'd (LBA) 55  EZ-Drive        a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            56  Golden Bow      a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    5c  Priam Edisk     a8  Darwin UFS      f1  SpeedStor
12  Compaq diagnost 61  SpeedStor       a9  NetBSD          f4  SpeedStor
14  Hidden FAT16 <3 63  GNU HURD or Sys ab  Darwin boot     f2  DOS secondary
16  Hidden FAT16    64  Novell Netware  af  HFS / HFS+      fb  VMware VMFS
17  Hidden HPFS/NTF 65  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE
18  AST SmartSleep  70  DiskSecure Mult b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 75  PC/IX           bb  Boot Wizard hid fe  LANstep
1c  Hidden W95 FAT3 80  Old Minix       be  Solaris boot    ff  BBT
1e  Hidden W95 FAT1
Hex code (type L to list codes):
 <-- 83

Command (m for help): <-- w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
root@server1:~#

Afterwards, there should be the partition /dev/sdb1:
fdisk -l
root@server1:~# fdisk -l

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00029d5c

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        3793    30461952   83  Linux
/dev/sda2            3793        3917      992257    5  Extended
/dev/sda5            3793        3917      992256   82  Linux swap / Solaris

Disk /dev/sdb: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x31e0dc4b

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        3916    31455238+  83  Linux
root@server1:~#
Let's format it with ext4...
mkfs.ext4 /dev/sdb1
... and mount it to /mnt/sdb1:
mkdir /mnt/sdb1
mount /dev/sdb1 /mnt/sdb1
You should see /dev/sdb1 in the output of...
mount
... now:
root@server1:~# mount
/dev/sda1 on / type ext3 (rw,errors=remount-ro)
tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
udev on /dev type tmpfs (rw,mode=0755)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)
/dev/sdb1 on /mnt/sdb1 type ext4 (rw)
root@server1:~#
To have /dev/sdb1 mounted automatically at boot time, add it to /etc/fstab:
vi /etc/fstab
[...]
/dev/sdb1 /mnt/sdb1               ext4    errors=remount-ro 0       1

Fr. terminal:
root@server1:~# mount -a
root@server1:~#df -h ( to check if mount drive is mounted)

Ref://http://www.howtoforge.com/openvz-mounting-host-devices-partitions-directories-in-a-container-with-bind-mounts-debian-ubuntu

Tuesday, February 4, 2014

How to setup NFS client (mount)

    
Download Your Free eBooks NOW - 10 Free Linux eBooks for Administrators
NFS (Network File System) is basically developed for sharing of files and folders between Linux/Unix systems by Sun Microsystems in 1980. It allows you to mount your local file systems over a network and remote hosts to interact with them as they are mounted locally on the same system. With the help of NFS, we can set up file sharing between Unix to Linux system and Linux to Unix system.
Install NFS Server in Linux
Setup NFS Server and NFS Client in Linux
Benefits of NFS
  1. NFS allows local access to remote files.
  2. It uses standard client/server architecture for file sharing between all *nix based machines.
  3. With NFS it is not necessary that both machines run on the same OS.
  4. With the help of NFS we can configure centralized storage solutions.
  5. Users get their data irrespective of physical location.
  6. No manual refresh needed for new files.
  7. Newer version of NFS also supports acl, pseudo root mounts.
  8. Can be secured with Firewalls and Kerberos.
NFS Services
Its a System V-launched service. The NFS server package includes three facilities, included in the portmap and nfs-utils packages.
  1. portmap : It maps calls made from other machines to the correct RPC service (not required with NFSv4).
  2. nfs: It translates remote file sharing requests into requests on the local file system.
  3. rpc.mountd: This service is responsible for mounting and unmounting of file systems.
Important Files for NFS Configuration
  1. /etc/exports : Its a main configuration file of NFS, all exported files and directories are defined in this file at the NFS Server end.
  2. /etc/fstab : To mount a NFS directory on your system across the reboots, we need to make an entry in /etc/fstab.
  3. /etc/sysconfig/nfs : Configuration file of NFS to control on which port rpc and other services are listening.

Setup and Configure NFS Mounts on Linux Server

To setup NFS mounts, we’ll be needing at least two Linux/Unix machines. Here in this tutorial, I’ll be using two servers.
  1. NFS Server: nfsserver.example.com with IP-192.168.0.100
  2. NFS Client : nfsclient.example.com with IP-192.168.0.101
Installing NFS Server and NFS Client
We need to install NFS packages on our NFS Server as well as on NFS Client machine. We can install it via “yum” (Red Hat Linux) and “apt-get” (Debian and Ubuntu) package installers.
[root@nfsserver ~]# yum install nfs-utils nfs-utils-lib
[root@nfsserver ~]# yum install portmap (not required with NFSv4)
[root@nfsserver ~]# apt-get install nfs-utils nfs-utils-lib
Now start the services on both machines.
[root@nfsserver ~]# /etc/init.d/portmap start
[root@nfsserver ~]# /etc/init.d/nfs start
[root@nfsserver ~]# chkconfig --level 35 portmap on
[root@nfsserver ~]# chkconfig --level 35 nfs on
After installing packages and starting services on both the machines, we need to configure both the machines for file sharing.

Setting Up the NFS Server

First we will be configuring the NFS server.
Configure Export directory
For sharing a directory with NFS, we need to make an entry in “/etc/exports” configuration file. Here I’ll be creating a new directory named “nfsshare” in “/” partition to share with client server, you can also share an already existing directory with NFS.
[root@nfsserver ~]# mkdir /nfsshare
Now we need to make an entry in “/etc/exports” and restart the services to make our directory shareable in the network.
[root@nfsserver ~]# vi /etc/exports

/nfsshare 192.168.0.101(rw,sync,no_root_squash)
In the above example, there is a directory in / partition named “nfsshare” is being shared with client IP “192.168.0.101” with read and write (rw) privilege, you can also use hostname of the client in the place of IP in above example.
NFS Options
Some other options we can use in “/etc/exports” file for file sharing is as follows.
  1. ro: With the help of this option we can provide read only access to the shared files i.e client will only be able to read.
  2. rw: This option allows the client server to both read and write access within the shared directory.
  3. sync: Sync confirms requests to the shared directory only once the changes have been committed.
  4. no_subtree_check: This option prevents the subtree checking. When a shared directory is the subdirectory of a larger file system, nfs performs scans of every directory above it, in order to verify its permissions and details. Disabling the subtree check may increase the reliability of NFS, but reduce security.
  5. no_root_squash: This phrase allows root to connect to the designated directory.
For more options with “/etc/exports“, you are recommended to read the man pages for export.

Setting Up the NFS Client

After configuring the NFS server, we need to mount that shared directory or partition in the client server.
Mount Shared Directories on NFS Client
Now at the NFS client end, we need to mount that directory in our server to access it locally. To do so, first we need to find out that shares available on the remote server or NFS Server.
[root@nfsclient ~]# showmount -e 192.168.0.100

Export list for 192.168.0.100:
/nfsshare 192.168.0.101
Above command shows that a directory named “nfsshare” is available at “192.168.0.100” to share with your server.
Mount Shared NFS Directory
To mount that shared NFS directory we can use following mount command.
[root@nfsclient ~]# mount -t nfs 192.168.0.100:/nfsshare /mnt/nfsshare
The above command will mount that shared directory in “/mnt/nfsshare” on the client server. You can verify it following command.
[root@nfsclient ~]# mount | grep nfs

sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
192.168.0.100:/nfsshare on /mnt type nfs (rw,addr=192.168.0.100)
The above mount command mounted the nfs shared directory on to nfs client temporarily, to mount an NFS directory permanently on your system across the reboots, we need to make an entry in “/etc/fstab“.
[root@nfsclient ~]# vi /etc/fstab
Add the following new line as shown below.
192.168.0.100:/nfsshare /mnt  nfs defauls 0 0

Test the Working of NFS Setup

We can test our NFS server setup by creating a test file on the server end and check its availability at nfs client side or vice-versa.
At the nfsserver end
I have created a new text file named “nfstest.txt’ in that shared directory.
[root@nfsserver ~]# cat > /nfsshare/nfstest.txt

This is a test file to test the working of NFS server setup.
At the nfsclient end
Go to that shared directory in client server and you’ll find that shared file without any manual refresh or service restart.
[root@nfsclient]# ll /mnt/nfsshare
total 4
-rw-r--r-- 1 root root 61 Sep 21 21:44 nfstest.txt
root@nfsclient ~]# cat /mnt/nfsshare/nfstest.txt
This is a test file to test the working of NFS server setup.

Removing the NFS Mount

If you want to unmount that shared directory from your server after you are done with the file sharing, you can simply unmount that particular directory with “umount” command. See this example below.
root@nfsclient ~]# umount /mnt/nfsshare
You can see that the mounts were removed by then looking at the filesystem again.
[root@nfsclient ~]# df -h -F nfs
You’ll see that those shared directories are not available any more.
Important commands for NFS
Some more important commands for NFS.
  1. showmount -e : Shows the available shares on your local machine
  2. showmount -e <server-ip or hostname>: Lists the available shares at the remote server
  3. showmount -d : Lists all the sub directories
  4. exportfs -v : Displays a list of shares files and options on a server
  5. exportfs -a : Exports all shares listed in /etc/exports, or given name
  6. exportfs -u : Unexports all shares listed in /etc/exports, or given name
  7. exportfs -r : Refresh the server’s list after modifying /etc/exports
This is it with NFS mounts for now, this was just a start, I’ll come up with more option and features of NFS in our future articles. Till then, Stay connected with Tecmint.com for more exciting and interesting tutorials in future. Do leave your comments and suggestions below in the comment box.

Referemce:  www.tecmint.com/how-to-setup-nfs-server-in-linux/


Sunday, January 20, 2013

fstab error, can't boot, can't edit fstab

Centos /Fedora OS

Fr. terminal

#  "mount -o remount,rw /"

then save and reboot

Saturday, January 19, 2013

Getting to know your Hardware

Getting to know your HW of your linux box.


From terminal:
Type:

hdparm -I /dev/sda | grep Serial 

source: http://linuxconfig.org/getting-know-a-hardware-on-your-linux-box

Tuesday, January 15, 2013

Creating/renaming network device i.e eth1 ; eht2

Creating/renaming stable names for network interfaces

to edit or rearrange device name on centos

vi /etc/udev/rules.d/70-persistent-net.rules

Wednesday, January 9, 2013

Installation and configuration of MRTG - Centos 6.3

Procedure:

From the terminal:
#: yum install snmp

Check if snmp is installed
# rpm -qa | grep snmp

Start the service fr. the terminal
# service snmpd start
#chkconfig snmpd on ( to start the service after reboot)

Configuration.

# vi /etc/snmp/snmpd.conf

enter the ff:
rocommunity     craz33guy
disk               /

where cras33guy = userrname

From terminal
# cfgmaker --global 'workdir: /var/www/mrtg/mymrtg' --output /etc/mrtg/mrtg.cfg craz33guy@192.168.60.xxx

# env LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg.l --confcache-file /var/lib/mrtg/mrtg.ok
# indexmaker  --output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg

then open /etc/#vi /etc/mrtg - edit the necessary changes
I.E.  mrtgTitle[192.168.60.191_192.168.60.191]: Traffic Analysis for 3 -- row-based|\


TWO CONNECT OTHER SERVER/UNIT

Fr. /etc/mrtg/dotxxx
Edit the ff:
# cd /etc/mrtg### Interface 3 >> Descr: 'eth0' | Name: 'eth0' | Ip: '192.168.60.191' | Eth: '00-13-46-3c-80-77' ###
Target[192.168.60.xxx_192.168.60.xxx]: /192.168.60.xxx:craz33guy@192.168.60.xxx:
SetEnv[192.168.60.xxx_192.168.60.xxx]: MRTG_INT_IP="192.168.60.xxx" MRTG_INT_DESCR="eth0"
MaxBytes[192.168.60.xxx_192.168.60.xxx]: 12500000
#mkdir dotxxx i.e dot191
Title[192.168.60.191_192.168.60.191]: Traffic Analysis for 3 -- row-based|\
PageTop[192.168.60.191_192.168.60.191]: <h1>192.168.60.191 -- row-based </h1>
                <div id="sysdetails">
                        <table> <tr> <td>System:</td> <td>row-based in Unknown</td>
                                </tr> <tr> <td>Maintainer:</td><td>root@localhost</td>
                                </tr> <tr><td>Description:</td> <td>eth0  </td>
                                </tr> <tr><td>ifType:</td><td>ethernetCsmacd (6)</td>
                                </tr>
                                <tr><td>ifName:</td> <td>eth0</td>
                                </tr>
                                <tr> <td>Max Speed:</td><td>12.5 MBytes/s</td>
                                </tr>
                                <tr> <td>Ip:</td> <td>192.168.60.191 ()</td>
                                </tr>
                        </table>
                </div>
then type

# env LANG=C /usr/bin/mrtg /etc/mrtg/dot191/dot191.cfg --lock-file /var/lock/mrtg/dot191._l --confcache-file /var/lib/mrtg/dot191.ok

# indexmaker --output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg /etc/mrtg/dot191/dot191.cfg

To VIEW MRTG
Fr. browser type
192.168.60.xxx/mrtg




















Monday, January 7, 2013

Configuring NFS Server

[1]It's the Configuration on the system you want to build NFS server.
[root@dlp ~]#
yum -y install nfs-utils
[root@dlp ~]#
vi /etc/idmapd.conf
# line 5: uncomment and change to your domain name

Domain =
server.world
[root@dlp ~]#
vi /etc/exports
# write like below *note

/home 10.0.0.0/24(rw,sync,no_root_squash,no_all_squash)
# *note
/home

⇒ shared directory

10.0.0.0/24
⇒ range of networks NFS permits accesses

rw
⇒ writable

sync
⇒ synchronize

no_root_squash
⇒ enable root privilege

no_all_squash
⇒ enable users' authority
[root@dlp ~]#
/etc/rc.d/init.d/rpcbind start

Starting rpcbind:
[  OK  ]

[root@dlp ~]#
/etc/rc.d/init.d/nfslock start

Starting NFS statd:
[  OK  ]

[root@dlp ~]#
/etc/rc.d/init.d/nfs start

RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
Installing knfsd (copyright (C) 1996 okir@monad.swb.de).
Starting NFS services:

[  OK  ]

Starting NFS daemon: NFSD: Using /var/lib/nfs/v4recovery as the NFSv4 state recovery directory
NFSD: starting 90-second grace period
[ OK ]

Starting NFS mountd: [ OK ]
[  OK  ]

Starting RPC idmapd: [ OK ]
[  OK  ]
[root@dlp ~]#
chkconfig  rpcbind on

[root@dlp ~]#
chkconfig nfslock on

[root@dlp ~]#
chkconfig nfs on
Configuration on NFS clients

[root@www ~]#
yum -y install nfs-utils
# install
[root@www ~]#
vi /etc/idmapd.conf
# line 5: uncomment and change to your domain name

Domain =
server.world
[root@www ~]#
/etc/rc.d/init.d/rpcbind start

Starting rpcbind:
[  OK  ]

[root@www ~]#
/etc/rc.d/init.d/rpcidmapd start

Starting RPC idmapd: RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
[ OK ]
[root@www ~]#
/etc/rc.d/init.d/nfslock start

Starting NFS statd:
[  OK  ]

[root@www ~]#
/etc/rc.d/init.d/netfs start

Mounting other filesystems:
[  OK  ]

[root@www ~]#
chkconfig rpcbind on

[root@www ~]#
chkconfig rpcidmapd on

[root@www ~]#
chkconfig nfslock on

[root@www ~]#
chkconfig netfs on

[root@www ~]#
mount -t nfs dlp.server.world:/home /home

[root@www ~]#
df -h

Mounted on

192.168.xx.x:/var/spool/asterisk/incoming      272G   36G  222G  14% /var/www/html/recordings/incoming

# home directory on NFS is mounted
[root@www ~]#
vi /etc/fstab

# add at the lat line:  server mounts to the one on NFS

/192.168.xx.x:/var/spool/asterisk/incoming  /var/www/html/recordings/incomin                                  g             nfs  hard,intr   0 0

Thursday, January 3, 2013

Finding a File containing a particular text string in Linux server

You need to use grep command. grep searches the given input FILEs for lines containing a match or a text string.

grep command form (syntax)

grep “text string to search” directory-path or ip addtress

Examples

For example search for a string called redeem reward in all text files located in /home/guest/*.txt directory, use
$ grep "192.168.xx.xx" /home/guest/*.txt

Task: Search all subdirectories recursively

You can search for a text string all files under each directory, recursively with -roption:
$ grep -r "192.168.xx.xx" /home/guest

Task: Only print filenames

By default, grep command prints the matching lines You can pass -H option to print the filename for each match.
$ grep -H -r “192.168.xx.xx” /home/guest
Output:
...
filename.txt: 192.168.xx.xx
...
To just print the filename use cut command as follows:
$ grep -H vivek /etc/* -R | cut -d: -f1



Output:

Sunday, December 30, 2012

Best way to test if a ssh tunnel is still active.

On linux, the command netstat -nt ¦ grep yourip:22 should give you a list of currently active ssh connections.

Sunday, December 23, 2012

Disable SElinux

How to disable SELinux
From  the Command Line  From the command line, you can edit the /etc/sysconfig/selinux file. This file is a symlink to /etc/selinux/config.  Change the value of SELINUX or SELINUXTYPE to disabled  Reboot the unit.

[root@host2a ~]# cat /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 - SELinux is fully disabled.
SELINUX=permissive
# SELINUXTYPE= type of policy in use. Possible values are:
#       targeted - Only targeted network daemons are protected.
#       strict - Full SELinux protection.
SELINUXTYPE=targeted

# SETLOCALDEFS= Check local definition changes
SETLOCALDEFS=0

Use the command below to check the status of SELINUX
From  the command line:  
# type :    sestatus
# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   enforcing
Mode from config file:          enforcing
Policy version:                 21
Policy from config file:        targeted

Changes will take effect  after the reboot. Check once again if selinux status is diabled
From the terminal
#  sestatus
Selinux  diabled
This will determine if changes from selinux configuration took effect.
If not
From the command :
Type:  iptables –F ( Flush)
Service iptables  save
Note: Same procedure if you want to enable SElinux

Uograding Mysql Enterprise to MySQL 5.5 and 5.1 on CentOS 5.5

Procedure
Link to upgrade:
rpm –Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
yum update
Note : For Centos 6.3
I
yum install libmysqlclient16 --enablerepo=webtatic
For 5.5 Just change libmysqlclient16 to libmysqlclient15

Tuesday, October 2, 2012

Linux Hard Disk Format Command

Step #1 : Partition the new disk using fdisk command

list all detected hard disks:
# fdisk -l | grep '^Disk'
Output:

Disk /dev/sda: 251.0 GB, 251000193024 bytes
Disk /dev/sdb: 251.0 GB, 251000193024 bytes
A device name refers to the entire hard disk. For more information see Linux partition naming convention and IDE drive mappings.
To partition the disk - /dev/sdb, enter:

# fdisk /dev/sdb
Step#2 : Format the new disk using mkfs.ext3 command
To format Linux partitions using ext2fs on the new disk:
# mkfs.ext3 /dev/sdb1

Step#3 : Mount the new disk using mount command

create a mount point /disk1 and use mount command to mount /dev/sdb1, enter:
# mkdir /disk1
# mount /dev/sdb1 /disk1
# df -H

Step#4 : Update /etc/fstab file

Open /etc/fstab file, enter:
# vi /etc/fstab
Append as follows:
/dev/sdb1               /disk1           ext3    defaults        1 2
Save and close the file.

Task: Label the partition

You can use label name insted of partition name to mount disk using /etc/fstab:
LABEL=/backup /disk1 ext3 defaults 1 2


ref: http://www.cyberciti.biz/faq/linux-disk-format/

Wednesday, September 12, 2012

Setting a UTC Timezone

What timezone should you use for your server?  Perhaps you should try Universal Co-ordinated Time (UTC).
vi /etc/sysconfig/clock and change the UTC line to: "UTC=true"
Set localtimezone to UTC: ln -sf /usr/share/zoneinfo/UTC /etc/localtime


Other Timezone

For example: ln -sf /usr/share/zoneinfo/Australia/Brisbane /etc/localtime.

Tuesday, September 4, 2012

Upgrade PHP 5.1/5.2 to 5.3 on CentOS

To upgrade from 5.2 to PHP 5.3
1.  used the yum commands list command to quickly get this information:
2. yum search php53 | cut -d' ' -f1 | grep php
3. First, shut down the Apache server as I didn’t want people going to broken pages as I did these updates:
     service httpd stop
4. Next, remove the old PHP packages:
 yum remove php php-cli php-common php-devel php-gd php-mbstring \
5. Finally,  installed the available replacement packages:
 yum install php53 php53-cli php53-common php53-devel php53-gd \

6. Install PHP mcrypt
Need to install the development package for mcrypt
      yum install php53-devel libmcrypt-devel
wget http://museum.php.net/php5/php-5.3.3.tar.gz
tar xf php-5.3.3.tar.gz
cd php-5.3.3/ext/mcrypt/
phpize
./configure
make
make test
make install
echo -e "; Enable mcrypt extension module\nextension=mcrypt.so" | \
wget http://pear.php.net/go-pear.phar
php go-pear.phar
PHP 5.3 now requires that you either have a timezone set in your php.ini file or that you pass the desired timezone via the date_default_timezone_set() function before calling the date() function.
I opened my server’s /etc/php.ini file and searched for timezone. My ini file had a section like the following:
[Date]
; Defines the default timezone used by the date functions
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
; date.timezone =
I uncommented the date.timezone line and added the timezone I wanted.
[Date]
; Defines the default timezone used by the date functions
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
date.timezone = 'America/Chicago'
There are two very important things to do in order for this to work properly for you:
    Use a timezone that is appropriate for your needs. Use PHP’s List of Supported Timezones to find the timezone that works for you.
    Since your server is likely to cache the PHP configuration, you will want to restart your web server process in order for the change to be recognized. The command to execute varies by system, but for most systems, the following will work:
    [user@server /etc]$ sudo service httpd restart
    [sudo] password for user:
    Stopping httpd:                                            [  OK  ]
    Starting httpd:                                            [  OK  ]
    [user@server /etc]$
 
Installing from repositoty
Fr. terminal

# wget http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
$wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
#ls
#rpm -ivh epel-release-5-4.noarch.rpm
#rpm -ivh remi-release-5.rpm

#yum remove php* (existing php)
#yum install php php-cli php-gd php-mysql php-mbstring php-pear enable=remi


Reference:
http://chrisjean.com/2011/06/24/upgrade-php-5-1-or-5-2-to-5-3-on-centos/

TIMEZONE ISSUE
http://chrisjean.com/2011/06/24/php-5-3-and-system-timezone-settings/

TO TEST THE CNF PERFORMANCE
http://www.omh.cc/mycnf/


Monday, August 27, 2012

MySQL Memory Allocation

Allocating RAM for MySQL - The Short Answer


If using just MyISAM, set key_buffer_size to 20% of _available_ RAM. (Plus innodb_buffer_pool_size=0)

If using just InnoDB, set innodb_buffer_pool_size t0 70% of _available_ RAM. (Plus key_buffer_size = 10M, small, but not zero.)

Rule of thumb for tuning mysql:
    ⚈  Start with released copy of my.cnf / my.ini.
    ⚈  Set key_buffer_size and innodb_buffer_pool_size according to engine usage and RAM.
    ⚈  Slow queries can usually be 'fixed' via indexes, schema changes, or SELECT changes, not by tuning.
    ⚈  Don't get carried away with the Query cache until you understand what it can and cannot do.
    ⚈  Don't change anything else unless you run into trouble (eg, max connections).
    ⚈  Be sure the changes are under the [mysqld] section, not some other section.

Now for the gory details. (NDB Cluster is not discussed here.)

What is the key_buffer?


MyISAM does two different things for caching.
    ⚈  Index blocks (1KB each, BTree structured, from .MYI file) live in the "key buffer".
    ⚈  Data block caching (from .MYD file) is left to the OS, so be sure to leave a bunch of free space for this
Caveat: Some flavors of OS always claim to be using over 90%, even when there is really lots of free space.

SHOW GLOBAL STATUS LIKE 'Key%'; then calculate Key_read_requests / Key_reads If it is high (say, over 10), then the key_buffer is big enough.

What is the buffer_pool?


InnoDB does all its caching in a the "buffer pool", whose size is controlled by innodb_buffer_pool_size. It contains 16KB data and index blocks from the open tables, plus some maintenance overhead.

MySQL 5.5 (and 5.1 with the "Plugin") lets you declare the block size to be 8KB or 4KB. MySQL 5.5 allows multiple buffer pools; this can help because there is one mutex per pool, thereby relieving some of the Mutex bottleneck

Mutex bottleneck

MySQL was designed in the days of single-CPU machines, and designed to be easily ported to many different architectures. Unfortunately, that lead to some sloppiness in how to interlock actions. A small number (too small) of "mutexes" to gain access to several critical processes. Of note:
    ⚈  MyISAM's key_buffer
    ⚈  The Query Cache
    ⚈  InnoDB's buffer_pool
With multi-core boxes, the mutex problem is causing performance problems. In general, past 4-8 cores, MySQL gets slower, not faster. MySQL 5.5 is making that somewhat better in InnoDB; the practical limit for cores is more like 32, and performance tends plateaus after that rather than declining.

One anecdote says "OpenSuse / Ubuntu distribution for multi core CPUs is not optimal": Forum #392502

HyperThreading and Multiple cores (CPUs)


Short answers:
    ⚈  Turn off HyperThreading
    ⚈  Turn off any cores beyond 8

HyperThreading is great for marketing, lousy for performance. It involves having two processing units sharing a single cache. If both units are doing the same thing, the cache will be reasonably useful. If the units are doing different things, they will be clobbering the cache entries that the other one wants.

Furthermore MySQL is not great on using multiple cores. So, if you turn off HT, the remaining cores run a little faster.

32-bit OS and MySQL


First, the OS (and the hardware?) may conspire to not let you use all 4GB, if that is what you have. If you have more than 4GB of RAM, the excess beyond 4GB is _totally_ inaccessable and unusable.

Secondly, the OS probably has a limit on how much RAM it will allow any process to use.

Example: FreeBSD's maxdsiz, which defaults to 512MB.

Example:
$ ulimt -a
...
max memory size (kbytes, -m) 524288

So, once you have determined how much RAM is available to mysqld, then apply the 20%/70%, but round down some.

If you get an error like [ERROR] /usr/libexec/mysqld: Out of memory (Needed xxx bytes), it probably means that MySQL exceeded what the OS is willing to give it. Decrease the cache settings.

64-bit OS with 32-bit MySQL


This combo relieves you of the OS limits in "32-bit OS and MySQL", and moves toward "64-bit OS and MySQL" with a limit of 4GB.

You should probably upgrade MySQL to 64-bit.

Anyway, if you have at least 4GB of RAM, then maybe these would be good:
    ⚈  key_buffer_size = 20% of _all_ of RAM, but not more than 3G
    ⚈  buffer_pool = 3G

64-bit OS and MySQL


MyISAM only: key_buffer_size (before 5.0.52 / 5.1.23) had a hard limit of 4G. See also 5.1 restrictions
Otherwise, use about 20% of RAM. Set (in my.cnf / my.ini) innodb_buffer_pool_size = 0.

InnoDB only: innodb_buffer_pool_size = 70% of RAM. If you have lots of RAM and are using 5.5, then consider having multiple pools. Set key_buffer_size = 20M (tiny, but non-zero)

If you have a mixture of engines, lower both numbers.

max_connections, thread_stack


Each "thread" takes some amount of RAM. This used to be about 200KB; 100 threads would be 20MB, not a signifcant size. If you have max_connections = 1000, then you are talking about 200MB, maybe more. Having that many connections probably implies other issues that should be addressed.

Thread stack overrun rarely happens. If it does, do something like thread_stack=256K

table_cache (table_open_cache)


(The name change in some version.)

The OS has some limit on the number of open files it will let a process have. Each table needs 1 to 3 open files.

In *nix, ulimit tells you what the file limit is. The maximum value is in the tens of thousands, but sometimes it is set to only 1024. This limits you to about 300 tables. More discussion on ulimit

On the other side, the table cache is (was) inefficiently implemented -- lookups were done with a linear scan. Hence, setting table_cache in the thousands could actually slow down mysql. (Benchmarks have shown this.)

You can see how well your system is performing via SHOW GLOBAL STATUS; and computing the opens/second via Opened_files / Uptime Opened_tables??? If this is more than, say, 5, table_cache should be increased. If it is less than, say, 1, you might get improvement by decreasing table_cache.

Query Cache


Short answer: query_cache_type = OFF

Long answer... There are many aspects of the "Query cache", many are negative.
    ⚈  The QC is totally unrelated to the key_buffer and buffer_pool (this confuses novices)
    ⚈  When it is useful, the QC is blazingly fast. It would not be hard to create a benchmark that runs 1000x faster.
    ⚈  When _any_ write happens on a table, _all_ entries in the QC for _that_ table are removed. This can be costly. And it happens even on a readonly Slave.
    ⚈  There is a single mutex controlling the QC.
    ⚈  The QC, unless it is OFF (0), is consulted for _every_ SELECT.
    ⚈  Yes, the mutex is hit even if query_cache_type = DEMAND (2).
    ⚈  Yes, the mutex is hit even for SQL_NO_CACHE.
    ⚈  Purges are performed with a linear algorithm, so a large QC (even 200MB) can be noticeably slow.

To see how well your QC is performing, SHOW GLOBAL STATUS LIKE 'Qc%'; then compute the read hit rate: Qcache_hits / Qcache_inserts If it is over, say, 5, the QC might be worth keeping.

thread_cache_size

This is a minor tunable. Zero will slow down thread (connection) creation. A small (say, 10), non-zero number is good. The setting has essentially no impact on RAM usage.

It is the number of "extra" processes to hang onto. It does not restrict the number of threads.

swappiness


??? RHEL, in its infinite wisdom, decided to let you control how aggressively the OS will preemptively swap RAM. This is good in general, but lousy for MySQL.

MySQL would love for RAM allocations to be reasonably stable -- the caches are (mostly) pre-allocated; the threads, etc, are (mostly) of limited scope. ANY swapping is likely to severly hurt performance of MySQL.

With a high value for swappiness, you lose some RAM because the OS is trying to keep a lot of space free for future allocations (that MySQL is not likely to need).

With swappiness = 0, the OS will probably crash rather than swap. I would rather have MySQL limping than die.

Somewhere in between (say, 5?) might be a good value for a MySQL-only server.

NUMA


OK, it's time to complicate the architecture of how a CPU talks to RAM. NUMA (Non-Uniform Memory Access) enters the picture. Each CPU (or maybe socket with several cores) has a part of the RAM hanging off each. This leads to memory access being faster for local RAM, but slower (tens of cycles slower) for RAM hanging off other CPUs.

Then the OS enters the picture. In at least one case (RHEL?), two things seem to be done:
    ⚈  OS allocations are pinned to the 'first' CPU's RAM.]
    ⚈  Other allocations go by default to the first CPU until it is full.

Now for the problem.
    ⚈  The OS and MySQL have allocated all the 'first' RAM.
    ⚈  MySQL has allocated some of the second RAM.
    ⚈  The OS needs to allocate something.
Ouch -- it is out of room in the one CPU where it is willing to allocate it's stuff, so it swaps out some of MySQL. Bad.

Possible solution: Configure the BIOS to "interleave" the RAM allocations. This should prevent the premature swapping, at the cost of off-CPU RAM accesses half the time. Well, you have the costly accesses anyway, since you really want to use all of RAM.

Overall performance loss/gain: A few percent.

huge pages


This is another hardware performance trick.

For a CPU to access RAM, especially mapping a 64-bit address to somewhere in, say, 16GB or 'real' RAM, the TLB is used. (TLB = Translation Lookup Buffer.) Think of the TLB as a hardware associative memory lookup table; given a 64-bit virtual address, what is the real address.

Because it is an associative memory of finite size, sometimes there will be "misses" that require reaching into real RAM to resolve the lookup. This is costly, so should be avoided.

Normally, RAM is 'paged' in 4KB pieces; the TLB actually maps the top 64-12 bits into a specific page. Then the bottom 12 bits of the virtual address are carried over intact.

For example, 128GB of RAM broken 4KB pages means 32M page-table entries. This is a lot, and probably far exceeds the capacity of the TLB. So, enter the "Huge page" trick.

With the help of both the hardware and the OS, it is possible to have some of RAM in huge pages, of say 4MB (instead of 4KB). This leads to far fewer TLB entries, but it means the unit of paging is 4MB for such parts of RAM. Hence, huge pages tend to be non-pagable.

Now RAM is broken into pagable and non pagable parts; what parts can reasonably be non pagable? In MySQL, the innodb_buffer_pool is] a perfect candidate. So, by correctly configuring these, InnoDB can run a little faster:
    ⚈  Huge pages enabled
    ⚈  Tell the OS to allocate the right amount (namely to match the buffer_pool)
    ⚈  Tell MySQL to use huge pages

innodb memory usage vs swap
That thread has more details on what to look for and what to set.

Overall performance gain: A few percent.

ENGINE=MEMORY


This is a little-used alternative to MyISAM and InnoDB. The data is not persistent, so it has limited uses. The size of a MEMORY table is limited to max_heap_table_size, which defaults to 16MB. I mention it in case you have changed the value to something huge; this would interfere with other possible uses of RAM.

Web server


A web server like Apache runs multiple threads. If each threads opens a connection to MySQL, you could run out of connections. Make sure MaxClients (or equivalent) is set to some civilized number (under 50).

Tools


    ⚈  MySQLTuner
    ⚈  TUNING-PRIMER

There are several tools that advise on memory. One misleading entry they come up with
Maximum possible memory usage: 31.3G (266% of installed RAM)
Don't let it scare you -- the formulas used are excessively conservative. They assume all of max_connections are in use and active, and doing something memory-intensive.

Total fragmented tables: 23 This implies that OPTIMIZE TABLE _might_ help. I suggest it for Referencetables with either a high percentage of "free space" (see SHOW TABLE STATUS) or where you know you do a lot of DELETEs and/or UPDATEs.
Reference :http://mysql.rjweb.org/doc.php/memory

SEO TOOLS

Check Page Rank of your Web site pages instantly:

This page rank checking tool is powered by Page Rank Checker service