第一章實驗(一):搭建web服務器

 

1.使用母盤鏈接克隆虛擬機並修改ip等基本參數:

克隆虛擬機,命名爲web服務器,修改如下:

ip a ##查看MAC地址

[root@www ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 ##確保MAC地址與eth1一致

DEVICE=eth0

HWADDR=00:0C:29:88:f9:43

TYPE=Ethernet

ONBOOT=yes

NM_CONTROLLED=no

BOOTPROTO=static

IPADDR=192.168.100.150

NETMASK=255.255.255.0

GATEWAY=192.168.100.100

DNS1=192.168.100.100

:wq

ip a

clip_image002

clip_image004

[root@www ~]# vim /etc/udev/rules.d/70-persistent-net.rules ##刪除eth0行,並將eth1改爲eth0

[root@www ~]# cat /etc/sysconfig/network ##設置主機的FQDN

NETWORKING=yes

HOSTNAME=www.linuxfan.cn

:wq

clip_image006

[root@www ~]# reboot

登錄到192.168.100.100上添加主機的dns解析:

[root@ns ~]# vim /var/named/chroot/var/named/linuxfan.cn.zone

www IN A 192.168.100.150

:wq

clip_image008

[root@ns ~]# vim /var/named/chroot/var/named/192.168.100.arpa

150 IN PTR www.linuxfan.cn.

:wq

clip_image010

/etc/init.d/named restart

[root@ns ~]# nslookup

> server 192.168.100.100

Default server: 192.168.100.100

Address: 192.168.100.100#53

> www.linuxfan.cn

Server: 192.168.100.100

Address: 192.168.100.100#53

Name: www.linuxfan.cn

Address: 192.168.100.150

> exit

clip_image012

[root@ns ~]#

2.下載軟件並安裝:登錄192.168.100.150

1)下載httpd

[root@www ~]# lftp ftp.linuxfan.cn

lftp ftp.linuxfan.cn:~> cd tools/

lftp ftp.linuxfan.cn:/tools> get httpd-2.2.17.tar.gz

6597991 bytes transferred

lftp ftp.linuxfan.cn:/tools> bye

[root@www ~]# ls httpd-2.2.17.tar.gz

httpd-2.2.17.tar.gz

clip_image014

2)解壓並安裝:

mount /dev/cdrom /mnt

yum -y install openssl-devel ##安裝openssl-devel提供https的支持

[root@www ~]# tar zxvf httpd-2.2.17.tar.gz -C /usr/src/

[root@www ~]# cd /usr/src/httpd-2.2.17/

[root@www httpd-2.2.17]# ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-cgi --enable-ssl && make &&make install

[root@www httpd-2.2.17]# echo $? ##返回0爲成功

0

[root@www httpd-2.2.17]# ls /usr/local/httpd/ ##安裝成功

bin cgi-bin error icons lib man modules

build conf htdocs include logs manual

3.安裝後優化和調整:

[root@www httpd]# ln -s /usr/local/httpd/bin/* /usr/local/bin/ ##優化執行命令的路徑

cd /usr/local/httpd/ ##進入

[root@www httpd]# cp bin/apachectl /etc/init.d/httpd

[root@www httpd]# vim /etc/init.d/httpd ##在開始位置修改bash和添加chkconfig和description;修改第82行實現執行命令時友好提示

#!/bin/bash ##聲明shell爲bash

# chkconfig: 35 85 15 ##在3和5運行級別開機啓動,開機啓動順序爲85,關機關閉順序爲15

# description: A Scripts for apache httpd deamon!

$HTTPD -k $ARGV &&echo "httpd is $ARGV complete." ##第82行

:wq

clip_image016

[root@www httpd]# ls -l /etc/init.d/httpd ##確認文件有執行權限,如果沒有使用命令“chmod +x /etc/init.d/httpd”授權

-rwxr-xr-x 1 root root 3496 1月 1 02:59 /etc/init.d/httpd

[root@www httpd]# chkconfig --add httpd

[root@www httpd]# chkconfig --list httpd

httpd 0:關閉 1:關閉 2:關閉 3:啓用 4:關閉 5:啓用 6:關閉

clip_image018

4.修改配置文件並啓動服務:

[root@www httpd]# vim /usr/local/httpd/conf/httpd.conf

:set nu ##打印出行號

88 ServerAdmin [email protected] ##修改管理員的郵箱

98 ServerName www.linuxfan.cn:80 ##添加網站的FQDN

:wq

clip_image020

[root@www httpd]# /etc/init.d/httpd start ##啓動服務

httpd is start complete.

[root@www httpd]# ps aux |grep httpd ##查看進程

root 73341 0.0 0.5 54808 2520 ? Ss 03:21 0:00 /usr/local/httpd/bin/httpd -k start

daemon 73342 0.0 0.4 54944 2000 ? S 03:21 0:00 /usr/local/httpd/bin/httpd -k start

daemon 73343 0.0 0.4 54944 2000 ? S 03:21 0:00 /usr/local/httpd/bin/httpd -k start

daemon 73344 0.0 0.4 54944 2000 ? S 03:21 0:00 /usr/local/httpd/bin/httpd -k start

daemon 73345 0.0 0.4 54944 2000 ? S 03:21 0:00 /usr/local/httpd/bin/httpd -k start

daemon 73346 0.0 0.4 54944 2000 ? S 03:21 0:00 /usr/local/httpd/bin/httpd -k start

[root@www httpd]# netstat -utpln |grep httpd ##查看監聽

tcp 0 0 :::80 :::* LISTEN 73341/httpd

clip_image022

5.訪問並測試:

[root@ns ~]# yum -y install elinks ##在192.168.100.100上進行測試

[root@ns ~]# vi /etc/resolv.conf

; generated by /sbin/dhclient-script

nameserver 192.168.100.100 ##添加DNS服務器

nameserver 192.168.1.1 ##不必修改,此dns服務器爲橋接網卡自動獲取的dns服務器目的是能上公網

clip_image024·

[root@ns ~]# elinks --dump http://www.linuxfan.cn ##成功完成實驗

It works!

clip_image026

windows主機上使用IE或者chrome(谷歌),firefox(火狐)等瀏覽器訪問:

http://www.linuxfan.cn

clip_image028

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章