debian; ubuntu; kali / 未分类 · 2014年7月9日

制作Debian风格的Tengine deb包

首先,在/root 目录下建一个制作deb包的环境目录tengine,先不必建立其他目录,最后的总体结构如下图: (暂时没图)
安装一下要用的模块 这个是参考了原作者的
libgd2-xpm may be not
apt-get install -y libxml2 libxslt1.1 libxslt1-dev libgd2-xpm libgd2-xpm-dev libgeoip1 libgeoip-dev libssl-dev libpcre3 libpcre3-dev libssl0.9.8
下载tengine源码包:tengine-1.4.2.tar.gz,进行编译安装,编译参数如下 若是有报错,把相关的模块去掉算了
wget -c http://tengine.taobao.org/download/tengine-1.4.2.tar.gz
./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二进制文件
这个在make 时会出错
http://tengine.taobao.org/document_cn/http_sysguard_cn.html
http://blog.linuxeye.com/357.html
–with-http_sysguard_module=shared
之前已经把所有依赖的包已经安装过了,所以不会出现问题,只要make -j3 &&make install 即可,安装完成后在/etc/nginx中的目录结构如下:
tree /etc/ngnix/
然后 move 文件 准备打包
mkdir -p /root/tengine/etc/nginx/ /root/tengine/var/www/ /root/tengine/etc/nginx/ /root/tengine/etc/nginx/ /root/tengine/usr/sbin/ /root/tengine/etc/logrotate.d
mv /etc/nginx/conf /root/tengine/etc/nginx/
mv /etc/nginx/html/* /root/tengine/var/www/
mv /etc/nginx/modules /root/tengine/etc/nginx/
mv /etc/nginx/sbin /root/tengine/etc/nginx/
mv /usr/sbin/nginx /root/tengine/usr/sbin/

开始补全在/root/tengine的其他目录。
logrotate.d/nginx内容如下,nginx日志轮训用
vi /root/tengine/etc/logrotate.d/nginx
/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用
mkdir -p /root/tengine/etc/init.d/
vi /root/tengine/etc/init.d/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 0

chmod +x /root/tengine/etc/init.d/nginx
cp /dev/null /root/tengine/etc/nginx/conf/nginx.conf
vi /root/tengine/etc/nginx/conf/nginx.conf

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目录有配置
control:提供软件包的关联信息, 用于软件包管理器显示软件包的信息,用于安装前校验的依赖关系.是必需提供的文件
postrm:在软件包从系统中卸载以后执行。dpkg告知这个脚本软件包是否已被卸载或清除。当因为冲突或升级,软件包被其它软件包卸载时也会执行这个脚本。
preinst:在安装或升级软件包之前执行。
prerm:脚本在软件包卸载之前执行。
postinst:脚本在解包之后作为配置过程的一部分运行。例如:监听本机ip地址,更换端口之类的修改。在本文中我不需要做调整,所以没有设置该文件。
DEBIAN/control内容如下,因为之前把依赖包都安装了,所以在控制文件中去掉了依赖关系设置,觉得这样做不好
mkdir -p /root/tengine/DEBIAN
vi /root/tengine/DEBIAN/control
Package: nginx
Version: 1.2.5
Architecture: amd64
Maintainer: Jose Parrella
Provides: httpd
Section: httpd
Priority: optional
Homepage: http://nginx.net
Description: xxxxxxxx

vi /root/tengine/DEBIAN/postinst
vi /root/tengine/DEBIAN/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

vi /root/tengine/DEBIAN/preinst
vi /root/tengine/DEBIAN/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 0

#要看清楚,不是说644是ok的
[email protected]:~# dpkg -b tengine/ tengine_1.4.2-1+deep_amd64.deb
dpkg-deb: error: 维护者的脚本 preinst 的权限位是 644 (必须 >=0555 且 <=0775) chmod 0755 tengine/DEBIAN/preinst ;chmod 0755 tengine/DEBIAN/prerm
chmod 0755 tengine/DEBIAN/postrm

打包
dpkg -b tengine/ tengine_1.4.2-1+deep_amd64.deb
卸载tengine软件包
apt-get --purge remove nginx
参考
http://my.oschina.net/guol/blog/95708
ps 其它好功能
加载ngx_http_autoindex_module.so模块,在配置文件中加入如下配置
dso{
load ngx_http_autoindex_module.so;
}
我在deepin 2014 打包的 好像云了debian 哈哈 当然是不能用了 可能ubuntu的话可以