From time to time you might need to interview somebody for a Linux role. It's hard to think of good questions; you don't want to scare somebody with your questions, but you do want to know if the person is knowledgable.
"People that use your Linux server complain it's slow. What tools would you use to check resource usage?"
top, sar, netstat -an, iostat, free, df.
"You discover a disk is full on your Linux server. What do you use to discover where the bigest files/directories are?"
"A system needs more disk space. You want to add a partition /var/log. You add a drive to the machine, it becomes /dev/sdb. What actions do you take to use this disk?"
Depending if you use LVM or not. If you don't use LVM:
If you do use LVM:
"People that use your Linux server complain it's slow. You've seen the disk usage is high. What can you do to improve this?"
"What happens in relation to DNS, SMTP and IMAP when I send send an email to example@example.com?"
My computer is likely to be configure to send the email to a mail server on port 25, SMTP protocol. That mailserver will query the DNS for the MX records of example.com. The mailserver that show up with the lowest priority will be contacted to deliver the email. That mailserver at example.com can accept the email and put in into the imap folder for the user or alias of example@example.com.
"You need to setup 100 Red Hat Enterprise Linux systems. If you don't want to walk around and eject and insert a boot CD 100 times, what options would you have?"
Kickstarting would help out. Install one machine as you like it, save /root/anaconda-ks.cfg to a webserver. Setup a PXE (DHCP, TFTP, HTTP, DNS) environment and use that kickstart file to install the rest.
"You have destroyed /etc/pam.d/system-auth and can't login anymore. Another machine has a propper version of /etc/pam.d/system-auth. How would you fix that broken machine?"
The machine needs to be booted in single user mode so you don't get a login prompt. After that here are some option:
"You have installed apache, php and mysql and a webapplication such as Drupal. The webapplication tries to send emails to an external mailserver but fails. What could be the cause when these items have been verified:
SELinux could be blocking apache from using port 25 on an external system. The logfile /var/log/messages might inform you about it. To fix it issue "setsebool -P httpd_can_network_connect=1".
"What determines the load (w, uptime) of a system?"
The number of processes that are waiting for execution. These processes are in the run queue. Processes could be waiting for io, network or memory allocation.
Hosting Drupal site in the Amazon EC2 cloud is not difficult. Here is a recipe I have used, first attempt was a Fedora 14 EC2 ami, but Fedora 14 comes with php 5.3, which can't be combined with Drupal 5.x. If you only have Drupal 6 (or Drupal 7) sites to host, you can use Fedora 14. If you want to use a "small" instance, please read this bug about readdir64_r. The fix for that bug is easy:
echo "hwcap 1 nosegneg" > /etc/ld.so.conf.d/libc6-xen.confLet's continue with Drupal on CentOS. Rightscale provides perfect CentOS amis that can be used on Amazons EC2 platform. If you install one, these are the steps I took to make it Drupal 5, Drupal 6 and Drupal 7 ready:
# Update the software.
yum -y update
# Set the timezone for this machine.
cp /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime
# This images came with 10Gb of ESB storage, I added another 64 Gb volume, here it's called "/dev/sdc".
# Use LVM to be ready to grow in the future.
pvcreate /dev/sdc
vgcreate vg0 /dev/sdc
lvcreate vg0 -L 32G -n var-www
lvcreate vg0 -L 1G -n var-lib-mysql
lvcreate vg0 -L 2G -n root
# Put filesystems on the logical volumes.
mke2fs -j /dev/vg0/var-www
mke2fs -j /dev/vg0/var-lib-mysql
mke2fs -j /dev/vg0/root
# Add the mountpoints to fstab.
echo "/dev/vg0/var-www /var/www/virtualhosts ext3 defaults 0 0" >> /etc/fstab
echo "/dev/vg0/var-lib-mysql /var/lib/mysql ext3 defaults 0 0" >> /etc/fstab
echo "/dev/vg0/root /root ext3 defaults 0 0" >> /etc/fstab
# Create the mountpoints.
mkdir /var/www /var/lib/mysql /root
# Mount all mounpoints in /etc/fstab.
mount -a
# Install the webserver.
yum -y install httpd
service httpd start
chkconfig httpd on
# Install the database server.
yum -y install mysql-server
service mysqld start
chkconfig mysqld on
/usr/bin/mysqladmin -u root password 'YourPassWord'
# Install PHP and all required Drupal php modules.
yum -y install php php-mysql php-mcrypt php-xml php-mbstring php-gd
# Add a single new file in the ESB root filesystem, that includes configurations from /var/www/conf.d
# Using this trick allows you to easily remount the volume on another host in case of troubles.
echo 'Include /var/www/conf.d/*.conf' >> /etc/httpd/conf.d/virtualhosts.conf
mkdir /var/www/conf.d
# Rightscale CentOS images comes with postfix and sendmail. Postfix is enabled, but sendmail is fine for me.
# First erase postfix.
yum -y erase postfix
# Now reinstall sendmail to fix a few permissions.
yum -y reinstall sendmail
service sendmail start
chkconfig on sendmail
# Reboot the box to make sure it's working properly.
rebootHet is altijd bewonderings waardig om te zien hoe mensen ranges kunnen gebruiken in shell scripts. Mensen die ranges beheersen, zijn sneller op de Linux command line.
Hier zijn wat ranges en patronen die je zou kunnen gebruiken:
Een oplopende reeks van karakters, in dit geval 1 tot 10, getoond op één lijn:
$ echo "file{1..9}"
file1 file2 file3 file4 file5 file6 file7 file8 file9
$ echo file{s..z}
files filet fileu filev filew filex filey filezDe volgorde van ranges kun je vinden in de man-page van "ascii".
Nog een patroon dat je kunt gebruiken:
$ echo file{1,2,4}
file1 file2 file4Als je meer informatie zoek, Google eens naar "Brace Expansion" of kijk in de man-page van bash.
Dus je hebt een enterprise kwaliteit shell script gemaakt en wil het uitrollen over een setje Red Hat-achtige machines? Een RPM maken is makkelijk, hier zijn de stappen die nodig zijn:
1. Installeer rpmbuild zodat je jouw eigen RPMs kunt gaan bouwen.
2. Pak je script in een tar.gz file en verplaats het naar /usr/src/redhat/SOURCES/
# tar -cvzf shell-script-0.1.tar.gz shell-script-0.1
# mv shell-script-0.1.tar.gz /usr/src/redhat/SOURCES/# cat /usr/src/redhat/SPECS/shell-script.spec
Summary: The do it all script. (Enterprise quality)
Name: shell-script
Version: 0.1
Release: 1
URL: http://meinit.nl
License: GPL
Group: Applications/Internet
BuildRoot: %{_tmppath}/%{name}-root
Requires: bash
Source0: shell-script-%{version}.tar.gz
BuildArch: noarch
%description
A shell script.
%prep
%setup
%build
%install
rm -rf ${RPM_BUILD_ROOT}
mkdir -p ${RPM_BUILD_ROOT}/usr/bin
install -m 755 shell-script.sh ${RPM_BUILD_ROOT}%{_bindir}
%clean
rm -rf ${RPM_BUILD_ROOT}
%files
%defattr(-,root,root)
%attr(755,root,root) %{_bindir}/shell-script.sh
%changelog
* Tue Jan 12 2010 Robert de Bock <robert@meinit.nl>
- Uberscript!# rpmbuild --bb /usr/src/redhat/SPECS/shell-script.spec# rpm -Uvh /usr/src/redhat/RPMS/noarch/shell-script-0.1.1.noarch.rpmAls je nieuw bent in de Red Hat terminology, kan het best wel moeilijk zijn om te begrijpen hoe je een simpele loadbalancer kunt maken met Linux. Hier staat wat informatie om je op weg te helpen.
Lees meer op the CentOS Virtual Server Administration paginas.
Terminologie:
Hier is een overzicht van een mogelijke setup:
Stappen die je moet volgen voor eeuwige glorie:
# yum install piranha-gui# chkconfig httpd on
# chkconfig piranha-gui on
# chkconfig pulse on
# sed -i 's/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/' /etc/sysctl.conf
# echo "*nat
:PREROUTING ACCEPT [46:3346]
:POSTROUTING ACCEPT [431:32444]
:OUTPUT ACCEPT [431:32534]
-A POSTROUTING -o eth0 -j MASQUERADE
COMMIT
*filter
:INPUT ACCEPT [4186:1094786]
:FORWARD ACCEPT [729:111992]
:OUTPUT ACCEPT [4266:388099]
-A FORWARD -i eth1 -j ACCEPT
COMMIT" > /etc/sysconfig/iptables
# chkconfig iptables on
# sed -i 's/SELINUX=enabled/SELINUX=disabled/' /etc/sysconfig/selinuxVoor deze stappen uit in de piranha-gui web interface:
# service httpd start
# piranha-passwd
# service piranha-gui start Je zult de configuratie die piranha maakt in sync moeten houden op beide machines, dit is een suggestie om dat te doen:
# ssh-keygen
# scp .ssh/id_rsa* 192.168.202.110:./.ssh/
# cp .ssh/id_rsa.pub .ssh/authorized_keys# cat update-lvs.cf
#!/bin/sh
copiedserialno=$(grep serial_no /tmp/lvs.cf | awk '{ print $NF }')
runningserialno=$(grep serial_no /etc/sysconfig/ha/lvs.cf | awk '{ print $NF }')
if [ "$copiedserialno" -gt "$runningserialno" ] ; then
mv /tmp/lvs.cf /etc/sysconfig/ha/lvs.cf
fi
# crontab -l
* * * * * /usr/bin/scp /etc/sysconfig/ha/lvs.cf 192.168.1.46:/tmp > /dev/null
* * * * * /root/update-lvs.cfOm alle veranderingen te testen kun je de load-balancer rebooten.
Het duurt niet zo lang meer voordat Fedora 14 uit komt. Eens kijken welke features Fedora 14 heeft.
Al met al een best wel interessante release, ookal is het moeilijk een goede distributie te verbeteren.
Veel van de veranderingen die gedaan worden in Fedora komen in RHEL terrecht. Het lijkt erop dat RHEL 7 ongeveer zal bestaan uit Fedora 16 (op zijn vroegst) tot Fedora 19. (op zijn laatst)
Hier is een korte howto die je helpt je Mac OS X machine logs te ontvangen van apparaten, zoals de Apple Airport Extreme. Er zijn wat howto's online te vinden, maar ik denk dat er wat verandert is sinds Mac OS X 10.5, dus die howto's werken niet perfect.
# echo "local0.notice /var/log/airport.log" >> /etc/syslog.conf# touch /var/log/airport.logAan het einde van het file, uncomment het gedeelte dat remote logging accepteert.
# cat /System/Library/LaunchDaemons/com.apple.syslogd.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.apple.syslogd</string>
<key>OnDemand</key>
<false/>
<key>ProgramArguments</key>
<array>
<!--
Un-comment the following lines to run syslogd with a sandbox profile.
Sandbox profiles restrict processes from performing unauthorized
operations; so it may be necessary to update the profile
(/usr/share/sandbox/syslogd.sb) if any changes are made to the syslog
configuration (/etc/syslog.conf).
-->
<!--
<string>/usr/bin/sandbox-exec</string>
<string>-f</string>
<string>/usr/share/sandbox/syslogd.sb</string>
-->
<string>/usr/sbin/syslogd</string>
</array>
<key>MachServices</key>
<dict>
<key>com.apple.system.logger</key>
<true/>
</dict>
<key>Sockets</key>
<dict>
<key>AppleSystemLogger</key>
<dict>
<key>SockPathName</key>
<string>/var/run/asl_input</string>
<key>SockPathMode</key>
<integer>438</integer>
</dict>
<key>BSDSystemLogger</key>
<dict>
<key>SockPathName</key>
<string>/var/run/syslog</string>
<key>SockType</key>
<string>dgram</string>
<key>SockPathMode</key>
<integer>438</integer>
</dict>
<!--
Un-comment the following lines to enable the network syslog protocol listener.
-->
<key>NetworkListener</key>
<dict>
<key>SockServiceName</key>
<string>syslog</string>
<key>SockType</key>
<string>dgram</string>
</dict>
</dict>
</dict>
</plist># launchctl unload /System/Library/LaunchDaemons/com.apple.syslogd.plist
# launchctl load /System/Library/LaunchDaemons/com.apple.syslogd.plistGa naar de System Preferences, klik Security, open het Firewall tabje en klik de +. Selecteer het file /usr/bin/syslog.
Als je niet in staat bent om /usr te openen, kun je deze hack proberen in de terminal:
$ cd
$ ln -s /usr/bin
$ ln -s /usr/sbinVertel nu aan alle apparaten waarvan je logs wilt zien (zoals de Apple Airport Extreme) dat ze de logs kunnen dumpen op het IP adres van je Mac OS X machine.
Je kunt de applicatie "Console" openen of vanaf een terminal dit commando draaien: "tail -f /var/log/airport.log".
Zit je ooit in de situatie (bijvoorbeeld je werk waar Windows gebruikt wordt) waar je naar jouw machine (bijvoorbeeld je Linux/UNIX machine thuis) zou willen verbinden via SSH, maar de firewall regels laten dat niet toe? Misschien kun je de http-proxy server gebruiken om toch te verbinden.
Let wel op, deze technische truc is misshien wel mogelijk, maar het kan zijn dat het niet toegestaan is. Bespreek het eerst eens met iemand in je organisatie.
Hier zijn de ingrediënten:
Welke proxy gebruikt jouw organisatie?
Er zijn een paar opties beschreven, van makkelijk naar moeilijk, kies er één. Kijk maar welke het beste werkt voor jou.
Configureer Putty om deze proxy te gebruiken.
Nu dat je de proxy server en poort hebt, kun je Putty configureren.
Gefeliciteerd, je bent alsnog verbonden!
If you'd like to move a single installation of Drupal into a multisite environment, use these steps, and replace example.com for your websites name. In this example, Drupal is installed in /var/www/drupal/ .
This one is obvious, the website was first pointing to an individual installation of Drupal, it needs to be directed to the multi-site installation of Drupal.
mkdir -p /var/www/drupal/sites/example.com/
cd /var/www/example.com
cp -Rip html/sites/all/themes html/sites/default/settings.php html/sites/default/files/ /var/www/drupal/sites/example.com/If you have used files (including images) on your website, the path needs to be updated. Earlier files were located on "sites/default/files/", but this will become "sites/example.com/files"
mysql -u root -pPaSsWoRd
USE examplecom;
UPDATE files SET filepath=REPLACE (filepath, 'default', 'example.com');
UPDATE files SET filepath=REPLACE ('filepath', 'images', 'sites/example.com/images') WHERE filepath REGEXP '^images.*';
QUIT;Go to Administer - Site building - Themes - Your Theme "configure" and change the path to reflect the right one. Mostly this means changing the word "files/" to "sites/example.com/files/".
For Apache, that would be:
apachectl configtest
apachectl restartCheck the website, everything should work, maybe you have to reselect your template to make it look better. If all works well, remove the old code.
rm -R /var/www/example.comAfter an installation you might find some file systems are too large, they are almost empty. When you want to use that space for another file system, here are the steps you can take:
Imagine /opt is now 10 Gb, but 1 Gb would be sufficient.
lsof /opt you will get a list of processes that currently use /opt. Stop these processes.df -h /opt or mount. In my example, I found /dev/mapper/VolGroup/opt hold files on /opt.umount /optresize2fs /dev/mapper/VolGroup/opt 1G. This frees the "right" part of the disk that LVM will un-allocate in a moment. All data from the file system is on the "left hand side".lvreduce -L 1G /dev/mapper/VolGroup-opt to shrink the logical volume. (It might warn you that you need to run e2fsck -f /dev/mapper/VolGroup-opt before you can continue.mount /opt.For /opt or any other filesystem that can easily be freed from open file handles, the above procedure works fine, but for "busy" filesystems, like /, /var, /usr, and so on, you'd have boot the machine without mounting filesystems. One way to do this is using the installation CD and starting up the "rescue" environment.