项目实战

某公司新购四台Dell R710服务器,购买域名xk.com。

一.目前想实现以下服务:

官网服务:www.xk.com

邮件服务:mail.xk.com

文件服务:ftp.xk.com

系统规划:CentOS 5.10

二.项目环境及IP规划:

1.跳板机一台:

   域名:moni01.xk.com  IP:192.168.13.253/24

   实现服务:dns1.xk.com    网络内主DNS

           ntp.xk.com       作为时间服务器,为整个网络主机同步时间

        ftp.xk.com   提供yum源及公共资源下载

2.WEB服务器两台,实现WEB服务:

   web01.xk.con      IP:192.168.13.10/24 提供静态网站服务

   web01.xk.com      IP:192.168.13.11/24 提供静态网站服务

3.邮件服务器一台:

   域名:mail01.xk.com    IP:192.168.13.251/24

   实现服务:mail.xk.com  提供邮件服务,允许公司人员通过web收发邮件

           dns2.xk.com  从DNS服务

           nfs.xk.com     提供公共区域共享,作为WEB服务器的网站根目录

三.环境部署搭建

1.基础环境搭建:

创建普通账户:

[root@moni01 ~]# useradd -u 801 yeyue

[root@moni01 ~]# groupadd -g 800 tarena

[root@moni01 ~]# usermod -g 800 yeyue

[root@moni01 ~]# tail -1 /etc/passwd

yeyue:x:801:800::/home/yeyue:/bin/bash

网络配置(以跳板机为例):

IP配置

[root@moni01 ~]# ifconfig |head -2 |tail -1

          inetaddr:192.168.13.253 Bcast:192.168.13.255 Mask:255.255.255.0

主机名域设置,网关设置(其他三台服务器需添加网关指向跳板机)

[root@moni01 ~]# tail -2 /etc/sysconfig/network

HOSTNAME=moni01.xk.com

DNS设置

[root@moni01 ~]# cat /etc/resolv.conf

search xk.com

nameserver 192.168.13.253

nameserver 192.168.13.251

ssh禁止直接通过root登录:

[root@moni01 ~]# vim /etc/ssh/sshd_config

 39 PermitRootLogin no

[root@moni01 ~]# service sshd restart

[root@moni01 ~]# chkconfig sshd on

2.跳板机服务的搭建

1)ftp搭建:

新建yum源存放位置,将其通过ftp服务共享

[root@moni01 ~]# mkdir /data     --新建yum源存放位置,将yum源存放在此文件夹内

[root@moni01 ~]# cat /etc/yum.repos.d/rhel-debuginfo.repo

[rhel-moni01]

name=Red Hat Enterprise Linux $releasever - $basearch - Debug

baseurl=file:///data/Server

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

2)通过yum库安装所需服务

[root@moni01 ~]# yum -y install vsftpd     服务端ftp

[root@moni01 ~]# yum -y install bind bind-chrootcaching-nameserver    --DNS服务

[root@moni01 ~]# yum -y install ntp      --ntp网络时间服务

3)配置DNS服务

[root@moni01 ~]# cd /var/named/chroot/etc/            --进入主配置文件目录

[root@moni01 etc]# cp -p named.caching-nameserver.confnamed.conf    --拷贝模板时,必须带权限

[root@moni01 etc]# vim named.conf    

 15         listen-on port 53 { 192.168.13.253; };

 27         allow-query     { any; };

 28         allow-query-cache { any; };

 37         match-clients      { any; };

 38         match-destinations { any; }

[root@moni01 etc]# vim named.rfc1912.zones

zone "xk.com" IN {

        type master;

        file"xk.com.zone";

        allow-updata {none; };

};

[root@moni01 etc]# named-checkconf named.conf    --检查语法

[root@moni01 etc]# cd /var/named/chroot/var/named/      --进入数据库文件

[root@moni01 named]# cp -p named.zero xk.com.zone     --拷贝必须带权限

[root@moni01 named]# cat xk.com.zone

$TTL    86400

@               INSOA  localhost.      root.localhost. (

                                       2014062701              ; serial(d. adams)

                                        3H              ; refresh

                                       15M             ; retry

                                        1W              ; expiry

                                        1D)            ; minimum

   IN NS moni01.xk.com.

   IN NS mail01.xk.com.

   IN MX 5 mail.xk.com.

moni01  IN A  192.168.13.253

mail01  IN   A  192.168.13.251

web01   IN A  192.168.13.10

web02   IN A  192.168.13.11

www     IN      A      192.168.13.10

www     IN      A      192.168.13.11     --实现http服务的负载均衡

mail    IN      A   192.168.13.251     --邮件服务器地址

[root@moni01 named]# named-checkzone xk.com xk.com.zone

zone xk.com/IN: loaded serial 2014062701

OK

[root@moni01 named]# service named restart

[root@moni01 named]# chkconfig named on

 

4)配置ntp网络时间服务

[root@moni01 ~]# vim /etc/ntp.conf

 11 restirct 192.168.13.0mask 255.255.255.0 nomodify      --添加13.0网段用户可同步时间

 20 server 127.127.1.0                        --添加应答机制

[root@moni01 etc]# service ntpd restart

[root@moni01 etc]# chkconfig ntpd on

5)配置ftp服务,提供yum源与公共资源下载

[root@moni01 ~]# vim /etc/vsftpd/vsftpd.conf 

12 anonymous_enable=YES

15 local_enable=YES

18 write_enable=NO

22 local_umask=022

119 chroot_local_user=YES

120 local_root=/data

[root@moni01 ~]# service vsftpd restart

[root@moni01 ~]# chkconfig vsftpd on

3.两台WEB服务器的搭配(以web01为样本)

在两台WEB服务器上安装HTTP服务并创建测试页面

通过跳板机yum源安装

[root@web01 ~]# cat /etc/yum.repos.d/rhel-debuginfo.repo

[rhel-web01]

name=Red Hat Enterprise Linux $releasever - $basearch - Debug

baseurl=ftp://192.168.13.253/Server

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

 

[root@web01 ~]# yum -y install httpd

[root@web01 ~]# vim /etc/httpd/conf/httpd.conf

 74 KeepAlive ON

[root@web01 ~]# vim /var/www/html/index.html    --创建测试页面

[root@web01 ~]# service httpd restart

[root@web01 ~]# chkconfig httpd on

注:web02配置与上述一致

4.邮件服务器的配置

通过远程yum库安装,postfix(邮件服务) dovecot (POP3邮件接收)   cyrus-sasl(SMTP认证控制)bind bind-chroot caching-nameserver(DNS服务)

1)将邮件服务器配置为跳板机的从DNS服务器

[root@mail01 etc]# vim /var/named/chroot/etc/named.conf

15         listen-on port53 { 192.168.13.251; };

 21         allow-transfer  { 192.168.13.251; };

 27         allow-query     { any; };

 28         allow-query-cache { any; };

 37         match-clients      { any; };

 38         match-destinations { any; };

[root@mail01 etc]# vim /var/named/chroot/etc/named.rfc1912.zones

 50 zone"xk.com" IN {

 51         type slave;

 52         file "slaves/xk.com.zone";

 53         masters { 192.168.13.253; };

 54 };

[root@mail01 etc]# service named restart

[root@mail01 etc]# chkconfig named on

[root@mail01 etc]# ls /var/named/chroot/var/named/slaves/

xk.com.zone

2)搭建邮件服务器

[root@mail01 etc]# cd /etc/postfix/

[root@mail01 postfix]# postconf -n > tmp.txt

[root@mail01 postfix]# mv main.cf main.cf.bak

[root@mail01 postfix]# mv tmp.txt main.cf

[root@mail01 postfix]# vim main.cf

  8 #inet_interfaces =localhost

 20 myhostname =mail.xk.com

 21 mydomain = xk.com

 22 myorigin = $mydomain

 23 mydestination =$mydomain

 24 home_mailbox = Maildir/

 25 mynetworks = 127.0.0.1                   

 26 smtpd_sasl_auth_enable= yes               

 27smtpd_sasl_security_options = noanonymous     

 28smtpd_recipient_restrictions =                

 29  permit_mynetworks,                 

 30  permit_sasl_authenticated,  

 31  reject_unauth_destination

[root@mail01 postfix]# service postfix restart

[root@mail01 postfix]# chkconfig postfix restart

[root@mail01 postfix]# service dovecot restart

[root@mail01 postfix]# chkconfig dovecot on

[root@mail01 postfix]# cp /usr/lib64/sasl2/smtpd.conf/etc/sasl2/smtpd.conf  --模板复制为主配置文件

[root@mail01 postfix]# cat /etc/sasl2/smtpd.conf

pwcheck_method: saslauthd

[root@mail01 postfix]# service saslauthd restart

[root@mail01 postfix]# chkconfig saslauthd on

3)测试:

[root@mail01 postfix]# printf "yg" |openssl base64

eWc=

[root@mail01 postfix]# printf "123" |openssl base64

MTIz

[root@mail01 postfix]# telnet mail.xk.com 25

Trying 192.168.13.251...

Connected to mail.xk.com (192.168.13.251).

Escape character is '^]'.

220 mail.xk.com ESMTP Postfix

mail from:yg@xk.com

250 2.1.0 Ok

rcpt to:123@sina.com

554 5.7.1 <123@sina.com>: Relay access denied

quit

221 2.0.0 Bye

Connection closed by foreign host.

[root@mail01 postfix]# telnet mail.xk.com 25

Trying 192.168.13.251...

Connected to mail.xk.com (192.168.13.251).

Escape character is '^]'.

220 mail.xk.com ESMTP Postfix

helo localhost

250 mail.xk.com

auth login

334 VXNlcm5hbWU6

eWc=

334 UGFzc3dvcmQ6

MTIz

235 2.0.0 Authentication successful

mail from:yg@xk.com

250 2.1.0 Ok

rcpt to:123@sina.com

250 2.1.5 Ok

quit

221 2.0.0 Bye

Connection closed by foreign host.         --经测试匿名用户发送邮件被拒绝,本地用户可发送

4)安装小松鼠web邮件服务器

[root@mail01 postfix]# yum -y install squirelmail

[root@mail01 postfix]# vim /etc/squirrelmail/config.php

26 $squirrelmail_default_language = 'zh_CN';

 27

 28 $domain                 = 'xk.com';

 29$imapServerAddress      ='192.168.13.251';

 32$smtpServerAddress      ='192.168.13.251';

[root@mail01 postfix]# service httpd restart

[root@mail01 postfix]# chkconfig httpd on

5)nfs服务配置将其作为共享并将其作为web服务器的网站根目录(实际工作中此方法虽然可以提供网站根目录的备份与其他普通用户的有限访问,但当此备份服务器出现问题时,将影响两台web服务器的正常运行)

[root@mail01 ~]# mkdir -p /data/web

[root@mail01 ~]# cat /etc/exports

/data/web 192.168.13.*(rw,sync)

[root@mail01 ~]# setfacl -m u:nfsnobody:rwx /data/web/

[root@mail01 data]# service portmap restart

[root@mail01 data]# service nfs restart

[root@mail01 data]# chkconfig portmap on

[root@mail01 data]# chkconfig nfs on

将此共享文件夹挂载在两台web服务器的网站根目录下

配置自动开机自动挂载

[root@web01 ~]# tail -2 /etc/fstab

192.168.13.251:/data/web /var/www/html  nfs  defaults  0 0

5.在web,mail服务器中配置计划任务,保证时间同步moni01的网络时间

[root@web01 html]# crontab -l

30 6 * * * /sbin/ntpdate192.168.13.253

6.在mail01中配置计划任务,定时备份web网页内容

[root@mail01 ~]# crontab -l

00 03 * * *  tar Ppzcf/web.bak/webdb-$(date +\%Y\%m\%d).tgz /data/web/*

 

 

 

实验总结:

通过本项目,简单的了解了服务器系统搭建的步鄹与框架,为日后工作的开展提供了一定的思路。并且从中体会到了服务与服务的不同搭配将发挥的用途也会不同,在实际工作中,应具体问题具体分析,以便通过最简单,最合适的配置,完成项目所需,提高服务可靠性。

 

本实验还有那些地方不完善:

1.  安全性能有待提高

2.  服务器使用率有待提高

3.  服务搭配有待优化

4.  服务器故障方案有待完善