Friday, November 6, 2009

Linux Servers configuration: (Web Server)

A computer that delivers (serves up) Web pages. Every Web server has an IP address and possibly a domain name.

For example, if you enter the URL http://www.redhat.com/index.html in your browser, this sends a request to the server whose domain name is redhat.com. The server then fetches the page named index.html and sends it to your browser.

Any computer can be turned into a Web server by installing server software and connecting the machine to the Internet. There are many Web server software applications, including public domain software from NCSA and Apache, and commercial packages from Microsoft, Netscape and others.

clip_image001

                                   Fig : Layout of a web server

# Web Server Configuration:

NOTE: In my case 192.168.8.X is http server. I have Jack and Jill with password as password for web page access. 192.168.8.Y acting as a client to server 192.168.8.X

Task 1: To host a web site with name station8.example.com

Step 1: Install http package

# yum install http

Step 2: keep required html file with a name index.html in /var/www/html directory

# echo "This is my first web page" > /var/www/html/index.html

Step 3: start the service

# service httpd start (or)

# /etc/init.d/httpd start

Step 4: make the service persistent across reboot.

# chkconfig httpd on

Task 2: To do name based virtual hosting (to host 2 sites stationX.example.com and wwwX.example.com)

Step 1: Append this data into main configuration file.

cat >> /etc/httpd/conf/httpd.conf

NameVirtualHost 192.168.8.X

<VirtualHost 192.168.8.X>

ServerName stationX.example.com

DocumentRoot /var/www/html

</VirtualHost>

<VirtualHost 192.168.8.X>

ServerName wwwX.example.com

DocumentRoot /var/www/virtual

</VirtualHost>

NOTE: stationX.example.com and wwwX.example.com should resolve to 192.168.8.X

# mkdir /var/www/virtual

# echo "testing name based virtual hosting" > /var/www/virtual/index.html

NOTE: /var/www/html and /var/www/virtual directories must present with related index.html!!!!

Step 2: reload service

# service httpd reload

Step 3: check it

# elinks -dump http://stationX.example.com

# elinks -dump http://wwwX.example.com

Task 3: To host a CGI script.

Step 1: modify configuration file.

Now the configuration file has the below content:

<VirtualHost 192.168.8.X>

ServerName wwwX.example.com

DocumentRoot /var/www/virtual

</VirtualHost>

Modify it and now it should look like as below:

<VirtualHost 192.168.8.X>

ServerName wwwX.example.com

DocumentRoot /var/www/virtual

ScriptAlias /cgi-bin/ /var/www/virtual/wwwX.example.com/cgi-bin/

</VirtualHost>

Step 2: create the directory and keep the required cgi script and make it executable

# mkdir -p /var/www/virtual/wwwX.example.com/cgi-bin

# cd /var/www/virtual/wwwX.example.com/cgi-bin

# wget ftp://192.168.8.254/pub/gls/test.sh

# chmod 755 /var/www/virtual/wwwX.example.com/cgi-bin/test.sh

Step 3: reload service

# service httpd reload

Step 4: check it

# elinks -dump http://wwwX.example.com/cgi-bin/test.sh

It should show u by executing test.sh!!!

In case of any problem or queries or suggestions feel free to leave a comment here.. :)

Wednesday, November 4, 2009

Linux Servers configuration: (FTP Server)

Today I’m going to tell you the basic configuration steps of some of the servers used in Linux like FTP, HTTP and SQUID. These configurations are important in the prospective of your RHCE exam also. Hope these Posts will be informative and help you to crack your RHCE exam.

FTP (File Transfer Protocol) Configuration:

The objectives of FTP are:

1) To promote sharing of files (computer programs and/or data),

2) To encourage indirect or implicit (via programs) use of remote computers,

3) To shield a user from variations in file storage systems among hosts, and

4) To transfer data reliably and efficiently.

FTP, though usable directly by a user at a terminal, is designed mainly for use by programs.

clip_image001

                                   Figure showing FTP Schema

clip_image002

       Figure showing the transfer of files from a FTP Server to a FTP Client.

 

# VSFTPD Configuration.

NOTE : In my case 192.168.8.1 is ftp server i have Jack and Jill with password as password in server. 192.168.8.2 and 192.168.8.3 is acting as ftp client to ftp server 192.168.8.1.

Task 1: To Allow ftp user to download files

IN 192.168.8.1:

--------------

Step 1: install vsftpd package

# yum install vsftpd

Step 2: keep the required files in /var/ftp

# touch /var/ftp/f{1..5}

Step 3: start vsftpd service.

# service vsftpd restart

Step 4: make the service persistent across the reboot.

# chkconfig vsftpd on

IN 192.168.8.2:

--------------

Step 1: check whether ftp user is allowed to download files or not.

# ftp 192.168.8.1

ftp> get f1

ftp> bye

Task 2: To Allow ftp user to upload files

IN 192.168.8.1:

---------------

Step 1: create a directory may be /var/ftp/upload which is writeable by ftp user.

# mkdir /var/ftp/upload

# chgrp ftp /var/ftp/upload

# chmod g+w /var/ftp/upload

Step 2: Allow anonymous user to upload the files in configuration file.

line 27 looks like:

#anon_upload_enable=YES

it should be uncommented and now it should look like:

anon_upload_enable=YES

Step 3: restart vsftpd service.

# service vsftpd restart

Step 4: make changes in SELinux policy to allow anonymous user to upload files

# setsebool -P allow_ftpd_anon_write=1

Step 5: change context of directory to allow anonymous user to upload files

# chcon -t public_content_rw_t /var/ftp/upload

IN 192.168.8.2:

--------------

Step 1: create the file which you want to upload.

# touch /root/client1

Step 2: check whether ftp user is allowed to upload files or not.

# ftp 192.168.8.1

ftp> cd upload

ftp> put /root/client1

ftp> by

Task 3: To Allow normal user Jack with password as password to download and upload files.

IN 192.168.8.1:

----------------

Step 1: Create user Jack with password as password

# useradd Jack

# echo "password" | passwd --stdin Jack

( NOTE: Use the above mentioned technique to assign password for the user instead of the traditional method "passwd <username>", coz here there is no need to type the password 2 times so it saves some time in RHCE exam and you can also know what password you are providing so it reduces the probability of assigning a wrong password to the user).

Step 2: keep some files in Jack user’s home directory.

# touch /home/Jack/b{1..5}

Step 3: change SElinux policy so that normal users can get access to their home directories.

# setsebool -P ftp_home_dir=1

IN 192.168.8.2:

--------------

Step 1: create the file which you want to upload.

# touch /root/client2

Step 2: check whether Jack user is allowed to upload files or not.

# ftp 192.168.8.1 -u Jack

Password:

ftp> get b1

ftp> put /root/client2

ftp> bye

In case of any problem or queries or suggestions feel free to leave a comment here..:)

Sunday, November 1, 2009

How to set services to start & stop automatically.

Red Hat and Red Hat based Linux distributions make use of the script called chkconfig to enable and disable the system services running in Linux.

For example, to enable the apache webserver to start in certain run levels, you use the chkconfig script to enable it in the desired run levels as follows:

# chkconfig httpd --add
# chkconfig httpd on --level 2,3,5

This will enable the apache webserver to automatically start in the run levels 2, 3 and 5. You can check this by running the command:

# chkconfig --list httpd

One can also disable the service by using the off flag as shown below:

# chkconfig httpd off
# chkconfig httpd --del

Red Hat also has a useful script called service which can be used to start or stop any service. Taking the previous example, to start apache webserver, you execute the command:

# service httpd start

and to stop the service…

# service httpd stop

The options being start, stop and restart which are self explanatory.

 
Things You Should Know About Linux !!!