from fabric.api import *from fabric.contrib.console import confirmfrom fabric.utils import abortfrom fabric.colors import *import time,os,json"""单机版安装fdfs:1、上传fsdf程序包;2、修改配置文件;3、启动程序;"""# 定义一些常量## 本地软件目录env.local_softdir="E:/安装/"## 远端家目录env.remote_dir="/data/"##fdfs存储路径env.storage_dir = "/data/airport/fdfs"#fdfs安装路径env.remote_softdir = "/data/fastdfs"env.roledefs = { 'fdfs': ["10.135.8.157"],}env.user = 'root'env.password = 'asdf1@34'@task()def editServer(ip,file): config = """[fdfs]fdfs-url=%sfdfs-src=%sgroup_name=group1 """ %(ip,file) return config@roles('fdfs')@task()def fdfs_deploy(): with cd(env.remote_dir): ip = env.host print("开始部署") run("echo 'start deploy fdfs'") ifExists=run(""" [ -e "./fastdfs" ] && echo "cunzai" || echo 'bucunzai'""") if ifExists == "bucunzai": put(env.local_softdir + "fastdfs.tar.gz", env.remote_dir) #修改配置文件 serverconfig = editServer(env.host,env.storage_dir) run(""" echo '%s' > /data/server.conf""" % serverconfig) run("tar -zxvf fastdfs.tar.gz") else: print("安装文件已存在,不需要再进行安装,退出安装") sys.exit(1)@roles('fdfs')@task()def fdfs_start(): with cd(env.remote_softdir): run("./install.sh",pty=False) run("./start.sh",pty=False)@taskdef install(default=True): execute(fdfs_deploy) execute(fdfs_start)