1.環境準備:
使用ctos1虛擬機,打開之後確認ip地址爲192.168.100.150,網關爲192.168.100.100,dns爲192.168.100.100.
設置主機名:
[root@www ~]# cat /etc/sysconfig/network ##設置主機的FQDN
NETWORKING=yes
HOSTNAME=www.linuxfan.cn
:wq
[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
[root@ns ~]# vim /var/named/chroot/var/named/192.168.100.arpa
150 IN PTR www.linuxfan.cn.
:wq
/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
[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
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
[root@www ~]# cd /usr/local/httpd
3.安裝後優化和調整:
[root@www httpd]# ln -s /usr/local/httpd/bin/* /usr/local/bin/ ##優化執行命令的路徑
[root@www httpd]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
[root@www httpd]# vim /etc/init.d/httpd ##在開始位置修改bash和添加chkconfig和description;修改第82行實現執行命令時友好提示
1 #!/bin/bash ##聲明shell爲bash
2 # chkconfig: 35 85 15 ##在3和5運行級別開機啓動,開機啓動順序爲85,關機關閉順序爲15
3 # description: A Scripts for apache httpd deamon!
82 $HTTPD -k $ARGV &&echo "httpd is $ARGV complete." ##第82行
: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
[root@www httpd]# chkconfig --add httpd
[root@www httpd]# chkconfig --list httpd
httpd 0:關閉 1:關閉 2:關閉 3:啓用 4:關閉 5:啓用 6:關閉
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
[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
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.3.5 ##不必修改,此dns服務器爲橋接網卡自動獲取的dns服務器目的是能上公網
[root@ns ~]# elinks --dump http://www.linuxfan.cn ##成功完成實驗
It works!
windows主機上使用IE或者chrome(谷歌),firefox(火狐)等瀏覽器訪問:
http://www.linuxfan.cn
搭建web服務器
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
Linux系統搭建簡單 D H C P服務
遇見ZZM
2019-02-24 12:53:29
簡單的三層交換配置路由 實驗(華爲)
tenggl_0824
2019-02-23 00:42:21
用虛擬機自主搭建互聯網架構的DNS
水柔山
2019-02-23 00:40:13
用系統爲centos6的主機,搭建PXE服務器,實現批量安裝centos6,7系統
水柔山
2019-02-23 00:40:13
Saltstack-部署
jungiewolf
2019-02-23 00:35:46
UPLOOKING_APUE
y674526601
2019-02-23 13:21:00
轉:如何用GCC編譯生成動態鏈接庫*.SO文件 動態庫
lazymorning
2019-02-23 12:58:42
使用Excel 2007繪製甘特圖
bokezyyx
2019-02-23 00:42:19
Jquery easyUi Droppable(放置)組件
StringLong
2019-02-23 00:41:59
黑盒測試之錯誤推測法
947154267yjn
2019-02-23 00:37:25
linux下如何防SYN***
曼尼
2019-02-23 00:31:43
如何提高網速20%!
曼尼
2019-02-23 00:31:38