Tuesday, February 21, 2012

Mounting NFS Shares

Network File System shares, or NFS exports, are easily mounted to Linux servers. Before an NFS export can be mounted, the nfs-utils package must be installed.

yum install nfs-utils

Additionally, the 'portmap' service must be running and enabled.

service portmap start
chkconfig portmap on

To mount the share, you'll need the following information.

The hostname, domain name, or IP of the NFS server.
The full path of the export on the server.

Also, be sure that the NFS server allows access from the host for the desired export.


Manually Mounting

Mounting NFS shares to the client is done using the mount command, in a similar fashion to mounting local file systems.

mount -t nfs4 -o options host:/remote/path/ /local/mount/point

For example: To mount an export '/var/data' on host '10.10.1.10' to the local directory '/remote/data', the following command would be used.

mount -t nfs4 10.10.1.10:/var/data /remote/data

The '-t nfs4' can usually be dropped completely. You'll now be able to access the remote directory under '/remote/data' as though it were part of the local filesystem.

For information on the various mount options, which can improve transfer performance and permissions, refer to the nfs man page.

man nfs
Mount via fstab

NFS mounts can also be specified within the /etc/fstab file for ease of mounting, and mounting on system startup. The format is the same as with local mounts.

host:/remote/path /local/mount/point nfs4 defaults 0 0

For the previously used example export, this would be:

10.10.1.10:/var/data /remote/data nfs4 defaults 0 0
Nginx is a lightweight, fast, and efficient web and proxy server. It is one of the fastest static conent web servers available, and can also be deployed to delivery dynamic content through a FastCGI interface. In addition, nginx is a very powerful reverse proxy (frontend) server and very capable software load balancer.

For a full listing of features, please refer to http://nginx.org.
Installation

Installation of the latest stable release of nginx can be done easily with the EPEL (Extra Packages for Enterprise Linux) package repository. To use this repository, execute the following as the root user:

rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm

Once the EPEL repository is in use, nginx can be easily installed through yum.

yum install nginx
Configuration

Nginx uses the configuration file /etc/nginx/nginx.conf, which can be edited using nano. Virtual hosts (web sites) are configured in this file with 'server' code blocks, which are located under the main 'http' block. The default 'server' block will listen on port 80, and has a document (web root) of '/usr/share/nginx/html'.

To help explain configuration of the server block, below is a very basic entry.

server {
listen 80;
server_name www.domain.com domain.com;

location / {
root /var/www/domain.com/html;
index index.html index.htm;
}

}

listen: Specifies the port on which this virtual host listens.
server: Lists the host headers for the site.
location /: Specifies how to handle requests under the location '/', the site root.
root: The document root for the site.
index: An ordered priority list of default documents.

For further details and examples on nginx's configuration, please refer to their offical wiki page and core documentation.

Note: If your server currently is configured with another web server, you'll likely need to have Nginx listen on a port other than 80. This is done simply by editing the 'listen' setting in the default server block, as well as any additional server blocks that are created.

To test your configuration, execute the following and it will report on any errors.

/usr/sbin/nginx -t
Starting and Testing

Once you've setup a working configuration, you can start the nginx server.

/etc/init.d/nginx start

If using the default document root (/usr/share/nginx/html), visiting your server's IP in a browser should yield the default server page.

nginx_test

Now that Nginx is running successfully, you'll want to be sure it's added to the default run level so it will start automatically at boot time.

chkconfig nginx on
The .htaccess file is pretty handy as it can also allow you to set various PHP flags that you may not want enable for all of you websites and in turn will let you run just about every PHP flag or directive on a one on one website basis.

You will need to log into your Linux server directly using SSH. If you are not familiar on how to do this, we have articles on how to implement this on both Windows and Mac;

Windows - http://www.hosting.com/support/linux/general/sshwindows
Mac - http://www.hosting.com/support/linux/general/sshmac

To create the .Htaccess file, you meerly need to create a text file with any Linux editor. The file must be called .htaccess and it must exist in the root directory of the website you want override the Php global directives for.

The format of the .htaccess is simple, however you will want to comment out exactly what flag or directive you are enabling for the site. An example of this would be as seen below;

#Turn register goabls of
php_value register_globals off

#Php max upload size
php_value upload_max_filesize 12M
php_value post_max_size 12M

#Enable another version of php if you have two installed (Enable Php 5)
AddType application/x-httpd-php5 .htm .html .php

Make sure you save the file when you are done editing it.

Just about any directive or flag can be added to the .htaccess file so you can commently customize the php functions of the website instead of changing it globally in the php.ini file. For a list of what you can use, please review the PHP manual at http://php.net/manual/en/index.php.
Using a .htaccess file will grant you greater control over your website, such as safe guarding it from hacking attempts or even keeping out spammers who may frequent your website. A great feature of using a .htaccess file is the ability to populate it with single IP addresses or entire IP ranges, effectively blocking those IP's from being able to access your server. This article will explain how to implement this via the .htaccess file.

You will need to log into your Linux server directly using SSH. If you are not familiar on how to do this, we have articles on how to implement this on both Windows and Mac.

To create the .htaccess file, you need to create a text file with any Linux editor. The file must be called .htaccess and it must exist in the root directory of the website you want to deny access to.

In the file, there is a specify format you must adhere to. To block both single IP's and IP ranges, you must include the following;

order allow,deny - The rule set
deny from 192.168.1 - IP you want to block
deny from 24.0.0.0/23 - IP Range you want to block

Please note to block an IP Range, you must know the subnet.

You can also specify a deny all and allow rule set as well;

order deny,allow - The rule set
deny from all - Deny access from all IP's.
Allow from 192.12.4.1 - IP you want to allow.

An example of a file blocking IP address 1.2.3.4 and a subnet 2.0.x.x is below:


order allow,deny
allow from all
deny from 1.2.3.4
deny from 2.0.

Monitoring Bandwidth with VNstat

VNstat is a bandwidth monitoring tool that will let you monitor your bandwidth and provide daily, weekly and monthly tracking metrics.

To install and setup Vnstat, you will need to follow the steps in this article.

Log into your linux server and type the following command.wget http://humdi.net/vnstat/vnstat-1.10.tar.gz

Next to uncompress the file you will need to run the following command. tar -zxvf vnstat-1.10.tar.gz

Now that you have the file uncompressed, you will need to install Vnstat. To do this, you will need to navigate to the VNstat directory and run the following command.
make & make install

Now that it has been installed, you will first need to run "vnstat --iflist" on your server, so you know the name of your network adaptors. vnstat --iflist

You will now be presented with the any available adaptors on your server. Available interfaces lo eth0 sit0

Now that you know what adaptors you have on your server, you will need to tell VNstat to create a small database for that adapator. To do this, simply type /usr/bin/vnstat -u -i then the adaptor name. So for our example, we would run the following /usr/bin/vnstat -u -i eth0 If you have multiple adaptors, you will need to do this for each adaptor. However you do not have to if you only want to monitor specific adaptors.

Next, make sure that Vnstat restarts whenever you reboot your server. To do this, add the service to your server's "Chkconfig" list by running the following command.

chkconfig --add vnstat
chkconfig vnstat on

Now you can access Vnstat by logging into the server at anytime and typing "vnstat". Doing so will give you a realtime status of your bandwidth.
Mumble is an opensource, low-latency, high quality VoIP voice chat software that is primarily intended for gaming. It's a free and worthy (often consider superior) alternative to more widely used software such as Teamspeak or Ventrilo.

Mumble's server component, known as 'murmur', is not provided in rpm format for easy installation to Redhat or CentOS server. The software is also not provide by the default or common third party yum repositories. However, installation can be done using a static binary package that is available.
Download

Before we can extract needed files, the lzma compression tool must be installed. This can easily be done using yum.

yum install lzma

Now, both the static binary package and an RPM from another Linux distribution must be downloaded to the server.

wget http://sourceforge.net/projects/mumble/files/Mumble/1.2.3/murmur-static_x86-1.2.3.tar.bz2/download
wget ftp://rpmfind.net/linux/Mandriva/devel/cooker/x86_64/media/contrib/release/mumble-server-1.2.2-3mdv2011.0.x86_64.rpm

Extract and Install Executable

Next, the murmur executable must be extract from the static binary package and installed into the server's PATH.

tar -xjf murmur-static_x86-1.2.3.tar.bz2
cp murmur-static_x86-1.2.3/murmur.x86 /usr/sbin/murmurd

Extract and Install Service Script and Config

To obtain a init startup script as well as a default config file, the downloaded rpm must be extracted.

rpm2cpio mumble-server-1.2.2-3mdv2011.0.x86_64.rpm > file.lzma
lzma -d file.lzma
mkdir mumble-rpm
cd mumble-rpm
cpio -imv --make-directories < ../file
rm ../file

The extracted files can now be moved into the system.

cp etc/mumble-server.ini /etc
cp etc/rc.d/init.d/mumble-server /etc/rc.d/init.d
chmod a+x /etc/rc.d/init.d/mumble-server

Next, a system user for murmur must be created and assigned to required directories and files.

upadd -g 4000 mumble-server useradd -g 4000 -G mumble-server -s /sbin/nologin -d / -M mumble-server mkdir /var/lib/mumble-server chown mumble-server:mumble-server /var/lib/mumble-server
mkdir /var/log/mumble-server
chown mumble-server:mumble-server
/var/log/mumble-server

Starting Mumble Server

Due to difference between Redhat/CentOS init scripts and the distribution the extracted RPM was built for, we must modify the installed init.d scripts

Execute:
nano /etc/rc.d/init.d/mumble-server

In nano editor, type CTRL+\ to bring up the search and replace tool. Search for the text 'gprintf', and replace with 'printf'. Select 'A' to replace all instances, then CTRL+o to save, and CTRL+x to exit.

The mumble server can now be started.

service mumble-server start

You may now connect your mumble client to your server using your server's IP and the default mumble port.
Run at System Boot

To have mumble server start at system boot, simply add the init script to the run level with ckconfig.

chkconfig --add mumble-server
chkconfig mumble-server on

Upgrade PHP on a Linux Server

Configure the YUM repository to look in the correct location for an upgraded PHP RPM. There are many different repositories online that offer upgraded RPMs for PHP so a quick search via Google will be of assistance. For this article we'll be referencing the YUM repositories at webtatic.com
Tell rpm to accept rpm's signed by webtatic

rpm --import http://repo.webtatic.com/yum/RPM-GPG-KEY-webtatic-andy
Add the yum repository information to yum

wget -P /etc/yum.repos.d/ http://repo.webtatic.com/yum/webtatic.repo

Update the existing installation of PHP which will also update all of the other PHP modules installed

yum --enablerepo=webtatic update php

Type Y and let the process complete.
You can now see your current version of PHP using php –v from the shell prompt.