某公司新購四臺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:[email protected]
250 2.1.0 Ok
rcpt to:[email protected]
554 5.7.1 <[email protected]>: 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:[email protected]
250 2.1.0 Ok
rcpt to:[email protected]
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. 服務器故障方案有待完善