准备工作(相关包放置目录如下)
/usr/java目录下:
jdk-7u76-linux-x64.rpm 【注意是.rpm格式】
/usr/local目录下:
nginx-0.7.65.tar.gz
[下面三个是开启tomcat的Http11NioProtocol提高并发的]
apr-1.3.9.tar.gz
apr-iconv-1.2.1.tar.gz
apr-util-1.3.9.tar.gz
tomcat-native.tar.gz
pcre-8.37.tar.gz
/usr/apache目录下:
apache-tomcat-6.0.28.tar.gz
project目录[放:PersonalProject,server.crt server.key (https密钥) (后面会在在tomcat项目指定路径)]
单个tomcat配置 不用配置字体为此的颜色
一、 JDK安装:
1.01、检查你的Linux系统,是32位机还是64位机
查看linux机器是32位还是64位的方法:
file /sbin/init 或者 file /bin/ls
/sbin/init: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped
如果显示 64-bit 则为64位;
file /sbin/init
/sbin/init: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.5, dynamically linked (uses shared libs), stripped
如果显示为32 bit 则为32bit;
1.02、Linux 64位机上安装JDK
1、卸载jkd:(包括系统自带的jdk和自己之前安装过的jdk的卸载方法):
①、卸载系统自带的jdk版本:
查看自带的jdk:
#rpm -qa | grep gcj
看到如下信息:
libgcj-4.1.2-44.el5
java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
使用rpm -e --nodeps 命令删除上面查找的内容:
#rpm -e --nodeps java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
②、卸载rpm安装的jkd版本
查看安装的jdk:
#rpm -qa|grep jdk
看到如下信息:
java-1.6.0-openjdk-1.6.0.0-0.25.b09.el5
jdk-1.6.0_16-fcs
卸载:
#rpm -e --nodeps jdk-1.6.0_16-fcs
(如果提示nodeps不能用的话,就不用这个选项了)
2、下载Linux_64位的jdk安装包,类似:jdk-7u76-linux-x64.rpm
方法一:
# cd /usr/java/
# rpm -ivh jdk-7u76-linux-x64.rpm
方法二、
如果是. bin包安装
# cd /usr/java/
# chmod a+x jdk-6u45-linux-x64-rpm.bin (这一步不会有反应 执行后就执行下一句就好了)
# ./jdk-6u45-linux-x64-rpm.bin
输入:# java -version
出现: java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
表示安装成功。
④、配置环境变量:
#vi /etc/profile
在文件的最后面添加:
JAVA_HOME=/usr/java/jdk1.7.0_76
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME CLASSPATH
然后:
Esc :wq! -------------> 保存退出
Esc :q! -------------> 不保存退出
(重启系统生效)
如果不想重启电脑,再配置立即生效的环境变量,不过这样的设置仅对当前 shell生效,如果从另外一个shell登录,将不能使用如下设置的变量:
# export JAVA_HOME=/usr/java/ jdk1.7.0_76
# export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
# export PATH=$PATH:$JAVA_HOME/bin
(注意:Linux中环境变量是以":"分割的,不是";")
二、 多个apache-tomcat安装与配置:
1.01、安装
1 、下载apache-tomcat-6.0.28.tar.gz
2 、把apache-tomcat-6.0.28.tar.gz放到要安装的目录(放在他们local下的)
3 、解压:tar -xvf apache-tomcat-6.0.28.tar.gz -C /usr/apache/ (解压到那个地方)
产生新的文件夹:apache-tomcat-6.0.28
4、apache-tomcat-6.0.28改名如下并copy此文件改名为apache-tomcat-2
apache-tomcat-1
apache-tomcat-2
1.02、配置
apache-tomcat-1,apache-tomcat-2配置web.xml和catalina.sh内容是一样的
1.0.0.1、 web.xml配置 (强制使用https)
在</web-app>标签前增加
<login-config>
<auth-method>CLIENT-CERT</auth-method>
<realm-name>Client Cert Users-only Area</realm-name>
</login-config>
<security-constraint>
<web-resource-collection >
<web-resource-name >SSL</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
1.0.0.2、 server.xml配置 (强制使用https)
apache-tomcat-1配置如下
<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<GlobalNamingResources>
<Resource
name="UserDatabase"
auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<!--
secure="true"
scheme="https"
SSLCertificateFile="/usr/apache/project/server.crt"
SSLCertificateKeyFile="/usr/apache/project/server.key"
sslProtocol="all"
-->
<Connector
protocol="org.apache.coyote.http11.Http11AprProtocol"
useBodyEncodingForURI="true"
port="444"
proxyPort="443"
maxThreads="1000"
acceptCount="700"
URIEncoding="UTF-8"
scheme="http"
SSLEnabled="true"
connectionTimeout="30000"
enableLookups="false"
compression="on"
compressionMinSize="2048"
compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain,text/json"
/>
<!--
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />-->
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
<Host name="localhost"
appBase="/usr/apache/project/PersonalProject"
unpackWARs="true"
autoDeploy="false"
xmlValidation="false"
xmlNamespaceAware="false" >
<Context path=""
docBase="/usr/apache/project/PersonalProject"
reloadable="true"
crossContext="true"
caseSensitive="false">
</Context>
</Host>
</Engine>
</Service>
</Server>
apache-tomcat-2配置如下
<?xml version='1.0' encoding='utf-8'?>
<Server port="8006" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<GlobalNamingResources>
<Resource
name="UserDatabase"
auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<!--
secure="true"
scheme="https"
SSLCertificateFile="/usr/apache/project/server.crt"
SSLCertificateKeyFile="/usr/apache/project/server.key"
sslProtocol="all"
-->
<Connector
protocol="org.apache.coyote.http11.Http11AprProtocol"
useBodyEncodingForURI="true"
port="555"
proxyPort="443"
maxThreads="1000"
acceptCount="700"
URIEncoding="UTF-8"
scheme="http"
SSLEnabled="true"
connectionTimeout="30000"
enableLookups="false"
compression="on"
compressionMinSize="2048"
compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain,text/json"
/>
<!--
<Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />
-->
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
<Host name="localhost"
appBase="/usr/apache/project/PersonalProject"
unpackWARs="true"
autoDeploy="false"
xmlValidation="false"
xmlNamespaceAware="false" >
<Context path=""
docBase="/usr/apache/project/PersonalProject"
reloadable="true"
crossContext="true"
caseSensitive="false">
</Context>
</Host>
</Engine>
</Service>
</Server>
继续在profile配置环境tomcat变量
CATALINA_BASE=/usr/apache/apache-tomcat-1
CATALINA_HOME=/usr/apache/apache-tomcat-1
export CATALINA_BASE CATALINA_HOME
TOMCAT_HOME=/usr/apache/apache-tomcat-1
export TOMCAT_HOME
CATALINA_2_BASE=/usr/apache/apache-tomcat-2
CATALINA_2_HOME=/usr/apache/apache-tomcat-2
export CATALINA_2_BASE CATALINA_2_HOME
TOMCAT_2_HOME=/usr/apache/apache-tomcat-2
export TOMCAT_2_HOME
让环境变量生效:(不需要重启)
source /etc/profile
1.0.0.3、tomcat下catalina.sh配置
87行这句话下[请根据内存自己调整jvm大小]:
# OS specific support. $var _must_ be set to either true or false. 下增加
export JAVA_OPTS="-server -Xms1400m -Xmx1400m -Xss1024k -XX:+AggressiveOpts -XX:+UseBiasedLocking -XX:PermSize=218M -XX:MaxPermSize=512M -XX:+DisableExplicitGC -XX:MaxTenuringThreshold=31 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSParallelRemarkEnabled
-XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -Djava.awt.headless=true -Dfile.encoding=utf-8"
1.0.0.4 APR安装
http://www.cnblogs.com/huangjingzhou/articles/2097241.html
由于apache开启了Http11NioProtocol 来提高并发 但是需要添加额外的支持
apr-1.3.9.tar.gz apr-iconv-1.2.1.tar.gz apr-util-1.3.9.tar.gz tomcat-native.tar.gz pcre-8.37.tar.gz
1)安装apr
tar zxvf apr-1.4.2.tar
cd apr-1.4.2
./configure --prefix=/usr/local/apr
make
make install
2)安装apr-iconv
程序代码
tar -zxvf apr-iconv-1.2.1.tar.gz
cd apr-iconv-1.2.1
./configure --prefix=/usr/local/apr-iconv --with-apr=/usr/local/apr
make
make install
3)安装apr-util
程序代码
tar zxvf apr-util-1.3.10.tar.gz
cd apr-util-1.3.10
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr --with-apr-iconv=/usr/local/apr-iconv/bin/apriconv
make
make install
4)安装tomcat-native
程序代码
tar zxvf tomcat-native-1.1.20-src.tar.gz
cd tomcat-native-1.1.20-src/jni/native
./configure --with-apr=/usr/local/apr --with-java-home=/usr/java/jdk1.6.0_23 (jdk路径)
make
make install
5)添加环境变量
vi /etc/profile #在他文件末尾处添加下面的变量
# apr
export LD_LIBRARY_PATH=/usr/local/apr/lib
执行
source /etc/profile
此时环境变量生效果
启动tomcat
TOMCAT_HOME/bin/start.sh
more TOMCAT_HOME/logs/catalina.out
即可看到
Aug 29, 2010 3:47:32 PM org.apache.catalina.core.AprLifecycleListener init
INFO: Loaded APR based Apache Tomcat Native library 1.1.20.
优化完成
上面安装完成后仍然会报错
在环境变量中添加 export LD_LIBRARY_PATH=/usr/local/apr/lib
让环境变量生效:(不需要重启)
source /etc/profile
哈哈哈 ok
但是得在防火墙吧444 555端口开放
Linux系统/etc/sysconfig目录下无iptables文件
解决:在控制台使用iptables命令随便写一条防火墙规则,如:iptables -P OUTPUT ACCEPT 使用service iptables save进行保存,默认就保存到了/etc/sysconfig目录下的iptables文件中
在iptables文件中增加红色字体内容:
:OUTPUT ACCEPT [220:27318]
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 555 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 444 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8443 -j ACCEPT
#iptables -A INPUT -p tcp --dport 9856 -j DROP
#iptables -A INPUT -p tcp --dport 7000 -j DROP
COMMIT
防火墙命令:
查看防火墙状态
#service iptables status
Linux关闭防火墙命令
1) 永久性生效,重启后不会复原
开启:chkconfig iptables on
关闭:chkconfig iptables off
2) 即时生效,重启后复原
开启:service iptables start
关闭:service iptables stop
分别启动两个tomcat 只能启动起来一个
解决方法:
Tomcat1增加 export CATALINA_HOME=$CATALINA_HOME export CATALINA_BASE=$CATALINA_BASE
Tomcat2增加 export CATALINA_HOME=$CATALINA_2_HOME export CATALINA_BASE=$CATALINA_2_BASE
一、 nginx的安装与配置
1.0.1安装
2、执行如下命令解压nginx:
1.#cd /usr/local
2.#tar zxvf nginx-0.7.63.tar.gz
3、编译安装nginx
1.#cd nginx-0.7.63
2.#./configure --with-http_stub_status_module --with-http_ssl_module #启动server状态页和https模块(红色部分配https必需加上,否则后面坑死人)
执行完后会提示一个错误,说缺少PCRE library 这个是HTTP Rewrite 模块,也即是url静态化的包
可上传pcre-7.9.tar.gz,输入如下命令安装:
1.#tar zxvf pcre-7.9.tar.gz
2.#cd pcre-7.9
3.#./configure
4.#make
5.#make install
安装pcre成功后,继续安装nginx
1.#cd nginx-0.7.63
2.#./configure --with-http_stub_status_module --with-http_ssl_module
3.#make
4.#make install
如果报错 SSL modules require the OpenSSL library.
1. ubuntu下解决办法: 【查看系统类:#cat /etc/issue】
1. apt-get install openssl
2. apt-get install libssl-dev
1. centos下解决办法:
1. yum -y install openssl openssl-devel
1.0.2配置
在/usr/local/nginx目录下配置/usr/local/nginx/conf/nginx.conf 配置后如下
worker_processes 4;
#worker_cpu_affinity 0001 0010 0100 1000;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 204800;
|
|