Chinaunix首页 | 论坛 | 博客
  • 博客访问: 301468
  • 博文数量: 47
  • 博客积分: 1667
  • 博客等级: 上尉
  • 技术积分: 686
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-06 16:20
文章分类

全部博文(47)

文章存档

2013年(20)

2012年(20)

2011年(7)

分类: LINUX

2013-05-03 18:14:42

yum  -y install apr  apr-util
#tomcat 使用apr 来进行文件读取和网络传输,可以大大提升tomcat对静态文件的处理性能






wget
mv jdk-6u45-linux-x64.bin\?AuthParam\=1367468841_b708af07c630bfaf0b69be53d448b8ef  jdk-6u45-linux-x64.bin
chmod a+x  jdk-6u45-linux-x64.bin
./jdk-6u45-linux-x64.bin
mv jdk1.6.0_45/  /usr/local/java




vim /etc/profile
JAVA_HOME=/usr/local/java
CLASSPATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib
PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin
export JAVA_HOME CLASSPATH PATH


source  /etc/profile 










wget
tar xvzf apache-tomcat-6.0.36.tar.gz
mv apache-tomcat-6.0.36   /usr/local/tomcat8080
cd  /usr/local/tomcat8080/bin/
tar xvzf commons-daemon-native.tar.gz
cd commons-daemon-1.0.10-native-src/unix
./configure  --with-java=/usr/local/java
make




groupadd  -g 1000 tomcat
useradd -M -u 1000  -g 1000  -s /sbin/nologin  tomcat


vim /etc/init.d/tomcat8080
#!/bin/sh
#chkconfig:35 24 43
#description:tomcat is web server
if  [  -f  /etc/init.d/functions  ]; then  
. /etc/init.d/functions
fi
prog=tomcat8080




JAVA_HOME=/usr/local/java
CATALINA_HOME=/usr/local/tomcat8080
DAEMON_HOME=/usr/local/tomcat8080/bin
TOMCAT_USER=tomcat


TMP_DIR=/tmp
PID_FILE=/var/run/${prog}.pid
CATALINA_BASE=/usr/local/tomcat8080
CATALINA_OPTS="-Djava.library.path=/usr/lib64"
CLASSPATH=\
$JAVA_HOME/lib/tools.jar:\
$CATALINA_HOME/bin/commons-daemon.jar:\
$CATALINA_HOME/bin/bootstrap.jar:$CATALINA_HOME/bin/tomcat-juli.jar


case "$1" in
  start)
    #
    # Start Tomcat
    #
    echo -n $"Starting $prog: "
     $DAEMON_HOME/commons-daemon-1.0.10-native-src/unix/jsvc \
    -user $TOMCAT_USER \
    -home $JAVA_HOME \
    -Dcatalina.home=$CATALINA_HOME \
    -Dcatalina.base=$CATALINA_BASE \
    -Djava.io.tmpdir=$TMP_DIR \
    -wait 10 \
    -pidfile $PID_FILE \
    -outfile $CATALINA_HOME/logs/catalina.out \
    -errfile '&1' \
    $CATALINA_OPTS \
    -server -Xms1400m -Xmx1400m -Xss512k \
    -cp $CLASSPATH \
    org.apache.catalina.startup.Bootstrap
    if [ $?  -eq  0 ];then
     success;echo
    else
     failure; echo ; 
    fi     




    #
    # To get a verbose JVM
    #-verbose \
    # To get a debug of jsvc.
    #-debug \
    exit $?
    ;;


  stop)
    #
    # Stop Tomcat
    #
    echo  -n $"Stopping $prog:"
    $DAEMON_HOME/commons-daemon-1.0.10-native-src/unix/jsvc \
    -stop \
    -pidfile $PID_FILE \
    org.apache.catalina.startup.Bootstrap
     if [ $?  -eq  0 ];then
     success;echo
    else
     failure; echo ; 
    fi     


 
   ;;


  *)
    echo "Usage tomcat.sh start/stop"
    exit 1;;
esac


vim /usr/local/tomcat/bin/catalina.sh 


export JAVA_OPTS="-server -Xms12000m -Xmx12000m -Xss512k"


-server :以server模式运行
-Xms ,-Xmx:jvm的内存设置。jvm:java虚拟机 。我测试发现在物理内存的50%-80%之间最好
-Xss :线程的堆栈大小,一般不大于1M




vim /usr/local/tomcat/conf/server.xml 
                  URIEncoding="UTF-8" minSpareThreads="25" maxSpareThreads="50"
              enableLookups="false"  disableUploadTimeout="true" 
               connectionTimeout="20000"
               acceptCount="1024"  maxThreads="1024" maxProcessors="1024" minProcessors="64"
               redirectPort="8443" />






URIEncoding="UTF-8"  编码
minSpareThreads="25"  最小空闲的线程数
maxSpareThreads="50"  最大的空闲线程数,超过这个数字,tomcat就会自动关闭空闲的线程数
enableLookups="false"  反查域名,关闭
disableUploadTimeout="true"
connectionTimeout="20000"  连接超时,毫秒
acceptCount="300"         最大连接数
maxThreads="300"          最大线程数
maxProcessors="300" minProcessors="5"  最大和最小连接线程数




chkconfig -add tomcat8080
chkconfig tomcat8080 on
service tomcat8080 start


























2,多实例运行tomcat
tomcat并发能力很低,所以一般采用单机多实例来跑,然后采用nginx反向代理来做,或者其他方法来实现负载均衡


/bin/cp -afr  /usr/local/tomcat8080 /usr/local/tomcat8088


vim /usr/local/tomcat/conf/server.xml 
 #将8080端口改为8088
                URIEncoding="UTF-8" minSpareThreads="25" maxSpareThreads="50"
              enableLookups="false"  disableUploadTimeout="true" 
               connectionTimeout="20000"
               acceptCount="1024"  maxThreads="1024" maxProcessors="1024" minProcessors="64"
               redirectPort="8443" />




##将8009端口改为8010







vim /etc/init.d/tomcat8088
#!/bin/sh
#chkconfig:35 24 43
#description:tomcat is web server
if  [  -f  /etc/init.d/functions  ]; then  
. /etc/init.d/functions
fi
prog=tomcat8088




JAVA_HOME=/usr/local/java
CATALINA_HOME=/usr/local/tomcat8088
DAEMON_HOME=/usr/local/tomcat8088/bin
TOMCAT_USER=tomcat


TMP_DIR=/tmp
PID_FILE=/var/run/${prog}.pid
CATALINA_BASE=/usr/local/tomcat8088
CATALINA_OPTS="-Djava.library.path=/usr/lib64"
CLASSPATH=\
$JAVA_HOME/lib/tools.jar:\
$CATALINA_HOME/bin/commons-daemon.jar:\
$CATALINA_HOME/bin/bootstrap.jar:$CATALINA_HOME/bin/tomcat-juli.jar


case "$1" in
  start)
    echo -n $"Starting $prog: "
     $DAEMON_HOME/commons-daemon-1.0.10-native-src/unix/jsvc \
    -user $TOMCAT_USER \
    -home $JAVA_HOME \
    -Dcatalina.home=$CATALINA_HOME \
    -Dcatalina.base=$CATALINA_BASE \
    -Djava.io.tmpdir=$TMP_DIR \
    -wait 10 \
    -pidfile $PID_FILE \
    -outfile $CATALINA_HOME/logs/catalina.out \
    -errfile '&1' \
    $CATALINA_OPTS \
    -server -Xms1400m -Xmx1400m -Xss512k \
    -cp $CLASSPATH \
    org.apache.catalina.startup.Bootstrap
    if [ $?  -eq  0 ];then
     success;echo
    else
     failure; echo ; 
    fi     
    ;;


  stop)

    echo  -n $"Stopping $prog:"
    $DAEMON_HOME/commons-daemon-1.0.10-native-src/unix/jsvc \
    -stop \
    -pidfile $PID_FILE \
    org.apache.catalina.startup.Bootstrap
     if [ $?  -eq  0 ];then
     success;echo
    else
     failure; echo ; 
    fi     
   ;;

  *)
    echo "Usage tomcat.sh start/stop"
    exit 1;;
esac


chkconfig -add tomcat8088
chkconfig tomcat8088 on
service tomcat8088 start

yum  -y   install pcre-devel openssl-devel
wget
tar xvzf nginx-1.0.15.tar.gz
cd nginx-1.0.15
wget
tar xvzf ngx_cache_purge-2.1.tar.gz
./configure  --prefix=/usr/local/nginx  --with-http_ssl_module  --with-http_stub_status_module  --with-http_flv_module  --with-http_dav_module --with-http_gzip_static_module --add-module=ngx_cache_purge-2.1
make && make install


vim /usr/local/nginx/conf/nginx.conf
user  tomcat tomcat;
worker_processes 1;
error_log  logs/error.log  crit;
pid        /usr/local/nginx/nginx.pid;
worker_rlimit_nofile 204800;
events
{
  use epoll;
  worker_connections 204800;
}


http
{
  include       mime.types;
  default_type  application/octet-stream;


  charset  utf-8;


  server_names_hash_bucket_size 128;
  client_header_buffer_size 2k;
  large_client_header_buffers 4 4k;
  client_max_body_size 8m;


  sendfile on;
  tcp_nopush     on;


  keepalive_timeout 60;


 
  open_file_cache max=204800 inactive=20s;
  open_file_cache_min_uses 1;
  open_file_cache_valid 30s;
  
  tcp_nodelay on;
  gzip on;
  gzip_min_length  1k;
  gzip_buffers     4 16k;
  gzip_http_version 1.0;
  gzip_comp_level 2;
  gzip_types       text/plain application/x-javascript text/css application/xml;
  gzip_vary on;
  proxy_temp_path   /usr/local/nginx/proxy_temp;
  proxy_cache_path  /dev/shm/ levels=1:2 keys_zone=tomcat_cache:200m inactive=1d max_size=8g;

upstream tomcatpoll {
   server 127.0.0.1:8080  weight=2 max_fails=2 fail_timeout=30s;
   server 127.0.0.1:8088  weight=1 max_fails=2 fail_timeout=30s;
}


  server
  {
    listen       80;
    server_name  
    index index.html index.html index.php;
   # root /usr/local/tomcat/webapps/ROOT;


    location /status
    {
        stub_status on;
    }
    location ~ /purge(/.*){
    proxy_cache_purge   tomcat_cache   $host$1$is_args$args;
}

    location /{
        proxy_set_header Host $host;
        proxy_redirect     off;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        client_max_body_size 4m;
        client_body_buffer_size 256k;
        proxy_pass    
        proxy_connect_timeout 30;
        proxy_send_timeout 30;
        proxy_read_timeout 60;
        proxy_buffer_size 256k;
        proxy_buffers 4 256k;
        proxy_busy_buffers_size 256k;
        proxy_temp_file_write_size 256k;
        proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
        proxy_max_temp_file_size 12m;
        proxy_cache tomcat_cache;
        proxy_cache_valid  200 304 12h;
        proxy_cache_key  $host$uri$is_args$args;
       }


    log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
              '$status $body_bytes_sent "$http_referer" '
              '"$http_user_agent" $http_x_forwarded_for "$upstream_cache_status"';
    access_log  logs/access.log  access;
      }
}


ulimit -SHn 51200

vim /etc/sysctl.conf
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_rmem = 4096        87380   4194304
net.ipv4.tcp_wmem = 4096        16384   4194304
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 262144
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 30
net.ipv4.ip_local_port_range = 1024    65000


阅读(3637) | 评论(0) | 转发(0) |
0

上一篇:DNS服务器

下一篇:mysql的权限验证

给主人留下些什么吧!~~