在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
一、安装 #./jdk-6u12-linux-i586.bin 2.安装tomcat: #tar zxvf apache-tomcat-6.0.18.tar.gz #mv apache-tomcat-6.0.29 tomcat 这里我将解压后的apache-tomcat-6.0.29重命名为了tomcat方便操作。 3.配置环境变量: JAVA_HOME="/opt/app/jdk1.6.0_45" CLASS_PATH="$JAVA_HOME/lib:$JAVA_HOME/jre/lib" PATH=".:$PATH:$JAVA_HOME/bin" CATALINA_HOME="/opt/app/tomcat" export JAVA_HOME CATALINA_HOME 执行下面命令使变更生效: # source /etc/profile 启动tomcat并输入http://domain:8080,如果看到猫的页面即tomcat和jdk安装成功 4.安装Nginx # tar zxvf nginx-1.4.4.tar.gz # mv nginx-1.4.4 nginx 同样重命名了一下。 # ./configure --prefix=/opt/app/nginx 结果出现了错误:error: C compiler cc is not found,按网上所说安装编译源码所需的工具和库: #yum install gcc gcc-c++ ncurses-devel perl 再次安装,发现还有错误:the HTTP rewrite module requires the PCRE library. # yum -y install pcre-devel openssl openssl-devel 终于成功, # ./configure --prefix=/opt/app/nginx # make # make install nginx安装成功后的安装目录为/opt/app/nginx 二、Nginx方面的配置 server { listen 80; server_name devtoutiao.renhe.cn; root /home/renhetoutiao/renhetoutiao/htdocs; access_log /home/renhetoutiao/renhetoutiao/logs/access_log.log; location = / { rewrite ^/$ /index.shtml last; } location ~ .shtml { proxy_pass http://localhost:8081; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location ~ .*.(js|css)?$ { expires 1h; } } server { listen 80; server_name devtoutiao.renhe.cn; root /home/renhetoutiao/renhetoutiao/htdocs; access_log /home/renhetoutiao/renhetoutiao/logs/access_log.log; location = / { rewrite ^/$ /index.shtml last; } location ~ .shtml { proxy_pass http://localhost:8081; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location ~ .*.(js|css)?$ { expires 1h; } } 对nginx的conf/nginx.conf修改,第二行 user root,赋予nginx root权限,在http中添加 include /usr/local/nginx/conf.d/*.conf; 三、Tomcat方面的配置 <?xml version='1.0' encoding='utf-8'?> <Server port="8015" 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" /> <Service name="Catalina"> <Connector port="8081" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Engine name="Catalina" defaultHost="localhost"> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="false" xmlValidation="false" xmlNamespaceAware="false"> <Context docBase="/home/renhetoutiao/renhetoutiao/web" path="" /> </Host> </Engine> </Service> </Server> <?xml version='1.0' encoding='utf-8'?> <Server port="8015" 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" /> <Service name="Catalina"> <Connector port="8081" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Engine name="Catalina" defaultHost="localhost"> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="false" xmlValidation="false" xmlNamespaceAware="false"> <Context docBase="/home/renhetoutiao/renhetoutiao/web" path="" /> </Host> </Engine> </Service> </Server> 因为使用nginx,tomcat的ajp不会使用,所以可以去掉,tomcat可以这样简单配置。注意每个项目的连接端口和关闭端口,不要有重复。 #!/bin/sh export CATALINA_BASE="$PWD" export CATALINA_HOME="/usr/local/tomcat" #启动为适配tomcat目录做的准备 #迁移tomcat必要的配置文件 catalina.policy catalina.properties context.xml tomcat-users.xml web.xml if [ ! -f "$CATALINA_BASE"/conf/catalina.policy ]; then cp "$CATALINA_HOME"/conf/catalina.policy "$CATALINA_BASE"/conf fi if [ ! -f "$CATALINA_BASE"/conf/catalina.properties ]; then cp "$CATALINA_HOME"/conf/catalina.properties "$CATALINA_BASE"/conf fi if [ ! -f "$CATALINA_BASE"/conf/web.xml ]; then cp "$CATALINA_HOME"/conf/web.xml "$CATALINA_BASE"/conf fi if [ ! -d "$CATALINA_BASE"/logs ]; then mkdir logs fi #准备classes和lib目录 CLASSES_PATH="$CATALINA_BASE"/web/WEB-INF/classes LIB_PATH="$CATALINA_BASE"/web/WEB-INF/lib rm -rf "$CLASSES_PATH" rm -rf "$LIB_PATH" cp -R "$CATALINA_BASE"/conf "$CLASSES_PATH" cp -R "$CATALINA_BASE"/lib "$LIB_PATH" #启动时会记录进程ID,存放于logs/tomcat.pid内 #shutdown时强制关闭该进程 $CATALINA_HOME/bin/startup.sh #!/bin/sh export CATALINA_BASE="$PWD" export CATALINA_HOME="/usr/local/tomcat" #启动为适配tomcat目录做的准备 #迁移tomcat必要的配置文件 catalina.policy catalina.properties context.xml tomcat-users.xml web.xml if [ ! -f "$CATALINA_BASE"/conf/catalina.policy ]; then cp "$CATALINA_HOME"/conf/catalina.policy "$CATALINA_BASE"/conf fi if [ ! -f "$CATALINA_BASE"/conf/catalina.properties ]; then cp "$CATALINA_HOME"/conf/catalina.properties "$CATALINA_BASE"/conf fi if [ ! -f "$CATALINA_BASE"/conf/web.xml ]; then cp "$CATALINA_HOME"/conf/web.xml "$CATALINA_BASE"/conf fi if [ ! -d "$CATALINA_BASE"/logs ]; then mkdir logs fi #准备classes和lib目录 CLASSES_PATH="$CATALINA_BASE"/web/WEB-INF/classes LIB_PATH="$CATALINA_BASE"/web/WEB-INF/lib rm -rf "$CLASSES_PATH" rm -rf "$LIB_PATH" cp -R "$CATALINA_BASE"/conf "$CLASSES_PATH" cp -R "$CATALINA_BASE"/lib "$LIB_PATH" #启动时会记录进程ID,存放于logs/tomcat.pid内 #shutdown时强制关闭该进程 $CATALINA_HOME/bin/startup.sh #!/bin/sh export CATALINA_BASE="$PWD" export CATALINA_HOME="/usr/local/tomcat" $CATALINA_HOME/bin/shutdown.sh #!/bin/sh export CATALINA_BASE="$PWD" export CATALINA_HOME="/usr/local/tomcat" $CATALINA_HOME/bin/shutdown.sh 通过tomcat的startup.sh脚本,会碰到项目中分配的线程没有及时释放,tomcat不能及时关闭,导致重启时产生端口冲突 TOMCAT_PID="$PWD"/"logs/tomcat.pid" if [ -f "$TOMCAT_PID" ]; then CATALINA_PID="$TOMCAT_PID" elif [ $1 = "start" ]; then CATALINA_PID="$TOMCAT_PID" fi TOMCAT_PID="$PWD"/"logs/tomcat.pid" if [ -f "$TOMCAT_PID" ]; then CATALINA_PID="$TOMCAT_PID" elif [ $1 = "start" ]; then CATALINA_PID="$TOMCAT_PID" fi 最后需要给项目用户可执行权限 chmod 777 catalina.sh |
请发表评论