首页 > 代码库 > nginx+tomcat

nginx+tomcat

jdk-6u32-linux-x64.bin

apache-tomcat-7.0.37.tar.gz

  111  sh jdk-6u32-linux-x64.bin

[root@server44 ~]# mv jdk1.6.0_32/ /usr/local/jdk
[root@server44 ~]# which java
/usr/bin/which: no java in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
[root@server44 ~]# java
-bash: java: command not found
[root@server44 ~]# javac
-bash: javac: command not found

[root@server44 ~]# vim /etc/profile
[root@server44 ~]# source /etc/profile
[root@server44 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/jdk/bin
[root@server44 ~]# echo $CLASSPATH
.:/usr/local/jdk/lib:/usr/local/jdk/jre/lib
[root@server44 ~]# vim test.java

[root@server44 ~]# cat test.java
public class test
{
    public static void main(String[] args)
    {
        System.out.println("Hello world");
    }

}
[root@server44 ~]# javac test.java
[root@server44 ~]# java test
Hello world

 

 

 

 

*********************************************************************************************************
                                          nginx + tomcat
**********************************************************************************************************
nginx + tomcat
    /etc/init.d/mysqld stop
    /etc/init.d/php-fpm stop
1.tomcat
  (1)下载    lftp 192.168.2.251
             sh /root/jdk-6u32-linux-x64.bin
             mv /root/jdk1.6.0_32/ /usr/local/lnmp/jdk
  (2)命令    vim /etc/profile
               export JAVA_HOME=/usr/local/lnmp/jdk(zuihou)
               export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
               export PATH=$PATH:$JAVA_HOME/bin
             source /etc/profile
  (3)检测     echo $JAVA_HOME
               /usr/local/lnmp/jdk
             echo $PATH
               /usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/lnmp/mysql/bin:/root/bin:/usr/local/lnmp/mysql/bin:/usr/local/lnmp/php/bin/:/usr/local/lnmp/jdk/bin
             echo $CLASSPATH
               .:/usr/local/lnmp/jdk/lib:/usr/local/lnmp/jdk/jre/lib
             which java
              /usr/local/lnmp/jdk/bin/java
             which javac
              /usr/local/lnmp/jdk/bin/javac
  (4)java测试 vim /root/test.java
                public class test {
                      public static void main(String[] args)
                      {
                            System.out.println("hello");
                      }
               }
             javac test.java
             java test
              hello

2.整合
  (1)安装tomcat
     解压    tar zfx apache-tomcat-7.0.37.tar.gz -C /usr/local/lnmp/
     重命名  mv /usr/local/lnmp/apache-tomcat-7.0.37/ /usr/local/lnmp/tomcat
     执行    /usr/local/lnmp/tomcat/bin/startup.sh
     端口    netstat -antlp  (8080)
  (2)测试页面 vim /usr/local/lnmp/tomcat/webapps/ROOT/test.jsp
                server220 The time is: <%=new java.util.Date()%>
 (3)配置    vim /usr/local/lnmp/nginx/conf/nginx.conf
                location ~ \.jsp$ {   (69)
                   proxy_pass   http://127.0.0.1:8080;
                }
  (4)重启    nginx -s reload
  (5)测试    192.168.2.220:8080
             192.168.2.220/test.jsp

3.附带均衡
需要2个测试机
  *1.副机
  (1)建目录   mkdir /usr/local/lnmp
  (2)profiel vim /etc/profile
               export JAVA_HOME=/usr/local/lnmp/jdk
               export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
               export PATH=$PATH:$JAVA_HOME/bin
             source /etc/profile
  (3)sh      /usr/local/lnmp/tomcat/bin/startup.sh
               Using CATALINA_BASE:   /usr/local/lnmp/tomcat
               Using CATALINA_HOME:   /usr/local/lnmp/tomcat
               Using CATALINA_TMPDIR: /usr/local/lnmp/tomcat/temp
               Using JRE_HOME:        /usr/local/lnmp/jdk
               Using CLASSPATH:       /usr/local/lnmp/tomcat/bin/bootstrap.jar:/usr/local/lnmp/tomcat/bin/tomcat-juli.jar
  (4)端口    netstat -antlp (880)
  (5)测试页面 vim /usr/local/lnmp/tomcat/webapps/ROOT/test.jsp
               server105 The time is: <%=new java.util.Date()%>
  *2.主机  
  (1)复制    scp -r /usr/local/lnmp/jdk/ 192.168.2.105:/usr/local/lnmp/
             scp -r /usr/local/lnmp/tomcat/ 192.168.2.105:/usr/local/lnmp/
  (2)配置    vim /usr/local/lnmp/nginx/conf/nginx.conf
               upstream westos {(19)
               server 192.168.2.105:8080;
               server 192.168.2.220:8080;
               }
               location ~ \.jsp$ { (68)
               proxy_pass   http://westos;
               }
  (3)重启    nginx -s reload
  (4)测试    192.168.2.220/test.jsp (变化)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4.同一个ip访问不做附带均衡
   (1)xiazai lftp i
   (2)qingchu
             cd nginx-1.6.0
             make clean  or  make tidy
   (3)jieya  tar zfx nginx-sticky-module-1.0.tar.gz -C nginx-1.6.0
   (4)anzhung
             cd nginx-1.6.0
             ./configure --prefix=/usr/local/lnmp/nginx/ --with-http_ssl_module --with-http_stub_status_module --add-module=/root/nginx-1.6.0/nginx-sticky-module-1.0/
             nginx -s stop
             make && make install
             nginx
   (5)peizhi vim /usr/local/lnmp/nginx/conf/nginx.conf
              upstream westos {
              sticky;  (20)
              server 192.168.2.105:8080;
              server 192.168.2.220:8080;
              }
   (6)jiance  nginx -t
     chongqi  nginx -s reload
   (7)ceshi   192.168.2.220/test.jsp (bu bian)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dan dian gu zhang(xiang hu bei fen)
1.zhuji
   (1)anzhuang
             yum install memcached -y
   (2)daxiao free -m
             vim /etc/sysconfig/memcached
               CACHESIZE="30"
   (3)qidong /etc/init.d/memcached start
   (4)duankou netstat -antlp | grep 11211
2.fuji
   (1)anzhuang
             yum install memcached -y
   (2)daxiao free -m
             vim /etc/sysconfig/memcached
               CACHESIZE="30"
   (3)qidong /etc/init.d/memcached start
   (4)duankou netstat -antlp | grep 11211
3.ceshi
   telnet localhost 11211
   (1)chakan stats
   (2)tianjia add user 0 0 6
              westos
              STORED
   (3)huode   get user
              VALUE user 0 6
              westos
              END
   (4)shezhi  set user 0 0 6
              redhat
              STORED
   (5)shanchu delete user
              DELETED

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nginx+tomcat+memcached
xu yao 2 ge jizi
node1:192.168.2.220
node2:192.168.2.105
node1 yu node2 peizhi da zhi xiang tong
   (1)ting   /usr/local/lnmp/tomcat/bin/shutdown.sh
   (2)peizhi vi /usr/local/lnmp/tomcat/conf/context.xml
               <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
               memcachedNodes="n1:192.168.2.220:11211,n2:192.168.2.105:11211"
               failoverNodes="n2"       //zai 192.168.2.220 shi n1
               requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
               transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
               />
   (3)xiazai cd /usr/local/lnmp/tomcat/lib/
             lftp i
             mget asm-3.2.jar  kryo-1.04.jar  kryo-serializers-0.10.jar  memcached-session-manager-1.6.3.jar  
                  memcached-session-manager-tc7-1.6.3.jar  minlog-1.2.jar  msm-kryo-serializer-1.6.3.jar
                  reflectasm-1.01.jar  spymemcached-2.7.3.jar
             rm -fr memcached-session-manager-tc6-1.6.3.jar
   (4)ceshiyemian
             vi /usr/local/lnmp/tomcat/webapps/ROOT/test.jsp
               <%@ page contentType="text/html; charset=GBK" %>
               <%@ page import="java.util.*" %>
               <html><head><title>Cluster App Test</title></head>
               <body>
               Server Info:
               <%
               out.println(request.getLocalAddr() + " : " + request.getLocalPort()+"<br>");%>
               <%
               out.println("<br> ID " + session.getId()+"<br>");
               String dataName = request.getParameter("dataName");
               if (dataName != null && dataName.length() > 0) {
               String dataValue = http://www.mamicode.com/request.getParameter("dataValue");
               session.setAttribute(dataName, dataValue);
               }
               out.print("<b>Session list</b>");
               Enumeration e = session.getAttributeNames();
               while (e.hasMoreElements()) {
               String name = (String)e.nextElement();
               String value = http://www.mamicode.com/session.getAttribute(name).toString();
               out.println( name + " = " + value+"<br>");
               System.out.println( name + " = " + value);
               }
               %>
   (5)kaiqi  /usr/local/lnmp/tomcat/bin/startup.sh
   (6)rizhi  tail -f /usr/local/lnmp/tomcat/logs/catalina.out
               INFO: MemcachedSessionService finished initialization, sticky true, operation timeout 1000, with node ids [n1] and failover node ids [n2] (kan dao cai ke yi ji xu)
   (7)ce shi
           1.  192.168.2.220/test.jsp (tian jia yong hu,lian jie n1,ze xin xi zai n2)
           2.  /usr/local/lnmp/tomcat/bin/shutdown.sh (ting )




vi /etc/yum.repos.d/yum.repo
[mplayer]
name=mplayer
baseurl=ftp://192.168.2.251/pub/mplayer
gpgcheck=0

yum  install -y xvidcap smplayer

nginx+tomcat