码迷,mamicode.com
首页 > 其他好文 > 详细

FPM打包工具制作线上nginx的RPM包

时间:2018-03-04 17:11:40      阅读:293      评论:0      收藏:0      [点我收藏+]

标签:链接库   lin   打包工具   tps   red   RKE   virt   direct   some   

 

一、安装FPM打包工具

1.FPM是ruby的模块,先安装FPM依赖的包

[root@localhost ~]#  yum -y install ruby rubygems ruby-devel rpm-build

2.因国内网络环境,访问http://rubygems.org/站点时不稳定,所以增加国内toabao提供的一个镜像站点,把原来的站点移除

[root@localhost ~]#  gem sources -a https://ruby.taobao.org/

[root@localhost ~]#  gem sources --remove http://rubygems.org/

[root@localhost ~]#  gem install fpm

Buildingnative extensions.  This could take awhile...

Buildingnative extensions.  This could take awhile...

ERROR:  Error installing fpm:

        ruby-xz requires Ruby version >=1.9.3.

Ruby版本太低安装不了最新的fpm,更新ruby或者安装旧版本fpm如:1.4.0

[root@localhost ~]#  gem install fpm -v 1.4.0

Successfullyinstalled clamp-0.6.5

Successfullyinstalled fpm-1.4.0

2gems installed

Installingri documentation for clamp-0.6.5...

Installingri documentation for fpm-1.4.0...

InstallingRDoc documentation for clamp-0.6.5...

InstallingRDoc documentation for fpm-1.4.0...

出现以上返回则证明安装成功

[root@localhost ~]#  gem -v

1.3.7

二、在一台新机器上编译安装源码nginx

1.下载需要的源码包

[root@localhost ~]#  wget http://sourceforge.net/projects/pcre/files/pcre/8.30/pcre-8.30.tar.gz

[root@localhost ~]#  wget http://tengine.taobao.org/download/tengine-2.0.3.tar.gz

2.创建pcre库

[root@localhost ~]#  tar zxvf pcre-8.30.tar.gz

[root@localhost ~]#  cd pcre-8.30

[root@localhost pcre-8.30]#  ./configure

[root@localhost pcre-8.30]#  make &&make install

3.创建动态链接库共享的调用

ln -sf /usr/local/lib/libpcre.a /usr/lib64/libpcre.a

ln -sf /usr/local/lib/libpcre.la /usr/lib64/libpcre.la

ln -sf /usr/local/lib/libpcre.so /usr/lib64/libpcre.so

ln -sf /usr/local/lib/libpcre.so.1 /usr/lib64/libpcre.so.1

ln -sf /usr/local/lib/libpcre.so.1.0.0 /usr/lib64/libpcre.so.1.0.0

4.编译安装nginx

[root@localhost package]# tar zxvf tengine-2.0.3.tar.gz

[root@localhost package]# cd tengine-2.0.3

[root@localhost tengine-2.0.3]# ./configure \

--user=www \

--group=www \

--prefix=/usr/local/nginx \

--with-http_stub_status_module \

--with-http_ssl_module

[root@localhost nginx-1.2.2]# make && make install

[root@localhost nginx-1.2.2]# cd ..

5.测试nginx是否安装成功

[root@localhost ~]#  /usr/local/nginx/sbin/nginx -t

the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

configuration file /usr/local/nginx/conf/nginx.conf test is successful

[root@localhost ~]#

三、创建一个安装tengine的临时目录,fpm可以从这个目录读取信息

[root@localhost ~]#  mkdir /tmp/install

[root@localhost ~]#  cd tengine-2.0.3

[root@localhost tengine-2.0.3]# make install DESTDIR=/tmp/install/

[root@localhost tengine-2.0.3]# cd /tmp/install

查看一下目录结构:

[root@localhost install]# tree -L 3

.

└── usr

    └── local

        └── nginx

 

3 directories, 0 files

四、准备rpm安装后所需要运行的脚本

1.创建放置脚本的目录

[root@localhost tengine-2.0.3]# cd /tmp/install

[root@localhost install]# mkdir script

2.编写rpm安装完成后调用的脚本

[root@localhost install]# cd script

[root@localhost script]# vim install_after.sh

#!/bin/bash

#创建web工作目录

mkdir -p /data/www

#创建www用户组和账号

groupadd www

useradd -g www www

#创建nginx日志目录

mkdir -p /data/weblogs/nginx

chmod +w /data/weblogs/nginx

chown -R www:www /data/weblogs/nginx

保存退出即可

3.修改临时目录下的配置文件

[root@localhost ~]# cd /tmp/install/usr/local/nginx/conf

[root@localhost conf]# mv nginx.conf nginx.conf.bak

[root@localhost conf]# vim nginx.conf

添加线上nginx配置文件中的配置内容即可

user  www;

worker_processes  16;

 

error_log  /data/weblogs/nginx/error.log;

#error_log  /data/weblogs/nginx/error.log;  notice;

#error_log  /data/weblogs/nginx/error.log;  info;

 

#pid        logs/nginx.pid;

 

events {

use epoll;

worker_connections  65535;

}

 

http {

server_names_hash_bucket_size 128;

client_header_buffer_size 32k;

large_client_header_buffers 4 32k;

client_max_body_size 8m;

 

#fastcgi_connect_timeout 300;

#fastcgi_send_timeout 300;

#fastcgi_read_timeout 300;

fastcgi_connect_timeout 30s;

fastcgi_send_timeout 30s;

fastcgi_read_timeout 30s;

fastcgi_buffer_size 64k;

fastcgi_buffers 4 64k;

fastcgi_busy_buffers_size 128k;

fastcgi_temp_file_write_size 128k;

fastcgi_intercept_errors on;

gzip  on;

gzip_min_length 1k;

gzip_buffers 4 16k;

gzip_http_version 1.0;

gzip_comp_level 2;

gzip_types text/plain application/x-javascript text/css application/xml application/json;

gzip_vary on;

 

include       mime.types;

default_type  application/octet-stream;

 

log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘

  ‘$status "$request_body" $body_bytes_sent "$http_referer" ‘

  ‘"$http_user_agent" "$http_x_forwarded_for" ‘

  ‘"$request_time" "$upstream_response_time"‘;

 

#access_log  logs/access.log  main;

 

sendfile        on;

#tcp_nopush     on;

 

#keepalive_timeout  0;

#keepalive_timeout  65;

keepalive_timeout  120s;

 

#gzip  on;

server {

listen       80;

server_name  localhost;

index        index.php;

root         /data/www/localhost;

charset      utf-8;

 

#charset koi8-r;

 

access_log  /data/weblogs/localhost.access.log  main;

 

location / {}

 

#error_page  404              /404.html;

 

# redirect server error pages to the static page /50x.html

#

error_page   500 502 503 504  /50x.html;

#location = /50x.html {

#    root   html;

#}

 

# proxy the PHP scripts to Apache listening on 127.0.0.1:80

#

#location ~ \.php$ {

#    proxy_pass   http://127.0.0.1;

#}

 

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

location ~ \.php$ {

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

include        fastcgi.conf;

}

 

# deny access to .htaccess files, if Apache‘s document root

# concurs with nginx‘s one

#

location ~ /\.ht {

deny  all;

}

 

location /nginx_status {

stub_status on;

access_log off;

allow 42.62.40.143/32;

allow 127.0.0.1;

allow 211.157.139.96/29;

allow 211.157.140.8/29;

allow 42.62.26.124/32;

allow 10.0.0.0/8;

deny all;

}

}

 

# another virtual host using mix of IP-, name-, and port-based configuration

#

#server {

#    listen       8000;

#    listen       somename:8080;

#    server_name  somename  alias  another.alias;

 

#    location / {

#        root   html;

#        index  index.html index.htm;

#    }

#}

 

 

# HTTPS server

#

#server {

#    listen       443;

#    server_name  localhost;

 

#    ssl                  on;

#    ssl_certificate      cert.pem;

#    ssl_certificate_key  cert.key;

 

#    ssl_session_timeout  5m;

 

#    ssl_protocols  SSLv2 SSLv3 TLSv1;

#    ssl_ciphers  HIGH:!aNULL:!MD5;

#    ssl_prefer_server_ciphers   on;

 

#    location / {

#        root   html;

#        index  index.html index.htm;

#    }

#}

include ./vhost/*;

}

 

4.创建vhost目录,创建nginx配置文件模板

[root@localhost ~]# cd /tmp/install/usr/local/nginx/conf

[root@localhost conf]# mkdir vhost

[root@localhost conf]# cd vhost

[root@localhost vhost]# touch sxx.example.com

[root@localhost vhost]# chmod 755 sxx.example.com

[root@localhost vhost]# vim sxx.example.com

添加以下模板内容

server {

    listen       80;

    server_name  sxx.example.com;

    index  index.php index.html index.htm;

    root         /data/www/sxx.example.com;

    charset      utf-8;

 

    access_log   /data/weblogs/nginx/s56.game.access.log  main;

 

    location / {

    }

 

    #error_page  404              /404.html;

 

    # redirect server error pages to the static page /50x.html

    error_page   500 502 503 504  /50x.html;

    #location = /50x.html {

    #   root html;

    #}

 

    location ~ \.php$ {

        fastcgi_pass   127.0.0.1:9000;

        fastcgi_index  index.php;

        fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

        include        fastcgi.conf;

    }

 

    # deny access to .htaccess files, if Apache‘s document root

    # concurs with nginx‘s one

    #

    location ~ /\.ht {

        deny  all;

    }

}

保存退出即可

五、制作rpm包,命令如下:

fpm -s dir -t rpm -n tengine -v 2.0.3 -d ‘pcre-devel,openssl-devel‘ -C /tmp/install/ - -post-install /tmp/install/script/install_after.sh -p /root

Fpm命令注释:

1.-s 指定源类型

2.dir 将目录打包成所需要的类型,可以用于源码编译安装的软件包

3.-t 指定目标类型,即想要制作什么包

4.rpm 对rpm进行转换

5.-n 指定包名称(这里我指定的是tengine)

6.-v 指定包的版本号(这里我指定的是2.0.3)

7.-d 指定依赖于哪些包(这里我指定安装nginx必须安装的组件是pcre-developenssl-devel

8.-C 指定需要打包的目录,即把哪个目录打包(在这里我之前创建了临时目录/tmp/install,并添加了nginx配置文件的模板)

9.--post-install 软件包安装完成之后所需要运行的脚本(我们在临时安装目录下创建了脚本目录/tmp/install/script/install_after.sh)

10.-p 指定打好的rpm的存放目录

我们可以在/root目录下查看是否生成该包

[root@localhost ~]# ls

tengine-2.0.3-1.x86_64.rpm

六、测试rpm是否可以正常使用

1.将打好的rpm传到测试机上

2.在一台没有nginx的机器上测试该包

[root@localhost ~]# rpm -ivh tengine-2.0.3-1.x86_64.rpm

error: Failed dependencies:

pcre-devel is needed by tengine-2.0.3-1.x86_64

openssl-devel is needed by tengine-2.0.3-1.x86_64

我们看到以上报错是依赖没有安装,yum安装即可

yum -y install pcre-devel openssl-devel

再次安装rpm包

[root@localhost ~]# rpm -ivh tengine-2.0.3-1.x86_64.rpm

Preparing...                ########################################### [100%]

1:tengine                 ########################################### [100%]

出现以上进度条证明安装完成

3.测试nginx是否正常

[root@localhost ~]# /usr/local/nginx/sbin/nginx -t

the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

configuration file /usr/local/nginx/conf/nginx.conf test is successful

[root@localhost ~]#

4.检查相关目录是否存在

日志目录,以及nginx配置文件目录vhost等等

5.启动nginx并查看是否正常监听

[root@localhost weblogs]# /usr/local/nginx/sbin/nginx

[root@localhost weblogs]# netstat -nultp|grep nginx

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      1507/nginx          

[root@localhost weblogs]#

 

 

 

FPM打包工具制作线上nginx的RPM包

标签:链接库   lin   打包工具   tps   red   RKE   virt   direct   some   

原文地址:https://www.cnblogs.com/bazingafraser/p/8505102.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!