part 4 apache conditional handling

conditional handling features:

A) make decisions based on current conditions:
 1) modules available
 2) remote HOST
 3) browser type - useragent(http header request)

B) <IfDefine> parameter - directives to be processed at server startup
C) <IfModule> - directive to be processed based on module existence. Eg mod_ssl
D) <IfVersion> - directive processed based on version of apache
E) SetEnvIf[NoCase] -sets environmental VAR (variable) based on :
   HTTP Request Header : i,e User-Agent, Referer , Accept-Language
   Remote_(Addr|Host) server_addr, Request_(method|Protocol), Request_URI
   Predefined Environmental VARs using : SetEnvIf[NoCase]
  
Task:

 Explore <IfModule>

 apachectl -D DUMP_MODULES 
 or
 apache2ctl -M | grep -E "(static|shared)" | wc -l

 cd /etc/apache2 && grep -R -i 'ifmodule' *   --searches for ifmodule

 inside the <VirutalHost>
 <VirtualHost>
 ..
 SetEnvIf Referer "site1.linuxcbt.internal" site1_referrer
 CustomLog /var/log/apache2/site2.site1_referral.access.log combined env=site1_referrer
 </VirtualHost>

part 3 apache content negotiation and content restriction

content negotiation

responds to http/1.1 request header options
presents client with bestmatch resources http/1.1
-alternate language, character set ,media type etc
handled by - mod_negotiation

content negotiation is based on 2 methods-
1 type maps - *.var file -include variants
2 MultiViews - server auto searches for alternatives based on client request

task:
negotiate content based on language

vim  index.html.var

URI: index.html

URI: index.html
Content-type: text/html
Content-language: en

URI: index.html.es
Content-type: text/html
Content-language: es


content restriction

restricts access to content based on
1 <Directory>
2 <Location> -url webspace
3 <Files>
4 <Auth> authentication related directives

default config restricts access to .htaccess , .ht* files

Tasks:
1) <Directory> - applies to filesystem location
<Directory /home/site2/www/private>
  Order allow,deny
  Allow from 127.0.0.1 192.179.90.22
</Directory>

 effectively take content offline from webspace
 <Directory /home/site2/www/private>
     Order deny,allow
     Deny from all
 </Directory>

 Use <Location> applies restriction based on URL string

 <LocationMatch ^/priv> - traps variants including but not limited to "/private , /priv ,/privilege , /primary etc"
 <LocationMatch ^/priv>
     Order deny,allow
     Deny from all
 </LocationMatch>
   eg -  example.com/privtt is restricted OR
  
   <Location ~ ^/priv>
   Order deny,allow
   Deny from all
   </Location>

 <Files> to restrict based on files
 NOTE:- it should be placed under <Directory> block or in .htaccess in particular directory as needed
 <Files ~ "\.(xls|docx|sql|pdf)">
 Order deny,allow
 deny from all
 </Files>
 <FilesMatch "\.">
   Order deny,allow
   Deny from all
 </FilesMatch




part 2 apache socket binding and htaccess

default port 80
binding facilitate virtual hosting
bindings are tagged to virtual host containers
Listen - key directive
grep -i listen #across apache config
on debian system check ports.conf

#bind to alternates ports



HTACCESS

-on demand configuration  updates to your sites managed by Apache
-substitute for "<Directory></Directory>" directives
-configure per directory options
-indirect site control via ftp,sftp etc
-

Options +Indexes
<Files *xls>
Order allow,deny
allow from 127.0.0.127 192.168.0.12/24
</Files>


Redirect /docs http://facebook.com

 

part 1 apache url mapping and redirect

Alias /doc/ "/usr/share/doc/"

if any other new directory except document root then it must be published with <Directory /your/directory/> </Directory>

AliasMatch
==========
AliasMatch ^/docs/(.*pdf) /var/www/docs2/$1

#$1 is first parenthesized block (.*pdf)<=its called reference


#anything terminating with pdf suffix

AliasMatch ^/docs/(.*pdf|txt) /var/www/docs2/$1
#anything terminating with pdf OR txt suffix
AliasMatch ^/docs/(.*) /var/www/docs2/$1
#reroute every thing to/docs2

AliasMatch ^/(docs)/(projectx)/(.*) /var/www/$2/$1/TXT/$3
#same as above but variablized

AliasMatch ^/(docs)/(projectx)/(.*\.pdf) /var/www/$2/$1/PDF/$3

                                                                                                                       

Redirect sends client to new destination
remaps url path beginning with '/' to new url
implementation of mod_alias as Redirect, RedirectMatch , RedirectPermanent, RedirectTemp
dafault status : 302
301: permanent
302:temporary

Redirect /docs  /docs2
#docs is redirected to docs2

Redirect /docs http://192.123.12.33/docs
#sends client to remote system

Redirect /docs http://www.google.com/docs

#invoke-rc.d apache2 reload


#  Using Redirect Match

RedirectMatch (.*)\.doc  $1.pdf #applies .pdf substitution across the site
eg.  google.com/docs2/TXT/file.doc

google.com/docs2/TXT/file # this is preserved and
.doc is replaced with .pdf and redirected


RedirectMatch /docs/(.*)\.doc /PDF/$1.pdf
anyfile terminating with .doc extension is redirected with same scheme
and same server









SED editor sed

Remove multiple spaces
= = = = = = =
 Remove leading spaces and number from history cmmand output

history | sed 's/^ *[0-9][0-9]* *//'

 
root@vm2:~# cat hello 
#ab 12
cd      99
   zz    te
#ef
    test
      #tellso


root@vm2:~# cat hello  | sed 's/^\s\+//g'

#ab 12
cd      99
zz    te
#ef
test
#tellso

Combinig sed expression
root@vm2:~# cat hello  | sed 's/^\s\+//g;s/\s\+/ /g'
#ab 12
cd 99
zz te
#ef
test
#tellso


sed 'p' passwd  #prints file content but double content
sed -n '1p' file.txt  #print 1st line
sed -n  '2p' file.txt  #print 2nd line
sed -n 4,13p file.txt #print 4 to 14 line
sed -n '$p'  file.txt  #print last
sed -n '1!p' file.txt  #print all except line 1
sed -n '1,3!p' file.txt #print all except line 1 to 3

AWK

will print all but very first column:

awk '{$1=""; print $0}' somefile

will print all but two first columns:

awk '{$1=$2=""; print $0}' somefile

history | awk '{$1=$1;print}' | cut -d' ' -f2-       #remove beginning spaces and history number , cut -f2- will start printing from 2nd field to last
history | awk '{$1=$1;print}' | cut -d' ' -f1-4     # cut -f1-4 will print from field 1 to 4

SED editor sed

cat test | sed 's#first#second#Ig'     ## use `I` for case insensitive

Remove multiple spaces
= = = = = = =
root@vm2:~# cat hello
#ab 12
cd      99
   zz    te
#ef
    test
      #tellso


root@vm2:~# cat hello  | sed 's/^\s\+//g'
#ab 12
cd      99
zz    te
#ef
test
#tellso

Combinig sed expression
root@vm2:~# cat hello  | sed 's/^\s\+//g;s/\s\+/ /g'
#ab 12
cd 99
zz te
#ef
test
#tellso


sed 'p' passwd  #prints file content but double content
sed -n '1p' file.txt  #print 1st line
sed -n  '2p' file.txt  #print 2nd line
sed -n 4,13p file.txt #print 4 to 14 line
sed -n '$p'  file.txt  #print last
sed -n '1!p' file.txt  #print all except line 1
sed -n '1,3!p' file.txt #print all except line 1 to 3
=======================using regular expression=======================
we use '-e' option when we use expression

sed -n -e '/2011/p' file.txt     # print line containing 2011
sed -n -e '/^root/p' passwd      # print lines starting with word 'root'
sed -n -e '/root$/p' passwd      # print lines Ending with word 'root'
sed -n -e '/^harke101$/p' passwd
sed -n -e '/^harke101.*$/p' passwd     # print lines Starting and Ending with word 'root'
sed -n -e '/[0-9]/p' firewall.txt     # print lines containing number 0-9
sed -n -e '/^[0-9][0-9][0-9]$/p'  firewall.txt #print beginning and ending with 3 char number
sed -n -e '/[0-9]\{3\}/p' firewall.txt # print beginning and ending with 3 char number
sed -n -e '/^[0-9]\{3\}$/p' firewall.txt # print beginning and ending with 3 char number




3.3 Overview of Regular Expression Syntax

To know how to use sed, people should understand regular expressions (regexp for short). A regular expression is a pattern that is matched against a subject string from left to right. Most characters are ordinary: they stand for themselves in a pattern, and match the corresponding characters in the subject. As a trivial example, the pattern
     The quick brown fox
matches a portion of a subject string that is identical to itself. The power of regular expressions comes from the ability to include alternatives and repetitions in the pattern. These are encoded in the pattern by the use of special characters, which do not stand for themselves but instead are interpreted in some special way. Here is a brief description of regular expression syntax as used in sed.
char
A single ordinary character matches itself.
*
Matches a sequence of zero or more instances of matches for the preceding regular expression, which must be an ordinary character, a special character preceded by \, a ., a grouped regexp (see below), or a bracket expression. As a GNU extension, a postfixed regular expression can also be followed by *; for example, a** is equivalent to a*. POSIX 1003.1-2001 says that * stands for itself when it appears at the start of a regular expression or subexpression, but many nonGNU implementations do not support this and portable scripts should instead use \* in these contexts.
\+
As *, but matches one or more. It is a GNU extension.
\?
As *, but only matches zero or one. It is a GNU extension.
\{i\}
As *, but matches exactly i sequences (i is a decimal integer; for portability, keep it between 0 and 255 inclusive).
\{i,j\}
Matches between i and j, inclusive, sequences.
\{i,\}
Matches more than or equal to i sequences.
\(regexp\)
Groups the inner regexp as a whole, this is used to:
  • Apply postfix operators, like \(abcd\)*: this will search for zero or more whole sequences of ‘abcd’, while abcd* would search for ‘abc’ followed by zero or more occurrences of ‘d’. Note that support for \(abcd\)* is required by POSIX 1003.1-2001, but many non-GNU implementations do not support it and hence it is not universally portable.
  • Use back references (see below).
.
Matches any character, including newline.
^
Matches the null string at beginning of the pattern space, i.e. what appears after the circumflex must appear at the beginning of the pattern space. In most scripts, pattern space is initialized to the content of each line (see How sed works). So, it is a useful simplification to think of ^#include as matching only lines where ‘#include’ is the first thing on line—if there are spaces before, for example, the match fails. This simplification is valid as long as the original content of pattern space is not modified, for example with an s command.
^ acts as a special character only at the beginning of the regular expression or subexpression (that is, after \( or \|). Portable scripts should avoid ^ at the beginning of a subexpression, though, as POSIX allows implementations that treat ^ as an ordinary character in that context.
$
It is the same as ^, but refers to end of pattern space. $ also acts as a special character only at the end of the regular expression or subexpression (that is, before \) or \|), and its use at the end of a subexpression is not portable.
[list]
[^list]
Matches any single character in list: for example, [aeiou] matches all vowels. A list may include sequences like char1-char2, which matches any character between (inclusive) char1 and char2. A leading ^ reverses the meaning of list, so that it matches any single character not in list. To include ] in the list, make it the first character (after the ^ if needed), to include - in the list, make it the first or last; to include ^ put it after the first character.
The characters $, *, ., [, and \ are normally not special within list. For example, [\*] matches either ‘\’ or ‘*’, because the \ is not special here. However, strings like [.ch.], [=a=], and [:space:] are special within list and represent collating symbols, equivalence classes, and character classes, respectively, and [ is therefore special within list when it is followed by ., =, or :. Also, when not in POSIXLY_CORRECT mode, special escapes like \n and \t are recognized within list. See Escapes.
regexp1\|regexp2
Matches either regexp1 or regexp2. Use parentheses to use complex alternative regular expressions. The matching process tries each alternative in turn, from left to right, and the first one that succeeds is used. It is a GNU extension.
regexp1regexp2
Matches the concatenation of regexp1 and regexp2. Concatenation binds more tightly than \|, ^, and $, but less tightly than the other regular expression operators.
\digit
Matches the digit-th \(...\) parenthesized subexpression in the regular expression. This is called a back reference. Subexpressions are implicity numbered by counting occurrences of \( left-to-right.
\n
Matches the newline character.
\char
Matches char, where char is one of $, *, ., [, \, or ^. Note that the only C-like backslash sequences that you can portably assume to be interpreted are \n and \\; in particular \t is not portable, and matches a ‘t’ under most implementations of sed, rather than a tab character.
Note that the regular expression matcher is greedy, i.e., matches are attempted from left to right and, if two or more matches are possible starting at the same character, it selects the longest.
Examples:
‘abcdef’
Matches ‘abcdef’.
‘a*b’
Matches zero or more ‘a’s followed by a single ‘b’. For example, ‘b’ or ‘aaaaab’.
‘a\?b’
Matches ‘b’ or ‘ab’.
‘a\+b\+’
Matches one or more ‘a’s followed by one or more ‘b’s: ‘ab’ is the shortest possible match, but other examples are ‘aaaab’ or ‘abbbbb’ or ‘aaaaaabbbbbbb’.
‘.*’
‘.\+’
These two both match all the characters in a string; however, the first matches every string (including the empty string), while the second matches only strings containing at least one character.
‘^main.*(.*)’
This matches a string starting with ‘main’, followed by an opening and closing parenthesis. The ‘n’, ‘(’ and ‘)’ need not be adjacent.
‘^#’
This matches a string beginning with ‘#’.
‘\\$’
This matches a string ending with a single backslash. The regexp contains two backslashes for escaping.
‘\$’
Instead, this matches a string consisting of a single dollar sign, because it is escaped.
‘[a-zA-Z0-9]’
In the C locale, this matches any ASCII letters or digits.
‘[^ tab]\+’
(Here tab stands for a single tab character.) This matches a string of one or more characters, none of which is a space or a tab. Usually this means a word.
‘^\(.*\)\n\1$’
This matches a string consisting of two equal substrings separated by a newline.
‘.\{9\}A$’
This matches nine characters followed by an ‘A’.
‘^.\{15\}A’
This matches the start of a string that contains 16 characters, the last of which is an ‘A’.

generate entropy to help speed up key generation

apt-get install rng-tools

vim /etc/default/rng-tools
HRNGDEVICE=/dev/urandom

/etc/init.d/rng-tools start
 /etc/init.d/rng-tools stop

fstab file insights

There's a file called /etc/fstab in your Linux system. Learn what its contents mean and how it's used in conjunction with the mount command. When you learn to understand the fstab file, you'll be able to edit its contents yourself, too.
In this tuXfile I assume you already know how to mount file systems and partitions with the mount command. If you don't, I suggest reading theMounting tuXfile before reading this one.

What is fstab and why it's useful

fstab is a configuration file that contains information of all the partitions and storage devices in your computer. The file is located under /etc, so the full path to this file is /etc/fstab.
/etc/fstab contains information of where your partitions and storage devices should be mounted and how. If you can't access your Windows partition from Linux, aren't able to mount your CD or write to your floppy as a normal user, or have problems with your CD-RW, you probably have a misconfigured /etc/fstab file. So, you can usually fix your mounting problems by editing your fstab file.
/etc/fstab is just a plain text file, so you can open and edit it with any text editor you're familiar with. However, note that you must have the root privileges before editing fstab. So, in order to edit the file, you must either log in as root or use the su command to become root.

Overview of the file

Of course everybody has a bit different /etc/fstab file because the partitions, devices and their properties are different on different systems. But the basic structure of fstab is always the same. Here's an example of the contents of /etc/fstab:
/dev/hda2   /              ext2 defaults             1 1
/dev/hdb1   /home          ext2 defaults             1 2
/dev/cdrom  /media/cdrom   auto ro,noauto,user,exec  0 0
/dev/fd0    /media/floppy  auto rw,noauto,user,sync  0 0
proc        /proc          proc defaults             0 0
/dev/hda1   swap           swap pri=42               0 0
What does all this gibberish mean? As you see, every line (or row) contains the information of one device or partition. The first column contains the device name, the second one its mount point, third its file system type, fourth the mount options, fifth (a number) dump options, and sixth (another number) file system check options. Let's take a closer look at this stuff.

1st and 2nd columns: Device and default mount point

The first and second columns should be pretty straightforward. They tell themount command exactly the same things that you tell mount when you mount stuff manually: what is the device or partition, and what is the mount point. The mount point specified for a device in /etc/fstab is its default mount point. That is the directory where the device will be mounted if you don't specify any other mount point when mounting the device.
Like you already learned from the Mounting tuXfile, most Linux distros create special directories for mount points. Most distros create them under/mnt, but some (at least SuSE) under /media. As you probably noticed when looking at the example fstab, I use SuSE's mount points as an example.
What does all this mean? If I type the following command:
$ mount /dev/fd0
my floppy will be mounted in /media/floppy, because that's the default mount point specified in /etc/fstab. If there is no entry for /dev/fd0 in my fstab when I issue the command above, mount gets very confused because it doesn't know where to mount the floppy.
You can freely change the default mount points listed in /etc/fstab if you're not satisfied with the defaults your distro has given you. Just make sure the mount point is a directory that already exists on your system. If it doesn't, simply create it.
Some partitions and devices are also automatically mounted when your Linux system boots up. For example, have a look at the example fstababove. There are lines that look like this:
/dev/hda2 / ext2 defaults 1 1
/dev/hdb1 /home ext2 defaults 1 2
As you've learned, these lines mean that /dev/hda2 will be mounted to / and /dev/hdb1 to /home. This is done automatically when your Linux system boots up... if it wouldn't, you'd have a hard time using your cool Linux system because all the programs you use are in / and you wouldn't be able to run them if / wasn't mounted! But how does the system know where you want to mount /dev/hda2 and /dev/hdb1? By looking at the/etc/fstab file of course.

3rd column: Filesystem type

The third column in /etc/fstab specifies the file system type of the device or partition. Many different file systems are supported but we'll take a look at the most common ones only.
ext2 and ext3 Very likely your Linux partitions are Ext3. Ext2 used to be the standard file system for Linux, but these days, Ext3 and ReiserFS are usually the default file systems for almost every new Linux distro. Ext3 is a newer file system type that differs from Ext2 in that it's journaled, meaning that if you turn the computer off without properly shutting down, you shouldn't lose any data and your system shouldn't spend ages doing file system checks the next time you boot up.
reiserfs Your Linux partitions may very well be formatted as ReiserFS. Like Ext3, ReiserFS is a journaled file system, but it's much more advanced than Ext3. Many Linux distros (including SuSE) have started using ReiserFS as their default file system for Linux partitions.
swap The file system name is self-explanatory. The file system type "swap" is used in your swap partitions.
vfat and ntfs Your Windows partitions are probably either Vfat or NTFS. The 9x series (95, 98, ME) all use Vfat (more widely known as FAT32), and the NT series (NT, 2000, XP) use NTFS. In 2000 and XP you can choose the file system type, so 2000 and XP partitions may be formatted as Vfat, too. If you want to be able to write to your Windows partitions from Linux, I suggest formatting them as Vfat, because Linux's support for writing to NTFS partitions is a bit shabby at this moment.
auto No, this isn't a file system type :-) The option "auto" simply means that the file system type is detected automatically. If you take a look at the example fstab above, you'll see that the floppy and CD-ROM both have "auto" as their file system type. Why? Their file system type may vary. One floppy might be formatted for Windows and the other for Linux's Ext2. That's why it's wise to let the system automatically detect the file system type of media such as floppies and cdroms.

4th column: Mount options

The fourth column in fstab lists all the mount options for the device or partition. This is also the most confusing column in the fstab file, but knowing what some of the most common options mean, saves you from a big headache. Yes, there are many options available, but I'll take a look at the most widely used ones only. For more information, check out the man page of mount.
auto and noauto With the auto option, the device will be mounted automatically (at bootup, just like I told you a bit earlier, or when you issue the mount -a command). auto is the default option. If you don't want the device to be mounted automatically, use the noauto option in /etc/fstab. With noauto, the device can be mounted only explicitly.
user and nouser These are very useful options. The user option allows normal users to mount the device, whereas nouser lets only the root to mount the device. nouser is the default, which is a major cause of headache for new Linux users. If you're not able to mount your cdrom, floppy, Windows partition, or something else as a normal user, add the useroption into /etc/fstab.
exec and noexec exec lets you execute binaries that are on that partition, whereas noexec doesn't let you do that. noexec might be useful for a partition that contains binaries you don't want to execute on your system, or that can't even be executed on your system. This might be the case of a Windows partition.
exec is the default option, which is a good thing. Imagine what would happen if you accidentally used the noexec option with your Linux root partition...
ro Mount the file system read-only.
rw Mount the file system read-write. Again, using this option might cure the headache of many new Linux users who are tearing their hair off because they can't write to their floppies, Windows partitions, or something else.
sync and async How the input and output to the file system should be done. sync means it's done synchronously. If you look at the examplefstab, you'll notice that this is the option used with the floppy. In plain English, this means that when you, for example, copy a file to the floppy, the changes are physically written to the floppy at the same time you issue the copy command.
However, if you have the async option in /etc/fstab, input and output is done asynchronously. Now when you copy a file to the floppy, the changes may be physically written to it long time after issuing the command. This isn't bad, and may sometimes be favorable, but can cause some nasty accidents: if you just remove the floppy without unmounting it first, the copied file may not physically exist on the floppy yet!
async is the default. However, it may be wise to use sync with the floppy, especially if you're used to the way it's done in Windows and have a tendency to remove floppies before unmounting them first.
defaults Uses the default options that are rw, suid, dev, exec, auto, nouser, and async.

5th and 6th columns: Dump and fsck options

Dump and, uh, what options? Well, dump is a backup utility and fsck is a file system check utility. I won't discuss them in great length here (they would both need their own tuXfile), but I'll mention them, because otherwise you'd spend the rest of the day wondering what on God's green Earth do these things mean.
The 5th column in /etc/fstab is the dump option. Dump checks it and uses the number to decide if a file system should be backed up. If it's zero, dump will ignore that file system. If you take a look at the example fstab, you'll notice that the 5th column is zero in most cases.
The 6th column is a fsck option. fsck looks at the number in the 6th column to determine in which order the file systems should be checked. If it's zero, fsck won't check the file system.

Example /etc/fstab entries

As an example, we'll take a look at a couple of fstab entries that have been a source of endless frustration for new Linux users: floppy and CD-ROM (although these days floppies aren't that important anymore).
/dev/fd0 /media/floppy auto rw,noauto,user,sync 0 0
This line means that the floppy is mounted to /media/floppy by default and that its file system type is detected automatically. This is useful because the type of the floppy may wary. Note especially the rw and user options: they must be there if you want to be able to mount and write to the floppy as a normal user. If you have trouble with this, check your fstabfile to see if these options are there. Also note the sync option. It can be async just as well, but it's sync because of reasons discussed a bit earlier.
/dev/cdrom /media/cdrom auto ro,noauto,user,exec 0 0
Note, again, the user option that enables you to mount the CD as a normal user. The CD-ROM has the ro option because it's no use mounting a CD-ROM read-write because you wouldn't be able to write to it anyway. Also note the exec option. It's especially useful if you'd like to be able to execute something from your CD.
Also note that the noauto option is used with the floppy and CD-ROM. This means that they won't be automatically mounted when your Linux system boots up. This is useful for removable media, because sometimes there won't be any floppy or CD-ROM when you boot up your system, so there isn't any reason to try to mount something that doesn't even exist.

glusterfs 3.5


A Distributed File System is a file system that allows multiple clients to concurrently access data across multiple servers or bricks in a trusted storage pool

GlusterFS uses a native FUSE-based client to export the file system, but it can also be configured to use NFS and CIFS to export the storage system to client hosts that cannot use the native client (FUSE).
GlusterFS is a powerful network/cluster filesystem running in user space that uses FUSE to connect 

with the VFS layer in the OS. GlusterFS is a File System itself that uses already tried and tested 

disk file systems like ext3, ext4, xfs, etc. to store the data. It can easily scale up to petabytes 

of storage which is available to user under a single mount point .

FUSE is a loadable kernel module for UNIX-like operating systems. It enables non-privileged users to create their own file systems without editing kernel code. This is achieved by running file system code in user space, while the actual FUSE module provides a bridge to kernel. 

Terms.

brick  - A locally attached filesystem (e.g. xfs on top of LVM) that is part of a volume.For example, if a server named storage1.example.com had a local storage mounted under /mnt/disk1, a brick would be referred to as storage1.example.com:/mnt/disk1.
client - The machine which mounts the volume.
server - The machine which hosts the filesystem in which data will be stored.
volume - A Network available filesystem which can be mounted using native GlusterFS, NFS, CIFS, it is a logical collection of bricks. Most management operations in GlusterFS happen on the volume level.

etc.


apt-get install xfsprogs
apt-get install software-properties-common
sudo add-apt-repository ppa:gluster/glusterfs-3.5
apt-get update
sudo apt-get install glusterfs-server


<if vmware used and additional harddisk is used , to detect new disk added without restart run 
below command>
#ls /sys/class/scsi_host/ | while read host ; do echo "- - -" > /sys/class/scsi_host/$host/scan ; done


fdisk /dev/sdb
...make new partition as lvm

pvcreate /dev/sdb1

vgcreate vg10 /dev/sdb1

lvcreate -L 1G vg10 -n lvmhome
OR
lvcreate -l 100%FREE -n lvmhome testvg
mkfs.xfs -i size=512 /dev/mapper/vg10-lvmhome 

#Mount the new lvm to /public directory on both servers
mkdir -p /public/sdb1
mount -t xfs  /dev/mapper/vg10-lvmhome /public/sdb1
echo "/dev/mapper/vg10-lvmhome /public/sdb1 xfs defaults 0 0" >> /etc/fstab 

#gluster peer status
Number of Peers: 0

Creating a trusted storage pool.
A trusted storage pool consists of the storage servers that will comprise the volume, in other 
words it is a trusted network of storage servers. When you start the first server, the storage pool 
consists of that server alone. To add additional storage servers to the storage pool, you can use 
the probe command from a storage server that is already trusted. The GlusterFS service must be 
running on all storage servers that you want to add to the storage pool.

Example 
( To create a trusted storage pool of four servers, add three servers to the storage pool from 

server gnode1 )

1. Probe the servers you want to add to the storage pool  on only one primary server eg here gluster1

root@gluster1:~# gluster peer probe gluster2
peer probe: success. 

Note: Do not self-probe local host - gluster1.

@gluster1 server
root@gluster1:~# gluster peer status
Number of Peers: 1

Hostname: gluster2
Uuid: 925b360f-a85d-44b8-87d1-94a0c4270e17
State: Peer in Cluster (Connected)

@gluster2 server
root@gluster2:~# gluster peer status
Number of Peers: 1

Hostname: 192.168.163.139
Uuid: 4f5f5a70-be91-4754-889b-ca0e708c0be3
State: Peer in Cluster (Connected)

Now that we have a trusted storage pool consisting of 4 servers lets create the Volumes that we can 
actually use to store files later on.
 Run below command in only one primary server

@gluster1#gluster volume create gvola replica 2 gluster1:/public/sdb1/brick/ gluster2:/public/sdb1/brick/

another example 
cat /etc/fstab   "on all nodes"
 /dev/sdb1  /export/disk1  xfs defaults 0 0
run `mkdir  /export/disk1/brick` on all nodes

# gluster volume create GWEB replica 3 mx1:/export/disk1/brick/  mx2:/export/disk1/brick/  mx3:/export/disk1/brick/

@gluster1# gluster volume start gvola
volume start: gvola: success
To confirm , make sure you see volume started.
#gluster volume info
 Volume Name: gvola
Type: Replicate
Volume ID: c29b0f57-c018-4d4e-9bdc-2dda6f122dfc
Status: Started
OR run #gluster volume status


Note: If the volume is not started, clues as to what went wrong will be in log files under /var/log/glusterfs on one or both of the servers - usually in etc-glusterfs-glusterd.vol.log

Allowing client to mount

#gluster volume set gvola auth.allow 192.168.163.141

At client side
modprobe fuse
to make sure fuse is loaded into kernel
dmesg | grep fuse

apt-get install glusterfs-client   <make sure version of client and server match>

Finally mounting the filesystem:-

mount -t glusterfs gluster1:gvola /mnt


Expanding Volume by adding Bricks  

 

 

Removing Brick

gluster volume rebalance GWEB stop   #stop rebalance if runing

gluster volume remove-brick GWEB replica 3 mx1:/export/disk2/brick mx2:/export/disk2/brick mx3:/export/disk2/brick start    #use "force" instead of "start"
























Detect new hard disk added in vm-ware workstation v 10.0 without reboot



ls /sys/class/scsi_host/ | while read host ; do echo "- - -" > /sys/class/scsi_host/$host/scan ; done
fdisk -l

git intro

 git clone https://github.com/miguelgrinberg/flasky.git

#creating branch called "test" and switch to it
git checkout -b test
 
git branch  #to know which branch
* test    <=this is current branch
  master
 
git status
git checkout README.md  #to discard changes

Or you can delete the whole branch:
$ git checkout master   #switch to master
$ git branch -D test


git  add .  #adds all to staging

git commit -a -m "message to forkers or self reference" #commit all
git commit file1 file2  #commit particular files
 
How do you know which commits have not yet been pushed upstream, but are still sitting in branches?  
git status won't tell you, so use this command: 

git log --branches --not --remotes
 
Add existing file to git hub
############################3


git init 

git add . 

git commit -m "Initial commit" 

git remote add origin <project url> 

git push -f origin master