前面嘗試了一下tengine的動態加載模塊的功能,以爲這樣就有可能有大量部署的機會了,以前沒用nginx是由於每次須要添加新的功能都須要從新編譯一次,雖然nginx在性能上比apache好,可是若是有上百臺機器部署了nginx就很差搞了,每一個部門的web需求都不同,所須要的模塊也不同,即便把全部自帶模塊都編譯進去,可是仍是會遇到一些很好的第三方模塊的,如今tengine支持動態加載模塊,就有但願了,一兩臺編譯是能夠接受的,大量部署tengine仍是用包管理的比較好。 html
下面開始製做以debian6系統爲基礎的tengine deb包,tengine包風格仍是相似於debian通常web服務器軟件包的風格。 nginx
要把全部支持動態加載的模塊都編譯進去,須要如下包的支持: web
apt-get install libxml2 apt-get install libxslt1.1 apt-get install libxslt1-dev apt-get install libgd2-xpm libgd2-xpm-dev apt-get install libgeoip1 libgeoip-dev apt-get install libssl-dev apt-get install libpcre3 libpcre3-dev apt-get install libssl0.9.8
首先,在/tmp目錄下建一個製做deb包的環境目錄tengine,先沒必要創建其餘目錄,最後的整體結構以下圖: shell
└── tengine ├── DEBIAN 這個目錄存放關於包的一些控制信息文件 ├── etc │ ├── init.d 存放/etc/init.d/nginx文件 │ ├── logrotate.d 存放nginx日誌輪轉配置文件 │ └── nginx │ ├── conf 存放nginx的配置文件 │ ├── modules 存放能夠動態加載的模塊 │ └── sbin 存放dso_tool工具 ├── usr │ └── sbin 存放nginx二進制文件 └── var ├── lib │ └── nginx ├── log │ └── nginx 存放nginx日誌 └── www 存放web站點
下載tengine源碼包:tengine-1.4.2.tar.gz,進行編譯安裝,編譯參數以下 apache
./configure --prefix=/etc/nginx --sbin-path=/usr/sbin --error-log-path=/var/log/nginx/error.log --conf-path=/etc/nginx/conf/nginx.conf --pid-path=/var/run --with-http_addition_module=shared --with-http_xslt_module=shared --with-http_geoip_module=shared --with-http_image_filter_module=shared --with-http_sub_module=shared --with-http_flv_module=shared --with-http_slice_module=shared --with-http_mp4_module=shared --with-http_concat_module=shared --with-http_random_index_module=shared --with-http_map_module=shared --with-http_split_clients_module=shared --with-http_charset_filter_module=shared --with-http_access_module=shared --with-http_userid_filter_module=shared --with-http_footer_filter_module=shared --with-http_upstream_least_conn_module=shared --with-http_upstream_ip_hash_module=shared --with-http_user_agent_module=shared --with-http_memcached_module=shared --with-http_referer_module=shared --with-http_limit_conn_module=shared --with-http_limit_req_module=shared --with-http_scgi_module=shared --with-http_secure_link_module=shared --with-http_autoindex_module=shared --with-http_sysguard_module=shared --with-http_rewrite_module=shared --with-http_fastcgi_module=shared --with-http_empty_gif_module=shared --with-http_browser_module=shared --with-http_uwsgi_module=shared
--prefix=/etc/nginx 這個目錄存放除nginx二進制文件外的其他文件 服務器
--sbin-path=/usr/sbin 這個目錄有編譯好的nginx二進制文件
app
以前已經把全部依賴的包已經安裝過了,因此不會出現問題,只要make&&make install便可,安裝完成後在/etc/nginx中的目錄結構以下: dom
nginx ├── conf │ ├── browsers │ └── 若干配置文件... ├── html │ ├── 50x.html │ └── index.html ├── logs ├── modules │ ├── ngx_http_access_module.so │ ├── ngx_http_addition_filter_module.so │ ├── ngx_http_uwsgi_module.so │ └── 若干模塊... └── sbin └── dso_tool
開始進行乾坤大挪移... ide
mv /etc/nginx/conf /tmp/tengine/etc/nginx/ mv /etc/nginx/html/* /tmp/tengine/var/www/ mv /etc/nginx/modules /tmp/tengine/etc/nginx/ mv /etc/nginx/sbin /tmp/tengine/etc/nginx/ mv /usr/sbin/nginx /tmp/tengine/usr/sbin/開始補全在/tmp/tengine的其餘目錄。
logrotate.d/nginx內容以下,nginx日誌輪訓用 memcached
/var/log/nginx/*.log { daily missingok rotate 52 compress delaycompress notifempty create 640 root adm sharedscripts postrotate [ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid` endscript }init.d/nginx內容以下,init啓動nginx用
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/sbin/nginx NAME=nginx DESC=nginx test -x $DAEMON || exit 0 if [ -f /etc/default/nginx ] ; then . /etc/default/nginx fi set -e . /lib/lsb/init-functions test_nginx_config() { if $DAEMON -t $DAEMON_OPTS >/dev/null 2>&1 then return 0 else $DAEMON -t $DAEMON_OPTS return $? fi } case "$1" in start) echo -n "Starting $DESC: " test_nginx_config start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \ --exec $DAEMON -- $DAEMON_OPTS || true echo "$NAME." ;; stop) echo -n "Stopping $DESC: " start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \ --exec $DAEMON || true echo "$NAME." ;; restart|force-reload) echo -n "Restarting $DESC: " start-stop-daemon --stop --quiet --pidfile \ /var/run/$NAME.pid --exec $DAEMON || true sleep 1 test_nginx_config start-stop-daemon --start --quiet --pidfile \ /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true echo "$NAME." ;; reload) echo -n "Reloading $DESC configuration: " test_nginx_config start-stop-daemon --stop --signal HUP --quiet --pidfile /var/run/$NAME.pid \ --exec $DAEMON || true echo "$NAME." ;; configtest) echo -n "Testing $DESC configuration: " if test_nginx_config then echo "$NAME." else exit $? fi ;; status) status_of_proc -p /var/run/$NAME.pid "$DAEMON" nginx && exit 0 || exit $? ;; *) echo "Usage: $NAME {start|stop|restart|reload|force-reload|status|configtest}" >&2 exit 1 ;; esac exit 0nginx/conf/nginx.conf內容以下,由於web站點目錄和log日誌目錄都有所改變,因此要小調一下
worker_processes 1; error_log /var/logs/nginx/error.log; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/logs/nginx/access.log main; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root /var/www; index index.html index.htm; } error_page 500 502 503 504 /var/www/50x.html; location = /50x.html { root /var/www; } } }
剩下DEBIAN目錄沒有配置,結構以下:
DEBIAN/ ├── control ├── postinst ├── postrm ├── preinst └── prermcontrol:提供軟件包的關聯信息, 用於軟件包管理器顯示軟件包的信息,用於安裝前校驗的依賴關係.是必需提供的文件
postrm:在軟件包從系統中卸載之後執行。dpkg告知這個腳本軟件包是否已被卸載或清除。當由於衝突或升級,軟件包被其它軟件包卸載時也會執行這個腳本。
preinst:在安裝或升級軟件包以前執行。
prerm:腳本在軟件包卸載以前執行。
postinst:腳本在解包以後做爲配置過程的一部分運行。例如:監聽本機ip地址,更換端口之類的修改。在本文中我不須要作調整,因此沒有設置該文件。
DEBIAN/control內容以下,由於以前把依賴包都安裝了,因此在控制文件中我去掉了依賴關係設置
Package: nginx Version: 1.2.5 Architecture: amd64 Maintainer: Jose Parrella <bureado@debian.org> Provides: httpd Section: httpd Priority: optional Homepage: http://nginx.net Description: xxxxxxxxDEBIAN/prerm文件內容以下
#!/bin/sh set -e case "$1" in remove|remove-in-favour|deconfigure|deconfigure-in-favour) if [ -x /etc/init.d/nginx ]; then if [ -x /usr/sbin/invoke-rc.d ] ; then invoke-rc.d nginx stop else /etc/init.d/nginx stop fi fi ;; upgrade|failed-upgrade) ;; *) echo "prerm called with unknown argument \`$1'" >&2 exit 1 ;; esac exit 0DEBIAN/postrm文件內容以下
#!/bin/sh set -e case "$1" in purge) rm -rf /var/lib/nginx /var/log/nginx /etc/nginx ;; remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) ;; *) echo "postrm called with unknown argument \`$1'" >&2 exit 1 esac # Automatically added by dh_installinit if [ "$1" = "purge" ] ; then update-rc.d nginx remove >/dev/null fi # End automatically added section exit 0
DEBIAN/preinst文件內容以下
#!/bin/sh set -e if [ ! -d /var/lib/nginx ] ; then mkdir -p /var/lib/nginx fi if [ ! -d /etc/nginx ] ; then mkdir -p /etc/nginx/conf mkdir -p /etc/nginx/modules mkdir -p /etc/nginx/sbin fi if [ ! -d /var/log/nginx ] ; then mkdir -p /var/log/nginx touch /var/log/nginx/error.log fi exit 0全部文件已經ok,剩下就是打包了
dpkg -b tengine/ tengine_1.4.2-1+squeeze_amd64.deb測試以下圖:
加載ngx_http_autoindex_module.so模塊,在配置文件中加入以下配置
dso{ load ngx_http_autoindex_module.so; }重啓nginx,加入前和加入後區別以下
訪問nginx默認界面
卸載tengine軟件包
apt-get --purge remove nginx