实验环境:
两台机器:Centos6.4
机器一: 192.168.56.10 安装httpd php 等整合
机器二: 192.168.56.11 安装 mysql
========================================================================================
(iptables -t nat -I PREROUTING -d 外IP -p tcp -m tcp --dport 端口 -j DNAT --to-destination 外网IP:端口)
========================================================================================
机器一:
1. yum -y install *libxml2* httpd* PHP* *gcc* mysql mysql-devel ( 这里的mysql 是客户端)
vim /etc/hosts
192.168.56.10 www.example.com
192.168.56.10 web.example.com
vim /etc/httpd/conf/httpd.conf
修改:ServerName www.example.com:80
DirectoryIndex index.html index.html.var index.php
NameVirtualHost 192.168.56.10:80 //开启虚拟主机
<VirtualHost 192.168.56.10:80>
ServerAdmin www.example.com
DocumentRoot /var/www/html
ServerName www.example.com
ErrorLog logs/www.example.com-error_log
CustomLog logs/www.example.com-access_log common
</VirtualHost>
2. 解压phpMyadmin-*
cp -RV phpmyadmin-* /var/www/html/phpmyadmin
cd /var/www/html/phpmyadmin
mv config.sample.inc.php config.sample.inc.php.bak
cp config.sample.inc.php.bak config.inc.php
vim config.inc.php
$cfg['blowfish_secret'] = 'redhat'; //随便指定,不为空
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['host'] = '192.168.56.11';//指定mysql 数据库地址
$cfg['Servers'][$i]['controluser'] = 'root';
$cfg['Servers'][$i]['controlpass'] = 'redhat'; //指定mysql 数据库的用户名和密码
$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
$cfg['Servers'][$i]['bookmarktable'] = 'pma_bookmark';
$cfg['Servers'][$i]['relation'] = 'pma_relation';
$cfg['Servers'][$i]['table_info'] = 'pma_table_info';
$cfg['Servers'][$i]['table_coords'] = 'pma_table_coords';
$cfg['Servers'][$i]['pdf_pages'] = 'pma_pdf_pages';
$cfg['Servers'][$i]['column_info'] = 'pma_column_info';
$cfg['Servers'][$i]['history'] = 'pma_history';
$cfg['Servers'][$i]['tracking'] = 'pma_tracking';
$cfg['Servers'][$i]['designer_coords'] = 'pma_designer_coords';
vim libraries/config.default.php
$cfg['blowfish_secret'] = 'redhat';
$cfg['Servers'][$i]['host'] = '192.168.56.11';
$cfg['Servers'][$i]['port'] = '3306'; //指定Mysql 数据库端口
$cfg['Servers'][$i]['controluser'] = 'root';
$cfg['Servers'][$i]['controlpass'] = 'redhat';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'redhat';
//这个里面默认的为空,找到他们写入跟上面一样的数值:
$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
$cfg['Servers'][$i]['bookmarktable'] = 'pma_bookmark';
$cfg['Servers'][$i]['relation'] = 'pma_relation';
$cfg['Servers'][$i]['table_info'] = 'pma_table_info';
$cfg['Servers'][$i]['table_coords'] = 'pma_table_coords';
$cfg['Servers'][$i]['pdf_pages'] = 'pma_pdf_pages';
$cfg['Servers'][$i]['column_info'] = 'pma_column_info';
$cfg['Servers'][$i]['history'] = 'pma_history';
$cfg['Servers'][$i]['tracking'] = 'pma_tracking';
$cfg['Servers'][$i]['designer_coords'] = 'pma_designer_coords';
===============================================================
客户端输入192.168.56.10/phpmyadmin 会报 mcrypt 插件错误:yum 安装PHP 没有mcrypt的插件。源码安装PHP你又必须指定 Mysql的安装位置。由于数据库和PHP分两台机器没法指定mysql的安装位置。所以我们采用编译安装模块。
========================================================================
1。开始编译 安装:libmcrypt-2.5.8
./configure make && make install
2。开始编译 安装:mhash-0.9.9.9
/configure make && make install
3。开始编译 安装:mcrypt-2.6.8
/configure make && make install
===================================================================
以上三个包编译安装为了一个目的就是解决 php 没有 mcrypt.so 模块的问题
====================================================================
4。开始编译 源码PHP :(只编译不安装)php-5.2.13
./configure --with-mcrypt
5. 编译完成以后,进入解压以后源码包的存放mcrypt的目录下
cd php-5.2.13/ext/mcrypt/
===========================================================
phpize 敲这条命令
aclocal 再敲这条命令
如果没有phpize 这条命令你需要安装php-devel.
亲身试验RHEL 光盘包没这个包。而centos里面有这个包。
敲这条命令的目的是为了在 mcrypt生产 configure 文件 。默认没有configure的
=====================================================================
6. 然后安装执行:
cd php-5.2.13/ext/mcrypt/
./configure
make clean
make
make install
7. 现在php的安装目录下面应该有了mcrypt.so 的文件了。
实在不清楚在哪里就用命令找一下
find / -name mcrypt.so
我找到的在这个路径下 :
/usr/lib64/php/modules/mcrypt.so
/tmp/php-5.2.13/ext/mcrypt/modules/mcrypt.so
/tmp/php-5.2.13/ext/mcrypt/.libs/mcrypt.so
==========================================================================
8。 最后一步,把mcrypt.so 让php 调用识别就行了 :
vim /etc/php.ini
extension=mcrypt.so
service httpd restart
========================================================================
有些报错可能会遇到,我没遇到;这里就标识出来吧:
特别注意:
1、phpize需在解压后的源码包下执行,执行后生成configure脚本
2、运行./configure时,如果提示
configure: error: Cannot find php-config. Please use --with-php-config=PATH
请使用:
./configure --with-php-config=/php-install-path/bin/php-config #而不是使用php.ini
==============================================================================
机器二: 192.168.56.11 比较简单
yum -y install mysql*
service mysqld restart
mysqladmin -u root password redhat
mysql -u root -p
输入密码进入mysql:
use mysql;
select host, user,password from user;
//查看到的只有本地的连接
| host | user | password |
+-----------------------+------+-------------------------------------------+
| localhost | root | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |
| SERVER-11.example.com | root | |
| 127.0.0.1 | root | |
| localhost | | |
| SERVER-11.example.com | |
//所以,我们要添加远程能够连接:
GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY 'redhat';
root@% root 是你mysql的用户名 % 代表所有主机: 这里可以写IP:如 [email protected]
BY 指定的是你root的密码 :(这里的密码和上面PHPMyadmin 里面保持一致)
flush privileges; //使修改即时生效
=================================================================================
再用select host, user,password from user; 查看
+-----------------------+------+-------------------------------------------+
| host | user | password |
+-----------------------+------+-------------------------------------------+
| localhost | root | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |
| SERVER-11.example.com | root | |
| 127.0.0.1 | root | |
| localhost | | |
| SERVER-11.example.com | | |
| % | root | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |
+-----------------------+------+-------------------------------------------+
=====================解决完成mcrypt.so完===================================
==========================================================================
安装 Discuz动网论坛
1. 修改php.ini
vim /etc/php.ini
short_open_tag = on
2. 解压论坛:unzip Discuz_7.2_FULL_SC_UTF8.zip -d discus
mv discus/upload/* /var/www/htlm/bbs
service httpd restart
浏览器打开:http://192.168.56.10/bbs/install/index.php
点击安装下一步,会出现 什么不可读写,需要下一步把红色部分变成读写:
解决方法:(权限必须777;755试了还是不能写)
cd /var/www/html/bbs
chmod -R 777 config.inc.php attachments/
chmod -R 777 forumdata/ uc_client/data/cache/
service httpd restart
=========================================================================
在数据库服务器上创建bbs的数据库:192.168.56.11
create database discuz;
=========================================================================
在浏览器输入http://192.168.56.10/bbs/install/index.php 下一步,下一步。
指定数据库服务器:92.168.56.11
数据库名字:discuz
数据库用户名:root
数据库密码:redhat
数据库表前缀:cdb_discuz
下面写管理员密码:
安装完成: http://192.168.56.10/bbs
网站前台:http://www.example.com/bbs/index.php
访问bbs后台:http://www.example.com/bbs/admincp.php
=============================================================
有些情况出不来页面就把instll.php 删除
root@localhost bbs]# mv install/ install.lock
[root@localhost bbs]# chmod o-rx install.lock/
这两步不操作也可成功:
==============================================================
额外操作:可以不做,没实质意义:
AB 压力测试 :
[root@localhost ~]# ulimit -a | grep "open files"
open files (-n) 1024
[root@localhost ~]# ulimit -n 10000
[root@localhost ~]# ulimit -a | grep "open files"
open files (-n) 10000
[root@localhost ~]#ab -c 2000 -n 4000 http://192.168.56.10/bbs/
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)
apr_socket_recv: Connection reset by peer (104)
Total of 331 requests completed
Server Software: Apache/2.2.15
Server Hostname: www.example.com
Server Port: 80
Document Path: /bbs/
Document Length: 7710 bytes
Concurrency Level: 2000 //用于并发连接的请求数
Time taken for tests: 75.946 seconds //测试过程消耗的时间
Complete requests: 331 //测试过程总共完成的请求数
Failed requests: 330 //失败的请求数
(Connect: 0, Receive: 1, Length: 330, Exceptions: 0)
Write errors: 0
Total transferred: 2675927 bytes //测试过程网络传输量
HTML transferred: 2559063 bytes //测试过程中的HTML内容传输量
Requests per second: 4.36 [#/sec] (mean) //服务器平均每秒相应的请求数
Time per request: 458886.079 [ms] (mean) //服务器平均每请求的相应时间
Time per request: 229.443 [ms] (mean, across all concurrent requests) //每个请求实际运行时间的平均值
Transfer rate: 34.41 [Kbytes/sec] received //平均每秒网络上的流量,可以帮助排除是否存在网络流量过大导致响应时间延长的问题
Connection Times (ms) //连接时间统计信息
min mean[+/-sd] median max
Connect: 0 330 823.9 270 3837
Processing: 191 4977 4422.9 2976 26613
Waiting: 174 4976 4419.4 2976 26550
Total: 514 5308 4778.8 2999 27018
Percentage of the requests served within a certain time (ms)
50% 2999
66% 5421
75% 6967
80% 8983
90% 13226
95% 17052
98% 17610
99% 19567
100% 27018 (longest request)
//整个场景中所有请求的响应情况。在场景中每个请求都有一个响应时间,其中50%的用户响应时间小于2999毫秒,60% 的用户响应时间小于5421毫秒,最大的响应时间小于27018毫秒 由于对于并发请求,cpu实际上并不是同时处理的,而是按照每个请求获得的时间片逐个轮转处理的,所以基本上
================================================================================
使用awstats 分析web 日志:
tar -zxvf awstats-6.95.tar.gz
mv awstats-6.95/ /usr/local/awstats
cd /usr/local/awstats/tools/
./awstats_configure.pl
指定你的http安装的路径,我是yum安装的,所以指定:
> /etc/httpd/conf/httpd.conf
输入两个Y
输入网站域名;www.example.com
vim /etc/awstats/awstats.www.example.com.conf
52 LogFile="/var/log/httpd/www.example.com-access_log"
在此先把access.log的日志格式修改一下 这里选择日志的格式为 combined,而不是common,awstats解析不了common
<VirtualHost 192.168.56.10>
DocumentRoot "/var/www/html"
ServerName www.example.com
ServerAlias www.francis.com
ErrorLog "logs/www.example.com-error_log"
CustomLog "logs/www.example.com-access_log" combined
</VirtualHost>
=============================================================
<VirtualHost 192.168.56.10>
DocumentRoot "/var/www/vir"
ServerName www.google.com
ErrorLog "logs/www.google.com-error_log"
CustomLog "logs/www.google.com-access_log" common
</VirtualHo>
===========================================================
cd /usr/local/awstats/
mkdir /var/lib/awstats
perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=192.168.56.10
注意:-config= 如果有DNS 用域名。如果没有DNS 用IP
===============================================================================
正确信息:cd /var/log/httpd/ rm -rf * (删除apche生成的日志。重新生成日志)
[root@SERVER-10 httpd]# perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=192.168.56.10 -update
Create/Update database for config "/etc/awstats/awstats.192.168.56.10.conf" by AWStats version 6.95 (build 1.943)
From data in log file "/var/log/httpd/www.example.com-access_log"...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
Jumped lines in file: 0
Parsed lines in file: 0
Found 0 dropped records,
Found 0 corrupted records,
Found 0 old records,
Found 0 new qualified records.
================================================================================
开启计划任务:
crontab -e
*/5 * * * * /usr/bin/perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.example.com(192.168.56.10)
service crond restart
chkconfig crond on
==============================================================================
cd /var/www/html/bbs/
vim awstats.html
<html>
<head>
<meta http-equiv=refresh content="0;url=http://www.example.com/awstats/awstats.pl
-config=192.168.56.10">
</head>
<body>
</body>
</html>
客户端输入 :192.168.56.10/bbs/awstats.html 看见一个网页
=====================================================================
这个 访问控制可以不做
=====================================================================
对awstats进行访问控制
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf 在里面查到与awstats相关信息
423 <Directory "/usr/local/awstats/wwwroot">
424 AuthName "Awstats"
425 AuthType Basic
426 AuthUserFile /usr/local/awstats/wwwroot/.htpasswd
427 require user awuser
428 Options None
429 AllowOverride AuthConfig
430 Order allow,deny
431 Allow from all
432 </Directory>
[root@localhost ~]# htpasswd -cm /usr/local/awstats/wwwroot/.htpasswd awuser
===================================================================================
搭建 Apache +tomcat 实现读取JSP 程序
[root@localhost local]# cat HelloWorld.java
public class HelloWorld {
public static void main(String args[]){
System.out.println("HelloWorld !!");
}
}
[root@localhost local]# javac HelloWorld.java //编译程序
[root@localhost local]# java HelloWorld //执行程序
HelloWorld !!
[root@localhost home]# tar -zxvf apache-tomcat-6.0.18.tar.gz -C /usr/local/src/
[root@localhost home]# ln -sf /usr/local/src/apache-tomcat-6.0.18 /usr/local/tomcat
[root@localhost home]# ln -sf /usr/local/tomcat/bin/startup.sh /usr/bin/tomcat-up
[root@localhost home]# ln -sf /usr/local/tomcat/bin/shutdown.sh /usr/bin/tomcat-down
[root@localhost home]# vim /usr/local/tomcat/conf/tomcat-users.xml
18 <tomcat-users>
19 <user username="crazy" password="linux" roles="manager,admin"/>
20 <!--
21 <role rolename="tomcat"/>
22 <role rolename="role1"/>
23 <user username="tomcat" password="tomcat" roles="tomcat"/>
24 <user username="both" password="tomcat" roles="tomcat,role1"/>
25 <user username="role1" password="tomcat" roles="role1"/>
26 -->
27 </tomcat-users>
[root@localhost home]# tomcat-up
[root@localhost home]# netstat -nutlp | grep java
tcp 0 0 ::ffff:127.0.0.1:8005 :::* LISTEN 3526/java
tcp 0 0 :::8009 :::* LISTEN 3526/java
tcp 0 0 :::8080 :::* LISTEN 3526/java
=====================================================
客户端输入192.168.56.10:8080 选择tomcat-manager
输入 root redhat 管理tomcat
cp mod_jk-1.2.28-httpd-2.2.X.so /etc/httpd/modules/
vim /etc/httpd/conf/httpd.conf
AddType application/x-jsp .jsp
cd /usr/local/tomcat/webapps
mkdir -p /var/www/html/apps
ln -sf /var/www/html/ web-apps1
vim /var/www/html/apps/showtime.jsp
<%@page language="java" import="java.util.*" %>
Now,the time&date is:<%out.println(new Date()); %>
======================================================
客户端 输入:http://192.168.56.10:8080/web-apps1/apps/showtime.jsp
Now,the time&date is:Thu Jul 10 23:37:11 CST 2014