fpm定製化RPM包之nginx rpm包的製做html
1.安裝ruby模塊python
# yum -y install ruby rubygems ruby-devel
2.添加阿里雲的Rubygems倉庫,國外資源會影響下載速度nginx
gem sources -a http://mirrors.aliyun.com/rubygems/ http://mirrors.aliyun.com/rubygems/ added to sources
移除原生的ruby倉庫c++
gem sources --remove http://rubygems.org/
3.安裝fpm數據庫
centos6: gem install json -v 1.8.3 gem install fpm -v 1.3.3
centos7直接使用以下命令:npm
[root@slave02 ~]# gem install fpm Fetching: cabin-0.9.0.gem (100%) Successfully installed cabin-0.9.0 Fetching: backports-3.8.0.gem (100%) Successfully installed backports-3.8.0 Fetching: arr-pm-0.0.10.gem (100%) Successfully installed arr-pm-0.0.10 Fetching: clamp-1.0.1.gem (100%) Successfully installed clamp-1.0.1 Fetching: ffi-1.9.18.gem (100%) Building native extensions. This could take a while... Successfully installed ffi-1.9.18 Fetching: childprocess-0.7.0.gem (100%) Successfully installed childprocess-0.7.0 Fetching: archive-tar-minitar-0.5.2.gem (100%) Successfully installed archive-tar-minitar-0.5.2 Fetching: io-like-0.3.0.gem (100%) Successfully installed io-like-0.3.0 Fetching: ruby-xz-0.2.3.gem (100%) Successfully installed ruby-xz-0.2.3 Fetching: stud-0.0.22.gem (100%) Successfully installed stud-0.0.22 Fetching: mustache-0.99.8.gem (100%) Successfully installed mustache-0.99.8 Fetching: insist-1.0.0.gem (100%) Successfully installed insist-1.0.0 Fetching: dotenv-2.2.1.gem (100%) Successfully installed dotenv-2.2.1 Fetching: pleaserun-0.0.29.gem (100%) Successfully installed pleaserun-0.0.29 Fetching: fpm-1.8.1.gem (100%) Successfully installed fpm-1.8.1 Parsing documentation for cabin-0.9.0 Installing ri documentation for cabin-0.9.0 Parsing documentation for backports-3.8.0 Installing ri documentation for backports-3.8.0 Parsing documentation for arr-pm-0.0.10 Installing ri documentation for arr-pm-0.0.10 Parsing documentation for clamp-1.0.1 Installing ri documentation for clamp-1.0.1 Parsing documentation for ffi-1.9.18 Installing ri documentation for ffi-1.9.18 Parsing documentation for childprocess-0.7.0 Installing ri documentation for childprocess-0.7.0 Parsing documentation for archive-tar-minitar-0.5.2 Installing ri documentation for archive-tar-minitar-0.5.2 Parsing documentation for io-like-0.3.0 Installing ri documentation for io-like-0.3.0 Parsing documentation for ruby-xz-0.2.3 Installing ri documentation for ruby-xz-0.2.3 Parsing documentation for stud-0.0.22 Installing ri documentation for stud-0.0.22 Parsing documentation for mustache-0.99.8 Installing ri documentation for mustache-0.99.8 Parsing documentation for insist-1.0.0 Installing ri documentation for insist-1.0.0 Parsing documentation for dotenv-2.2.1 Installing ri documentation for dotenv-2.2.1 Parsing documentation for pleaserun-0.0.29 Installing ri documentation for pleaserun-0.0.29 Parsing documentation for fpm-1.8.1 Installing ri documentation for fpm-1.8.1 15 gems installed
4.在打包機器上先安裝一次nginxjson
yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre pcre-devel glib glib-devel useradd nginx -M -s /sbin/nologin tar xf nginx-1.12.0.tar.gz cd nginx-1.12.0 ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-file-aio --with-http_dav_module --with-pcre make && make install
5.編寫腳本
軟件包卸載前、卸載後的腳本,能夠根據狀況是否編寫,不編寫問題也不大。可是rpm安裝後的腳本是必須的。vim
mkdir /data/scripts/ -p cd /data/scripts/
# 編寫一個rpm安裝後須要執行的腳本
vim nginx_post_install.sh centos
#!/bin/bash useradd nginx -M -s /sbin/nologin chmod +x /etc/init.d/nginx chkconfig --add nginx echo 'PATH=/user/local/nginx/sbin:$PATH'>> /etc/profile.d/nginx.sh
# 卸載nginx後須要執行的腳本ruby
# cat after_remove.sh #!/bin/bash rm -rf /usr/local/nginx rm -f /etc/rc.d/init.d/nginx
準備個啓動腳本,以下:
vim /etc/init.d/nginx #!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # proxy and IMAP/POP3 proxy server # processname: nginx # config: /usr/local/nginx/conf/nginx.conf # pidfile: /usr/local/nginx/logs/nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/local/nginx/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" lockfile=/var/lock/subsys/nginx make_dirs() { # make required directories user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -` if [ -z "`grep $user /etc/passwd`" ]; then useradd -M -s /bin/nologin $user fi options=`$nginx -V 2>&1 | grep 'configure arguments:'` for opt in $options; do if [ `echo $opt | grep '.*-temp-path'` ]; then value=`echo $opt | cut -d "=" -f 2` if [ ! -d "$value" ]; then # echo "creating" $value mkdir -p $value && chown -R $user $value fi fi done } start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 make_dirs echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { configtest || return $? stop sleep 1 start } reload() { configtest || return $? echo -n $"Reloading $prog: " $nginx -s reload RETVAL=$? echo } force_reload() { restart } configtest() { $nginx -t -c $NGINX_CONF_FILE } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest) $1 ;; reload) rh_status_q || exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0 ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2 esac
6. 打包(打包的過程其實就是將咱們編譯安裝好的文件、目錄打包,/data/scripts/是本次的打包工做目錄)
# 將nginx啓動腳本和注意的配置及啓動文件拷貝到打包目錄
mkdir -p /data/scripts/etc/rc.d/init.d cp /etc/init.d/nginx /data/scripts/etc/rc.d/init.d/ mkdir -p /data/scripts/usr/local/nginx/ cp -r /usr/local/nginx/ /data/scripts/usr/local/nginx/
# /data/scripts目錄結構
[root@master scripts]# tree
. ├── after_remove.sh ├── etc │ └── rc.d │ └── init.d │ └── nginx ├── nginx-1.12.0-1.el6.x86_64.rpm ├── nginx_post_install.sh └── usr └── local └── nginx ├── client_body_temp ├── conf │ ├── fastcgi.conf │ ├── fastcgi.conf.default │ ├── fastcgi_params │ ├── fastcgi_params.default │ ├── koi-utf │ ├── koi-win │ ├── mime.types │ ├── mime.types.default │ ├── nginx.conf │ ├── nginx.conf.default │ ├── scgi_params │ ├── scgi_params.default │ ├── uwsgi_params │ ├── uwsgi_params.default │ └── win-utf ├── etc │ └── rc.d │ └── init.d │ └── nginx ├── fastcgi_temp ├── html │ ├── 50x.html │ └── index.html ├── logs │ ├── access.log │ ├── error.log │ └── nginx.pid ├── proxy_temp ├── sbin │ └── nginx ├── scgi_temp └── uwsgi_temp
# 打包,即將準備好的文件打包成rpm
# fpm -f -s dir -t rpm -n nginx --epoch 0 -v 1.12.0 --iteration 1.el6 -C /data/scripts/ -d 'pcre-devel,openssl-devel,autoconf,glib-devel' --post-uninstall /data/scripts/nginx_post_install.sh --post-uninstall /data/scripts/after_remove.sh --workdir /data/scripts/ etc usr
Created package {:path=>"nginx-1.12.0-1.el6.x86_64.rpm"}
報錯:
Need executable 'rpmbuild' to convert dir to rpm {:level=>:error}
解決:
yum install rpm-build -y
# 注意:咱們能夠操做前修改下主機名,這樣打包出來的Build Host就會跟着改變。
7. 安裝rpm包
yum命令安裝rpm包
yum -y localinstall nginx-1.12.0-1.x86_64.rpm
這個命令會自動先安裝rpm包的依賴,而後再安裝rpm包。
FPM經常使用參數: -f :強制覆蓋[覆蓋同名rpm包] -n :指定的rpm包名 -p :指定的rpm包文件放置位置 -v :指定的rpm包版本 -d :指定依賴的軟件 ( [-d 'name'] or [-d 'name > version'] 例子: -d 'libstdc++ >= 4.4.3') -a :指定系統架構,若是是noarch則爲'-a all' 或者 '-a native' [x86_64] 當軟件不區分64位或32位的時候能夠 noarch -s :指定INPUT的數據類型 (["-s dir"] 省略數據類型) -m :指定打包人員[Packager] ([ -m 'user']) -C :指定打包的相對路徑,相似於buildroot. 譬如-C /tmp/apr/ 而打包機器的數據包路徑是/tmp/apr/{opt,usr,etc} 那安裝這個rpm包後,在本地的數據就是/opt/,/usr/,/etc/ -t :指定須要製做成什麼包,可選項有(deb,rpm,solaris,etc) 支持的源類型:: "dir" "rpm" "gem" "python" "empty" "tar" "deb" "cpan" "npm" "osxpkg" "pear" "pkgin" "virtualenv" "zip" 支持的目標類型: "rpm" "deb" "solaris" "puppet" "dir" "osxpkg" "p5p" "puppet" "sh" "solaris" "tar" "zip" --description :軟件包描述 --conflicts :指定衝突軟件 --url :指定站點[慣例都是添加軟件的官網 例如: --url "http://www.cnblog.com/roach57" ] --verbose :安裝過程詳細打印 --after-install :包安裝以後執行的腳本 也可寫做 --post-install FILE --before-install :包安裝以前執行的腳本 --after-remove :包卸載以後執行的腳本 --before-remove :包卸載以前執行的腳本 --after-upgrade :包更新以後執行的腳本[僅支持 deb 和 rpm 這兩種包] --before-upgrade :包更新以前執行的腳本 --iteration :發佈序號[就是rpm包裏面的release] --epoch :紀元 [不知道幹嗎用的] --no-rpm-sign :不使用rpm簽名 Signature --license :證書許可 [可選項有 'BSD(開源軟件)' 'GPLv2(自由軟件)' 'MIT' 'Public Domain(公共域)' 'Distributable(貢獻)' 'commercial(商業)' 'Share(共享)等',通常的開發都寫'BSD'或'GPL'] --vendor :供應商名稱 [ --vendor 'roach57@163.com'] --no-depends :表明沒有任何依賴包,和-d是對立的,不能共用 --config-files :指定配置文件,能夠指定目錄[遞歸] --directories :指定包目錄 --category :軟件所屬的類別[這是個什麼軟件]下面有個對應的表格: [參考這個文件 /usr/share/doc/rpm-x.x.x/GROUPS ] Amusements/Games [娛樂/遊戲] Amusements/Graphics [娛樂/圖形] Applications/Archiving [應用/文檔] Applications/Communications [應用/通信] Applications/Databases [應用/數據庫] Applications/Editors [應用/編輯器] Applications/Emulators [應用/仿真器] Applications/Engineering [應用/工程] Applications/File [應用/文件] Applications/Internet [應用/因特網] Applications/Multimedia [應用/多媒體] Applications/Productivity [應用/產品] Applications/Publishing [應用/印刷] Applications/System [應用/系統] Applications/Text [應用/文本] Development/Debuggers [開發/調試器] Development/Languages [開發/語言] Development/Libraries [開發/函數庫] Development/System [開發/系統] Development/Tools [開發/工具] Documentation [文檔] System Environment/Base [系統環境/基礎] System Environment/Daemons [系統環境/守護] System Environment/Kernel [系統環境/內核] System Environment/Libraries [系統環境/函數庫] System Environment/Shells [系統環境/接口] User Interface/Desktops [用戶界面/桌面] User Interface/X [用戶界面/X窗口] User Interface/X Hardware Support [用戶界面/X硬件支持] RPM包的組成格式: roach-1.0.1-57.el6.x86_64.rpm | | | | | 軟件名稱| | | | 版本號 | | | 發佈號 | | 硬件平臺 | 擴展名 例子備註: roach :軟件名稱 1.0.1 :軟件版本號 57.el6 :發佈號主要是對軟件存在的bug或漏洞進行修補,在軟件功能上並無變化,el6指的是rhel6系統中發佈 x86_64 :指64位的PC架構,另外還有'i386' 'i686' 等32位的PC架構,noarch是指不區分硬件架構 rpm :擴展名