Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1807821
  • 博文数量: 524
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 2483
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-25 18:36
个人简介

打杂

文章分类

全部博文(524)

文章存档

2022年(3)

2021年(9)

2019年(1)

2018年(32)

2017年(11)

2016年(152)

2015年(198)

2014年(118)

分类: LINUX

2016-12-28 15:36:07

python 系统批量运维管理器Fabric  nginx 批量部署
系统环境: centos 6.5_x64
软件需求:
            nginx-1.4.7.tar.gz
            pcre-8.33.tar.gz
fabric模块需要单独安装
python  版本  
Python 2.7.6

点击(此处)折叠或打开

  1. #!/usr/bin/python27
  2. #coding: utf-8
  3. from fabric.colors import *
  4. from fabric.api import *

  5. env.user='root'
  6. env.hosts=['172.16.1.188','172.16.1.189']
  7. env.passwords = {
  8.     'root@172.16.1.188:22': 'centos',
  9.     'root@172.16.1.189:22': 'centos'
  10. }
  11. nginx_package="/home/nginx-1.4.7.tar.gz" #本地软件nginx-1.4.7.tar.gz位置
  12. pcre_package="/home/pcre-8.33.tar.gz" #本地软件pcre-8.33.tar.gz位置
  13. nginx_init="/home/nginx" #本地nginx启动脚本位置
  14. rpackage="/usr/local/src" #远程安装包路径
  15. init="/etc/init.d/" #启动脚本存放位置
  16. @task
  17. def install_gcc():
  18.     print yellow("########Install gcc ########")
  19.     run("yum install gcc gcc-c++ -y")
  20. @task
  21. def put_task():
  22.     print yellow("########Put package ########")
  23.     result = put(nginx_package, rpackage)
  24.     result = put(pcre_package, rpackage)
  25.     result = put(nginx_init, init)
  26. @task
  27. def install_pcre():
  28.     print yellow("########Install pcre ########")
  29.     with cd("/usr/local/src"):
  30.         run("tar -zxvf pcre-8.33.tar.gz")
  31.         with cd("pcre-8.33"):
  32.             run("./configure && make && make install")
  33. @task
  34. def install_nginx():
  35.     print yellow("########Install nginx ########")
  36.     with cd("/usr/local/src"):
  37.         run("tar -zxvf nginx-1.4.7.tar.gz")
  38.         with cd("nginx-1.4.7"):
  39.             run("groupadd www && useradd -g www www -s /bin/false")
  40.             run("./configure --prefix=/usr/local/nginx --user=www --group=www --with-pcre=/usr/local/src/pcre-8.33")
  41.             run("make && make install")
  42.             run("chmod 755 /etc/init.d/nginx && /etc/init.d/nginx start")
  43. @task
  44. def go():
  45.     install_gcc()
  46.     put_task()
  47.     install_pcre()
  48.     install_nginx()

执行脚本:       #  fab  -f install.py  -P go
阅读(1591) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~