3. Cấu hình Samba:
Tập tin
/etc/samba/smb.conf là tập tin cấu hình chính của
Samba server, với tập tin này chúng ta có thể chỉ rõ thư mục nào muốn truy cập từ các máy Windows, địa chỉ IP nào được phép,... Xem phần phụ lục để biết nội dung tập tin này.
Tập tin /etc/samba/lmhosts là tập tin ánh xạ tên Samba Net BIOS tới địa chỉ IP. Nó cũng tương tự như dạng tập tin /etc/hosts ngoại trừ thành phần hostname phải tương ứng với dạng đặt tên Net BIOS.
Tạo tập tin /etc/samba/smbpasswd, đây là tập tin mật khẩu được mã hóa. Nó chứa đựng username, Unix UID và mật khẩu SMB được băm của người sử dụng được phép vào Samba server.
Để tạo tài khoản sử dụng Samba, đầu tiên phải có một tài khoản Linux hợp lệ trong hệ thống, vì vậy tạo các user muốn kết nối đến Samba server trước khi tạo ra tập tin smbpasswd. Cách thực hiện:
Chroot vào minimal system.Tạo tài khoản sinhvien:
sh-3.1# adduser sinhvien (nhập password cho sinhvien)
Cách tạo tập tin smbpasswd từ tập tin /etc/passwd, dùng lệnh:
sh-3.1# cat /etc/passwd | mksmbpasswd.sh > /etc/samba/smbpasswd
Tạo tài khoản sinhvien sử dụng Samba:
sh-3.1# smbpasswd -a sinhvien
Nhập vào password, đây là password được sử dụng để kết nối vào Samba server.
4. Test dịch vụ Samba:
Khởi động vào minimal system. Bật dịch vụ Samba:
[root@localhost ~]# /etc/init.d/smb start
Sử dụng client Windows để kết nối vào Samba server. Lưu ý rằng client và server phải cùng workgroup. Khi kết nối, cần phải nhập vào tài khoản sinhvien và password được tạo với lệnh smbpasswd.
Kết nối thành công, client Windows có thể sử dụng tài nguyên được chia sẻ từ Samba server.
VII. Dịch vụ Web server:
1. Mục đích:
Apache là web server được sử dụng rộng rãi nhất cho hệ thống Linux, chức năng đơn giản nhất của nó là: hiển thị và đưa những trang HTML trên máy chủ đến trình duyệt của người sử dụng để nó hiểu mã của HTML đó.
Download các phiên bản của Apache web server tại http://www.apache.org
2. Cài đặt và cấu hình:
+ Giải nén gói cần cài đặt:
Sao chép gói httpd-2.2.2.tar.gz vào buildroot/build_i686/root/root/ sau đó:
Chroot vào
buildroot để build gói này:
[root@localhost ~] # cp httpd-2.2.2.tar.gz buildroot/build_i686/root/root/
[root@localhost ~] # chroot buildroot/build_i686/root/ sh
~# tar zxvf httpd-2.2.2.tar.gz
~# cd httpd-2.2.2
~/http-2.2.2# CFLAGS=“-Os –pipe” ./configure --prefix=/usr \
--sysconfdir=/etc/httpd/conf \
--localstatedir=/var/run
~/http-2.2.2# make
~/http-2.2.2# make install
+ Sao chép các tập tin và thư viện sau vào minimal system để chạy được dịch vụ httpd.
Vào thư mục buildroot/build_i686/root/usr/ và sao chép các tập tin sau:
[root@localhost ~] # cd buildroot/build_i686/root/usr/
[root@localhost usr] # cp -a lib/libapr-1.so* /mnt/minimalSystem/lib/
[root@localhost usr] # cp -a lib/libexpat.so* /mnt/minimalSystem/lib/
[root@localhost usr] # cp -a lib/libaprutil-1.so* /mnt/minimalSystem/lib/
[root@localhost usr] # cp -a bin/httpd /mnt/minimalSystem/usr/sbin/
[root@localhost usr] # cp -a logs/* /mnt/minimalSystem/var/run
[root@localhost usr] # cp -a htdocs/* /mnt/minimalSystem/usr
[root@localhost usr] # cd ../etc/httpd/conf
[root@localhost conf] # cp –a mime.types httpd.conf /mnt/minimalSystem/etc/httpd/conf
+ Sao chép tập tin script
httpd trong
/etc/init.d/ và tập tin
httpd trong
/etc/sysconfig/ của hệ thống Linux chuẩn vào minimal system.
[root@localhost root] # cp /etc/init.d/httpd /mnt/minimalSystem/etc/init.d
[root@localhost root] # cp /etc/sysconfig/httpd /mnt/minimalSystem/etc/sysconfig
+ Khởi động dịch vụ web server:
Vào hệ thống minimal system và khởi động bằng lệnh sau:
#/etc/init.d/httpd start
Tắt dịch vụ bằng lệnh:
#/etc/init.d/httpd stop
3. Test dịch vụ:
Sau khi server đã chạy httpd, ở máy client, mở trình duyệt web và gõ vào địa chỉ:
http://192.168.1.1/, đây chính là địa chỉ IP của máy server để chạy trang chủ, trang hiển thị lên là trang
index.html.
IX. Dịch vụ Send Mail:
1. Mục đích:
Sau khi chúng ta đã cài đặt được một số dịch vụ FTP, Telnet, SSH, DNS, Web-Server trên minimal system, thì việc đưa sendmail vào minimal cũng là một việc cần thiết và quan trọng. Sendmail là một chương trình truyền tải thư tín điện tử (Internet Mail Transport Agents (MTAs)) được sử dụng rộng rải trên thế giới hiện nay. Mục đích của MTA là chỉ gửi thư điện tử từ máy này đến máy khác.
2. Thông tin về download gói sendmail:
Dưới dây là các địa chỉ download các gói sendmail được nén dưới dạng tar.gz hoặc tar.bz2, chúng ta sử dụng gói
sendmail.8.13.6.tar.gz.
http://www.sendmail.org/ftp/sendmail.8.13.6.tar.gz.
ftp://ftp.sendmail.org/pub/sendmail/sendmail.8.13.6.tar.gz.
3. Biên dịch
Chúng ta sẽ đặt gói
sendmail.8.13.6.tar.gz trong thư mục
/root của
buildroot (cũng có thể đặt đường dẫn khác), tất cả các bước của quá trình cài đặt sẽ dùng tài khoản root. Sau đây là cách đơn giản nhất để dịch được gói sendmail này.
Giải nén tập tin sendmail.8.13.6.tar.gz.
~# tar zxvf sendmail.8.13.6.tar.gz
~# cd sendmail.8.13.6
Trước hết giải nén sendmail.8.13.6.tar.gz, sau đó vào thư mục vừa giải nén, dùng lệnh ls để xem danh sách các tập tin và thư mục ở đây, dùng lệnh cd vào thư mục sendmail, ở đây có tập tin Build, đây là tập tin script dùng cho việc cài đặt. Thực hiện lệnh “sh Build” thì gặp phải một lỗi sau:
milter.o mime.o parseaddr.o queue.o ratectrl.o readcf.o recipient.o sasl.o savemail.o sfsasl.o shmticklib.o sm_resolve.o srvrsmtp.o stab.o stats.o sysexits.o timers.o tls.o trace.o udb.o usersmtp.o util.o version.o /root/sendmail-8.13.6/obj.Linux.2.4.20-8.i686/libsmutil/libsmutil.a /root/sendmail-8.13.6/obj.Linux.2.4.20-8.i686/libsm/libsm.a -ldb -lresolv -lcrypt -lnsl -ldl
domain.o: In function `getmxrr':
domain.c:(.text+0x290): undefined reference to `__dn_skipname'
domain.o: In function `dns_getcanonname':
domain.c:(.text+0x100f): undefined reference to `__dn_skipname'
collect2: ld returned 1 exit status
make: *** [sendmail] Error 1
Cần vào trong tập tin domain.c.
~/sendmail.8.13.6# vi sendmail/domain.c
Đóng đoạn mã dưới lại, đối với DNS với những phiên bản cũ hơn thì hàm “dn_skipname” không được định nghĩa vì thế sẽ gây ra lỗi trong khi dịch, dưới đây là hai đoạn code sẽ gây ra lỗi.
/* find first satisfactory answer */
hp = (HEADER *)&answer;
cp = (unsigned char *)&answer + HFIXEDSZ;
eom = (unsigned char *)&answer + n;
for (qdcount = ntohs((unsigned short) hp->qdcount);
qdcount--;
cp += n + QFIXEDSZ)
{
if ((n = dn_skipname(cp, eom)) < 0)
goto punt;
}
/* skip question part of response -- we know what we asked */
for (qdcount = ntohs((unsigned short) hp->qdcount);
qdcount--;
ap += ret + QFIXEDSZ)
{
if ((ret = dn_skipname(ap, eom)) < 0)
{
if (tTd(8, 20))
sm_dprintf("qdcount failure (%d)\n",
ntohs((unsigned short) hp- >qdcount));
*statp = EX_SOFTWARE;
return false; /* ???XXX??? */
}
}
Bây giờ thực hiện lại lệnh “sh Build”:
~/sendmail.8.13.6# sh Build
Khi chạy lệnh trên thành công cần vào thư mục
cf/cf tạo hai tập tin
sendmail.cf và
sendmail.mc:
~/sendmail.8.13.6# cd cf/cf
~/sendmail.8.13.6/cf/cf# cp generic-linux.cf sendmail.cf
~/sendmail.8.13.6/cf/cf# cp generic-linux.mc sendmail.mc
~/sendmail.8.13.6/cf/cf# sh Build sendmail-cf
~/sendmail.8.13.6/cf/cf# make install-cf CF=config
~/sendmail.8.13.6/cf/cf# sh Build install-cf
Sau đó vào lại thư mục sendmail.8.13.6 chạy lệnh:
~/sendmail.8.13.6/cf/cf# cd ../../
~/sendmail.8.13.6/# sh Build install
Cũng có thể cài đặt mailstats, makemap, praliases, smrsh bằng các lệnh “sh Build install” nó tương ứng như những trang man của hệ thống. Nhưng điều mà chúng ta cần là tập tin thực thi chương trình sendmail, nó được chứa ở /usr/sbin/sendmail, hoặc sau khi cài đặt xong dùng lệnh “which sendmail” để biết được sendmail được cài đặt vào đâu, theo đường dẫn này để sao chép vào hệ thống đích (minimal system).
Đến đây xem như ta đã cài đặt được gói phần mềm sendmail, công việc còn lại là cấu hình sendmail.
Chúng ta cần sao chép các tập tin script để sendmail chạy, có thể sao chép từ hệ thống thực:
- Cần sao chép tập tin sendmail trong thư mục /etc/sysconfig/.
- Cần sao chép tập tin sendmail scripts trong thư mục /etc/init.d/.
- Cần sao chép tập tin local-host-names trong thư mục /etc/mail.
- Cần sao chép tập tin access trong thư mục /etc/mail.
- Cần sao chép tập tin alias trong thư mục /etc/mail.
- Cần sao chép tập tin domaintable trong thư mục /etc/mail.
- Cần sao chép tập tin virtusertable trong thư mục /etc/mail.
4. Cấu hình Mail Server:
Chroot vào hệ thống minimal system. Tạo tài khoản
smmsp có thư mục home là
/var/spool/mqueue, và thực hiện các bước sau:
Bước 1: Sửa nội dung tập tin /etc/mail/access. Tập tin này được cần thêm vào những đối tượng mà chúng ta cho phép hoặc cấm gửi mail. Có ba trường hợp xảy ra đó là:
RELAY: cho phép gửi và nhận mail.
REJECT: cấm gửi và nhận mail, tuy nhiên người gửi mail đến đối tượng này sẽ nhân được thông báo rằng đối tượng này đã bị ngăn chặn mail đến và mail đi.
DISCARD: cấm gửi và nhận mail.
Mặc định đối tượng nào không có trong tập tin này là RELAY.
localhost.localdomain RELAY
localhost RELAY
127.0.0.1 RELAY
192.168 RELAY
hcmuaf.edu.vn RELAY
loc@hcmuaf.edu.vn RELAY
duy@hcmuaf.edu.vn REJECT
vuong@hotmail.com DISCARD
Bước 2: Cập nhật lại cơ sở dữ liệu vào tập tin access.db
#
makemap hash /etc/mail/access.db < /etc/mail/access
Bước 3: Sửa tập tin /etc/mail/sendmail.cf .
Tìm và sửa những giá trị sau:
#Cwlocalhost (comment).
Cwlocalhost hcmuaf.edu.vn
#Dj$w.Foo.Com.
Dj$w.hcmuaf.edu.vn
#C{w} localhost.
C{w} hcmuaf.edu.vn
#O DaemonPortOptions=Port=smtp,Addr=127.0.0.1, Name=MTA
Bước 4: Lưu tập tin lại và khởi động dịch vụ sendmail.
# /etc/init.d/sendmail start
Dịch vụ này đang trong quá trình test thử nghiệm, chưa hoàn chỉnh.
Chương 5
KẾT LUẬN VÀ HƯỚNG PHÁT TRIỂN
I. So sánh kết quả đạt được so với yêu cầu đề tài đặt ra ban đầu:
Nhìn chung, ta đã hoàn thành được yêu cầu của đề tài đặt ra là xây dựng một hệ thống Linux từ các gói mã nguồn mở chính qui trên mạng.
Hệ thống Linux này có đầy đủ các tính năng cơ bản của một hệ điều hành Linux và có dung lượng nhỏ hơn 30MB.
Cụ thể hơn, ta đã xây dựng được một hệ thống với tương đối đầy đủ các dịch vụ hỗ trợ cho việc bảo mật và quản trị mạng cần thiết mà một hệ thống Linux chuẩn cần có.
Những dịch vụ như là: FTP, SSH, Telnet, DNS, Samba, Iptables, Web server đã được test thử và hoạt động tốt.
II. Các ưu, nhược điểm:
1. Ưu điểm:
- Hệ thống nhỏ gọn, dung lượng tối ưu, là ý tưởng để xây dựng các hệ thống nhúng trong thực tế.
- Phát triển hệ thống theo hướng nguồn mở (open source) hoàn toàn miễn phí.
- Tích hợp gần như đầy đủ dịch vụ cho việc quản trị hệ thống.
- Hệ thống chạy ổn định, không sinh lỗi và không ăn bộ nhớ.
2. Nhược điểm:
- Không cung cấp hướng dẫn cách sử dụng các lệnh trong hệ thống.
- Chưa hỗ trợ được một Makefile cho toàn bộ hệ thống.
- Giao diện tương tác user chỉ là giao diện dòng lệnh.
III. Hướng phát triển:
- Do dung lượng của hệ thống nhỏ gọn nên có thể cài đặt vào Flash: disk on chip hoặc là disk on module.
- Phát triển cho hệ thống nhỏ gọn hơn nữa để đưa vào đĩa mềm.
- Đang xây dựng hệ thống bằng tay một cách thủ công, có thể phát triển để xây dựng hệ thống một cách tự động (autobuilding) bằng cách dùng một Makefile cho toàn hệ thống.
- Tích hợp thêm giao diện đồ họa vào minimal system để hệ thống thân thiện hơn với người dùng.
TÀI LIỆU THAM KHẢO
[1] How to build a minimal system, ở địa chỉ:
http://users.rsise.anu.edu.au/~okeefe/p2b/buildMin/buildMin.html
[2] From-PowerUp-To-Bash-Prompt ở địa chỉ:
http://en.tldp.org/HOWTO/From-PowerUp-To-Bash-Prompt-HOWTO.html
[3] Gerard Beekmans, Linux From Scratch, 2005, ở địa chỉ:
http://www.linuxfromscratch.org/
[4] BLFS Development Team, Beyond Linux From Scratch, 2003, ở địa chỉ:
http://www.linuxfromscratch.org/
[5] Nguyễn Phương Lan & Hoàng Đức Hải, Lập trình Linux, 2003.
[6] Gerhard Mourani, Securing and Optimizing Linux_Redhat Edition, 2003
[7] V. Stanfield, R. W. Smith, Linux System Administration, Second Edition, 2003
[8] Don Davies, Embedding Redhat Linux in a DiskOnChip – HOWTO, 2002.
[9] Building Tiny Linux Systems with Busybox, Part2: Building The Kernel ở: http://www.linuxjournal.com/
[10] Tom Fawcett, The Linux Bootdisk HOWTO, 2002, ở địa chỉ:
http://www.linuxlots.com/~fawcett/Bootdisk-HOWTO/index.html
[11] Karim Yaghmour, Building Embedded Linux Systems, 2003 ở:
http://www.oreillynet.com/cs/catalog/view/au/1113?x-t=book.view
[12] Trần Thạch Tùng, Bảo mật và Tối ưu trong Red Hat Linux, 2003
PHỤ LỤC
1. /etc/rc.d/rc.sysinit
#!/bin/bash
# /etc/rc.d/rc.sysinit - run once at boot time
HOSTNAME=`/bin/hostname`
HOSTTYPE=`uname -m`
unamer=`uname -r`
if [ -f /etc/sysconfig/network ]; then
. /etc/sysconfig/network
fi
if [ -z "$HOSTNAME" -o "$HOSTNAME" = "(none)" ]; then
HOSTNAME=localhost
fi
# Mount /proc and /sys (done here so volume labels can work with fsck)
mount -n -t proc /proc /proc
mount -n -t sysfs /sys /sys >/dev/null 2>&1
. /etc/init.d/functions
if [ "$HOSTTYPE" != "s390" -a "$HOSTTYPE" != "s390x" ]; then
last=0
for i in `LC_ALL=C grep '^[0-9].*respawn:/sbin/getty' /etc/inittab | sed 's/^.* tty\([0-9][0-9]*\).*/\1/g'`; do
> /dev/tty$i
last=$i
done
if [ $last -gt 0 ]; then
> /dev/tty$((last+1))
> /dev/tty$((last+2))
fi
fi
# Set the system clock.
#update_boot_stage RCclock
ARC=0
SRM=0
UTC=0
if [ -f /etc/sysconfig/clock ]; then
. /etc/sysconfig/clock
# convert old style clock config to new values
if [ "${CLOCKMODE}" = "GMT" ]; then
UTC=true
elif [ "${CLOCKMODE}" = "ARC" ]; then
ARC=true
fi
fi
CLOCKDEF=""
CLOCKFLAGS="$CLOCKFLAGS --hctosys"
case "$UTC" in
yes|true) CLOCKFLAGS="$CLOCKFLAGS --utc"
CLOCKDEF="$CLOCKDEF (utc)" ;;
no|false) CLOCKFLAGS="$CLOCKFLAGS --localtime"
CLOCKDEF="$CLOCKDEF (localtime)" ;;
esac
case "$ARC" in
yes|true) CLOCKFLAGS="$CLOCKFLAGS --arc"
CLOCKDEF="$CLOCKDEF (arc)" ;;
esac
case "$SRM" in
yes|true) CLOCKFLAGS="$CLOCKFLAGS --srm"
CLOCKDEF="$CLOCKDEF (srm)" ;;
esac
/sbin/hwclock $CLOCKFLAGS
action $"Setting clock $CLOCKDEF: `date`" /bin/true
# Set the hostname.
#update_boot_stage RChostname
action $"Setting hostname ${HOSTNAME}: " hostname ${HOSTNAME}
if [ -f /fsckoptions ]; then
fsckoptions=`cat /fsckoptions`
fi
if [ -f /forcefsck ] || strstr "$cmdline" forcefsck ; then
fsckoptions="-f $fsckoptions"
elif [ -f /.autofsck ]; then
[ -f /etc/sysconfig/autofsck ] && . /etc/sysconfig/autofsck
if [ "$AUTOFSCK_DEF_CHECK" = "yes" ]; then
AUTOFSCK_OPT="$AUTOFSCK_OPT -f"
fi
fsckoptions="$AUTOFSCK_OPT $fsckoptions"
fi
if [ "$BOOTUP" = "color" ]; then
fsckoptions="-C $fsckoptions"
else
fsckoptions="-V $fsckoptions"
fi
if [ -f /etc/sysconfig/readonly-root ]; then
. /etc/sysconfig/readonly-root
if [ "$READONLY" = "yes" ]; then
# Call rc.readonly to set up magic stuff needed for readonly root
. /etc/rc.readonly
fi
fi
_RUN_QUOTACHECK=0
if [ -z "$fastboot" -a "$READONLY" != "yes" ]; then
STRING=$"Checking filesystems"
echo $STRING
if [ "${RHGB_STARTED}" != "0" -a -w /etc/rhgb/temp/rhgb-console ]; then
fsck -T -A -a $fsckoptions > /etc/rhgb/temp/rhgb-console
else
fsck -T -A -a $fsckoptions
fi
rc=$?
if [ "$rc" -eq "0" ]; then
success "$STRING"
echo
elif [ "$rc" -eq "1" ]; then
passed "$STRING"
echo
elif [ "$rc" -eq "2" -o "$rc" -eq "3" ]; then
echo $"Unmounting filesystems"
umount -a
mount -n -o remount,ro /
echo $"Automatic reboot in progress."
reboot -f
fi
# A return of 4 or higher means there were serious problems.
if [ $rc -gt 1 ]; then
if [ -x /usr/bin/rhgb-client ] && /usr/bin/rhgb-client --ping ; then
chvt 1
fi
failure "$STRING"
echo
echo
echo $"*** An error occurred during the file system check."
echo $"*** Dropping you to a shell; the system will reboot"
echo $"*** when you leave the shell."
str=$"(Repair filesystem)"
PS1="$str \# # "; export PS1
[ "$SELINUX" = "1" ] && disable_selinux
sulogin
echo $"Unmounting file systems"
umount -a
mount -n -o remount,ro /
echo $"Automatic reboot in progress."
reboot -f
elif [ "$rc" -eq "1" ]; then
_RUN_QUOTACHECK=1
fi
if [ -f /.autofsck -a -x /usr/bin/rhgb-client ] && /usr/bin/rhgb-client --ping ; then
chvt 8
fi
fi
# Remount the root filesystem read-write.
update_boot_stage RCmountfs
state=`LC_ALL=C awk '/ \/ / && ($3 !~ /rootfs/) { print $4 }' /proc/mounts`
[ "$state" != "rw" -a "$READONLY" != "yes" ] && \
mount -n -o remount,rw /
# Clear mtab
(> /etc/mtab) &> /dev/null
# Remove stale backups
rm -f /etc/mtab~ /etc/mtab~~
# Enter mounted filesystems into /etc/mtab
#mount -f /
mount -f /proc >/dev/null 2>&1
mount -f /sys >/dev/null 2>&1
# Initialize pseudo-random number generator
if [ -f "/var/lib/random-seed" ]; then
cat /var/lib/random-seed > /dev/urandom
else
touch /var/lib/random-seed
fi
chmod 600 /var/lib/random-seed
dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=512 2>/dev/null
# Clean out /.
rm -f /fastboot /fsckoptions /forcefsck /.autofsck /halt /poweroff &> /dev/null
# Do we need w|u)tmpx files? We don't set them up, but the sysadmin might...
_NEED_XFILES=
[ -f /var/run/utmpx -o -f /var/log/wtmpx ] && _NEED_XFILES=1
# Clean up /var. I'd use find, but /usr may not be mounted.
for afile in /var/lock/* /var/run/* ; do
if [ -d "$afile" ]; then
case "$afile" in
*/news|*/mon) ;;
*/sudo) rm -f $afile/*/* ;;
*/vmware) rm -rf $afile/*/* ;;
*/samba) rm -rf $afile/*/* ;;
*/screen) rm -rf $afile/* ;;
*) rm -f $afile/* ;;
esac
else
rm -f $afile
fi
done
# Clean up utmp/wtmp
> /var/run/utmp
touch /var/log/wtmp
chgrp utmp /var/run/utmp /var/log/wtmp
chmod 0664 /var/run/utmp /var/log/wtmp
if [ -n "$_NEED_XFILES" ]; then
> /var/run/utmpx
touch /var/log/wtmpx
chgrp utmp /var/run/utmpx /var/log/wtmpx
chmod 0664 /var/run/utmpx /var/log/wtmpx
fi
/sbin/ifconfig lo 127.0.0.1 up
/sbin/ifconfig eth0 192.168.1.1 up
2. /etc/rc.d/init.d/functions
# functions This file contains functions to be used by most or all
# shell scripts in the /etc/init.d directory.
TEXTDOMAIN=initscripts
# Make sure umask is sane
umask 022
# Set up a default search path.
PATH="/sbin:/usr/sbin:/bin:/usr/bin"
export PATH
# Read in our configuration
if [ -z "${BOOTUP:-}" ]; then
if [ -f /etc/sysconfig/init ]; then
. /etc/sysconfig/init
else
# This all seem confusing? Look in /etc/sysconfig/init,
# or in /usr/doc/initscripts-*/sysconfig.txt
BOOTUP=color
RES_COL=60
MOVE_TO_COL="echo -en \\033[${RES_COL}G"
SETCOLOR_SUCCESS="echo -en \\033[1;32m"
SETCOLOR_FAILURE="echo -en \\033[1;31m"
SETCOLOR_WARNING="echo -en \\033[1;33m"
SETCOLOR_NORMAL="echo -en \\033[0;39m"
LOGLEVEL=1
fi
if [ "$CONSOLETYPE" = "serial" ]; then
BOOTUP=serial
MOVE_TO_COL=
SETCOLOR_SUCCESS=
SETCOLOR_FAILURE=
SETCOLOR_WARNING=
SETCOLOR_NORMAL=
fi
fi
if [ "${BOOTUP:-}" != "verbose" ]; then
INITLOG_ARGS="-q"
else
INITLOG_ARGS=
fi
# Check if $pid (could be plural) are running
checkpid() {
local i
for i in $* ; do
[ -d "/proc/$i" ] && return 0
done
return 1
}
# A function to start a program.
daemon() {
# Test syntax.
local gotbase= force=
local base= user= nice= bg= pid=
nicelevel=0
while [ "$1" != "${1##[-+]}" ]; do
case $1 in
'') echo $"$0: Usage: daemon [+/-nicelevel] {program}"
return 1;;
--check)
base=$2
gotbase="yes"
shift 2
;;
--check=?*)
base=${1#--check=}
gotbase="yes"
shift
;;
--user)
user=$2
shift 2
;;
--user=?*)
user=${1#--user=}
shift
;;
--force)
force="force"
shift
;;
[-+][0-9]*)
nice="nice -n $1"
shift
;;
*) echo $"$0: Usage: daemon [+/-nicelevel] {program}"
return 1;;
esac
done
# Save basename.
[ -z "$gotbase" ] && base=${1##*/}
# See if it's already running. Look *only* at the pid file.
if [ -f /var/run/${base}.pid ]; then
local line p
read line < /var/run/${base}.pid
for p in $line ; do
[ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p"
done
fi
[ -n "${pid:-}" -a -z "${force:-}" ] && return
# make sure it doesn't core dump anywhere unless requested
ulimit -S -c ${DAEMON_COREFILE_LIMIT:-0} >/dev/null 2>&1
# if they set NICELEVEL in /etc/sysconfig/foo, honor it
[ -n "$NICELEVEL" ] && nice="nice -n $NICELEVEL"
# Echo daemon
[ "${BOOTUP:-}" = "verbose" -a -z "$LSB" ] && echo -n " $base"
# And start it up.
if [ -z "$user" ]; then
$nice $*
else
$nice runuser -s /bin/bash - $user -c "$*"
fi
[ "$?" -eq 0 ] && success $"$base startup" || failure $"$base startup"
}
# A function to stop a program.
killproc() {
RC=0
# Test syntax.
if [ "$#" -eq 0 ]; then
echo $"Usage: killproc {program} [signal]"
return 1
fi
notset=0
# check for second arg to be kill level
if [ -n "$2" ]; then
killlevel=$2
else
notset=1
killlevel="-9"
fi
# Save basename.
base=${1##*/}
# Find pid.
pid=
if [ -f /var/run/${base}.pid ]; then
local line p
read line < /var/run/${base}.pid
for p in $line ; do
[ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p"
done
fi
if [ -z "$pid" ]; then
pid=`pidof -o $$ -o $PPID -o %PPID -x $1 || \
pidof -o $$ -o $PPID -o %PPID -x $base`
fi
# Kill it.
if [ -n "${pid:-}" ] ; then
[ "$BOOTUP" = "verbose" -a -z "$LSB" ] && echo -n "$base "
if [ "$notset" -eq "1" ] ; then
if checkpid $pid 2>&1; then
# TERM first, then KILL if not dead
kill -TERM $pid >/dev/null 2>&1
usleep 100000
if checkpid $pid && sleep 1 &&
checkpid $pid && sleep 3 &&
checkpid $pid ; then
kill -KILL $pid >/dev/null 2>&1
usleep 100000
fi
fi
checkpid $pid
RC=$?
[ "$RC" -eq 0 ] && failure $"$base shutdown" || success $"$base shutdown"
RC=$((! $RC))
# use specified level only
else
if checkpid $pid; then
kill $killlevel $pid >/dev/null 2>&1
RC=$?
[ "$RC" -eq 0 ] && success $"$base $killlevel" || failure $"$base $killlevel"
fi
fi
else
failure $"$base shutdown"
RC=0
fi
# Remove pid file if any.
if [ "$notset" = "1" ]; then
rm -f /var/run/$base.pid
fi
return $RC
}
# A function to find the pid of a program. Looks *only* at the pidfile
pidfileofproc() {
local base=${1##*/}
# Test syntax.
if [ "$#" = 0 ] ; then
echo $"Usage: pidfileofproc {program}"
return 1
fi
# First try "/var/run/*.pid" files
if [ -f /var/run/$base.pid ] ; then
local line p pid=
read line < /var/run/$base.pid
for p in $line ; do
[ -z "${p//[0-9]/}" -a -d /proc/$p ] && pid="$pid $p"
done
if [ -n "$pid" ]; then
echo $pid
return 0
fi
fi
}
# A function to find the pid of a program.
pidofproc() {
base=${1##*/}
# Test syntax.
if [ "$#" = 0 ]; then
echo $"Usage: pidofproc {program}"
return 1
fi
# First try "/var/run/*.pid" files
if [ -f /var/run/$base.pid ]; then
local line p pid=
read line < /var/run/$base.pid
for p in $line ; do
[ -z "${p//[0-9]/}" -a -d /proc/$p ] && pid="$pid $p"
done
if [ -n "$pid" ]; then
echo $pid
return 0
fi
fi
pidof -c -o $$ -o $PPID -o %PPID -x $1 || \
pidof -c -o $$ -o $PPID -o %PPID -x $base
}
status() {
local base=${1##*/}
local pid
# Test syntax.
if [ "$#" = 0 ] ; then
echo $"Usage: status {program}"
return 1
fi
# First try "pidof"
pid=`pidof -o $$ -o $PPID -o %PPID -x $1 || \
pidof -o $$ -o $PPID -o %PPID -x ${base}`
if [ -n "$pid" ]; then
echo $"${base} (pid $pid) is running..."
return 0
fi
# Next try "/var/run/*.pid" files
if [ -f /var/run/${base}.pid ] ; then
read pid < /var/run/${base}.pid
if [ -n "$pid" ]; then
echo $"${base} dead but pid file exists"
return 1
fi
fi
# See if /var/lock/subsys/${base} exists
if [ -f /var/lock/subsys/${base} ]; then
echo $"${base} dead but subsys locked"
return 2
fi
echo $"${base} is stopped"
return 3
}
echo_success() {
[ "$BOOTUP" = "color" ] && $MOVE_TO_COL
echo -n "[ "
[ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
echo -n $"OK"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo -n " ]"
echo -ne "\r"
return 0
}
echo_failure() {
[ "$BOOTUP" = "color" ] && $MOVE_TO_COL
echo -n "["
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo -n $"FAILED"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo -n "]"
echo -ne "\r"
return 1
}
echo_passed() {
[ "$BOOTUP" = "color" ] && $MOVE_TO_COL
echo -n "["
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo -n $"PASSED"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo -n "]"
echo -ne "\r"
return 1
}
echo_warning() {
[ "$BOOTUP" = "color" ] && $MOVE_TO_COL
echo -n "["
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo -n $"WARNING"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo -n "]"
echo -ne "\r"
return 1
}
# Inform the graphical boot of our current state
update_boot_stage() {
if [ "$GRAPHICAL" = "yes" -a -x /usr/bin/rhgb-client ]; then
/usr/bin/rhgb-client --update="$1"
fi
return 0
}
# Log that something succeeded
success() {
#if [ -z "${IN_INITLOG:-}" ]; then
# initlog $INITLOG_ARGS -n $0 -s "$1" -e 1
#fi
[ "$BOOTUP" != "verbose" -a -z "$LSB" ] && echo_success
return 0
}
# Log that something failed
failure() {
rc=$?
#if [ -z "${IN_INITLOG:-}" ]; then
# initlog $INITLOG_ARGS -n $0 -s "$1" -e 2
#fi
[ "$BOOTUP" != "verbose" -a -z "$LSB" ] && echo_failure
[ -x /usr/bin/rhgb-client ] && /usr/bin/rhgb-client --details=yes
[ -w /var/gdm/.gdmfifo ] && echo "BOOTUP_ERRORS" > /var/gdm/.gdmfifo &
return $rc
}
# Log that something passed, but may have had errors. Useful for fsck
passed() {
rc=$?
#if [ -z "${IN_INITLOG:-}" ]; then
# initlog $INITLOG_ARGS -n $0 -s "$1" -e 1
#fi
[ "$BOOTUP" != "verbose" -a -z "$LSB" ] && echo_passed
return $rc
}
# Log a warning
warning() {
rc=$?
#if [ -z "${IN_INITLOG:-}" ]; then
# initlog $INITLOG_ARGS -n $0 -s "$1" -e 1
#fi
[ "$BOOTUP" != "verbose" -a -z "$LSB" ] && echo_warning
return $rc
}
# Run some action. Log its output.
action() {
STRING=$1
echo -n "$STRING "
if [ "${RHGB_STARTED}" != "" -a -w /etc/rhgb/temp/rhgb-console ]; then
echo -n "$STRING " > /etc/rhgb/temp/rhgb-console
fi
shift
$* && success $"$STRING" || failure $"$STRING"
rc=$?
echo
if [ "${RHGB_STARTED}" != "" -a -w /etc/rhgb/temp/rhgb-console ]; then
if [ "$rc" = "0" ]; then
echo_success > /etc/rhgb/temp/rhgb-console
else
echo_failure > /etc/rhgb/temp/rhgb-console
[ -x /usr/bin/rhgb-client ] && /usr/bin/rhgb-client --details=yes
fi
echo
fi
return $rc
}
# returns OK if $1 contains $2
strstr() {
[ "${1#*$2*}" = "$1" ] && return 1
return 0
}
# Confirm whether we really want to run this service
confirm() {
[ -x /usr/bin/rhgb-client ] && /usr/bin/rhgb-client --details=yes
while : ; do
echo -n $"Start service $1 (Y)es/(N)o/(C)ontinue? [Y] "
read answer
if strstr $"yY" "$answer" || [ "$answer" = "" ] ; then
return 0
elif strstr $"cC" "$answer" ; then
rm -f /var/run/confirm
[ -x /usr/bin/rhgb-client ] && /usr/bin/rhgb-client --details=no
return 2
elif strstr $"nN" "$answer" ; then
return 1
fi
done
}
3. /etc/vsftpd/vsftpd.conf
# Example config file /etc/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
#anonymous_enable=YES
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/vsftpd.log
#
# If you want, you can have your log file in standard ftpd xferlog format
#xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd.banned_emails
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd.chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
listen=YES
4. /etc/init.d/named
#!/bin/sh
#
# named This shell script takes care of starting and stopping
# named (BIND DNS server).
#
# chkconfig: - 55 45
# description: named (BIND) is a Domain Name Server (DNS) \
# that is used to resolve host names to IP addresses.
# probe: true
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -f /usr/sbin/named ] || exit 0
[ -f /etc/named.conf ] || exit 0
RETVAL=0
# See how we were called.
case "$1" in
start)
# Start daemons.
echo -n "Starting named: "
daemon named
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/named
echo
;;
stop)
# Stop daemons.
echo -n "Shutting down named: "
killproc named
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/named
echo
;;
status)
/usr/sbin/rndc status
exit $?
;;
restart)
$0 stop
$0 start
;;
reload)
/usr/sbin/rndc reload
exit $?
;;
probe)
# named knows how to reload intelligently; we don't want linuxconf
# to offer to restart every time
/usr/sbin/rndc reload >/dev/null 2>&1 || echo start
exit 0
;;
*)
echo "Usage: named {start|stop|status|restart}"
exit 1
esac
exit $RETVAL
5. /etc/samba/smb.conf
[global]
workgroup = WORKGROUP
netbios name = MinSystem
server string = Samba Server
security = user
encrypt passwords = true
smb passwd file = /etc/samba/smbpasswd
hosts allow = 192.168.1. 192.168.2. 127.
; load printers = yes
; printcap name = /etc/printcap
; printcap name = lpstat
; printing = cups
; guest account = pcguest
log file = /var/log/samba/log.%m
max log size = 50
; password server =
; realm = MY_REALM
; include = /usr/local/samba/lib/smb.conf.%m
socket options = TCP_NODELAY
; interfaces = 192.168.12.2/24 192.168.13.2/24
local master = yes
os level = 65
preferred master = yes
; domain logons = yes
; logon script = %m.bat
# run a specific logon batch file per username
; logon script = %U.bat
# Where to store roving profiles (only for Win95 and WinNT)
# %L substitutes for this servers netbios name, %U is username
# You must uncomment the [Profiles] share below
; logon path = \\%L\Profiles\%U
# Windows Internet Name Serving Support Section:
# WINS Support - Tells the NMBD component of Samba to enable it's WINS Server
; wins support = yes
# WINS Server - Tells the NMBD components of Samba to be a WINS Client
# Note: Samba can be either a WINS Server, or a WINS Client, but NOT both
; wins server = w.x.y.z
# WINS Proxy - Tells Samba to answer name resolution queries on
# behalf of a non WINS capable client, for this to work there must be
# at least one WINS Server on the network. The default is NO.
; wins proxy = yes
# DNS Proxy - tells Samba whether or not to try to resolve NetBIOS names
# via DNS nslookups. The default is NO.
dns proxy = no
name resolve order = lmhosts host bcash
# These scripts are used on a domain controller or stand-alone
# machine to add or delete corresponding unix accounts
; add user script = /usr/sbin/useradd %u
; add group script = /usr/sbin/groupadd %g
; add machine script = /usr/sbin/adduser -n -g machines -c Machine -d /dev/null -s /bin/false %u
; delete user script = /usr/sbin/userdel %u
; delete user from group script = /usr/sbin/deluser %u %g
; delete group script = /usr/sbin/groupdel %g
#============================ Share Definitions ==============================
[homes]
comment = Home Directories
browseable = no
writable = yes
# Un-comment the following and create the netlogon directory for Domain Logons
; [netlogon]
; comment = Network Logon Service
; path = /usr/local/samba/lib/netlogon
; guest ok = yes
; writable = no
; share modes = no
;[Profiles]
; path = /usr/local/samba/profiles
; browseable = no
; guest ok = yes
# NOTE: If you have a BSD-style print system there is no need to
# specifically define each individual printer
[printers]
comment = All Printers
path = /usr/spool/samba
browseable = no
# Set public = yes to allow user 'guest account' to print
; guest ok = no
writable = no
printable = yes
# This one is useful for people to share files
[tmp]
comment = Temporary file space
path = /tmp
read only = no
writable = yes
public = yes
6. /etc/inittab
id:3:initdefault:
# System initialization.
si::sysinit:/etc/rc.d/rc.sysinit
l0:0:wait:/etc/rc.d/rc 0
l1:1:wait:/etc/rc.d/rc 1
l3:3:wait:/etc/rc.d/rc 3
l6:6:wait:/etc/rc.d/rc 6
# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now
# When our UPS tells us power has failed, assume we have a few minutes
# of power left. Schedule a shutdown for 2 minutes from now.
# This does, of course, assume you have powerd installed and your
# UPS connected and working correctly.
pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"
# If power was restored before the shutdown kicked in, cancel it.
pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"
# Run
gettys in standard runlevels
1:2345:respawn:/sbin/getty 9600 tty1
2:2345:respawn:/sbin/getty 9600 tty2
3:2345:respawn:/sbin/getty 9600 tty3
7. /etc/fstab
#
/dev/hda11 / ext2 defaults 1 1
proc /proc proc defaults 0 0
sys /sys sysfs defaults 0 0