Category Archives: Redhat

Ramdisk: How do you install and set up Ramdisk under Linux (CentOS, RHEL, Fedora)?

Ramdisk is very good to have if you want something to stay in memory.   Files in memory makes it so you can access them with out having to access hard drive all the time.  Perfect candidates would be things which do not change eg. web images or downloadable files, etc.  If you have Linux Kernel 2.4 or later, you already have support of ramdisk built in.  You can check if ramdisk is setup by doing: 

# dmesg | grep RAMDISK
RAMDISK driver initialized: 16 RAM disks of 16384K size 1024 blocksize

You should get above output on CentOS and RHEL.  Other linux flavors will have similar output as well.  If you would like to see how they are named and what you would need to refer to, do the following:

# ls -l /dev/ram*
lrwxrwxrwx 1 root root 4 Apr 24 12:05 /dev/ram -> ram1
brw-rw---- 1 root disk 1, 0 Apr 24 12:05 /dev/ram0
brw-rw---- 1 root disk 1, 1 Apr 24 12:05 /dev/ram1
brw-rw---- 1 root disk 1, 10 Apr 24 12:05 /dev/ram10
brw-rw---- 1 root disk 1, 11 Apr 24 12:05 /dev/ram11
brw-rw---- 1 root disk 1, 12 Apr 24 12:05 /dev/ram12
brw-rw---- 1 root disk 1, 13 Apr 24 12:05 /dev/ram13
brw-rw---- 1 root disk 1, 14 Apr 24 12:05 /dev/ram14
brw-rw---- 1 root disk 1, 15 Apr 24 12:05 /dev/ram15
brw-rw---- 1 root disk 1, 2 Apr 24 12:05 /dev/ram2
brw-rw---- 1 root disk 1, 3 Apr 24 12:05 /dev/ram3
brw-rw---- 1 root disk 1, 4 Apr 24 12:05 /dev/ram4
brw-rw---- 1 root disk 1, 5 Apr 24 12:05 /dev/ram5
brw-rw---- 1 root disk 1, 6 Apr 24 12:05 /dev/ram6
brw-rw---- 1 root disk 1, 7 Apr 24 12:05 /dev/ram7
brw-rw---- 1 root disk 1, 8 Apr 24 12:05 /dev/ram8
brw-rw---- 1 root disk 1, 9 Apr 24 12:05 /dev/ram9
lrwxrwxrwx 1 root root 4 Apr 24 12:05 /dev/ramdisk -> ram0

All those ramdisks listed have same size.  In above example, they are all 16MB.  Let us change that so we have more space allowed.  Note that I say allowed and not allocated.  We allocate space in one of the later steps by formatting one of the drives above.   Let us set it up so we have 128 MB.  Since this has to be in multiples of 1024, we will setup Ramdisk to have 131072K. 

vi /etc/grub.conf

Find first line which looks similar to following:

kernel /vmlinuz-2.6.9-42.0.10.EL ro root=/dev/VolGroup00/LogVol00

add ramdisk_size=131072 to the end of the line.  Now your line should look like:

kernel /vmlinuz-2.6.9-42.0.10.EL ro root=/dev/VolGroup00/LogVol00 ramdisk_size=131072 Save and exit grub.conf.  At this point you have it configured to have ramdisk with new size but it does not take effect until you reboot your system.  Once you have rebooted your system, we can start doing rest of configurations.

mke2fs -m 0 /dev/ram0

This will format the ram0 ramdrive for us to use. At this point, kernel will allocate space for you.  Let us setup Ramdisk mount point so we can use it.  We will also have it be owned by user “sunny” so that user can read/write to that mount.

mkdir /home/ramdisk
mount /dev/ram0 /home/ramdisk
chown sunny.sunny /home/ramdisk

At this point you should be able to type:  mount and see your new Ramdisk drive mounted on /home/ramdisk

Remember that everything you put on this drive will be gone if you reboot your server.  If you unmounted the Ramdisk drive and remounted it, your files will still be there.  It is because your system has that much ram set aside for your Ramdisk and will not use it for anything else.   If you would like to setup Ramdisk the same next time you boot up, add these lines to your /etc/rc.local files.

mke2fs -m 0 /dev/ram0
mount /dev/ram0 /home/ramdisk
chown sunny.sunny /home/ramdisk

————————————-
DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. Use at your own risk.

Subversion: How do you install and set up Subversion for revision control?

Code revision control is very crucial part of development.  It ensures you know who has changed which files and you are able to rollback to older versions in case new changes are breaking your website page or entire project.  There are few options for you if you are looking into setting up code revision control.  My preferred option is Subversion.  Subversion is an open-source revision control system which is becoming more and more popular every day.  It is very easy to install and setup your project under Subversion.  If you want detailed instructions, please see the Subversion Book.  They do a great job explaining what revision control is, what are the different types of revision control are out there, detailed instructions on installing subversion, doing administrator tasks, etc.  Here are instructions on how to set up Subversion under CentOS.  Same instructions apply to most linux distributions. 

YUM Install 

Easiest way to install subversion is via “yum” by typing:

yum install subversion

Once install is done, confirm it by typing “svn” at the prompt and you should get:

Type 'svn help' for usage.

At this point you can skip to “Setting up Subversion repository” part.

SOURCE Install

Obtain source from:  Subversion.  At the time of writing, latest (1.4.3) version can be obtain from this link:  http://subversion.tigris.org/downloads/subversion-1.4.3.tar.gz

tar zxf subversion*
cd subversion*
./configure
make && make install

after everything goes well, type svn at the prompt and you should get:

Type 'svn help' for usage.

Setting up Subversion repository

adduser svnusers
mkdir repos/branches -p
mkdir repos/trunk -p
mkdir repos/tags -p
mkdir /svn
svnadmin create /svn/demorepo
svn import --message "Initial set up" repos file:///svn/demorepo
cd /svn/demorepo
chown .svnusers . -R
chmod 775 * -R
chmod +s db

Thats all there is to it to setup Subversion repository.  At this point, you should add any users you want to have access to the repository by adding them to “svnusers” group.

————————————-
DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. Use at your own risk.

Rsync: Using rsync to backup data from one server to another over SSH. Quick rsync tutorial.

Rsync is a great tool which can be used to do many tasks which involved copying/moving data. If privacy/security is of concern, which it always should be, you can use rsync to do all the copying/moving of data over SSH. Read through “man rsync” to get deeper understanding of rsync. Here is my attempt to a short tutorial on rsync. Let us start with most simple example of using rsync over ssh.

rsync -ae ssh server1:/home /home/backups/server1_home_backup/

This command will download all the files/directories from /home on server1 and copies them to /home/backups/server1_home_backup/
-a = archive mode. This will preserve permissions, timestamps, etc.
-e = specify which remote shell to use. In our case, we want to use ssh which follow right after “e”

Let us improve on this and add couple more parameters:

rsync -zave ssh --progress server1:/home /home/backups/server1_home_backup/
-z = adds zip compression.
-v = verbose
–progress = my favorite parameter when I am doing rsync manually, not so good when you have it in cron. This show progress (how_many_files_left/how_many_files_total) and speed along with some other useful data.

Great.. we are moving along pretty good. Let us add some security to make sure things work the way we want to.

rsync --delete-after -zave ssh --progress server1:/home /home/backups/server1_home_backup/

–delete-after = this will delete files on backup server which are missing from source after ALL syncing is done. If you don’t care of having extra files on your backup server and have plenty of disk space to spare, do not use this parameter.

Lastly, one of the VERY handy parameters,

rsync --delete-after -zave ssh --progress server1:/home /home/backups/server1_home_backup/ -n

The -n (or –dry-run) parameter is great to use for testing. It will not transfer or delete any files, rather will report to you what it would have done if it was ran with out -n parameter. This way you can test it with out destroying or transfering data just to find out that is not what you wanted.

For further reading: man rsync

Mcache: Install and configure mcache (msession) to be used for session caching in PHP.

Installing mcache, previously known as msession, on CentOS 32 bit system.

If you are on 64 bit system, you will get errors, lots of them.  I went through and fixed “some” errors by modifying code but it was just taking too much time so I decided not to go 64 bit route.  But below are the efforts I made.  Maybe somebody can help with rest of the steps.   Following instructions work fine with 32 bit systems. For more help look at the MCache Handbook.
Thank you Mohawk Software for all your efforts developing this!

Web site: http://www.mohawksoft.org/?q=node/32
PHP reference:  http://us2.php.net/manual/en/ref.msession.php

yum install ncurses-devel #otherwise you might see errors about no such file curses.h

wget http://www.mohawksoft.org/download/mcache-070415-M2.0b6.tar.gz
wget http://www.mohawksoft.org/download/phoenix-070415-M2.0b6.tar.gz
tar zxf mcache*.gz
tar zxf phoenix*.gz
cd phoenix
ln -s Linux.mak config/config.mak
make dirs
make links
make butils
export PATH=$PATH:/opt/mohawk/bin
make libs
vi sqldrv/Makefile # about line 24, comment out POSTGRES=1 and ODBC=1
cd ../mcac*
make server
vi tools/Makefile # after line which says: CARGS+=-DBINDIR=\"$(BINDIR)\"
                  # add:  CARGS+=-DSBINDIR=\"$(SBINDIR)\"
make utils
ln -s /opt/mohawk/lib/libphoenix.so.2.2.2 /lib/
/opt/mohawk/sbin/mcache &

In your php.ini, add:   
[Session]
; Use mcache as the save handler
session.save_handler = mcache
; Set the host which runs the mcache daemon
session.save_path = localhost

Let us test if mcache server is running:

/opt/mohawk/bin/mping
You should see:
Usage: /opt/mohawk/bin/mping host
Pings a session daemon
Using localhost
localhost:8086 is alive

Great! You mcache server is now up and running and listening for connections.

You can add above command to your start up scripts so server will run next time you reboot.  Easiest way to achieve this is to add that command to end of /etc/rc.local

32 bit installation is now complete! 

———————

I could not get 64 bit install to go but here are my notes for whoever wants to try it.  If you get it working, please come back and comment on how you got it installed.

64 bit install notes:First error:  CPU you selected does not support x86-64 instruction set
to fix this, edit config/unixgcc.mak and remove all instances of -mtune=pentium3

Following are code changes to fix some other errors:

line 83 in phmalloc.h
virtual void *memdup(void *mem, unsigned int cb);
to
virtual void *memdup(void *mem, size_t cb);

line 446 in mexpat.cpp
static void *xmlalloc(void *context, unsigned int cb)
to
static void *xmlalloc(void *context, size_t cb)

static void *xmlrealloc(void *context, void *p, unsigned int cb)
to
static void *xmlrealloc(void *context, void *p, size_t cb)

Samba: How do you install and set up Samba in linux? [Redhat Enterprise(RHEL), CentOS, Fedora]

Setting up Samba “can” be complicated at times. Especially if you are looking for instructions online where there are WAY too many tutorials which go in to details about what configuration does what, etc. Well, this post is nothing like that. Here I just show you quick and easy way to install Samba, configure it, and set up the drive letter on your XP/Vista. NOTE: for using Samba with Vista, please see my previous post in which I talk about changing settings in Vista so you can connect to your Samba share: Windows Vista Installation

NOTE: This set up is very “open” and should not be used on servers which are facing the world. This is for private network where you trust all the computers and its users.

Installing Samba (using yum on CentOS and Fedora): yum install samba
Installing Samba (using rpm):

  1. Obtain Samba rpm from rhn.redhat.com
  2. rpm -ivh samba*.rpm

Configuring Samba:
cd /etc/samba
mv smb.conf smb.conf.backup
vi smb.conf

Paste content below in to your vi:

[global]
workgroup = wrkgrp
netbios name = smbserver
security = SHARE
load printers = No
default service = global
path = /home
available = No
encrypt passwords = yes
[share]
writeable = yes
admin users = smbuser
path = /home/share
force user = root
valid users = smbuser
public = yes
available = yes

save and exit

adduser smbuser #add unix account
passwd smbuser #set unix account password
smbpasswd -a smbuser #lets create same user account on samba
<put same password as your unix account password>
/etc/init.d/smb restart

Now let us setup drive letter on our Windows so we can easily access these files.

Start -> run -> cmd <enter>

At the prompt type: net use z: \\ip_of_your_samba_server\share /user: smbuser password_you_assigned

That is it! At this point you have successfully set up Samba under Linux and are now successfully connected to your share from your Windows machine.