Tengine (淘宝nginx ) + tomcat 安装整合

==系统架构==

OS:Linux2.6.18-194.el5PAEi386GNU/Linux
Disk:20GBMemory:4GSwap:5G

==用户/组规划==

mkdir/app
groupaddapp
useraddtomcat-u505-Gapp-b/app
useraddnginx-u506-Gapp-b/app

==基础服务==
Nginx+Tomcat

版本:

Tengineversion:Tengine/1.4.6(nginx/1.2.9)http://tengine.taobao.org/

[root@ceshi1~]#/app/tomcat/bin/version.sh
UsingCATALINA_BASE:/app/tomcat
UsingCATALINA_HOME:/app/tomcat
UsingCATALINA_TMPDIR:/app/tomcat/temp
UsingJRE_HOME:/usr/local/jdk1.7.0_17
UsingCLASSPATH:/app/tomcat/bin/bootstrap.jar:/app/tomcat/bin/tomcat-juli.jar
Serverversion:ApacheTomcat/7.0.40
Serverbuilt:May5201308:54:06
Servernumber:7.0.40.0
OSName:Linux
OSVersion:2.6.32-358.6.2.el6.x86_64
Architecture:amd64
JVMVersion:1.7.0_17-b02
JVMVendor:OracleCorporation

==依赖服务==
Pcre(支持正则的模块)JDK(Java开发工具包)

版本:Pcre:pcre-8.32JDK:1.7.0_17

==服务安装==
1.32bitJDK:

a)wgethttp://219.239.26.10/download/38564427/54254163/3/gz/53/228/1362527298357_484/jdk-7u17-linux-i586.tar.gz
b)tarzxfjdk-7u17-linux-i586.tar.gz
c)mvjdk1.7.0_17/usr/local
d)配置环境变量
1.vim/etc/profile
PATH="/usr/local/jdk1.7.0_17/bin:$PATH:$HOME/bin"
JAVA_OPTS='-Xms2048m-Xmx2048m-XX:PermSize=128M-XX:MaxPermSize=256M'
CATALINA_OPTS='-Djava.awt.headless=true'
JAVA_HOME="/usr/local/jdk1.7.0_17"
CLASS_PATH="$JAVA_HOME/lib:$JAVA_HOME/jre/lib"
CATALINA_HOME="/app/tomcat"
exportPATHJAVA_HOMEJAVA_OPTSCATALINA_OPTSCLASS_PATHCATALINA_HOME

2.source/etc/profile

2.Tomcat:

a)wgethttp://apache.dataguru.cn/tomcat/tomcat-7/v7.0.40/bin/apache-tomcat-7.0.40.tar.gz
b)tarzxfapache-tomcat-7.0.40.tar.gz
c)mvapache-tomca-7.0.40/*/app/tomcat/


3.Pcre
a)wgethttp://sourceforge.net/projects/pcre/files/pcre/8.32/pcre-8.32.tar.bz2/download
b)tarxfpcre-8.32.tar.bz2
c)cdpcre-8.32
d)./configure
e)make&&makeinstall


4.nginx
a)wgethttp://nginx.org/download/nginx-1.4.6.tar.gz
b)tarzxfnginx-1.4.6.tar.gz
c)cdnginx-1.4.6
d)./configure--prefix=/app/nginx--user=nginx--group=app--prefix=/app/nginx--with-http_stub_status_module--with-http_ssl_module--with-http_concat_module--with-http_upstream_check_module--with-http_sub_module--with-http_realip_module

--with-http_stub_status_module:该模块可以为Tengine提供主动式后端服务器健康检查的功能http://tengine.taobao.org/document_cn/http_upstream_check_cn.html

--with-http_concat_module:该模块类似于apache中的mod_concat模块,用于合并多个文件在一个响应报文中http://tengine.taobao.org/document_cn/http_concat_cn.html

--without-http_upstream_consistent_hash_module:这个模块提供一致性hash作为负载均衡算法http://tengine.taobao.org/document_cn/http_upstream_consistent_hash_cn.html

ngx_http_upstream_session_sticky_module该模块是一个负载均衡模块,通过cookie实现客户端与后端服务器的会话保持,在一定条件下可以保证同一个客户端访问的都是同一个后端服务器http://tengine.taobao.org/document_cn/http_upstream_session_sticky_cn.html

e)make&&makeinstall
f)如果遇到报错:./configure:error:SSLmodulesrequiretheOpenSSLlibrary解决办法:yuminstallopenssl

==服务配置==


Nginx配置
监听端口:80/8080
----
vim/app/nginx/conf/nginx.conf
<pre>
worker_rlimit_nofile65535;

events{
worker_connections10240;
useepoll;
}


http{
includemime.types;
default_typeapplication/octet-stream;
client_max_body_size1000m;
server_tokensoff;

log_formatmain'$remote_addr-$remote_user[$time_local]'
'"$request"$status$body_bytes_sent'
'"$http_referer""$http_user_agent"'
'"$http_x_forwarded_for"';
access_loglogs/access.logmain;

sendfileon;
#tcp_nopushon;

keepalive_timeout65;

gzipon;
gzip_min_length1k;
gzip_buffers416k;
gzip_http_version1.0;
gzip_comp_level2;
gzip_typestext/plainapplication/x-javascripttext/csstext/javascriptapplication/xml;
gzip_varyon;


include../conf.d/www.tets.com;(添加虚拟主机)
}

vim/app/nginx/conf.d/www.test.com

server{
listen80;
server_namewww.test.com;
charsetutf-8;

location~*{
proxy_passhttp://127.0.0.1:8080;(指定代理)
proxy_set_headerHostwww.test.com;
proxy_set_headerX-Real-IP$remote_addr;
proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;
}

location~/\.ht{denyall;}
}

Tomcat配置
vim/app/tomcat/conf/server.xml(添加主机、指定网站目录)

<Hostname=www.test.comappBase="webapps">
<Contextpath=""docBase="/app/web/www.test.com/ROOT"debug="0"reloadable="true"/>
</Host>

==Shell脚本==


1.tomcat启动脚本(此脚本适合同一台服务器部署多个tomcat的情况)
vim/etc/init.d/tomcat

#!/bin/bash
#
#httpdStartupscriptfortheTomcatHTTPServer
#
#chkconfig:-9292
#description:Thewebcontainertomcatis365wos

#HTMLfilesandCGI.
#processname:java
#config:/app/tomcat/conf/server.xml

source/app/tomcat/bin/mainsh/tomcatstatus.sh

#/app/tomcat/bin/whoareyou.plDevel
case$1in
start)
iftomcatup
then
echo-e"Tomcatstarting...\t\t\t[OK]";
else
echo-e"Tomcatstarting...\t\t\t[Error]";
fi
;;
stop)
iftomcatdown
then
echo-e"Tomcatshutdown...\t\t\t[OK]";
else
echo-e"Tomcatshutdown...\t\t\t[Error]";
fi
;;
restart)
iftomcatdown
then
echo-e"Tomcatshutdown...\t\t\t[OK]";
else
echo-e"Tomcatshutdown...\t\t\t[Error]";
fi

iftomcatup
then
echo-e"Tomcatstarting...\t\t\t[OK]";
else
echo-e"Tomcatstarting...\t\t\t[Error]";
fi
;;
status)
tomcatstatus
;;
*)
echo"Error,Pleaseenterstart|stop|restart|status"
esac
</pre>

vim/app/tomcat/bin/mainsh/tomcatstatus.sh

#!/bin/bash
tomcatup()
{
/app/tomcat/bin/startup.sh&>/dev/null

}

tomcatdown()
{
/app/tomcat/bin/shutdown.sh&>/dev/null
kill-9$(/bin/ps-ef|grep"/app/tomcat/conf/logging.properties"|grep-vgrep|awk'$1~'\/$USER\/'{print$2}')&>/dev/null

}

tomcatstatus()
{
cat=$(ps-ef|grep"/app/tomcat/conf/logging.properties"|wc-l)
if[$cat-ge2]
then
echo-e"Tomcatrunning...\t\t\t[OK]"
else
echo-e"Tomcatstoping...\t\t\t[OK]"
fi
}

tomcat脚本2(此脚本适合单Tomcat时使用)

vim/etc/init.d/tomcat

#Sourcefunctionlibrary.
./etc/rc.d/init.d/functions

start(){
if[-z$(/sbin/pidofjava)];then
echo"Startingtomcat"
/app/tomcat/bin/startup.sh&>/dev/null
touch/var/lock/subsys/tomcat
else
echo"tomcatallreadyrunning"
fi
}

stop(){
if[!-z$(/sbin/pidofjava)];then
echo"Shuttingdowntomcat"
/app/tomcat/bin/shutdown.sh&>/dev/null
kill-9$(/bin/ps-ef|grep"/app/tomcat/conf/logging.properties"|grep-vgrep|awk'$1~'\/$USER\/'{print$2}')&>/dev/null
until[-z$(/sbin/pidofjava)];do:;done
rm-f/var/lock/subsys/tomcat
else
echo"tomcatnotrunning"
fi
}

status(){
cat=$(ps-ef|grep"/app/tomcat/conf/logging.properties"|wc-l)
if[$cat-ge2]
then
echo-e"Tomcatrunning...\t\t\t[OK]"
else
echo-e"Tomcatstoping...\t\t\t[NO]"
fi
}
case"$1"in
start)
start
;;

stop)
stop
;;

restart)
stop
start
;;

status)
#/app/tomcat/bin/catalina.shversion
status
;;
*)
echo"Usage:$0{start|stop|restart|status}"
esac

exit0

2.nginx启动脚本

vim/etc/init.d/nginx
#!/bin/sh
#
#nginx-thisscriptstartsandstopsthenginxdaemon
#
#chkconfig:-8515
#description:NginxisanHTTP(S)server,HTTP(S)reverse\
#proxyandIMAP/POP3proxyserver
#processname:nginx
#config:/app/nginx/conf/nginx.conf
#pidfile:/app/nginx/logs/nginx.pid

#Sourcefunctionlibrary.
./etc/rc.d/init.d/functions

#Sourcenetworkingconfiguration.
./etc/sysconfig/network

#Checkthatnetworkingisup.
["$NETWORKING"="no"]&&exit0

nginx="/app/nginx/sbin/nginx"
prog=$(basename$nginx)

NGINX_CONF_FILE="/app/nginx/conf/nginx.conf"

[-f/etc/sysconfig/nginx]&&./etc/sysconfig/nginx

lockfile=/var/lock/subsys/nginx

start(){
[-x$nginx]||exit5
[-f$NGINX_CONF_FILE]||exit6
echo-n$"Starting$prog:"
daemon$nginx-c$NGINX_CONF_FILE
retval=$?
echo
[$retval-eq0]&&touch$lockfile
return$retval
}

stop(){
echo-n$"Stopping$prog:"
killproc$prog-QUIT
retval=$?
echo
[$retval-eq0]&&rm-f$lockfile
return$retval
killall-9nginx
}

restart(){
configtest||return$?
stop
sleep1
start
}

reload(){
configtest||return$?
echo-n$"Reloading$prog:"
killproc$nginx-HUP
RETVAL=$?
echo
}

force_reload(){
restart
}

configtest(){
$nginx-t-c$NGINX_CONF_FILE
}

rh_status(){
status$prog
}

rh_status_q(){
rh_status>/dev/null2>&1
}

case"$1"in
start)
rh_status_q&&exit0
$1
;;
stop)
rh_status_q||exit0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q||exit7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q||exit0
;;
*)
echo$"Usage:$0{start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit2
esac

3.日志查看脚本

vim/bin/log
#!/bin/bash
case$1in
1|nginx_access)
tail-f/app/nginx/logs/access.log-n100
;;
2|nginx_error)
tail-f/app/nginx/logs/error.log-n200
;;
3|tomcat)
tail-f/app/tomcat/logs/catalina.out-n200
;;

*)
echo输入错误!!
echo"命令方法"
echo"/bin/logtomcat"
echo""
echo"或者"
echo"/bin/lognginx_access"
echo""
echo"或者"
echo"/bin/lognginx_error"
echo""
;;

esac

==目录权限设置==


创建网站目录:

mkdir-p/app/web/www.test.com/ROOT/

设置权限:

chown-Rnginx:app/app/nginx
chown-Rtomcat:app/app/web/www.test.com
chown-Rtomcat:app/app/tomcat
chmod755/bin/log/etc/init.d/tomcat/app/tomcat/bin/mainsh/tomcatstatus.sh/etc/init.d/nginx

==设置开机自启动==

chkconfig--level35nginxon
chkconfig--level35tomcaton

==异常处理==

Startingnginx:/app/nginx/sbin/nginx:errorwhileloadingsharedlibraries:libpcre.so.1:cannotopensharedobjectfile:
Nosuchfileordirectory[FAILED]

pcre.libpcre.so.1=>notfound并没有找到

解决办法:
find/-namelibpcre.so.1
/usr/local/lib/libpcre.so.1

ln-s/usr/local/lib/libpcre.so.1/lib

总结:上面的问题其实是pcre的动态库路径不对,无需编译


Error:failed/usr/local/jdk/jre/lib/i386/client/libjvm.so,because/usr/local/jdk/jre/lib/i386/client/libjvm.so:cannotrestoresegmentprotafterreloc:Permissiondenied

解决办法:
1打开/etc/selinux/config

2把selinux=enforcing改为selinux=disabled

3重启linux

你可能感兴趣的:(tomcat,tengine,安装整合)