1.环境准备:
设置主机ip地址为192.168.100.150,网关为192.168.100.100,dns为192.168.100.100.
设置主机名:
sed -i ‘s/localhost.localdomain/www.gxfc.com/g‘ /etc/sysconfig/network ##修改不显示主机名,将localhost.localdomain替换为www.gxifc.com
[[email protected] ~]# cat /etc/sysconfig/network ##查看设置主机的FQDN
NETWORKING=yes
HOSTNAME=www.gxfc.com
[[email protected] ~]# reboot ##重启使修改的主机名生效
[[email protected] ~]# hostname ##查看主机名是否生效
www.gxfc.com
登录到内部DNS服务器上添加主机的dns解析,如果已经添加可以不用设置:
[[email protected] ~]# vim /var/named/chroot/etc/named.conf ##在该文件末尾添加如下内容
zone "gxfc.com" IN {
type master;
file "gxfc.com.zone";
};
:wq
[[email protected] ~]# vim /var/named/chroot/var/named/gxfc.com.zone
$TTL 86400
@ IN SOA gxfa.com. root.gxfc.com. (
20170310
1H
2M
3W
1D
)
@ IN NS ns.gxfc.com.
@ IN A 192.168.100.150
ns IN A 192.168.100.150
www IN A 192.168.100.150
:wq
[[email protected] ~]# /etc/init.d/named restart ##重启dns服务
停止 named: [确定]
启动 named: [确定]
[[email protected] ~]# nslookup
> server 192.168.100.100
Default server: 192.168.100.100
Address: 192.168.100.100#53
> www.gxfc.com
Server:192.168.100.100
Address:192.168.100.100#53
Name:www.gxfc.com
Address: 192.168.100.150
> exit
[[email protected] ~]#
2.下载软件并安装:登录192.168.100.150
1)从官网下载httpd软件包
2)解压并安装:
[[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-charset-lite --enable-cgi &&make &&make install
编译参数属性解释: |
|
--prefix |
指定httpd2.4的安装路径 |
--sysconfdir |
指定配置文件路径 |
--enable-so |
启动sharedobject共享对象 |
--enable-ssl |
启用ssl,借助于此可以实现HTTPS访问 |
--enable-cgi |
启用CGI,可以实现CGI脚本执行 |
--enable-rewrite |
启用Rewrite重写,能够实现诸如301重定向的功能,以来PCRE包 |
--with-zlib |
启用zlib压缩 |
--with-pcre |
启用PCRE |
--with-apr |
指定apr的路径,httpd2.4依赖apr1.4版本以上,所以要指明 |
--with-apr-util |
指定apr-util的路径,同上 |
--enable-modules |
启用哪些模块加载,most尽可能多的 |
--enable-mpms-shared=all |
http2.4上prefork、worker、event是模块化的,可以动态加载 |
--with-mpm=prefork |
指明默认的httpd2.4 MPM,即运行在prefork模型下 |
[[email protected] httpd-2.2.17]# ls /usr/local/httpd/ ##安装成功
bin cgi-bin error icons lib man modules
build conf htdocs include logs manual
3.安装后优化和调整:
[[email protected] httpd]# ln -s /usr/local/httpd/bin/* /usr/local/bin/ ##优化执行命令的路径
[[email protected] httpd]# httpd -v
[[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!
:wq
[[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
[[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 /etc/httpd/httpd.conf
:set nu ##打印出行号
192 ServerAdmin [email protected]gxfc.com ##修改管理员的邮箱
201 ServerName www.gxfc.com: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服务器
[[email protected] ~]# elinks --dump http://www.gxfc.com ##成功完成实验
It works!
windows主机上使用IE或者chrome(谷歌),firefox(火狐)等浏览器访问:
http://www.gxfc.com