jack_sir 发表于 2011-12-21 08:44

Django Nginx fcgi 安装配置脚本

<div><font class="Apple-style-span" face="黑体" size="3"><div>#!/bin/bash</div><div><br></div><div>sudo apt-get install build-essential zlib1g-dev python-mysqldb \</div><div>libpcre3-dev memcached mysql-server python-pip&nbsp;</div><div><br></div><div>sudo pip install flup</div><div>sudo pip install django-primate</div><div>#sudo pip install --upgrade flup</div><div><br></div><div>src_dir='/opt/src'</div><div>build_dir='/opt/build'</div><div>project_dir='/data/web/qibar'</div><div>sudo mkdir $src_dir</div><div>sudo mkdir $build_dir</div><div>sudo mkdir /opt/sh</div><div><br></div><div>cd ${src_dir}</div><div>wget https://nodeload.github.com/gnosek/nginx-upstream-fair/tarball/master</div><div>wget http://sysoev.ru/nginx/nginx-1.0.4.tar.gz</div><div>wget http://media.djangoproject.com/releases/1.3/Django-1.3.tar.gz</div><div><br></div><div>cd ${build_dir}</div><div>sudo tar xzvf ${src_dir}/Django-1.3.tar.gz</div><div>cd Django-1.3/</div><div>sudo python setup.py install</div><div>django-admin.py startproject ${project_dir}</div><div>mkdir ${project_dir}/static</div><div>cd ${project_dir}/static</div><div>sudo ln -s /usr/local/lib/python2.7/dist-packages/django/contrib/admin/media admin</div><div><br></div><div>cd ${build_dir}</div><div>sudo tar xzvf ${src_dir}/gnosek-nginx-upstream-fair-5f6a3b7.tar.gz</div><div><br></div><div>cd ${build_dir}</div><div>sudo tar xzf ${src_dir}/nginx-1.0.4.tar.gz</div><div>cd nginx-1.0.4</div><div>sudo ./configure --conf-path=/etc/nginx/nginx.conf \</div><div>--user=www-data --group=www-data \</div><div>--error-log-path=/var/log/nginx/error.log \</div><div>--pid-path=/var/run/nginx.pid \</div><div>--lock-path=/var/lock/nginx.lock \</div><div>--http-log-path=/var/log/nginx/access.log \</div><div>--http-client-body-temp-path=/var/lib/nginx/body \</div><div>--http-proxy-temp-path=/var/lib/nginx/proxy \</div><div>--add-module=${build_dir}/gnosek-nginx-upstream-fair-5f6a3b7 \</div><div>--http-fastcgi-temp-path=/var/lib/nginx/fastcgi \</div><div>--with-http_stub_status_module \</div><div>--with-http_gzip_static_module \</div><div>--with-http_realip_module</div><div><br></div><div>sudo make &amp;&amp; sudo make install</div><div>sudo makedir /var/lib/nginx</div><div>sudo chown www-data:www-data /var/lib/nginx</div><div>sudo mkdir /etc/nginx/sites</div><div>sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx-conf-bak</div><div><br></div><div>cat &gt; /etc/nginx/sites/qibar.conf &lt;&lt; EOF</div><div>&nbsp; &nbsp; server {</div><div>&nbsp; &nbsp; listen &nbsp; &nbsp; &nbsp; 80;</div><div>&nbsp; &nbsp; server_name qibar.com www.qibar.com;</div><div>&nbsp; &nbsp; index index.html;</div><div>&nbsp; &nbsp; root &nbsp; /data/web/qibar;</div><div><br></div><div>&nbsp; &nbsp; location ~ \.(jgp|png|gif|ico|swf|css|js)$ {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; expires 10d;<span class="Apple-tab-span" style="white-space:pre">        </span></div><div>&nbsp; &nbsp; }</div><div><br></div><div>&nbsp; &nbsp; location / {</div><div>&nbsp; &nbsp; &nbsp; # host and port to fastcgi server</div><div>&nbsp; &nbsp; &nbsp; fastcgi_pass 127.0.0.1:9001;</div><div>&nbsp; &nbsp; &nbsp; fastcgi_param PATH_INFO $fastcgi_script_name;</div><div>&nbsp; &nbsp; &nbsp; fastcgi_param REQUEST_METHOD $request_method;</div><div>&nbsp; &nbsp; &nbsp; fastcgi_param QUERY_STRING $query_string;</div><div>&nbsp; &nbsp; &nbsp; fastcgi_param CONTENT_TYPE $content_type;</div><div>&nbsp; &nbsp; &nbsp; fastcgi_param CONTENT_LENGTH $content_length;</div><div>&nbsp; &nbsp; &nbsp; fastcgi_pass_header Authorization;</div><div>&nbsp; &nbsp; &nbsp; fastcgi_intercept_errors off;</div><div>&nbsp; &nbsp; &nbsp; fastcgi_param SERVER_PROTOCOL $server_protocol;</div><div>&nbsp; &nbsp; &nbsp; fastcgi_param SERVER_PORT $server_port;</div><div>&nbsp; &nbsp; &nbsp; fastcgi_param SERVER_NAME $server_name;</div><div>&nbsp; &nbsp; }</div><div>&nbsp;</div><div>&nbsp; &nbsp; access_log &nbsp; &nbsp;/var/log/nginx/django_log main;</div><div>&nbsp; }</div><div><br></div><div>EOF</div><div><br></div><div>cat &gt; /etc/nginx/nginx.conf &lt;&lt; EOF</div><div>user www-data www-data;</div><div>worker_processes &nbsp;2;</div><div>#worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;</div><div>error_log &nbsp;/var/log/nginx/error.log;</div><div>worker_rlimit_nofile 51200;</div><div><br></div><div>events {</div><div>&nbsp; &nbsp; use epoll;</div><div>&nbsp; &nbsp; worker_connections &nbsp;51200;</div><div>}</div><div><br></div><div>http {</div><div>&nbsp; &nbsp; include &nbsp; &nbsp; &nbsp; mime.types;</div><div>&nbsp; &nbsp; default_type &nbsp;application/octet-stream;</div><div><br></div><div>&nbsp; &nbsp; server_names_hash_bucket_size 128;</div><div>&nbsp; &nbsp; client_header_buffer_size 64k;</div><div>&nbsp; &nbsp; large_client_header_buffers 4 128k;</div><div>&nbsp; &nbsp; client_max_body_size 8m;</div><div><br></div><div>&nbsp; &nbsp; sendfile on;</div><div>&nbsp; &nbsp; tcp_nopush &nbsp; &nbsp; on;</div><div>&nbsp; &nbsp; keepalive_timeout 30;</div><div>&nbsp; &nbsp; tcp_nodelay on;</div><div>&nbsp; &nbsp; server_tokens off;</div><div><br></div><div>&nbsp; &nbsp; proxy_connect_timeout 30;</div><div>&nbsp; &nbsp; proxy_send_timeout 10;</div><div>&nbsp; &nbsp; proxy_read_timeout 20;</div><div>&nbsp; &nbsp; proxy_buffer_size 32k;</div><div>&nbsp; &nbsp; proxy_buffers 8 64k;</div><div><br></div><div>&nbsp; &nbsp; gzip on;</div><div>&nbsp; &nbsp; gzip_min_length &nbsp;1k;</div><div>&nbsp; &nbsp; gzip_buffers &nbsp; &nbsp; 4 16k;</div><div>&nbsp; &nbsp; gzip_http_version 1.1;</div><div>&nbsp; &nbsp; gzip_comp_level 2;</div><div>&nbsp; &nbsp; gzip_types &nbsp;text/plain &nbsp;text/css &nbsp;application/xml application/x-javascript ;</div><div><br></div><div>&nbsp; &nbsp; fastcgi_connect_timeout 300;</div><div>&nbsp; &nbsp; fastcgi_send_timeout 300;</div><div>&nbsp; &nbsp; fastcgi_read_timeout 300;</div><div>&nbsp; &nbsp; fastcgi_buffer_size 256k;</div><div>&nbsp; &nbsp; fastcgi_buffers 4 256k;</div><div>&nbsp; &nbsp; fastcgi_busy_buffers_size 256k;</div><div>&nbsp; &nbsp; fastcgi_temp_file_write_size 256k;</div><div>&nbsp; &nbsp; fastcgi_temp_path /var/lib/nginx/fastcgi;</div><div><br></div><div>&nbsp; &nbsp; log_format &nbsp;main &nbsp; &nbsp;'$remote_addr - $remote_user [$time_local] "$request" '</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '$status $body_bytes_sent "$http_referer" '</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '"$http_user_agent" $http_x_forwarded_for';</div><div><br></div><div>include sites/*.conf;</div><div><br></div><div>}</div><div><br></div><div>EOF</div><div><br></div><div>###compilaze kerner&nbsp;</div><div>cat &gt; /etc/sysctl.conf &lt;&lt; EOF</div><div>net.ipv4.ip_forward = 0</div><div>net.ipv4.conf.default.rp_filter = 1</div><div>net.ipv4.conf.default.accept_source_route = 0</div><div>kernel.sysrq = 0</div><div>kernel.core_uses_pid = 1</div><div>kernel.msgmnb = 65536</div><div>kernel.msgmax = 65536</div><div>kernel.shmmax = 512000000</div><div>net.core.wmem_default = 8388608</div><div>net.core.rmem_default = 8388608</div><div>net.core.rmem_max = 16777216</div><div>net.core.wmem_max = 16777216</div><div>net.ipv4.tcp_mem = 94500000 915000000 927000000</div><div>net.ipv4.tcp_syncookies = 1</div><div>net.ipv4.tcp_sack = 0</div><div>net.ipv4.tcp_window_scaling = 1</div><div>net.ipv4.tcp_max_orphans = 3276800</div><div>net.ipv4.tcp_max_syn_backlog = 65536</div><div>net.ipv4.tcp_timestamps = 0</div><div>net.ipv4.tcp_synack_retries = 1</div><div>net.ipv4.tcp_syn_retries = 1</div><div>net.ipv4.tcp_max_tw_buckets = 6000</div><div>net.ipv4.tcp_tw_recycle = 1</div><div>net.ipv4.tcp_tw_reuse = 1</div><div>net.ipv4.tcp_fin_timeout = 10</div><div>net.ipv4.tcp_keepalive_time = 30</div><div>net.ipv4.ip_local_port_range = 1024 &nbsp;65535</div><div>EOF</div><div><br></div><div>sudo sysctl -p</div><div><br></div><div>##Get the Restart scripts</div><div><br></div><div>cat &gt; /etc/init.d/nginx &lt;&lt; EOF</div><div>#!/bin/bash</div><div><br></div><div>start () {</div><div>&nbsp; &nbsp; sudo /usr/local/nginx/sbin/nginx</div><div>&nbsp; &nbsp; echo "Nginx started ...."</div><div>}</div><div><br></div><div>stop () {</div><div>&nbsp; &nbsp; if ps -ef | grep nginx | grep -v grep &gt; /dev/null 2&gt;&amp;1;then</div><div>&nbsp; &nbsp; &nbsp; &nbsp; sudo /usr/local/nginx/sbin/nginx -s stop&nbsp;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>echo "Nginx stoped...."</div><div>&nbsp; &nbsp; else</div><div>&nbsp; &nbsp; &nbsp; &nbsp; echo "Nginx Not Running....."</div><div>&nbsp; &nbsp; &nbsp; &nbsp; exit 1</div><div>&nbsp; &nbsp; fi</div><div>}</div><div><br></div><div>case $1 in&nbsp;</div><div>start)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>start</div><div>;;</div><div>stop)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>stop</div><div>;;</div><div>restart)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>stop</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>start</div><div>;;</div><div>*)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>echo "Usage:$0 start|stop|restart!"</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>exit 1</div><div>;;</div><div>esac</div><div><br></div><div>EOF</div><div><br></div><div>cat &gt; /etc/init.d/fcgi &lt;&lt; EOF</div><div>#!/bin/bash</div><div><br></div><div>pid=`cat /tmp/fcgi.pid`</div><div><br></div><div>start () {</div><div>&nbsp; &nbsp; cd /data/web/qibar</div><div>&nbsp; &nbsp; python manage.py runfcgi host=127.0.0.1 port=9001 pidfile=/tmp/fcgi.pid</div><div>&nbsp; &nbsp; echo "Fcgi Starting...!"</div><div>}</div><div><br></div><div>stop () {</div><div>&nbsp; &nbsp; if [ -f /tmp/fcgi.pid ];then</div><div>&nbsp; &nbsp; &nbsp; &nbsp; kill -9 $pid</div><div>&nbsp; &nbsp; &nbsp; &nbsp; echo "Fcgi Stopped!!!"</div><div>&nbsp; &nbsp; else</div><div>&nbsp; &nbsp; &nbsp; &nbsp; echo "Fcgi not running.....!"</div><div>&nbsp; &nbsp; fi</div><div>}</div><div><br></div><div>case $1 in</div><div>start)</div><div>&nbsp; &nbsp; start</div><div>;;</div><div>stop)</div><div>&nbsp; &nbsp; stop</div><div>;;</div><div>restart)</div><div>&nbsp; &nbsp; stop</div><div>&nbsp; &nbsp; start&nbsp;</div><div>;;</div><div>*)</div><div>&nbsp; &nbsp; echo "Usage:$0 start|stop|restart!"</div><div>&nbsp; &nbsp; exit 1</div><div>;;</div><div>esac</div><div><br></div><div>EOF</div><div><br></div><div><div>update-rc.d nginx defaults</div><div>update-rc.d fcgi defaults</div></div><div><br></div><div>echo "CREATE DATABASE qibar DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"</div><div><br></div></font></div>
页: [1]
查看完整版本: Django Nginx fcgi 安装配置脚本