Tuesday, February 21, 2012

How To Install The Mumble VoIP Server to Redhat/Centos

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.
By default the Linux OS has a very efficient memory management process that should be freeing any cached memory on the machine that it is being run on. However when it comes to Cached memory the Linux OS may at times decide that the Cached memory is being used and is needed which can lead to memory related issues and ultimately rob your server of any potentially free memory. To combat this you can force the Linux OS to free up and stored Cached memory.

Connect via shell using a program such as Putty
At the shell prompt type crontab -e as this will allow you to edit cron jobs for the root user.
If you are not familiar with vi (linux editor) you press "i" to insert text and once done hit "esc" and type ":wq" to save the file.
Scroll to the bottom of the cron file using the arrows key and enter the following line:
0 * * * * /root/clearcache.sh
Create a file in '/root' called 'clearcache.sh' with the following content:

#!/bin/sh
sync; echo 3 > /proc/sys/vm/drop_caches
Once you have saved this file, the job is complete!



Every hour the cron job will run this command and clear any memory cache that has built up.

An example from a test server before and after running this task.

BEFORE:

AFTER:

Note before the server was using 1.918Gb of RAM with 1.4983Gb in Cache and after running the script the server is now only using 172Mb of RAM and only 38.9Gb in Cache.
The network scripts are located in /etc/sysconfig/network-scripts/. Go into that directory.

cd /etc/sysconfig/network-scripts/

The file we're interested in is ifcfg-eth0, the interface for the Ethernet device. Let's assume we want to bind three additional IP's (192.168.1.111, 192.168.1.112, and 192.168.1.113) to the NIC. We need to create three alias files while ifcfg-eth0 maintains the primary IP address. This is how we'll set up the aliases to bind the IP addresses.

Adapter IP Address Type

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

eth0 192.168.1.110 Primary

eth0:0 192.168.1.111 Alias 1

eth0:1 192.168.1.112 Alias 2

eth0:2 192.168.1.113 Alias 3

The :X (where X is the interface number) is appended to the interface file name to create the alias. For each alias you create you assign a number sequentially. For this example we will create aliases for eth0. Make a copy of ifcfg-eth0 for the three aliases.

cp ifcfg-eth0 ifcfg-eth0:0
cp ifcfg-eth0 ifcfg-eth0:1
cp ifcfg-eth0 ifcfg-eth0:2

Take a look inside ifcfg-eth0 and review the contents.

more ifcfg-eth0

We're interested in only two lines (DEVICE and IPADDR). We'll rename the device in each file to its corresponding interface alias and change the IP's. We'll start with ifcfg-eth0:0. Open ifcfg-eth0:0 in vi and change the two lines so they have the new interface and IP address.

vi ifcfg-eth0:0

DEVICE=eth0:0

IPADDR=192.168.1.111

Save ifcfg-eth0:0 and edit the other two alias files (ifcfg-eth0:1 and ifcfg-eth0:2) so they have the new interfaces and IP addresses set (follow the table from above). Once you save all your changes you can restart the network for the changes to take effect.

service network restart

To verify all the aliases are up and running you can run ifconfig (depending on how many new IP's you set up, you can use ifconfig | more to pause the output).

ifconfig

You can also test the IP's by pinging them from a different machine. If everything is working then there should be a response back.

ping 192.168.1.111
ping 192.168.1.112
ping 192.168.1.113

Apache optimization

compressing javascript and css files with htaccess

Compressing is one of those optimizations for a website which can be easily done and still has tremendous effect. Gzip compressing your files results in less bandwidth being used and a lot less data that needs to travel all the way to the impatient client.

gzip compressing is a piece of cake when you can use htaccess. You can put the code below in your .htaccess file:



SetOutputFilter DEFLATE

< /Files>




SetOutputFilter DEFLATE

< /Files>



This will use an output filter to compress the files. All .js and .css files within the jurisdiction of this .htaccess file will be sent compressed to the client.

compressing HTML within your PHP files


Compressing is one of those optimizations for a website which can be easily done and still has tremendous effect. Gzip compressing your files results in less bandwidth being used and a lot less data that needs to travel all the way to the impatient client.

gzip compressing your PHP files is a piece of cake with Output Buffering (OB). OB buffers everything you output in your scripts, and releases it when you want it to. This neat little trick can come in handy when you want to send headers from within your HTML, since the headers are ordered to be released before the HTML when OB is used.

OB can gzip compress the HTML buffered, so you can put this above everything in your PHP file:

if (substr_count($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip"))

ob_start("ob_gzhandler");

else

ob_start();


It checks whether gzip is supported, and then starts output buffering with gzip compression. To release all compressed output you can put this at the bottom of the PHP file:

ob_end_flush();


This flushes all output to the browser.
Monday, February 20, 2012

Finding the largest files and / or directories on a Linux system

Errors about disks being full is always a pain. With normal use of the system, you never know what takes up the most space, which you must if you want to clean up your system efficiently.

Unfortunately there's no command to locate your largest files or directories on a Linux system. Though piping a few commands can easily help you get the list of files and directories you want.

- du : Checking size on files or directories
- sort : Sorting lines of given data
- head : Limit output to the first part of the original output

So this is what you can enter if you want to know the top 10 of the largest files and / or directories on your Linux system. Du checks size (-a for all files and dirs), sort sorts the data it receives from du (-n for numeric sorting, -r for reversing the sort), and throws it at head, which takes the top 10 and shows it.

du -a /var | sort -n -r | head -n 10
Deleting old files in Linux is often necessary. Often logs need to be periodically removed for example. Accomplishing this through bash scripts is a nuisance. Luckily there is the Find utility, it allows a few very interesting arguments, one of them is executing a command when a file is found. This argument can be used to call rm, thus, enabling you to remove what you find. Another argument Find allows can specify a time in which should be searched. This way you can delete files older than 10 days, or older than 30 minutes. A combination of these arguments can be used to do what we want.

First off, we need to find files older than, for example, 10 days.

find /var/log -mtime +10


You can also find files older than, say, 30 minutes:

find /tmp -mmin +30


Another argument Find accepts is executing commands when it finds something. You can remove files older than x days like this:

find /path/* -mtime +5 -exec rm {} \;



The " {} " represents the file found by Find, so you can feed it to rm. The " \; " ends the command that needs to be executed, which you need to unless you want errors like:

find: missing argument to `-exec`


Like i said, {} represents the file. You can do anything with a syntax like this. You can also move files around with Find:

find ~/projects/* -mtime +14 -exec mv {} ~/old_projects/ \;



Which effectively moves the files in ~/projects to ~/old_projects when their older than 14 days.