自动化shell安装 nginx and resin jsp安装脚本

其实和前几天的那个tomcat差不多的,只是把jsp的解析换成了resin。

nginx and resin 自动安装脚本



#!/bin/bash
ulimit -SHn 51200
echo "ulimit -SHn 51200" >>/etc/rc.local
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
echo "/usr/sbin/setenforce 0" >> /etc/rc.local
/usr/sbin/setenforce 0
cat >> /etc/sysctl.conf <<EOF
net.ipv4.tcp_max_syn_backlog = 65536
net.core.netdev_max_backlog =  32768
net.core.somaxconn = 32768
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_tw_recycle = 1
#net.ipv4.tcp_tw_len = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800
#net.ipv4.tcp_fin_timeout = 30
#net.ipv4.tcp_keepalive_time = 120
net.ipv4.ip_local_port_range = 1024  65535
EOF
sysctl -p
rpm -qa|grep  httpd
rpm -e httpd
rpm -qa|grep mysql
rpm -e mysql
yum -y remove httpd*
yum -y remove mysql-server mysql
yum -y install yum-fastestmirror
yum -y remove httpd
if [ -s /etc/selinux/config ]; then
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
fi
LANG=C
yum -y install path gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
echo "============================nginx install================================="
wget -c http://yum.lvtao.net/linux/lnamp/pcre-8.13.tar.gz
tar zxvf pcre-8.13.tar.gz
cd pcre-8.13/
./configure
make && make install
cd ../
useradd www
wget -c http://yum.lvtao.net/linux/lnamp/nginx-1.2.0.tar.gz
tar zxvf nginx-1.2.0.tar.gz
cd nginx-1.2.0
./configure --user=www--group=www--prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6
make && make install
cat >> /etc/init.d/nginx <<EOF
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig:   - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /usr/local/nginx/conf/nginx.conf
# pidfile:     /usr/local/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "\$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=\$(basename \$nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
lockfile=/var/lock/subsys/nginx
start() {
    [ -x \$nginx ] || exit 5
    [ -f \$NGINX_CONF_FILE ] || exit 6
    echo -n \$"Starting \$prog: "
    daemon \$nginx -c \$NGINX_CONF_FILE
retval=\$?
    echo
    [ \$retval -eq 0 ] && touch \$lockfile
    return \$retval
}
stop() {
    echo -n \$"Stopping \$prog: "
    killproc \$prog -QUIT
retval=\$?
    echo
    [ \$retval -eq 0 ] && rm -f \$lockfile
    return \$retval
}
restart() {
    configtest || return \$?
    stop
    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/null 2>&1
}
case "\$1" in
    start)
        rh_status_q && exit 0
        \$1
        ;;
    stop)
        rh_status_q || exit 0
        \$1
        ;;
    restart|configtest)
        \$1
        ;;
    reload)
        rh_status_q || exit 7
        \$1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo \$"Usage: \$0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac
EOF
rm -f /usr/local/nginx/conf/nginx.conf
cat >> /usr/local/nginx/conf/nginx.conf <<EOF
user  www www;
worker_processes 8;
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;
error_log  logs/error.log;
pid        /usr/local/nginx/logs/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events
    {
        use epoll;
        worker_connections 51200;
    }
http
    {
        include       mime.types;
        default_type  application/octet-stream;
        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 50m;
        #sendfile on;
        #tcp_nopush     on;
        keepalive_timeout 60;
        #tcp_nodelay on;
        #fastcgi_connect_timeout 300;
        #fastcgi_send_timeout 300;
        #fastcgi_read_timeout 300;
        #fastcgi_buffer_size 64k;
        #fastcgi_buffers 4 64k;
        #fastcgi_busy_buffers_size 128k;
        #fastcgi_temp_file_write_size 256k;
        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;
        #limit_zone  crawler  \$binary_remote_addr  10m;
#log_format main '$remote_addr - $remote_user [$time_local] $status ' '"$request" $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"';
log_format kkk  '"\$http_x_forwarded_for - \$remote_user [\$time_local] \$request ' '"\$status" \$body_bytes_sent "\$http_referer" ' '"\$http_user_agent" ';
server {
access_log  /usr/local/nginx/logs/access.log  kkk;
listen       80;
server_name  localhost;
charset   UTF-8;
root  /usr/local/resin/webapps/ROOT/ ;
location / { 
                index  index.php index.jsp index.html index.htm; 
                if (!-f \$request_filename){ 
                                proxy_pass http://localhost:8080; 
           } 
        }
location /NginxStatus {
stub_status on;
access_log off;
}
location ~ \.(jsp|jspx|do)?$
{
index index.jsp;
proxy_pass http://localhost:8080;
               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 ~ .*\.(gif|jpg|jpeg|png|bmp|swf)\$ 
{
expires      30d;
}
location ~ .*\.(js|css)?\$
{
expires      1h;
}
}
}
EOF
chmod +x /etc/init.d/nginx
/etc/init.d/nginx start
chkconfig --level 345 nginx on
echo "============================resin install finished================================="
echo "===================================================================================="
wget http://download.oracle.com/otn-pub/java/jdk/6u32-b05/jdk-6u32-linux-i586.bin?AuthParam=1338301571_542fe22441e1ec7a3aa4fb56d0517798
mkdir /usr/java
mv jdk-6u31-linux-i586-rpm.bin /usr/java
cd /usr/java
chmod 777 *
./jdk-6u31-linux-i586-rpm.bin
echo -ne "
export JAVA_HOME=/usr/java/jdk1.6.0_31
export PATH=\$PATH:\$JAVA_HOME/bin:\$JAVA_HOME/jre/bin
export CLASSPATH=.:/usr/java/jdk1.6.0_31/lib:/usr/java/jdk1.6.0_31/jre/lib:\$CLASSPATH
" >>/etc/profile
source  /etc/profile
java -version
cd -
echo "============tomcat========"
wget http://www.caucho.com/download/resin-4.0.27.tar.gz
tar zxf resin-4.0.27.tar.gz 
cd resin-4.0.27
./configure --prefix=/usr/local/resin --with-java-home=/usr/java/jdk1.6.0_31/
make && make install
/usr/local/resin/bin/resin.sh start
#/etc/init.d/resin start
cp -r init.d/resin /etc/init.d/resin
chmod +x /etc/init.d/resin
/sbin/chkconfig --add resin
/sbin/chkconfig --level 2345 resin on
echo "ip:8080"
echo "==================================================="


jdk的下载地址,需要换一下,因为第二天就失效了。


Resin配置虚拟主机:


Resin修改主目录

<web-app id="/" document-directory="webapps/ROOT"/>


<hostid="sms.zhcw.com"root-directory="/usr/html/sms.zhcw.com">
<web-appid="/"document-directory="."/>
    
</host>
<hostid="vote.zhcw.com"root-directory="/usr/html/vote.zhcw.com">
<web-appid="/"document-directory="."/>
    
</host>




你可能感兴趣的:(nginx,nginx,resin,resin,虚拟主机,resin集群)