自动安装nginx 不同版本

简介:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/python
# conding:utf8
 
from  optparse  import  OptionParser
import  re
import  pycurl
import  StringIO
import  sys
import  urllib2
import  subprocess
import  threading
import  os
from  optparse  import  OptionParser
 
def  parse_url(url):
     =  pycurl.Curl()
     =  StringIO.StringIO()
     c.setopt(c.URL, url)
     c.setopt(pycurl.FOLLOWLOCATION,  1 )
     c.setopt(c.WRITEFUNCTION, b.write)
     c.perform()
     c.setopt(c.CONNECTTIMEOUT,  5 )
     c.setopt(c.TIMEOUT,  5 )
     status  =  c.getinfo(pycurl.HTTP_CODE)
     if  status  = =  200 :
         content  =  b.getvalue()
         return  content
     c.close()
     b.close()
 
def  nginx_download(version):
     nginx_package  =  "nginx-%s.tar.gz"  %  (version)
     url  =  "http://nginx.org/download/%s"  %  (nginx_package)
     if  not  os.path.exists( "/root/%s"  %  (nginx_package)):
         print  "download %s ..."  %  (nginx_package)
         =  urllib2.urlopen(url)
         data  =  f.read()
         with  open ( "/root/%s"  %  (nginx_package),  "wb" ) as nginx:
             nginx.write(data)
         print  "download success"
     return  0
 
def  list_nginx():
     url  =  "http://nginx.org/download/"
     content  =  parse_url(url)
     version  =  []
     =  re. compile (r '>(nginx-(.*?).tar.gz)<' )
     for  in  p.finditer(content):
         version.append(m.group( 2 )) 
     return  version[: - 21 : - 1 ]
 
def  install_nginx(version):
     nginx_package  =  "nginx-%s.tar.gz"  %  (version)
     lua_module  =  "https://github.com/openresty/lua-nginx-module.git"
     echo_module  =  "https://github.com/openresty/echo-nginx-module.git"
     check_module  =  "https://github.com/yaoweibin/nginx_upstream_check_module"
     
     packages  =  [ 'openssl-devel' 'zlib-devel' 'pcre-devel' 'lua-devel' 'gcc' ]
     
     for  package  in  packages:
         =  subprocess.call( "rpm -qa | grep '%s'"  %  (package), shell = True )
        print  p
         if  p ! =  0 :
             p1  =  subprocess.call( "yum install %s -y"  %  (package), shell = True )
         if  p1  = =  0 :
             print  "yum install %s success"  %  (package)
 
     if  os.path.exists( "/root" ):
             subprocess.call( "cd /root" , shell = True )
 
         if  not  os.path.exists( "/root/lua-nginx-module" ): 
             print  "git lua-nginx-module ..."
             =  subprocess.call( "git clone %s"  %  (lua_module), shell = True )
             if  = =  0 :
                 print  "git lua-nginx-module success"
 
         if  not  os.path.exists( "/root/echo-nginx-module" ):
             print  "git echo-nginx-module ..."
             =  subprocess.call( "git clone %s"  %  (echo_module), shell = True )
             if  = =  0 :
                 print  "git echo-nginx-module success"
 
         if  not  os.path.exists( "/root/nginx_upstream_check_module" ):  
             print  "git nginx_upstream_check_module ..."
             =  subprocess.call( "git clone %s"  %  (check_module), shell = True )
             if  = =  0 :
                 print  "git nginx_upstream_check_module success"
         
         if  not  os.path.exists( "/root/nginx-%s"  %  (version)):
             print  "tar %s ..."  %  (nginx_package)
             subprocess.call( "tar -xzvf %s"  %  (nginx_package), shell = True )
             print  "tar success"
 
         print  "install %s ..."  %  (nginx_package)
         =  subprocess.call( "cd /root/nginx-%s;./configure --prefix=/usr/local/nginx-%s --with-http_ssl_module --with-http_gzip_static_module --with-http_ssl_module --with-http_spdy_module --with-http_stub_status_module --add-module=/root/lua-nginx-module --add-module=/root/echo-nginx-module"  %  (version, version), shell = True )
         if  = =  0 :
             =  subprocess.call( "cd /root/nginx-%s;make"  %  (version), shell = True )
             if  = =  0 :
                 subprocess.call( "cd /root/nginx-%s;make install"  %  (version), shell = True )
                 print  "install %s success"  %  (nginx_package)
 
def  main():
     parser  =  OptionParser()
     parser.add_option( "-l" "--list" , action = "store_true" , dest = "list" help = "list nginx version" )
     parser.add_option( "-i" "--version" , action = "store" , dest = "version" help = "install nginx version" )
     (options, args)  =  parser.parse_args()
     if  options. list :
         for  version  in  list_nginx():
             print  version
     elif  options.version:
         if  options.version  in  list_nginx():
             if  nginx_download(options.version)  = =  0 :
                 install_nginx(options.version)
     
if  __name__  = =  '__main__' :
     main() 









本文转自 Art_Hero 51CTO博客,原文链接:http://blog.51cto.com/curran/1624960,如需转载请自行联系原作者
目录
相关文章
|
15天前
|
应用服务中间件 Linux 网络安全
CentOS 7.4源码编译nginx1.12 并且隐藏nginx的版本
CentOS 7.4源码编译nginx1.12 并且隐藏nginx的版本
14 0
|
1月前
|
应用服务中间件 nginx
Nginx安装nginx-rtmp-module模块
【2月更文挑战第4天】 nginx中的模块虽然就是类似插件的概念,但是它无法像VsCode那样轻松的安装扩展。 nginx要安装其它模块必须同时拿到nginx源代码和模块源代码,然后手动编译,将模块打到nginx中,最终生成一个名为nginx的可执行文件。
74 6
|
2月前
|
负载均衡 Ubuntu 应用服务中间件
|
2月前
|
缓存 负载均衡 应用服务中间件
如何在 CentOS 7 上为 NGINX 安装开源 HTTP 加速器:Varnish
如何在 CentOS 7 上为 NGINX 安装开源 HTTP 加速器:Varnish
71 1
如何在 CentOS 7 上为 NGINX 安装开源 HTTP 加速器:Varnish
|
6天前
|
应用服务中间件 nginx
yum 安装报错 No package nginx available Error:Nothing to do
yum 安装报错 No package nginx available Error:Nothing to do
19 1
|
27天前
|
应用服务中间件 Linux PHP
Linux下安装php环境并且配置Nginx支持php-fpm模块
Linux下安装php环境并且配置Nginx支持php-fpm模块
29 0
|
28天前
|
前端开发 应用服务中间件 网络安全
http转为https,ssl证书安装及nginx配置
http转为https,ssl证书安装及nginx配置
43 1
|
28天前
|
网络协议 应用服务中间件 网络安全
linxu安装nginx
linxu安装nginx
66 0
|
1月前
|
NoSQL 关系型数据库 MySQL
Docker安装详细步骤及相关环境安装配置(mysql、jdk、redis、自己的私有仓库Gitlab 、C和C++环境以及Nginx服务代理)
Docker安装详细步骤及相关环境安装配置(mysql、jdk、redis、自己的私有仓库Gitlab 、C和C++环境以及Nginx服务代理)
216 0
|
1月前
|
负载均衡 应用服务中间件 nginx