Chinaunix首页 | 论坛 | 博客
  • 博客访问: 663390
  • 博文数量: 198
  • 博客积分: 4256
  • 博客等级: 上校
  • 技术积分: 1725
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-15 13:12
文章分类

全部博文(198)

文章存档

2012年(12)

2011年(39)

2010年(135)

2009年(12)

我的朋友

分类: 系统运维

2011-06-25 23:35:18

#!/bin/bash

sudo apt-get install build-essential zlib1g-dev python-mysqldb \
libpcre3-dev memcached mysql-server python-pip 

sudo pip install flup
sudo pip install django-primate
#sudo pip install --upgrade flup

src_dir='/opt/src'
build_dir='/opt/build'
project_dir='/data/web/qibar'
sudo mkdir $src_dir
sudo mkdir $build_dir
sudo mkdir /opt/sh

cd ${src_dir}
wget
wget
wget

cd ${build_dir}
sudo tar xzvf ${src_dir}/Django-1.3.tar.gz
cd Django-1.3/
sudo python setup.py install
django-admin.py startproject ${project_dir}
mkdir ${project_dir}/static
cd ${project_dir}/static
sudo ln -s /usr/local/lib/python2.7/dist-packages/django/contrib/admin/media admin

cd ${build_dir}
sudo tar xzvf ${src_dir}/gnosek-nginx-upstream-fair-5f6a3b7.tar.gz

cd ${build_dir}
sudo tar xzf ${src_dir}/nginx-1.0.4.tar.gz
cd nginx-1.0.4
sudo ./configure --conf-path=/etc/nginx/nginx.conf \
--user=www-data --group=www-data \
--error-log-path=/var/log/nginx/error.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/var/lib/nginx/body \
--http-proxy-temp-path=/var/lib/nginx/proxy \
--add-module=${build_dir}/gnosek-nginx-upstream-fair-5f6a3b7 \
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-http_realip_module

sudo make && sudo make install
sudo makedir /var/lib/nginx
sudo chown www-data:www-data /var/lib/nginx
sudo mkdir /etc/nginx/sites
sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx-conf-bak

cat > /etc/nginx/sites/qibar.conf << EOF
    server {
    listen       80;
    server_name qibar.com
    index index.html;
    root   /data/web/qibar;

    location ~ \.(jgp|png|gif|ico|swf|css|js)$ {
        expires 10d;
    }

    location / {
      # host and port to fastcgi server
      fastcgi_pass 127.0.0.1:9001;
      fastcgi_param PATH_INFO $fastcgi_script_name;
      fastcgi_param REQUEST_METHOD $request_method;
      fastcgi_param QUERY_STRING $query_string;
      fastcgi_param CONTENT_TYPE $content_type;
      fastcgi_param CONTENT_LENGTH $content_length;
      fastcgi_pass_header Authorization;
      fastcgi_intercept_errors off;
      fastcgi_param SERVER_PROTOCOL $server_protocol;
      fastcgi_param SERVER_PORT $server_port;
      fastcgi_param SERVER_NAME $server_name;
    }
 
    access_log    /var/log/nginx/django_log main;
  }

EOF

cat > /etc/nginx/nginx.conf << EOF
user www-data www-data;
worker_processes  2;
#worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;
error_log  /var/log/nginx/error.log;
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 64k;
    large_client_header_buffers 4 128k;
    client_max_body_size 8m;

    sendfile on;
    tcp_nopush     on;
    keepalive_timeout 30;
    tcp_nodelay on;
    server_tokens off;

    proxy_connect_timeout 30;
    proxy_send_timeout 10;
    proxy_read_timeout 20;
    proxy_buffer_size 32k;
    proxy_buffers 8 64k;

    gzip on;
    gzip_min_length  1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.1;
    gzip_comp_level 2;
    gzip_types  text/plain  text/css  application/xml application/x-javascript ;

    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 256k;
    fastcgi_buffers 4 256k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    fastcgi_temp_path /var/lib/nginx/fastcgi;

    log_format  main    '$remote_addr - $remote_user [$time_local] "$request" '
                        '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" $http_x_forwarded_for';

include sites/*.conf;

}

EOF

###compilaze kerner 
cat > /etc/sysctl.conf << EOF
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
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 512000000
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_sack = 0
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 65536
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 10
net.ipv4.tcp_keepalive_time = 30
net.ipv4.ip_local_port_range = 1024  65535
EOF

sudo sysctl -p

##Get the Restart scripts

cat > /etc/init.d/nginx << EOF
#!/bin/bash

start () {
    sudo /usr/local/nginx/sbin/nginx
    echo "Nginx started ...."
}

stop () {
    if ps -ef | grep nginx | grep -v grep > /dev/null 2>&1;then
        sudo /usr/local/nginx/sbin/nginx -s stop 
echo "Nginx stoped...."
    else
        echo "Nginx Not Running....."
        exit 1
    fi
}

case $1 in 
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage:$0 start|stop|restart!"
exit 1
;;
esac

EOF

cat > /etc/init.d/fcgi << EOF
#!/bin/bash

pid=`cat /tmp/fcgi.pid`

start () {
    cd /data/web/qibar
    python manage.py runfcgi host=127.0.0.1 port=9001 pidfile=/tmp/fcgi.pid
    echo "Fcgi Starting...!"
}

stop () {
    if [ -f /tmp/fcgi.pid ];then
        kill -9 $pid
        echo "Fcgi Stopped!!!"
    else
        echo "Fcgi not running.....!"
    fi
}

case $1 in
start)
    start
;;
stop)
    stop
;;
restart)
    stop
    start 
;;
*)
    echo "Usage:$0 start|stop|restart!"
    exit 1
;;
esac

EOF

update-rc.d nginx defaults
update-rc.d fcgi defaults

echo "CREATE DATABASE qibar DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"

阅读(1373) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~