Archive for Jr Admin

Setting up User Quotas on Rehat

First there was the machine. And it was good. Then there were users. And disk space beacame scarce. Inevitably when admining a box with lots of users you’re going to run in to disk usage issues. You can tackle this before it becomes a problem by setting up disk space quotas for each user (or for groups but I’ll explain that later)

So the first thing you gotta do is enable quotas on the partition that your users reside on. To do this we edit fstab. In this example we’re going to set up quotas for users in /home. Append usrquotas to the defaults field in your fstab.

Change

/dev/hda5 /home ext3 defaults 1 1

To

/dev/hda5 /home ext3 defaults,usrquota 1 1

Now give it the old :wq!.

Since we’re edited fstab we need to remount the affected directory.

mount -o remount,rw /home

Okay, time for the nitty gritty. You need to set up the reference files quotas will need to run. Run:

quotacheck -C /home

This will create .aquota.user and .aquota.group which you won’t really touch.

So let’s set up a quota for user badmonkey. Run:

edquota badmonkey

You’ll enter vi file that looks like this.

Disk quotas for user badmonkey (uid 500):
Filesystem blocks soft hard inodes soft hard
/dev/hda5 112 0 0 19 0 0

Presently badmonkey is using 112K and has 19 files. You can set up quotas by 1K blocks or by inodes or both. The number under soft is the limit they can hit before recieving a warning. The number under hard is what they can hit before the system stops them from creating any new files.

Let’s say we want a hard limit of 512M and 800 files. We’ll make the soft limit 3/4’s of the hard limit. We’ll edit the file so it looks like this:

Disk quotas for user badmonkey (uid 500):
Filesystem blocks soft hard inodes soft hard
/dev/hda5 112 393216 524288 19 600 800

Do a :wq!. Now all that’s left is to turn quotas on.

quotaon /home.

You are done! badmonkey can no longer be such a badmonkey w/o dealing wiht the consequences. Bear in mind when you add a new user you’ll want to run quotacheck -C /home again (Which will require you to turn quotas off)

You can apply the same thing to groups. Howver you’ll also want to add grpquota to /etc/fstab.

Comments

Setting up ip aliases in freebsd

Often times in a server environment your going to need to setup multiple ip addresses to the same ethernet card, it’s really a simple procedure, and the way that I generally do these things is create a file called /etc/rc.aliases and include the alias line in there:

If the IP is on the same netmask:

/sbin/ifconfig fxp0 alias 192.0.3.9 netmask 255.255.255.255

Otherwise, just specify the network address and netmask as usual:

/sbin/ifconfig fxp0 alias 172.16.0.223 netmask 255.255.255.0

once you’ve added each line, then add a line in the /etc/rc.local file

sh /etc/rc.aliases

This way when you want to edit the aliases on each server you have them all in one location.

Comments (1)

FreeBSD servers and keyboards

One of the minor issues I have with freebsd out of the box is that when I have a server network of a few hundred servers, I can’t just plug in a keyboard when we’re having an issue with the networking.

This is a common issue, the freebsd kernel doesn’t support just plug and play keyboards, however there is an easy fix to this mess.. well, easy if your comfortable recompiling a kernel (which you should be).

# cd /usr/src/sys/i386/conf
# cp GENERIC MYKERNEL

vi MYKERNEL

search for:

device atkbd0 at atkbdc? irq 1 flags 0×1

and replace the line with:

device atkbd0 at atkbdc? irq 1

save it (:wq!)

and then

# /usr/sbin/config MYKERNEL

# cd ../compile/MYKERNEL
(For FreeBSD versions prior to 5.0, use the following form instead: # cd ../../compile/MYKERNEL)

# make depend
# make
# make install
If everything went cleanly..
# shutdown -r now

and it should come back with a kernel that allows you to just plug in a PS2 style keyboard without any issues.

Comments

using tar via ssh — for remote file transfers

Having to move large sums of data between boxes is part of an admins life… and sometimes those machines are across the country, and your moving a bunch of sensitive data, and the bosses want to make sure no one can sniff at it… ok, whatever boss ;)

So here’s what I do, use friendly unix tar, and ssh pipe it to another machine.

Lemme show you some examples:
This shows you how to send files FROM the local machine TO a remote machine.

$ cd directory-with-files
$ tar cf - . | ssh username@remoteserver.com “cd /directory-to-put-files; tar xf -” [ENTER]

Ok, you may be asking me to explain this madness:
Change to a directory with files you want to transfer

tar cf - . - create a tar file, with the name “-”, which means output to screen, in the directory “.” (currently in, or right here)

| ssh username@remoteserver - setup an ssh connection to the remote server
“cd /directory-to-put-files; tar xf -” [ENTER] - once connected, change directorys on the local machine, and then EXTRACT that tar file named “-” or output to the screen.

In this case, the output to the screen will be piped thru ssh to the other computer and boom your set.



Now, in order to reverse the logic and transfer FROM a server TO the local machine:

$ cd directory-to-put-files
$ ssh username@remoteserver.com “cd /directory-to-get-files; tar cf - .” | tar xf - [ENTER]

Try it out :)

Comments (1)

How to find the current working directory of a process…

Ok, this might sound insane, but this is the type of question you get asked sometimes, or the situation where you need to know comes up.

I was once asked what the current working directory was of a process on the server… often times I don’t even think about it, however the script was writing files, and we had no idea where ;)

I tracked it down to a pretty simple method

> ps -awux | grep [process]

root 90 0.0 0.0 1016 228 ?? Is 27Apr05 1:01.81 /usr/sbin/cron

> ls -l /proc/[pid from above, which is 90]/cwd

lrwxrwxrwx 1 root root 0 Nov 4 12:56 /proc/90/cwd -> /var/spool

And it’s current working directory is /var/spool

Neat :)

Comments

man and a new one I just stumbled on….

Ok, I feel stupid, however I never realized that I could search man pages!

For those that don’t know, unix offers a built in “manual” command called “man”… sometimes it’s helpful, sometimes it’s there just for reference. It’s easy

$ man command

in this case man ls

LS(1) FreeBSD General Commands Manual LS(1)

NAME
ls - list directory contents

SYNOPSIS
ls [-ABCFGHLPRTWabcdfghiklmnopqrstuwx1] [file …]

DESCRIPTION
For each operand that names a file of a type other than directory, ls
displays its name as well as any requested, associated information. For
each operand that names a file of type directory, ls displays the names
of files contained within that directory, as well as any requested, asso-
ciated information.[and on and on]


man is a great thing, however sometimes you end up forgetting the command your using, and thats when my new little friend helps out…

$ man -k search-scring[ENTER]

This is awsome, now I can find all the insane instances of locate :) man -k locate

cfree(3) - free up allocated memory
index(3) - locate character in string
locate(1) - find filenames quickly
locate.updatedb(8) - update locate database
memchr(3) - locate byte in byte string
mmap(2) - allocate memory, or map files or devices into memory
pthread_mutex_destroy(3) - free resources allocated for a mutex
rindex(3) - locate character in string
strchr(3) - locate character in string
strpbrk(3) - locate multiple characters in string
strrchr(3) - locate character in string
strstr(3), strcasestr(3), strnstr(3) - locate a substring in a string
usbhid(3), hid_get_report_desc(3), hid_use_report_desc(3), hid_dispose_report_desc(3), hid_start_par
se(3), hid_end_parse(3), hid_get_item(3), hid_report_size(3), hid_locate(3), hid_usage_page(3), hid_
usage_in_page(3), hid_init(3), hid_get_data(3), hid_set_data(3) - USB HID access routines
whereis(1) - locate programs
which(1) - locate a program file in the user’s path

Give it a whirl!

Comments

« Previous entries · Next entries »