CentOS5.2 jsp服务器

1.安装CentOS
什么是CentOS?百度去。。下iso,刻盘,安装。分区的时候注意,手动分区,/usr和/var要拎出来单独设置挂载点,/opt放软件也可以设置挂载点,/boot给个512M绰绰有余,接下去/home、/、SWAP,其他的随便。。
然后定制软件的时候,不要装万维网发布服务器(默认的是Apache2.2.3),我们自己手动装。
防火墙开启,SELinux就关了吧,很烦。
2.配置国内源(CentOS USTC mirror)系统更新
# cd /etc/yum.repos.d
# mv CentOS-Base.repo  CentOS-Base.repo.save
# wget http://centos.ustc.edu.cn/CentOS-Base.repo.5
# mv CentOS-Base.repo.5 CentOS-Base.repo
3.gcc安装
很重要,我们要编译很多东西,必须用到gcc(不安装下边的./configure 和make命令不能用)
# yum install gcc
4.Apache2安装(下载最新版本)
下载httpd-2.2.10.tar.gz和zlib-1.2.3.tar.gz。
可以使用wget http://labs.xiaonei.com/apache-mirror/httpd/httpd-2.2.11.tar.gz下载后默认在root文件下。(wget url(官方找地址))
安装zlib,这个必须装,不然mod_deflate(压缩网页提高速度)出不来,死的很难看
# tar zxvf zlib-1.2.3.tar.gz
# cd zlib-1.2.3
# ./configure --prefix=/usr/local/apache2
# make;make install
接下去安装Apache
# tar xzvf httpd-2.2.0.tar.gz
# cd httpd-2.2.0
# ./configure --prefix=/usr/local/apache2 --enable-so --enable-mods-shared=all --enable-rewrite --enable-deflate --with-mpm=worker --with-z=/usr/local/apache2
# make;make install
# cd /usr/local/apache2/bin
# ./apachectl start
如果启动错误,打不开页面。执行下边语句。
chcon -t textrel_shlib_t '/usr/local/apache2/modules/mod_deflate.so'
打开FF,输入http://localhost,看到It's work!安装成功。
然后把apache加入启动服务
# cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
# gedit /etc/init.d/httpd
然后在第三行加入
# chkconfig: 345 85 15
# description: This is Apache Web Server
注意:#号不能去掉
然后继续输入命令
# chkconfig --add httpd
# chkconfig httpd on
# chkconfig --list httpd
5.安装J2SE(www.java.sun.com 下载最新版本)
下载jdk-6u10-linux-i586.bin。
然后安装jdk,会出来很多more,more完后yes就行。
# ./jdk-6u10-linux-i586.bin
# mv jdk1.6.0_10 /usr/local/
# cd /usr/local
# ln -s jdk1.6.0_10 jdk6
6.安装Tomcat6
下载apache-tomcat-6.0.18.tar.gz。
tomcat安装以解压安装为主,相对简单。
# cp apache-tomcat-6.0.18.tar.gz /usr/local/
# cd /usr/local
# tar xzvf apache-tomcat-6.0.18.tar.gz
# ln -s apache-tomcat-6.0.18 tomcat6
7.配置J2SE和Tomcat的环境变量
# gedit /etc/profile
编辑环境变量文件,添加如下语句到文件文尾:
export JAVA_HOME=/usr/local/jdk6
export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
export TOMCAT_HOME=/usr/local/tomcat6
export CATALINA_HOME=/usr/local/tomcat6
export CLASSPATH=$CLASSPATH:$CATALINA_HOME/common/lib
使环境变量立即生效(最好还是重启一下):
# source /etc/profile
8.启动tomcat
首先为Tomcat编辑一段启动脚本,并置于/etc/rc.d/init.d目录下。
# gedit /etc/rc.d/init.d/tomcat
贴入如下内容:
#!/bin/bash
#
# Startup script for the tomcat
#
# chkconfig: 345 80 15
# description: Tomcat is a Servlet+JSP Engine.
export JAVA_HOME=/usr/local/jdk6
export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
export TOMCAT_HOME=/usr/local/tomcat6
export CATALINA_HOME=/usr/local/tomcat6
export CLASSPATH=$CLASSPATH:$CATALINA_HOME/common/lib

# Source function library.
. /etc/rc.d/init.d/functions
start(){
if [ -z $(/sbin/pidof java) ]; then
echo "Starting tomcat6"
/usr/local/tomcat6/bin/startup.sh
touch /var/lock/subsys/tomcat
else
echo "tomcat allready running"
fi
}
stop(){
if [ ! -z $(/sbin/pidof java) ]; then
echo "Shutting down tomcat"
/usr/local/tomcat6/bin/shutdown.sh
until [ -z $(/sbin/pidof java) ]; do :; done
rm -f /var/lock/subsys/tomcat
else
echo "tomcat not running"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
/usr/local/tomcat6/bin/catalina.sh version
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
esac
exit 0
让Tomcat和httpd一样作为一项系统服务,并随系统自动启动。
# chmod 755 /etc/rc.d/init.d/tomcat
# chkconfig --add tomcat
# chkconfig tomcat on
# chkconfig --list tomcat
# /etc/rc.d/init.d/tomcat start
打开FF,输入http://localhost:8080,看到那只猫出来就安装成功。
用reboot 重启后 关闭tomcat的时间长点。不过没关系
9.编译生成mod_jk
去www.apache.org的tomcat下载页面可以找到下载连接
# tar xzvf tomcat-connectors-1.2.26-src.tar.gz
# cd tomcat-connectors-1.2.26-src/native
# ./configure --with-apxs=/usr/local/apache2/bin/apxs
# make
# cp ./apache-2.0/mod_jk.so /usr/local/apache2/modules/
10.Apache和Tomcat整合配置
在/usr/local/apache2/conf/下面建立两个配置文件mod_jk.conf和workers.properties。
# gedit /usr/local/apache2/conf/mod_jk.conf
贴入如下内容:
# installed in the previous section
#加载mod_jk模块
LoadModule jk_module modules/mod_jk.so
# Where to find workers.properties
JkWorkersFile conf/workers.properties
# Where to put jk logs
JkLogFile logs/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
# 请求分发配置,可以配置多项
JkMount /servlet/* loadbalancer
JkMount /*.jsp loadbalancer
JkMount /*.do loadbalancer
JkMount /*.action loadbalancer
JkMount /dwr/* loadbalancer
JkMount /group/* loadbalancer
JkMount /*.jws loadbalancer
JkMount /*.view loadbalancer
#关掉主机Lookup,提高系统性能。
HostnameLookups Off
# gedit /usr/local/apache2/conf/workers.properties
贴入以下内容:
worker.list=loadbalancer
# Define the first node...
worker.server1.port=8009
worker.server1.host=127.0.0.1
worker.server1.type=ajp13
worker.server1.lbfactor=1
worker.server1.local_worker=1
worker.server1.cachesize=1000
worker.server1.cache_timeout=600
worker.server1.socket_keepalive=1
worker.server1.socket_timeout=0
worker.server1.retries=3
# Define the second node...
# Now we define the load-balancing behaviour
worker.loadbalancer.type=lb
worker.retries=3
worker.loadbalancer.balance_workers=server1
worker.loadbalancer.sticky_session=true
worker.loadbalancer.sticky_session_force=true
修改httpd.conf,在httpd.conf中增加Include conf/mod_jk.conf,并且修改相关www发布地址。
# gedit /usr/local/apache2/conf/httpd.conf
修改以下几个地方:
#serverName www.example.com:80 ---> serverName localhost:80
DocumentRoot "/usr/local/apache2/htdocs" ---> DocumentRoot "/var/www/html"
<Directory "/usr/local/apache2/htdocs"> ---> <Directory "/var/www/html">
DirectoryIndex index.html ---> DirectoryIndex index.jsp index.action index.do index.html
在文档最后面增加:
<ifmodule mod_deflate.c>
AddOutputFilter DEFLATE xml jsp js css
</ifmodule>
Include conf/mod_jk.conf
建立/var/www/html文件夹:
# mkdir /var/www
# mkdir /var/www/html
重启Apache:
# /etc/rc.d/init.d/httpd restart
11.安装MySQL
下载Mysql5.1的安装包
MySQL-client-community-5.1.29-0.rhel5.i386.rpm
MySQL-server-community-5.1.29-0.rhel5.i386.rpm
MySQL-devel-community-5.1.29-0.rhel5.i386.rpm
MySQL-shared-community-5.1.29-0.rhel5.i386.rpm
安装所有的rpm包:
# rpm -ivh MySQL-client-community-5.1.29-0.rhel5.i386.rpm MySQL-server-community-5.1.29-0.rhel5.i386.rpm MySQL-devel-community-5.1.29-0.rhel5.i386.rpm MySQL-shared-community-5.1.29-0.rhel5.i386.rpm
安装完成后,打开控制台启动mysql
# service mysql start
登录MySQL
由于头一次登录,MySQL默认是root用户,没有密码。所以直接用命令:mysql 就行了。
# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.37-community MySQL Community Edition (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
修改mysql用户密码,用户名root,密码root:
# mysqladmin -u root password root
复制my.cnf文件到/etc目录:
# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
打开my.cnf,增加UTF-8字符集:
gedit /etc/my.cnf
在[mysqld]下增加default-character-set=utf8
安装mysql图形工具 。下载mysql-gui-tools-5.0r12-rhel4-i386.tar.gz
解压缩后安装

你可能感兴趣的:(apache,tomcat,jsp,mysql,centos)