1. System
Standardowa instalacja dystrybucji RedHat 6.2, J�dro 2.2.14, Apache 1.3.12.
[root@linuks /]# /etc/rc.d/init.d/httpd stop2.2 Tworzenie u�ytkownika Tworzymy nowego u�ytkownika 'www':
[root@linuks /]# useradd -c "Apache Server" -u 80 -s /bin/false -r -d /home/httpd www 2>/dev/null ||:2.3 Tworzenie katalog�w Tworzymy now� struktur� katalog�w w kt�rej b�dzie dzia�a� nasz Apache:
[root@linuks /]# mkdir /chroot [root@linuks /]# mkdir -p /chroot/httpd/dev [root@linuks /]# mkdir -p /chroot/httpd/lib [root@linuks /]# mkdir -p /chroot/httpd/etc [root@linuks /]# mkdir -p /chroot/httpd/usr/sbin [root@linuks /]# mkdir -p /chroot/httpd/var/run [root@linuks /]# mkdir -p /chroot/httpd/var/lock [root@linuks /]# mkdir -p /chroot/httpd/var/log/httpd [root@linuks /]# mkdir -p /chroot/httpd/home/httpdNadajemy prawa do katalogu
[root@linuks /]# chmod 750 /chroot/httpd/var/log/httpd2.4 Biblioteki
[root@linuks /]# ldd /usr/sbin/httpdPowiniene� otrzyma� podobn� list� do tej:
libm.so.6 => /lib/libm.so.6 (0x4001b000) libcrypt.so.1 => /lib/libcrypt.so.1 (0x4003a000) libdb.so.3 => /usr/lib/libdb.so.3 (0x40067000) libdl.so.2 => /lib/libdl.so.2 (0x40121000) libc.so.6 => /lib/libc.so.6 (0x40124000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)2.5 Kopiowanie plik�w i bibliotek
[root@linuks /]# cp -r /etc/httpd /chroot/httpd/etc/ [root@linuks /]# cp -r /home/httpd/cgi-bin /chroot/httpd/home/httpd [root@linuks /]# cp -r /home/httpd/html /chroot/httpd/home/httpd [root@linuks /]# cp -r /home/httpd/icons /chroot/httpd/home/httpd [root@linuks /]# cp /usr/sbin/httpd /chroot/httpd/usr/sbin/ [root@linuks /]# cp /lib/libm.so.6 /chroot/httpd/lib/ [root@linuks /]# cp /lib/libcrypt.so.1 /chroot/httpd/lib/ [root@linuks /]# cp /lib/libdb.so.3 /chroot/httpd/lib/ [root@linuks /]# cp /lib/libdl.so.2 /chroot/httpd/lib/ [root@linuks /]# cp /lib/libc.so.6 /chroot/httpd/lib/ [root@linuks /]# cp /lib/ld-linux.so.2 /chroot/httpd/lib/ [root@linuks /]# cp /lib/libnss_compat* /chroot/httpd/lib/ [root@linuks /]# cp /lib/libnss_dns* /chroot/httpd/lib/ [root@linuks /]# cp /lib/libnss_files* /chroot/httpd/lib/ [root@linuks /]# cp /etc/passwd /chroot/httpd/etc [root@linuks /]# cp /etc/group /chroot/httpd/etc [root@linuks /]# cp /etc/mime.types /chroot/httpd/etc [root@linuks /]# cp /etc/resolv.conf /chroot/httpd/etc [root@linuks /]# cp /etc/hosts /chroot/httpd/etc [root@linuks /]# cp /etc/nsswitch.conf /chroot/httpd/etc [root@linuks /]# cp /etc/localtime /chroot/httpd/etcTworzymy specjalny plik i nadajemu mu odpowiednie prawa:
[root@linuks /]# mknod /chroot/httpd/dev/null c 1 3 [root@linuks /]# chmod 666 /chroot/httpd/dev/null2.6 Modyfikacja plik�w
[root@linuks /]# joe /chroot/httpd/etc/httpd/conf/httpd.confOdszukujemy linie:
[root@linuks /]# joe /chroot/httpd/etc/passwdUsuwamy wszystkie wpisy z wyj�tkiem tego:
[root@linuks /]# joe /chroot/httpd/etc/groupUsuwamy wszystkie wpisy z wyj�tkiem tego:
[root@linuks /]# joe /etc/rc.d/init.d/syslogOdszukujemy lini�:
[root@linuks /]# joe /etc/logrotate.d/apacheUstawiamy nowe �cie�ki do log�w:
/chroot/httpd/var/log/httpd/access_log { missingok postrotate /bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true endscript } /chroot/httpd/var/log/httpd/agent_log { missingok postrotate /bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true endscript } /chroot/httpd/var/log/httpd/error_log { missingok postrotate /bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true endscript } /chroot/httpd/var/log/httpd/referer_log { missingok postrotate /bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true endscript }
[root@linuks /]# joe /etc/rc.d/init.d/httpdOdszukujemy lini�:
[root@linuks /]# chattr +i /chroot/httpd/etc/passwd [root@linuks /]# chattr +i /chroot/httpd/etc/group [root@linuks /]# chattr +i /chroot/httpd/etc/resolv.conf [root@linuks /]# chattr +i /chroot/httpd/etc/hosts [root@linuks /]# chattr +i /chroot/httpd/etc/nsswitch.conf [root@linuks /]# chattr +i /chroot/httpd/etc/httpd/conf/httpd.conf2.8 Usuwanie plik�w i katalog�w
[root@linuks /]# rm -rf /var/log/httpd/ [root@linuks /]# rm -rf /etc/httpd [root@linuks /]# rm -rf /home/httpd [root@linuks /]# rm -f /usr/sbin/httpd2.9 Restart syslog'a, Start Apache'a
[root@linuks /]# /etc/rc.d/init.d/syslog restart [root@linuks /]# /etc/rc.d/init.d/httpd start
[root@linuks /]# ps ax | grep httpd 23993 ? S 0:01 httpd 23994 ? S 0:01 httpd 23995 ? S 0:01 httpd 23996 ? S 0:00 httpdWydajemy polecenie:
[root@linuks /]# ls -la /proc/numer_procesu/root/np:
[root@linuks /]# ls -la /proc/23993/root/Je�eli polecenie zwr�ci Ci tak� list�:
dev etc home lib usr varto znaczy, �e wszystko dzia�a !!! I Apache dzia�a ju� we w�asnym �rodowisku. Powy�szy opis mo�na wykorzysta� r�wnie� w innych dystrybucjach, nale�y tylko pami�ta�, �e dystrybucje mog� mie� opisywane pliki w innych katalogach, cz�� plik�w mo�e inaczej si� nazywa�.