标签:
配置包
httpd-2.2.22.tar.gz(Apache)
apache-tomcat-7.0.27.tar.gz(Tomcat)
tomcat-connectors-1.2.36-src.tar.gz(mod_jk)
jdk-6u24-linux-i586.bin(jdk)
l 上传配置包到服务端
l 查看Linux系统 安装相应辅助软件包 例如libtool gcc等
REDHAT:
rpm –qa | grep libtool
UBUNTU:
apt-get install libtool
l 安装Apache
采用源码包安装方式 指令如下
1. tar –zxvf httpd-2.2.22.tar.gz
2. cd httpd-2.2.22
3. ./configure --prefix=/usr/local/apache
--enable-modules=most --enable-mods-shared=all --enable-so
4. make
5. make install
指令3说明:
--prefix是安装路径
--enable-so是不可缺少的加载模块开关
--enable-modules=most是动态加载大多数模块静态编译到apache的二进制文件中,--enable-mods-shard=all表示动态加载所有模块
l 测试安装是否成功
/usr/local/apache/bin/apachectl start
netstat –tlunp | grep 80
证明安装成功
l 安装JDK
1. 查看当前jdk版本
Java -version
如果jdk版本低于1.6需要卸载重新安装jdk
无jdk直接跳到第3步安装jdk
2. 卸载jdk
REDHAT:
rpm -qa | grep jdk
rpm -e –nodeps java版本名
3. 安装jdk
1. cd /usr/local
2. chmod u+x jdk-6u24-linux-i586.bin
3. ./jdk-6u24-linux-i586.bin
4. mv jdk1.6.0_24 jdk
修改环境变量
5. vi /etc/profile
在文件最后添加如下语句
export JAVA_HOME=/usr/local/jdk
export JRE_HOME=/usr/local/jdk/jre
export PATH=$PATH:$JAVA_HOME/bin:JRE_HOME/bin
exportCLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:
6. java –version查看版本是否安装成功
l 安装Tomcat
1. cd /usr/local
2. tar -zxvf apache-tomcat-7.0.27.tar.gz
3. mv apache-tomcat-7.0.27 tomcat
l 安装Apache连接Tomcat插件mod_jk
1. cd /usr/local
2. tar -zxvf tomcat-connectors-1.2.36-src.tar.gz
3. cd tomcat-connectors-1.2.36-src/native
4. ./buildconf.sh
5. ./configure --with-apxs=/usr/local/apache/bin/apxs
--with-java-home=/usr/local/jdk
6. make
7. make install
8. ll ./apache-2.0/mod_jk.so /usr/local/apache/modules/mod_jk.so
如果能够给查到这2个文件说明安装完毕
l 配置Apache
添加2个文件 mod_jk.conf和workers.properties
1. cd /usr/local/apache/conf
2. vim mod_jk.conf
JkWorkersFile /usr/local/apache/conf/workers.properties
JkLogFile /usr/local/apache/logs/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%H:%S %Y]"
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkMount /servlet/* worker1
JkMount /*.jsp worker1
JKMount /*.do worker1
3. vim workers.properties
worker.list=worker1
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009
worker.worker1.lbfactor=50
worker.worker1.cachesize=10
worker.worker1.cache_timeout=600
worker.worker1.socket_keepalive=1
worker.worker1.socket_timeout=300
4. vi httpd.conf
添加:
LoadModule jk_module modules/mod_jk.so
Include /usr/local/apache/conf/mod_jk.conf
配置虚拟路径 红字是图片存放地址
Alias /voteadmin "/home/httpd/mt/images"
<Directory "/home/httpd/mt/images">
Options Indexes MultiViews
AddOutputFilter Includes html
AllowOverride None
Order allow,deny
Allow from all
</Directory>
修改:
红字是主目录地址
#DocumentRoot "/usr/local/apache/htdocs"
DocumentRoot "/home/httpd/mt/
#<Directory "/usr/local/apache/htdocs">
<Directory "/home/httpd/mt">
<IfModule dir_module>
DirectoryIndex index.jsp
</IfModule>
l 配置Tomcat
1. vi /usr/local/tomcat/conf/server.xml
在<Host></Host>标签内添加:
红字是主目录地址
<Context path="" docBase="/home/httpd/mt/" debug="0" reloadable="true" crossContext="true" />
属性说明:
reloadable:如果这个属性设为true,tomcat服务器在运行状态下会监视在WEB-INF/classes和WEB-INF/lib目录下class文件的改动,如果监测到有class文件被更新的,服务器会自动重新加载Web应用。
crossContext: 设为true解决Tomcat默认不能跨WebApp进行访问。
debug: 调试信息(1~99)数字越大调试信息越详细
在如下标签内添加加黑内容:
<Connector port="8009" enableLookups="false" redirectPort="8443" protocol="AJP/1.3" jvmRoute="worker1" />
属性说明
enableLookups:设为true表示支持域名解析,可以把IP地址解析为主机名.WEB应用中调用
l 上传主目录
1. 打包
程序打成以Web开头的zip包
2. 上传解压
cd /home/httpd/mt
rz
unzip *
rm Web* -f
3. 上传配置文件
cd ..
rz
yes|cp *properties /home/httpd/mt/WEB-INF/classes/
l 启动服务
/usr/local/tomcat/bin/startup.sh 启动 tomcat
/usr/local/apache/bin/apachectl start 启动apache
l 查看是否配置成功
netstat –tlunp | grep 80
1. 安装apache时
如果出现APR NO,APR-UTIL NO pcre NO中的情况
参考url:http://www.linlook.com/detail_MTI5Mw==.html
需要安装apr apr-util pcre包 并在编译时指定该软件的路径
例 安装apr包
tar –zxvf apr-1.4.5.tar.gz
cd apr-1.4.5
./configure
make
make install
注:apr-util安装时需要指定apr的路径
--with-apr=PATH
--with-apr-util=PATH
2. 安装tomcat-connectors时
如果出现libtool,autoconf等错误信息
安装相应的安装包即可解决
l 配置apache
§ 注释之前语句添加如下文字
vi workers.properties
worker.list=worker1
#========tomcat1========
worker.tomcat1.port=8009
worker.tomcat1.host=localhost
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor = 1
#========tomcat2========
worker.tomcat2.port=9009
worker.tomcat2.host=localhost
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor = 1
#========worker1 负载均衡控制器========
worker.worker1.type=lb
worker.worker1.balanced_workers=tomcat1,tomcat2
worker.worker1.sticky_session=true
l 配置tomcat(同一台服务器可以直接复制之前的tomcat)
§ 修改全部的tomcat内 server.xml
vi server.xml
1. 修改jvmRoute
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1" >
红字内文字需一一对应
2. 取消注释
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
注:如果配置集群前配置过tomcat需要去掉<Connector port="8009" enableLookups="false" redirectPort="8443" protocol="AJP/1.3" jvmRoute="worker1" />中的 jvmRoute=”worker1”
注:同一台服务器开启2个以上tomcat时需要修改端口号
l 查看配置是否成功
netstat –tlunp | grep 80
l 修改httpd.conf文件
<IfModule prefork.c>
ServerLimit 3000
StartServers 5
MinSpareServers 10
MaxSpareServers 20
ServerLimit 2048
MaxClients 2000
MaxRequestsPerChild 1000
</IfModule>
参考文档地址:
http://chenqing24.blog.163.com/blog/static/846538420125271127213/
l 修改server.xml
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-" maxThreads="1000"
minSpareThreads="1000"/>
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="2000"redirectPort="8443"
enableLookups="false" acceptCount="500" maxThreads="1000"/>
<Connector port="8009" protocol="HTTP/1.1"
connectionTimeout="2000"redirectPort="8443"
enableLookups="false" acceptCount="500" maxThreads="1000"/>
参考文档地址:
http://www.iteye.com/topic/190329
PS:上述apache与tomcat优化 解决1800台主机注册访问
标签:
原文地址:http://my.oschina.net/u/1162040/blog/383289