lnmp的rpm包制作

说明:1. lnmp 即,linux、niginx、mysql、php 所组成的web服务环境。
           2. 制作lnmp的rpm包可以节省因编译源码包所浪费的大量的时间和精力,也便于实现运维的自动化。    
           3. 此lnmp包,除了启动脚本,所有文件都同一安装在/usr/local/lnmp目录下面。有一个同一的启动脚本 lnmp,启动和停止服务直接/etc/init.d/lnmp  start/stop 即可。也可以单独运行各自的脚本。
           5. 以下是我自己编写的rpm包的 spec文件,可以直接使用。
            


%define prefix  /usr/local/lnmp

Name:           lnmp
Version:        1.0
Release:        1%{?dist}
Summary:        Web Integrated Environment for lnmp

Group:          System Environment/Base
License:        LCPL
URL:            http://www.yonchin.org
Source0:        lnmp-1.0.tar.gz
Source1:        libunwind-1.1.tar.gz
Source2:        gperftools-2.0.tar.gz
Source3:        libxml2-2.6.30.tar.gz
Source4:        libmcrypt-2.5.8.tar.bz2
Source5:        zlib-1.2.8.tar.gz
Source6:        libpng-1.6.2.tar.gz
Source7:        jpegsrc.v9.tar.gz
Source8:        freetype-2.5.0.1.tar.bz2
Source9:        gd-2.1.0-preview.tar.gz
Source10:       pcre-8.33.tar.bz2
Source11:       nginx-1.5.1.tar.gz
Source12:       mysql-5.6.12.tar.gz
Source13:       php-5.5.0.tar.gz
Source14:       lnmp
Source15:       nginx
Source16:       php-fpm
Source17:       mysqld
Source18:       nginx.conf
Source19:       php-fpm.conf
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)


%description
nginx+mysql+php


%prep
%setup -q -b 1 -b 2 -b 3 -b 4 -b 5 -b 6 -b 7 -b 8 -b 9 -b 10 -b 11 -b 12 -b 13


%build
cd ../libunwind-1.1
./configure --prefix=%{prefix}/gperftools \
--disable-dependency-tracking \
CFLAGS="-O3 -fPIC"
make -j3
 

cd ../gperftools-2.0
./configure --prefix=%{prefix}/gperftools \
--enable-frame-pointers \
--disable-dependency-tracking \
CFLAGS="-O3 -fPIC"
CFLAGS=-fPIC
make -j3

cd ../libxml2-2.6.30
./configure --prefix=%{prefix}/libxml2 \
CFLAGS="-O3 -fPIC"
make -j3
 

cd ../libmcrypt-2.5.8
./configure --prefix=%{prefix}/libmcrypt \
CFLAGS="-O3 -fPIC"
make -j3
 

cd ../zlib-1.2.8
./configure --prefix=%{prefix}/zlib
make -j3
 

cd ../libpng-1.6.2
./configure --prefix=%{prefix}/libpng \
CFLAGS="-O3 -fPIC"
make -j3
 

cd ../jpeg-9
./configure --prefix=%{prefix}/jpeg9 \
        CFLAGS="-O3 -fPIC"
make -j3
 

cd ../freetype-2.5.0.1
./configure --prefix=%{prefix}/freetype \
CFLAGS="-O3 -fPIC"
make -j3

cd ../gd-2.1.0
./configure --prefix=%{prefix}/gd2 \
        --with-zlib=%{prefix}/zlib \
        --with-png=%{prefix}/libpng \
        --with-jpeg=%{prefix}/jpeg9 \
        --with-freetype=%{prefix}/freetype \
        LDFLAGS="-L%{prefix}/libpng/lib/ -L%{prefix}/zlib/lib/" \
        CFLAGS="-O3 -fPIC"
make -j3
 

cd ../pcre-8.33
./configure --prefix=%{prefix}/pcre
        CFLAGS="-O3 -fPIC"
make -j3
 

cd ../nginx-1.5.1
./configure --prefix=%{prefix}/nginx \
        --with-http_flv_module \
        --with-http_stub_status_module \
        --with-google_perftools_module \
        --with-http_gzip_static_module \
        --with-pcre-jit
make -j3
 

cd ../mysql-5.6.12
cmake . -DCMAKE_INSTALL_PREFIX=%{prefix}/mysql -DMYSQL_DATADIR=%{prefix}/mysql/data -DMYSQL_UNIX_ADDR=%{prefix}/mysql/data/mysql.sock   -DEFAULT_CHARSET=utf8   -DEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSET=all -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1  -DWITH_MYISAM_STORAGE_ENGINE=1  -DWITH_READLINE=1 -DWITH_ZLIB=bundled -DWITH_TCP_PORT=3306 -DMYSQL_USER=mysql
make -j3
                             
 cd ../php-5.5.0
./configure --prefix=%{prefix}/php \
        --with-config-file-path=%{prefix}/php/etc \
        --with-mysql=%{prefix}/mysql \
        --with-libxml-dir=%{prefix}/libxml2 \
        --with-mcrypt=%{prefix}/libmcrypt \
        --with-zlib-dir=%{prefix}/zlib \
        --with-png-dir=%{prefix}/libpng \
        --with-jpeg-dir=%{prefix}/jpeg9 \
        --with-freetype-dir=%{prefix}/freetype \
        --with-gd \
        --with-mysqli=%{prefix}/mysql/bin/mysql_config \
        --without-iconv \
        --enable-fpm \
        --enable-opcache \
        --enable-soap \
        --enable-mbstring=all \
        --enable-sockets \
        CFLAGS="-O3 -fPIC"
make -j3


%install
rm -rf $RPM_BUILD_ROOT
cd ../libunwind-1.1
make install DESTDIR=$RPM_BUILD_ROOT

cd ../gperftools-2.0
make install DESTDIR=$RPM_BUILD_ROOT

cd ../libxml2-2.6.30
make install DESTDIR=$RPM_BUILD_ROOT

cd ../libmcrypt-2.5.8
make install DESTDIR=$RPM_BUILD_ROOT

cd ../zlib-1.2.8
make install DESTDIR=$RPM_BUILD_ROOT

cd ../libpng-1.6.2
make install DESTDIR=$RPM_BUILD_ROOT

cd ../jpeg-9
make install DESTDIR=$RPM_BUILD_ROOT

cd ../freetype-2.5.0.1
make install DESTDIR=$RPM_BUILD_ROOT

cd ../gd-2.1.0
make install DESTDIR=$RPM_BUILD_ROOT

cd ../pcre-8.33
make install DESTDIR=$RPM_BUILD_ROOT

cd ../nginx-1.5.1
make install DESTDIR=$RPM_BUILD_ROOT
cd ../mysql-5.6.12
make install DESTDIR=$RPM_BUILD_ROOT

cd ../php-5.5.0
make install INSTALL_ROOT=$RPM_BUILD_ROOT

install -p -m 0755 -D %{SOURCE14} %{buildroot}%{_initrddir}/lnmp
install -p -m 0755 -D %{SOURCE15} %{buildroot}%{_initrddir}/nginx
install -p -m 0755 -D %{SOURCE16} %{buildroot}%{_initrddir}/php-fpm
install -p -m 0755 -D %{SOURCE17} %{buildroot}%{_initrddir}/mysqld
install -p -m 0644 -D %{SOURCE18} %{buildroot}%{prefix}/nginx/conf/nginx.conf
install -p -m 0644 -D %{SOURCE19} %{buildroot}%{prefix}/php/etc/php-fpm.conf
 
 %pre
if [ $1 = 1 ];then
/usr/sbin/groupadd nginx
/usr/sbin/groupadd mysql
/usr/sbin/useradd -r nginx -g nginx -s /sbin/nologin
/usr/sbin/useradd -r mysql -g mysql -s /sbin/nologin

fi

%post
if [ $1 = 1 ];then
/sbin/chkconfig --add lnmp
cat >/etc/profile.d/lnmp.sh<PATH=$PATH:%{prefix}/libpng/bin:%{prefix}/mysql/bin
EOF
source /etc/profile &>/dev/null

cat >/etc/ld.so.conf.d/lnmp.conf</usr/local/lnmp/libpng/lib
/usr/local/lnmp/jpeg9/lib
/usr/local/lnmp/zlib/lib
/usr/local/lnmp/freetype/lib
/usr/local/lnmp/libxml2/lib
/usr/local/lnmp/libmcrypt/lib
/usr/local/lnmp/gperftools/lib
/usr/local/lnmp/pcre/lib
/usr/local/lnmp/gd2/lib
EOF
/sbin/ldconfig
ln -sv /usr/local/lnmp/zlib/include/* /usr/include/
              ln -sv  /usr/local/lnmp/zlib/lib/* /usr/lib/
fi

%postun
/usr/sbin/userdel nginx &>/dev/null
/usr/sbin/userdel mysql &>/dev/null
/bin/rm -f /etc/profile.d/lnmp.sh &>/dev/null
/bin/rm -f /etc/ld.so.conf.d/lnmp.conf &>/dev/null

 

%clean
rm -rf $RPM_BUILD_ROOT
                                    
 %files
%defattr(-,root,root,-)
%doc
/usr/local/lnmp/freetype/
/usr/local/lnmp/gd2/
/usr/local/lnmp/gperftools/
/usr/local/lnmp/jpeg9/
/usr/local/lnmp/libmcrypt/
/usr/local/lnmp/libpng/
/usr/local/lnmp/libxml2/
/usr/local/lnmp/mysql/
/usr/local/lnmp/php/
/usr/local/lnmp/nginx/
/usr/local/lnmp/pcre/
/etc/rc.d/init.d/

 


%changelog
*  Fri Jul 2013 Mr.Yang    - 1.0.1
- LNMP 


可能错误及解决方法:
1. 遇到/usr/lib/rpm/check-rpaths 找不到路径问题
解决方法:
       删除$HOME/.rpmmacros  文件中的%__arch_install_post   /usr/lib/rpm/check-rpaths   /usr/lib/rpm/check-buildroot 这一行即可。