分类: LINUX
2008-10-17 18:38:11
From:
Author:cioworld
我用Debian架好了Apache2+PHP5+MySQL5环境,一朋友把他的网站移过来,我倒,竟然用的JSP的程序架的。得,要快点支持jsp。偶以前没弄过,找了N多资料(先鄙视一下那些垃圾站,抓文章都抓的不完整,让人没法看,Y的还把排名弄得这么前,害人命啊。弄垃圾站你也要弄得专业点嘛!)都让我看得头大。最后参考了N多资料把这tomcat给弄起来了。其实也很简单,为什么有人非写得那么复杂,让我一看就不愿意试。没办法,我只好先弄好之后写上一篇,方便自己。
一、安装jdk6
$ sudo aptitude install sun-java6-jdk
$ sudo vim /etc/environment
JAVA_HOME=/usr/lib/jvm/java-6-sun
#下载最新的版本:apache-tomcat-6.0.18
$ wget -c http://apache.freelamp.com/tomcat/tomcat-6/v6.0.18/bin/apache-tomcat-6.0.18.tar.gz
$ sudo tar zxvf apache-tomcat-6.0.18.tar.gz #解压缩
#移动到 /usr/local 下,这是本地系统管理员用来自由添加程序的目录。
$ sudo mv apache-tomcat-6.0.18 /usr/local/tomcat6 # 重命名新的tomcat6文件夹
$ chmod 755 /usr/local/tomcat6/bin/*.sh #给.sh文件加个执行权限
#添加一个独立运行此服务的用户tomcat,登陆设置为nologin。防止他拥用root权限给系统带来安全隐患。我们用下面的命令:
$ sudo useradd -d /usr/local/tomcat6 -s /usr/sbin/nologin tomcat
#设置用户tomcat对tomcat的权限
$ sudo chown -R tomcat:tomcat /usr/local/tomcat6
$ sudo vim /etc/init.d/tomcat
# Tomcat auto-start
#
# description: Auto-starts tomcat
# processname: tomcat
# pidfile: /var/run/tomcat.pid
export JAVA_HOME=/usr/lib/jvm/java-6-sun
case $1 in
start)
sh /usr/local/tomcat6/bin/startup.sh
;;
stop)
sh /usr/local/tomcat6/bin/shutdown.sh
;;
restart)
sh /usr/local/tomcat6/bin/shutdown.sh
sh /usr/local/tomcat6/bin/startup.sh
;;
esac
exit 0
$ sudo chmod 755 /etc/init.d/tomcat
$ sudo ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat;
$ sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat;
$ sudo /etc/init.d/tomcat start
Using CATALINA_BASE: /usr/local/tomcat6
Using CATALINA_HOME: /usr/local/tomcat6
Using CATALINA_TMPDIR: /usr/local/tomcat6/temp
Using JRE_HOME: /usr/lib/jvm/java-6-sun
$ sudo apt-get install libapache2-mod-jk
/usr/lib/apache2/modules/mod_jk.so # 链接模块
/usr/share/doc/libapache2-mod-jk/httpd_example_apache2.conf #配置模版文件
/etc/libapache2-mod-jk/workers.properties
$ cat /etc/apache2/mods-available/jk.load
LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so
$ sudo vim /etc/apache2/httpd.conf
JkLogFile /var/log/apache2/mod_jk.log
JkLogLevel info
JkMount /*.jsp ajp13_worker
JkMount /*/servlet/ ajp13_worker
#JkUnMount /servlet/*.gif ajp13_worker
$ cat /etc/libapache2-mod-jk/workers.properties
workers.properties -
workers.tomcat_home=/usr/local/tomcat6 #这一行是tomcat服务器地址
ps=/
worker.list=ajp13_worker
worker.ajp13_worker.port=8009
worker.ajp13_worker.host=localhost
worker.ajp13_worker.type=ajp13
worker.ajp13_worker.lbfactor=1
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=ajp13_worker
$ sudo vim httpd.conf
NameVirtualHost *:80
$ cat /etc/apache2/mods-available/dir.conf
<IfModule mod_dir.c>
DirectoryIndex index.html index.htm index.shtml index.php index.cgi index.jsp
IfModule>
<VirtualHost *:80>
ServerName www.examples.com
ServerAlias examples.com
ServerAdmin examples@gmail.com
DocumentRoot "/var/www/examples/htdocs/"
<Directory />
Options FollowSymLinks
AllowOverride None
Directory>
<Directory /var/www/examples/htdocs/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Directory>
ScriptAlias /cgi-bin/ /var/www/examples/cgi-bin/
<Directory "/var/www/examples/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
Directory>
ErrorLog /var/www/examples/log/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/www/examples/log/access.log combined
ServerSignature On
Alias /docs "/var/www/examples/htdocs/"
<Directory "/var/www/examples/htdocs/">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
allow from all
Directory>
VirtualHost>
$ sudo vim /usr/local/tomcat6/conf/server.xml
<Context path="" docBase="/var/www/examples/htdocs/" debug="0" reloadable=" true" />
$ sudo vim /usr/local/tomcat6/conf/tomcat-users.xml
<user username="用户名" password="密码" roles="admin,manager"/>
$ sudo /etc/init.d/tomcat restart
$ sudo /etc/init.d/apache2 restart