简单搭建web服务器
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了简单搭建web服务器相关的知识,希望对你有一定的参考价值。
第一章实验(一):搭建web服务器
1.环境准备:
开启一台centos6.5系统的虚拟机作为web服务器,确认ip地址为192.168.100.150,网关为192.168.100.100,dns为192.168.100.100.
另外一台同样系统的虚拟机,ip地址为192.168.100.100 作为dns服务器
首先设置主机名,保证主机名和web服务器的域名相同:
[[email protected] ~]# cat /etc/sysconfig/network ##设置主机的FQDN
NETWORKING=yes
HOSTNAME=www.linuxfan.cn
:wq
[[email protected] ~]# reboot
登录到192.168.100.100的 DNS服务器上添加主机的dns解析:
[[email protected] ~]# vim /var/named/chroot/var/named/linuxfan.cn.zone
www IN A 192.168.100.150
:wq
[[email protected] ~]# vim /var/named/chroot/var/named/192.168.100.arpa
(添加反向解析)
150 IN PTR www.linuxfan.cn.
:wq
/etc/init.d/named restart(重启域名服务)
[[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
[[email protected] ~]#
2.下载软件并安装:登录192.168.100.150(web服务器)
1)下载httpd
[[email protected] ~]# lftp ftp.linuxfan.cn ( dns服务器也作为ftp服务器)
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
2)解压并安装:
mount /dev/cdrom /mnt
yum -y install openssl-devel ##安装openssl-devel提供https的支持
[[email protected] ~]# tar zxvf httpd-2.2.17.tar.gz -C /usr/src/
[[email protected] ~]# cd /usr/src/httpd-2.2.17/
[[email protected] httpd-2.2.17]# ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-cgi --enable-ssl && make &&make install
[[email protected] httpd-2.2.17]# echo $? ##返回0为成功
[[email protected] httpd-2.2.17]# ls /usr/local/httpd/ ##安装成功
bin cgi-bin error icons lib man modules
build conf htdocs include logs manual
[[email protected] ~]# cd /usr/local/httpd
3.安装后优化和调整:
[[email protected] httpd]# ln -s /usr/local/httpd/bin/* /usr/local/bin/ ##优化执行命令的路径
[[email protected] httpd]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
[[email protected] 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
[[email protected] httpd]# ls -l /etc/init.d/httpd ##确认文件有执行权限,如果没有使用命令
“chmod +x /etc/init.d/httpd”授权
[[email protected] httpd]# chkconfig --add httpd
[[email protected] httpd]# chkconfig --list httpd
httpd 0:关闭1:关闭2:关闭3:启用4:关闭5:启用6:关闭
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
[[email protected] httpd]# /etc/init.d/httpd start ##启动服务
httpd is start complete.
[[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
[[email protected] httpd]# netstat -utpln |grep httpd ##查看监听
tcp 0 0 :::80 :::* LISTEN 73341/httpd
5.访问并测试:
[[email protected] ~]# yum -y install elinks ##在192.168.100.100上进行测试
[[email protected] ~]# vi /etc/resolv.conf
; generated by /sbin/dhclient-script
nameserver 192.168.100.100 ##添加DNS服务器
nameserver 192.168.3.5 ##不必修改,此dns服务器为桥接网卡自动获取的dns服务器目的是能上公网
此次外网的网卡网段为192.168.1.0
网段不同,此外网网段为192.168.1.0网段
[[email protected] ~]# elinks --dump http://www.linuxfan.cn ##成功完成实验
(elinks:将html网页用文本的方式显示)
It works!
windows主机上使用IE或者chrome(谷歌),firefox(火狐)等浏览器访问:
本文出自 “12289734” 博客,请务必保留此出处http://12299734.blog.51cto.com/12289734/1873316
以上是关于简单搭建web服务器的主要内容,如果未能解决你的问题,请参考以下文章