技术开发 频道

RHEL5.4下LAMP平台搭建及基本测试

  【IT168 文档

  实验目的:

  完成Linux下面的LAMP环境的搭建,实现Discuz论坛,实现awstats分析Web日志,以及AB实现HTTP性能测试,最后通过phpMyAdmin管理MySQL数据库

RHEL5.4下LAMP平台搭建及基本测试

  实验软件包:

  软件下载地址:

  Apache: http://apache.freelamp.com/httpd/httpd-2.2.15.tar.gz

  Mysql: ftp://mirror2.dataphone.se/pub/mysql/Downloads/MySQL-5.1/mysql-5.1.44.tar.gz

  Php: http://cn.php.net/distributions/php-5.3.2.tar.gz

  Discuz: http://download.comsenz.com/Discuz/7.2/Discuz_7.2_FULL_SC_UTF8.zip

  PhpMyAdmin: http://219.239.26.14/download/3786632/4780719/2/zip/236/72/1268753528812_584/phpMyAdmin-3.3.1-all-languages.zip

  Awstats:

  http://cdnetworks-kr-2.dl.sourceforge.net/project/awstats/AWStats/6.95/awstats-6.95.tar.gz

  实验环境:RHEL5.4

  Web server:192.168.0.10/24

  Dns server: 192.168.0.20/24

  Clinet: 192.168.0.100/24

  前提条件:

  在所有linux主机上配置yum仓库,把DVD光盘挂在到本地/media下,红色字体代表修改后结果

  [root@localhost ~]# cat /etc/yum.repos.d/rhel-debuginfo.repo

  [rhel-debuginfo]

  name=Red Hat Enterprise Linux $releasever - $basearch - Debug

  baseurl=file:///media/Server //指定本地/media

  enabled=1 //开启仓库

  gpgcheck=1

  gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

  关闭所有linux防火墙与SELINUX

  [root@localhost bin]# iptables -F

  [root@localhost bin]# iptables -X

  [root@localhost bin]# iptables -Z

  [root@localhost bin]# setenforce 0

  [root@localhost bin]# service iptables save

  一、DNS环境的搭建

  1、 安装DNS相关软件包

[root@localhost ~]# yum -y install bind bind-devel bind-chroot caching-nameserver

  2、配置DNS主配置文件

[root@localhost ~]# cd /var/named/chroot/etc/
[root@localhost etc]# cp -p named.caching-nameserver.conf named.conf
[root@localhost etc]# cat named.conf
//
// named.caching-nameserver.conf
//
// Provided by Red Hat caching-nameserver package to configure the
// ISC BIND named(8) DNS server as a caching only nameserver
// (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
// DO NOT EDIT THIS FILE - use system-config-bind or an editor
// to create named.conf - edits to this file will be lost on
// caching-nameserver package upgrade.
//
options {
        listen
-on port 53 { any; };
        listen
-on-v6 port 53 { ::1; };
        directory       "
/var/named";
        
dump-file       "/var/named/data/cache_dump.db";
        
statistics-file "/var/named/data/named_stats.txt";
        memstatistics
-file "/var/named/data/named_mem_stats.txt";

        
// Those options should be used carefully because they disable port
        
// randomization
        
// query-source    port 53;
        
// query-source-v6 port 53;

        allow
-query     { any; };
        allow
-query-cache { any; };
};
logging {
        channel default_debug {
                
file "data/named.run";
                severity dynamic;
        };
};
view localhost_resolver {
        match
-clients      { any; };
        match
-destinations { any; };
        recursion yes;
        include "
/etc/named.rfc1912.zones";
};
[root@localhost etc]# vim named.rfc1912.zones  在文件最后添加
zone "crazylinux.com"
IN {
        type master;
        
file "cl.zheng";
};

zone "google.com"
IN {
        type master;
        
file "g.zheng";
};

zone "
0.168.192.in-addr.arpa" IN {
        type master;
        
file "cl.fan";
};

  3、配置区域文件

[root@localhost etc]# cd /var/named/chroot/var/named/
[root@localhost named]# cp
-p named.zero cl.zheng
[root@localhost named]# cp
-p named.zero g.zheng
[root@localhost named]# cp
-p named.zero cl.fan
[root@localhost named]# cat cl.zheng
$TTL    
86400
@               IN SOA  localhost.      root.localhost. (
                                        
42              ; serial (d. adams)
                                        3H              ; refresh
                                        15M             ; retry
                                        1W              ; expiry
                                        1D )            ; minimum
     
   IN      NS      dns.crazylinux.com.
dns     IN      A      
192.168.0.20
www     IN      A      
192.168.0.10
[root@localhost named]# cat g.zheng
$TTL    
86400
@               IN SOA  localhost.      root.localhost. (
                                        
42              ; serial (d. adams)
                                        3H              ; refresh
                                        15M             ; retry
                                        1W              ; expiry
                                        1D )            ; minimum
      
  IN      NS      dns.google.com.
dns     IN      A      
192.168.0.20
www     IN      A      
192.168.0.10
[root@localhost named]# cat cl.fan
$TTL    
86400
@               IN SOA  localhost.      root.localhost. (
                                        
42              ; serial (d. adams)
                                        3H              ; refresh
                                        15M             ; retry
                                        1W              ; expiry
                                        1D )            ; minimum
  
      IN      NS      dns.crazylinux.com.
20      IN      PTR     dns.crazylinux.com.
20      IN      PTR     dns.google.com.
10      IN      PTR     www.crazylinux.com.
10      IN      PTR     www.google.com.
[root@localhost named]# cat /etc/resolv.conf
nameserver 192.168.0.20
search example.com
[root@localhost named]# service named restart
[root@localhost named]# chkconfig named on

  4、测试DNS

[root@localhost named]# host www.crazylinux.com
www.crazylinux.com has address
192.168.0.10
[root@localhost named]# host www.google.com
www.google.com has address
192.168.0.10

  二、 LAMP环境的搭建

  1、安装APACHE(配置源码包之前先安装GCC环境)

[root@localhost ~]# yum -y install gcc
[root@localhost bin]# rpm
-e httpd --nodeps
[root@localhost media]# tar
-jxvf httpd-2.2.13.tar.bz2 -C /usr/local/src/
[root@localhost httpd
-2.2.13]# ./configure  --prefix=/usr/local/apache2
--enable-so --enable-rewrite
[root@localhost httpd
-2.2.13]# make && make install
做个小技巧,实现开机自动启动APACHE
[root@localhost httpd
-2.2.13]# cd /usr/local/apache2/bin/
[root@localhost bin]# vim apachectl
#
!/bin/sh
#
# chkconfig:
- 85 15
# description: Apache is a World Wide Web server.  It is used to serve \
#              HTML files and CGI.
[root@localhost bin]# cp apachectl
/etc/init.d/apache
[root@localhost bin]# chkconfig
--add apache
[root@localhost bin]# service apache restart
[root@localhost bin]# chkconfig apache on
测试:在clinet上IE中输入服务器的ip
http:
//192.168.0.10

4

  2、 配置个人主页

[root@localhost bin]# vim /usr/local/apache2/conf/httpd.conf  把382行前的#去掉
381 # User home directories
382 Include conf/extra/httpd-userdir.conf
[root@localhost bin]# useradd crazylinux
[root@localhost bin]# su
- crazylinux
[crazylinux@localhost
~]$ mkdir public_html
[crazylinux@localhost
~]$ echo "Crazylinux's Home Page" >> public_html/index.html
[crazylinux@localhost
~]$ chmod o+x /home/crazylinux/
[crazylinux@localhost
~]$ exit
[root@localhost bin]# service apache restart

配置个人主页

  去掉

[root@localhost bin]# vim /usr/local/apache2/conf/extra/httpd-userdir.conf

  在第10行下添加

10 UserDir public_html
11 Alias /crazylinux "/home/crazylinux/public_html"
[root@localhost bin]# service apache restart

配置个人主页

  3、 构建基于域名的虚拟主机

  前提条件

[root@localhost bin]# cat /etc/resolv.conf
nameserver
192.168.0.20
search example.com
[root@localhost bin]# host www.crazylinux.com
www.crazylinux.com has address
192.168.0.10
[root@localhost bin]# host www.google.com
www.google.com has address
192.168.0.10

  开始配置基于域名的虚拟主机

[root@localhost bin]# vim /usr/local/apache2/conf/httpd.conf 把388行前面的#号去掉
387 # Virtual hosts
388 Include conf/extra/httpd-vhosts.conf
[root@localhost bin]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf   修改下面这样
NameVirtualHost 192.168.0.10
<VirtualHost 192.168.0.10>
    DocumentRoot
"/usr/local/apache2/htdocs/crazylinux"
    ServerName www.crazylinux.com
    ErrorLog
"logs/www.crazylinux.com.error.log"
    CustomLog
"logs/www.crazylinux.com.access.log" common
</VirtualHost>

<VirtualHost 192.168.0.10>
    DocumentRoot
"/usr/local/apache2/htdocs/google"
    ServerName www.google.com
    ErrorLog
"logs/www.google.com.error.log"
    CustomLog
"logs/www.google.com.access.log" common
</VirtualHost>
[root@localhost bin]# cd /usr/local/apache2/htdocs/
[root@localhost bin]# cd
/usr/local/apache2/htdocs/
[root@localhost htdocs]# mkdir crazylinux
[root@localhost htdocs]# mkdir google
[root@localhost htdocs]# echo www.crazylinux.com
>> crazylinux/index.html
[root@localhost htdocs]# echo www.google.com
>> google/index.html
[root@localhost htdocs]# service apache restart

  测试:在clinet中指定DNS服务器的ip

构建基于域名的虚拟主机

构建基于域名的虚拟主机

  4、 AB压力测试

  先修改最大文件数限制

[root@localhost htdocs]# ulimit -a | grep "open files"
open files                      (
-n) 1024
[root@localhost htdocs]# ulimit
-n 10000
[root@localhost htdocs]# ulimit
-a | grep "open files"
open files                      (
-n) 10000
[root@localhost htdocs]#
/usr/local/apache2/bin/ab -q -c 2000     \
-n 4000 http://www.crazylinux.com/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright
1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.crazylinux.com (be patient).....done


Server Software:        Apache
/2.2.13
Server Hostname:        www.crazylinux.com
Server Port:            
80

Document Path:          
/
Document Length:        
19 bytes

Concurrency Level:      
2000            //用于并发连接的请求数
Time taken for tests:   8.958 seconds      //测试过程消耗的时间
Complete requests:      4000           //测试过程总共完成的请求数
Failed requests:        0                 //失败的请求数
Write errors:           0
Total transferred:      
1078152 bytes     //测试过程网络传输量
HTML transferred:       76152 bytes     //测试过程中的HTML内容传输量
Requests per second:    446.51 [#/sec] (mean)       //服务器平均每秒相应的请求数
Time per request:       4479.196 [ms] (mean)    //服务器平均每请求的相应时间
Time per request:       2.240 [ms] (mean, across all concurrent requests)
Transfer rate:          
117.53 [Kbytes/sec] received

Connection Times (ms)                        
//连接时间统计信息
              min  mean[+/-sd] median   max
Connect:        
0  535 1262.9      0    4313
Processing:    
1  583 1539.2     42    8389
Waiting:        
0  583 1539.1     42    8386
Total:        
36 1118 2052.6     42    8956

Percentage of the requests served within a certain time (ms)
  
50%     42
  
66%     76
  
75%    864
  
80%   2489
  
90%   4321
  
95%   4609
  
98%   8872
  
99%   8909
100%   8956 (longest request)

  5、使用awstats分析Web日志

[root@localhost media]# tar -zxvf awstats-6.9.tar.gz -C /usr/local/src/
[root@localhost media]# mv
/usr/local/src/awstats-6.9/ /usr/local/src/awstats
[root@localhost media]# cd
/usr/local/src/awstats/tools/
[root@localhost tools]# .
/awstats_configure.pl
And then, run configure.pl from
this location.
Do you want to
continue setup from this NON standard directory [yN] ? y
Warning: You Apache config file contains directives to write
'common' log files
This means that some features can
't work (os, browsers and keywords detection).
Do you want me to setup Apache to write 'combined' log files [y/N] ? y
Do you want me to build a
new AWStats config/profile
file (required
if first install) [y/N] ? y
-----> Define config file name to create
What is the name of your web site or profile analysis
?
Example: www.mysite.com
Example: demo
Your web site, virtual server or profile name:
> www.crazylinux.com
-----> Define config file path
In which directory
do you plan to store your config file(s) ?
Default:
/etc/awstats
Directory path to store config file(s) (Enter
for default):
>

-----> Add update process inside a scheduler
Sorry, configure.pl does not support automatic add to cron yet.
You can
do it manually by adding the following command to your cron:
/usr/local/src/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.crazylinux.com
Or
if you have several config files and prefer having only one command:
/usr/local/src/awstats/tools/awstats_updateall.pl now
Press ENTER to continue...
Press ENTER to finish...

[root@localhost tools]# vim
/etc/awstats/awstats.www.crazylinux.com.conf  把LogFile修改
LogFile="/usr/local/apache2/logs/www.crazylinux.com.access.log"
[root@localhost awstats]# touch /usr/local/apache2/logs/www.crazylinux.com.access.log

  在此先把access.log的日志格式修改一下,这里选择日志的格式为 combined,而不是common,awstats解析不了common

[root@localhost awstats]# cat /usr/local/apache2/conf/extra/httpd-vhosts.conf
NameVirtualHost
192.168.0.10
<VirtualHost 192.168.0.10>
    DocumentRoot
"/usr/local/apache2/htdocs/crazylinux"
    ServerName www.crazylinux.com
    ErrorLog
"logs/www.crazylinux.com.error.log"
    CustomLog
"logs/www.crazylinux.com.access.log" combined
</VirtualHost>

<VirtualHost 192.168.0.10>
    DocumentRoot
"/usr/local/apache2/htdocs/google"
    ServerName www.google.com
    ErrorLog
"logs/www.google.com.error.log"
    CustomLog
"logs/www.google.com.access.log" common
</VirtualHost>
[root@localhost awstats]# perl
/usr/local/src/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.crazylinux.com
Create
/Update database for config "/etc/awstats/awstats.www.crazylinux.com.conf" by AWStats version 6.9 (build 1.925)
From data in log file
"/usr/local/apache2/logs/www.crazylinux.com.access.log"...
Phase
1 : First bypass old records, searching new record...
Direct access after last parsed record (after line
57)
Jumped lines in file:
57
Found
57 already parsed records.
Parsed lines in file:
8675
Found
0 dropped records,
Found
0 corrupted records,
Found
0 old records,
Found
8675 new qualified records.
[root@localhost tmp]# crontab
-l
* */5 * * * /usr/bin/perl /usr/local/src/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.crazylinux.com
[root@localhost tmp]# service crond restart
Stopping crond: [  OK  ]
Starting crond: [  OK  ]
[root@localhost tmp]# chkconfig crond on

  在之前把APACHE全局的CustomLog注释掉

#CustomLog "logs/access_log" combined
测试:
[root@localhost
~]# cat /usr/local/apache2/htdocs/crazylinux/awstats.html
<html>
<head>
<meta http-equiv=refresh content="0;url=http://www.crazylinux.com/awstats/awstats.pl?
config=www.crazylinux.com">
</head>
<body>
</body>
</html>

  在client上IE中输入http://www.crazylinux.com/awstats.html

使用awstats分析Web日志

  6、对awstats进行访问控制

<Directory "/usr/local/src/awstats/wwwroot">
    
AuthName "Awstats"
    AuthType Basic
    AuthUserFile
/usr/local/src/awstats/wwwroot/.htpasswd
    require user awuser
    Options None
    AllowOverride AuthConfig
    Order allow,deny
    Allow from all
</Directory>
[root@localhost
~]# /usr/local/apache2/bin/htpasswd
-c /usr/local/src/awstats/wwwroot/.htpasswd awuser
New password:
Re
-type new password:
Adding password
for user awuser
[root@localhost
~]# service apache restart

  [root@localhost ~]# vim /usr/local/apache2/conf/httpd.conf 在里面查到与awstats相关信息

  测试:在client中IE输入http://www.crazylinux.com/awstats.html

对awstats进行访问控制

  7、安装配置MYSQL

[root@localhost media]# tar -zxvf mysql-5.0.75.tar.gz -C /usr/local/src/
[root@localhost media]# cd
/usr/local/src/mysql-5.0.75/
[root@localhost mysql
-5.0.75]# useradd -M -s /sbin/nologin mysql
[root@localhost mysql
-5.0.75]# yum -y install libtermcap-devel

安装配置MYSQL

[root@localhost mysql-5.0.75]# ./configure --prefix=/usr/local/mysql --with-mysqlduser=mysql
[root@localhost mysql
-5.0.75]# make
[root@localhost mysql
-5.0.75]# make install
[root@localhost mysql
-5.0.75]# cp support-files/my-medium.cnf /etc/my.cnf
[root@localhost mysql
-5.0.75]# /usr/local/mysql/bin/mysql_install_db --user=mysql
[root@localhost mysql
-5.0.75]# chown -R root:mysql /usr/local/mysql/
[root@localhost mysql
-5.0.75]# chown -R mysql /usr/local/mysql/var/
[root@localhost mysql
-5.0.75]# echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf
[root@localhost mysql
-5.0.75]# ldconfig
[root@localhost mysql
-5.0.75]# /usr/local/mysql/bin/mysqld_safe --user=mysql &
[root@localhost mysql
-5.0.75]# ps -e | grep mysql   验证是否成功开启mysql
1664 pts/2    00:00:00 mysqld_safe
1690 pts/2    00:00:00 mysqld
[root@localhost mysql
-5.0.75]# netstat -ntulp | grep mysql
tcp     0  0 0.0.0.0:3306    0.0.0.0:*               LISTEN      1690/mysqld
[root@localhost mysql-5.0.75]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql
-5.0.75]# chmod +x /etc/init.d/mysqld
[root@localhost mysql
-5.0.75]# chkconfig --add mysqld
[root@localhost mysql
-5.0.75]# chkconfig mysqld on
[root@localhost mysql
-5.0.75]# export PATH=$PATH:/usr/local/mysql/bin/
[root@localhost mysql
-5.0.75]# echo "PATH=$PATH:/usr/local/mysql/bin/" >> /etc/profile
[root@localhost mysql
-5.0.75]# mysqladmin -u root password 123456   //修改mysql密码

  8、安装配置PHP

[root@localhost media]# tar -jxvf php-5.2.10.tar.bz2 -C /usr/local/src/
[root@localhost media]# cd
/usr/local/src/php-5.2.10/
[root@localhost php
-5.2.10]# ./configure --prefix=/usr/local/php5
--enable-mbstring --with-apxs2=/usr/local/apache2/bin/apxs
--with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php5
[root@localhost php
-5.2.10]# make && make install
[root@localhost php
-5.2.10]# cp php.ini-dist /usr/local/php5/php.ini
在APACHE里添加php,使APACHE支持PHP
[root@localhost php
-5.2.10]# vim /usr/local/apache2/conf/httpd.conf
LoadModule php5_module        modules
/libphp5.so
AddType application/x-httpd-php .php
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>
[root@localhost php
-5.2.10]# cat /usr/local/apache2/htdocs/crazylinux/index.php
<?php
        phpinfo();
?>
[root@localhost php
-5.2.10]# service apache restart

  测试:在client的IE中输入http://www.crazylinux.com

安装配置PHP

  9、测试PHP与APACHE的协同工作

[root@localhost php-5.2.10]# cd /usr/local/apache2/htdocs/crazylinux/
[root@localhost crazylinux]# cat testdb.php

测试PHP与APACHE的协同工作

  在APACHE本机测试:(在client测试的话需要mysql授权,比较麻烦)需要先安装firefox浏览器

测试PHP与APACHE的协同工作

  10、架设Discuz论坛

[root@localhost media]# cp Discuz_7.2_FULL_SC_UTF8.zip /home/
[root@localhost media]# mysql
-uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is
63
Server version:
5.0.75-log Source distribution

Type
'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql
> create database bbsdb;
Query OK,
1 row affected (0.01 sec)

mysql
> grant all on bbsdb.* to runbbs@localhost identified by '123456';
Query OK,
0 rows affected (0.01 sec)

mysql
> quit
Bye
[root@localhost media]# cd
/home/
[root@localhost home]# unzip Discuz_7.2_FULL_SC_UTF8.zip
-d discus
[root@localhost home]# mv discuz
/upload/ /usr/local/apache2/htdocs/google/bbs
[root@localhost bbs]# chown
-R daemon config.inc.php attachments forumdata/ uc_client/data/cache/

安装向导图

安装向导图

安装向导图

安装向导图

安装向导图

安装向导图

安装向导图

[root@localhost bbs]# mv install/ install.lock
[root@localhost bbs]# chmod o
-rx install.lock/

  11、安装phpMyAdmin数据库管理套件

[root@localhost media]# tar -zxvf phpMyAdmin-3.3.1-all-languages.tar.gz
-C /usr/local/apache2/htdocs/google/
[root@localhost media]# cd
/usr/local/apache2/htdocs/google/
[root@localhost google]# mv phpMyAdmin
-3.3.1-all-languages/ phpMyAdmin
[root@localhost google]# cd phpMyAdmin
/
[root@localhost phpMyAdmin]# cp config.sample.inc.php config.inc.php
[root@localhost phpMyAdmin]# vim config.inc.php
$cfg[
'blowfish_secret'] = '123456'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

安装phpMyAdmin数据库管理套件

安装phpMyAdmin数据库管理套件

0
相关文章