本站首页    管理页面    写新日志    退出


«October 2025»
1234
567891011
12131415161718
19202122232425
262728293031


公告
 本博客在此声明所有文章均为转摘,只做资料收集使用。

我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:
日志总数:1304
评论数量:2242
留言数量:5
访问次数:7631311
建立时间:2006年5月29日




[网络与系统管理]Debian学习笔记6
软件技术

lhwork 发表于 2007/2/2 10:13:31

Chapter 10. Debian服务器篇 Table of Contents 10.1. 在IBM X335服务器上安装Debian woody 3.0 10.2. 系统管理工具 10.3. Apache2 10.3.1. 虚拟主机 10.3.2. 性能调整 10.3.3. 安全 10.4. Exim4邮件服务器 10.4.1. 邮件系统基础知识 10.4.2. Exim4邮件服务器的工作原理 10.4.3. 安装与配置 10.5. 安装Zope2.7 10.6. 安装Zope 3.1.0b1 10.7. 安装MySQL数据库 10.8. 安装Samba服务器 10.9. 设置磁盘配额 10.10. 安装OpenLDAP目录服务器 10.11. 安装HylaFAX传真服务器 10.11.1. 安装 10.11.2. 配置 10.12. 安装Jabberd服务器 10.13. 安装Jabberd2服务器 10.14. MoinMoin服务器 10.14.1. 安装配置 10.14.2. 访问控制列表(ACL) 10.14.3. 用户验证 10.14.4. XML处理 10.14.5. 文档 10.14.6. Plugin开发 10.14.7. About WiKi 10.15. 安装Trac服务器 10.16. 安装Subversion服务器 10.17. CUPS(Common UNIX Printing System) Debian的服务器应用范围也是很广的,支持各种网络服务器,如DNS、Sabma和Zope等。本章主要介绍在Debian系统下各种服务器的安装配置。 10.1. 在IBM X335服务器上安装Debian woody 3.0 硬件配置情况:一台IBM X335服务器,配置Intel Xeon 2.8G CPU,1G内存,两个36G硬盘(RAID 1),BroadCom bcm5700千兆网卡。软件配置:Debian woody stable 3.0,采用bootbf2.4.iso进行网络安装,安装步骤如下: 下载相关软件: bootbf2_4_iso.zip,到这里下载http://people.debian.org/~blade/boot-floppies/netinst-full-pre/。解压密码是:“Yes, I know that this data may be harmful!”。 LSI53C1030和bcm5700驱程,到这里下载2_4_20-modules_bin.zip。解压密码是:“Yes, I know that this data may be harmful!”。 把解压出来iso刻录成启动光盘,驱程用dd if=2_4_20-modules.bin of=/dev/fd0写到1.44M软盘上。 500)this.width=500'> 驱程需与Debian内核版本匹配才可驱动。 准备好软件后,就可开始安装。在光盘启动,出现boot:提示符后直接按回车载入安装程序,首先选择键盘。 接着安装程序提示检测不到硬盘,需加载驱动模块。这时插入驱程软盘,按回车,出现可加载模块列表,按顺序选择mptbase.o,mptscsih.o加载LSI53C1030驱动,注意,不能先加载mptscsih.o,否则加载不成功。接着可加载bcm5700.o网卡驱动模块,加载成功后退出。这时安装程序应该就可找到硬盘和网卡了。 加载完驱程后,首先进行硬盘分区和格式化工作。 配置网卡,因为需进行网络安装,所以网卡要在这里配置好。 配置系统模块,如没特别的设备,按默认就可以了。 开始安装基本系统,很快就完成,因为才安装几十兆的内容。 安装完基本系统后,就可设置系统启动配置,使系统可直接从硬盘启动,选择把lilo安装到MBR中。这时你也可做一张开机盘,以备进行故障恢复。 现在可重启服务器。如果启动成功,Debian会自动运行base-config进行系统始初配置。配置后,就可登录系统了。 由于默认安装的2.4.20内核不支持超线程技术和大内存,所以需重新编译内核。我以编译2.4.28内核为例说明,2.6内核的编译方法也是一样的。 安装内核编译所需的一些工具:# apt-get install kernel-package ncurses-dev fakeroot 到内核站点http://www.kernel.org下载最2.4.28内核原码包:# cd /usr/src# wget http://www.kernel.org/pub/linux/kernel/v2.4/linux-2.4.28.tar.bz2 下载完成后,就可解包和配置内核,配置内核前需了解清楚机器的硬件配置情况:# tar -xjf linux-2.4.28.tar.bz2# cd linux-2.4.28/# make menuconfig 配置内核时,我主要修改了三个内容 修改Processor type and features里有关CPU和内存的内容,把CPU类型从P3改为P4,支持4个CPU,支持4G内存; 选择Fusion MPT device support,把Fusion MPT(base+ScsiHost)drivers编译进内核。 选择Network device support,进入Ethernet(1000Mbit)类,把Broadcom Tigon3 support编译进内核。 我还把一些明确不需要的模块删除了,以精简内核,配置完成后存盘退出。你也可把配置的内核参数文件保存起来,以备以后重新编译内核时导入使用。 配置完内核后就可进行实质的编译工作了,按以下命令依次执行:# make dep# make-kpkg clean# fakeroot make-kpkg --revision=mykernel.1.0 kernel_image 如果在编译过程异常中止,我们需运行以下命令重新配置内核:# make clean# make menuconfig 内核编译完成后,就会在/usr/src目录下生成一个名为kernel-image-2.4.28_mykernel.1.0_i386.deb的内核安装包。我们用以下命令安装新内核:# dpkg -i kernel-image-2.4.28_mykernel.1.0_i386.deb 内核安装时,会把vmlinuz-2.4.28和System.map-2.4.20拷贝到/boot目录下。并有一些自动配置过程,包括制作启动盘和配置lilo启动信息。启动盘可做可不做,但lilo启动信息配置就不要做,我试过几次,如果做了系统就起不来了。我们可手动配置/etc/lilo.conf来实现多重内核启动。把以下信息添加到/etc/lilo.conf中:prompt #这句可使系统启动时出现内核选择菜单。timeout=100 #提供10秒的选择时延。...image=/boot/vmlinuz-2.4.28 label=Linux-2.4.28... 最后运行以下命令把引导信息写入MBR。# lilo -v -v -v 500)this.width=500'> 其实一个-v选项就可以了,多几个-v选项只是可多显示一些信息。 到现在为止,新内核的编译配置已全部完成,重启服务器,选择新内核引导系统。 2.6内核的编译过程和上面的一样。主要是配置内核时菜单会有些不同。在2.6内核中,模块是用module-init-tools来管理的,所以如果需加载模块,就要安装该工具。 10.2. 系统管理工具 Linux是一个开放的、高可配置的操作系统,一个合格的Linux系统管理员应该可支持不同应用环境的要求。下面介绍一些管理工具,可帮助我们了解系统状态和优化系统。 top top命令可实时地显示Linux系统的进程、CPU、内存、负载等的信息。它是我们了解系统整体状态最好的工具。top - 10:06:09 up 31 days, 2:14, 1 user, load average: 0.00, 0.00, 0.00Tasks: 47 total, 1 running, 46 sleeping, 0 stopped, 0 zombie Cpu0 : 0.0% us, 0.0% sy, 0.0% ni, 100.0% id, 0.0% wa, 0.0% hi, 0.0% si Cpu1 : 0.3% us, 0.0% sy, 0.0% ni, 99.7% id, 0.0% wa, 0.0% hi, 0.0% siMem: 1034732k total, 472336k used, 562396k free, 16460k buffersSwap: 1052248k total, 0k used, 1052248k free, 357940k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1 root 16 0 1504 480 1352 S 0.0 0.0 0:00.59 init 2 root RT 0 0 0 0 S 0.0 0.0 0:00.06 migration/0 3 root 34 19 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/0 4 root RT 0 0 0 0 S 0.0 0.0 0:00.04 migration/1 5 root 34 19 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/1 6 root 5 -10 0 0 0 S 0.0 0.0 0:00.00 events/0 7 root 5 -10 0 0 0 S 0.0 0.0 0:00.00 events/1 8 root 5 -10 0 0 0 S 0.0 0.0 0:00.00 khelper 9 root 5 -10 0 0 0 S 0.0 0.0 0:00.00 kblockd/0 10 root 5 -10 0 0 0 S 0.0 0.0 0:00.00 kblockd/1 11 root 17 0 0 0 0 S 0.0 0.0 0:00.00 khubd 38 root 15 0 0 0 0 S 0.0 0.0 0:00.00 pdflush 37 root 15 0 0 0 0 S 0.0 0.0 0:00.00 kirqd 41 root 6 -10 0 0 0 S 0.0 0.0 0:00.00 aio/0 40 root 16 0 0 0 0 S 0.0 0.0 0:00.00 kswapd0 42 root 5 -10 0 0 0 S 0.0 0.0 0:00.00 aio/1 top命令的运行状态是一个实时的显示过程,我们可在这个界面监控系统运行情况。我们可通过几个按键来控制top命令,如按q可退出top命令状态,按s可输入信息的更新频率等。这些命令可按h帮助键查询。如:Help for Interactive Commands - procps version 3.2.1Window 1:Def: Cumulative mode Off. System: Delay 3.0 secs; Secure mode Off. Z,B Global: 'Z' change color mappings; 'B' disable/enable bold l,t,m Toggle Summaries: 'l' load avg; 't' task/cpu stats; 'm' mem info 1,I Toggle SMP view: '1' single/separate states; 'I' Irix/Solaris mode f,o . Fields/Columns: 'f' add or remove; 'o' change display order F or O . Select sort field <,> . Move sort field: '<' next col left; '>' next col right R . Toggle normal/reverse sort c,i,S . Toggle: 'c' cmd name/line; 'i' idle tasks; 'S' cumulative time x,y . Toggle highlights: 'x' sort field; 'y' running tasks z,b . Toggle: 'z' color/mono; 'b' bold/reverse (only if 'x' or 'y') u . Show specific user only n or # . Set maximum tasks displayed k,r Manipulate tasks: 'k' kill; 'r' renice d or s Set update interval W Write configuration file q Quit ( commands shown with '.' require a visible task display window ) Press 'h' or '?' for help with Windows,any other key to continue ps ps命令可查询系统的进程状态,常用的命令参数是ps aux,该命令可显示所有用户的进程,如果进程的命令太长,则显示的进程信息会不全。我们可用ps auxw命令来加长显示,w参数可多加几个,最多可加三个,以显示更长的进程信息。debian:~# ps auxUSER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMANDroot 1 0.0 0.0 1416 448 ? S May24 0:06 init [3] root 2 0.0 0.0 0 0 ? SW May24 0:00 [keventd]root 3 0.0 0.0 0 0 ? SW May24 0:00 [keventd]root 4 0.0 0.0 0 0 ? SW May24 0:00 [keventd]root 5 0.0 0.0 0 0 ? SW May24 0:00 [keventd]root 6 0.0 0.0 0 0 ? SWN May24 0:11 [ksoftirqd_CPU0]root 7 0.0 0.0 0 0 ? SWN May24 0:11 [ksoftirqd_CPU1]root 8 0.0 0.0 0 0 ? SWN May24 0:10 [ksoftirqd_CPU2]root 9 0.0 0.0 0 0 ? SWN May24 0:10 [ksoftirqd_CPU3]root 10 0.0 0.0 0 0 ? SW May24 17:29 [kswapd]root 11 0.0 0.0 0 0 ? SW May24 0:00 [kreclaimd]root 12 0.0 0.0 0 0 ? SW May24 15:47 [bdflush]root 13 0.0 0.0 0 0 ? SW May24 0:00 [kupdated]root 14 0.0 0.0 0 0 ? SW May24 0:00 [mdrecoveryd]root 21 0.0 0.0 0 0 ? SW May24 0:00 [scsi_eh_2]root 24 0.0 0.0 0 0 ? SW May24 0:47 [kjournald]root 84 0.0 0.0 0 0 ? SW May24 0:00 [khubd]root 177 0.0 0.0 0 0 ? SW May24 0:59 [kjournald]root 178 0.0 0.0 0 0 ? SW May24 0:00 [kjournald]root 514 0.0 0.0 1476 600 ? S May24 0:06 syslogd -m 0 要显示进程树的依赖关系可用以下命令:debian:~# ps axufUSER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMANDroot 1 0.1 0.2 1944 648 ? S 07:59 0:02 init [5]root 2 0.0 0.0 0 0 ? SN 07:59 0:00 [ksoftirqd/0]root 3 0.0 0.0 0 0 ? S< 07:59 0:00 [events/0]root 4 0.0 0.0 0 0 ? S< 07:59 0:00 [khelper]root 5 0.0 0.0 0 0 ? S< 07:59 0:00 [kthread]root 7 0.0 0.0 0 0 ? S< 07:59 0:00 \_ [kacpid]root 73 0.0 0.0 0 0 ? S< 07:59 0:00 \_ [kblockd/0]root 76 0.0 0.0 0 0 ? S< 07:59 0:00 \_ [khubd]root 139 0.0 0.0 0 0 ? S 07:59 0:00 \_ [pdflush]root 140 0.0 0.0 0 0 ? S 07:59 0:00 \_ [pdflush]root 142 0.0 0.0 0 0 ? S< 07:59 0:00 \_ [aio/0]root 733 0.0 0.0 0 0 ? S< 07:59 0:00 \_ [kseriod]root 820 0.0 0.0 0 0 ? S< 07:59 0:00 \_ [exec-osm/0]root 141 0.0 0.0 0 0 ? S 07:59 0:00 [kswapd0]root 830 0.0 0.0 0 0 ? S 07:59 0:00 [kjournald]root 1402 0.0 0.1 1736 392 ? Ss 08:00 0:00 dhclient -e -pf /var/run/dhclient.eth0.pid -lroot 1409 0.0 0.4 6004 1272 ? Ss 08:00 0:00 /sbin/mount.smbfs //t02/yangjing /root/data -root 1420 0.0 0.0 0 0 ? S 08:00 0:00 [smbiod]root 1422 0.0 0.3 5936 1240 ? Ss 08:00 0:00 /sbin/mount.smbfs //t02/books /root/books -oroot 1633 0.0 0.1 1628 604 ? Ss 08:00 0:00 /sbin/syslogdroot 1639 0.0 0.1 1580 372 ? Ss 08:00 0:00 /sbin/klogd -xroot 1688 0.0 1.2 3788 3788 ? SLs 08:00 0:00 /usr/sbin/slmodemd --alsa -c CHINA modem:1root 1772 0.0 0.1 1572 560 ? Ss 08:00 0:00 /usr/sbin/acpid -c /etc/acpi/events -s /var/rroot 1791 0.0 6.7 24084 21076 ? S 08:00 0:00 /usr/lib/AntiVir/antivir --updater-daemonroot 1829 0.0 0.5 4532 1856 ? Ss 08:00 0:00 /usr/sbin/cupsd102 1836 0.0 0.2 2160 768 ? Ss 08:00 0:00 /usr/bin/dbus-daemon-1 --system109 1874 0.0 0.3 5372 1004 ? Ss 08:00 0:00 /usr/sbin/exim4 -bd -q30mroot 1886 0.0 0.1 1624 356 ? Ss 08:00 0:00 /usr/sbin/gpm -m /dev/input/mice -t exps2uucp 2005 0.0 0.4 4680 1388 ? Ss 08:00 0:00 /usr/sbin/faxquucp 2007 0.0 0.3 4360 1116 ? Ss 08:00 0:00 /usr/sbin/hfaxd -i 4559uucp 2024 0.0 0.6 4788 1948 ? S 08:00 0:00 /usr/sbin/faxgetty ttySL0root 2034 0.0 0.1 1748 552 ? Ss 08:00 0:00 /usr/sbin/inetddaemon 2099 0.0 0.1 1824 408 ? Ss 08:00 0:00 /usr/sbin/atdroot 2106 0.0 0.2 2188 876 ? Ss 08:00 0:00 /usr/sbin/cronroot 2148 0.0 0.0 1424 168 ? S 08:00 0:00 /usr/bin/vmnet-bridge -d /var/run/vmnet-bridgroot 2158 0.0 0.2 2644 636 ? Ss 08:00 0:00 /usr/bin/kdmroot 2162 1.6 4.1 33132 13004 tty7 S<s+ 08:00 0:19 \_ /usr/X11R6/bin/X -br -nolisten tcp :0 vt7root 2189 0.0 0.4 3628 1372 ? S 08:00 0:00 \_ -:0root 2216 0.0 0.3 4744 1232 ? Ss 08:01 0:00 \_ /bin/sh /usr/bin/startkderoot 2286 0.0 0.2 4472 708 ? Ss 08:01 0:00 \_ /usr/bin/ssh-agent /usr/bin/ssh-aroot 2287 0.0 0.2 4468 708 ? Ss 08:01 0:00 \_ /usr/bin/ssh-agent /usr/bin/startroot 2334 0.0 0.1 1560 336 ? S 08:01 0:00 \_ kwrapper ksmserver STAT栏表示进程的状态,共有以下几种: R-----运行中 S-----睡眠中 I-----停止 Z-----僵死 kill kill命令可终止进程,后接进程号即可。如我们可用上面的ps命令查出你想终止的进程的进程号为299,用kill 299则可把该进程终止。 kill命令一些常用参数说明。 -1或-HUP,中止进程,如果进程是系统服务,则进程会重载配置文件并重启。 -15或-TERM,中止进程,并清除无用的文件和进程。这是最优雅地中止进程的方式。 -9或-KILL,强行中止进程,这是最粗暴地中止进程的方式。 free free可显示系统的内存使用情况。-b、-k、-m三个参数表示以bytes,kilobytes和megabytes为单位显示内存的使用情况。debian:~# free -m total used free shared buffers cachedMem: 2010 2005 5 456 146 1150-/+ buffers/cache: 708 1301Swap: 2000 127 1872 vmstat 使用vmstat 2 命令可每隔2秒显示一行系统信息,这些信息包括CPU占用效、内存使用情况和磁盘IO等。通过它我们可实时监控系统的资源使用情况,进行系统优化。debian:~# vmstat 2 procs memory swap io system cpu r b w swpd free buff cache si so bi bo in cs us sy id 0 0 0 130804 6000 149744 1179340 0 0 0 1 1 2 0 0 2 0 0 0 130804 6000 149744 1179396 0 0 28 162 266 387 0 0 100 0 0 0 130804 6000 149744 1179472 0 0 30 110 222 280 0 0 99 1 0 0 130804 6000 149744 1179516 0 0 22 122 235 306 9 2 89 0 0 0 130804 6000 149748 1179580 0 0 24 148 373 469 10 1 90 1 0 0 130804 6000 149748 1179628 0 0 24 90 271 356 13 1 85 1 0 0 130804 6000 149748 1179700 0 0 28 118 263 322 23 2 76 0 0 0 130804 6000 149748 1179760 0 0 30 148 279 409 14 1 85 sar sar工具可帮我们收集动态的系统信息,它的参数很丰富,功能强大。sar工具的特点是可通过计数器和计数间隔来定期、定量地输出系统状态信息。如:debian:~# sar -b 2 1009时47分48 tps rtps wtps bread/s bwrtn/s09时47分50 23.50 3.50 20.00 28.00 176.0009时47分52 47.50 6.50 41.00 52.00 424.0009时47分54 28.50 4.50 24.00 36.00 204.0009时47分56 52.00 9.50 42.50 76.00 352.0009时47分58 30.50 5.00 25.50 40.00 216.0009时48分00 28.50 4.50 24.00 36.00 204.0009时48分02 32.00 3.50 28.50 28.00 412.0009时48分04 46.00 5.50 40.50 44.00 388.0009时48分06 26.00 5.00 21.00 40.00 196.0009时48分06 tps rtps wtps bread/s bwrtn/s09时48分08 35.00 5.00 30.00 40.00 264.00Average: 34.95 5.25 29.70 42.00 283.60 上面的命令表示隔2秒输出一条磁盘I/O信息,共输出10条。-b表示输出磁盘I/O信息,如果是-B则可输出paging信息,参数还很多,请用man sar查看。 watch watch命令可重复执行某个命令,监控命令的执行状态。下面这个命令可让我们监控Z2.log文件的大小变化。debian:~# watch -n 3 du /home/Jims/zope/log/Z2.log -n 3表示每隔3秒执行一次du /home/Jims/zope/log/Z2.log。 sysctl 使用sysctl -a可显示所有运行中的内核参数,用sysctl -w fs.file-max=10240 命令可修改fs.file-max内核参数的值,并使参数马上生效。但重启系统后,参数设置会失效,因为命令行只能修改运行中的内核参数。如果我们要把参数设置固定下来,可把内核参数写入/etc/sysctl.conf文件。该文件的格式如下:# /etc/sysctl.conf - Configuration file for setting system variables# See sysctl.conf (5) for information.# Controls IP packet forwardingnet.ipv4.ip_forward = 0# Controls source route verificationnet.ipv4.conf.default.rp_filter = 1# Controls the System Request debugging functionality of the kernelkernel.sysrq = 0# Controls whether core dumps will append the PID to the core filename.# Useful for debugging multi-threaded applications.kernel.core_uses_pid = 1 ulimit 使用ulimit -a可显示系统的资源限制情况。debian:~# ulimit -acore file size (blocks, -c) 0data seg size (kbytes, -d) unlimitedmax nice (-e) unlimitedfile size (blocks, -f) unlimitedpending signals (-i) unlimitedmax locked memory (kbytes, -l) unlimitedmax memory size (kbytes, -m) unlimitedopen files (-n) 1024 #最多可打开1024个文件pipe size (512 bytes, -p) 8 #管道的最大值POSIX message queues (bytes, -q) unlimitedmax rt priority (-r) unlimitedstack size (kbytes, -s) 8192 #堆栈的最大值cpu time (seconds, -t) unlimitedmax user processes (-u) unlimitedvirtual memory (kbytes, -v) unlimitedfile locks (-x) unlimited lsof 显示打开的文件,可按用户(lsof -u userid),按程序(lsof -c program)显示,下面的命令显示yangjing用户打开的文件。debian:~# lsof -u yangjingCOMMAND PID USER FD TYPE DEVICE SIZE NODE NAMEsu 2492 yangjing cwd DIR 3,3 4096 585622 /home/yangjingsu 2492 yangjing rtd DIR 3,3 4096 2 /su 2492 yangjing txt REG 3,3 27000 536692 /bin/su.... netstat netstat -nal可显示所有的网络连接。debian:~# netstat -nalActive Internet connections (servers and established)Proto Recv-Q Send-Q Local Address Foreign Address Statetcp 0 0 0.0.0.0:37 0.0.0.0:* LISTENtcp 0 0 0.0.0.0:9 0.0.0.0:* LISTENtcp 0 0 0.0.0.0:8010 0.0.0.0:* LISTENtcp 0 0 0.0.0.0:13 0.0.0.0:* LISTENtcp 0 0 0.0.0.0:4559 0.0.0.0:* LISTENtcp 0 0 127.0.0.1:631 0.0.0.0:* LISTENtcp 0 0 0.0.0.0:25 0.0.0.0:* LISTENtcp 0 0 192.168.6.195:38238 192.168.3.2:22 ESTABLISHEDtcp 0 0 192.168.6.195:36031 192.168.3.4:5222 ESTABLISHEDtcp 0 0 192.168.6.195:41702 192.168.3.2:445 ESTABLISHEDtcp 0 0 192.168.6.195:41703 192.168.3.2:445 ESTABLISHEDudp 0 0 0.0.0.0:9 0.0.0.0:*udp 0 0 0.0.0.0:68 0.0.0.0:*udp 0 0 0.0.0.0:8010 0.0.0.0:*udp 0 0 0.0.0.0:631 0.0.0.0:*Active UNIX domain sockets (servers and established)Proto RefCnt Flags Type State I-Node Pathunix 2 [ ACC ] STREAM LISTENING 2856 @/tmp/fam-root-unix 2 [ ACC ] STREAM LISTENING 3177 /tmp/orbit-root/linc-932-0-2094001684ddbunix 2 [ ACC ] STREAM LISTENING 3243 /tmp/orbit-root/linc-940-0-1af7207c191daunix 2 [ ACC ] STREAM LISTENING 2621 /tmp/.X11-unix/X0unix 2 [ ACC ] STREAM LISTENING 6049 /tmp/orbit-root/linc-d04-0-5643868fdcf06unix 2 [ ACC ] STREAM LISTENING 2742 /tmp/ssh-GdGZSq2216/agent.2216unix 2 [ ACC ] STREAM LISTENING 2745 /tmp/ssh-qKCByg2216/agent.2216unix 2 [ ACC ] STREAM LISTENING 2787 /tmp/ksocket-root/kdeinit__0unix 2 [ ACC ] STREAM LISTENING 2789 /tmp/ksocket-root/kdeinit-:0unix 2 [ ACC ] STREAM LISTENING 2800 /tmp/.ICE-unix/dcop2319-1158105681... df df可以按文件系统显示磁盘的使用情况,如果带-h参数,则可以k,M,G这种直观的计量单位显示磁盘容量。debian:~# df -h文件系统 容量 已用 可用 已用% 挂载点/dev/hda3 9.4G 8.2G 742M 92% /devshm 153M 0 153M 0% /dev/shm//t02/yangjing 29G 26G 3.0G 90% /root/data//t02/books 236G 189G 47G 81% /root/books/dev/hda1 8.7G 7.5G 753M 92% /mnt/hda1 du du可以按目录显示每个文件使用磁盘大小的情况,同样也可带-h参数,-c参数还可显示统计值。debian:~# du -hc python8.0K python/pdb12K python/zope332K python32K 总计 pppstats 使用pppstats可得到ppp连接的状态信息。 10.3. Apache2 Apache是Internet上应用最广的Web Server。Apache2是Apache1.x的升级版本,集成了大量最新的技术。 10.3.1. 虚拟主机 Listen 80Listen 8000<VirtualHost *:80> ServerName www.example1.com DocumentRoot /var/www/example1</VirtualHost><VirtualHost *:8000> ServerName www.example2.com DocumentRoot /var/www/example2</VirtualHost> 虚拟主机中的端口号需与Listen中定义的端口号对应。在Listen中定义过的监听端口才能在VirtualHost中使用。 10.3.2. 性能调整 /etc/apache2/apache2.conf文件<IfModule prefork.c>StartServers 10MinSpareServers 10MaxSpareServers 15ServerLimit 2000MaxClients 1000MaxRequestsPerChild 10000</IfModule> 10.3.3. 安全 隐藏服务器版本信息## ServerTokens# This directive configures what you return as the Server HTTP response# Header. The default is 'Full' which sends information about the OS-Type# and compiled in modules.# Set to one of: Full | OS | Minor | Minimal | Major | Prod# where Full conveys the most information, and Prod the least.#ServerTokens Prod## Optionally add a line containing the server version and virtual host# name to server-generated pages (internal error documents, FTP directory# listings, mod_status and mod_info output etc., but not CGI generated# documents or custom error documents).# Set to "EMail" to also include a mailto: link to the ServerAdmin.# Set to one of: On | Off | EMail#ServerSignature Off 10.4. Exim4邮件服务器 10.4.1. 邮件系统基础知识 在实现安装邮件服务器之前,让我们先来学习一些邮件系统的基础知识。 一个完整的邮件系统应该包含三部份内容:邮件用户代理(MUA,Mail User Agent),邮件传送代理(MTA,Mail Transport Agent)和邮件分发代理(MDA,Mail Deliver Agent)。 MUA是mail、pine、mutt等程序,负责查看邮件、编写邮件和向MTA发送邮件。 MTA是sendmail,postfix,qmail和Exim等服务器,负责邮件在Internet中的传递,从一个MTA服务器发送到另一个MTA服务器。当一个MTA收到一封从另一个MTA传递过来的邮件时,如果邮件中的域名地址和本机域名地址一样,则MTA会把邮件收下来,保存在MTA的接收邮件队列中。如果邮件的域名地址与本机的不一样,则会根据域名进行转发,这个过程在mail系统中叫做relay。 MDA是procmail等程序,负责从MTA中收取邮件,并根据用户名保存到用户邮箱。 smtp和pop3是邮件系统中重要的一对协议,smtp用于发送邮件,pop3用于接收邮件。下面分别介绍它们的命令。POP3 命令包括:USER username 认证用户名PASS password 认证密码认证,认证通过则状态转换APOP name,digest 认可一种安全传输口令的办法,执行成功导致状态转换,请参见 RFC 1321 。STAT 处理请求 server 回送邮箱统计资料,如邮件数、 邮件总字节数UIDL n 处理 server 返回用于该指定邮件的唯一标识, 如果没有指定,返回所有的。LIST n 处理 server 返回指定邮件的大小等RETR n 处理 server 返回邮件的全部文本DELE n 处理 server 标记删除,QUIT 命令执行时才真正删除RSET 处理撤消所有的 DELE 命令TOP n,m 处理 返回 n 号邮件的前 m 行内容,m 必须是自然数NOOP 处理 server 返回一个肯定的响应QUIT 希望结束会话。如果 server 处于"处理" 状态,则现在进入"更新"状态,删除那些标记成删除的邮件。如果 server 处于"认可"状态,则结束会话时 server 不进入"更新"状态 。SMTP 命令包括:HELO 向服务器标识用户身份。发送者能欺骗,说谎,但一般情况下服务器都能检测到。EHLO 向服务器标识用户身份。发送者能欺骗,说谎,但一般情况下服务器都能检测到。MAIL FROM 命令中指定的地址是发件人地址RCPT TO 标识单个的邮件接收人;可有多个 RCPT TO;常在 MAIL 命令后面。DATA 在单个或多个 RCPT 命令后,表示所有的邮件接收人已标识,并初始化数据传输,以 CRLF.CRLF 结束VRFY 用于验证指定的用户/邮箱是否存在;由于安全方面的原因,服务器常禁止此命令EXPN 验证给定的邮箱列表是否存在,扩充邮箱列表,也常被禁用HELP 查询服务器支持什么命令NOOP 无操作,服务器应响应 OKRSET 重置会话,当前传输被取消QUIT 结束会话 10.4.2. Exim4邮件服务器的工作原理 Exim4被设计成能高效地、不间断地在Internet上运行,而且能处理各种混合邮件。Exim4是如何投递邮件和接收邮件的呢?有何安全机制能确保邮件的安全呢?这节将简单介绍Exim4的工作原理。 Exim4处理的每封邮件都以一个16位字符的名称标识,该标识由三部份组成,以"-"号分隔,如:1GS3YU-0000zG-Nd。这些字符是经过base编码的,第一部份的原始信息是接收邮件的时间,第二部份的原始信息是接收邮件的进程id,第三部份的信息与配置文件中localhost_number的设置相关。标识名与时间和进程相关,有效保证了标识名的唯一性。 Exim4通过基于TCP/IP的SMTP协议从其它主机收取邮件。Exim4接收邮件后,会把邮件分成两个文件保存在spool目录,在我的机器上就是/var/spool/exim4/input/目录。这两个文件的命名规则是邮件标识后加-D和-H。以-D结尾的文件保存着邮件正文的信息,以-H结尾的文件保存邮件的头信息。在一些操作系统上,同一目录下包含太多的文件会造成性能问题,所以Exim4也可通过设置split_spool_directory选项,在input目录下再创建62个子目录来保存邮件信息。这62个子目录以单个字母和数字命名(26个小写字母+26个大写字母+10个数字共62个数字和字母)。这样的设置,使邮件的排队只在子目录下进行,而不是一个目录所有邮件。所以即使在邮件量不大的情况下也能效提升邮件系统的性能。 接收的邮件会停留在spool目录直到邮件被传递到接收者或被管理员删除。如果邮件不能被传递,则邮件会被打上"frozen"标记,并且不会再尝试投递该邮件。但管理员可以设置ignore_bounce_errors_after和timeout_frozen_after选项,指定一定时间后解除邮件的"frozen"状态。 当Exim4处理邮件时会把处理过程的日志信息保存在/var/log/exim4目录下。其中mainlog日志记录了大量的信息,从中我们可以跟踪Exim4处理邮件的过程。在一个大负载的服务器上,生成大量的日志信息会影响服务器的性能,所以我们也可以用no_message_logs参数禁止日志功能。 router和transport是Exim4传递邮件过程中两个重要的环节,router负责处理邮件地址,并把邮件传递给不同的transport作进一步处理,transport负责把spool中的邮件传递到目的地,完成投递过程。有两种的transport,一种是本地transport,它的目的地是文件或者本机管道(pipe);另一种transport是远程transport,它的目的地是远程主机。如果一封邮件有多个接收者,则它可能会通过多个transport进行投递。 router和transport都有不同的driver,实现不同的功能。 router drivers: accept, dnslookup, ipliteral, iplookup, manualroute, queryprogram, redirect, transport drivers: appendfile, autoreply, lmtp, pipe smtp 10.4.3. 安装与配置 用以下命令安装exim4邮件系统:debian:#~ apt-get install exim4 exim4-config exim4-daemon-light 下载完成后会自动运行配置向导,我们也可运行dpkg-reconfigure exim4-confg命令配置Exim4服务器。exim4的配置文件位于/etc/exim4目录下,update-exim4.conf.conf文件的配置内容由上面的命令产生,经常改变的命令都集中在这里,而exim4.conf.template文件是Exim4的主配置文件,里面通过DEBCONFsomethingDEBCONF的方式引用update-exim4.conf.conf文档的something内容。 exim4.conf.template是Exim4的配置文件,它以分段的格式组织各配置参数。一般的配置参数放在配置文件的最开头,其它所有的可选配置参数都以"beging+段名"的形式作为段的开始标识。下面是一些可选段: ACL,设置SMTP邮件的ACL(访问控制列表)。 authenticators,设置验证模式。 routers,设置不同的router,处理不同类型的邮件地址,并确定如何发送邮件。 transports,设置不同的transport,把信息传递到不同的目的地。 retry,设置重试的规则,当邮件不能马上投递时,我们可设置一些重试规则进行再次投递。 rewrite,定义邮件地址的重写规则。 local_scan,使用local_scan()函数的功能。要用LOCAL_SCAN_HAS_OPTIONS=yes选项开启。 exim4的配置文件有两种方式,一种是集中式的,所有的配置都集中在exim4.conf.template文件中,一种是分散式的,配置文件按功能不同分散成很多个文件存放在conf.d目录下。一般建议新手使用集中式。 下面是一个update-exim4.conf.conf的示例,它可通过debconf程序自动生成,生成后我们可用文本编辑器来修改它。这个示例把exim4配置成通过网上的smarthost来发送Internet邮件。# /etc/exim4/update-exim4.conf.conf## Edit this file and /etc/mailname by hand and execute update-exim4.conf# yourself or use 'dpkg-reconfigure exim4-config'## Please note that this is _not_ a dpkg-conffile and that automatic changes# to this file might happen. The code handling this will honor your local# changes, so this is usually fine, but will break local schemes that mess# around with multiple versions of the file.## update-exim4.conf uses this file to determine variable values to replace# the DEBCONFsomethingDEBCONF strings in the configuration template files.## Most settings found in here do have corresponding questions in the# Debconf configuration, but not all of them.## This is a Debian specific filedc_eximconfig_configtype='smarthost' #用smarthost发信;通过SMTP或fetchmail接收信件dc_other_hostnames=''dc_local_interfaces='127.0.0.1' #只接收本机的SMTP请求,只在本机使用Exim4dc_readhost=''dc_relay_domains=''dc_minimaldns='false'dc_relay_nets=''dc_smarthost='smtp.21cn.com' #远程的SMTP主机,我们通过它来发送邮件CFILEMODE='644'dc_use_split_config='false' #不使用分散方式的配置文件dc_hide_mailname='false'dc_mailname_in_oh='true' 编辑/etc/mailname文档,该文档记录你所发邮件的域名后缀。我的mailname只有一条记录,内容如下:debian 运行update-exim4.conf命令可以测试/etc/exim4下的配置文件有没有语法错误,如果正常则会生成一个有效简洁的配置文件备份,保存在/var/lib/exim4/config.autogenerated文件中,方便我们查看。 用以下命令还可测试Exim4的配置有否出错:debian:#~ exim4 -bVExim version 4.63 #1 built 23-Aug-2006 17:21:47Copyright (c) University of Cambridge 2006Berkeley DB: Sleepycat Software: Berkeley DB 4.3.29: (September 6, 2005)Support for: crypteq iconv() IPv6 GnuTLS move_frozen_messagesLookups: lsearch wildlsearch nwildlsearch iplsearch cdb dbm dbmnz dsearch nis nis0 passwdAuthenticators: cram_md5 plaintextRouters: accept dnslookup ipliteral manualroute queryprogram redirectTransports: appendfile/maildir/mailstore autoreply lmtp pipe smtpFixed never_users: 0Size of off_t: 8Configuration file is /var/lib/exim4/config.autogenerated 启动exim4ebian:/etc/init.d# ./exim4 restartStopping MTA for restart: exim4_listener.Restarting MTA: exim4. 本地邮件发送测试:debian:~# exim4 -bt faxR: system_aliases for fax@debianR: userforward for fax@debianR: procmail for fax@debianR: maildrop for fax@debianR: local_user for fax@debianfax@debian router = local_user, transport = maildir_home 外部邮件发送测试:debian:#~ exim4 -bt jims.yang@gmail.comR: smarthost for jims.yang@gmail.comjims.yang@gmail.com router = smarthost, transport = remote_smtp_smarthost host smtp.cdn.21cn.com [202.104.32.230] 测试通过后,我们就可正式发送邮件啦。为了清楚显示邮件的传送过程,我们使用了-v参数。fax是我系统上的一个用户,主机名为debian,所以fax用户的本机邮件地址就是fax@debian。debian:~# exim4 -v fax@debianfrom:rootto:fax@debiansubject:local mail testtest will be ok..LOG: MAIN <= yjnet@21cn.com U=root P=local S=318debian:~# delivering 1GQemL-0001eD-PqR: system_aliases for fax@debianR: userforward for fax@debianR: procmail for fax@debianR: maildrop for fax@debianR: local_user for fax@debianT: maildir_home for fax@debianLOG: MAIN => fax <fax@debian> R=local_user T=maildir_homeLOG: MAIN Completed 出现Completed说明邮件已发送成功,切换到fax用户我们就可以收到新的邮件啦。下面我们来试试发送Internet。在正式测试之前,我们还要做一些配置。因为通过smtp.21cn.com发送邮件是要经过用户验证的。 把登录smtp.21cn.com的用户名和密码写入/etc/exim4/passwd.client文档。# password file used when the local exim is authenticating to a remote# host as a client.## see passwd_client(5) for more documentation## Example:### target.mail.server.example:login:passwordsmtp.cdn.21cn.com:yjnet:1234 smtp.cdn.21cn.com是真正的stmp服务器名,而smtp.21cn.com是别名。在这里一定要用真正的smtp服务器名,否则验证不通过。如何知道真正的smtp服务器名呢?很简单,用我们最常用的ping命令即可。debian:~# ping smtp.21cn.comPING smtp.cdn.21cn.com (202.104.32.230): 56 data bytes yjnet是登录用户名,1234是登录密码。 把系统用户对应的外部邮件地址写入/etc/exim4/email-addresses文件。# This is /etc/email-addresses. It is part of the exim package## This file contains email addresses to use for outgoing mail. Any local# part not in here will be qualified by the system domain as normal.## It should contain lines of the form:##user: someone@isp.com#otheruser: someoneelse@anotherisp.comroot:yjnet@21cn.com 这里的外网邮件用户名yjnet要与passwd.client中的登录用户名yjnet一致。如果不一致,会造成个别mail client不能正常发送邮件。 exim4默认是不使用明文的验证方式的,因为明文的密码很容易在网上被截取。但smtp.cdn.21cn.com是使用明文验证的,所以我们要打开exim4的明文验证模式。修改/etc/exim4/exim4.conf.template,加入AUTH_CLIENT_ALLOW_NOTLS_PASSWORDS = 1配置参数。添加参数时要注意,一定要把该参数放到本配置小节的最开头,这样在后面才能有效引用该参数。####################################################################### AUTHENTICATION CONFIGURATION #######################################################################begin authenticators....# Because AUTH PLAIN and AUTH LOGIN send the password in clear, we# only allow these mechanisms over encrypted connections by default.# You can set AUTH_CLIENT_ALLOW_NOTLS_PASSWORDS to allow unencrypted# clear text password authentication on all connections.AUTH_CLIENT_ALLOW_NOTLS_PASSWORDS = 1.... 配置完成要重启exim4服务器使配置生效。下面我们就可测试用smtp.21cn.com服务器发邮件啦。debian:~# exim4 -v jims.yang@gmail.comfrom:yjnet@21cn.comto:jims.yang@gmail.comsubject:test from exim4测试邮件正文。.LOG: MAIN <= yjnet@21cn.com U=root P=local S=327debian:~# delivering 1GQfnH-0001hE-PYR: smarthost for jims.yang@gmail.comT: remote_smtp_smarthost for jims.yang@gmail.comConnecting to smtp.cdn.21cn.com [202.104.32.230]:25 ... connected SMTP<< 220 21cn.com SMTP Server 5 of AIMC 2.9.5.2 (DELAYED). SMTP>> EHLO debian SMTP<< 250-21cn.com, helo (DELAYED) 250-EXPN 250-HELP 250-8BITMIME 250-AUTH=LOGIN PLAIN 250-AUTH LOGIN PLAIN 250 XTMD SMTP>> AUTH PLAIN **************** SMTP<< 504 Unknown authentication mechanismLOG: MAIN plain authenticator failed H=smtp.cdn.21cn.com [202.104.32.230] 504 Unknown authentication mechanism SMTP>> AUTH LOGIN SMTP<< 334 VXNlcm5hbWU6 SMTP>> ******** SMTP<< 334 UGFzc3dvcmQ6 SMTP>> ******** SMTP<< 235 OK Authenticated SMTP>> MAIL FROM:<yjnet@21cn.com> AUTH=root@debian SMTP<< 250 Ok SMTP>> RCPT TO:<jims.yang@gmail.com> SMTP<< 250 User <jims.yang@gmail.com> is not local, will forward to <64.233.167.114:25>. SMTP>> DATA SMTP<< 354 Start mail input; end with <CRLF>.<CRLF> SMTP>> writing message and terminating "." SMTP<< 250 Requested mail action okay, completed. Message-ID=<E1GQfnH-0001hE-PY@debian> SMTP>> QUITLOG: MAIN => jims.yang@gmail.com R=smarthost T=remote_smtp_smarthost H=smtp.cdn.21cn.com [202.104.32.230]LOG: MAIN Completed 成功发送。


阅读全文(4320) | 回复(-1) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 1.185 second(s), page refreshed 144808593 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号