准备软件:
1. J2SDK(1.6.0): jdk-6u10-rc-bin-b28-linux-i586-21_jul_2008-rpm.bin
2. Apache(2.2.9): httpd-2.2.9.tar.gz
3. Resin(3.1.6): resin-3.1.6.tar.gz
4. MySQL(5.0.22): Server: mysql-5.0.22.tar.gz
5. MySQL-JDBC Connector: mysql-connector-java-5.1.6.tar.gz
一.安装MYSQL
#./configure –prefix=/usr/local/mysq –with-charset=gbk
配置过程中我们要给mysql设置一个安装目录,我们设置在 /usr/local/mysql 下,以为把文件放到一个地方比较容易管理,如果你还想获得更多的配置信息,使用 ./configure –help:
在这里我要特别强调在 编译的时候要选择好MYSQL的默认编码,因为如果不选择按默认安装的时候在JSP中就不支持GBK编码了
# make
# make install
# cp support-files/my-medium.cnf /etc/my.cnf 复制MYSQL主配置文件,
注:BLOG中有MySql主配置文件说明详细介绍
设置自启动MYSQL
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld复制MYSQL启动脚本
# chmod 700 /etc/rc.d/init.d/mysqld 设权限为执行。Chmod +x也可以达到同样效果
# chkconfig –add mysqld添加系统服务
# groupadd mysql #建立mysql组
# useradd -g mysql mysql #建立mysql用户并且加入到mysql组中
建立用户后我们就初始化表 (注意:必须先执行本步骤后才能进行以下步骤)
#cd /usr/local/mysql
# /usr/local/mysql/bin/mysql_install_db –user=mysql #初试化表并且规定用mysql用户来访问初始化表以后就开始给mysql和root用户设定访问权限, 我们先到安装mysql的目录:
然后设置权限
# chown -R root . #设定root能访问/usr/local/mysql
# chown -R mysql var #设定mysql用户能访问/usr/local/mysql/var ,里面存的是mysql的数据库文件
# chown -R mysql var/. #设定mysql用户能访问/usr/local/mysql/var下的所有文件
# chown -R mysql var/mysql/. #设定mysql用户能访问/usr/local/mysql/var/mysql下的所有文件
# chgrp -R mysql . #设定mysql组能够访问/usr/local/mysql
设置完成后,基本上就装好了,好了,我们运行一下我们的mysql:
# /usr/local/mysql/bin/mysqld_safe –user=mysql &
如果没有问题的话,应该会出现类似这样的提示:
[1] 42264
# Starting mysqld daemon with databases from /usr/local/mysql/var
这就证明你安装成功了
# /etc/rc.d/init.d/mysqld start 启动MYSQL
# ln -s /usr/local/mysql/bin/mysql /sbin/mysql
# ln -s /usr/local/mysql/bin/mysqladmin /sbin/mysqladmin
为了能让系统找到mysql,请运行如下命令
# PATH=$PATH:/usr/local/mysql/bin
# export PATH
# echo “/usr/local/mysql/lib/mysql” >;>; /etc/ld.so.conf
# ldconfig
日志管理
开启错误日志 (在[safe_mysqld]项下添加)
# vi /etc/my.cnf
[safe_mysqld]
err-log=/var/log/mysqld/err.log
开启常规日志和更新日志 (在[mysqld]项下添加)
# vi /etc/my.cnf
[mysqld]
log=/var/log/mysqld/log.log
log-update=/var/log/mysqld/update.log
创建日志文件并设置权限
# mkdir /var/log/mysqld
# touch /var/log/mysqld/err.log /var/log/mysqld/log.log /var/log/mysqld/update.log
# chown -R mysql.mysql /var/log/mysqld
# service mysqld restart
说明:
错误日志包含了服务器写入标准错误输出设备的所有消息,同时还包括了mysql服务的启动和关闭事件
常规日志用来记录有关mysql服务器运行的常规信息,包括用户的连接、查询及其他各种时间
更新日志用来记录修改数据库的查询信息,包括所有涉及数据库修改的SQl语句的查询记录
建议调试结束后关闭日志
用如下命令修改MYSQL密码,默认安装密码为空,为了安全你必须马上修改
/usr/local/mysql/bin/mysqladmin -uroot password xuefeng
现在修改的密码为:xuefeng
二.安装JDK
# chmod u+x ./ jdk-6u10-rc-bin-b28-linux-i586-21_jul_2008-rpm.bin加执行权限
# ./ jdk-6u10-rc-bin-b28-linux-i586-21_jul_2008-rpm.bin解压
# rpm -ivh jdk-6u10-rc-linux-i586.rpm安装程序会将J2SDK安装到/usr/java
设置JDK变量环境
# vi /etc/profile
添加如下
PATH=$PATH:/usr/java/jdk1.6.0_10/bin
export PATH
JAVA_HOME=/usr/java/jdk1.6.0_10
export JAVA_HOME
CLASSPATH=.:/usr/java/jdk1.6.0_10/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/htmlconverter.jar:/usr/local/resin/lib:/usr/java/jdbc/mysql-connector-java-5.1.6-bin.jar
export CLASSPATH
RESIN_HOME=/usr/java/resin
export RESIN_HOME
USERNAME=”root”
export USERNAME
#source /etc/profile 强制刷新生效
[root@localhost /]# java -version
java version “1.4.2”
gcj (GCC) 3.4.6 20060404 (Red Hat 3.4.6-8)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
看到类似信息就表示jdk环境已经好了。其实在上面的/etc/profile中,我们不仅仅设置了jdk的环境变量,还一并设置了resin和jdbc的环境变量,这些都是后面安装resin所必需的设定
三、安装mysql的jdbc
# tar -zxvf mysql-connector-java-5.1.6.tar.gz
#mv mysql-connector-java-5.1.6 /usr/java/将解压的文件剪切到/usr/java/目录下。
#cd /usr/java/
# ln -s mysql-connector-java-5.1.6/ jdbc创建JDBC的软连接与/usr/java/目录下
四.安装APACHE
# tar -zxvf httpd-2.2.9.tar.gz
#cd httpd-2.2.9
修改include/httpd.h 增大最大线程数
vi include/httpd.h
找到DEFAULT_KEEPALIVE 100
?define DEFAULT_KEEPALIVE 100
在这段下面加上一段
#ifndef HARD_SERVER_LIMIT
#define HARD_SERVER_LIMIT 2000
#endif
保存退出编译apache
# ./configure –prefix=/usr/local/apache –enable-so
apache支持dso方式了。这样就可以用dso的方式把php和resin的模块加进来
#make
#make install
#/usr/local/apache/bin/httpd –l 查看加载模块
Compiled in modules:
core.c
mod_authn_file.c
mod_authn_default.c
mod_authz_host.c
mod_authz_groupfile.c
mod_authz_user.c
mod_authz_default.c
mod_auth_basic.c
mod_include.c
mod_filter.c
mod_log_config.c
mod_env.c
mod_setenvif.c
prefork.c
http_core.c
mod_mime.c
mod_status.c
mod_autoindex.c
mod_asis.c
mod_cgi.c
mod_negotiation.c
mod_dir.c
mod_actions.c
mod_userdir.c
mod_alias.c
mod_so.c
哈哈加载成功了
设置自启动
# vi /etc/rc.d/rc.local
如下,添加/usr/local/apache/bin/httpd -k start
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don’t
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
/usr/local/apache/bin/httpd -k start
创建网页根目录
# mkdir /var/www
# vi /usr/local/apache/conf/httpd.conf
//存放网页的目录,原来为DocumentRoot “”,改成:
DocumentRoot “/var/www”
//这句应该和DocumentRoot 的目录保持一致,原来为;,改成:
;
//Indexes:当在目录中找不到DirectoryIndex列表中指定的文件就生成当前目录的文件列表
//FollowSymlinks:允许符号链接跟随,访问不在本目录下的文件
Options Indexes FollowSymLinks
//禁止读取.htaccess配置文件的内容
AllowOverride None
//指定先执行Allow(允许)访问规则,再执行Deny(拒绝)访问规则
Order allow,deny
//设置Allow(允许)访问规则,允许所有连接
Allow from all
创建线程数
#vi httpd
添加如下
<IfModule prefork.c>
StartServers 10
MinSpareServers 20
MaxSpareServers 20
ServerLimit 2000
MaxClients 2000
MaxRequestsPerChild 10000
</IfModule>
编译之前我们修改过线程数,可是如果不加这条,2000线程无法达到。
启动服务:
# /usr/local/apache/bin/apachectl start
或
#cp support/apachectl /etc/init.d/httpd
#vi /etc/init.d/httpd
加入
# chkconfig: – 85 15
# description: httpd is a World Wide Web server. It is used to serve 注:不加这两条无法创建服务启动
#chkconfig –add httpd
# service httpd start
五.安装PHP
#./configure –prefix=/usr/local/php –with-mysql=/usr/local/mysql –enable-force-cgi-redirect –with-freetype-dir=/usr –with-png-dir=/usr –with-gd –enable-gd-native-ttf –with-ttf –with-gdbm –with-gettext –with-iconv –with-jpeg-dir=/usr –with-zlib –with-xmlrpc –enable-calendar –enable-mbstring –with-apxs2=/usr/local/apache/bin/apxs
#make
#make install
#这里由于服务器需要用到GD库,所以加了一些支持GD的编译参数,GD直接用了redhat自带的GD库,大家没有安装的话可以从安装盘安装,注意除了安装GD以外,还要安装libjpeg,libpng等库文件。另外–with-mysql=/usr/local/mysql指向你安装mysql的路径。–with-apxs指向apache的apxs文件的路径。在配置过程中,除了指定安装目录外,还有-with-apxs2和-with-mysql这两个选项。-with-apxs2的作用是与 apache的工具apxs配合,产生模块文件到目录/usr/local/apache/modules/,同时在apache的配置文件中写入一行 “LoadModule php5_module modules/libphp5.so”;
#vi /usr/local/apache/conf/httpd.conf
找到#AddType application 这行,在下面加两行。
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
找到下面一行在后面加上index.php和index.jsp,这表示网站的默认页也能够为index.php
DirectoryIndex index.html index.html.var index.php index.jsp
注意:改变了http.conf后,要重启apache服务器,否则不会生效
然CPOPY PHP的配置文件
#cp php.ini-dist /usr/local/php/lib/php.ini
修改php.ini文件
register_globals = On
default_charset = “iso-8859-1”在下添加default_charset = “gbk”
检查一下apache配置文件是否正确(/usr/local/apache/bin/apachectl -t),输出“Syntax OK”后就可以启动
ok!重新启动一下apache服务器
#/usr/local/apache/bin/apachectl restart
然后在/var/www目录下写个php测试页info.php:内容如下
<?php
phpinfo();
?>
保存此文件, 在你的浏览器中输入http://localhost/phpinfo.php,你应该看到PHP的系统信息。
如果出现错误,比如提示你下灾phpinfo.php,那么apache就是还无法解析php文件,那么请仔细检查以上的操作是否正确.
六.安装RESIN
# tar -zxvf resin-3.1.6.tar.gz
# mv resin-3.1.6 /usr/java
# ln –s resin-3.1.6/ resin
启动resin
# /usr/java/resin/bin/httpd.sh start
现在就能够从http://localhost:8080/上能看到resin的页面,这也就表示单独的resin运行成功了。然后,为了整合resin和apache,我们需要重新编译一下,以生成mod_caucho给apache调用。
# cd /usr/java/resin
# ./configure –with-java-home= jdk1.6.0_10 –with-apxs=/usr/local/apache/bin/apxs
# make
# make install
修改/usr/java/resin/conf/resin.conf,大约在最后(安装的resin版本不同,配置文件的内容可能有所不同),将<document-directory>修改成自己的apache的documentroot的值。
<web-app id=”/” root-directory=”/webpps/ROOT”/> ##这里修改成/var/www
最后#vi /usr/local/apache/conf/httpd.conf
CauchoStatus yes下面
添加以下内容
<location /caucho-status>
sethandler caucho-status
</location>
重服务服务
/usr/local/apache/bin/httpd –k restart
/usr/java/resin/bin/httpd.sh restart
测试
将test.jsp文件:
2+2=<%=2+2%>
放到目录/var/www中
访问:
http://localhost/test.jsp
如能正常显示2+2=4,则说明成功.
哈哈,大告成功