1.环境准备:
使用ctos1虚拟机,打开之后确认ip地址为192.168.100.150,网关为192.168.100.100,dns为192.168.100.100.设置主机名:[root@www ~]# cat /etc/sysconfig/network ##设置主机的FQDNNETWORKING=yesHOSTNAME=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.100Default server: 192.168.100.100Address: 192.168.100.100#53> www.linuxfan.cnServer: 192.168.100.100Address: 192.168.100.100#53Name: www.linuxfan.cnAddress: 192.168.100.150> exit[root@ns ~]# 2.下载软件并安装:登录192.168.100.1501)下载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.gz2)解压并安装:mount /dev/cdrom /mntyum -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 modulesbuild conf htdocs include logs manual[root@www ~]# cd /usr/local/httpd3.安装后优化和调整:[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为bash2 # chkconfig: 35 85 15 ##在3和5运行级别开机启动,开机启动顺序为85,关机关闭顺序为153 # 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 httpdhttpd 0:关闭 1:关闭 2:关闭 3:启用 4:关闭 5:启用 6:关闭4.修改配置文件并启动服务:[root@www httpd]# vim /usr/local/httpd/conf/httpd.conf:set nu ##打印出行号 88 ServerAdmin admin@linuxfan.cn ##修改管理员的邮箱 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 startdaemon 73342 0.0 0.4 54944 2000 ? S 03:21 0:00 /usr/local/httpd/bin/httpd -k startdaemon 73343 0.0 0.4 54944 2000 ? S 03:21 0:00 /usr/local/httpd/bin/httpd -k startdaemon 73344 0.0 0.4 54944 2000 ? S 03:21 0:00 /usr/local/httpd/bin/httpd -k startdaemon 73345 0.0 0.4 54944 2000 ? S 03:21 0:00 /usr/local/httpd/bin/httpd -k startdaemon 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-scriptnameserver 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