搭建web服務器實驗

搭建web服務器linux

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

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

ip a ##查看MAC地址shell

clip_image001

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

DEVICE=eth0vim

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

TYPE=Ethernet瀏覽器

ONBOOT=yesbash

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

clip_image003

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

clip_image004

[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

clip_image012

[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_image014

[root@ns ~]#

2.下載軟件並安裝:登陸192.168.100.100

1)下載httpd

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

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

clip_image016

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

6597991 bytes transferred

clip_image018

lftp ftp.linuxfan.cn:/tools> bye

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

httpd-2.2.17.tar.gz

clip_image020

2)解壓並安裝:

mount /dev/cdrom /mnt

clip_image022

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

clip_image024

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

clip_image026

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

clip_image028

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

clip_image030

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

0

clip_image032

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

bin cgi-bin error icons lib man modules

build conf htdocs include logs manual

clip_image0343.安裝後優化和調整:

[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

clip_image036

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

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

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

clip_image038

# description: A Scripts for apache httpd deamon!

clip_image040

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

clip_image042

:wq

[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

clip_image044

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

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

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

clip_image046

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

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

:set nu ##打印出行號

88 ServerAdmin admin@linuxfan.cn ##修改管理員的郵箱

clip_image048

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

clip_image050

:wq

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

httpd is start complete.

clip_image052

[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

clip_image054

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

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

clip_image056

5.訪問並測試:

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

clip_image058

[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_image060

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

It works!

clip_image062

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

http://www.linuxfan.cn

clip_image063

相關文章
相關標籤/搜索