Wednesday, October 15, 2014

Reduce size of ext3/ext4 LVM partition



Reduce size of ext3/ext4 LVM partition in RHEL


Sometimes when we are running out of disk space in our linux box and if partition created on LVM , then we can make some free space in the volume group by reducing the LVM using lvreduce command.   
Scenario : Suppose we want to reduce /home by 2GB which is LVM and formated as ext4.
[root@linux ~]# df -h /home/

Filesystem                                              Size       Used    Avail     Use%      Mounted on

/dev/mapper/vg_linux-LogVo              12G         9.2G   1.9G      84%       /home
 
Step:1 Umount the filesystem
[root@linux ~]#  umount  /home
 
Step:2 check the filesystem for Errors using e2fsck command.
[root@linux ~]# e2fsck  -f  /dev/mapper/vgsrv-home
e2fsck 1.41.12 (17-May-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/vgsrv-home: 12/770640 files (0.0% non-contiguous), 2446686/3084288 blocks
Note: In the above command e2fsck , we use the option '-f' to forcefully check the filesystem , even if the filesystem is clean.
 
Step:3 Shrink the size of /home to desire size.
As shown in the above scenario , size of /home is 12 GB , so by reducing it by 2GB , then the size will become 10GB.
[root@linux ~]# resize2fs /dev/mapper/vgsrv-home 10G
resize2fs 1.41.12 (17-May-2013)
Resizing the filesystem on /dev/mapper/vgsrv-home to 2621440 (4k) blocks.
The filesystem on /dev/mapper/vgsrv-home is now 2621440 blocks long.
 
Step:4 Now reduce the size using lvreduce command.
[root@linux ~]# lvreduce  -L 10G /dev/mapper/vgsrv-home

  WARNING: Reducing active logical volume to 10.00 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce LogVol00? [y/n]: y
  Reducing logical volume LogVol00 to 10.00 GiB
  Logical volume LogVol00 successfully resized
 
Step:5 (Optional) For the safer side , now check the reduced filesystem for errors
[root@linux ~]# e2fsck -f /dev/mapper/vgsrv-home
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/vgsrv-home: 12/648960 files (0.0% non-contiguous), 2438425/2621440 blocks
 
Step:6 Mount the file system and verify the size.
[root@linux ~]# mount /home
[root@linux ~]# df -h /home


Filesystem                                            Size    Used   Avail    Use%        Mounted on


/dev/mapper/vgsrv-home                9.9G    9.2G   208M    98%        /home


Apache Server Interview Questions And Answers



Q:-Briefly explain Apache Web Server?
Answer: Apache Web Server is one of the most secure, powerful and popular open source HTTP Servers. It can be used to host anything from personal web sites to corporate domains.
               
Q: - What is location of log files for Apache server ?
Answer: /var/log/httpd

Q:-What is virtual hosting?
Answer: Virtual hosting is a method for hosting multiple domain names on a server using a single IP address. Virtual hosting allows one server to share its resources, such as memory and processor cycles, in order to use its resources more efficiently.

Q: - What are the types of virtual hosts ?
Answer:
name-based and IP-based.
Name-based virtual host means that multiple names are running on each IP address.
IP-based virtual host means that a different IP address exists for each website served. Most configurations are named-based because it only requires one IP address.

Q: - How to restart Apache web server ?
Answer: service httpd restart
/etc/init.d/httpd  restart

Q: - How to check the version of Apache server ?
Answer: rpm -qa |grep httpd

Q: - What is meaning of "Listen" in httpd.conf file ?
Answer:Port number on which to listen for nonsecure (http) transfers.
Default port number of httpd is 80

Q: - What is DocumentRoot ?
Answer:it is a location of files which are accessible by clients. By default, the Apache HTTP server in RedHat Enterprise Linux is configured to serve files from the /var/www/html/ directory.

Q: - On which port Apache server works ?
Answer: http - port 80
               https - port 443

Q: - Tell me name of main configuration file of Apache server ?
Answer:/etc/httpd/conf/httpd.conf

Q: - What do you mean by a valid ServerName directive?
Answer:The DNS system is used to associate IP addresses with domain names. The value of ServerName is returned when the server generates a URL. If you are using a certain domain name, you must make sure that it is included in your DNS system and will be available to clients visiting your site.

Q: - What is the main difference between <Location> and <Directory> sections?
Answer:Directory sections refer to file system objects; Location sections refer to elements in the address bar of the Web page.

Q:-What is the difference between a restart and a graceful restart of a web server?
Answer:During a normal restart, the server is stopped and then started, causing some requests to be lost. A graceful restart allows Apache children to continue to serve their current requests until they can be replaced with children running the new configuration.
.
Q: - If you have added “loglevel Debug” in httpd.conf file, than what will happen?
 Answer: It will give you more information in the error log in order to debug a problem.

Q: - Can you record the MAC (hardware) address of clients that access your server?
Answer: No

Q: - Can you record all the cookies sent to your server by clients in Web Server logs?
Answer: Yes, add following lines in httpd.conf file.
CustomLog logs/cookies_in.log "%{UNIQUE_ID}e %{Cookie}i" CustomLog logs/cookies2_in.log "%{UNIQUE_ID}e %{Cookie2}i"

Q: - Can we do automatically roll over the Apache logs at specific times without having to shut down and restart the server?
Answer: Yes
Use CustomLog and the rotatelogs programs
Add following line in httpd.conf file. CustomLog "| /path/to/rotatelogs/path/to/logs/access_log.%Y-%m-%d 86400" combined

Q: - What we can do to find out how people are reaching your site?
Answer: Add the following effector to your activity log format. %{Referer}

Q: - If you have only one IP address, but you want to host two web sites on your server. What will you do?
Answer: In this case I will use Name Based Virtual hosting.
ServerName 10.111.203.25
NameVirtualHost *:80
<VirtualHost *:80>
ServerName web1.test.com
DocumentRoot /var/www/html/web1
</VirtualHost>

<VirtualHost *:80>
ServerName web2.test2.com
DocumentRoot /var/www/html/web2
</VirtualHost>

Q: - Can I serve content out of a directory other than the DocumentRootdirectory?
Answer: Yes, by using “Alias” we can do this.

Q: - If you have to more than one URL map to the same directory but you don't have multiple Alias directives. What you will do?
Answer: In this case I will use “AliasMatch” directives.
The AliasMatch directive allows you to use regular expressions to match arbitrary patterns in URLs and map anything matching the pattern to the desired URL.

Q: - How you will put a limit on uploads on your web server?
Answer: This can be achieved by LimitRequestBody directive.
<Directory "/var/www/html/data_uploads">
LimitRequestBody 100000
</Directory>
Here I have put limit of 100000 Bytes.

Q: - I want to stop people using my site by Proxy server. Is it possible?
Answer: <Directory proxy:http://www.test.com/myfiles>
Order Allow,Deny
Deny from all
Satisfy All
</Directory>

Q: - What is mod_evasive module?
Answer: mod_evasive is a third-party module that performs one simple task, and performs it very well. It detects when your site is receiving a Denial of Service (DoS) attack, and it prevents that attack from doing as much damage. mod_evasive detects when a single client is making multiple requests in a short period of time, and denies further requests from that client. The period for which the ban is in place can be very short, because it just gets renewed the next time a request is detected from that same host.

Q: - How t to enable PHP scripts on your server?
Answer: If you have mod_php installed, use AddHandler to map .php and .phtml files to the PHP handler. AddHandler application/x-httpd-php .phtml .php

Q: - Which tool you have used for Apache benchmarking?
Answer: ab (Apache bench)
ab -n 1000 -c 10 http://www.test.com/test.html.

Q: - Can we cache files which are viewed frequently?
Answer: Yes we can do it by using mod_file_cache module.
CacheFile /www/htdocs/index.html.

Q:- How do you check for the httpd.conf consistency and any errors in it?
Answer: httpd –t

Q:- Apache runs as which user? and location of main config file?.
Answer:  Apache runs with the user “nobody” and httpd daemon. Apache main configuration file: /etc/httpd/conf/httpd.conf (CentOS/RHEL/Fedora) and /etc/apache2.conf (Ubuntu/Debian).

Q:- On which port Apache listens http and https both?
Answer : By default Apache runs on http port 80 and https port 443 (for SSL certificate). You can also use netstat command to check ports.

SMTP (Simple Mail Transfer Protocol)



SMTP

SMTP is Simple Mail Transport Protocol. This is the protocol used by the email systems to transfer mail messages from one server to another. 





 

Mail User Agent:

The Mail User Agent (MUA), or mail client, is the application that is used to write, send and read email messages. Anyone who has written and sent a message on any computer has used a Mail User Agent of one type or another. 

   ex: 
       Popular locally installed email clients:  Evolution, Thunderbird, outlook, mutt(text based), lotus notes
  Popular web-based email clients : Gmail, Outlook.com and Yahoo! Mail.

Mail Transfer Agent:

The Mail Transfer Agent (MTA) is the part of the email system that does much of the work of transferring the email messages from one computer to another (either on the same local network or over the internet to a remote system). 


   ex:  For Linux, sendmail, Postfix, Qmail and Exim.   
        For Windows, Exchange server

Mail Delivery Agent:

A mail delivery agent or message delivery agent (MDA) is a computer software component that is responsible for the delivery of e-mail messages to a local recipient's mailbox. Also called an LDA, or local delivery agent.



Postfix as MTA:

                  package: postfix
                  service: postfix
                  port number: 25  (standard smtp port number)
                  main config file: /etc/postfix/main.cf


yum install postfix

The key options in the main.cf file are:

vi main.cf
myhostname = mail.domain.com
mydomain = domain.com
inet_interfaces = all

save and exit
:wq


chkconfig --level 35 postfix on
service postfix restart

Test:    mail    -s     <subject>    <mailaddress>

  To check mail,     su  -  user
                               $mail

Send Test Email

Now test the setup by sending a test email to your own email address, to send email use following command.

mail  user@domain.com
Subject: This is Subject Line
Email content line 1
Email content line 2
Email content line 3
^d

To send email press button CTRL+d (^d). Now check your mail box.

       Note: Default mail location   /var/spool/mail/$USER