python 系统批量运维管理器Fabric nginx 批量部署
系统环境: centos 6.5_x64
软件需求:
nginx-1.4.7.tar.gz
pcre-8.33.tar.gz
fabric模块需要单独安装
python 版本 Python 2.7.6
-
#!/usr/bin/python27
-
#coding: utf-8
-
from fabric.colors import *
-
from fabric.api import *
-
-
env.user='root'
-
env.hosts=['172.16.1.188','172.16.1.189']
-
env.passwords = {
-
'root@172.16.1.188:22': 'centos',
-
'root@172.16.1.189:22': 'centos'
-
}
-
nginx_package="/home/nginx-1.4.7.tar.gz" #本地软件nginx-1.4.7.tar.gz位置
-
pcre_package="/home/pcre-8.33.tar.gz" #本地软件pcre-8.33.tar.gz位置
-
nginx_init="/home/nginx" #本地nginx启动脚本位置
-
rpackage="/usr/local/src" #远程安装包路径
-
init="/etc/init.d/" #启动脚本存放位置
-
@task
-
def install_gcc():
-
print yellow("########Install gcc ########")
-
run("yum install gcc gcc-c++ -y")
-
@task
-
def put_task():
-
print yellow("########Put package ########")
-
result = put(nginx_package, rpackage)
-
result = put(pcre_package, rpackage)
-
result = put(nginx_init, init)
-
@task
-
def install_pcre():
-
print yellow("########Install pcre ########")
-
with cd("/usr/local/src"):
-
run("tar -zxvf pcre-8.33.tar.gz")
-
with cd("pcre-8.33"):
-
run("./configure && make && make install")
-
@task
-
def install_nginx():
-
print yellow("########Install nginx ########")
-
with cd("/usr/local/src"):
-
run("tar -zxvf nginx-1.4.7.tar.gz")
-
with cd("nginx-1.4.7"):
-
run("groupadd www && useradd -g www www -s /bin/false")
-
run("./configure --prefix=/usr/local/nginx --user=www --group=www --with-pcre=/usr/local/src/pcre-8.33")
-
run("make && make install")
-
run("chmod 755 /etc/init.d/nginx && /etc/init.d/nginx start")
-
@task
-
def go():
-
install_gcc()
-
put_task()
-
install_pcre()
-
install_nginx()
执行脚本: # fab -f install.py -P go
阅读(2842) | 评论(0) | 转发(1) |