標籤:web伺服器 虛擬機器 命名
第一章實驗(一):搭建web伺服器
1.使用母盤連結複製虛擬機器並修改ip等基本參數:
複製虛擬機器,命名為web伺服器,修改如下:
ip a ##查看MAC地址
[[email protected] ~]# 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
[[email protected] ~]# vim /etc/udev/rules.d/70-persistent-net.rules ##刪除eth0行,並將eth1改為eth0
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image002[4]" border="0" alt="clip_image002[4]" src="http://s3.51cto.com/wyfs02/M02/86/5D/wKiom1e9KF7Bx4LGAAASkjZ96Y4160.jpg" width="244" height="50" />
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image004[4]" border="0" alt="clip_image004[4]" src="http://s3.51cto.com/wyfs02/M02/86/5C/wKioL1e9KF-w1r-cAAAbi9DJtsg816.jpg" width="244" height="66" />
[[email protected] ~]# cat /etc/sysconfig/network ##設定主機的FQDN
NETWORKING=yes
HOSTNAME=www.linuxfan.cn
:wq
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image006[4]" border="0" alt="clip_image006[4]" src="http://s3.51cto.com/wyfs02/M00/86/5C/wKioL1e9KF_SaJlRAAANZ83S5Ho375.jpg" width="244" height="41" />
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image008[4]" border="0" alt="clip_image008[4]" src="http://s3.51cto.com/wyfs02/M01/86/5C/wKioL1e9KGDgYMqaAAALaElqq7w957.jpg" width="244" height="54" />
[[email protected] ~]# reboot
登入到192.168.100.100上添加主機的dns解析:
[[email protected] ~]# vim /var/named/chroot/var/named/linuxfan.cn.zone
www IN A 192.168.100.150
:wq
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image010[4]" border="0" alt="clip_image010[4]" src="http://s3.51cto.com/wyfs02/M00/86/5D/wKiom1e9KGHhE0O4AAA4RbB3ubk179.jpg" width="244" height="178" />
[[email protected] ~]# vim /var/named/chroot/var/named/192.168.100.arpa
150 IN PTR www.linuxfan.cn.
:wq
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image012[4]" border="0" alt="clip_image012[4]" src="http://s3.51cto.com/wyfs02/M01/86/5D/wKiom1e9KGKAuYvlAAAqmVUtHP4894.jpg" width="244" height="156" />
/etc/init.d/named restart
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image014[4]" border="0" alt="clip_image014[4]" src="http://s3.51cto.com/wyfs02/M02/86/5D/wKiom1e9KGKA573xAAAUOWG75ag483.jpg" width="244" height="70" />
[[email protected] ~]# 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
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image016[4]" border="0" alt="clip_image016[4]" src="http://s3.51cto.com/wyfs02/M02/86/5C/wKioL1e9KGOBVf3ZAAAdw_-yK_U850.jpg" width="244" height="96" />
[[email protected] ~]#
2.下載軟體並安裝:登入192.168.100.100
1)下載httpd
[[email protected] ~]# 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
[[email protected] ~]# ls httpd-2.2.17.tar.gz
httpd-2.2.17.tar.gz
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image018[4]" border="0" alt="clip_image018[4]" src="http://s3.51cto.com/wyfs02/M00/86/5D/wKiom1e9KGTSV2BoAAAljRMX-iM161.jpg" width="244" height="79" />
2)解壓並安裝:
mount /dev/cdrom /mnt
yum -y install openssl-devel ##安裝openssl-devel提供https的支援
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image020[4]" border="0" alt="clip_image020[4]" src="http://s3.51cto.com/wyfs02/M00/86/5C/wKioL1e9KGWiEQsBAAAq3SPRHX4643.jpg" width="244" height="108" />
[[email protected] ~]# tar zxvf httpd-2.2.17.tar.gz -C /usr/src/
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image022[4]" border="0" alt="clip_image022[4]" src="http://s3.51cto.com/wyfs02/M01/86/5D/wKiom1e9KGWwXZ6gAAAdgbe1jpc391.jpg" width="244" height="79" />
[[email protected] ~]# cd /usr/src/httpd-2.2.17/
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image024[4]" border="0" alt="clip_image024[4]" src="http://s3.51cto.com/wyfs02/M02/86/5D/wKiom1e9KGajk_g8AAAwVbWqp-E812.jpg" width="244" height="119" />
[[email protected] httpd-2.2.17]# ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-cgi --enable-ssl && make &&make install
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image026[4]" border="0" alt="clip_image026[4]" src="http://s3.51cto.com/wyfs02/M02/86/5C/wKioL1e9KGewdDJDAAAuTAyc1cw494.jpg" width="244" height="102" />
[[email protected] httpd-2.2.17]# echo $? ##返回0為成功
0
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image028[4]" border="0" alt="clip_image028[4]" src="http://s3.51cto.com/wyfs02/M00/86/5C/wKioL1e9KGjAVwR0AAAPttukEUE552.jpg" width="244" height="45" />
[[email protected] httpd-2.2.17]# ls /usr/local/httpd/ ##安裝成功
bin cgi-bin error icons lib man modules
build conf htdocs include logs manual
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image030[4]" border="0" alt="clip_image030[4]" src="http://s3.51cto.com/wyfs02/M01/86/5C/wKioL1e9KGijaZB7AAAXkEfGeVs409.jpg" width="244" height="54" />
3.安裝後最佳化和調整:
[[email protected] httpd]# ln -s /usr/local/httpd/bin/* /usr/local/bin/ ##最佳化執行命令的路徑
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image032[4]" border="0" alt="clip_image032[4]" src="http://s3.51cto.com/wyfs02/M00/86/5D/wKiom1e9KGmj4rkQAAASqpSv338276.jpg" width="244" height="53" />
[[email protected] httpd]# cp /usr/local/bin/apachectl /etc/init.d/httpd
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image034[4]" border="0" alt="clip_image034[4]" src="http://s3.51cto.com/wyfs02/M01/86/5D/wKiom1e9KGnBzuObAAAR6wLhT-Y845.jpg" width="244" height="49" />
[[email protected] 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!
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image036[4]" border="0" alt="clip_image036[4]" src="http://s3.51cto.com/wyfs02/M01/86/5D/wKiom1e9KGrjk1pQAAAhXpacEJo495.jpg" width="244" height="66" />
$HTTPD -k $ARGV &&echo "httpd is $ARGV complete." ##第82行
:wq
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image038[4]" border="0" alt="clip_image038[4]" src="http://s3.51cto.com/wyfs02/M01/86/5C/wKioL1e9KGuDGMvgAAApbMLfbVw997.jpg" width="244" height="106" />
[[email protected] 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
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image040[4]" border="0" alt="clip_image040[4]" src="http://s3.51cto.com/wyfs02/M02/86/5D/wKiom1e9KGuAMofzAAAQDmehU8I506.jpg" width="244" height="40" />
[[email protected] httpd]# chkconfig --add httpd
[[email protected] httpd]# chkconfig --list httpd
httpd 0:關閉 1:關閉 2:關閉 3:啟用 4:關閉 5:啟用 6:關閉
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image042[4]" border="0" alt="clip_image042[4]" src="http://s3.51cto.com/wyfs02/M00/86/5D/wKiom1e9KGywb0m_AAAXy6gq06E838.jpg" width="244" height="59" />
4.修改設定檔並啟動服務:
[[email protected] httpd]# vim /usr/local/httpd/conf/httpd.conf
:set nu ##列印出行號
88 ServerAdmin [email protected] ##修改管理員的郵箱
98 ServerName www.linuxfan.cn:80 ##添加網站的FQDN
:wq
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image044[4]" border="0" alt="clip_image044[4]" src="http://s3.51cto.com/wyfs02/M01/86/5D/wKiom1e9KG2x2MjBAAA9AUCW3ys868.jpg" width="244" height="138" />
[[email protected] httpd]# /etc/init.d/httpd start ##啟動服務
httpd is start complete.
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image046[4]" border="0" alt="clip_image046[4]" src="http://s3.51cto.com/wyfs02/M02/86/5D/wKiom1e9KG2y0Nq4AAAVLwM6flE924.jpg" width="244" height="56" />
[[email protected] 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
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image048[4]" border="0" alt="clip_image048[4]" src="http://s3.51cto.com/wyfs02/M00/86/5D/wKiom1e9KG7hnHf-AABJlrwyJfg302.jpg" width="244" height="157" />
[[email protected] httpd]# netstat -utpln |grep httpd ##查看監聽
tcp 0 0 :::80 :::* LISTEN 73341/httpd
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image050[4]" border="0" alt="clip_image050[4]" src="http://s3.51cto.com/wyfs02/M00/86/5D/wKiom1e9KG-DSFOtAAAVNUnv9fM469.jpg" width="244" height="58" />
5.訪問並測試:
[[email protected] ~]# yum -y install elinks ##在192.168.100.100上進行測試
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image052[4]" border="0" alt="clip_image052[4]" src="http://s3.51cto.com/wyfs02/M00/86/5C/wKioL1e9KG-jWUGlAAAeylcWS0M588.jpg" width="244" height="80" />
[[email protected] ~]# vi /etc/resolv.conf
; generated by /sbin/dhclient-script
nameserver 192.168.100.100 ##添加DNS伺服器
nameserver 192.168.1.1 ##不必修改,此dns伺服器為橋接網卡自動擷取的dns伺服器目的是能上公網
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image054[4]" border="0" alt="clip_image054[4]" src="http://s3.51cto.com/wyfs02/M01/86/5D/wKiom1e9KHDTvflyAAAS7ytC0CA309.jpg" width="244" height="62" />
[[email protected] ~]# elinks --dump http://www.linuxfan.cn ##成功完成實驗
It works!
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image056[4]" border="0" alt="clip_image056[4]" src="http://s3.51cto.com/wyfs02/M02/86/5D/wKiom1e9KHGj3w-eAAASWpX1EDo640.jpg" width="244" height="54" />
windows主機上使用IE或者chrome(Google),firefox(Firefox)等瀏覽器訪問:
http://www.linuxfan.cn
650) this.width=650;" style="background-image: none; border-right- 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image058[4]" border="0" alt="clip_image058[4]" src="http://s3.51cto.com/wyfs02/M02/86/5D/wKiom1e9KHHCFc45AAAS8FIiI7M523.jpg" width="244" height="65" />
搭建web伺服器