环境信息:
主机1:dns-ftp | centos6.5 | 提供dns解析和yum源码ftp等 | 192.168.200.254 |
主机2:www.leslie.com | centos6.5 | 架设网站 | 192.168.200.202 |
主机3:windows | windows7 | 测试网页 | 192.168.200.20 |
1:在dns-ftp主机上设置dns解析,前提是搭建了dns服务
[root@dns-ftp ~]# vi /etc/sysconfig/network [root@dns-ftp ~]# cat /etc/sysconfig/network NETWORKING=yes IPV6=no HOSTNAME=ftp.linuxfan.cn [root@dns-ftp ~]# vi /var/named/chroot/etc/named.conf [root@dns-ftp ~]# cat /var/named/chroot/etc/named.conf options { listen-on port 53 { any; }; forwarders { 202.106.0.20;114.114.114.114;8.8.8.8; }; directory "/var/named"; }; zone "leslie.com." IN { type master; file "leslie.com.zone"; }; [root@dns-ftp ~]# vi /var/named/chroot/var/named/leslie.com.zone [root@dns-ftp ~]# cat /var/named/chroot/var/named/leslie.com.zone $TTL 86400 @ IN SOA leslie.com. root.leslie.com. ( 20150630 1H;   2M 3W 1D ) @ IN NS ns.leslie.com. mail IN MX 10 mail.leslie.com. @ IN A 192.168.200.254 mail IN A 192.168.200.254 ns IN A 192.168.200.254 ftp IN A 192.168.200.254 ntp IN CNAME ns www IN A 192.168.200.202 [root@dns-ftp ~]# /etc/init.d/named restart 停止 named: [确定] 启动 named: [root@dns-ftp ~]# vi /etc/resolv.conf [root@dns-ftp ~]# cat /etc/resolv.conf ; generated by /sbin/dhclient-script nameserver 202.106.0.20 nameserver 192.168.200.254 [确定] [root@dns-ftp ~]# nslookup > server 192.168.200.254 Default server: 192.168.200.254 Address: 192.168.200.254#53 > www.leslie.com Server: 192.168.200.254 Address: 192.168.200.254#53 Name: www.leslie.com Address: 192.168.200.202 [root@dns-ftp ~]# ping www.leslie.com PING www.leslie.com (192.168.200.202) 56(84) bytes of data. 64 bytes from 192.168.200.202: icmp_seq=1 ttl=64 time=1.39 ms 64 bytes from 192.168.200.202: icmp_seq=2 ttl=64 time=0.491 ms
2:在web服务器上下载软件、解压操作:
下载:可以到官方网站下载,这里我在ftp下载了一份,从ftp拿出来直接用了
(官方下载地址:http://httpd.apache.org/download.cgi)
[root@www ~]# lftp ftp.leslie.com lftp ftp.leslie.com:~> ls dr-xr-xr-x 7 0 0 4096 Nov 29 2013 centos6 drwxr-xr-x 3 0 0 4096 Mar 18 2016 ntop drwxr-xr-x 2 0 0 4096 Apr 15 12:29 pub dr-xr-xr-x 2 0 0 4096 Mar 20 2016 tools lftp ftp.leslie.com:/> cd tools/ lftp ftp.leslie.com:/tools> get httpd-2.2.17.tar.gz 6597991 bytes transferred lftp ftp.leslie.com:/tools> quit
解压:tar zxvf 软件名 -C 解压到的位置
[root@www ~]# ls anaconda-ks.cfg httpd-2.2.17.tar.gz index.html install.log install.log.syslog [root@www ~]# tar zxf httpd-2.2.17.tar.gz -C /usr/src/ [root@www ~]# cd /usr/src/httpd-2.2.17/ [root@www httpd-2.2.17]# [root@www httpd-2.2.17]# ls ABOUT_APACHE BuildBin.dsp configure.in include LICENSE NWGNUmakefile ROADMAP VERSIONING acinclude.m4 buildconf docs INSTALL Makefile.in os server Apache.dsw CHANGES emacs-style InstallBin.dsp Makefile.win README srclib build config.layout httpd.dsp LAYOUT modules README.platforms support BuildAll.dsp configure httpd.spec libhttpd.dsp NOTICE README-win32.txt test
3:编译安装:
首先配置编译文件 makefile为下一步编译做准备
./configure --prefix=/usr/local/httpd --enable-so --enable-cgi --enable-rewrite --enable-ssl
[root@www httpd-2.2.17]# ./configure --prefix=/usr/local/httpd --enable-so --enable-cgi --enable-rewrite --enable-ssl checking for chosen layout... Apache checking for working mkdir -p... yes checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking target system type... x86_64-unknown-linux-gnu Configuring Apache Portable Runtime library ... checking for APR... reconfig configuring package in srclib/apr now checking build system type... x86_64-unknown-linux-gnu ......
no OpenSSL headers found checking for SSL-C version... checking sslc.h usability... no checking sslc.h presence... no checking for sslc.h... no no SSL-C headers found configure: error: ...No recognized SSL/TLS toolkit detected
执行后出现以下错误,根据错误信息发现缺少openssl依赖,安装openssl-devel后重新执行
[root@www httpd-2.2.17]# yum -y install openssl-devel
......
Installed:
openssl-devel.x86_64 0:1.0.1e-15.el6
Dependency Installed:
keyutils-libs-devel.x86_64 0:1.4-4.el6 krb5-devel.x86_64 0:1.10.3-10.el6_4.6
libcom_err-devel.x86_64 0:1.41.12-18.el6 libselinux-devel.x86_64 0:2.0.94-5.3.el6_4.1
libsepol-devel.x86_64 0:2.0.41-4.el6 zlib-devel.x86_64 0:1.2.3-29.el6
Complete!
再次重生成文件 可以看到
[root@www httpd-2.2.17]# ./configure --prefix=/usr/local/httpd --enable-so --enable-cgi --enable-rewrite --enable-ssl
##可以看到生成的makefile文件 [root@www httpd-2.2.17]# ls |grep Makefile Makefile Makefile.in Makefile.win
然后将生成的makefile文件编译
[root@www httpd-2.2.17]# make
Making all in srclib
make[1]: Entering directory `/usr/src/httpd-2.2.17/srclib‘
Making all in apr
make[2]: Entering directory `/usr/src/httpd-2.2.17/srclib/apr‘
make[3]: Entering directory `/usr/src/httpd-2.2.17/srclib/apr‘
......
最后将编译好的二进制文件安装
[root@www httpd-2.2.17]# make install
Making install in srclib
make[1]: Entering directory `/usr/src/httpd-2.2.17/srclib‘
Making install in apr
make[2]: Entering directory `/usr/src/httpd-2.2.17/srclib/apr‘
make[3]: Entering directory `/usr/src/httpd-2.2.17/srclib/apr‘
make[3]: Nothing to be done for `local-all‘.
make[3]: Leaving directory `/usr/src/httpd-2.2.17/srclib/apr‘
......
到此便完成了编译安装。
使用下面这条命令可以看出上条命令是否执行成功,0是成功,非0失败
安装OK!
[root@www httpd-2.2.17]# echo $? 0 [root@www httpd-2.2.17]# [root@www httpd-2.2.17]# ls /usr/local/httpd/ ##查看安装位置文件 bin build cgi-bin conf error htdocs icons include lib logs man manual modules
4优化操作:apache已经安装完成了,为了便于日后维护使用,做一些简单的优化操作
创建链接文件:将安装目录下的文件链接到环境变量里,这样在任何位置目录下都可以执行apached的命令了
[root@www httpd-2.2.17]# ln -s /usr/local/httpd/bin/* /usr/local/bin/ [root@www httpd-2.2.17]# ls /usr/local/httpd/bin/ ab apr-1-config apxs dbmmanage envvars-std htdbm htpasswd httxt2dbm rotatelogs apachectl apu-1-config checkgid envvars htcacheclean htdigest httpd logresolve
复制启动脚本到启动目录下 方便对服务进行管理
[root@www httpd-2.2.17]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
[root@www httpd-2.2.17]# vi /etc/init.d/httpd
1 #!/bin/bash
2 # chkconfig: 35 85 10 #3 5 运行级别开机启动顺序85,关机是10
3 #this is web run script ##脚本的描述
......
82 $HTTPD -k $ARGV &&echo "httpd is $ARGV ok!"
##这条语句是服务启动关闭重启等操作,会有提示信息
5 修改配置文件:
ServerAdmin admin@leslie.com ##这行改成管理员的邮箱,有什么问题以便于用户联系管理员。
ServerName www.leslie.com:80 ##这行是主机名加端口,httpd服务默认是80-端口的
vi /usr/local/httpd/conf/httpd.conf ... 88 ServerAdmin admin@leslie.com 98 ServerName www.leslie.com:80 ...
6 启动服务:
[root@www httpd-2.2.17]# /etc/init.d/httpd start httpd is start ok! [root@www httpd-2.2.17]# service httpd restart httpd is restart ok!
7 查看和测试:
##查看监听的地址端口和查看进程
[root@www httpd-2.2.17]# netstat -utpln |grep httpd tcp 0 0 :::80 :::* LISTEN 73092/httpd [root@www httpd-2.2.17]# ps aux |grep httpd root 73092 0.0 0.5 54808 2916 ? Ss Aug14 0:00 /usr/local/httpd/bin/httpd -k start daemon 73108 0.0 0.3 54944 1928 ? S 00:00 0:00 /usr/local/httpd/bin/httpd -k start daemon 73109 0.0 0.3 54944 1928 ? S 00:00 0:00 /usr/local/httpd/bin/httpd -k start daemon 73110 0.0 0.3 54944 1928 ? S 00:00 0:00 /usr/local/httpd/bin/httpd -k start daemon 73111 0.0 0.3 54944 1928 ? S 00:00 0:00 /usr/local/httpd/bin/httpd -k start daemon 73112 0.0 0.3 54944 1928 ? S 00:00 0:00 /usr/local/httpd/bin/httpd -k start root 73116 0.0 0.1 103256 836 pts/0 S+ 00:00 0:00 grep httpd
linux下访问测试:
[root@ftp ~]# elinks --dump http://www.leslie.com It works!
windows7上浏览器访问测试:
输入地址:http://www.leslie.com (注意windeos7网卡的dns要指向dns服务器192.168.200.254)
网站的网页项目放在安装目录下的 htdocs下
[root@www httpd-2.2.17]# cd /usr/local/httpd/htdocs/ [root@www htdocs]# ls index.html [root@www htdocs]# pwd /usr/local/httpd/htdocs
有项目放到这个位置就可以访问到了,更改文件测试下
[root@www htdocs]# vi index.html [root@www htdocs]# cat index.html <html><body><h1>www.leslie.com!</h1></body></html> [root@www htdocs]#
[root@ftp ~]# elinks --dump http://www.leslie.com www.leslie.com!
本文出自 “向往技术的小白” 博客,请务必保留此出处http://lesliecheung.blog.51cto.com/12622169/1956161
原文地址:http://lesliecheung.blog.51cto.com/12622169/1956161