Gentoo Linux建站全攻略
站长空间
随着社会的发展,网络对人们的影响越来越深。为了能够适应网络对服务器的要求,越来越多的网络管理人员开始使用linux建立服务器。那么,在名目众多的linux操作系统中,哪一个版本将最终成为时代宠儿呢?Gentoo linux!
Gentoo的发展和组织是一帆风顺的。作为一个崭新的、并在较短的时间内便赢得了业界和用户认同的Linux项目。它快速、设计干净而有弹性,是一个现代模式的发行版。下面让我们一起走近Gentoo,共同学习一下使用Gentoo linux 建立服务器。
本文实现功能包括:外部DNS服务、FTP服务、WEB服务、邮件服务安装配置指南。
硬件环境:
P4计算机,双网卡,由于Linux对于板卡的驱动是针对芯片的,所以为了减少麻烦本文采用了不同芯片的网卡:D-Link 530、RTL 8139,为了减轻服务器负载,本文并没有安装X系统,所以显卡的好坏也无所谓。
系统、软件环境:
操作系统:Gentoo Linux 2004-01,内核为Gentoo-dev-sources
IP配置列表:

1.外部DNS服务
小知识:什么叫做DNS.
域名管理系统DNS(Domain Name System)是域名解析服务器的意思.它在互联网的作用是:把域名转换成为网络可以识别的IP地址。比如:我们上网时输入的www.163.com会自动转换成为202.108.42.72。
对于有固定公网IP的用户来说,如果能到本地ISP去注册一个域名是最好的选择,但是为了降低企业组网的成本,笔者采用了免费的二级域名来为企业服务。具体过程为:
首先到 www.3322.org 申请一个静态域名(如eserver.3322.org), 然后下载Linux平台客户端。
假设下载的文件存放到/tmp下,安装源码:
tar zxvf /tmp/ez-ipupdate-3.0.10-linux-i386.tgz
cp -Rf /tmp/ez-ipupdate /usr/local/3322
此时,已将域名解析所需的文件全部安装到/usr/local/3322下。修改其中唯一的配置文件qdns.conf为如下内容:
#!/usr/local/bin/ez-ipupdate -c
## example config file for ez-ipupdate
# this file is actually executable!
#下面动态域名和静态域名选一个
#动态域名
service-type=qdns
#静态域名
#service-type=qdns-static
#设置你在3322.org上注册的用户名和密码
user=user:password
#你需要更新的域名
host=eserver.3322.org
#你的网络端口,用于连接外网的网卡端口,即eth0。
interface=eth0
保存配置文件,然后使用www.3322.org解析域名:http://romlinux.3322.org,源码为:/usr/local/3322/ez-ipupdate /usr/local/3322/qdns.conf
解析成功后,ping http://romlinux.3322.org就会指向服务器的Eth0 的IP。
2.FTP服务
小知识:FTP (File Transfer Protocol) 的意思是:
文件传输协议。是在TCP/IP环境中传输文件的一个协议。通常是客户机上的用户从远程服务器上卸下文件。FTP是每个TCP/IP系统的核心组成部分,在相对于OSI协议模型的应用层实现。它的操作基于Telnet程序和TCP协议。FTP在许多计算机系统上采用,是系统间文件传输的公共协议。也就是我们平时下载东东的服务器,建立完成后,就可以让朋友们从你的电脑上下载他们需要的东东了。
安装过程为:
1) 安装Proftpd,源码为:
emerge proftpd
2) 修改Proftpd的配置文件为如下内容:
ServerName "ProFTPD Default Installation"
ServerType standalone
DefaultServer on
Port 21
Umask 022
MaxInstances 10
# Set the user and group under which the server will run.
User ftp
Group ftp
# To cause every FTP user to be "jailed" (chrooted) into their home
# directory, uncomment this line.
DefaultRoot ~ //将用户限制在自己的目录内
# Normally, we want files to be overwriteable.
#<Directory />
# AllowOverwrite on
#</Directory>
// 下面是配置一个匿名登录服务
<Anonymous ~ftp>
User ftp
Group ftp
UserAlias anonymous ftp
MaxClients 50
DisplayLogin welcome.msg
DisplayFirstChdir .message
<Limit WRITE>
DenyAll
</Limit>
<Directory incoming/*> //设置incoming目录为可写
<Limit READ>
AllowAll
</Limit>
<Limit WRITE>
AllowAll
</Limit>
<Limit STOR>
AllowAll
</Limit>
</Directory>
</Anonymous>
然后建立可写目录和下载目录:
Mkdir /home/ftp/incoming
Mkdir /home/ftp/pub
启动 proftpd
/etc/init.d/proftpd start
rc-update add proftpd default // 将 proftpd 加入启动级
到此,一个具有最简功能的FTP服务器已经打造成功。其目录为:/home/ftp。对于其下的incoming目录可上传,但不能下载,pub目录只可下载,不能上传。
现在用你的ftp客户端(如 ncftp,ftp,gftp)登录ftp://eserver.3322.org。
注意:由于采用的是系统用户登录,只要你拥有系统用户,就可以登录到此FTP。其目录为/home/username,权限为可写。
3.WEB服务
小知识:WEB服务器也称为WWW(WORLD WIDE WEB)服务器,主要功能是提供网上信息浏览服务。(1)应用层使用HTTP协议。(2)HTML文档格式。(3)浏览器统一资源定位器(URL)。例如,我们经常上的www.cpcw.com,就是利用WEB服务搭建起来的网站。安装了此项服务之后,就可以在自己的电脑上建立网站,来让别人访问了。
1) 安装配置 Mysql,源码为:
emerge mysql
// 安装完毕后进行必要的配置:
ebuild /var/db/pkg/dev-db/mysql-x.x.xx/mysql-x.x.xx.ebuild config // 初始化数据库
/etc/init.d/mysql start // 启动mysql进程
rc-update add mysql default // 将mysql加入启动级
2) 安装Apache2、PHP,源码为:
USE="mysql apache2 -qt -qtmt -pdflib" emerge mod_php apache
/etc/init.d/apache2 start // 启动apache2进程
rc-update add apache2 default // 将apache2加入启动级
3) 配置 Apache2,编辑/etc/conf.d/apache加入对PHP和SSL的支持:
APACHE2_OPTS="-D SSL -D PHP4"
4) 修改 /etc/apache2/conf/apache2.conf :
ServerName romlinux.3322.org // 我的ServerName
5) 修改 /etc/apache2/conf/commonapache2.conf:
ServerAdmin webmaster@localhost // 管理员Mail地址
DirectoryIndex index.php // 第一个请求页名字
AddDefaultCharset gb2312 // 将默认编码改为中文
// 确保/etc/hostname 中为你的ServerName
6) 测试WEB服务:打开浏览器输入地址http://localhost或http://yourServerName,看到画面表示apache2安装成功
测试PHP:在/var/www/localhost/htdocs中编辑一文件phpinfo.php,内容如下:
<?php phpinfo(); ?>
然后在浏览器地址栏中输入 http://localhost/phpinfo.php,如果显示PHP的相关信息,则表示 PHP 安装配置成功。
4.邮件服务
小知识:什么是邮件服务器呢?
邮件服务器提供了邮件系统的基本结构,包括邮件传输、邮件分发、邮件存储等功能,以确保邮件能够发送到Internet网络中的任意地方。目前邮件服务器有两种不同的应用群体:ISP提供商和企事业单位。电子邮件是Internet应用服务之一,通过网络,可以以非常低廉的价格、非常快速的方式,与世界上任何一个网络用户联络,这些电子邮件可以包含文字、图像、声音或其他多媒体信息。
安装过程为:
1) 安装配置Postfix,源码为:
emerge postfix mutt
2) 然后对postfix进行必要的配置,修改/etc/postfix/main.cf中如下内容:
myhostname = $eserver.3322.org //这是我的域名
mydomain = $3322.org // 这里填3322.org
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain $mydomain
mynetworks = my.ip.net.work/24, 127.0.0.0/8
home_mailbox = .maildir/
local_destination_concurrency_limit = 2
default_destination_concurrency_limit = 10
3) 修改/etc/postfix/master.cf如下:
# service type private unpriv chroot wakeup maxproc command + args
# (yes) (yes) (yes) (never) (50)
#
=========================================================
smtp inet n - n - - smtpd -v
// 只要在smtpd后面添加 -v
4) 下面修改 /etc/mail/aliases 加入你的alias,使其中至少有一项为:
root: your@email.address。
然后执行:
/usr/bin/newaliases // 让新的别名生效
/etc/init.d/postfix start // 启动postfix进程
rc-update add postfix default // 将postfix加入启动级
5) 测试邮件系统:由root给系统其他用户(如user)发一封邮件
mutt -x user
Subject: check postfix // 邮件主题
(End message with a . on a line by itself)
How are u? // 输入邮件正文
. // 键入一个 . 结束输入,发送邮件
以用户user登录,键入mutt会提示你 .maildir不存在是否建立,键入yes,如果看到刚才root发来的邮件表示postfix运行正常。
6) 安装配置Courier-imap,源码为:
emerge courier-imap
对Courier-imap进行必要的配置,源码为:
cd /etc/courier-imap
// 如果你要开启courier-imap或pop3的ssl ,你要生成cert文件,
// 如果你不想可以跳过下面一步。
nano -w pop3d.cnf
nano -w imapd.cnf
// 修改上述两个文件中的 C, ST, L, CN, 和email参数。
mkpop3dcert
mkimapdcert
7) 启动 courier 相关服务,源码为:
/etc/init.d/courier-imapd start
/etc/init.d/courier-imapd-ssl start
/etc/init.d/courier-pop3d start
/etc/init.d/courier-pop3d-ssl start
将courier加入启动级,源码为:
rc-update add courier-imap default
rc-update add courier-imap-ssl default
rc-update add courier-pop3 default
rc-update add courier-pop3-ssl default
8) 安装配置 Fetchmail,源码为:
emerge fetchmail
/etc/init.d/fetchmail start // 启动fetchmail进程
rc-update add fetchmail default // 将fetchmail加入启动级
用fetchmail可以将你的远端 POP3 邮件服务器上的邮件收取到本地用户邮件中。配置fetchmail,主要是配置/etc/fetchmailrc,注意要把fetchmailrc的权限设为700,不然账户密码会被别人偷看。源码为:
defaults
proto pop3
poll sina // 账户名
proto pop3 // POP3协议
via pop3.sina.com.cn // 远端POP3服务器地址
user "loginname" // 用户名
pass "password" // 登录密码
is localuser // 收取邮件的本地用户名,邮件会收取到该用户的~/.maildir邮箱中
fetchall // 不保留远端邮件复本
9) 安装配置 SquirrelMail,源码为:
emerge squirrelmail
开始配置 SquirrelMail,源码为:
cd /var/www/localhost/htdocs/squirrelmail
./configure
修改内容,源码为:
1. Organization Preferences ->> Organization Name (你的主机名),Default Language (zh_CN)。
2. Server Settings ->> Domain (你的domainname,要与postfix中的设置一致)。
3. IMAP Settings ->> IMAP Server (localhost),Authentication type (llogin),Server software (courier)。
4. General Options ->> Default Charset (gb2312)。
给squirrelmail做个链接,源码为:
cd /var/www/localhost/htdocs
ln -s squirrelmail mail
在浏览器中键入地址http://localhost/mail/就能看到如下面的SquirrelMail登录画面,用root或其他系统用户登录。
现在我们就可以使用SquirrelMail代替mutt来收发邮件了,实现了在图形界面下收发电子邮件了。